blob: e1b2eac22d5c5433dc2291afc743324e13015a9f [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>
19 */
20
21// Allow use of STL min and max functions in Windows
22#define NOMINMAX
23
Mark Lobodzinski90224de2017-01-26 15:23:11 -070024#include <sstream>
25
26#include "vk_enum_string_helper.h"
27#include "vk_layer_data.h"
28#include "vk_layer_utils.h"
29#include "vk_layer_logging.h"
30
31
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -070032#include "buffer_validation.h"
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -070033
Tobin Ehlis58c884f2017-02-08 12:15:27 -070034void SetLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070035 if (std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair) !=
36 pCB->imageSubresourceMap[imgpair.image].end()) {
37 pCB->imageLayoutMap[imgpair].layout = layout;
38 } else {
39 assert(imgpair.hasSubresource);
40 IMAGE_CMD_BUF_LAYOUT_NODE node;
41 if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) {
42 node.initialLayout = layout;
43 }
44 SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout});
45 }
46}
47template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070048void SetLayout(layer_data *device_data, OBJECT *pObject, VkImage image, VkImageSubresource range, const LAYOUT &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070049 ImageSubresourcePair imgpair = {image, true, range};
50 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
51 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
52 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
53 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
54}
55
56template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070057void SetLayout(layer_data *device_data, OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070058 VkImageAspectFlags aspectMask) {
59 if (imgpair.subresource.aspectMask & aspectMask) {
60 imgpair.subresource.aspectMask = aspectMask;
61 SetLayout(device_data, pObject, imgpair, layout);
62 }
63}
64
Tobin Ehlis58c884f2017-02-08 12:15:27 -070065bool FindLayoutVerifyNode(layer_data *device_data, GLOBAL_CB_NODE *pCB, ImageSubresourcePair imgpair,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070066 IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) {
67 const debug_report_data *report_data = core_validation::GetReportData(device_data);
68
69 if (!(imgpair.subresource.aspectMask & aspectMask)) {
70 return false;
71 }
72 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
73 imgpair.subresource.aspectMask = aspectMask;
74 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
75 if (imgsubIt == pCB->imageLayoutMap.end()) {
76 return false;
77 }
78 if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) {
79 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
80 reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
81 "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s",
82 reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout),
83 string_VkImageLayout(imgsubIt->second.layout));
84 }
85 if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) {
86 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
87 reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
88 "Cannot query for VkImage 0x%" PRIx64
89 " layout when combined aspect mask %d has multiple initial layout types: %s and %s",
90 reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout),
91 string_VkImageLayout(imgsubIt->second.initialLayout));
92 }
93 node = imgsubIt->second;
94 return true;
95}
96
Tobin Ehlis58c884f2017-02-08 12:15:27 -070097bool FindLayoutVerifyLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070098 const VkImageAspectFlags aspectMask) {
99 if (!(imgpair.subresource.aspectMask & aspectMask)) {
100 return false;
101 }
102 const debug_report_data *report_data = core_validation::GetReportData(device_data);
103 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
104 imgpair.subresource.aspectMask = aspectMask;
105 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
106 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) {
107 return false;
108 }
109 if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) {
110 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
111 reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
112 "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s",
113 reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(layout),
114 string_VkImageLayout(imgsubIt->second.layout));
115 }
116 layout = imgsubIt->second.layout;
117 return true;
118}
119
120// Find layout(s) on the command buffer level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700121bool FindCmdBufLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, VkImage image, VkImageSubresource range,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700122 IMAGE_CMD_BUF_LAYOUT_NODE &node) {
123 ImageSubresourcePair imgpair = {image, true, range};
124 node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM);
125 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT);
126 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT);
127 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT);
128 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT);
129 if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
130 imgpair = {image, false, VkImageSubresource()};
131 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
132 if (imgsubIt == pCB->imageLayoutMap.end()) return false;
133 // TODO: This is ostensibly a find function but it changes state here
134 node = imgsubIt->second;
135 }
136 return true;
137}
138
139// Find layout(s) on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700140bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700141 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
142 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
143 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
144 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
145 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
146 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
147 imgpair = {imgpair.image, false, VkImageSubresource()};
148 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
149 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false;
150 layout = imgsubIt->second.layout;
151 }
152 return true;
153}
154
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700155bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700156 auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image);
157 if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700158 auto image_state = GetImageState(device_data, image);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700159 if (!image_state) return false;
160 bool ignoreGlobal = false;
161 // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case.
162 if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) {
163 ignoreGlobal = true;
164 }
165 for (auto imgsubpair : sub_data->second) {
166 if (ignoreGlobal && !imgsubpair.hasSubresource) continue;
167 auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair);
168 if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) {
169 layouts.push_back(img_data->second.layout);
170 }
171 }
172 return true;
173}
174
175// Set the layout on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700176void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700177 VkImage &image = imgpair.image;
178 (*core_validation::GetImageLayoutMap(device_data))[imgpair].layout = layout;
179 auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image];
180 auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair);
181 if (subresource == image_subresources.end()) {
182 image_subresources.push_back(imgpair);
183 }
184}
185
186// Set the layout on the cmdbuf level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700187void 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 -0700188 pCB->imageLayoutMap[imgpair] = node;
189 auto subresource =
190 std::find(pCB->imageSubresourceMap[imgpair.image].begin(), pCB->imageSubresourceMap[imgpair.image].end(), imgpair);
191 if (subresource == pCB->imageSubresourceMap[imgpair.image].end()) {
192 pCB->imageSubresourceMap[imgpair.image].push_back(imgpair);
193 }
194}
195
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700196void SetImageViewLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, VkImageView imageView, const VkImageLayout &layout) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700197 auto view_state = GetImageViewState(device_data, imageView);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700198 assert(view_state);
199 auto image = view_state->create_info.image;
200 const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange;
201 // TODO: Do not iterate over every possibility - consolidate where possible
202 for (uint32_t j = 0; j < subRange.levelCount; j++) {
203 uint32_t level = subRange.baseMipLevel + j;
204 for (uint32_t k = 0; k < subRange.layerCount; k++) {
205 uint32_t layer = subRange.baseArrayLayer + k;
206 VkImageSubresource sub = {subRange.aspectMask, level, layer};
207 // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both
208 // are used. Verify that the extra implicit layout is OK for descriptor set layout validation
209 if (subRange.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
210 if (vk_format_is_depth_and_stencil(view_state->create_info.format)) {
211 sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
212 }
213 }
214 SetLayout(device_data, pCB, image, sub, layout);
215 }
216 }
217}
218
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700219bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700220 const VkRenderPassBeginInfo *pRenderPassBegin,
221 const FRAMEBUFFER_STATE *framebuffer_state) {
222 bool skip_call = false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700223 auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr();
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700224 auto const &framebufferInfo = framebuffer_state->createInfo;
225 const auto report_data = core_validation::GetReportData(device_data);
226 if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) {
227 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
228 DRAWSTATE_INVALID_RENDERPASS, "DS",
229 "You cannot start a render pass using a framebuffer "
230 "with a different number of attachments.");
231 }
232 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
233 const VkImageView &image_view = framebufferInfo.pAttachments[i];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700234 auto view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700235 assert(view_state);
236 const VkImage &image = view_state->create_info.image;
237 const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange;
238 IMAGE_CMD_BUF_LAYOUT_NODE newNode = {pRenderPassInfo->pAttachments[i].initialLayout,
239 pRenderPassInfo->pAttachments[i].initialLayout};
240 // TODO: Do not iterate over every possibility - consolidate where possible
241 for (uint32_t j = 0; j < subRange.levelCount; j++) {
242 uint32_t level = subRange.baseMipLevel + j;
243 for (uint32_t k = 0; k < subRange.layerCount; k++) {
244 uint32_t layer = subRange.baseArrayLayer + k;
245 VkImageSubresource sub = {subRange.aspectMask, level, layer};
246 IMAGE_CMD_BUF_LAYOUT_NODE node;
247 if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) {
248 SetLayout(device_data, pCB, image, sub, newNode);
249 continue;
250 }
251 if (newNode.layout != VK_IMAGE_LAYOUT_UNDEFINED && newNode.layout != node.layout) {
252 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
253 DRAWSTATE_INVALID_RENDERPASS, "DS",
254 "You cannot start a render pass using attachment %u "
255 "where the render pass initial layout is %s and the previous "
256 "known layout of the attachment is %s. The layouts must match, or "
257 "the render pass initial layout for the attachment must be "
258 "VK_IMAGE_LAYOUT_UNDEFINED",
259 i, string_VkImageLayout(newNode.layout), string_VkImageLayout(node.layout));
260 }
261 }
262 }
263 }
264 return skip_call;
265}
266
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700267void TransitionAttachmentRefLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700268 VkAttachmentReference ref) {
269 if (ref.attachment != VK_ATTACHMENT_UNUSED) {
270 auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment];
271 SetImageViewLayout(device_data, pCB, image_view, ref.layout);
272 }
273}
274
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700275void TransitionSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin,
276 const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700277 auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700278 if (!renderPass) return;
279
280 if (framebuffer_state) {
281 auto const &subpass = renderPass->createInfo.pSubpasses[subpass_index];
282 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
283 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]);
284 }
285 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
286 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]);
287 }
288 if (subpass.pDepthStencilAttachment) {
289 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment);
290 }
291 }
292}
293
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700294bool TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier,
295 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700296 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
297 return false;
298 }
299 VkImageSubresource sub = {aspect, level, layer};
300 IMAGE_CMD_BUF_LAYOUT_NODE node;
301 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
302 SetLayout(device_data, pCB, mem_barrier->image, sub,
303 IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout));
304 return false;
305 }
306 bool skip = false;
307 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
308 // TODO: Set memory invalid which is in mem_tracker currently
309 } else if (node.layout != mem_barrier->oldLayout) {
310 skip |= log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0,
311 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
312 "You cannot transition the layout of aspect %d from %s when current layout is %s.", aspect,
313 string_VkImageLayout(mem_barrier->oldLayout), string_VkImageLayout(node.layout));
314 }
315 SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout);
316 return skip;
317}
318
319// TODO: Separate validation and layout state updates
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700320bool TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700321 const VkImageMemoryBarrier *pImgMemBarriers) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700322 GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700323 bool skip = false;
324 uint32_t levelCount = 0;
325 uint32_t layerCount = 0;
326
327 for (uint32_t i = 0; i < memBarrierCount; ++i) {
328 auto mem_barrier = &pImgMemBarriers[i];
329 if (!mem_barrier) continue;
330 // TODO: Do not iterate over every possibility - consolidate where possible
331 ResolveRemainingLevelsLayers(device_data, &levelCount, &layerCount, mem_barrier->subresourceRange,
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700332 GetImageState(device_data, mem_barrier->image));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700333
334 for (uint32_t j = 0; j < levelCount; j++) {
335 uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j;
336 for (uint32_t k = 0; k < layerCount; k++) {
337 uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k;
338 skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
339 skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
340 skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
341 skip |= TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
342 }
343 }
344 }
345 return skip;
346}
347
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700348bool VerifySourceImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage srcImage, VkImageSubresourceLayers subLayers,
349 VkImageLayout srcImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700350 const auto report_data = core_validation::GetReportData(device_data);
351 bool skip_call = false;
352
353 for (uint32_t i = 0; i < subLayers.layerCount; ++i) {
354 uint32_t layer = i + subLayers.baseArrayLayer;
355 VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer};
356 IMAGE_CMD_BUF_LAYOUT_NODE node;
357 if (!FindCmdBufLayout(device_data, cb_node, srcImage, sub, node)) {
358 SetLayout(device_data, cb_node, srcImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(srcImageLayout, srcImageLayout));
359 continue;
360 }
361 if (node.layout != srcImageLayout) {
362 // TODO: Improve log message in the next pass
363 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
364 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
365 "Cannot copy from an image whose source layout is %s "
366 "and doesn't match the current layout %s.",
367 string_VkImageLayout(srcImageLayout), string_VkImageLayout(node.layout));
368 }
369 }
370 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
371 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
372 // TODO : Can we deal with image node from the top of call tree and avoid map look-up here?
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700373 auto image_state = GetImageState(device_data, srcImage);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700374 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
375 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
376 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0,
377 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
378 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
379 }
380 } else {
381 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode,
382 "DS", "Layout for input image is %s but can only be TRANSFER_SRC_OPTIMAL or GENERAL. %s",
383 string_VkImageLayout(srcImageLayout), validation_error_map[msgCode]);
384 }
385 }
386 return skip_call;
387}
388
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700389bool VerifyDestImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage destImage, VkImageSubresourceLayers subLayers,
390 VkImageLayout destImageLayout, UNIQUE_VALIDATION_ERROR_CODE msgCode) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700391 const auto report_data = core_validation::GetReportData(device_data);
392 bool skip_call = false;
393
394 for (uint32_t i = 0; i < subLayers.layerCount; ++i) {
395 uint32_t layer = i + subLayers.baseArrayLayer;
396 VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer};
397 IMAGE_CMD_BUF_LAYOUT_NODE node;
398 if (!FindCmdBufLayout(device_data, cb_node, destImage, sub, node)) {
399 SetLayout(device_data, cb_node, destImage, sub, IMAGE_CMD_BUF_LAYOUT_NODE(destImageLayout, destImageLayout));
400 continue;
401 }
402 if (node.layout != destImageLayout) {
403 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
404 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
405 "Cannot copy from an image whose dest layout is %s and "
406 "doesn't match the current layout %s.",
407 string_VkImageLayout(destImageLayout), string_VkImageLayout(node.layout));
408 }
409 }
410 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
411 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700412 auto image_state = GetImageState(device_data, destImage);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700413 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
414 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
415 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0,
416 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
417 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
418 }
419 } else {
420 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, msgCode,
421 "DS", "Layout for output image is %s but can only be TRANSFER_DST_OPTIMAL or GENERAL. %s",
422 string_VkImageLayout(destImageLayout), validation_error_map[msgCode]);
423 }
424 }
425 return skip_call;
426}
427
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700428void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin,
429 FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700430 auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700431 if (!renderPass) return;
432
433 const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr();
434 if (framebuffer_state) {
435 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
436 auto image_view = framebuffer_state->createInfo.pAttachments[i];
437 SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout);
438 }
439 }
440}
441
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700442bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo,
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700443 const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
444 bool skip_call = false;
445 VkImageFormatProperties ImageFormatProperties;
446 const VkPhysicalDevice physical_device = core_validation::GetPhysicalDevice(device_data);
447 const debug_report_data *report_data = core_validation::GetReportData(device_data);
448
449 if (pCreateInfo->format != VK_FORMAT_UNDEFINED) {
450 VkFormatProperties properties;
451 core_validation::GetFormatPropertiesPointer(device_data)(physical_device, pCreateInfo->format, &properties);
452
453 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties.linearTilingFeatures == 0)) {
454 std::stringstream ss;
455 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
456 skip_call |=
457 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
458 VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02150]);
459 }
460
461 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties.optimalTilingFeatures == 0)) {
462 std::stringstream ss;
463 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
464 skip_call |=
465 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
466 VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02155]);
467 }
468
469 // Validate that format supports usage as color attachment
470 if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
471 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
472 ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
473 std::stringstream ss;
474 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
475 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
476 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
477 __LINE__, VALIDATION_ERROR_02158, "IMAGE", "%s. %s", ss.str().c_str(),
478 validation_error_map[VALIDATION_ERROR_02158]);
479 }
480 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
481 ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
482 std::stringstream ss;
483 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
484 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
485 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
486 __LINE__, VALIDATION_ERROR_02153, "IMAGE", "%s. %s", ss.str().c_str(),
487 validation_error_map[VALIDATION_ERROR_02153]);
488 }
489 }
490 // Validate that format supports usage as depth/stencil attachment
491 if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
492 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
493 ((properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
494 std::stringstream ss;
495 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
496 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
497 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
498 __LINE__, VALIDATION_ERROR_02159, "IMAGE", "%s. %s", ss.str().c_str(),
499 validation_error_map[VALIDATION_ERROR_02159]);
500 }
501 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
502 ((properties.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
503 std::stringstream ss;
504 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
505 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
506 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
507 __LINE__, VALIDATION_ERROR_02154, "IMAGE", "%s. %s", ss.str().c_str(),
508 validation_error_map[VALIDATION_ERROR_02154]);
509 }
510 }
511 } else {
512 skip_call |=
513 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
514 VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s",
515 validation_error_map[VALIDATION_ERROR_00715]);
516 }
517
518 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
519 core_validation::GetImageFormatPropertiesPointer(device_data)(physical_device, pCreateInfo->format, pCreateInfo->imageType,
520 pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags,
521 &ImageFormatProperties);
522
523 VkDeviceSize imageGranularity = core_validation::GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity;
524 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
525
Mark Lobodzinski688ed322017-01-27 11:13:21 -0700526 if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) {
527 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
528 VALIDATION_ERROR_00716, "Image",
529 "CreateImage extent is 0 for at least one required dimension for image: "
530 "Width = %d Height = %d Depth = %d. %s",
531 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
532 validation_error_map[VALIDATION_ERROR_00716]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700533 }
534
535 // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720
536 // All these extent-related VUs should be checked here
537 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
538 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
539 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
540 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
541 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
542 "CreateImage extents exceed allowable limits for format: "
543 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
544 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
545 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height,
546 ImageFormatProperties.maxExtent.depth, string_VkFormat(pCreateInfo->format));
547 }
548
549 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height *
550 (uint64_t)pCreateInfo->extent.depth * (uint64_t)pCreateInfo->arrayLayers *
551 (uint64_t)pCreateInfo->samples * (uint64_t)vk_format_get_size(pCreateInfo->format) +
552 (uint64_t)imageGranularity) &
553 ~(uint64_t)imageGranularity;
554
555 if (totalSize > ImageFormatProperties.maxResourceSize) {
556 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
557 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
558 "CreateImage resource size exceeds allowable maximum "
559 "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ",
560 totalSize, ImageFormatProperties.maxResourceSize);
561 }
562
563 // TODO: VALIDATION_ERROR_02132
564 if (pCreateInfo->mipLevels > ImageFormatProperties.maxMipLevels) {
565 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
566 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
567 "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels,
568 ImageFormatProperties.maxMipLevels);
569 }
570
571 if (pCreateInfo->arrayLayers > ImageFormatProperties.maxArrayLayers) {
572 skip_call |= log_msg(
573 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, VALIDATION_ERROR_02133,
574 "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers,
575 ImageFormatProperties.maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]);
576 }
577
578 if ((pCreateInfo->samples & ImageFormatProperties.sampleCounts) == 0) {
579 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
580 VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s",
581 string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties.sampleCounts,
582 validation_error_map[VALIDATION_ERROR_02138]);
583 }
584
585 if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) {
586 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
587 VALIDATION_ERROR_00731, "Image",
588 "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or "
589 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
590 validation_error_map[VALIDATION_ERROR_00731]);
591 }
592
593 return skip_call;
594}
595
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700596void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) {
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700597 IMAGE_LAYOUT_NODE image_state;
598 image_state.layout = pCreateInfo->initialLayout;
599 image_state.format = pCreateInfo->format;
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700600 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 -0700601 ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()};
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700602 (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair);
603 (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state;
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700604}
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700605
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700606bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700607 const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700608 *image_state = core_validation::GetImageState(device_data, image);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700609 *obj_struct = {reinterpret_cast<uint64_t &>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT};
610 if (disabled->destroy_image) return false;
611 bool skip = false;
612 if (*image_state) {
613 skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743);
614 }
615 return skip;
616}
617
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700618void PostCallRecordDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700619 core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct);
620 // Clean up memory mapping, bindings and range references for image
621 for (auto mem_binding : image_state->GetBoundMemory()) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700622 auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700623 if (mem_info) {
624 core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info);
625 }
626 }
627 core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT);
628 // Remove image from imageMap
629 core_validation::GetImageMap(device_data)->erase(image);
630 std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap =
631 core_validation::GetImageSubresourceMap(device_data);
632
633 const auto &sub_entry = imageSubresourceMap->find(image);
634 if (sub_entry != imageSubresourceMap->end()) {
635 for (const auto &pair : sub_entry->second) {
636 core_validation::GetImageLayoutMap(device_data)->erase(pair);
637 }
638 imageSubresourceMap->erase(sub_entry);
639 }
640}
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700641
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700642bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700643 bool skip = false;
644 const debug_report_data *report_data = core_validation::GetReportData(device_data);
645
646 if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
647 char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
648 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
649 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
650 }
651
652 if (vk_format_is_depth_or_stencil(image_state->createInfo.format)) {
653 char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
654 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
655 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
656 validation_error_map[VALIDATION_ERROR_01088]);
657 } else if (vk_format_is_compressed(image_state->createInfo.format)) {
658 char const str[] = "vkCmdClearColorImage called with compressed image.";
659 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
660 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
661 validation_error_map[VALIDATION_ERROR_01088]);
662 }
663
664 if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
665 char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
666 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
667 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str,
668 validation_error_map[VALIDATION_ERROR_01084]);
669 }
670 return skip;
671}
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700672
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700673void ResolveRemainingLevelsLayers(layer_data *dev_data, VkImageSubresourceRange *range, IMAGE_STATE *image_state) {
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700674 // If the caller used the special values VK_REMAINING_MIP_LEVELS and VK_REMAINING_ARRAY_LAYERS, resolve them now in our
675 // internal state to the actual values.
676 if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
677 range->levelCount = image_state->createInfo.mipLevels - range->baseMipLevel;
678 }
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700679
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700680 if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
681 range->layerCount = image_state->createInfo.arrayLayers - range->baseArrayLayer;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700682 }
683}
684
685// Return the correct layer/level counts if the caller used the special values VK_REMAINING_MIP_LEVELS or VK_REMAINING_ARRAY_LAYERS.
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700686void ResolveRemainingLevelsLayers(layer_data *dev_data, uint32_t *levels, uint32_t *layers, VkImageSubresourceRange range,
687 IMAGE_STATE *image_state) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700688 *levels = range.levelCount;
689 *layers = range.layerCount;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700690 if (range.levelCount == VK_REMAINING_MIP_LEVELS) {
691 *levels = image_state->createInfo.mipLevels - range.baseMipLevel;
692 }
693 if (range.layerCount == VK_REMAINING_ARRAY_LAYERS) {
694 *layers = image_state->createInfo.arrayLayers - range.baseArrayLayer;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700695 }
696}
697
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700698bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700699 VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) {
700 bool skip = false;
701 const debug_report_data *report_data = core_validation::GetReportData(device_data);
702
703 VkImageSubresourceRange resolved_range = range;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700704 ResolveRemainingLevelsLayers(device_data, &resolved_range, image_state);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700705
706 if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
707 if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700708 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
709 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
710 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0,
711 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
712 "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name);
713 }
714 } else {
715 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01086;
716 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
717 error_code = VALIDATION_ERROR_01101;
718 } else {
719 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
720 }
721 skip |=
722 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, error_code, "DS",
723 "%s: Layout for cleared image is %s but can only be "
724 "TRANSFER_DST_OPTIMAL or GENERAL. %s",
725 func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]);
726 }
727 }
728
729 for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) {
730 uint32_t level = level_index + resolved_range.baseMipLevel;
731 for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) {
732 uint32_t layer = layer_index + resolved_range.baseArrayLayer;
733 VkImageSubresource sub = {resolved_range.aspectMask, level, layer};
734 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700735 if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700736 if (node.layout != dest_image_layout) {
737 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01085;
738 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
739 error_code = VALIDATION_ERROR_01100;
740 } else {
741 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
742 }
743 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
744 __LINE__, error_code, "DS",
745 "%s: Cannot clear an image whose layout is %s and "
746 "doesn't match the current layout %s. %s",
747 func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout),
748 validation_error_map[error_code]);
749 }
750 }
751 }
752 }
753
754 return skip;
755}
756
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700757void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range,
758 VkImageLayout dest_image_layout) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700759 VkImageSubresourceRange resolved_range = range;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700760 ResolveRemainingLevelsLayers(device_data, &resolved_range, GetImageState(device_data, image));
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700761
762 for (uint32_t level_index = 0; level_index < resolved_range.levelCount; ++level_index) {
763 uint32_t level = level_index + resolved_range.baseMipLevel;
764 for (uint32_t layer_index = 0; layer_index < resolved_range.layerCount; ++layer_index) {
765 uint32_t layer = layer_index + resolved_range.baseArrayLayer;
766 VkImageSubresource sub = {resolved_range.aspectMask, level, layer};
767 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700768 if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
769 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 -0700770 }
771 }
772 }
773}
774
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700775bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700776 VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
777 bool skip = false;
778 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700779 auto cb_node = GetCBNode(dev_data, commandBuffer);
780 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700781 if (cb_node && image_state) {
782 skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_02527);
783 skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
784 skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_01096);
785 for (uint32_t i = 0; i < rangeCount; ++i) {
786 skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]);
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700787 skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()");
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700788 }
789 }
790 return skip;
791}
792
793// This state recording routine is shared between ClearColorImage and ClearDepthStencilImage
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700794void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
795 uint32_t rangeCount, const VkImageSubresourceRange *pRanges, CMD_TYPE cmd_type) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700796 auto cb_node = GetCBNode(dev_data, commandBuffer);
797 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700798 if (cb_node && image_state) {
799 AddCommandBufferBindingImage(dev_data, cb_node, image_state);
800 std::function<bool()> function = [=]() {
801 SetImageMemoryValid(dev_data, image_state, true);
802 return false;
803 };
804 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700805 core_validation::UpdateCmdBufferLastCmd(cb_node, cmd_type);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700806 for (uint32_t i = 0; i < rangeCount; ++i) {
807 RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout);
808 }
809 }
810}
811
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700812bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image,
813 VkImageLayout imageLayout, uint32_t rangeCount,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700814 const VkImageSubresourceRange *pRanges) {
815 bool skip = false;
Mark Lobodzinski1241a312017-02-01 10:57:21 -0700816 const debug_report_data *report_data = core_validation::GetReportData(device_data);
817
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700818 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700819 auto cb_node = GetCBNode(device_data, commandBuffer);
820 auto image_state = GetImageState(device_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700821 if (cb_node && image_state) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -0700822 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_02528);
823 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
824 skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_01111);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700825 for (uint32_t i = 0; i < rangeCount; ++i) {
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700826 skip |=
827 VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()");
Mark Lobodzinski1241a312017-02-01 10:57:21 -0700828 // Image aspect must be depth or stencil or both
829 if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
830 ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
831 char const str[] =
832 "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be "
833 "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT";
834 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
835 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
836 }
837 }
838 if (image_state && !vk_format_is_depth_or_stencil(image_state->createInfo.format)) {
839 char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image.";
840 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
841 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str,
842 validation_error_map[VALIDATION_ERROR_01103]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700843 }
844 }
845 return skip;
846}
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -0700847
848// Returns true if [x, xoffset] and [y, yoffset] overlap
849static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) {
850 bool result = false;
851 uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end));
852 uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset);
853
854 if (intersection_max > intersection_min) {
855 result = true;
856 }
857 return result;
858}
859
860// Returns true if two VkImageCopy structures overlap
861static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) {
862 bool result = false;
863 if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) &&
864 (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer,
865 dst->dstSubresource.layerCount))) {
866 result = true;
867 switch (type) {
868 case VK_IMAGE_TYPE_3D:
869 result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth);
870 // Intentionally fall through to 2D case
871 case VK_IMAGE_TYPE_2D:
872 result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height);
873 // Intentionally fall through to 1D case
874 case VK_IMAGE_TYPE_1D:
875 result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width);
876 break;
877 default:
878 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
879 assert(false);
880 }
881 }
882 return result;
883}
884
885// Returns true if offset and extent exceed image extents
886static bool ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const IMAGE_STATE *image_state) {
887 bool result = false;
888 // Extents/depths cannot be negative but checks left in for clarity
889 switch (image_state->createInfo.imageType) {
890 case VK_IMAGE_TYPE_3D: // Validate z and depth
891 if ((offset->z + extent->depth > image_state->createInfo.extent.depth) || (offset->z < 0) ||
892 ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) {
893 result = true;
894 }
895 // Intentionally fall through to 2D case to check height
896 case VK_IMAGE_TYPE_2D: // Validate y and height
897 if ((offset->y + extent->height > image_state->createInfo.extent.height) || (offset->y < 0) ||
898 ((offset->y + static_cast<int32_t>(extent->height)) < 0)) {
899 result = true;
900 }
901 // Intentionally fall through to 1D case to check width
902 case VK_IMAGE_TYPE_1D: // Validate x and width
903 if ((offset->x + extent->width > image_state->createInfo.extent.width) || (offset->x < 0) ||
904 ((offset->x + static_cast<int32_t>(extent->width)) < 0)) {
905 result = true;
906 }
907 break;
908 default:
909 assert(false);
910 }
911 return result;
912}
913
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700914bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -0700915 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions) {
916 bool skip = false;
917 const debug_report_data *report_data = core_validation::GetReportData(device_data);
918 VkCommandBuffer command_buffer = cb_node->commandBuffer;
919
920 // TODO: This does not cover swapchain-created images. This should fall out when this layer is moved into the core_validation
921 // layer
922 if (src_image_state && dst_image_state) {
923 for (uint32_t i = 0; i < region_count; i++) {
924 if (regions[i].srcSubresource.layerCount == 0) {
925 std::stringstream ss;
926 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero";
927 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
928 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
929 "%s", ss.str().c_str());
930 }
931
932 if (regions[i].dstSubresource.layerCount == 0) {
933 std::stringstream ss;
934 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero";
935 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
936 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE",
937 "%s", ss.str().c_str());
938 }
939
940 // For each region the layerCount member of srcSubresource and dstSubresource must match
941 if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) {
942 std::stringstream ss;
943 ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i
944 << "] do not match";
945 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
946 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s",
947 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]);
948 }
949
950 // For each region, the aspectMask member of srcSubresource and dstSubresource must match
951 if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) {
952 char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match";
953 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
954 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s",
955 str, validation_error_map[VALIDATION_ERROR_01197]);
956 }
957
958 // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT
959 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) ||
960 (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) {
961 std::stringstream ss;
962 ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT";
963 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
964 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s",
965 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]);
966 }
967
968 // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of
969 // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT
970 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) &&
971 (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) {
972 char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects";
973 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
974 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s",
975 str, validation_error_map[VALIDATION_ERROR_01221]);
976 }
977
978 // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D,
979 // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively
980 if (((src_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) ||
981 (dst_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D)) &&
982 ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) ||
983 (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) {
984 std::stringstream ss;
985 ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i
986 << "] baseArrayLayer was not zero or layerCount was not 1.";
987 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
988 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s",
989 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]);
990 }
991
992 // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
993 if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
994 std::stringstream ss;
995 ss << "vkCmdCopyImage: pRegions[" << i
996 << "] specifies a src mipLevel greater than the number specified when the srcImage was created.";
997 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
998 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s",
999 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]);
1000 }
1001 if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
1002 std::stringstream ss;
1003 ss << "vkCmdCopyImage: pRegions[" << i
1004 << "] specifies a dst mipLevel greater than the number specified when the dstImage was created.";
1005 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1006 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s",
1007 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]);
1008 }
1009
1010 // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the
1011 // image was created
1012 if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) >
1013 src_image_state->createInfo.arrayLayers) {
1014 std::stringstream ss;
1015 ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion["
1016 << i << "] baseArrayLayer + layerCount is "
1017 << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount);
1018 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1019 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s",
1020 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]);
1021 }
1022 if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) >
1023 dst_image_state->createInfo.arrayLayers) {
1024 std::stringstream ss;
1025 ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion["
1026 << i << "] baseArrayLayer + layerCount is "
1027 << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount);
1028 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1029 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s",
1030 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]);
1031 }
1032
1033 // The source region specified by a given element of regions must be a region that is contained within srcImage
1034 if (ExceedsBounds(&regions[i].srcOffset, &regions[i].extent, src_image_state)) {
1035 std::stringstream ss;
1036 ss << "vkCmdCopyImage: srcSubResource in pRegions[" << i << "] exceeds extents srcImage was created with";
1037 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1038 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s",
1039 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]);
1040 }
1041
1042 // The destination region specified by a given element of regions must be a region that is contained within dst_image
1043 if (ExceedsBounds(&regions[i].dstOffset, &regions[i].extent, dst_image_state)) {
1044 std::stringstream ss;
1045 ss << "vkCmdCopyImage: dstSubResource in pRegions[" << i << "] exceeds extents dstImage was created with";
1046 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1047 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s",
1048 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]);
1049 }
1050
1051 // The union of all source regions, and the union of all destination regions, specified by the elements of regions,
1052 // must not overlap in memory
1053 if (src_image_state->image == dst_image_state->image) {
1054 for (uint32_t j = 0; j < region_count; j++) {
1055 if (RegionIntersects(&regions[i], &regions[j], src_image_state->createInfo.imageType)) {
1056 std::stringstream ss;
1057 ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "].";
1058 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1059 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE",
1060 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]);
1061 }
1062 }
1063 }
1064 }
1065
1066 // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes
1067 // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because
1068 // because both texels are 4 bytes in size. Depth/stencil formats must match exactly.
1069 if (vk_format_is_depth_or_stencil(src_image_state->createInfo.format) ||
1070 vk_format_is_depth_or_stencil(dst_image_state->createInfo.format)) {
1071 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1072 char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats.";
1073 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1074 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE",
1075 str);
1076 }
1077 } else {
1078 size_t srcSize = vk_format_get_size(src_image_state->createInfo.format);
1079 size_t destSize = vk_format_get_size(dst_image_state->createInfo.format);
1080 if (srcSize != destSize) {
1081 char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes.";
1082 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1083 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s",
1084 str, validation_error_map[VALIDATION_ERROR_01184]);
1085 }
1086 }
1087 }
1088 return skip;
1089}
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001090
1091// TODO : Should be tracking lastBound per commandBuffer and when draws occur, report based on that cmd buffer lastBound
1092// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1093// to that same cmd buffer by separate thread are not changing state from underneath us
1094// Track the last cmd buffer touched by this thread
1095static bool hasDrawCmd(GLOBAL_CB_NODE *pCB) {
1096 for (uint32_t i = 0; i < NUM_DRAW_TYPES; i++) {
1097 if (pCB->drawCount[i]) return true;
1098 }
1099 return false;
1100}
1101
1102// Returns true if sub_rect is entirely contained within rect
1103static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) {
1104 if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) ||
1105 (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height))
1106 return false;
1107 return true;
1108}
1109
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001110bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
1111 const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001112 GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001113 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1114
1115 bool skip = false;
1116 if (cb_node) {
1117 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001118 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001119 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
1120 if (!hasDrawCmd(cb_node) && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
1121 (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
1122 // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass)
1123 // Can we make this warning more specific? I'd like to avoid triggering this test if we can tell it's a use that must
1124 // call CmdClearAttachments. Otherwise this seems more like a performance warning.
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001125 skip |=
1126 log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1127 reinterpret_cast<uint64_t &>(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
1128 "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds."
1129 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
1130 commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001131 }
1132 skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122);
1133 }
1134
1135 // Validate that attachment is in reference list of active subpass
1136 if (cb_node->activeRenderPass) {
1137 const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr();
1138 const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001139 auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001140
1141 for (uint32_t i = 0; i < attachmentCount; i++) {
1142 auto clear_desc = &pAttachments[i];
1143 VkImageView image_view = VK_NULL_HANDLE;
1144
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001145 if (0 == clear_desc->aspectMask) {
1146 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1147 (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s",
1148 validation_error_map[VALIDATION_ERROR_01128]);
1149 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
1150 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1151 (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s",
1152 validation_error_map[VALIDATION_ERROR_01126]);
1153 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001154 if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001155 skip |=
1156 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1157 (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01114, "DS",
1158 "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s",
1159 clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001160 } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) {
1161 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001162 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__,
1163 DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
1164 "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.",
1165 clear_desc->colorAttachment);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001166 } else {
1167 image_view = framebuffer->createInfo
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001168 .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment];
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001169 }
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001170 if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) ||
1171 (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1172 char const str[] =
1173 "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s";
1174 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1175 (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i,
1176 validation_error_map[VALIDATION_ERROR_01125]);
1177 }
1178 } else { // Must be depth and/or stencil
1179 if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1180 ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1181 char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s";
1182 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1183 (uint64_t)commandBuffer, __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i,
1184 validation_error_map[VALIDATION_ERROR_01127]);
1185 }
1186 if (!subpass_desc->pDepthStencilAttachment ||
1187 (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) {
1188 skip |= log_msg(
1189 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1190 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
1191 "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001192 } else {
1193 image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment];
1194 }
1195 }
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001196 if (image_view) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001197 auto image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001198 for (uint32_t j = 0; j < rectCount; j++) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001199 // The rectangular region specified by a given element of pRects must be contained within the render area of
1200 // the current render pass instance
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001201 if (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect)) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001202 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1203 __LINE__, VALIDATION_ERROR_01115, "DS",
1204 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
1205 "the current render pass instance. %s",
1206 j, validation_error_map[VALIDATION_ERROR_01115]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001207 }
1208 // The layers specified by a given element of pRects must be contained within every attachment that
1209 // pAttachments refers to
1210 auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer;
1211 auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount;
1212 if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) {
1213 skip |=
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001214 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1215 __LINE__, VALIDATION_ERROR_01116, "DS",
1216 "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of "
1217 "pAttachment[%d]. %s",
1218 j, i, validation_error_map[VALIDATION_ERROR_01116]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001219 }
1220 }
1221 }
1222 }
1223 }
1224 return skip;
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001225}
1226
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001227bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001228 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) {
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001229 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001230 bool skip = false;
1231 if (cb_node && src_image_state && dst_image_state) {
1232 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541);
1233 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542);
1234 skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
1235 skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001236
1237 // For each region, the number of layers in the image subresource should not be zero
1238 // For each region, src and dest image aspect must be color only
1239 for (uint32_t i = 0; i < regionCount; i++) {
1240 if (pRegions[i].srcSubresource.layerCount == 0) {
1241 char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001242 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001243 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1244 "IMAGE", str);
1245 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001246 if (pRegions[i].dstSubresource.layerCount == 0) {
1247 char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001248 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001249 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1250 "IMAGE", str);
1251 }
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001252 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
1253 skip |= log_msg(
1254 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1255 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01339, "IMAGE",
1256 "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i,
1257 validation_error_map[VALIDATION_ERROR_01339]);
1258 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001259 if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
1260 (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) {
1261 char const str[] =
1262 "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT";
1263 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1264 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE",
1265 "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]);
1266 }
1267 }
1268
1269 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1270 char const str[] = "vkCmdResolveImage called with unmatched source and dest formats.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001271 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001272 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT,
1273 "IMAGE", str);
1274 }
1275 if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) {
1276 char const str[] = "vkCmdResolveImage called with unmatched source and dest image types.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001277 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001278 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE",
1279 str);
1280 }
1281 if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
1282 char const str[] = "vkCmdResolveImage called with source sample count less than 2.";
1283 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1284 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s",
1285 str, validation_error_map[VALIDATION_ERROR_01320]);
1286 }
1287 if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
1288 char const str[] = "vkCmdResolveImage called with dest sample count greater than 1.";
1289 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1290 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s",
1291 str, validation_error_map[VALIDATION_ERROR_01321]);
1292 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001293 } else {
1294 assert(0);
1295 }
1296 return skip;
1297}
1298
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001299void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
1300 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001301 // Update bindings between images and cmd buffer
1302 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1303 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
1304
1305 std::function<bool()> function = [=]() {
1306 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()");
1307 };
1308 cb_node->validate_functions.push_back(function);
1309 function = [=]() {
1310 SetImageMemoryValid(device_data, dst_image_state, true);
1311 return false;
1312 };
1313 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001314 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001315}
1316
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001317bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001318 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
1319 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1320
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001321 bool skip = false;
1322 if (cb_node && src_image_state && dst_image_state) {
1323 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001324 VALIDATION_ERROR_02194);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001325 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001326 VALIDATION_ERROR_02195);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001327 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539);
1328 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540);
1329 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_02182,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001330 "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001331 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_02186,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001332 "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001333 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
1334 skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001335
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001336 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001337
1338 // Warn for zero-sized regions
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001339 if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) ||
1340 (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) ||
1341 (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) {
1342 std::stringstream ss;
1343 ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area.";
1344 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1345 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE",
1346 "%s", ss.str().c_str());
1347 }
1348 if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) ||
1349 (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) ||
1350 (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) {
1351 std::stringstream ss;
1352 ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area.";
1353 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1354 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE",
1355 "%s", ss.str().c_str());
1356 }
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001357 if (pRegions[i].srcSubresource.layerCount == 0) {
1358 char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero";
1359 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1360 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1361 "IMAGE", str);
1362 }
1363 if (pRegions[i].dstSubresource.layerCount == 0) {
1364 char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero";
1365 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1366 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1367 "IMAGE", str);
1368 }
1369
1370 // Check that src/dst layercounts match
1371 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
1372 skip |=
1373 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1374 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE",
1375 "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s",
1376 i, validation_error_map[VALIDATION_ERROR_01304]);
1377 }
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07001378
1379 if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) {
1380 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1381 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01303, "IMAGE",
1382 "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i,
1383 validation_error_map[VALIDATION_ERROR_01303]);
1384 }
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001385 }
1386
1387 VkFormat src_format = src_image_state->createInfo.format;
1388 VkFormat dst_format = dst_image_state->createInfo.format;
1389
1390 // Validate consistency for unsigned formats
1391 if (vk_format_is_uint(src_format) != vk_format_is_uint(dst_format)) {
1392 std::stringstream ss;
1393 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, "
1394 << "the other one must also have unsigned integer format. "
1395 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
1396 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1397 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s",
1398 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]);
1399 }
1400
1401 // Validate consistency for signed formats
1402 if (vk_format_is_sint(src_format) != vk_format_is_sint(dst_format)) {
1403 std::stringstream ss;
1404 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, "
1405 << "the other one must also have signed integer format. "
1406 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
1407 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1408 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s",
1409 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]);
1410 }
1411
1412 // Validate aspect bits and formats for depth/stencil images
1413 if (vk_format_is_depth_or_stencil(src_format) || vk_format_is_depth_or_stencil(dst_format)) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001414
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001415 if (src_format != dst_format) {
1416 std::stringstream ss;
1417 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth "
1418 << "stencil, the other one must have exactly the same format. "
1419 << "Source format is " << string_VkFormat(src_format) << " Destination format is "
1420 << string_VkFormat(dst_format);
1421 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1422 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE",
1423 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]);
1424 }
1425
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001426 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001427 VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask;
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001428
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001429 if (vk_format_is_depth_and_stencil(src_format)) {
1430 if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1431 std::stringstream ss;
1432 ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of "
1433 "VK_IMAGE_ASPECT_DEPTH_BIT "
1434 << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage";
1435 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1436 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__,
1437 DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
1438 }
1439 } else if (vk_format_is_stencil_only(src_format)) {
1440 if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) {
1441 std::stringstream ss;
1442 ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT "
1443 << "set in both the srcImage and dstImage";
1444 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1445 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__,
1446 DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
1447 }
1448 } else if (vk_format_is_depth_only(src_format)) {
1449 if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) {
1450 std::stringstream ss;
1451 ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH "
1452 << "set in both the srcImage and dstImage";
1453 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1454 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__,
1455 DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
1456 }
1457 }
1458 }
1459 }
1460
1461 // Validate filter
1462 if (vk_format_is_depth_or_stencil(src_format) && (filter != VK_FILTER_NEAREST)) {
1463 std::stringstream ss;
1464 ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil "
1465 << "then filter must be VK_FILTER_NEAREST.";
1466 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1467 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s",
1468 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]);
1469 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001470 } else {
1471 assert(0);
1472 }
1473 return skip;
1474}
1475
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001476void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
1477 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001478 // Update bindings between images and cmd buffer
1479 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1480 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
1481
1482 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); };
1483 cb_node->validate_functions.push_back(function);
1484 function = [=]() {
1485 SetImageMemoryValid(device_data, dst_image_state, true);
1486 return false;
1487 };
1488 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001489 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001490}
1491
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07001492// This validates that the initial layout specified in the command buffer for the IMAGE is the same as the global IMAGE layout
1493bool ValidateCmdBufImageLayouts(core_validation::layer_data *device_data, GLOBAL_CB_NODE *pCB) {
1494 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1495 bool skip = false;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07001496 for (auto cb_image_data : pCB->imageLayoutMap) {
1497 VkImageLayout imageLayout;
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07001498 if (!FindGlobalLayout(device_data, cb_image_data.first, imageLayout)) {
1499 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
1500 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS", "Cannot submit cmd buffer using deleted image 0x%" PRIx64 ".",
1501 reinterpret_cast<const uint64_t &>(cb_image_data.first));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07001502 } else {
1503 if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
1504 // TODO: Set memory invalid which is in mem_tracker currently
1505 } else if (imageLayout != cb_image_data.second.initialLayout) {
1506 if (cb_image_data.first.hasSubresource) {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07001507 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1508 reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT,
1509 "DS", "Cannot submit cmd buffer using image (0x%" PRIx64
1510 ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], "
1511 "with layout %s when first use is %s.",
1512 reinterpret_cast<const uint64_t &>(cb_image_data.first.image),
1513 cb_image_data.first.subresource.aspectMask, cb_image_data.first.subresource.arrayLayer,
1514 cb_image_data.first.subresource.mipLevel, string_VkImageLayout(imageLayout),
1515 string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07001516 } else {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07001517 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1518 reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT,
1519 "DS", "Cannot submit cmd buffer using image (0x%" PRIx64
1520 ") with layout %s when "
1521 "first use is %s.",
1522 reinterpret_cast<const uint64_t &>(cb_image_data.first.image),
1523 string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07001524 }
1525 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07001526 SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07001527 }
1528 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07001529 return skip;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07001530}
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001531
1532// Print readable FlagBits in FlagMask
1533static std::string string_VkAccessFlags(VkAccessFlags accessMask) {
1534 std::string result;
1535 std::string separator;
1536
1537 if (accessMask == 0) {
1538 result = "[None]";
1539 } else {
1540 result = "[";
1541 for (auto i = 0; i < 32; i++) {
1542 if (accessMask & (1 << i)) {
1543 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
1544 separator = " | ";
1545 }
1546 }
1547 result = result + "]";
1548 }
1549 return result;
1550}
1551
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001552// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask
1553// must have at least one of 'optional_bits' set
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001554// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001555static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask,
1556 const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits,
1557 const char *type) {
1558 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1559 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001560
1561 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
1562 if (accessMask & ~(required_bit | optional_bits)) {
1563 // TODO: Verify against Valid Use
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001564 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
1565 DRAWSTATE_INVALID_BARRIER, "DS",
1566 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
1567 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001568 }
1569 } else {
1570 if (!required_bit) {
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001571 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
1572 DRAWSTATE_INVALID_BARRIER, "DS",
1573 "%s AccessMask %d %s must contain at least one of access bits %d "
1574 "%s when layout is %s, unless the app has previously added a "
1575 "barrier for this transition.",
1576 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
1577 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001578 } else {
1579 std::string opt_bits;
1580 if (optional_bits != 0) {
1581 std::stringstream ss;
1582 ss << optional_bits;
1583 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
1584 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001585 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
1586 DRAWSTATE_INVALID_BARRIER, "DS",
1587 "%s AccessMask %d %s must have required access bit %d %s %s when "
1588 "layout is %s, unless the app has previously added a barrier for "
1589 "this transition.",
1590 type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit,
1591 string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001592 }
1593 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001594 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001595}
1596
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001597bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer,
1598 const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) {
1599 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001600
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001601 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001602 switch (layout) {
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001603 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
1604 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1605 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
1606 break;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001607 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001608 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
1609 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
1610 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
1611 break;
1612 }
1613 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
1614 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
1615 break;
1616 }
1617 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
1618 skip |= ValidateMaskBits(
1619 device_data, cmdBuffer, accessMask, layout, 0,
1620 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
1621 type);
1622 break;
1623 }
1624 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
1625 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0,
1626 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
1627 break;
1628 }
1629 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
1630 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
1631 break;
1632 }
1633 case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: {
1634 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_MEMORY_READ_BIT, 0, type);
1635 break;
1636 }
1637 case VK_IMAGE_LAYOUT_UNDEFINED: {
1638 if (accessMask != 0) {
1639 // TODO: Verify against Valid Use section spec
1640 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
1641 DRAWSTATE_INVALID_BARRIER, "DS",
1642 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
1643 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
1644 }
1645 break;
1646 }
1647 case VK_IMAGE_LAYOUT_GENERAL:
1648 default: { break; }
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001649 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07001650 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07001651}
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001652
1653// ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001654// VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY
1655// layout attachments don't have CLEAR as their loadOp.
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001656bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001657 const uint32_t attachment, const VkAttachmentDescription &attachment_description) {
1658 bool skip = false;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001659 // Verify that initial loadOp on READ_ONLY attachments is not CLEAR
1660 if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
1661 if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) ||
1662 (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001663 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
1664 VkDebugReportObjectTypeEXT(0), __LINE__, VALIDATION_ERROR_02351, "DS",
1665 "Cannot clear attachment %d with invalid first layout %s. %s", attachment,
1666 string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_02351]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001667 }
1668 }
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001669 return skip;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001670}
1671
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001672bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) {
1673 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001674 bool skip = false;
1675
1676 // Track when we're observing the first use of an attachment
1677 std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true);
1678 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
1679 const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i];
1680 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
1681 auto attach_index = subpass.pColorAttachments[j].attachment;
1682 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
1683
1684 switch (subpass.pColorAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001685 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1686 // This is ideal.
1687 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001688
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001689 case VK_IMAGE_LAYOUT_GENERAL:
1690 // May not be optimal; TODO: reconsider this warning based on other constraints?
1691 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
1692 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1693 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
1694 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001695
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001696 default:
1697 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1698 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1699 "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.",
1700 string_VkImageLayout(subpass.pColorAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001701 }
1702
1703 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001704 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index,
1705 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001706 }
1707 attach_first_use[attach_index] = false;
1708 }
1709 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
1710 switch (subpass.pDepthStencilAttachment->layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001711 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1712 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1713 // These are ideal.
1714 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001715
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001716 case VK_IMAGE_LAYOUT_GENERAL:
1717 // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than
1718 // doing a bunch of transitions.
1719 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
1720 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1721 "GENERAL layout for depth attachment may not give optimal performance.");
1722 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001723
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001724 default:
1725 // No other layouts are acceptable
1726 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1727 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1728 "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "
1729 "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.",
1730 string_VkImageLayout(subpass.pDepthStencilAttachment->layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001731 }
1732
1733 auto attach_index = subpass.pDepthStencilAttachment->attachment;
1734 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001735 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index,
1736 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001737 }
1738 attach_first_use[attach_index] = false;
1739 }
1740 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
1741 auto attach_index = subpass.pInputAttachments[j].attachment;
1742 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
1743
1744 switch (subpass.pInputAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001745 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1746 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
1747 // These are ideal.
1748 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001749
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001750 case VK_IMAGE_LAYOUT_GENERAL:
1751 // May not be optimal. TODO: reconsider this warning based on other constraints.
1752 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
1753 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1754 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
1755 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001756
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001757 default:
1758 // No other layouts are acceptable
1759 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
1760 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1761 "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.",
1762 string_VkImageLayout(subpass.pInputAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001763 }
1764
1765 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07001766 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index,
1767 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07001768 }
1769 attach_first_use[attach_index] = false;
1770 }
1771 }
1772 return skip;
1773}
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07001774
1775// For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07001776bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info,
1777 VkDeviceSize offset, VkDeviceSize end_offset) {
1778 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1779 bool skip = false;
1780 // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are
1781 // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07001782 // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range
1783 for (auto image_handle : mem_info->bound_images) {
1784 auto img_it = mem_info->bound_ranges.find(image_handle);
1785 if (img_it != mem_info->bound_ranges.end()) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07001786 if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07001787 std::vector<VkImageLayout> layouts;
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07001788 if (FindLayouts(device_data, VkImage(image_handle), layouts)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07001789 for (auto layout : layouts) {
1790 if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07001791 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
1792 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
1793 "Cannot map an image with layout %s. Only "
1794 "GENERAL or PREINITIALIZED are supported.",
1795 string_VkImageLayout(layout));
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07001796 }
1797 }
1798 }
1799 }
1800 }
1801 }
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07001802 return skip;
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07001803}