blob: e372ea3d2001b5ad35026ec2951f4824c165c95c [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 Lobodzinski087380c2017-05-16 14:42:25 -0600602 } else if (GetDeviceExtensions(device_data)->khr_shared_presentable_image) {
603 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) {
921 if (!GetDeviceExtensions(device_data)->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) + "]";
1013 skip |= ValidateImageSubresourceRange(dev_data, image_state, nullptr, pRanges[i], "vkCmdClearColorImage",
1014 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,
1024 uint32_t rangeCount, const VkImageSubresourceRange *pRanges, CMD_TYPE cmd_type) {
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);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001034 core_validation::UpdateCmdBufferLastCmd(cb_node, cmd_type);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001035 for (uint32_t i = 0; i < rangeCount; ++i) {
1036 RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout);
1037 }
1038 }
1039}
1040
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001041bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image,
1042 VkImageLayout imageLayout, uint32_t rangeCount,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001043 const VkImageSubresourceRange *pRanges) {
1044 bool skip = false;
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001045 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1046
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001047 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001048 auto cb_node = GetCBNode(device_data, commandBuffer);
1049 auto image_state = GetImageState(device_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001050 if (cb_node && image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001051 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00014);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001052 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001053 VALIDATION_ERROR_18a02415);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001054 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001055 skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_18a00017);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001056 for (uint32_t i = 0; i < rangeCount; ++i) {
Petr Kraus4d718682017-05-18 03:38:41 +02001057 std::string param_name = "pRanges[" + std::to_string(i) + "]";
1058 skip |= ValidateImageSubresourceRange(device_data, image_state, nullptr, pRanges[i], "vkCmdClearDepthStencilImage",
1059 param_name.c_str());
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -07001060 skip |=
1061 VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()");
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001062 // Image aspect must be depth or stencil or both
1063 if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1064 ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1065 char const str[] =
1066 "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be "
1067 "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT";
1068 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 +02001069 HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001070 }
1071 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001072 if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001073 char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image.";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001074 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1075 HandleToUint64(image), __LINE__, VALIDATION_ERROR_18a0001c, "IMAGE", "%s. %s", str,
1076 validation_error_map[VALIDATION_ERROR_18a0001c]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001077 }
1078 }
1079 return skip;
1080}
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001081
1082// Returns true if [x, xoffset] and [y, yoffset] overlap
1083static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) {
1084 bool result = false;
1085 uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end));
1086 uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset);
1087
1088 if (intersection_max > intersection_min) {
1089 result = true;
1090 }
1091 return result;
1092}
1093
1094// Returns true if two VkImageCopy structures overlap
1095static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) {
1096 bool result = false;
1097 if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) &&
1098 (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer,
1099 dst->dstSubresource.layerCount))) {
1100 result = true;
1101 switch (type) {
1102 case VK_IMAGE_TYPE_3D:
1103 result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth);
1104 // Intentionally fall through to 2D case
1105 case VK_IMAGE_TYPE_2D:
1106 result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height);
1107 // Intentionally fall through to 1D case
1108 case VK_IMAGE_TYPE_1D:
1109 result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width);
1110 break;
1111 default:
1112 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
1113 assert(false);
1114 }
1115 }
1116 return result;
1117}
1118
Dave Houltonfc1a4052017-04-27 14:32:45 -06001119// Returns non-zero if offset and extent exceed image extents
1120static const uint32_t x_bit = 1;
1121static const uint32_t y_bit = 2;
1122static const uint32_t z_bit = 4;
Dave Houlton1150cf52017-04-27 14:38:11 -06001123static uint32_t ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const VkExtent3D *image_extent) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001124 uint32_t result = 0;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001125 // Extents/depths cannot be negative but checks left in for clarity
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001126 if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) ||
1127 ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001128 result |= z_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001129 }
1130 if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) ||
1131 ((offset->y + static_cast<int32_t>(extent->height)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001132 result |= y_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001133 }
1134 if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) ||
1135 ((offset->x + static_cast<int32_t>(extent->width)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001136 result |= x_bit;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001137 }
1138 return result;
1139}
1140
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001141// Test if two VkExtent3D structs are equivalent
1142static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) {
1143 bool result = true;
1144 if ((extent->width != other_extent->width) || (extent->height != other_extent->height) ||
1145 (extent->depth != other_extent->depth)) {
1146 result = false;
1147 }
1148 return result;
1149}
1150
Dave Houlton6f9059e2017-05-02 17:15:13 -06001151// Returns the effective extent of an image subresource, adjusted for mip level and array depth.
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001152static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) {
1153 const uint32_t mip = subresource->mipLevel;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001154
1155 // Return zero extent if mip level doesn't exist
Dave Houlton1150cf52017-04-27 14:38:11 -06001156 if (mip >= img->createInfo.mipLevels) {
1157 return VkExtent3D{0, 0, 0};
Dave Houltonfc1a4052017-04-27 14:32:45 -06001158 }
Dave Houlton1150cf52017-04-27 14:38:11 -06001159
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001160 // 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 -06001161 VkExtent3D extent = img->createInfo.extent;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001162 extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip));
1163 extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip));
1164 extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip));
Dave Houltonfc1a4052017-04-27 14:32:45 -06001165
Dave Houlton6f9059e2017-05-02 17:15:13 -06001166 // Image arrays have an effective z extent that isn't diminished by mip level
1167 if (VK_IMAGE_TYPE_3D != img->createInfo.imageType) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001168 extent.depth = img->createInfo.arrayLayers;
1169 }
1170
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001171 return extent;
1172}
1173
1174// Test if the extent argument has all dimensions set to 0.
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001175static inline bool IsExtentAllZeroes(const VkExtent3D *extent) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001176 return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0));
1177}
1178
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001179// Test if the extent argument has any dimensions set to 0.
1180static inline bool IsExtentSizeZero(const VkExtent3D *extent) {
1181 return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0));
1182}
1183
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001184// Returns the image transfer granularity for a specific image scaled by compressed block size if necessary.
1185static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) {
1186 // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device.
1187 VkExtent3D granularity = {0, 0, 0};
1188 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
1189 if (pPool) {
1190 granularity =
1191 GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001192 if (FormatIsCompressed(img->createInfo.format)) {
1193 auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001194 granularity.width *= block_size.width;
1195 granularity.height *= block_size.height;
1196 }
1197 }
1198 return granularity;
1199}
1200
1201// Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure
1202static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) {
1203 bool valid = true;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001204 if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) ||
1205 (SafeModulo(extent->height, granularity->height) != 0)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001206 valid = false;
1207 }
1208 return valid;
1209}
1210
1211// Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values
1212static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset,
1213 const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) {
1214 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1215 bool skip = false;
1216 VkExtent3D offset_extent = {};
1217 offset_extent.width = static_cast<uint32_t>(abs(offset->x));
1218 offset_extent.height = static_cast<uint32_t>(abs(offset->y));
1219 offset_extent.depth = static_cast<uint32_t>(abs(offset->z));
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001220 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001221 // 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 -07001222 if (IsExtentAllZeroes(&offset_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001223 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1224 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1225 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) "
1226 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1227 function, i, member, offset->x, offset->y, offset->z);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001228 }
1229 } else {
1230 // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even
1231 // integer multiples of the image transfer granularity.
1232 if (IsExtentAligned(&offset_extent, granularity) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001233 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1234 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1235 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer "
1236 "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).",
1237 function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height,
1238 granularity->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001239 }
1240 }
1241 return skip;
1242}
1243
1244// Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values
1245static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent,
1246 const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent,
1247 const uint32_t i, const char *function, const char *member) {
1248 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1249 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001250 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001251 // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image
1252 // subresource extent.
1253 if (IsExtentEqual(extent, subresource_extent) == false) {
Petr Krausbc7f5442017-05-14 23:43:38 +02001254 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1255 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1256 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) "
1257 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1258 function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width,
1259 subresource_extent->height, subresource_extent->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001260 }
1261 } else {
1262 // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even
1263 // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image
1264 // subresource extent dimensions.
1265 VkExtent3D offset_extent_sum = {};
1266 offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width;
1267 offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height;
1268 offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth;
Dave Houlton6f9059e2017-05-02 17:15:13 -06001269
1270 bool x_ok =
1271 ((0 == SafeModulo(extent->width, granularity->width)) || (subresource_extent->width == offset_extent_sum.width));
1272 bool y_ok =
1273 ((0 == SafeModulo(extent->height, granularity->height)) || (subresource_extent->height == offset_extent_sum.height));
1274 bool z_ok =
1275 ((0 == SafeModulo(extent->depth, granularity->depth)) || (subresource_extent->depth == offset_extent_sum.depth));
1276
1277 if (!(x_ok && y_ok && z_ok)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001278 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001279 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 +02001280 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001281 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's "
1282 "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + "
1283 "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).",
1284 function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height,
1285 granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth,
1286 subresource_extent->width, subresource_extent->height, subresource_extent->depth);
1287 }
1288 }
1289 return skip;
1290}
1291
1292// Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value
1293static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value,
1294 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1295 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1296
1297 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001298 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001299 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 +02001300 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001301 "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image "
1302 "transfer granularity width (%d).",
1303 function, i, member, value, granularity);
1304 }
1305 return skip;
1306}
1307
1308// Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value
1309static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value,
1310 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1311 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1312 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001313 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001314 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 +02001315 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001316 "%s: pRegion[%d].%s (%" PRIdLEAST64
1317 ") must be an even integer multiple of this command buffer's queue family image transfer "
1318 "granularity width (%d).",
1319 function, i, member, value, granularity);
1320 }
1321 return skip;
1322}
1323
1324// Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure
1325bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
1326 const IMAGE_STATE *img, const VkBufferImageCopy *region,
1327 const uint32_t i, const char *function) {
1328 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001329 if (FormatIsCompressed(img->createInfo.format) == true) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001330 // TODO: Add granularity checking for compressed formats
1331
1332 // bufferRowLength must be a multiple of the compressed texel block width
1333 // bufferImageHeight must be a multiple of the compressed texel block height
1334 // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block
1335 // bufferOffset must be a multiple of the compressed texel block size in bytes
1336 // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x)
1337 // must equal the image subresource width
1338 // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y)
1339 // must equal the image subresource height
1340 // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z)
1341 // must equal the image subresource depth
1342 } else {
1343 VkExtent3D granularity = GetScaledItg(device_data, cb_node, img);
1344 skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset");
1345 skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength");
1346 skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight");
1347 skip |= CheckItgOffset(device_data, cb_node, &region->imageOffset, &granularity, i, function, "imageOffset");
1348 VkExtent3D subresource_extent = GetImageSubresourceExtent(img, &region->imageSubresource);
1349 skip |= CheckItgExtent(device_data, cb_node, &region->imageExtent, &region->imageOffset, &granularity, &subresource_extent,
1350 i, function, "imageExtent");
1351 }
1352 return skip;
1353}
1354
1355// Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure
1356bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
Dave Houlton6f9059e2017-05-02 17:15:13 -06001357 const IMAGE_STATE *src_img, const IMAGE_STATE *dst_img,
1358 const VkImageCopy *region, const uint32_t i, const char *function) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001359 bool skip = false;
Dave Houlton6f9059e2017-05-02 17:15:13 -06001360 VkExtent3D granularity = GetScaledItg(device_data, cb_node, src_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001361 skip |= CheckItgOffset(device_data, cb_node, &region->srcOffset, &granularity, i, function, "srcOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001362 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_img, &region->srcSubresource);
1363 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->srcOffset, &granularity, &subresource_extent, i,
1364 function, "extent");
1365
1366 granularity = GetScaledItg(device_data, cb_node, dst_img);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001367 skip |= CheckItgOffset(device_data, cb_node, &region->dstOffset, &granularity, i, function, "dstOffset");
Dave Houlton6f9059e2017-05-02 17:15:13 -06001368 subresource_extent = GetImageSubresourceExtent(dst_img, &region->dstSubresource);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001369 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->dstOffset, &granularity, &subresource_extent, i,
1370 function, "extent");
1371 return skip;
1372}
1373
Dave Houlton6f9059e2017-05-02 17:15:13 -06001374// Validate contents of a VkImageCopy struct
1375bool ValidateImageCopyData(const layer_data *device_data, const debug_report_data *report_data, const uint32_t regionCount,
1376 const VkImageCopy *ic_regions, const IMAGE_STATE *src_state, const IMAGE_STATE *dst_state) {
1377 bool skip = false;
1378
1379 for (uint32_t i = 0; i < regionCount; i++) {
1380 VkImageCopy image_copy = ic_regions[i];
1381 bool slice_override = false;
1382 uint32_t depth_slices = 0;
1383
1384 // Special case for copying between a 1D/2D array and a 3D image
1385 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1386 if ((VK_IMAGE_TYPE_3D == src_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != dst_state->createInfo.imageType)) {
1387 depth_slices = image_copy.dstSubresource.layerCount; // Slice count from 2D subresource
1388 slice_override = (depth_slices != 1);
1389 } else if ((VK_IMAGE_TYPE_3D == dst_state->createInfo.imageType) && (VK_IMAGE_TYPE_3D != src_state->createInfo.imageType)) {
1390 depth_slices = image_copy.srcSubresource.layerCount; // Slice count from 2D subresource
1391 slice_override = (depth_slices != 1);
1392 }
1393
1394 // Do all checks on source image
1395 //
1396 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
1397 if ((0 != image_copy.srcOffset.y) || (1 != image_copy.extent.height)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001398 skip |=
1399 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1400 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00124, "IMAGE",
1401 "vkCmdCopyImage(): pRegion[%d] srcOffset.y is %d and extent.height is %d. For 1D images these must "
1402 "be 0 and 1, respectively. %s",
1403 i, image_copy.srcOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_09c00124]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001404 }
1405 }
1406
1407 if ((src_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (src_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
1408 if ((0 != image_copy.srcOffset.z) || (1 != image_copy.extent.depth)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001409 skip |=
1410 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1411 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00128, "IMAGE",
1412 "vkCmdCopyImage(): pRegion[%d] srcOffset.z is %d and extent.depth is %d. For 1D and 2D images "
1413 "these must be 0 and 1, respectively. %s",
1414 i, image_copy.srcOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_09c00128]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001415 }
1416 }
1417
1418 // VU01199 changed with mnt1
1419 if (GetDeviceExtensions(device_data)->khr_maintenance1) {
1420 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1421 if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) {
1422 skip |=
1423 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001424 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001425 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and srcSubresource.layerCount "
1426 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1427 i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001428 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001429 }
1430 }
1431 } else { // Pre maint 1
1432 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1433 if ((0 != image_copy.srcSubresource.baseArrayLayer) || (1 != image_copy.srcSubresource.layerCount)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001434 skip |=
1435 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1436 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
1437 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer is %d and "
1438 "srcSubresource.layerCount is %d. For copies with either source or dest of type "
1439 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s",
1440 i, image_copy.srcSubresource.baseArrayLayer, image_copy.srcSubresource.layerCount,
1441 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001442 }
1443 }
1444 }
1445
1446 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec.
1447 if ((image_copy.srcSubresource.baseArrayLayer >= src_state->createInfo.arrayLayers) ||
1448 (image_copy.srcSubresource.baseArrayLayer + image_copy.srcSubresource.layerCount > src_state->createInfo.arrayLayers)) {
1449 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 -06001450 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0012a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001451 "vkCmdCopyImage(): pRegion[%d] srcSubresource.baseArrayLayer (%d) must be less than the source image's "
1452 "arrayLayers (%d), and the sum of baseArrayLayer and srcSubresource.layerCount (%d) must be less than "
1453 "or equal to the source image's arrayLayers. %s",
1454 i, image_copy.srcSubresource.baseArrayLayer, src_state->createInfo.arrayLayers,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001455 image_copy.srcSubresource.layerCount, validation_error_map[VALIDATION_ERROR_09c0012a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001456 }
1457
1458 // Checks that apply only to compressed images
1459 if (FormatIsCompressed(src_state->createInfo.format)) {
1460 VkExtent3D block_size = FormatCompressedTexelBlockExtent(src_state->createInfo.format);
1461
1462 // image offsets must be multiples of block dimensions
1463 if ((SafeModulo(image_copy.srcOffset.x, block_size.width) != 0) ||
1464 (SafeModulo(image_copy.srcOffset.y, block_size.height) != 0) ||
1465 (SafeModulo(image_copy.srcOffset.z, block_size.depth) != 0)) {
1466 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 -06001467 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001468 "vkCmdCopyImage(): pRegion[%d] srcOffset (%d, %d) must be multiples of the compressed image's "
1469 "texel width & height (%d, %d). %s.",
1470 i, image_copy.srcOffset.x, image_copy.srcOffset.y, block_size.width, block_size.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001471 validation_error_map[VALIDATION_ERROR_09c0013a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001472 }
1473
1474 // extent width must be a multiple of block width, or extent+offset width must equal subresource width
1475 VkExtent3D mip_extent = GetImageSubresourceExtent(src_state, &(image_copy.srcSubresource));
1476 if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) &&
1477 (image_copy.extent.width + image_copy.srcOffset.x != mip_extent.width)) {
1478 skip |=
1479 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001480 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013c, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001481 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1482 "width (%d), or when added to srcOffset.x (%d) must equal the image subresource width (%d). %s.",
1483 i, image_copy.extent.width, block_size.width, image_copy.srcOffset.x, mip_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001484 validation_error_map[VALIDATION_ERROR_09c0013c]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001485 }
1486
1487 // extent height must be a multiple of block height, or extent+offset height must equal subresource height
1488 if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) &&
1489 (image_copy.extent.height + image_copy.srcOffset.y != mip_extent.height)) {
1490 skip |=
1491 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001492 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c0013e, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001493 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
1494 "height (%d), or when added to srcOffset.y (%d) must equal the image subresource height (%d). %s.",
1495 i, image_copy.extent.height, block_size.height, image_copy.srcOffset.y, mip_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001496 validation_error_map[VALIDATION_ERROR_09c0013e]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001497 }
1498
1499 // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
1500 uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth);
1501 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.srcOffset.z != mip_extent.depth)) {
1502 skip |=
1503 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001504 reinterpret_cast<const uint64_t &>(src_state->image), __LINE__, VALIDATION_ERROR_09c00140, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001505 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1506 "depth (%d), or when added to srcOffset.z (%d) must equal the image subresource depth (%d). %s.",
1507 i, image_copy.extent.depth, block_size.depth, image_copy.srcOffset.z, mip_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001508 validation_error_map[VALIDATION_ERROR_09c00140]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001509 }
1510 } // Compressed
1511
1512 // Do all checks on dest image
1513 //
1514 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
1515 if ((0 != image_copy.dstOffset.y) || (1 != image_copy.extent.height)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001516 skip |=
1517 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1518 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00130, "IMAGE",
1519 "vkCmdCopyImage(): pRegion[%d] dstOffset.y is %d and extent.height is %d. For 1D images these must "
1520 "be 0 and 1, respectively. %s",
1521 i, image_copy.dstOffset.y, image_copy.extent.height, validation_error_map[VALIDATION_ERROR_09c00130]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001522 }
1523 }
1524
1525 if ((dst_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (dst_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
1526 if ((0 != image_copy.dstOffset.z) || (1 != image_copy.extent.depth)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001527 skip |=
1528 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1529 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00134, "IMAGE",
1530 "vkCmdCopyImage(): pRegion[%d] dstOffset.z is %d and extent.depth is %d. For 1D and 2D images "
1531 "these must be 0 and 1, respectively. %s",
1532 i, image_copy.dstOffset.z, image_copy.extent.depth, validation_error_map[VALIDATION_ERROR_09c00134]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001533 }
1534 }
1535
1536 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1537 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1538 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 -06001539 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001540 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
1541 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1542 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001543 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001544 }
1545 }
1546 // VU01199 changed with mnt1
1547 if (GetDeviceExtensions(device_data)->khr_maintenance1) {
1548 if (dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1549 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
1550 skip |=
1551 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001552 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001553 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and dstSubresource.layerCount "
1554 "is %d. For VK_IMAGE_TYPE_3D images these must be 0 and 1, respectively. %s",
1555 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001556 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001557 }
1558 }
1559 } else { // Pre maint 1
1560 if (src_state->createInfo.imageType == VK_IMAGE_TYPE_3D || dst_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
1561 if ((0 != image_copy.dstSubresource.baseArrayLayer) || (1 != image_copy.dstSubresource.layerCount)) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001562 skip |=
1563 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1564 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0011a, "IMAGE",
1565 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer is %d and "
1566 "dstSubresource.layerCount is %d. For copies with either source or dest of type "
1567 "VK_IMAGE_TYPE_3D, these must be 0 and 1, respectively. %s",
1568 i, image_copy.dstSubresource.baseArrayLayer, image_copy.dstSubresource.layerCount,
1569 validation_error_map[VALIDATION_ERROR_09c0011a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001570 }
1571 }
1572 }
1573
1574 // TODO: this VU is redundant with VU01224. Gitlab issue 812 submitted to get it removed from the spec.
1575 if ((image_copy.dstSubresource.baseArrayLayer >= dst_state->createInfo.arrayLayers) ||
1576 (image_copy.dstSubresource.baseArrayLayer + image_copy.dstSubresource.layerCount > dst_state->createInfo.arrayLayers)) {
1577 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 -06001578 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00136, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001579 "vkCmdCopyImage(): pRegion[%d] dstSubresource.baseArrayLayer (%d) must be less than the dest image's "
1580 "arrayLayers (%d), and the sum of baseArrayLayer and dstSubresource.layerCount (%d) must be less than "
1581 "or equal to the dest image's arrayLayers. %s",
1582 i, image_copy.dstSubresource.baseArrayLayer, dst_state->createInfo.arrayLayers,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001583 image_copy.dstSubresource.layerCount, validation_error_map[VALIDATION_ERROR_09c00136]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001584 }
1585
1586 // Checks that apply only to compressed images
1587 if (FormatIsCompressed(dst_state->createInfo.format)) {
1588 VkExtent3D block_size = FormatCompressedTexelBlockExtent(dst_state->createInfo.format);
1589
1590 // image offsets must be multiples of block dimensions
1591 if ((SafeModulo(image_copy.dstOffset.x, block_size.width) != 0) ||
1592 (SafeModulo(image_copy.dstOffset.y, block_size.height) != 0) ||
1593 (SafeModulo(image_copy.dstOffset.z, block_size.depth) != 0)) {
1594 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 -06001595 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00144, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001596 "vkCmdCopyImage(): pRegion[%d] dstOffset (%d, %d) must be multiples of the compressed image's "
1597 "texel width & height (%d, %d). %s.",
1598 i, image_copy.dstOffset.x, image_copy.dstOffset.y, block_size.width, block_size.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001599 validation_error_map[VALIDATION_ERROR_09c00144]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001600 }
1601
1602 // extent width must be a multiple of block width, or extent+offset width must equal subresource width
1603 VkExtent3D mip_extent = GetImageSubresourceExtent(dst_state, &(image_copy.dstSubresource));
1604 if ((SafeModulo(image_copy.extent.width, block_size.width) != 0) &&
1605 (image_copy.extent.width + image_copy.dstOffset.x != mip_extent.width)) {
1606 skip |=
1607 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001608 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00146, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001609 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1610 "width (%d), or when added to dstOffset.x (%d) must equal the image subresource width (%d). %s.",
1611 i, image_copy.extent.width, block_size.width, image_copy.dstOffset.x, mip_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001612 validation_error_map[VALIDATION_ERROR_09c00146]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001613 }
1614
1615 // extent height must be a multiple of block height, or extent+offset height must equal subresource height
1616 if ((SafeModulo(image_copy.extent.height, block_size.height) != 0) &&
1617 (image_copy.extent.height + image_copy.dstOffset.y != mip_extent.height)) {
1618 skip |=
1619 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001620 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c00148, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001621 "vkCmdCopyImage(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block "
1622 "height (%d), or when added to dstOffset.y (%d) must equal the image subresource height (%d). %s.",
1623 i, image_copy.extent.height, block_size.height, image_copy.dstOffset.y, mip_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001624 validation_error_map[VALIDATION_ERROR_09c00148]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001625 }
1626
1627 // extent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
1628 uint32_t copy_depth = (slice_override ? depth_slices : image_copy.extent.depth);
1629 if ((SafeModulo(copy_depth, block_size.depth) != 0) && (copy_depth + image_copy.dstOffset.z != mip_extent.depth)) {
1630 skip |=
1631 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001632 reinterpret_cast<const uint64_t &>(dst_state->image), __LINE__, VALIDATION_ERROR_09c0014a, "IMAGE",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001633 "vkCmdCopyImage(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block "
1634 "depth (%d), or when added to dstOffset.z (%d) must equal the image subresource depth (%d). %s.",
1635 i, image_copy.extent.depth, block_size.depth, image_copy.dstOffset.z, mip_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001636 validation_error_map[VALIDATION_ERROR_09c0014a]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001637 }
1638 } // Compressed
1639 }
1640 return skip;
1641}
1642
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001643bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001644 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1645 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001646 bool skip = false;
1647 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001648 skip = ValidateImageCopyData(device_data, report_data, region_count, regions, src_image_state, dst_image_state);
1649
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001650 VkCommandBuffer command_buffer = cb_node->commandBuffer;
1651
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001652 for (uint32_t i = 0; i < region_count; i++) {
Dave Houlton6f9059e2017-05-02 17:15:13 -06001653 bool slice_override = false;
1654 uint32_t depth_slices = 0;
1655
1656 // Special case for copying between a 1D/2D array and a 3D image
1657 // TBD: This seems like the only way to reconcile 3 mutually-exclusive VU checks for 2D/3D copies. Heads up.
1658 if ((VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType) &&
1659 (VK_IMAGE_TYPE_3D != dst_image_state->createInfo.imageType)) {
1660 depth_slices = regions[i].dstSubresource.layerCount; // Slice count from 2D subresource
1661 slice_override = (depth_slices != 1);
1662 } else if ((VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType) &&
1663 (VK_IMAGE_TYPE_3D != src_image_state->createInfo.imageType)) {
1664 depth_slices = regions[i].srcSubresource.layerCount; // Slice count from 2D subresource
1665 slice_override = (depth_slices != 1);
1666 }
1667
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001668 if (regions[i].srcSubresource.layerCount == 0) {
1669 std::stringstream ss;
1670 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero";
Petr Krausbc7f5442017-05-14 23:43:38 +02001671 skip |=
1672 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1673 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001674 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001675
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001676 if (regions[i].dstSubresource.layerCount == 0) {
1677 std::stringstream ss;
1678 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero";
Petr Krausbc7f5442017-05-14 23:43:38 +02001679 skip |=
1680 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1681 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001682 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001683
Dave Houlton6f9059e2017-05-02 17:15:13 -06001684 if (GetDeviceExtensions(device_data)->khr_maintenance1) {
1685 // No chance of mismatch if we're overriding depth slice count
1686 if (!slice_override) {
1687 // The number of depth slices in srcSubresource and dstSubresource must match
1688 // Depth comes from layerCount for 1D,2D resources, from extent.depth for 3D
1689 uint32_t src_slices =
1690 (VK_IMAGE_TYPE_3D == src_image_state->createInfo.imageType ? regions[i].extent.depth
1691 : regions[i].srcSubresource.layerCount);
1692 uint32_t dst_slices =
1693 (VK_IMAGE_TYPE_3D == dst_image_state->createInfo.imageType ? regions[i].extent.depth
1694 : regions[i].dstSubresource.layerCount);
1695 if (src_slices != dst_slices) {
1696 std::stringstream ss;
1697 ss << "vkCmdCopyImage: number of depth slices in source and destination subresources for pRegions[" << i
1698 << "] do not match";
1699 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 -06001700 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_09c00118, "IMAGE",
1701 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c00118]);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001702 }
1703 }
1704 } else {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001705 // For each region the layerCount member of srcSubresource and dstSubresource must match
1706 if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) {
1707 std::stringstream ss;
1708 ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i
1709 << "] do not match";
1710 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 -06001711 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00118, "IMAGE", "%s. %s",
1712 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c00118]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001713 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001714 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001715
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001716 // For each region, the aspectMask member of srcSubresource and dstSubresource must match
1717 if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) {
1718 char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match";
1719 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 -06001720 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00112, "IMAGE", "%s. %s", str,
1721 validation_error_map[VALIDATION_ERROR_09c00112]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001722 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001723
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001724 // For each region, the aspectMask member of srcSubresource must be present in the source image
1725 if (!VerifyAspectsPresent(regions[i].srcSubresource.aspectMask, src_image_state->createInfo.format)) {
1726 std::stringstream ss;
1727 ss << "vkCmdCopyImage: pRegion[" << i
1728 << "] srcSubresource.aspectMask cannot specify aspects not present in source image";
1729 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 -06001730 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0011c, "IMAGE", "%s. %s",
1731 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c0011c]);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001732 }
1733
1734 // For each region, the aspectMask member of dstSubresource must be present in the destination image
1735 if (!VerifyAspectsPresent(regions[i].dstSubresource.aspectMask, dst_image_state->createInfo.format)) {
1736 std::stringstream ss;
1737 ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image";
1738 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 -06001739 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0011e, "IMAGE", "%s. %s",
1740 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_09c0011e]);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001741 }
1742
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001743 // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT
1744 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) ||
1745 (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) {
1746 std::stringstream ss;
1747 ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT";
1748 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 -06001749 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600150, "IMAGE", "%s. %s",
1750 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600150]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001751 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001752
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001753 // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of
1754 // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT
1755 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) &&
1756 (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) {
1757 char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects";
1758 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 -06001759 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a60014e, "IMAGE", "%s. %s", str,
1760 validation_error_map[VALIDATION_ERROR_0a60014e]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001761 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001762
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001763 // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
1764 if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
1765 std::stringstream ss;
1766 ss << "vkCmdCopyImage: pRegions[" << i
1767 << "] specifies a src mipLevel greater than the number specified when the srcImage was created.";
1768 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 -06001769 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600152, "IMAGE", "%s. %s",
1770 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600152]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001771 }
1772 if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
1773 std::stringstream ss;
1774 ss << "vkCmdCopyImage: pRegions[" << i
1775 << "] specifies a dst mipLevel greater than the number specified when the dstImage was created.";
1776 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 -06001777 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600152, "IMAGE", "%s. %s",
1778 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600152]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001779 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001780
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001781 // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the
1782 // image was created
1783 if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) >
1784 src_image_state->createInfo.arrayLayers) {
1785 std::stringstream ss;
1786 ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i
1787 << "] baseArrayLayer + layerCount is "
1788 << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount);
1789 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 -06001790 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600154, "IMAGE", "%s. %s",
1791 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600154]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001792 }
1793 if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) >
1794 dst_image_state->createInfo.arrayLayers) {
1795 std::stringstream ss;
1796 ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i
1797 << "] baseArrayLayer + layerCount is "
1798 << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount);
1799 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 -06001800 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_0a600154, "IMAGE", "%s. %s",
1801 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_0a600154]);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001802 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001803
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001804 // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies
1805 if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) {
1806 // 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 -06001807 VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
1808 if (0 != ExceedsBounds(&regions[i].srcOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001809 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001810 ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << regions[i].srcSubresource.mipLevel
1811 << " ], offset [ " << regions[i].srcOffset.x << ", " << regions[i].srcOffset.y << ", " << regions[i].srcOffset.z
1812 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1813 << regions[i].extent.depth << " ] exceeds the source image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001814 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 -06001815 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f4, "IMAGE", "%s. %s",
1816 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f4]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001817 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001818
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001819 // 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 -06001820 img_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
1821 if (0 != ExceedsBounds(&regions[i].dstOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001822 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001823 ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << regions[i].dstSubresource.mipLevel
1824 << " ], offset [ " << regions[i].dstOffset.x << ", " << regions[i].dstOffset.y << ", " << regions[i].dstOffset.z
1825 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1826 << regions[i].extent.depth << " ] exceeds the destination image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001827 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 -06001828 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f6, "IMAGE", "%s. %s",
1829 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f6]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001830 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001831 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001832
Dave Houltonfc1a4052017-04-27 14:32:45 -06001833 // Each dimension offset + extent limits must fall with image subresource extent
1834 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
Dave Houlton6f9059e2017-05-02 17:15:13 -06001835 VkExtent3D copy_extent = regions[i].extent;
1836 if (slice_override) copy_extent.depth = depth_slices;
1837 uint32_t extent_check = ExceedsBounds(&(regions[i].srcOffset), &copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001838 if (extent_check & x_bit) {
1839 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 -06001840 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00120, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001841 "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1842 "width [%1d]. %s",
1843 i, regions[i].srcOffset.x, regions[i].extent.width, subresource_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001844 validation_error_map[VALIDATION_ERROR_09c00120]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001845 }
1846
1847 if (extent_check & y_bit) {
1848 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 -06001849 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00122, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001850 "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1851 "height [%1d]. %s",
1852 i, regions[i].srcOffset.y, regions[i].extent.height, subresource_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001853 validation_error_map[VALIDATION_ERROR_09c00122]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001854 }
1855 if (extent_check & z_bit) {
1856 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 -06001857 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00126, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001858 "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1859 "depth [%1d]. %s",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001860 i, regions[i].srcOffset.z, copy_extent.depth, subresource_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001861 validation_error_map[VALIDATION_ERROR_09c00126]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001862 }
1863
1864 subresource_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
Dave Houlton6f9059e2017-05-02 17:15:13 -06001865 copy_extent = regions[i].extent;
1866 if (slice_override) copy_extent.depth = depth_slices;
1867 extent_check = ExceedsBounds(&(regions[i].dstOffset), &copy_extent, &subresource_extent);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001868 if (extent_check & x_bit) {
1869 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 -06001870 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0012c, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001871 "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1872 "width [%1d]. %s",
1873 i, regions[i].dstOffset.x, regions[i].extent.width, subresource_extent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001874 validation_error_map[VALIDATION_ERROR_09c0012c]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001875 }
1876 if (extent_check & y_bit) {
1877 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 -06001878 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c0012e, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001879 "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1880 "height [%1d]. %s",
1881 i, regions[i].dstOffset.y, regions[i].extent.height, subresource_extent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001882 validation_error_map[VALIDATION_ERROR_09c0012e]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001883 }
1884 if (extent_check & z_bit) {
1885 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 -06001886 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_09c00132, "IMAGE",
Dave Houltonfc1a4052017-04-27 14:32:45 -06001887 "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1888 "depth [%1d]. %s",
Dave Houlton6f9059e2017-05-02 17:15:13 -06001889 i, regions[i].dstOffset.z, copy_extent.depth, subresource_extent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001890 validation_error_map[VALIDATION_ERROR_09c00132]);
Dave Houltonfc1a4052017-04-27 14:32:45 -06001891 }
1892
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001893 // The union of all source regions, and the union of all destination regions, specified by the elements of regions,
1894 // must not overlap in memory
1895 if (src_image_state->image == dst_image_state->image) {
1896 for (uint32_t j = 0; j < region_count; j++) {
1897 if (RegionIntersects(&regions[i], &regions[j], src_image_state->createInfo.imageType)) {
1898 std::stringstream ss;
1899 ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "].";
1900 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 -06001901 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_190000f8, "IMAGE", "%s. %s",
1902 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_190000f8]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001903 }
1904 }
1905 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001906 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001907
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001908 // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes
1909 // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because
1910 // because both texels are 4 bytes in size. Depth/stencil formats must match exactly.
Dave Houlton1150cf52017-04-27 14:38:11 -06001911 if (FormatIsDepthOrStencil(src_image_state->createInfo.format) || FormatIsDepthOrStencil(dst_image_state->createInfo.format)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001912 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1913 char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats.";
Petr Krausbc7f5442017-05-14 23:43:38 +02001914 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1915 HandleToUint64(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001916 }
1917 } else {
Dave Houlton1d2022c2017-03-29 11:43:58 -06001918 size_t srcSize = FormatSize(src_image_state->createInfo.format);
1919 size_t destSize = FormatSize(dst_image_state->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001920 if (srcSize != destSize) {
1921 char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes.";
1922 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 -06001923 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_1900010e, "IMAGE", "%s. %s", str,
1924 validation_error_map[VALIDATION_ERROR_1900010e]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001925 }
1926 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001927
Dave Houlton33c22b72017-02-28 13:16:02 -07001928 // Source and dest image sample counts must match
1929 if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) {
1930 char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts.";
1931 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 -06001932 HandleToUint64(command_buffer), __LINE__, VALIDATION_ERROR_19000110, "IMAGE", "%s %s", str,
1933 validation_error_map[VALIDATION_ERROR_19000110]);
Dave Houlton33c22b72017-02-28 13:16:02 -07001934 }
1935
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001936 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_190000fe);
1937 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_19000108);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001938 // Validate that SRC & DST images have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001939 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_190000fc,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001940 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001941 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_19000106,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001942 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07001943 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001944 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_19002415);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001945 skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001946 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_19000017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06001947 bool hit_error = false;
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001948 for (uint32_t i = 0; i < region_count; ++i) {
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001949 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001950 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_19000102, &hit_error);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001951 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001952 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_1900010c, &hit_error);
Dave Houlton6f9059e2017-05-02 17:15:13 -06001953 skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, src_image_state, dst_image_state,
1954 &regions[i], i, "vkCmdCopyImage()");
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001955 }
1956
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001957 return skip;
1958}
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001959
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001960void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06001961 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1962 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
1963 // Make sure that all image slices are updated to correct layout
1964 for (uint32_t i = 0; i < region_count; ++i) {
1965 SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout);
1966 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout);
1967 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001968 // Update bindings between images and cmd buffer
1969 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1970 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Dave Houltoneba86e22017-03-02 14:56:23 -07001971 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); };
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001972 cb_node->validate_functions.push_back(function);
1973 function = [=]() {
1974 SetImageMemoryValid(device_data, dst_image_state, true);
1975 return false;
1976 };
1977 cb_node->validate_functions.push_back(function);
1978 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGE);
1979}
1980
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001981// Returns true if sub_rect is entirely contained within rect
1982static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) {
1983 if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) ||
1984 (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height))
1985 return false;
1986 return true;
1987}
1988
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001989bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
1990 const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001991 GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001992 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1993
1994 bool skip = false;
1995 if (cb_node) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06001996 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT,
1997 VALIDATION_ERROR_18602415);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001998 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001999 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002000 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
Chris Forbes05375e72017-04-21 13:15:15 -07002001 if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002002 (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
2003 // 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 -07002004 // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call
2005 // CmdClearAttachments.
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002006 skip |=
2007 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 +02002008 HandleToUint64(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002009 "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds."
2010 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
2011 commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002012 }
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002013 skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_18600017);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002014 }
2015
2016 // Validate that attachment is in reference list of active subpass
2017 if (cb_node->activeRenderPass) {
2018 const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr();
2019 const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002020 auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002021
2022 for (uint32_t i = 0; i < attachmentCount; i++) {
2023 auto clear_desc = &pAttachments[i];
2024 VkImageView image_view = VK_NULL_HANDLE;
2025
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002026 if (0 == clear_desc->aspectMask) {
2027 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 -06002028 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00c03, "IMAGE", "%s",
2029 validation_error_map[VALIDATION_ERROR_01c00c03]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002030 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
2031 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 -06002032 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00028, "IMAGE", "%s",
2033 validation_error_map[VALIDATION_ERROR_01c00028]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002034 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002035 if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002036 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2037 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1860001e, "DS",
2038 "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s",
2039 clear_desc->colorAttachment, cb_node->activeSubpass,
2040 validation_error_map[VALIDATION_ERROR_1860001e]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002041 } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) {
2042 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002043 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, HandleToUint64(commandBuffer), __LINE__,
2044 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002045 "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.",
2046 clear_desc->colorAttachment);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002047 } else {
2048 image_view = framebuffer->createInfo
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002049 .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment];
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002050 }
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002051 if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) ||
2052 (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2053 char const str[] =
2054 "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s";
2055 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 -06002056 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00026, "IMAGE", str, i,
2057 validation_error_map[VALIDATION_ERROR_01c00026]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002058 }
2059 } else { // Must be depth and/or stencil
2060 if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
2061 ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2062 char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s";
2063 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 -06002064 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_01c00c01, "IMAGE", str, i,
2065 validation_error_map[VALIDATION_ERROR_01c00c01]);
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002066 }
2067 if (!subpass_desc->pDepthStencilAttachment ||
2068 (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) {
2069 skip |= log_msg(
2070 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002071 HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002072 "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002073 } else {
2074 image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment];
2075 }
2076 }
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002077 if (image_view) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002078 auto image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002079 for (uint32_t j = 0; j < rectCount; j++) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002080 // The rectangular region specified by a given element of pRects must be contained within the render area of
2081 // the current render pass instance
Mark Lobodzinskid833bb72017-02-22 10:55:30 -07002082 // TODO: This check should be moved to CmdExecuteCommands or QueueSubmit to cover secondary CB cases
2083 if ((cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2084 (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect))) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002085 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 -06002086 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_18600020, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002087 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
2088 "the current render pass instance. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002089 j, validation_error_map[VALIDATION_ERROR_18600020]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002090 }
2091 // The layers specified by a given element of pRects must be contained within every attachment that
2092 // pAttachments refers to
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002093 auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount;
Dave Houlton8e157032017-05-22 16:16:27 -06002094 if ((pRects[j].baseArrayLayer >= attachment_layer_count) ||
2095 (pRects[j].baseArrayLayer + pRects[j].layerCount > attachment_layer_count)) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002096 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002097 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 -06002098 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_18600022, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07002099 "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of "
2100 "pAttachment[%d]. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002101 j, i, validation_error_map[VALIDATION_ERROR_18600022]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07002102 }
2103 }
2104 }
2105 }
2106 }
2107 return skip;
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002108}
2109
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002110bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002111 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) {
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002112 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002113 bool skip = false;
2114 if (cb_node && src_image_state && dst_image_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002115 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800200);
2116 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_1c800204);
2117 skip |=
2118 ValidateCmdQueueFlags(device_data, cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_1c802415);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002119 skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002120 skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_1c800017);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002121
2122 // For each region, the number of layers in the image subresource should not be zero
2123 // For each region, src and dest image aspect must be color only
2124 for (uint32_t i = 0; i < regionCount; i++) {
2125 if (pRegions[i].srcSubresource.layerCount == 0) {
2126 char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002127 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 +02002128 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002129 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002130 if (pRegions[i].dstSubresource.layerCount == 0) {
2131 char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002132 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 +02002133 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002134 }
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002135 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
2136 skip |= log_msg(
2137 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002138 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_0a200216, "IMAGE",
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002139 "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002140 validation_error_map[VALIDATION_ERROR_0a200216]);
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002141 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002142 if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
2143 (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) {
2144 char const str[] =
2145 "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT";
2146 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 -06002147 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_0a200214, "IMAGE", "%s. %s", str,
2148 validation_error_map[VALIDATION_ERROR_0a200214]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002149 }
2150 }
2151
2152 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
2153 char const str[] = "vkCmdResolveImage called with unmatched source and dest formats.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002154 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 +02002155 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002156 }
2157 if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) {
2158 char const str[] = "vkCmdResolveImage called with unmatched source and dest image types.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07002159 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 +02002160 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE", str);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002161 }
2162 if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
2163 char const str[] = "vkCmdResolveImage called with source sample count less than 2.";
2164 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 -06002165 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_1c800202, "IMAGE", "%s. %s", str,
2166 validation_error_map[VALIDATION_ERROR_1c800202]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002167 }
2168 if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
2169 char const str[] = "vkCmdResolveImage called with dest sample count greater than 1.";
2170 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 -06002171 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_1c800206, "IMAGE", "%s. %s", str,
2172 validation_error_map[VALIDATION_ERROR_1c800206]);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07002173 }
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002174 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002175 } else {
2176 assert(0);
2177 }
2178 return skip;
2179}
2180
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002181void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2182 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002183 // Update bindings between images and cmd buffer
2184 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2185 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2186
2187 std::function<bool()> function = [=]() {
2188 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()");
2189 };
2190 cb_node->validate_functions.push_back(function);
2191 function = [=]() {
2192 SetImageMemoryValid(device_data, dst_image_state, true);
2193 return false;
2194 };
2195 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002196 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002197}
2198
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002199bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002200 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2201 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2202
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002203 bool skip = false;
2204 if (cb_node && src_image_state && dst_image_state) {
2205 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002206 VALIDATION_ERROR_184001d2);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002207 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002208 VALIDATION_ERROR_184001d4);
2209 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001b8);
2210 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_184001c2);
2211 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true,
2212 VALIDATION_ERROR_184001b6, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
2213 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true,
2214 VALIDATION_ERROR_184001c0, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2215 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_18402415);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002216 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002217 skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_18400017);
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002218 // TODO: Need to validate image layouts, which will include layout validation for shared presentable images
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002219
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002220 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002221 // Warn for zero-sized regions
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002222 if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) ||
2223 (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) ||
2224 (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) {
2225 std::stringstream ss;
2226 ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area.";
2227 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 +02002228 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s",
2229 ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002230 }
2231 if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) ||
2232 (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) ||
2233 (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) {
2234 std::stringstream ss;
2235 ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area.";
2236 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Petr Krausbc7f5442017-05-14 23:43:38 +02002237 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE", "%s",
2238 ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002239 }
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002240 if (pRegions[i].srcSubresource.layerCount == 0) {
2241 char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero";
2242 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 +02002243 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002244 }
2245 if (pRegions[i].dstSubresource.layerCount == 0) {
2246 char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero";
2247 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 +02002248 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT, "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002249 }
2250
2251 // Check that src/dst layercounts match
2252 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
2253 skip |=
2254 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 -06002255 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001de, "IMAGE",
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002256 "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002257 i, validation_error_map[VALIDATION_ERROR_09a001de]);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07002258 }
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002259
2260 if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) {
2261 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 -06002262 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_09a001dc, "IMAGE",
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002263 "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002264 validation_error_map[VALIDATION_ERROR_09a001dc]);
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07002265 }
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002266 }
2267
2268 VkFormat src_format = src_image_state->createInfo.format;
2269 VkFormat dst_format = dst_image_state->createInfo.format;
2270
2271 // Validate consistency for unsigned formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06002272 if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002273 std::stringstream ss;
2274 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, "
2275 << "the other one must also have unsigned integer format. "
2276 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2277 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002278 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001cc, "IMAGE", "%s. %s",
2279 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001cc]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002280 }
2281
2282 // Validate consistency for signed formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06002283 if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002284 std::stringstream ss;
2285 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, "
2286 << "the other one must also have signed integer format. "
2287 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
2288 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 -06002289 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ca, "IMAGE", "%s. %s",
2290 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001ca]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002291 }
2292
2293 // Validate aspect bits and formats for depth/stencil images
Dave Houlton1d2022c2017-03-29 11:43:58 -06002294 if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002295 if (src_format != dst_format) {
2296 std::stringstream ss;
2297 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth "
2298 << "stencil, the other one must have exactly the same format. "
2299 << "Source format is " << string_VkFormat(src_format) << " Destination format is "
2300 << string_VkFormat(dst_format);
2301 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 -06002302 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001ce, "IMAGE", "%s. %s",
2303 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001ce]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002304 }
2305
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002306 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002307 VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask;
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002308
Dave Houlton1d2022c2017-03-29 11:43:58 -06002309 if (FormatIsDepthAndStencil(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002310 if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
2311 std::stringstream ss;
2312 ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of "
2313 "VK_IMAGE_ASPECT_DEPTH_BIT "
2314 << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage";
2315 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 +02002316 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2317 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002318 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002319 } else if (FormatIsStencilOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002320 if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) {
2321 std::stringstream ss;
2322 ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT "
2323 << "set in both the srcImage and dstImage";
2324 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 +02002325 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2326 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002327 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002328 } else if (FormatIsDepthOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002329 if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) {
2330 std::stringstream ss;
2331 ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH "
2332 << "set in both the srcImage and dstImage";
2333 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 +02002334 HandleToUint64(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
2335 "%s", ss.str().c_str());
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002336 }
2337 }
2338 }
2339 }
2340
2341 // Validate filter
Dave Houlton1d2022c2017-03-29 11:43:58 -06002342 if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002343 std::stringstream ss;
2344 ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil "
2345 << "then filter must be VK_FILTER_NEAREST.";
2346 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 -06002347 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_184001d0, "IMAGE", "%s. %s",
2348 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_184001d0]);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07002349 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002350 } else {
2351 assert(0);
2352 }
2353 return skip;
2354}
2355
Tobin Ehlis58c884f2017-02-08 12:15:27 -07002356void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
2357 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002358 // Update bindings between images and cmd buffer
2359 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
2360 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
2361
2362 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); };
2363 cb_node->validate_functions.push_back(function);
2364 function = [=]() {
2365 SetImageMemoryValid(device_data, dst_image_state, true);
2366 return false;
2367 };
2368 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002369 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002370}
2371
Tony Barbourdf013b92017-01-25 12:53:48 -07002372// This validates that the initial layout specified in the command buffer for
2373// the IMAGE is the same
2374// as the global IMAGE layout
Tony Barboure0c5cc92017-02-08 13:53:39 -07002375bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
2376 std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap) {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002377 bool skip = false;
Tony Barbourdf013b92017-01-25 12:53:48 -07002378 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002379 for (auto cb_image_data : pCB->imageLayoutMap) {
2380 VkImageLayout imageLayout;
Tony Barbourdf013b92017-01-25 12:53:48 -07002381
Jeremy Hayes55b6c292017-02-28 09:44:45 -07002382 if (FindLayout(imageLayoutMap, cb_image_data.first, imageLayout)) {
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002383 if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
2384 // TODO: Set memory invalid which is in mem_tracker currently
2385 } else if (imageLayout != cb_image_data.second.initialLayout) {
2386 if (cb_image_data.first.hasSubresource) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002387 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2388 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2389 "Cannot submit cmd buffer using image (0x%" PRIx64
2390 ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], "
2391 "with layout %s when first use is %s.",
2392 HandleToUint64(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask,
2393 cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel,
2394 string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002395 } else {
Petr Krausbc7f5442017-05-14 23:43:38 +02002396 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2397 HandleToUint64(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2398 "Cannot submit cmd buffer using image (0x%" PRIx64
2399 ") with layout %s when "
2400 "first use is %s.",
2401 HandleToUint64(cb_image_data.first.image), string_VkImageLayout(imageLayout),
2402 string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002403 }
2404 }
Tony Barbourdf013b92017-01-25 12:53:48 -07002405 SetLayout(imageLayoutMap, cb_image_data.first, cb_image_data.second.layout);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002406 }
2407 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002408 return skip;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002409}
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002410
Tony Barbourdf013b92017-01-25 12:53:48 -07002411void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) {
2412 for (auto cb_image_data : pCB->imageLayoutMap) {
2413 VkImageLayout imageLayout;
2414 FindGlobalLayout(device_data, cb_image_data.first, imageLayout);
2415 SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout);
2416 }
2417}
2418
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002419// Print readable FlagBits in FlagMask
2420static std::string string_VkAccessFlags(VkAccessFlags accessMask) {
2421 std::string result;
2422 std::string separator;
2423
2424 if (accessMask == 0) {
2425 result = "[None]";
2426 } else {
2427 result = "[";
2428 for (auto i = 0; i < 32; i++) {
2429 if (accessMask & (1 << i)) {
2430 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
2431 separator = " | ";
2432 }
2433 }
2434 result = result + "]";
2435 }
2436 return result;
2437}
2438
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002439// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask
2440// must have at least one of 'optional_bits' set
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002441// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002442static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask,
2443 const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits,
2444 const char *type) {
2445 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2446 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002447
2448 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
2449 if (accessMask & ~(required_bit | optional_bits)) {
2450 // TODO: Verify against Valid Use
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002451 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 +02002452 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002453 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2454 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002455 }
2456 } else {
2457 if (!required_bit) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002458 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 +02002459 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002460 "%s AccessMask %d %s must contain at least one of access bits %d "
2461 "%s when layout is %s, unless the app has previously added a "
2462 "barrier for this transition.",
2463 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
2464 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002465 } else {
2466 std::string opt_bits;
2467 if (optional_bits != 0) {
2468 std::stringstream ss;
2469 ss << optional_bits;
2470 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
2471 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002472 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 +02002473 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002474 "%s AccessMask %d %s must have required access bit %d %s %s when "
2475 "layout is %s, unless the app has previously added a barrier for "
2476 "this transition.",
2477 type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit,
2478 string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002479 }
2480 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002481 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002482}
2483
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002484bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer,
2485 const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) {
2486 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002487
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002488 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002489 switch (layout) {
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002490 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
2491 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2492 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2493 break;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002494 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002495 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
2496 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
2497 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2498 break;
2499 }
2500 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
2501 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
2502 break;
2503 }
2504 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
2505 skip |= ValidateMaskBits(
2506 device_data, cmdBuffer, accessMask, layout, 0,
2507 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
2508 type);
2509 break;
2510 }
2511 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
2512 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0,
2513 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
2514 break;
2515 }
2516 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
2517 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
2518 break;
2519 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002520 case VK_IMAGE_LAYOUT_UNDEFINED: {
2521 if (accessMask != 0) {
2522 // TODO: Verify against Valid Use section spec
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002523 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 +02002524 HandleToUint64(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002525 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2526 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
2527 }
2528 break;
2529 }
Chris Forbesbfd831d2017-04-28 17:29:10 -07002530 case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
Dave Houlton1150cf52017-04-27 14:38:11 -06002531 // Notes: QueuePresentKHR performs automatic visibility operations,
2532 // so the app is /NOT/ required to include VK_ACCESS_MEMORY_READ_BIT
2533 // when transitioning to this layout.
2534 //
2535 // When transitioning /from/ this layout, the application needs to
2536 // avoid only a WAR hazard -- any writes need to be ordered after
2537 // the PE's reads. There is no need for a memory dependency for this
2538 // case.
Mark Lobodzinski087380c2017-05-16 14:42:25 -06002539 // Intentionally fall through
2540
2541 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2542 // Todo -- shouldn't be valid unless extension is enabled
2543 // Intentionally fall through
Chris Forbesbfd831d2017-04-28 17:29:10 -07002544
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002545 case VK_IMAGE_LAYOUT_GENERAL:
2546 default: { break; }
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002547 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002548 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002549}
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002550
2551// ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002552// VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY
2553// layout attachments don't have CLEAR as their loadOp.
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002554bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002555 const uint32_t attachment, const VkAttachmentDescription &attachment_description) {
2556 bool skip = false;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002557 // Verify that initial loadOp on READ_ONLY attachments is not CLEAR
2558 if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2559 if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) ||
2560 (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) {
Mark Lobodzinskieb9e73f2017-04-13 10:06:48 -06002561 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 -06002562 VALIDATION_ERROR_12200688, "DS", "Cannot clear attachment %d with invalid first layout %s. %s",
2563 attachment, string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_12200688]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002564 }
2565 }
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002566 return skip;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002567}
2568
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002569bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) {
2570 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002571 bool skip = false;
2572
2573 // Track when we're observing the first use of an attachment
2574 std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true);
2575 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2576 const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i];
Cort Stratton7547f772017-05-04 15:18:52 -07002577
2578 // Check input attachments first, so we can detect first-use-as-input for VU #00349
2579 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
2580 auto attach_index = subpass.pInputAttachments[j].attachment;
2581 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2582
2583 switch (subpass.pInputAttachments[j].layout) {
2584 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2585 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
2586 // These are ideal.
2587 break;
2588
2589 case VK_IMAGE_LAYOUT_GENERAL:
2590 // May not be optimal. TODO: reconsider this warning based on other constraints.
2591 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2592 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2593 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
2594 break;
2595
2596 default:
2597 // No other layouts are acceptable
2598 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2599 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2600 "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.",
2601 string_VkImageLayout(subpass.pInputAttachments[j].layout));
2602 }
2603
2604 VkImageLayout layout = subpass.pInputAttachments[j].layout;
2605 bool found_layout_mismatch = subpass.pDepthStencilAttachment &&
2606 subpass.pDepthStencilAttachment->attachment == attach_index &&
2607 subpass.pDepthStencilAttachment->layout != layout;
2608 for (uint32_t c = 0; !found_layout_mismatch && c < subpass.colorAttachmentCount; ++c) {
2609 found_layout_mismatch =
2610 (subpass.pColorAttachments[c].attachment == attach_index && subpass.pColorAttachments[c].layout != layout);
2611 }
2612 if (found_layout_mismatch) {
2613 skip |= log_msg(
2614 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002615 VALIDATION_ERROR_140006ae, "DS",
Cort Stratton7547f772017-05-04 15:18:52 -07002616 "CreateRenderPass: Subpass %u pInputAttachments[%u] (%u) has layout %u, but is also used as a depth/color "
2617 "attachment with a different layout. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002618 i, j, attach_index, layout, validation_error_map[VALIDATION_ERROR_140006ae]);
Cort Stratton7547f772017-05-04 15:18:52 -07002619 }
2620
2621 if (attach_first_use[attach_index]) {
2622 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index,
2623 pCreateInfo->pAttachments[attach_index]);
2624
2625 bool used_as_depth =
2626 (subpass.pDepthStencilAttachment != NULL && subpass.pDepthStencilAttachment->attachment == attach_index);
2627 bool used_as_color = false;
2628 for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) {
2629 used_as_color = (subpass.pColorAttachments[k].attachment == attach_index);
2630 }
2631 if (!used_as_depth && !used_as_color &&
2632 pCreateInfo->pAttachments[attach_index].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2633 skip |= log_msg(
2634 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002635 VALIDATION_ERROR_1400069c, "DS",
Cort Stratton7547f772017-05-04 15:18:52 -07002636 "CreateRenderPass: attachment %u is first used as an input attachment in subpass %u with loadOp=CLEAR. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002637 attach_index, attach_index, validation_error_map[VALIDATION_ERROR_1400069c]);
Cort Stratton7547f772017-05-04 15:18:52 -07002638 }
2639 }
2640 attach_first_use[attach_index] = false;
2641 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002642 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
2643 auto attach_index = subpass.pColorAttachments[j].attachment;
2644 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2645
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002646 // TODO: Need a way to validate shared presentable images here, currently just allowing
2647 // VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR
2648 // as an acceptable layout, but need to make sure shared presentable images ONLY use that layout
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002649 switch (subpass.pColorAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002650 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2651 // This is ideal.
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06002652 case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR:
2653 // TODO: See note above, just assuming that attachment is shared presentable and allowing this for now.
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002654 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002655
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002656 case VK_IMAGE_LAYOUT_GENERAL:
2657 // May not be optimal; TODO: reconsider this warning based on other constraints?
2658 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2659 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2660 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
2661 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002662
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002663 default:
2664 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2665 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2666 "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.",
2667 string_VkImageLayout(subpass.pColorAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002668 }
2669
2670 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002671 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index,
2672 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002673 }
2674 attach_first_use[attach_index] = false;
2675 }
2676 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
2677 switch (subpass.pDepthStencilAttachment->layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002678 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2679 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2680 // These are ideal.
2681 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002682
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002683 case VK_IMAGE_LAYOUT_GENERAL:
2684 // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than
2685 // doing a bunch of transitions.
2686 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2687 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2688 "GENERAL layout for depth attachment may not give optimal performance.");
2689 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002690
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002691 default:
2692 // No other layouts are acceptable
2693 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2694 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2695 "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "
2696 "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.",
2697 string_VkImageLayout(subpass.pDepthStencilAttachment->layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002698 }
2699
2700 auto attach_index = subpass.pDepthStencilAttachment->attachment;
2701 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002702 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index,
2703 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002704 }
2705 attach_first_use[attach_index] = false;
2706 }
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002707 }
2708 return skip;
2709}
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002710
2711// For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002712bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info,
2713 VkDeviceSize offset, VkDeviceSize end_offset) {
2714 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2715 bool skip = false;
2716 // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are
2717 // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002718 // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range
2719 for (auto image_handle : mem_info->bound_images) {
2720 auto img_it = mem_info->bound_ranges.find(image_handle);
2721 if (img_it != mem_info->bound_ranges.end()) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002722 if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002723 std::vector<VkImageLayout> layouts;
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002724 if (FindLayouts(device_data, VkImage(image_handle), layouts)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002725 for (auto layout : layouts) {
2726 if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002727 skip |=
2728 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
2729 HandleToUint64(mem_info->mem), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2730 "Mapping an image with layout %s can result in undefined behavior if this memory is "
2731 "used by the device. Only GENERAL or PREINITIALIZED should be used.",
2732 string_VkImageLayout(layout));
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002733 }
2734 }
2735 }
2736 }
2737 }
2738 }
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002739 return skip;
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002740}
Mark Lobodzinski96210742017-02-09 10:33:46 -07002741
2742// Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict
2743// is true, verify that (actual & desired) flags == desired
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002744static 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 -06002745 VulkanObjectType obj_type, int32_t const msgCode, char const *func_name, char const *usage_str) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002746 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002747
2748 bool correct_usage = false;
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002749 bool skip = false;
Mark Lobodzinski33826372017-04-13 11:10:11 -06002750 const char *type_str = object_string[obj_type];
Mark Lobodzinski96210742017-02-09 10:33:46 -07002751 if (strict) {
2752 correct_usage = ((actual & desired) == desired);
2753 } else {
2754 correct_usage = ((actual & desired) != 0);
2755 }
2756 if (!correct_usage) {
2757 if (msgCode == -1) {
2758 // TODO: Fix callers with msgCode == -1 to use correct validation checks.
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002759 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 -06002760 MEMTRACK_INVALID_USAGE_FLAG, "MEM",
2761 "Invalid usage flag for %s 0x%" PRIxLEAST64
2762 " used by %s. In this case, %s should have %s set during creation.",
2763 type_str, obj_handle, func_name, type_str, usage_str);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002764 } else {
2765 const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode];
Mark Lobodzinski33826372017-04-13 11:10:11 -06002766 skip = log_msg(
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002767 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 -06002768 "Invalid usage flag for %s 0x%" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation. %s",
2769 type_str, obj_handle, func_name, type_str, usage_str, valid_usage);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002770 }
2771 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002772 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002773}
2774
2775// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2776// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002777bool ValidateImageUsageFlags(layer_data *device_data, IMAGE_STATE const *image_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002778 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002779 return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict, HandleToUint64(image_state->image),
2780 kVulkanObjectTypeImage, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002781}
2782
2783// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2784// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002785bool ValidateBufferUsageFlags(layer_data *device_data, BUFFER_STATE const *buffer_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002786 int32_t const msgCode, char const *func_name, char const *usage_string) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002787 return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict, HandleToUint64(buffer_state->buffer),
2788 kVulkanObjectTypeBuffer, msgCode, func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002789}
2790
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002791bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) {
Mark Lobodzinski96210742017-02-09 10:33:46 -07002792 bool skip = false;
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002793 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2794
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002795 // TODO: Add check for VALIDATION_ERROR_1ec0071e
2796 // TODO: Add check for VALIDATION_ERROR_01400728
2797 // TODO: Add check for VALIDATION_ERROR_0140072a
2798 // TODO: Add check for VALIDATION_ERROR_0140072c
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002799
2800 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
2801 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 -06002802 VALIDATION_ERROR_01400726, "DS",
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002803 "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
2804 "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002805 validation_error_map[VALIDATION_ERROR_01400726]);
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002806 }
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06002807
2808 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) {
2809 skip |=
2810 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2811 DRAWSTATE_INVALID_FEATURE, "DS",
2812 "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with the "
2813 "VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set.");
2814 }
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06002815
2816 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
2817 skip |=
2818 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2819 DRAWSTATE_INVALID_FEATURE, "DS",
2820 "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with the "
2821 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set.");
2822 }
Mark Lobodzinski96210742017-02-09 10:33:46 -07002823 return skip;
2824}
2825
2826void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) {
2827 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
2828 GetBufferMap(device_data)
2829 ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo))));
2830}
2831
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002832bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) {
2833 bool skip = false;
2834 BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002835 // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time
2836 if (buffer_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002837 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_01a0074e);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002838 // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags:
2839 // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002840 skip |= ValidateBufferUsageFlags(
2841 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 -06002842 VALIDATION_ERROR_01a00748, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT");
Mark Lobodzinski96210742017-02-09 10:33:46 -07002843 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002844 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002845}
2846
2847void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) {
2848 (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo));
2849}
Mark Lobodzinski602de982017-02-09 11:01:33 -07002850
2851// For the given format verify that the aspect masks make sense
2852bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
2853 const char *func_name) {
2854 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2855 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06002856 if (FormatIsColor(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002857 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002858 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 -06002859 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002860 "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002861 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002862 } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002863 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 -06002864 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002865 "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002866 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002867 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002868 } else if (FormatIsDepthAndStencil(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002869 if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002870 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 -06002871 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002872 "%s: Depth/stencil image formats must have "
2873 "at least one of VK_IMAGE_ASPECT_DEPTH_BIT "
2874 "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002875 func_name, validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002876 } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002877 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 -06002878 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002879 "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and "
2880 "VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002881 func_name, validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002882 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002883 } else if (FormatIsDepthOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002884 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002885 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 -06002886 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002887 "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002888 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002889 } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002890 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 -06002891 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002892 "%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 -06002893 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002894 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002895 } else if (FormatIsStencilOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002896 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002897 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 -06002898 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002899 "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002900 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002901 } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) {
Petr Krausbc7f5442017-05-14 23:43:38 +02002902 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 -06002903 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mark Lobodzinski602de982017-02-09 11:01:33 -07002904 "%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 -06002905 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002906 }
2907 }
2908 return skip;
2909}
2910
Petr Kraus4d718682017-05-18 03:38:41 +02002911bool ValidateImageSubresourceRange(const layer_data *device_data, const IMAGE_STATE *image_state,
2912 const VkImageViewCreateInfo *image_view_create_info,
2913 const VkImageSubresourceRange &subresourceRange, const char *cmd_name, const char *param_name) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002914 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2915 bool skip = false;
Petr Kraus4d718682017-05-18 03:38:41 +02002916
2917 // Validate mip levels
2918 const auto image_mip_count = image_state->createInfo.mipLevels;
2919
Mark Lobodzinski602de982017-02-09 11:01:33 -07002920 if (subresourceRange.levelCount == 0) {
Petr Kraus4d718682017-05-18 03:38:41 +02002921 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 -06002922 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0a8007fc, "IMAGE",
2923 "%s: %s.levelCount is 0. %s", cmd_name, param_name, validation_error_map[VALIDATION_ERROR_0a8007fc]);
Petr Kraus4d718682017-05-18 03:38:41 +02002924 } else if (subresourceRange.levelCount == VK_REMAINING_MIP_LEVELS) {
2925 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#416
2926 if (subresourceRange.baseMipLevel >= image_mip_count) {
2927 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2928 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_SUBRANGE, "IMAGE",
2929 "%s: %s.baseMipLevel (= %" PRIu32 ") is greater or equal to the mip level count of the image (i.e. "
2930 "greater or equal to %" PRIu32 ").",
2931 cmd_name, param_name, subresourceRange.baseMipLevel, image_mip_count);
2932 }
2933 } else {
2934 const uint64_t necessary_mip_count = uint64_t{subresourceRange.baseMipLevel} + uint64_t{subresourceRange.levelCount};
2935
2936 if (necessary_mip_count > image_mip_count) {
2937 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 -06002938 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0a8007fc, "IMAGE",
2939 "%s: %s.baseMipLevel + .levelCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64
2940 ") is greater than the "
Petr Kraus4d718682017-05-18 03:38:41 +02002941 "mip level count of the image (i.e. greater than %" PRIu32 "). %s",
2942 cmd_name, param_name, subresourceRange.baseMipLevel, subresourceRange.levelCount, necessary_mip_count,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002943 image_mip_count, validation_error_map[VALIDATION_ERROR_0a8007fc]);
Petr Kraus4d718682017-05-18 03:38:41 +02002944 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07002945 }
Petr Kraus4d718682017-05-18 03:38:41 +02002946
2947 // Validate array layers
2948 bool is_3D_to_2D_map = image_view_create_info && GetDeviceExtensions(device_data)->khr_maintenance1 &&
2949 image_state->createInfo.imageType == VK_IMAGE_TYPE_3D &&
2950 image_view_create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY;
2951
2952 const auto image_layer_count = is_3D_to_2D_map ? image_state->createInfo.extent.depth : image_state->createInfo.arrayLayers;
2953 const auto image_layer_count_var_name = is_3D_to_2D_map ? "extent.depth" : "arrayLayers";
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002954 const auto invalid_layer_code = is_3D_to_2D_map ? VALIDATION_ERROR_0a800800 : VALIDATION_ERROR_0a800802;
Petr Kraus4d718682017-05-18 03:38:41 +02002955
Mark Lobodzinski602de982017-02-09 11:01:33 -07002956 if (subresourceRange.layerCount == 0) {
Petr Kraus4d718682017-05-18 03:38:41 +02002957 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2958 HandleToUint64(image_state->image), __LINE__, invalid_layer_code, "IMAGE", "%s: %s.layerCount is 0. %s",
2959 cmd_name, param_name, validation_error_map[invalid_layer_code]);
2960 } else if (subresourceRange.layerCount == VK_REMAINING_ARRAY_LAYERS) {
2961 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#416
2962 if (subresourceRange.baseArrayLayer >= image_layer_count) {
2963 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2964 HandleToUint64(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_SUBRANGE, "IMAGE",
2965 "%s: %s.baseArrayLayer (= %" PRIu32 ") is greater or equal to the %s of the image when it was created "
2966 "(i.e. greater or equal to %" PRIu32 ").",
2967 cmd_name, param_name, subresourceRange.baseArrayLayer, image_layer_count_var_name, image_layer_count);
2968 }
2969 } else {
2970 const uint64_t necessary_layer_count = uint64_t{subresourceRange.baseArrayLayer} + uint64_t{subresourceRange.layerCount};
2971
2972 if (necessary_layer_count > image_layer_count) {
2973 skip |=
2974 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2975 HandleToUint64(image_state->image), __LINE__, invalid_layer_code, "IMAGE",
2976 "%s: %s.baseArrayLayer + .layerCount (= %" PRIu32 " + %" PRIu32 " = %" PRIu64 ") is greater than the "
2977 "%s of the image when it was created (i.e. greater than %" PRIu32 "). %s",
2978 cmd_name, param_name, subresourceRange.baseArrayLayer, subresourceRange.layerCount, necessary_layer_count,
2979 image_layer_count_var_name, image_layer_count, validation_error_map[invalid_layer_code]);
2980 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07002981 }
Petr Kraus4d718682017-05-18 03:38:41 +02002982
Mark Lobodzinski602de982017-02-09 11:01:33 -07002983 return skip;
2984}
2985
2986bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) {
2987 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2988 bool skip = false;
2989 IMAGE_STATE *image_state = GetImageState(device_data, create_info->image);
2990 if (image_state) {
2991 skip |= ValidateImageUsageFlags(
2992 device_data, image_state,
2993 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
2994 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2995 false, -1, "vkCreateImageView()",
2996 "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT");
2997 // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06002998 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_0ac007f8);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002999 // Checks imported from image layer
Petr Kraus4d718682017-05-18 03:38:41 +02003000 skip |= ValidateImageSubresourceRange(device_data, image_state, create_info, create_info->subresourceRange,
3001 "vkCreateImageView", "pCreateInfo->subresourceRange");
Mark Lobodzinski602de982017-02-09 11:01:33 -07003002
3003 VkImageCreateFlags image_flags = image_state->createInfo.flags;
3004 VkFormat image_format = image_state->createInfo.format;
3005 VkFormat view_format = create_info->format;
3006 VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask;
3007
3008 // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
3009 if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
3010 // 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 -06003011 if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07003012 std::stringstream ss;
3013 ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format)
Petr Krausbc7f5442017-05-14 23:43:38 +02003014 << " is not in the same format compatibility class as image (" << HandleToUint64(create_info->image)
3015 << ") format " << string_VkFormat(image_format)
3016 << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
Mark Lobodzinski602de982017-02-09 11:01:33 -07003017 << "can support ImageViews with differing formats but they must be in the same compatibility class.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003018 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 -06003019 VALIDATION_ERROR_0ac007f4, "IMAGE", "%s %s", ss.str().c_str(),
3020 validation_error_map[VALIDATION_ERROR_0ac007f4]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003021 }
3022 } else {
3023 // Format MUST be IDENTICAL to the format the image was created with
3024 if (image_format != view_format) {
3025 std::stringstream ss;
3026 ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image "
Petr Krausbc7f5442017-05-14 23:43:38 +02003027 << HandleToUint64(create_info->image) << " format " << string_VkFormat(image_format)
Mark Lobodzinski602de982017-02-09 11:01:33 -07003028 << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003029 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 -06003030 VALIDATION_ERROR_0ac007f6, "IMAGE", "%s %s", ss.str().c_str(),
3031 validation_error_map[VALIDATION_ERROR_0ac007f6]);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003032 }
3033 }
3034
3035 // Validate correct image aspect bits for desired formats and format consistency
3036 skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
3037 }
3038 return skip;
3039}
3040
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -07003041void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) {
3042 auto image_view_map = GetImageViewMap(device_data);
3043 (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info));
3044
3045 auto image_state = GetImageState(device_data, create_info->image);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003046 auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06003047 sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels);
3048 sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers);
Mark Lobodzinski602de982017-02-09 11:01:33 -07003049}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003050
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003051bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3052 BUFFER_STATE *dst_buffer_state) {
3053 bool skip = false;
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003054 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000ee);
3055 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c000f2);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003056 // Validate that SRC & DST buffers have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003057 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true,
3058 VALIDATION_ERROR_18c000ec, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3059 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
3060 VALIDATION_ERROR_18c000f0, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07003061 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003062 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_18c02415);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003063 skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003064 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_18c00017);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003065 return skip;
3066}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07003067
Mark Lobodzinski680421d2017-02-09 13:06:56 -07003068void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
3069 BUFFER_STATE *dst_buffer_state) {
3070 // Update bindings between buffers and cmd buffer
3071 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
3072 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
3073
3074 std::function<bool()> function = [=]() {
3075 return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()");
3076 };
3077 cb_node->validate_functions.push_back(function);
3078 function = [=]() {
3079 SetBufferMemoryValid(device_data, dst_buffer_state, true);
3080 return false;
3081 };
3082 cb_node->validate_functions.push_back(function);
3083 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFER);
3084}
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003085
3086static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) {
3087 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3088 bool skip = false;
3089 auto buffer_state = GetBufferState(device_data, buffer);
3090 if (!buffer_state) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003091 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 -07003092 __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Petr Krausbc7f5442017-05-14 23:43:38 +02003093 "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", HandleToUint64(buffer));
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003094 } else {
3095 if (buffer_state->in_use.load()) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003096 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 -06003097 HandleToUint64(buffer), __LINE__, VALIDATION_ERROR_23c00734, "DS",
Petr Krausbc7f5442017-05-14 23:43:38 +02003098 "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", HandleToUint64(buffer),
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003099 validation_error_map[VALIDATION_ERROR_23c00734]);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003100 }
3101 }
3102 return skip;
3103}
3104
3105bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state,
3106 VK_OBJECT *obj_struct) {
3107 *image_view_state = GetImageViewState(device_data, image_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003108 *obj_struct = {HandleToUint64(image_view), kVulkanObjectTypeImageView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003109 if (GetDisables(device_data)->destroy_image_view) return false;
3110 bool skip = false;
3111 if (*image_view_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003112 skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_25400804);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003113 }
3114 return skip;
3115}
3116
3117void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state,
3118 VK_OBJECT obj_struct) {
3119 // Any bound cmd buffers are now invalid
3120 invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct);
3121 (*GetImageViewMap(device_data)).erase(image_view);
3122}
3123
3124bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) {
3125 *buffer_state = GetBufferState(device_data, buffer);
Petr Krausbc7f5442017-05-14 23:43:38 +02003126 *obj_struct = {HandleToUint64(buffer), kVulkanObjectTypeBuffer};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003127 if (GetDisables(device_data)->destroy_buffer) return false;
3128 bool skip = false;
3129 if (*buffer_state) {
3130 skip |= validateIdleBuffer(device_data, buffer);
3131 }
3132 return skip;
3133}
3134
3135void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) {
3136 invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct);
3137 for (auto mem_binding : buffer_state->GetBoundMemory()) {
3138 auto mem_info = GetMemObjInfo(device_data, mem_binding);
3139 if (mem_info) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003140 core_validation::RemoveBufferMemoryRange(HandleToUint64(buffer), mem_info);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003141 }
3142 }
Petr Krausbc7f5442017-05-14 23:43:38 +02003143 ClearMemoryObjectBindings(device_data, HandleToUint64(buffer), kVulkanObjectTypeBuffer);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003144 GetBufferMap(device_data)->erase(buffer_state->buffer);
3145}
3146
3147bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
3148 VK_OBJECT *obj_struct) {
3149 *buffer_view_state = GetBufferViewState(device_data, buffer_view);
Petr Krausbc7f5442017-05-14 23:43:38 +02003150 *obj_struct = {HandleToUint64(buffer_view), kVulkanObjectTypeBufferView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003151 if (GetDisables(device_data)->destroy_buffer_view) return false;
3152 bool skip = false;
3153 if (*buffer_view_state) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003154 skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_23e00750);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07003155 }
3156 return skip;
3157}
3158
3159void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
3160 VK_OBJECT obj_struct) {
3161 // Any bound cmd buffers are now invalid
3162 invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct);
3163 GetBufferViewMap(device_data)->erase(buffer_view);
3164}
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003165
3166bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3167 bool skip = false;
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003168 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_1b40003e);
Mike Schuchardt9c582402017-02-23 15:57:37 -07003169 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003170 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_1b402415);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003171 skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()");
3172 // Validate that DST buffer has correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003173 skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_1b40003a,
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003174 "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003175 skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_1b400017);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07003176 return skip;
3177}
3178
3179void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
3180 std::function<bool()> function = [=]() {
3181 SetBufferMemoryValid(device_data, buffer_state, true);
3182 return false;
3183 };
3184 cb_node->validate_functions.push_back(function);
3185 // Update bindings between buffer and cmd buffer
3186 AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state);
3187 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER);
3188}
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003189
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003190bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions,
3191 IMAGE_STATE *image_state, const char *function) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003192 bool skip = false;
3193
3194 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003195 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
3196 if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003197 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 -06003198 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160018e, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003199 "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these "
3200 "must be 0 and 1, respectively. %s",
3201 function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003202 validation_error_map[VALIDATION_ERROR_0160018e]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003203 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003204 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003205
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003206 if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
3207 if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003208 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 -06003209 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600192, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003210 "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these "
3211 "must be 0 and 1, respectively. %s",
3212 function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003213 validation_error_map[VALIDATION_ERROR_01600192]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003214 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003215 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003216
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003217 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
3218 if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) {
3219 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 -06003220 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001aa, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003221 "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is "
3222 "%d. For 3D images these must be 0 and 1, respectively. %s",
3223 function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003224 validation_error_map[VALIDATION_ERROR_016001aa]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003225 }
3226 }
3227
3228 // If the the calling command's VkImage parameter's format is not a depth/stencil format,
3229 // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size
Dave Houlton1d2022c2017-03-29 11:43:58 -06003230 auto texel_size = FormatSize(image_state->createInfo.format);
Dave Houlton1150cf52017-04-27 14:38:11 -06003231 if (!FormatIsDepthAndStencil(image_state->createInfo.format) && SafeModulo(pRegions[i].bufferOffset, texel_size) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003232 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 -06003233 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600182, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003234 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64
3235 " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003236 function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01600182]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003237 }
3238
3239 // BufferOffset must be a multiple of 4
Dave Houlton1d2022c2017-03-29 11:43:58 -06003240 if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003241 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 -06003242 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600184, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003243 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003244 pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01600184]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003245 }
3246
3247 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
3248 if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) {
3249 skip |= log_msg(
3250 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003251 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600186, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003252 "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s",
3253 function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003254 validation_error_map[VALIDATION_ERROR_01600186]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003255 }
3256
3257 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
3258 if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) {
3259 skip |= log_msg(
3260 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003261 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600188, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003262 "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s",
3263 function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003264 validation_error_map[VALIDATION_ERROR_01600188]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003265 }
3266
3267 // subresource aspectMask must have exactly 1 bit set
3268 const int num_bits = sizeof(VkFlags) * CHAR_BIT;
3269 std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask);
3270 if (aspect_mask_bits.count() != 1) {
3271 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 -06003272 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a8, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003273 "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003274 validation_error_map[VALIDATION_ERROR_016001a8]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003275 }
3276
3277 // image subresource aspect bit must match format
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06003278 if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003279 skip |= log_msg(
3280 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003281 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a6, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003282 "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x. %s",
3283 function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003284 validation_error_map[VALIDATION_ERROR_016001a6]);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003285 }
3286
3287 // Checks that apply only to compressed images
3288 // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that
3289 // reserves a place for these compressed image checks. This block of code could move there once the image
3290 // stuff is moved into core validation.
Dave Houlton1d2022c2017-03-29 11:43:58 -06003291 if (FormatIsCompressed(image_state->createInfo.format)) {
3292 auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003293
3294 // BufferRowLength must be a multiple of block width
Dave Houlton1d2022c2017-03-29 11:43:58 -06003295 if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003296 skip |= log_msg(
3297 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003298 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600196, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003299 "%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 -06003300 function, i, pRegions[i].bufferRowLength, block_size.width, validation_error_map[VALIDATION_ERROR_01600196]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003301 }
3302
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003303 // BufferRowHeight must be a multiple of block height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003304 if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003305 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 -06003306 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_01600198, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003307 "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel "
3308 "height (%d). %s.",
3309 function, i, pRegions[i].bufferImageHeight, block_size.height,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003310 validation_error_map[VALIDATION_ERROR_01600198]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003311 }
3312
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003313 // image offsets must be multiples of block dimensions
Dave Houlton1d2022c2017-03-29 11:43:58 -06003314 if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) ||
3315 (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) ||
3316 (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003317 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 -06003318 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019a, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003319 "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel "
3320 "width & height (%d, %d). %s.",
3321 function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003322 block_size.height, validation_error_map[VALIDATION_ERROR_0160019a]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003323 }
3324
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003325 // bufferOffset must be a multiple of block size (linear bytes)
Dave Houlton1d2022c2017-03-29 11:43:58 -06003326 size_t block_size_in_bytes = FormatSize(image_state->createInfo.format);
3327 if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003328 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 -06003329 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019c, "IMAGE",
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003330 "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64
3331 ") must be a multiple of the compressed image's texel block "
3332 "size (" PRINTF_SIZE_T_SPECIFIER "). %s.",
3333 function, i, pRegions[i].bufferOffset, block_size_in_bytes,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003334 validation_error_map[VALIDATION_ERROR_0160019c]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003335 }
Dave Houlton67e9b532017-03-02 17:00:10 -07003336
3337 // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width
Dave Houlton75967fc2017-03-06 17:21:16 -07003338 VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
Dave Houlton1d2022c2017-03-29 11:43:58 -06003339 if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003340 (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) {
3341 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 -06003342 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_0160019e, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003343 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width "
3344 "(%d), or when added to offset.x (%d) must equal the image subresource width (%d). %s.",
3345 function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003346 mip_extent.width, validation_error_map[VALIDATION_ERROR_0160019e]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003347 }
3348
3349 // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height
Dave Houlton1d2022c2017-03-29 11:43:58 -06003350 if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003351 (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) {
3352 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 -06003353 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a0, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003354 "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height "
3355 "(%d), or when added to offset.y (%d) must equal the image subresource height (%d). %s.",
3356 function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003357 mip_extent.height, validation_error_map[VALIDATION_ERROR_016001a0]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003358 }
3359
3360 // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
Dave Houlton1d2022c2017-03-29 11:43:58 -06003361 if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07003362 (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) {
3363 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 -06003364 HandleToUint64(image_state->image), __LINE__, VALIDATION_ERROR_016001a2, "IMAGE",
Dave Houlton75967fc2017-03-06 17:21:16 -07003365 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth "
3366 "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d). %s.",
3367 function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z,
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003368 mip_extent.depth, validation_error_map[VALIDATION_ERROR_016001a2]);
Dave Houlton67e9b532017-03-02 17:00:10 -07003369 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003370 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003371 }
3372
3373 return skip;
3374}
3375
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003376static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount,
3377 const VkBufferImageCopy *pRegions, const char *func_name, UNIQUE_VALIDATION_ERROR_CODE msg_code) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003378 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003379 const VkImageCreateInfo *image_info = &(image_state->createInfo);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003380
3381 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003382 VkExtent3D extent = pRegions[i].imageExtent;
3383 VkOffset3D offset = pRegions[i].imageOffset;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003384
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003385 if (IsExtentSizeZero(&extent)) // Warn on zero area subresource
3386 {
3387 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3388 (uint64_t)0, __LINE__, IMAGE_ZERO_AREA_SUBREGION, "IMAGE",
3389 "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", func_name, i, extent.width,
3390 extent.height, extent.depth);
3391 }
3392
3393 VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
3394
3395 // 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 -06003396 if (FormatIsCompressed(image_info->format)) {
3397 auto block_extent = FormatCompressedTexelBlockExtent(image_info->format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003398 if (image_extent.width % block_extent.width) {
3399 image_extent.width += (block_extent.width - (image_extent.width % block_extent.width));
3400 }
3401 if (image_extent.height % block_extent.height) {
3402 image_extent.height += (block_extent.height - (image_extent.height % block_extent.height));
3403 }
3404 if (image_extent.depth % block_extent.depth) {
3405 image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth));
3406 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003407 }
3408
Dave Houltonfc1a4052017-04-27 14:32:45 -06003409 if (0 != ExceedsBounds(&offset, &extent, &image_extent)) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003410 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 -07003411 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds image bounds. %s.", func_name, i,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003412 validation_error_map[msg_code]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003413 }
3414 }
3415
3416 return skip;
3417}
3418
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003419static inline bool ValidtateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state,
3420 uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name,
3421 UNIQUE_VALIDATION_ERROR_CODE msg_code) {
3422 bool skip = false;
3423
3424 VkDeviceSize buffer_size = buff_state->createInfo.size;
3425
3426 for (uint32_t i = 0; i < regionCount; i++) {
3427 VkExtent3D copy_extent = pRegions[i].imageExtent;
3428
3429 VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength);
3430 VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight);
Dave Houlton1d2022c2017-03-29 11:43:58 -06003431 VkDeviceSize unit_size = FormatSize(image_state->createInfo.format); // size (bytes) of texel or block
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003432
Dave Houltonf3229d52017-02-21 15:59:08 -07003433 // Handle special buffer packing rules for specific depth/stencil formats
3434 if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
Dave Houlton1d2022c2017-03-29 11:43:58 -06003435 unit_size = FormatSize(VK_FORMAT_S8_UINT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003436 } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
3437 switch (image_state->createInfo.format) {
3438 case VK_FORMAT_D16_UNORM_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003439 unit_size = FormatSize(VK_FORMAT_D16_UNORM);
Dave Houltonf3229d52017-02-21 15:59:08 -07003440 break;
3441 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003442 unit_size = FormatSize(VK_FORMAT_D32_SFLOAT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003443 break;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003444 case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through
Dave Houltonf3229d52017-02-21 15:59:08 -07003445 case VK_FORMAT_D24_UNORM_S8_UINT:
3446 unit_size = 4;
3447 break;
3448 default:
3449 break;
3450 }
3451 }
3452
Dave Houlton1d2022c2017-03-29 11:43:58 -06003453 if (FormatIsCompressed(image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003454 // Switch to texel block units, rounding up for any partially-used blocks
Dave Houlton1d2022c2017-03-29 11:43:58 -06003455 auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003456 buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width;
3457 buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height;
3458
3459 copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width;
3460 copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height;
3461 copy_extent.depth = (copy_extent.depth + block_dim.depth - 1) / block_dim.depth;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003462 }
3463
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003464 // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy
3465 uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount);
3466 if (IsExtentSizeZero(&copy_extent) || (0 == z_copies)) {
3467 // TODO: Issure warning here? Already warned in ValidateImageBounds()...
3468 } else {
3469 // Calculate buffer offset of final copied byte, + 1.
3470 VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice
3471 max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col
3472 max_buffer_offset *= unit_size; // convert to bytes
3473 max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes)
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003474
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003475 if (buffer_size < max_buffer_offset) {
3476 skip |=
3477 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
3478 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes. %s.", func_name,
3479 i, buffer_size, validation_error_map[msg_code]);
3480 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003481 }
3482 }
3483
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003484 return skip;
3485}
3486
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003487bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout srcImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003488 IMAGE_STATE *src_image_state, BUFFER_STATE *dst_buffer_state, uint32_t regionCount,
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003489 const VkBufferImageCopy *pRegions, const char *func_name) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003490 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3491 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer");
3492
3493 // Validate command buffer state
3494 if (CB_RECORDING != cb_node->state) {
3495 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 -06003496 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_19202413, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003497 "Cannot call vkCmdCopyImageToBuffer() on command buffer which is not in recording state. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003498 validation_error_map[VALIDATION_ERROR_19202413]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003499 } else {
3500 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYIMAGETOBUFFER);
3501 }
3502
3503 // Command pool must support graphics, compute, or transfer operations
3504 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3505
3506 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3507 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3508 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 -06003509 HandleToUint64(cb_node->createInfo.commandPool), __LINE__, VALIDATION_ERROR_19202415, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003510 "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, "
3511 "or transfer capabilities. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003512 validation_error_map[VALIDATION_ERROR_19202415]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003513 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003514 skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003515 VALIDATION_ERROR_1920016c);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003516 skip |= ValidtateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003517 VALIDATION_ERROR_1920016e);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003518
3519 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003520 VALIDATION_ERROR_19200178);
3521 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200176);
3522 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200180);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003523
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003524 // Validate that SRC image & DST buffer have correct usage flags set
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003525 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_19200174,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003526 "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003527 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
3528 VALIDATION_ERROR_1920017e, "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
3529 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_19200017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003530 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003531 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003532 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout,
3533 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_1920017c,
3534 &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003535 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06003536 "vkCmdCopyImageToBuffer()");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003537 }
3538 return skip;
3539}
3540
3541void PreCallRecordCmdCopyImageToBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003542 BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions,
3543 VkImageLayout src_image_layout) {
3544 // Make sure that all image slices are updated to correct layout
3545 for (uint32_t i = 0; i < region_count; ++i) {
3546 SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout);
3547 }
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003548 // Update bindings between buffer/image and cmd buffer
3549 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003550 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003551
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003552 std::function<bool()> function = [=]() {
3553 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()");
3554 };
3555 cb_node->validate_functions.push_back(function);
3556 function = [=]() {
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003557 SetBufferMemoryValid(device_data, dst_buffer_state, true);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003558 return false;
3559 };
3560 cb_node->validate_functions.push_back(function);
3561
3562 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGETOBUFFER);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003563}
3564
3565bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout dstImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003566 BUFFER_STATE *src_buffer_state, IMAGE_STATE *dst_image_state, uint32_t regionCount,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003567 const VkBufferImageCopy *pRegions, const char *func_name) {
3568 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3569 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage");
3570
3571 // Validate command buffer state
3572 if (CB_RECORDING != cb_node->state) {
3573 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 -06003574 HandleToUint64(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_18e02413, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003575 "Cannot call vkCmdCopyBufferToImage() on command buffer which is not in recording state. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003576 validation_error_map[VALIDATION_ERROR_18e02413]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003577 } else {
3578 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYBUFFERTOIMAGE);
3579 }
3580
3581 // Command pool must support graphics, compute, or transfer operations
3582 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3583 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3584 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
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->createInfo.commandPool), __LINE__, VALIDATION_ERROR_18e02415, "DS",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003587 "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, "
3588 "or transfer capabilities. %s.",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003589 validation_error_map[VALIDATION_ERROR_18e02415]);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003590 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003591 skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003592 VALIDATION_ERROR_18e00158);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003593 skip |= ValidtateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003594 VALIDATION_ERROR_18e00156);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003595 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003596 VALIDATION_ERROR_18e00166);
3597 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00160);
3598 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00164);
3599 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true,
3600 VALIDATION_ERROR_18e0015c, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3601 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_18e00162,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003602 "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003603 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e00017);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003604 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003605 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003606 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout,
3607 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_18e0016a,
3608 &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003609 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i,
3610 "vkCmdCopyBufferToImage()");
3611 }
3612 return skip;
3613}
3614
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003615void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003616 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions,
3617 VkImageLayout dst_image_layout) {
3618 // Make sure that all image slices are updated to correct layout
3619 for (uint32_t i = 0; i < region_count; ++i) {
3620 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout);
3621 }
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003622 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003623 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003624 std::function<bool()> function = [=]() {
3625 SetImageMemoryValid(device_data, dst_image_state, true);
3626 return false;
3627 };
3628 cb_node->validate_functions.push_back(function);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003629 function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); };
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003630 cb_node->validate_functions.push_back(function);
3631
3632 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFERTOIMAGE);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003633}
Mike Weiblen672b58b2017-02-21 14:32:53 -07003634
3635bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) {
3636 const auto report_data = core_validation::GetReportData(device_data);
3637 bool skip = false;
3638 const VkImageAspectFlags sub_aspect = pSubresource->aspectMask;
3639
3640 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
3641 const int num_bits = sizeof(sub_aspect) * CHAR_BIT;
3642 std::bitset<num_bits> aspect_mask_bits(sub_aspect);
3643 if (aspect_mask_bits.count() != 1) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003644 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 -06003645 __LINE__, VALIDATION_ERROR_2a6007ca, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003646 "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003647 validation_error_map[VALIDATION_ERROR_2a6007ca]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003648 }
3649
3650 IMAGE_STATE *image_entry = GetImageState(device_data, image);
3651 if (!image_entry) {
3652 return skip;
3653 }
3654
3655 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
3656 if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003657 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 -06003658 __LINE__, VALIDATION_ERROR_2a6007c8, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003659 "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003660 validation_error_map[VALIDATION_ERROR_2a6007c8]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003661 }
3662
3663 // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
3664 if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) {
Petr Krausbc7f5442017-05-14 23:43:38 +02003665 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 -06003666 __LINE__, VALIDATION_ERROR_0a4007cc, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003667 "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003668 pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_0a4007cc]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003669 }
3670
3671 // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
3672 if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) {
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003673 skip |=
3674 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, HandleToUint64(image),
3675 __LINE__, VALIDATION_ERROR_0a4007ce, "IMAGE",
3676 "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s",
3677 pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_0a4007ce]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003678 }
3679
3680 // VU 00741: subresource's aspect must be compatible with image's format.
3681 const VkFormat img_format = image_entry->createInfo.format;
Dave Houlton1d2022c2017-03-29 11:43:58 -06003682 if (FormatIsColor(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003683 if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) {
3684 skip |= log_msg(
Petr Krausbc7f5442017-05-14 23:43:38 +02003685 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 -06003686 VALIDATION_ERROR_0a400c01, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003687 "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003688 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003689 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003690 } else if (FormatIsDepthOrStencil(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003691 if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003692 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 -06003693 HandleToUint64(image), __LINE__, VALIDATION_ERROR_0a400c01, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003694 "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be "
3695 "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s",
Tobin Ehlis3c37fb32017-05-24 09:31:13 -06003696 validation_error_map[VALIDATION_ERROR_0a400c01]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003697 }
3698 }
3699 return skip;
3700}