blob: 770ee98a547f8ef8226276b64b1536f0d265300e [file] [log] [blame]
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -07001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
4 * Copyright (C) 2015-2017 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@lunarg.com>
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060019 * Author: Dave Houlton <daveh@lunarg.com>
Mark Lobodzinskid42e4d22017-01-17 14:14:22 -070020 */
21
22// Allow use of STL min and max functions in Windows
23#define NOMINMAX
24
Mark Lobodzinski90224de2017-01-26 15:23:11 -070025#include <sstream>
26
27#include "vk_enum_string_helper.h"
28#include "vk_layer_data.h"
29#include "vk_layer_utils.h"
30#include "vk_layer_logging.h"
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) {
Chris Forbes4eab4b02017-04-26 10:21:20 -070035 if (pCB->imageLayoutMap.find(imgpair) != pCB->imageLayoutMap.end()) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070036 pCB->imageLayoutMap[imgpair].layout = layout;
37 } else {
38 assert(imgpair.hasSubresource);
39 IMAGE_CMD_BUF_LAYOUT_NODE node;
40 if (!FindCmdBufLayout(device_data, pCB, imgpair.image, imgpair.subresource, node)) {
41 node.initialLayout = layout;
42 }
43 SetLayout(device_data, pCB, imgpair, {node.initialLayout, layout});
44 }
45}
46template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070047void SetLayout(layer_data *device_data, OBJECT *pObject, VkImage image, VkImageSubresource range, const LAYOUT &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070048 ImageSubresourcePair imgpair = {image, true, range};
49 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
50 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
51 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
52 SetLayout(device_data, pObject, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
53}
54
55template <class OBJECT, class LAYOUT>
Tobin Ehlis58c884f2017-02-08 12:15:27 -070056void SetLayout(layer_data *device_data, OBJECT *pObject, ImageSubresourcePair imgpair, const LAYOUT &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070057 VkImageAspectFlags aspectMask) {
58 if (imgpair.subresource.aspectMask & aspectMask) {
59 imgpair.subresource.aspectMask = aspectMask;
60 SetLayout(device_data, pObject, imgpair, layout);
61 }
62}
63
Tony Barbourdf013b92017-01-25 12:53:48 -070064// Set the layout in supplied map
Tony Barboure0c5cc92017-02-08 13:53:39 -070065void SetLayout(std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
66 VkImageLayout layout) {
Tony Barbourdf013b92017-01-25 12:53:48 -070067 imageLayoutMap[imgpair].layout = layout;
68}
69
Tobin Ehlisc8266452017-04-07 12:20:30 -060070bool FindLayoutVerifyNode(layer_data const *device_data, GLOBAL_CB_NODE const *pCB, ImageSubresourcePair imgpair,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -070071 IMAGE_CMD_BUF_LAYOUT_NODE &node, const VkImageAspectFlags aspectMask) {
72 const debug_report_data *report_data = core_validation::GetReportData(device_data);
73
74 if (!(imgpair.subresource.aspectMask & aspectMask)) {
75 return false;
76 }
77 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
78 imgpair.subresource.aspectMask = aspectMask;
79 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
80 if (imgsubIt == pCB->imageLayoutMap.end()) {
81 return false;
82 }
83 if (node.layout != VK_IMAGE_LAYOUT_MAX_ENUM && node.layout != imgsubIt->second.layout) {
84 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
85 reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
86 "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s",
87 reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.layout),
88 string_VkImageLayout(imgsubIt->second.layout));
89 }
90 if (node.initialLayout != VK_IMAGE_LAYOUT_MAX_ENUM && node.initialLayout != imgsubIt->second.initialLayout) {
91 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
92 reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
93 "Cannot query for VkImage 0x%" PRIx64
94 " layout when combined aspect mask %d has multiple initial layout types: %s and %s",
95 reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(node.initialLayout),
96 string_VkImageLayout(imgsubIt->second.initialLayout));
97 }
98 node = imgsubIt->second;
99 return true;
100}
101
Tobin Ehlisc8266452017-04-07 12:20:30 -0600102bool FindLayoutVerifyLayout(layer_data const *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700103 const VkImageAspectFlags aspectMask) {
104 if (!(imgpair.subresource.aspectMask & aspectMask)) {
105 return false;
106 }
107 const debug_report_data *report_data = core_validation::GetReportData(device_data);
108 VkImageAspectFlags oldAspectMask = imgpair.subresource.aspectMask;
109 imgpair.subresource.aspectMask = aspectMask;
110 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
111 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) {
112 return false;
113 }
114 if (layout != VK_IMAGE_LAYOUT_MAX_ENUM && layout != imgsubIt->second.layout) {
115 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
116 reinterpret_cast<uint64_t &>(imgpair.image), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
117 "Cannot query for VkImage 0x%" PRIx64 " layout when combined aspect mask %d has multiple layout types: %s and %s",
118 reinterpret_cast<uint64_t &>(imgpair.image), oldAspectMask, string_VkImageLayout(layout),
119 string_VkImageLayout(imgsubIt->second.layout));
120 }
121 layout = imgsubIt->second.layout;
122 return true;
123}
124
125// Find layout(s) on the command buffer level
Tobin Ehlisc8266452017-04-07 12:20:30 -0600126bool FindCmdBufLayout(layer_data const *device_data, GLOBAL_CB_NODE const *pCB, VkImage image, VkImageSubresource range,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700127 IMAGE_CMD_BUF_LAYOUT_NODE &node) {
128 ImageSubresourcePair imgpair = {image, true, range};
129 node = IMAGE_CMD_BUF_LAYOUT_NODE(VK_IMAGE_LAYOUT_MAX_ENUM, VK_IMAGE_LAYOUT_MAX_ENUM);
130 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_COLOR_BIT);
131 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_DEPTH_BIT);
132 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_STENCIL_BIT);
133 FindLayoutVerifyNode(device_data, pCB, imgpair, node, VK_IMAGE_ASPECT_METADATA_BIT);
134 if (node.layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
135 imgpair = {image, false, VkImageSubresource()};
136 auto imgsubIt = pCB->imageLayoutMap.find(imgpair);
137 if (imgsubIt == pCB->imageLayoutMap.end()) return false;
138 // TODO: This is ostensibly a find function but it changes state here
139 node = imgsubIt->second;
140 }
141 return true;
142}
143
144// Find layout(s) on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700145bool FindGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700146 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
147 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
148 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
149 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
150 FindLayoutVerifyLayout(device_data, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
151 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
152 imgpair = {imgpair.image, false, VkImageSubresource()};
153 auto imgsubIt = (*core_validation::GetImageLayoutMap(device_data)).find(imgpair);
154 if (imgsubIt == (*core_validation::GetImageLayoutMap(device_data)).end()) return false;
155 layout = imgsubIt->second.layout;
156 }
157 return true;
158}
159
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700160bool FindLayouts(layer_data *device_data, VkImage image, std::vector<VkImageLayout> &layouts) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700161 auto sub_data = (*core_validation::GetImageSubresourceMap(device_data)).find(image);
162 if (sub_data == (*core_validation::GetImageSubresourceMap(device_data)).end()) return false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700163 auto image_state = GetImageState(device_data, image);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700164 if (!image_state) return false;
165 bool ignoreGlobal = false;
166 // TODO: Make this robust for >1 aspect mask. Now it will just say ignore potential errors in this case.
167 if (sub_data->second.size() >= (image_state->createInfo.arrayLayers * image_state->createInfo.mipLevels + 1)) {
168 ignoreGlobal = true;
169 }
170 for (auto imgsubpair : sub_data->second) {
171 if (ignoreGlobal && !imgsubpair.hasSubresource) continue;
172 auto img_data = (*core_validation::GetImageLayoutMap(device_data)).find(imgsubpair);
173 if (img_data != (*core_validation::GetImageLayoutMap(device_data)).end()) {
174 layouts.push_back(img_data->second.layout);
175 }
176 }
177 return true;
178}
Tony Barboure0c5cc92017-02-08 13:53:39 -0700179bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
180 VkImageLayout &layout, const VkImageAspectFlags aspectMask) {
Tony Barbourdf013b92017-01-25 12:53:48 -0700181 if (!(imgpair.subresource.aspectMask & aspectMask)) {
182 return false;
183 }
184 imgpair.subresource.aspectMask = aspectMask;
185 auto imgsubIt = imageLayoutMap.find(imgpair);
186 if (imgsubIt == imageLayoutMap.end()) {
187 return false;
188 }
189 layout = imgsubIt->second.layout;
190 return true;
Tony Barboure0c5cc92017-02-08 13:53:39 -0700191}
Tony Barbourdf013b92017-01-25 12:53:48 -0700192
193// find layout in supplied map
Tony Barboure0c5cc92017-02-08 13:53:39 -0700194bool FindLayout(const std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap, ImageSubresourcePair imgpair,
195 VkImageLayout &layout) {
Tony Barbourdf013b92017-01-25 12:53:48 -0700196 layout = VK_IMAGE_LAYOUT_MAX_ENUM;
197 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_COLOR_BIT);
198 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_DEPTH_BIT);
199 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_STENCIL_BIT);
200 FindLayout(imageLayoutMap, imgpair, layout, VK_IMAGE_ASPECT_METADATA_BIT);
201 if (layout == VK_IMAGE_LAYOUT_MAX_ENUM) {
202 imgpair = {imgpair.image, false, VkImageSubresource()};
203 auto imgsubIt = imageLayoutMap.find(imgpair);
204 if (imgsubIt == imageLayoutMap.end()) return false;
205 layout = imgsubIt->second.layout;
206 }
207 return true;
208}
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700209
210// Set the layout on the global level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700211void SetGlobalLayout(layer_data *device_data, ImageSubresourcePair imgpair, const VkImageLayout &layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700212 VkImage &image = imgpair.image;
213 (*core_validation::GetImageLayoutMap(device_data))[imgpair].layout = layout;
214 auto &image_subresources = (*core_validation::GetImageSubresourceMap(device_data))[image];
215 auto subresource = std::find(image_subresources.begin(), image_subresources.end(), imgpair);
216 if (subresource == image_subresources.end()) {
217 image_subresources.push_back(imgpair);
218 }
219}
220
221// Set the layout on the cmdbuf level
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700222void 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 -0700223 pCB->imageLayoutMap[imgpair] = node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700224}
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600225// Set image layout for given VkImageSubresourceRange struct
226void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state,
227 VkImageSubresourceRange image_subresource_range, const VkImageLayout &layout) {
228 assert(image_state);
229 for (uint32_t level_index = 0; level_index < image_subresource_range.levelCount; ++level_index) {
230 uint32_t level = image_subresource_range.baseMipLevel + level_index;
231 for (uint32_t layer_index = 0; layer_index < image_subresource_range.layerCount; layer_index++) {
232 uint32_t layer = image_subresource_range.baseArrayLayer + layer_index;
233 VkImageSubresource sub = {image_subresource_range.aspectMask, level, layer};
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700234 // TODO: If ImageView was created with depth or stencil, transition both layouts as the aspectMask is ignored and both
235 // are used. Verify that the extra implicit layout is OK for descriptor set layout validation
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600236 if (image_subresource_range.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600237 if (FormatIsDepthAndStencil(image_state->createInfo.format)) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700238 sub.aspectMask |= (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
239 }
240 }
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600241 SetLayout(device_data, cb_node, image_state->image, sub, layout);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700242 }
243 }
244}
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600245// Set image layout for given VkImageSubresourceLayers struct
246void SetImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *image_state,
247 VkImageSubresourceLayers image_subresource_layers, const VkImageLayout &layout) {
248 // Transfer VkImageSubresourceLayers into VkImageSubresourceRange struct
249 VkImageSubresourceRange image_subresource_range;
250 image_subresource_range.aspectMask = image_subresource_layers.aspectMask;
251 image_subresource_range.baseArrayLayer = image_subresource_layers.baseArrayLayer;
252 image_subresource_range.layerCount = image_subresource_layers.layerCount;
253 image_subresource_range.baseMipLevel = image_subresource_layers.mipLevel;
254 image_subresource_range.levelCount = 1;
255 SetImageLayout(device_data, cb_node, image_state, image_subresource_range, layout);
256}
257// Set image layout for all slices of an image view
258void SetImageViewLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImageView imageView, const VkImageLayout &layout) {
259 auto view_state = GetImageViewState(device_data, imageView);
260 assert(view_state);
261
262 SetImageLayout(device_data, cb_node, GetImageState(device_data, view_state->create_info.image),
263 view_state->create_info.subresourceRange, layout);
264}
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700265
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700266bool VerifyFramebufferAndRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700267 const VkRenderPassBeginInfo *pRenderPassBegin,
268 const FRAMEBUFFER_STATE *framebuffer_state) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600269 bool skip = false;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700270 auto const pRenderPassInfo = GetRenderPassState(device_data, pRenderPassBegin->renderPass)->createInfo.ptr();
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700271 auto const &framebufferInfo = framebuffer_state->createInfo;
272 const auto report_data = core_validation::GetReportData(device_data);
273 if (pRenderPassInfo->attachmentCount != framebufferInfo.attachmentCount) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600274 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
275 reinterpret_cast<uint64_t>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
276 "You cannot start a render pass using a framebuffer "
277 "with a different number of attachments.");
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700278 }
279 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
280 const VkImageView &image_view = framebufferInfo.pAttachments[i];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700281 auto view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700282 assert(view_state);
283 const VkImage &image = view_state->create_info.image;
284 const VkImageSubresourceRange &subRange = view_state->create_info.subresourceRange;
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700285 auto initial_layout = pRenderPassInfo->pAttachments[i].initialLayout;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700286 // TODO: Do not iterate over every possibility - consolidate where possible
287 for (uint32_t j = 0; j < subRange.levelCount; j++) {
288 uint32_t level = subRange.baseMipLevel + j;
289 for (uint32_t k = 0; k < subRange.layerCount; k++) {
290 uint32_t layer = subRange.baseArrayLayer + k;
291 VkImageSubresource sub = {subRange.aspectMask, level, layer};
292 IMAGE_CMD_BUF_LAYOUT_NODE node;
293 if (!FindCmdBufLayout(device_data, pCB, image, sub, node)) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700294 // Missing layouts will be added during state update
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700295 continue;
296 }
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700297 if (initial_layout != VK_IMAGE_LAYOUT_UNDEFINED && initial_layout != node.layout) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600298 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
299 __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
300 "You cannot start a render pass using attachment %u "
301 "where the render pass initial layout is %s and the previous "
302 "known layout of the attachment is %s. The layouts must match, or "
303 "the render pass initial layout for the attachment must be "
304 "VK_IMAGE_LAYOUT_UNDEFINED",
305 i, string_VkImageLayout(initial_layout), string_VkImageLayout(node.layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700306 }
307 }
308 }
309 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600310 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700311}
312
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700313void TransitionAttachmentRefLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, FRAMEBUFFER_STATE *pFramebuffer,
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700314 VkAttachmentReference ref) {
315 if (ref.attachment != VK_ATTACHMENT_UNUSED) {
316 auto image_view = pFramebuffer->createInfo.pAttachments[ref.attachment];
317 SetImageViewLayout(device_data, pCB, image_view, ref.layout);
318 }
319}
320
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700321void TransitionSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const RENDER_PASS_STATE *render_pass_state,
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700322 const int subpass_index, FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700323 assert(render_pass_state);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700324
325 if (framebuffer_state) {
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700326 auto const &subpass = render_pass_state->createInfo.pSubpasses[subpass_index];
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700327 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
328 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pInputAttachments[j]);
329 }
330 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
331 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, subpass.pColorAttachments[j]);
332 }
333 if (subpass.pDepthStencilAttachment) {
334 TransitionAttachmentRefLayout(device_data, pCB, framebuffer_state, *subpass.pDepthStencilAttachment);
335 }
336 }
337}
338
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700339bool ValidateImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier,
340 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700341 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
342 return false;
343 }
344 VkImageSubresource sub = {aspect, level, layer};
345 IMAGE_CMD_BUF_LAYOUT_NODE node;
346 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700347 return false;
348 }
349 bool skip = false;
350 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
351 // TODO: Set memory invalid which is in mem_tracker currently
352 } else if (node.layout != mem_barrier->oldLayout) {
Mark Lobodzinski91c28262017-03-22 13:06:12 -0600353 skip |=
354 log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
355 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(pCB->commandBuffer), __LINE__,
356 DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
357 "For image 0x%" PRIxLEAST64 " you cannot transition the layout of aspect %d from %s when current layout is %s.",
358 reinterpret_cast<const uint64_t &>(mem_barrier->image), aspect, string_VkImageLayout(mem_barrier->oldLayout),
359 string_VkImageLayout(node.layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700360 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700361 return skip;
362}
363
Tobin Ehlis0d4274b2017-02-17 15:17:04 -0700364// Transition the layout state for renderpass attachments based on the BeginRenderPass() call. This includes:
365// 1. Transition into initialLayout state
366// 2. Transition from initialLayout to layout used in subpass 0
367void TransitionBeginRenderPassLayouts(layer_data *device_data, GLOBAL_CB_NODE *cb_state, const RENDER_PASS_STATE *render_pass_state,
368 FRAMEBUFFER_STATE *framebuffer_state) {
369 // First transition into initialLayout
370 auto const rpci = render_pass_state->createInfo.ptr();
371 for (uint32_t i = 0; i < rpci->attachmentCount; ++i) {
372 VkImageView image_view = framebuffer_state->createInfo.pAttachments[i];
373 SetImageViewLayout(device_data, cb_state, image_view, rpci->pAttachments[i].initialLayout);
374 }
375 // Now transition for first subpass (index 0)
376 TransitionSubpassLayouts(device_data, cb_state, render_pass_state, 0, framebuffer_state);
377}
378
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700379void TransitionImageAspectLayout(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkImageMemoryBarrier *mem_barrier,
380 uint32_t level, uint32_t layer, VkImageAspectFlags aspect) {
381 if (!(mem_barrier->subresourceRange.aspectMask & aspect)) {
382 return;
383 }
384 VkImageSubresource sub = {aspect, level, layer};
385 IMAGE_CMD_BUF_LAYOUT_NODE node;
386 if (!FindCmdBufLayout(device_data, pCB, mem_barrier->image, sub, node)) {
387 SetLayout(device_data, pCB, mem_barrier->image, sub,
388 IMAGE_CMD_BUF_LAYOUT_NODE(mem_barrier->oldLayout, mem_barrier->newLayout));
389 return;
390 }
391 if (mem_barrier->oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
392 // TODO: Set memory invalid
393 }
394 SetLayout(device_data, pCB, mem_barrier->image, sub, mem_barrier->newLayout);
395}
396
Dave Houlton10b39482017-03-16 13:18:15 -0600397bool VerifyAspectsPresent(VkImageAspectFlags aspect_mask, VkFormat format) {
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600398 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600399 if (!FormatIsColor(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600400 }
401 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600402 if (!FormatHasDepth(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600403 }
404 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0) {
Dave Houlton1d2022c2017-03-29 11:43:58 -0600405 if (!FormatHasStencil(format)) return false;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -0600406 }
407 return true;
408}
409
Mike Weiblen62d08a32017-03-07 22:18:27 -0700410// Verify an ImageMemoryBarrier's old/new ImageLayouts are compatible with the Image's ImageUsageFlags.
411bool ValidateBarrierLayoutToImageUsage(layer_data *device_data, const VkImageMemoryBarrier *img_barrier, bool new_not_old,
412 VkImageUsageFlags usage_flags, const char *func_name) {
413 const auto report_data = core_validation::GetReportData(device_data);
414 bool skip = false;
415 const VkImageLayout layout = (new_not_old) ? img_barrier->newLayout : img_barrier->oldLayout;
416 UNIQUE_VALIDATION_ERROR_CODE msg_code = VALIDATION_ERROR_UNDEFINED; // sentinel value meaning "no error"
417
418 switch (layout) {
419 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
420 if ((usage_flags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) {
421 msg_code = VALIDATION_ERROR_00303;
422 }
423 break;
424 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
425 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
426 msg_code = VALIDATION_ERROR_00304;
427 }
428 break;
429 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
430 if ((usage_flags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
431 msg_code = VALIDATION_ERROR_00305;
432 }
433 break;
434 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
435 if ((usage_flags & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0) {
436 msg_code = VALIDATION_ERROR_00306;
437 }
438 break;
439 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
440 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) == 0) {
441 msg_code = VALIDATION_ERROR_00307;
442 }
443 break;
444 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
445 if ((usage_flags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) == 0) {
446 msg_code = VALIDATION_ERROR_00308;
447 }
448 break;
449 default:
450 // Other VkImageLayout values do not have VUs defined in this context.
451 break;
452 }
453
454 if (msg_code != VALIDATION_ERROR_UNDEFINED) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600455 skip |=
456 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
457 reinterpret_cast<const uint64_t &>(img_barrier->image), __LINE__, msg_code, "DS",
458 "%s: Image barrier 0x%p %sLayout=%s is not compatible with image 0x%" PRIx64 " usage flags 0x%" PRIx32 ". %s",
459 func_name, img_barrier, ((new_not_old) ? "new" : "old"), string_VkImageLayout(layout),
460 reinterpret_cast<const uint64_t &>(img_barrier->image), usage_flags, validation_error_map[msg_code]);
Mike Weiblen62d08a32017-03-07 22:18:27 -0700461 }
462 return skip;
463}
464
465// Verify image barriers are compatible with the images they reference.
466bool ValidateBarriersToImages(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t imageMemoryBarrierCount,
467 const VkImageMemoryBarrier *pImageMemoryBarriers, const char *func_name) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700468 GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700469 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700470
Mike Weiblen62d08a32017-03-07 22:18:27 -0700471 for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) {
472 auto img_barrier = &pImageMemoryBarriers[i];
473 if (!img_barrier) continue;
474
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600475 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, img_barrier->image)->createInfo);
Tobin Ehlis7ee9cbd2017-04-26 16:51:48 -0600476 // For a Depth/Stencil image both aspects MUST be set
477 if (FormatIsDepthAndStencil(image_create_info->format)) {
478 auto const aspect_mask = img_barrier->subresourceRange.aspectMask;
479 auto const ds_mask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
480 if ((aspect_mask & ds_mask) != (ds_mask)) {
481 skip |=
482 log_msg(core_validation::GetReportData(device_data), VK_DEBUG_REPORT_ERROR_BIT_EXT,
483 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, reinterpret_cast<const uint64_t &>(img_barrier->image), __LINE__,
484 VALIDATION_ERROR_00302, "DS",
485 "%s: Image barrier 0x%p references image 0x%" PRIx64
486 " of format %s that must have the depth and stencil aspects set, but its "
487 "aspectMask is 0x%" PRIx32 ". %s",
488 func_name, img_barrier, reinterpret_cast<const uint64_t &>(img_barrier->image),
489 string_VkFormat(image_create_info->format), aspect_mask, validation_error_map[VALIDATION_ERROR_00302]);
490 }
491 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600492 uint32_t level_count = ResolveRemainingLevels(&img_barrier->subresourceRange, image_create_info->mipLevels);
493 uint32_t layer_count = ResolveRemainingLayers(&img_barrier->subresourceRange, image_create_info->arrayLayers);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700494
Mike Weiblen62d08a32017-03-07 22:18:27 -0700495 for (uint32_t j = 0; j < level_count; j++) {
496 uint32_t level = img_barrier->subresourceRange.baseMipLevel + j;
497 for (uint32_t k = 0; k < layer_count; k++) {
498 uint32_t layer = img_barrier->subresourceRange.baseArrayLayer + k;
499 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
500 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
501 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
502 skip |= ValidateImageAspectLayout(device_data, pCB, img_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700503 }
504 }
Mike Weiblen62d08a32017-03-07 22:18:27 -0700505
506 IMAGE_STATE *image_state = GetImageState(device_data, img_barrier->image);
507 if (image_state) {
508 VkImageUsageFlags usage_flags = image_state->createInfo.usage;
509 skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, false, usage_flags, func_name);
510 skip |= ValidateBarrierLayoutToImageUsage(device_data, img_barrier, true, usage_flags, func_name);
511 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700512 }
513 return skip;
514}
515
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700516void TransitionImageLayouts(layer_data *device_data, VkCommandBuffer cmdBuffer, uint32_t memBarrierCount,
517 const VkImageMemoryBarrier *pImgMemBarriers) {
518 GLOBAL_CB_NODE *pCB = GetCBNode(device_data, cmdBuffer);
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700519
520 for (uint32_t i = 0; i < memBarrierCount; ++i) {
521 auto mem_barrier = &pImgMemBarriers[i];
522 if (!mem_barrier) continue;
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700523
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600524 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, mem_barrier->image)->createInfo);
525 uint32_t level_count = ResolveRemainingLevels(&mem_barrier->subresourceRange, image_create_info->mipLevels);
526 uint32_t layer_count = ResolveRemainingLayers(&mem_barrier->subresourceRange, image_create_info->arrayLayers);
527
528 for (uint32_t j = 0; j < level_count; j++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700529 uint32_t level = mem_barrier->subresourceRange.baseMipLevel + j;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600530 for (uint32_t k = 0; k < layer_count; k++) {
Mark Lobodzinski6b6c50a2017-02-27 12:56:14 -0700531 uint32_t layer = mem_barrier->subresourceRange.baseArrayLayer + k;
532 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_COLOR_BIT);
533 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_DEPTH_BIT);
534 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_STENCIL_BIT);
535 TransitionImageAspectLayout(device_data, pCB, mem_barrier, level, layer, VK_IMAGE_ASPECT_METADATA_BIT);
536 }
537 }
538 }
539}
540
Tobin Ehlisc8266452017-04-07 12:20:30 -0600541bool VerifyImageLayout(layer_data const *device_data, GLOBAL_CB_NODE const *cb_node, IMAGE_STATE *image_state,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600542 VkImageSubresourceLayers subLayers, VkImageLayout explicit_layout, VkImageLayout optimal_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -0600543 const char *caller, UNIQUE_VALIDATION_ERROR_CODE msg_code, bool *error) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700544 const auto report_data = core_validation::GetReportData(device_data);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600545 const auto image = image_state->image;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600546 bool skip = false;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700547
548 for (uint32_t i = 0; i < subLayers.layerCount; ++i) {
549 uint32_t layer = i + subLayers.baseArrayLayer;
550 VkImageSubresource sub = {subLayers.aspectMask, subLayers.mipLevel, layer};
551 IMAGE_CMD_BUF_LAYOUT_NODE node;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600552 if (FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
553 if (node.layout != explicit_layout) {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600554 *error = true;
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600555 // TODO: Improve log message in the next pass
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600556 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
557 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
558 "%s: Cannot use image 0x%" PRIxLEAST64
559 " with specific layout %s that doesn't match the actual current layout %s.",
560 caller, reinterpret_cast<const uint64_t &>(image), string_VkImageLayout(explicit_layout),
561 string_VkImageLayout(node.layout));
Tobin Ehlise35b66a2017-03-15 12:18:31 -0600562 }
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700563 }
564 }
Tobin Ehlis2d85ec62017-03-14 15:38:48 -0600565 // If optimal_layout is not UNDEFINED, check that layout matches optimal for this case
566 if ((VK_IMAGE_LAYOUT_UNDEFINED != optimal_layout) && (explicit_layout != optimal_layout)) {
567 if (VK_IMAGE_LAYOUT_GENERAL == explicit_layout) {
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700568 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
569 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600570 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
571 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(cb_node->commandBuffer),
572 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
573 "%s: For optimal performance image 0x%" PRIxLEAST64 " layout should be %s instead of GENERAL.",
574 caller, reinterpret_cast<const uint64_t &>(image), string_VkImageLayout(optimal_layout));
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700575 }
576 } else {
Tobin Ehlisc8266452017-04-07 12:20:30 -0600577 *error = true;
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600578 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
579 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, msg_code, "DS",
580 "%s: Layout for image 0x%" PRIxLEAST64 " is %s but can only be %s or VK_IMAGE_LAYOUT_GENERAL. %s",
581 caller, reinterpret_cast<const uint64_t &>(image), string_VkImageLayout(explicit_layout),
582 string_VkImageLayout(optimal_layout), validation_error_map[msg_code]);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700583 }
584 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600585 return skip;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700586}
587
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700588void TransitionFinalSubpassLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB, const VkRenderPassBeginInfo *pRenderPassBegin,
589 FRAMEBUFFER_STATE *framebuffer_state) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700590 auto renderPass = GetRenderPassState(device_data, pRenderPassBegin->renderPass);
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700591 if (!renderPass) return;
592
593 const VkRenderPassCreateInfo *pRenderPassInfo = renderPass->createInfo.ptr();
594 if (framebuffer_state) {
595 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
596 auto image_view = framebuffer_state->createInfo.pAttachments[i];
597 SetImageViewLayout(device_data, pCB, image_view, pRenderPassInfo->pAttachments[i].finalLayout);
598 }
599 }
600}
601
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700602bool PreCallValidateCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo,
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700603 const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600604 bool skip = false;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700605 const debug_report_data *report_data = core_validation::GetReportData(device_data);
606
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600607 if (pCreateInfo->format == VK_FORMAT_UNDEFINED) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600608 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
609 VALIDATION_ERROR_00715, "IMAGE", "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED. %s",
610 validation_error_map[VALIDATION_ERROR_00715]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600611
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600612 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600613 }
614
615 const VkFormatProperties *properties = GetFormatProperties(device_data, pCreateInfo->format);
616
617 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) && (properties->linearTilingFeatures == 0)) {
618 std::stringstream ss;
619 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600620 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
621 VALIDATION_ERROR_02150, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02150]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600622
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600623 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600624 }
625
626 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) && (properties->optimalTilingFeatures == 0)) {
627 std::stringstream ss;
628 ss << "vkCreateImage format parameter (" << string_VkFormat(pCreateInfo->format) << ") is an unsupported format";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600629 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
630 VALIDATION_ERROR_02155, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02155]);
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600631
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600632 return skip;
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600633 }
634
635 // Validate that format supports usage as color attachment
636 if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
637 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
638 ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
639 std::stringstream ss;
640 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
641 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600642 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600643 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
644 VALIDATION_ERROR_02158, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02158]);
645 }
646 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
647 ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0)) {
648 std::stringstream ss;
649 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
650 << ") does not support requested Image usage type VK_IMAGE_USAGE_COLOR_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600651 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600652 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
653 VALIDATION_ERROR_02153, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02153]);
654 }
655 }
656
657 // Validate that format supports usage as depth/stencil attachment
658 if (pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
659 if ((pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL) &&
660 ((properties->optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
661 std::stringstream ss;
662 ss << "vkCreateImage: VkFormat for TILING_OPTIMAL image (" << string_VkFormat(pCreateInfo->format)
663 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600664 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600665 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
666 VALIDATION_ERROR_02159, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02159]);
667 }
668 if ((pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR) &&
669 ((properties->linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
670 std::stringstream ss;
671 ss << "vkCreateImage: VkFormat for TILING_LINEAR image (" << string_VkFormat(pCreateInfo->format)
672 << ") does not support requested Image usage type VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT";
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600673 skip |=
Jeremy Hayes96dcd812017-03-14 14:04:19 -0600674 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
675 VALIDATION_ERROR_02154, "IMAGE", "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02154]);
676 }
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700677 }
678
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700679 const VkImageFormatProperties *ImageFormatProperties = GetImageFormatProperties(
680 device_data, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling, pCreateInfo->usage, pCreateInfo->flags);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700681
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700682 VkDeviceSize imageGranularity = GetPhysicalDeviceProperties(device_data)->limits.bufferImageGranularity;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700683 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -0600684 // TODO : This is also covering 2918 & 2919. Break out into separate checks
Mark Lobodzinski688ed322017-01-27 11:13:21 -0700685 if ((pCreateInfo->extent.width <= 0) || (pCreateInfo->extent.height <= 0) || (pCreateInfo->extent.depth <= 0)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600686 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
687 VALIDATION_ERROR_02917, "Image",
688 "CreateImage extent is 0 for at least one required dimension for image: "
689 "Width = %d Height = %d Depth = %d. %s",
690 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
691 validation_error_map[VALIDATION_ERROR_02917]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700692 }
693
694 // TODO: VALIDATION_ERROR_02125 VALIDATION_ERROR_02126 VALIDATION_ERROR_02128 VALIDATION_ERROR_00720
695 // All these extent-related VUs should be checked here
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700696 if ((pCreateInfo->extent.depth > ImageFormatProperties->maxExtent.depth) ||
697 (pCreateInfo->extent.width > ImageFormatProperties->maxExtent.width) ||
698 (pCreateInfo->extent.height > ImageFormatProperties->maxExtent.height)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600699 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
700 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
701 "CreateImage extents exceed allowable limits for format: "
702 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
703 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
704 ImageFormatProperties->maxExtent.width, ImageFormatProperties->maxExtent.height,
705 ImageFormatProperties->maxExtent.depth, string_VkFormat(pCreateInfo->format));
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700706 }
707
Dave Houlton1150cf52017-04-27 14:38:11 -0600708 uint64_t totalSize =
709 ((uint64_t)pCreateInfo->extent.width * (uint64_t)pCreateInfo->extent.height * (uint64_t)pCreateInfo->extent.depth *
710 (uint64_t)pCreateInfo->arrayLayers * (uint64_t)pCreateInfo->samples * (uint64_t)FormatSize(pCreateInfo->format) +
711 (uint64_t)imageGranularity) &
712 ~(uint64_t)imageGranularity;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700713
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700714 if (totalSize > ImageFormatProperties->maxResourceSize) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600715 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
716 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
717 "CreateImage resource size exceeds allowable maximum "
718 "Image resource size = 0x%" PRIxLEAST64 ", maximum resource size = 0x%" PRIxLEAST64 " ",
719 totalSize, ImageFormatProperties->maxResourceSize);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700720 }
721
722 // TODO: VALIDATION_ERROR_02132
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700723 if (pCreateInfo->mipLevels > ImageFormatProperties->maxMipLevels) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600724 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
725 IMAGE_INVALID_FORMAT_LIMITS_VIOLATION, "Image",
726 "CreateImage mipLevels=%d exceeds allowable maximum supported by format of %d", pCreateInfo->mipLevels,
727 ImageFormatProperties->maxMipLevels);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700728 }
729
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700730 if (pCreateInfo->arrayLayers > ImageFormatProperties->maxArrayLayers) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600731 skip |= log_msg(
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700732 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__, VALIDATION_ERROR_02133,
733 "Image", "CreateImage arrayLayers=%d exceeds allowable maximum supported by format of %d. %s", pCreateInfo->arrayLayers,
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700734 ImageFormatProperties->maxArrayLayers, validation_error_map[VALIDATION_ERROR_02133]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700735 }
736
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -0700737 if ((pCreateInfo->samples & ImageFormatProperties->sampleCounts) == 0) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600738 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
739 VALIDATION_ERROR_02138, "Image", "CreateImage samples %s is not supported by format 0x%.8X. %s",
740 string_VkSampleCountFlagBits(pCreateInfo->samples), ImageFormatProperties->sampleCounts,
741 validation_error_map[VALIDATION_ERROR_02138]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700742 }
743
744 if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600745 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, 0, __LINE__,
746 VALIDATION_ERROR_00731, "Image",
747 "vkCreateImage parameter, pCreateInfo->initialLayout, must be VK_IMAGE_LAYOUT_UNDEFINED or "
748 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
749 validation_error_map[VALIDATION_ERROR_00731]);
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700750 }
751
Mark Lobodzinski847b60c2017-03-13 09:32:45 -0600752 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600753 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
754 VALIDATION_ERROR_02143, "DS",
755 "vkCreateImage(): the sparseBinding device feature is disabled: Images cannot be created with the "
756 "VK_IMAGE_CREATE_SPARSE_BINDING_BIT set. %s",
757 validation_error_map[VALIDATION_ERROR_02143]);
Mark Lobodzinski847b60c2017-03-13 09:32:45 -0600758 }
759
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600760 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600761 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
762 DRAWSTATE_INVALID_FEATURE, "DS",
763 "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the "
764 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set.");
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -0600765 }
766
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -0600767 return skip;
Mark Lobodzinski90224de2017-01-26 15:23:11 -0700768}
769
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700770void PostCallRecordCreateImage(layer_data *device_data, const VkImageCreateInfo *pCreateInfo, VkImage *pImage) {
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700771 IMAGE_LAYOUT_NODE image_state;
772 image_state.layout = pCreateInfo->initialLayout;
773 image_state.format = pCreateInfo->format;
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700774 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 -0700775 ImageSubresourcePair subpair{*pImage, false, VkImageSubresource()};
Mark Lobodzinski214144a2017-01-27 14:25:32 -0700776 (*core_validation::GetImageSubresourceMap(device_data))[*pImage].push_back(subpair);
777 (*core_validation::GetImageLayoutMap(device_data))[subpair] = image_state;
Mark Lobodzinski42fe5f72017-01-11 11:36:16 -0700778}
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700779
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700780bool PreCallValidateDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700781 const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700782 *image_state = core_validation::GetImageState(device_data, image);
Dave Houlton1150cf52017-04-27 14:38:11 -0600783 *obj_struct = {reinterpret_cast<uint64_t &>(image), kVulkanObjectTypeImage};
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700784 if (disabled->destroy_image) return false;
785 bool skip = false;
786 if (*image_state) {
787 skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743);
788 }
789 return skip;
790}
791
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700792void PostCallRecordDestroyImage(layer_data *device_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) {
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700793 core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct);
794 // Clean up memory mapping, bindings and range references for image
795 for (auto mem_binding : image_state->GetBoundMemory()) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700796 auto mem_info = core_validation::GetMemObjInfo(device_data, mem_binding);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700797 if (mem_info) {
798 core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info);
799 }
800 }
Mark Lobodzinski33826372017-04-13 11:10:11 -0600801 core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, kVulkanObjectTypeImage);
Mark Lobodzinski9ef5d562017-01-27 12:28:30 -0700802 // Remove image from imageMap
803 core_validation::GetImageMap(device_data)->erase(image);
804 std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap =
805 core_validation::GetImageSubresourceMap(device_data);
806
807 const auto &sub_entry = imageSubresourceMap->find(image);
808 if (sub_entry != imageSubresourceMap->end()) {
809 for (const auto &pair : sub_entry->second) {
810 core_validation::GetImageLayoutMap(device_data)->erase(pair);
811 }
812 imageSubresourceMap->erase(sub_entry);
813 }
814}
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700815
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700816bool ValidateImageAttributes(layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700817 bool skip = false;
818 const debug_report_data *report_data = core_validation::GetReportData(device_data);
819
820 if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
821 char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
822 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
823 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
824 }
825
Dave Houlton1d2022c2017-03-29 11:43:58 -0600826 if (FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700827 char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
828 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
829 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
830 validation_error_map[VALIDATION_ERROR_01088]);
Dave Houlton1d2022c2017-03-29 11:43:58 -0600831 } else if (FormatIsCompressed(image_state->createInfo.format)) {
Mark Lobodzinskic409a582017-01-27 15:16:01 -0700832 char const str[] = "vkCmdClearColorImage called with compressed image.";
833 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
834 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
835 validation_error_map[VALIDATION_ERROR_01088]);
836 }
837
838 if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
839 char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
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_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str,
842 validation_error_map[VALIDATION_ERROR_01084]);
843 }
844 return skip;
845}
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700846
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600847uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) {
848 // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS
849 uint32_t mip_level_count = range->levelCount;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700850 if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600851 mip_level_count = mip_levels - range->baseMipLevel;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700852 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600853 return mip_level_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700854}
855
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600856uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) {
857 // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS
858 uint32_t array_layer_count = range->layerCount;
859 if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
860 array_layer_count = layers - range->baseArrayLayer;
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700861 }
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600862 return array_layer_count;
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700863}
864
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700865bool VerifyClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *image_state,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700866 VkImageSubresourceRange range, VkImageLayout dest_image_layout, const char *func_name) {
867 bool skip = false;
868 const debug_report_data *report_data = core_validation::GetReportData(device_data);
869
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600870 uint32_t level_count = ResolveRemainingLevels(&range, image_state->createInfo.mipLevels);
871 uint32_t layer_count = ResolveRemainingLayers(&range, image_state->createInfo.arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700872
873 if (dest_image_layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
874 if (dest_image_layout == VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700875 if (image_state->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
876 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600877 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
878 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700879 "%s: Layout for cleared image should be TRANSFER_DST_OPTIMAL instead of GENERAL.", func_name);
880 }
881 } else {
882 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01086;
883 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
884 error_code = VALIDATION_ERROR_01101;
885 } else {
886 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
887 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -0600888 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
889 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, error_code, "DS",
890 "%s: Layout for cleared image is %s but can only be "
891 "TRANSFER_DST_OPTIMAL or GENERAL. %s",
892 func_name, string_VkImageLayout(dest_image_layout), validation_error_map[error_code]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700893 }
894 }
895
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600896 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
897 uint32_t level = level_index + range.baseMipLevel;
898 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
899 uint32_t layer = layer_index + range.baseArrayLayer;
900 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700901 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700902 if (FindCmdBufLayout(device_data, cb_node, image_state->image, sub, node)) {
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700903 if (node.layout != dest_image_layout) {
904 UNIQUE_VALIDATION_ERROR_CODE error_code = VALIDATION_ERROR_01085;
905 if (strcmp(func_name, "vkCmdClearDepthStencilImage()") == 0) {
906 error_code = VALIDATION_ERROR_01100;
907 } else {
908 assert(strcmp(func_name, "vkCmdClearColorImage()") == 0);
909 }
910 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
911 __LINE__, error_code, "DS",
912 "%s: Cannot clear an image whose layout is %s and "
913 "doesn't match the current layout %s. %s",
914 func_name, string_VkImageLayout(dest_image_layout), string_VkImageLayout(node.layout),
915 validation_error_map[error_code]);
916 }
917 }
918 }
919 }
920
921 return skip;
922}
923
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700924void RecordClearImageLayout(layer_data *device_data, GLOBAL_CB_NODE *cb_node, VkImage image, VkImageSubresourceRange range,
925 VkImageLayout dest_image_layout) {
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600926 VkImageCreateInfo *image_create_info = &(GetImageState(device_data, image)->createInfo);
927 uint32_t level_count = ResolveRemainingLevels(&range, image_create_info->mipLevels);
928 uint32_t layer_count = ResolveRemainingLayers(&range, image_create_info->arrayLayers);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700929
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -0600930 for (uint32_t level_index = 0; level_index < level_count; ++level_index) {
931 uint32_t level = level_index + range.baseMipLevel;
932 for (uint32_t layer_index = 0; layer_index < layer_count; ++layer_index) {
933 uint32_t layer = layer_index + range.baseArrayLayer;
934 VkImageSubresource sub = {range.aspectMask, level, layer};
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700935 IMAGE_CMD_BUF_LAYOUT_NODE node;
Mark Lobodzinski3c0f6362017-02-01 13:35:48 -0700936 if (!FindCmdBufLayout(device_data, cb_node, image, sub, node)) {
937 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 -0700938 }
939 }
940 }
941}
942
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700943bool PreCallValidateCmdClearColorImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700944 VkImageLayout imageLayout, uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
945 bool skip = false;
946 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700947 auto cb_node = GetCBNode(dev_data, commandBuffer);
948 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700949 if (cb_node && image_state) {
950 skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCmdClearColorImage()", VALIDATION_ERROR_02527);
Mike Schuchardt9c582402017-02-23 15:57:37 -0700951 skip |= ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdClearColorImage()", VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT,
952 VALIDATION_ERROR_01095);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700953 skip |= ValidateCmd(dev_data, cb_node, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
954 skip |= insideRenderPass(dev_data, cb_node, "vkCmdClearColorImage()", VALIDATION_ERROR_01096);
955 for (uint32_t i = 0; i < rangeCount; ++i) {
956 skip |= ValidateImageAttributes(dev_data, image_state, pRanges[i]);
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700957 skip |= VerifyClearImageLayout(dev_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearColorImage()");
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700958 }
959 }
960 return skip;
961}
962
963// This state recording routine is shared between ClearColorImage and ClearDepthStencilImage
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700964void PreCallRecordCmdClearImage(layer_data *dev_data, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
965 uint32_t rangeCount, const VkImageSubresourceRange *pRanges, CMD_TYPE cmd_type) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700966 auto cb_node = GetCBNode(dev_data, commandBuffer);
967 auto image_state = GetImageState(dev_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700968 if (cb_node && image_state) {
969 AddCommandBufferBindingImage(dev_data, cb_node, image_state);
970 std::function<bool()> function = [=]() {
971 SetImageMemoryValid(dev_data, image_state, true);
972 return false;
973 };
974 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700975 core_validation::UpdateCmdBufferLastCmd(cb_node, cmd_type);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700976 for (uint32_t i = 0; i < rangeCount; ++i) {
977 RecordClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout);
978 }
979 }
980}
981
Tobin Ehlis58c884f2017-02-08 12:15:27 -0700982bool PreCallValidateCmdClearDepthStencilImage(layer_data *device_data, VkCommandBuffer commandBuffer, VkImage image,
983 VkImageLayout imageLayout, uint32_t rangeCount,
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700984 const VkImageSubresourceRange *pRanges) {
985 bool skip = false;
Mark Lobodzinski1241a312017-02-01 10:57:21 -0700986 const debug_report_data *report_data = core_validation::GetReportData(device_data);
987
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700988 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700989 auto cb_node = GetCBNode(device_data, commandBuffer);
990 auto image_state = GetImageState(device_data, image);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700991 if (cb_node && image_state) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -0700992 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_02528);
Mike Schuchardt9c582402017-02-23 15:57:37 -0700993 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearDepthStencilImage()", VK_QUEUE_GRAPHICS_BIT,
994 VALIDATION_ERROR_01110);
Mark Lobodzinski1241a312017-02-01 10:57:21 -0700995 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
996 skip |= insideRenderPass(device_data, cb_node, "vkCmdClearDepthStencilImage()", VALIDATION_ERROR_01111);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -0700997 for (uint32_t i = 0; i < rangeCount; ++i) {
Mark Lobodzinski9c93dbd2017-02-02 08:31:18 -0700998 skip |=
999 VerifyClearImageLayout(device_data, cb_node, image_state, pRanges[i], imageLayout, "vkCmdClearDepthStencilImage()");
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001000 // Image aspect must be depth or stencil or both
1001 if (((pRanges[i].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1002 ((pRanges[i].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1003 char const str[] =
1004 "vkCmdClearDepthStencilImage aspectMasks for all subresource ranges must be "
1005 "set to VK_IMAGE_ASPECT_DEPTH_BIT and/or VK_IMAGE_ASPECT_STENCIL_BIT";
1006 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1007 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
1008 }
1009 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001010 if (image_state && !FormatIsDepthOrStencil(image_state->createInfo.format)) {
Mark Lobodzinski1241a312017-02-01 10:57:21 -07001011 char const str[] = "vkCmdClearDepthStencilImage called without a depth/stencil image.";
1012 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
1013 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01103, "IMAGE", "%s. %s", str,
1014 validation_error_map[VALIDATION_ERROR_01103]);
Mark Lobodzinskid81d1012017-02-01 09:03:06 -07001015 }
1016 }
1017 return skip;
1018}
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001019
1020// Returns true if [x, xoffset] and [y, yoffset] overlap
1021static bool RangesIntersect(int32_t start, uint32_t start_offset, int32_t end, uint32_t end_offset) {
1022 bool result = false;
1023 uint32_t intersection_min = std::max(static_cast<uint32_t>(start), static_cast<uint32_t>(end));
1024 uint32_t intersection_max = std::min(static_cast<uint32_t>(start) + start_offset, static_cast<uint32_t>(end) + end_offset);
1025
1026 if (intersection_max > intersection_min) {
1027 result = true;
1028 }
1029 return result;
1030}
1031
1032// Returns true if two VkImageCopy structures overlap
1033static bool RegionIntersects(const VkImageCopy *src, const VkImageCopy *dst, VkImageType type) {
1034 bool result = false;
1035 if ((src->srcSubresource.mipLevel == dst->dstSubresource.mipLevel) &&
1036 (RangesIntersect(src->srcSubresource.baseArrayLayer, src->srcSubresource.layerCount, dst->dstSubresource.baseArrayLayer,
1037 dst->dstSubresource.layerCount))) {
1038 result = true;
1039 switch (type) {
1040 case VK_IMAGE_TYPE_3D:
1041 result &= RangesIntersect(src->srcOffset.z, src->extent.depth, dst->dstOffset.z, dst->extent.depth);
1042 // Intentionally fall through to 2D case
1043 case VK_IMAGE_TYPE_2D:
1044 result &= RangesIntersect(src->srcOffset.y, src->extent.height, dst->dstOffset.y, dst->extent.height);
1045 // Intentionally fall through to 1D case
1046 case VK_IMAGE_TYPE_1D:
1047 result &= RangesIntersect(src->srcOffset.x, src->extent.width, dst->dstOffset.x, dst->extent.width);
1048 break;
1049 default:
1050 // Unrecognized or new IMAGE_TYPE enums will be caught in parameter_validation
1051 assert(false);
1052 }
1053 }
1054 return result;
1055}
1056
Dave Houltonfc1a4052017-04-27 14:32:45 -06001057// Returns non-zero if offset and extent exceed image extents
1058static const uint32_t x_bit = 1;
1059static const uint32_t y_bit = 2;
1060static const uint32_t z_bit = 4;
Dave Houlton1150cf52017-04-27 14:38:11 -06001061static uint32_t ExceedsBounds(const VkOffset3D *offset, const VkExtent3D *extent, const VkExtent3D *image_extent) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001062 uint32_t result = 0;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001063 // Extents/depths cannot be negative but checks left in for clarity
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001064 if ((offset->z + extent->depth > image_extent->depth) || (offset->z < 0) ||
1065 ((offset->z + static_cast<int32_t>(extent->depth)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001066 result |= z_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001067 }
1068 if ((offset->y + extent->height > image_extent->height) || (offset->y < 0) ||
1069 ((offset->y + static_cast<int32_t>(extent->height)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001070 result |= y_bit;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001071 }
1072 if ((offset->x + extent->width > image_extent->width) || (offset->x < 0) ||
1073 ((offset->x + static_cast<int32_t>(extent->width)) < 0)) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001074 result |= x_bit;
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001075 }
1076 return result;
1077}
1078
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001079// Test if two VkExtent3D structs are equivalent
1080static inline bool IsExtentEqual(const VkExtent3D *extent, const VkExtent3D *other_extent) {
1081 bool result = true;
1082 if ((extent->width != other_extent->width) || (extent->height != other_extent->height) ||
1083 (extent->depth != other_extent->depth)) {
1084 result = false;
1085 }
1086 return result;
1087}
1088
1089// Returns the image extent of a specific subresource.
1090static inline VkExtent3D GetImageSubresourceExtent(const IMAGE_STATE *img, const VkImageSubresourceLayers *subresource) {
1091 const uint32_t mip = subresource->mipLevel;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001092
1093 // Return zero extent if mip level doesn't exist
Dave Houlton1150cf52017-04-27 14:38:11 -06001094 if (mip >= img->createInfo.mipLevels) {
1095 return VkExtent3D{0, 0, 0};
Dave Houltonfc1a4052017-04-27 14:32:45 -06001096 }
Dave Houlton1150cf52017-04-27 14:38:11 -06001097
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001098 // Don't allow mip adjustment to create 0 dim, but pass along a 0 if that's what subresource specified
Dave Houltonfc1a4052017-04-27 14:32:45 -06001099 VkExtent3D extent = img->createInfo.extent;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001100 extent.width = (0 == extent.width ? 0 : std::max(1U, extent.width >> mip));
1101 extent.height = (0 == extent.height ? 0 : std::max(1U, extent.height >> mip));
1102 extent.depth = (0 == extent.depth ? 0 : std::max(1U, extent.depth >> mip));
Dave Houltonfc1a4052017-04-27 14:32:45 -06001103
1104 // For 2D images, the number of layers present becomes the effective depth (for 2D <-> 3D copies)
1105 // In this case the depth extent is not diminished with mip level
Dave Houlton1150cf52017-04-27 14:38:11 -06001106 if (VK_IMAGE_TYPE_2D == img->createInfo.imageType) {
Dave Houltonfc1a4052017-04-27 14:32:45 -06001107 extent.depth = img->createInfo.arrayLayers;
1108 }
1109
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001110 return extent;
1111}
1112
1113// Test if the extent argument has all dimensions set to 0.
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001114static inline bool IsExtentAllZeroes(const VkExtent3D *extent) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001115 return ((extent->width == 0) && (extent->height == 0) && (extent->depth == 0));
1116}
1117
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001118// Test if the extent argument has any dimensions set to 0.
1119static inline bool IsExtentSizeZero(const VkExtent3D *extent) {
1120 return ((extent->width == 0) || (extent->height == 0) || (extent->depth == 0));
1121}
1122
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001123// Returns the image transfer granularity for a specific image scaled by compressed block size if necessary.
1124static inline VkExtent3D GetScaledItg(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const IMAGE_STATE *img) {
1125 // Default to (0, 0, 0) granularity in case we can't find the real granularity for the physical device.
1126 VkExtent3D granularity = {0, 0, 0};
1127 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
1128 if (pPool) {
1129 granularity =
1130 GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].minImageTransferGranularity;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001131 if (FormatIsCompressed(img->createInfo.format)) {
1132 auto block_size = FormatCompressedTexelBlockExtent(img->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001133 granularity.width *= block_size.width;
1134 granularity.height *= block_size.height;
1135 }
1136 }
1137 return granularity;
1138}
1139
1140// Test elements of a VkExtent3D structure against alignment constraints contained in another VkExtent3D structure
1141static inline bool IsExtentAligned(const VkExtent3D *extent, const VkExtent3D *granularity) {
1142 bool valid = true;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001143 if ((SafeModulo(extent->depth, granularity->depth) != 0) || (SafeModulo(extent->width, granularity->width) != 0) ||
1144 (SafeModulo(extent->height, granularity->height) != 0)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001145 valid = false;
1146 }
1147 return valid;
1148}
1149
1150// Check elements of a VkOffset3D structure against a queue family's Image Transfer Granularity values
1151static inline bool CheckItgOffset(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkOffset3D *offset,
1152 const VkExtent3D *granularity, const uint32_t i, const char *function, const char *member) {
1153 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1154 bool skip = false;
1155 VkExtent3D offset_extent = {};
1156 offset_extent.width = static_cast<uint32_t>(abs(offset->x));
1157 offset_extent.height = static_cast<uint32_t>(abs(offset->y));
1158 offset_extent.depth = static_cast<uint32_t>(abs(offset->z));
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001159 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001160 // If the queue family image transfer granularity is (0, 0, 0), then the offset must always be (0, 0, 0)
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001161 if (IsExtentAllZeroes(&offset_extent) == false) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001162 skip |=
1163 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1164 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1165 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) must be (x=0, y=0, z=0) "
1166 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1167 function, i, member, offset->x, offset->y, offset->z);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001168 }
1169 } else {
1170 // If the queue family image transfer granularity is not (0, 0, 0), then the offset dimensions must always be even
1171 // integer multiples of the image transfer granularity.
1172 if (IsExtentAligned(&offset_extent, granularity) == false) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001173 skip |= log_msg(
1174 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1175 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1176 "%s: pRegion[%d].%s (x=%d, y=%d, z=%d) dimensions must be even integer "
1177 "multiples of this command buffer's queue family image transfer granularity (w=%d, h=%d, d=%d).",
1178 function, i, member, offset->x, offset->y, offset->z, granularity->width, granularity->height, granularity->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001179 }
1180 }
1181 return skip;
1182}
1183
1184// Check elements of a VkExtent3D structure against a queue family's Image Transfer Granularity values
1185static inline bool CheckItgExtent(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkExtent3D *extent,
1186 const VkOffset3D *offset, const VkExtent3D *granularity, const VkExtent3D *subresource_extent,
1187 const uint32_t i, const char *function, const char *member) {
1188 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1189 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07001190 if (IsExtentAllZeroes(granularity)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001191 // If the queue family image transfer granularity is (0, 0, 0), then the extent must always match the image
1192 // subresource extent.
1193 if (IsExtentEqual(extent, subresource_extent) == false) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001194 skip |=
1195 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1196 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
1197 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d) "
1198 "when the command buffer's queue family image transfer granularity is (w=0, h=0, d=0).",
1199 function, i, member, extent->width, extent->height, extent->depth, subresource_extent->width,
1200 subresource_extent->height, subresource_extent->depth);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001201 }
1202 } else {
1203 // If the queue family image transfer granularity is not (0, 0, 0), then the extent dimensions must always be even
1204 // integer multiples of the image transfer granularity or the offset + extent dimensions must always match the image
1205 // subresource extent dimensions.
1206 VkExtent3D offset_extent_sum = {};
1207 offset_extent_sum.width = static_cast<uint32_t>(abs(offset->x)) + extent->width;
1208 offset_extent_sum.height = static_cast<uint32_t>(abs(offset->y)) + extent->height;
1209 offset_extent_sum.depth = static_cast<uint32_t>(abs(offset->z)) + extent->depth;
1210 if ((IsExtentAligned(extent, granularity) == false) && (IsExtentEqual(&offset_extent_sum, subresource_extent) == false)) {
1211 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001212 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1213 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001214 "%s: pRegion[%d].%s (w=%d, h=%d, d=%d) dimensions must be even integer multiples of this command buffer's "
1215 "queue family image transfer granularity (w=%d, h=%d, d=%d) or offset (x=%d, y=%d, z=%d) + "
1216 "extent (w=%d, h=%d, d=%d) must match the image subresource extents (w=%d, h=%d, d=%d).",
1217 function, i, member, extent->width, extent->height, extent->depth, granularity->width, granularity->height,
1218 granularity->depth, offset->x, offset->y, offset->z, extent->width, extent->height, extent->depth,
1219 subresource_extent->width, subresource_extent->height, subresource_extent->depth);
1220 }
1221 }
1222 return skip;
1223}
1224
1225// Check a uint32_t width or stride value against a queue family's Image Transfer Granularity width value
1226static inline bool CheckItgInt(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const uint32_t value,
1227 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1228 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1229
1230 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001231 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001232 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1233 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001234 "%s: pRegion[%d].%s (%d) must be an even integer multiple of this command buffer's queue family image "
1235 "transfer granularity width (%d).",
1236 function, i, member, value, granularity);
1237 }
1238 return skip;
1239}
1240
1241// Check a VkDeviceSize value against a queue family's Image Transfer Granularity width value
1242static inline bool CheckItgSize(layer_data *device_data, const GLOBAL_CB_NODE *cb_node, const VkDeviceSize value,
1243 const uint32_t granularity, const uint32_t i, const char *function, const char *member) {
1244 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1245 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001246 if (SafeModulo(value, granularity) != 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001247 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1248 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_IMAGE_TRANSFER_GRANULARITY, "DS",
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001249 "%s: pRegion[%d].%s (%" PRIdLEAST64
1250 ") must be an even integer multiple of this command buffer's queue family image transfer "
1251 "granularity width (%d).",
1252 function, i, member, value, granularity);
1253 }
1254 return skip;
1255}
1256
1257// Check valid usage Image Tranfer Granularity requirements for elements of a VkBufferImageCopy structure
1258bool ValidateCopyBufferImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
1259 const IMAGE_STATE *img, const VkBufferImageCopy *region,
1260 const uint32_t i, const char *function) {
1261 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06001262 if (FormatIsCompressed(img->createInfo.format) == true) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001263 // TODO: Add granularity checking for compressed formats
1264
1265 // bufferRowLength must be a multiple of the compressed texel block width
1266 // bufferImageHeight must be a multiple of the compressed texel block height
1267 // all members of imageOffset must be a multiple of the corresponding dimensions of the compressed texel block
1268 // bufferOffset must be a multiple of the compressed texel block size in bytes
1269 // imageExtent.width must be a multiple of the compressed texel block width or (imageExtent.width + imageOffset.x)
1270 // must equal the image subresource width
1271 // imageExtent.height must be a multiple of the compressed texel block height or (imageExtent.height + imageOffset.y)
1272 // must equal the image subresource height
1273 // imageExtent.depth must be a multiple of the compressed texel block depth or (imageExtent.depth + imageOffset.z)
1274 // must equal the image subresource depth
1275 } else {
1276 VkExtent3D granularity = GetScaledItg(device_data, cb_node, img);
1277 skip |= CheckItgSize(device_data, cb_node, region->bufferOffset, granularity.width, i, function, "bufferOffset");
1278 skip |= CheckItgInt(device_data, cb_node, region->bufferRowLength, granularity.width, i, function, "bufferRowLength");
1279 skip |= CheckItgInt(device_data, cb_node, region->bufferImageHeight, granularity.width, i, function, "bufferImageHeight");
1280 skip |= CheckItgOffset(device_data, cb_node, &region->imageOffset, &granularity, i, function, "imageOffset");
1281 VkExtent3D subresource_extent = GetImageSubresourceExtent(img, &region->imageSubresource);
1282 skip |= CheckItgExtent(device_data, cb_node, &region->imageExtent, &region->imageOffset, &granularity, &subresource_extent,
1283 i, function, "imageExtent");
1284 }
1285 return skip;
1286}
1287
1288// Check valid usage Image Tranfer Granularity requirements for elements of a VkImageCopy structure
1289bool ValidateCopyImageTransferGranularityRequirements(layer_data *device_data, const GLOBAL_CB_NODE *cb_node,
1290 const IMAGE_STATE *img, const VkImageCopy *region, const uint32_t i,
1291 const char *function) {
1292 bool skip = false;
1293 VkExtent3D granularity = GetScaledItg(device_data, cb_node, img);
1294 skip |= CheckItgOffset(device_data, cb_node, &region->srcOffset, &granularity, i, function, "srcOffset");
1295 skip |= CheckItgOffset(device_data, cb_node, &region->dstOffset, &granularity, i, function, "dstOffset");
1296 VkExtent3D subresource_extent = GetImageSubresourceExtent(img, &region->dstSubresource);
1297 skip |= CheckItgExtent(device_data, cb_node, &region->extent, &region->dstOffset, &granularity, &subresource_extent, i,
1298 function, "extent");
1299 return skip;
1300}
1301
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001302bool PreCallValidateCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001303 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1304 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001305 bool skip = false;
1306 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1307 VkCommandBuffer command_buffer = cb_node->commandBuffer;
1308
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001309 for (uint32_t i = 0; i < region_count; i++) {
1310 if (regions[i].srcSubresource.layerCount == 0) {
1311 std::stringstream ss;
1312 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] srcSubresource is zero";
1313 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1314 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s",
1315 ss.str().c_str());
1316 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001317
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001318 if (regions[i].dstSubresource.layerCount == 0) {
1319 std::stringstream ss;
1320 ss << "vkCmdCopyImage: number of layers in pRegions[" << i << "] dstSubresource is zero";
1321 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1322 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s",
1323 ss.str().c_str());
1324 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001325
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001326 if (!GetDeviceExtensions(device_data)->khr_maintenance1_enabled) {
1327 // For each region the layerCount member of srcSubresource and dstSubresource must match
1328 if (regions[i].srcSubresource.layerCount != regions[i].dstSubresource.layerCount) {
1329 std::stringstream ss;
1330 ss << "vkCmdCopyImage: number of layers in source and destination subresources for pRegions[" << i
1331 << "] do not match";
1332 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1333 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01198, "IMAGE", "%s. %s",
1334 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01198]);
1335 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001336 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001337
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001338 // For each region, the aspectMask member of srcSubresource and dstSubresource must match
1339 if (regions[i].srcSubresource.aspectMask != regions[i].dstSubresource.aspectMask) {
1340 char const str[] = "vkCmdCopyImage: Src and dest aspectMasks for each region must match";
1341 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1342 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01197, "IMAGE", "%s. %s", str,
1343 validation_error_map[VALIDATION_ERROR_01197]);
1344 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001345
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001346 // For each region, the aspectMask member of srcSubresource must be present in the source image
1347 if (!VerifyAspectsPresent(regions[i].srcSubresource.aspectMask, src_image_state->createInfo.format)) {
1348 std::stringstream ss;
1349 ss << "vkCmdCopyImage: pRegion[" << i
1350 << "] srcSubresource.aspectMask cannot specify aspects not present in source image";
1351 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1352 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01200, "IMAGE", "%s. %s",
1353 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01200]);
1354 }
1355
1356 // For each region, the aspectMask member of dstSubresource must be present in the destination image
1357 if (!VerifyAspectsPresent(regions[i].dstSubresource.aspectMask, dst_image_state->createInfo.format)) {
1358 std::stringstream ss;
1359 ss << "vkCmdCopyImage: pRegion[" << i << "] dstSubresource.aspectMask cannot specify aspects not present in dest image";
1360 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1361 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01201, "IMAGE", "%s. %s",
1362 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01201]);
1363 }
1364
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001365 // AspectMask must not contain VK_IMAGE_ASPECT_METADATA_BIT
1366 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) ||
1367 (regions[i].dstSubresource.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)) {
1368 std::stringstream ss;
1369 ss << "vkCmdCopyImage: pRegions[" << i << "] may not specify aspectMask containing VK_IMAGE_ASPECT_METADATA_BIT";
1370 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1371 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01222, "IMAGE", "%s. %s",
1372 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01222]);
1373 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001374
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001375 // For each region, if aspectMask contains VK_IMAGE_ASPECT_COLOR_BIT, it must not contain either of
1376 // VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT
1377 if ((regions[i].srcSubresource.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) &&
1378 (regions[i].srcSubresource.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) {
1379 char const str[] = "vkCmdCopyImage aspectMask cannot specify both COLOR and DEPTH/STENCIL aspects";
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 &>(command_buffer), __LINE__, VALIDATION_ERROR_01221, "IMAGE", "%s. %s", str,
1382 validation_error_map[VALIDATION_ERROR_01221]);
1383 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001384
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001385 if (!GetDeviceExtensions(device_data)->khr_maintenance1_enabled) {
1386 // If either of the calling command's src_image or dst_image parameters are of VkImageType VK_IMAGE_TYPE_3D,
1387 // the baseArrayLayer and layerCount members of both srcSubresource and dstSubresource must be 0 and 1, respectively
1388 if (((src_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) ||
1389 (dst_image_state->createInfo.imageType == VK_IMAGE_TYPE_3D)) &&
1390 ((regions[i].srcSubresource.baseArrayLayer != 0) || (regions[i].srcSubresource.layerCount != 1) ||
1391 (regions[i].dstSubresource.baseArrayLayer != 0) || (regions[i].dstSubresource.layerCount != 1))) {
1392 std::stringstream ss;
1393 ss << "vkCmdCopyImage: src or dstImage type was IMAGE_TYPE_3D, but in subRegion[" << i
1394 << "] baseArrayLayer was not zero or layerCount was not 1.";
1395 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1396 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01199, "IMAGE", "%s. %s",
1397 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01199]);
1398 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001399 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001400
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001401 // MipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
1402 if (regions[i].srcSubresource.mipLevel >= src_image_state->createInfo.mipLevels) {
1403 std::stringstream ss;
1404 ss << "vkCmdCopyImage: pRegions[" << i
1405 << "] specifies a src mipLevel greater than the number specified when the srcImage was created.";
1406 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1407 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s",
1408 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]);
1409 }
1410 if (regions[i].dstSubresource.mipLevel >= dst_image_state->createInfo.mipLevels) {
1411 std::stringstream ss;
1412 ss << "vkCmdCopyImage: pRegions[" << i
1413 << "] specifies a dst mipLevel greater than the number specified when the dstImage was created.";
1414 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1415 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01223, "IMAGE", "%s. %s",
1416 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01223]);
1417 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001418
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001419 // (baseArrayLayer + layerCount) must be less than or equal to the arrayLayers specified in VkImageCreateInfo when the
1420 // image was created
1421 if ((regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount) >
1422 src_image_state->createInfo.arrayLayers) {
1423 std::stringstream ss;
1424 ss << "vkCmdCopyImage: srcImage arrayLayers was " << src_image_state->createInfo.arrayLayers << " but subRegion[" << i
1425 << "] baseArrayLayer + layerCount is "
1426 << (regions[i].srcSubresource.baseArrayLayer + regions[i].srcSubresource.layerCount);
1427 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1428 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s",
1429 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]);
1430 }
1431 if ((regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount) >
1432 dst_image_state->createInfo.arrayLayers) {
1433 std::stringstream ss;
1434 ss << "vkCmdCopyImage: dstImage arrayLayers was " << dst_image_state->createInfo.arrayLayers << " but subRegion[" << i
1435 << "] baseArrayLayer + layerCount is "
1436 << (regions[i].dstSubresource.baseArrayLayer + regions[i].dstSubresource.layerCount);
1437 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1438 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01224, "IMAGE", "%s. %s",
1439 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01224]);
1440 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001441
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001442 // Check region extents for 1D-1D, 2D-2D, and 3D-3D copies
1443 if (src_image_state->createInfo.imageType == dst_image_state->createInfo.imageType) {
1444 // The source region specified by a given element of regions must be a region that is contained within srcImage
Dave Houltonfc1a4052017-04-27 14:32:45 -06001445 VkExtent3D img_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
1446 if (0 != ExceedsBounds(&regions[i].srcOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001447 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001448 ss << "vkCmdCopyImage: Source pRegion[" << i << "] with mipLevel [ " << regions[i].srcSubresource.mipLevel
1449 << " ], offset [ " << regions[i].srcOffset.x << ", " << regions[i].srcOffset.y << ", " << regions[i].srcOffset.z
1450 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1451 << regions[i].extent.depth << " ] exceeds the source image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001452 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1453 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01175, "IMAGE", "%s. %s",
1454 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01175]);
1455 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001456
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001457 // The destination region specified by a given element of regions must be a region that is contained within dst_image
Dave Houltonfc1a4052017-04-27 14:32:45 -06001458 img_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
1459 if (0 != ExceedsBounds(&regions[i].dstOffset, &regions[i].extent, &img_extent)) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001460 std::stringstream ss;
Dave Houltonfc1a4052017-04-27 14:32:45 -06001461 ss << "vkCmdCopyImage: Dest pRegion[" << i << "] with mipLevel [ " << regions[i].dstSubresource.mipLevel
1462 << " ], offset [ " << regions[i].dstOffset.x << ", " << regions[i].dstOffset.y << ", " << regions[i].dstOffset.z
1463 << " ], extent [ " << regions[i].extent.width << ", " << regions[i].extent.height << ", "
1464 << regions[i].extent.depth << " ] exceeds the destination image dimensions";
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06001465 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1466 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01176, "IMAGE", "%s. %s",
1467 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01176]);
1468 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001469 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001470
Dave Houltonfc1a4052017-04-27 14:32:45 -06001471 // Each dimension offset + extent limits must fall with image subresource extent
1472 VkExtent3D subresource_extent = GetImageSubresourceExtent(src_image_state, &(regions[i].srcSubresource));
1473 uint32_t extent_check = ExceedsBounds(&(regions[i].srcOffset), &regions[i].extent, &subresource_extent);
1474 if (extent_check & x_bit) {
1475 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1476 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01202, "IMAGE",
1477 "vkCmdCopyImage: Source image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1478 "width [%1d]. %s",
1479 i, regions[i].srcOffset.x, regions[i].extent.width, subresource_extent.width,
1480 validation_error_map[VALIDATION_ERROR_01202]);
1481 }
1482
1483 if (extent_check & y_bit) {
1484 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1485 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01203, "IMAGE",
1486 "vkCmdCopyImage: Source image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1487 "height [%1d]. %s",
1488 i, regions[i].srcOffset.y, regions[i].extent.height, subresource_extent.height,
1489 validation_error_map[VALIDATION_ERROR_01203]);
1490 }
1491 if (extent_check & z_bit) {
1492 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1493 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01204, "IMAGE",
1494 "vkCmdCopyImage: Source image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1495 "depth [%1d]. %s",
1496 i, regions[i].srcOffset.z, regions[i].extent.depth, subresource_extent.depth,
1497 validation_error_map[VALIDATION_ERROR_01204]);
1498 }
1499
1500 subresource_extent = GetImageSubresourceExtent(dst_image_state, &(regions[i].dstSubresource));
1501 extent_check = ExceedsBounds(&(regions[i].dstOffset), &regions[i].extent, &subresource_extent);
1502 if (extent_check & x_bit) {
1503 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1504 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01205, "IMAGE",
1505 "vkCmdCopyImage: Dest image pRegion %1d x-dimension offset [%1d] + extent [%1d] exceeds subResource "
1506 "width [%1d]. %s",
1507 i, regions[i].dstOffset.x, regions[i].extent.width, subresource_extent.width,
1508 validation_error_map[VALIDATION_ERROR_01205]);
1509 }
1510 if (extent_check & y_bit) {
1511 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1512 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01206, "IMAGE",
1513 "vkCmdCopyImage: Dest image pRegion %1d y-dimension offset [%1d] + extent [%1d] exceeds subResource "
1514 "height [%1d]. %s",
1515 i, regions[i].dstOffset.y, regions[i].extent.height, subresource_extent.height,
1516 validation_error_map[VALIDATION_ERROR_01206]);
1517 }
1518 if (extent_check & z_bit) {
1519 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1520 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01207, "IMAGE",
1521 "vkCmdCopyImage: Dest image pRegion %1d z-dimension offset [%1d] + extent [%1d] exceeds subResource "
1522 "depth [%1d]. %s",
1523 i, regions[i].dstOffset.z, regions[i].extent.depth, subresource_extent.depth,
1524 validation_error_map[VALIDATION_ERROR_01207]);
1525 }
1526
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001527 // The union of all source regions, and the union of all destination regions, specified by the elements of regions,
1528 // must not overlap in memory
1529 if (src_image_state->image == dst_image_state->image) {
1530 for (uint32_t j = 0; j < region_count; j++) {
1531 if (RegionIntersects(&regions[i], &regions[j], src_image_state->createInfo.imageType)) {
1532 std::stringstream ss;
1533 ss << "vkCmdCopyImage: pRegions[" << i << "] src overlaps with pRegions[" << j << "].";
1534 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1535 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01177, "IMAGE",
1536 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_01177]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001537 }
1538 }
1539 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001540 }
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001541
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001542 // The formats of src_image and dst_image must be compatible. Formats are considered compatible if their texel size in bytes
1543 // is the same between both formats. For example, VK_FORMAT_R8G8B8A8_UNORM is compatible with VK_FORMAT_R32_UINT because
1544 // because both texels are 4 bytes in size. Depth/stencil formats must match exactly.
Dave Houlton1150cf52017-04-27 14:38:11 -06001545 if (FormatIsDepthOrStencil(src_image_state->createInfo.format) || FormatIsDepthOrStencil(dst_image_state->createInfo.format)) {
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001546 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1547 char const str[] = "vkCmdCopyImage called with unmatched source and dest image depth/stencil formats.";
1548 skip |=
1549 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1550 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT, "IMAGE", str);
1551 }
1552 } else {
Dave Houlton1d2022c2017-03-29 11:43:58 -06001553 size_t srcSize = FormatSize(src_image_state->createInfo.format);
1554 size_t destSize = FormatSize(dst_image_state->createInfo.format);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001555 if (srcSize != destSize) {
1556 char const str[] = "vkCmdCopyImage called with unmatched source and dest image format sizes.";
1557 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1558 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01184, "IMAGE", "%s. %s", str,
1559 validation_error_map[VALIDATION_ERROR_01184]);
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001560 }
1561 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001562
Dave Houlton33c22b72017-02-28 13:16:02 -07001563 // Source and dest image sample counts must match
1564 if (src_image_state->createInfo.samples != dst_image_state->createInfo.samples) {
1565 char const str[] = "vkCmdCopyImage() called on image pair with non-identical sample counts.";
1566 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06001567 reinterpret_cast<uint64_t &>(command_buffer), __LINE__, VALIDATION_ERROR_01185, "IMAGE", "%s %s", str,
1568 validation_error_map[VALIDATION_ERROR_01185]);
Dave Houlton33c22b72017-02-28 13:16:02 -07001569 }
1570
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001571 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02533);
1572 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyImage()", VALIDATION_ERROR_02534);
1573 // Validate that SRC & DST images have correct usage flags set
1574 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01178,
1575 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
1576 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01181,
1577 "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07001578 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyImage()",
1579 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_01193);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001580 skip |= ValidateCmd(device_data, cb_node, CMD_COPYIMAGE, "vkCmdCopyImage()");
1581 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImage()", VALIDATION_ERROR_01194);
Tobin Ehlisc8266452017-04-07 12:20:30 -06001582 bool hit_error = false;
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001583 for (uint32_t i = 0; i < region_count; ++i) {
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001584 skip |= VerifyImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -06001585 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_01180, &hit_error);
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06001586 skip |= VerifyImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout,
Tobin Ehlisc8266452017-04-07 12:20:30 -06001587 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyImage()", VALIDATION_ERROR_01183, &hit_error);
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001588 skip |= ValidateCopyImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &regions[i], i,
1589 "vkCmdCopyImage()");
1590 }
1591
Mark Lobodzinskib39d2ec2017-02-02 14:38:47 -07001592 return skip;
1593}
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001594
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001595void PreCallRecordCmdCopyImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06001596 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkImageCopy *regions,
1597 VkImageLayout src_image_layout, VkImageLayout dst_image_layout) {
1598 // Make sure that all image slices are updated to correct layout
1599 for (uint32_t i = 0; i < region_count; ++i) {
1600 SetImageLayout(device_data, cb_node, src_image_state, regions[i].srcSubresource, src_image_layout);
1601 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].dstSubresource, dst_image_layout);
1602 }
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001603 // Update bindings between images and cmd buffer
1604 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1605 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Dave Houltoneba86e22017-03-02 14:56:23 -07001606 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImage()"); };
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07001607 cb_node->validate_functions.push_back(function);
1608 function = [=]() {
1609 SetImageMemoryValid(device_data, dst_image_state, true);
1610 return false;
1611 };
1612 cb_node->validate_functions.push_back(function);
1613 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGE);
1614}
1615
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001616// Returns true if sub_rect is entirely contained within rect
1617static inline bool ContainsRect(VkRect2D rect, VkRect2D sub_rect) {
1618 if ((sub_rect.offset.x < rect.offset.x) || (sub_rect.offset.x + sub_rect.extent.width > rect.offset.x + rect.extent.width) ||
1619 (sub_rect.offset.y < rect.offset.y) || (sub_rect.offset.y + sub_rect.extent.height > rect.offset.y + rect.extent.height))
1620 return false;
1621 return true;
1622}
1623
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001624bool PreCallValidateCmdClearAttachments(layer_data *device_data, VkCommandBuffer commandBuffer, uint32_t attachmentCount,
1625 const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001626 GLOBAL_CB_NODE *cb_node = GetCBNode(device_data, commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001627 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1628
1629 bool skip = false;
1630 if (cb_node) {
Mike Schuchardt9c582402017-02-23 15:57:37 -07001631 skip |=
1632 ValidateCmdQueueFlags(device_data, cb_node, "vkCmdClearAttachments()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_01121);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001633 skip |= ValidateCmd(device_data, cb_node, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001634 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_CLEARATTACHMENTS);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001635 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
Chris Forbes05375e72017-04-21 13:15:15 -07001636 if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001637 (cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
1638 // There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass)
Mark Lobodzinskid833bb72017-02-22 10:55:30 -07001639 // This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call
1640 // CmdClearAttachments.
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001641 skip |=
1642 log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1643 reinterpret_cast<uint64_t &>(commandBuffer), 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
1644 "vkCmdClearAttachments() issued on command buffer object 0x%p prior to any Draw Cmds."
1645 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
1646 commandBuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001647 }
1648 skip |= outsideRenderPass(device_data, cb_node, "vkCmdClearAttachments()", VALIDATION_ERROR_01122);
1649 }
1650
1651 // Validate that attachment is in reference list of active subpass
1652 if (cb_node->activeRenderPass) {
1653 const VkRenderPassCreateInfo *renderpass_create_info = cb_node->activeRenderPass->createInfo.ptr();
1654 const VkSubpassDescription *subpass_desc = &renderpass_create_info->pSubpasses[cb_node->activeSubpass];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001655 auto framebuffer = GetFramebufferState(device_data, cb_node->activeFramebuffer);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001656
1657 for (uint32_t i = 0; i < attachmentCount; i++) {
1658 auto clear_desc = &pAttachments[i];
1659 VkImageView image_view = VK_NULL_HANDLE;
1660
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001661 if (0 == clear_desc->aspectMask) {
1662 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001663 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01128, "IMAGE", "%s",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001664 validation_error_map[VALIDATION_ERROR_01128]);
1665 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
1666 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001667 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01126, "IMAGE", "%s",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001668 validation_error_map[VALIDATION_ERROR_01126]);
1669 } else if (clear_desc->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001670 if (clear_desc->colorAttachment >= subpass_desc->colorAttachmentCount) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001671 skip |=
1672 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001673 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01114, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001674 "vkCmdClearAttachments() color attachment index %d out of range for active subpass %d. %s",
1675 clear_desc->colorAttachment, cb_node->activeSubpass, validation_error_map[VALIDATION_ERROR_01114]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001676 } else if (subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment == VK_ATTACHMENT_UNUSED) {
1677 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001678 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, reinterpret_cast<uint64_t>(commandBuffer),
1679 __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001680 "vkCmdClearAttachments() color attachment index %d is VK_ATTACHMENT_UNUSED; ignored.",
1681 clear_desc->colorAttachment);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001682 } else {
1683 image_view = framebuffer->createInfo
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001684 .pAttachments[subpass_desc->pColorAttachments[clear_desc->colorAttachment].attachment];
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001685 }
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001686 if ((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) ||
1687 (clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1688 char const str[] =
1689 "vkCmdClearAttachments aspectMask [%d] must set only VK_IMAGE_ASPECT_COLOR_BIT of a color attachment. %s";
1690 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001691 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01125, "IMAGE", str, i,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001692 validation_error_map[VALIDATION_ERROR_01125]);
1693 }
1694 } else { // Must be depth and/or stencil
1695 if (((clear_desc->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) &&
1696 ((clear_desc->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1697 char const str[] = "vkCmdClearAttachments aspectMask [%d] is not a valid combination of bits. %s";
1698 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001699 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01127, "IMAGE", str, i,
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001700 validation_error_map[VALIDATION_ERROR_01127]);
1701 }
1702 if (!subpass_desc->pDepthStencilAttachment ||
1703 (subpass_desc->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) {
1704 skip |= log_msg(
1705 report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001706 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001707 "vkCmdClearAttachments() depth/stencil clear with no depth/stencil attachment in subpass; ignored");
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001708 } else {
1709 image_view = framebuffer->createInfo.pAttachments[subpass_desc->pDepthStencilAttachment->attachment];
1710 }
1711 }
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001712 if (image_view) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001713 auto image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001714 for (uint32_t j = 0; j < rectCount; j++) {
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001715 // The rectangular region specified by a given element of pRects must be contained within the render area of
1716 // the current render pass instance
Mark Lobodzinskid833bb72017-02-22 10:55:30 -07001717 // TODO: This check should be moved to CmdExecuteCommands or QueueSubmit to cover secondary CB cases
1718 if ((cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
1719 (false == ContainsRect(cb_node->activeRenderPassBeginInfo.renderArea, pRects[j].rect))) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001720 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1721 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01115, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001722 "vkCmdClearAttachments(): The area defined by pRects[%d] is not contained in the area of "
1723 "the current render pass instance. %s",
1724 j, validation_error_map[VALIDATION_ERROR_01115]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001725 }
1726 // The layers specified by a given element of pRects must be contained within every attachment that
1727 // pAttachments refers to
1728 auto attachment_base_array_layer = image_view_state->create_info.subresourceRange.baseArrayLayer;
1729 auto attachment_layer_count = image_view_state->create_info.subresourceRange.layerCount;
1730 if ((pRects[j].baseArrayLayer < attachment_base_array_layer) || pRects[j].layerCount > attachment_layer_count) {
1731 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06001732 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1733 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, VALIDATION_ERROR_01116, "DS",
Mark Lobodzinskiac7e51e2017-02-02 15:50:27 -07001734 "vkCmdClearAttachments(): The layers defined in pRects[%d] are not contained in the layers of "
1735 "pAttachment[%d]. %s",
1736 j, i, validation_error_map[VALIDATION_ERROR_01116]);
Mark Lobodzinski2def2bf2017-02-02 15:22:50 -07001737 }
1738 }
1739 }
1740 }
1741 }
1742 return skip;
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001743}
1744
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001745bool PreCallValidateCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001746 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageResolve *pRegions) {
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001747 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001748 bool skip = false;
1749 if (cb_node && src_image_state && dst_image_state) {
1750 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02541);
1751 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdResolveImage()", VALIDATION_ERROR_02542);
Mike Schuchardt9c582402017-02-23 15:57:37 -07001752 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdResolveImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_01334);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001753 skip |= ValidateCmd(device_data, cb_node, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
1754 skip |= insideRenderPass(device_data, cb_node, "vkCmdResolveImage()", VALIDATION_ERROR_01335);
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001755
1756 // For each region, the number of layers in the image subresource should not be zero
1757 // For each region, src and dest image aspect must be color only
1758 for (uint32_t i = 0; i < regionCount; i++) {
1759 if (pRegions[i].srcSubresource.layerCount == 0) {
1760 char const str[] = "vkCmdResolveImage: number of layers in source subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001761 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 -07001762 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1763 "IMAGE", str);
1764 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001765 if (pRegions[i].dstSubresource.layerCount == 0) {
1766 char const str[] = "vkCmdResolveImage: number of layers in destination subresource is zero";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001767 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 -07001768 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1769 "IMAGE", str);
1770 }
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001771 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
1772 skip |= log_msg(
1773 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1774 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01339, "IMAGE",
1775 "vkCmdResolveImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s", i,
1776 validation_error_map[VALIDATION_ERROR_01339]);
1777 }
Mark Lobodzinski2a3368e2017-02-06 15:29:37 -07001778 if ((pRegions[i].srcSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) ||
1779 (pRegions[i].dstSubresource.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT)) {
1780 char const str[] =
1781 "vkCmdResolveImage: src and dest aspectMasks for each region must specify only VK_IMAGE_ASPECT_COLOR_BIT";
1782 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1783 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01338, "IMAGE",
1784 "%s. %s", str, validation_error_map[VALIDATION_ERROR_01338]);
1785 }
1786 }
1787
1788 if (src_image_state->createInfo.format != dst_image_state->createInfo.format) {
1789 char const str[] = "vkCmdResolveImage called with unmatched source and dest formats.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001790 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 -07001791 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_FORMAT,
1792 "IMAGE", str);
1793 }
1794 if (src_image_state->createInfo.imageType != dst_image_state->createInfo.imageType) {
1795 char const str[] = "vkCmdResolveImage called with unmatched source and dest image types.";
Mark Lobodzinski50fbef12017-02-06 15:31:33 -07001796 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 -07001797 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_TYPE, "IMAGE",
1798 str);
1799 }
1800 if (src_image_state->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
1801 char const str[] = "vkCmdResolveImage called with source sample count less than 2.";
1802 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1803 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01320, "IMAGE", "%s. %s",
1804 str, validation_error_map[VALIDATION_ERROR_01320]);
1805 }
1806 if (dst_image_state->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
1807 char const str[] = "vkCmdResolveImage called with dest sample count greater than 1.";
1808 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1809 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01321, "IMAGE", "%s. %s",
1810 str, validation_error_map[VALIDATION_ERROR_01321]);
1811 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001812 } else {
1813 assert(0);
1814 }
1815 return skip;
1816}
1817
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001818void PreCallRecordCmdResolveImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
1819 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001820 // Update bindings between images and cmd buffer
1821 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1822 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
1823
1824 std::function<bool()> function = [=]() {
1825 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdResolveImage()");
1826 };
1827 cb_node->validate_functions.push_back(function);
1828 function = [=]() {
1829 SetImageMemoryValid(device_data, dst_image_state, true);
1830 return false;
1831 };
1832 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001833 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_RESOLVEIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001834}
1835
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001836bool PreCallValidateCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001837 IMAGE_STATE *dst_image_state, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
1838 const debug_report_data *report_data = core_validation::GetReportData(device_data);
1839
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001840 bool skip = false;
1841 if (cb_node && src_image_state && dst_image_state) {
1842 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): srcImage",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001843 VALIDATION_ERROR_02194);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001844 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdBlitImage(): dstImage",
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001845 VALIDATION_ERROR_02195);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001846 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02539);
1847 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdBlitImage()", VALIDATION_ERROR_02540);
1848 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_02182,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001849 "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001850 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_02186,
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001851 "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07001852 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdBlitImage()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_01299);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001853 skip |= ValidateCmd(device_data, cb_node, CMD_BLITIMAGE, "vkCmdBlitImage()");
1854 skip |= insideRenderPass(device_data, cb_node, "vkCmdBlitImage()", VALIDATION_ERROR_01300);
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001855
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001856 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001857 // Warn for zero-sized regions
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001858 if ((pRegions[i].srcOffsets[0].x == pRegions[i].srcOffsets[1].x) ||
1859 (pRegions[i].srcOffsets[0].y == pRegions[i].srcOffsets[1].y) ||
1860 (pRegions[i].srcOffsets[0].z == pRegions[i].srcOffsets[1].z)) {
1861 std::stringstream ss;
1862 ss << "vkCmdBlitImage: pRegions[" << i << "].srcOffsets specify a zero-volume area.";
1863 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1864 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE",
1865 "%s", ss.str().c_str());
1866 }
1867 if ((pRegions[i].dstOffsets[0].x == pRegions[i].dstOffsets[1].x) ||
1868 (pRegions[i].dstOffsets[0].y == pRegions[i].dstOffsets[1].y) ||
1869 (pRegions[i].dstOffsets[0].z == pRegions[i].dstOffsets[1].z)) {
1870 std::stringstream ss;
1871 ss << "vkCmdBlitImage: pRegions[" << i << "].dstOffsets specify a zero-volume area.";
1872 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1873 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_INVALID_EXTENTS, "IMAGE",
1874 "%s", ss.str().c_str());
1875 }
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001876 if (pRegions[i].srcSubresource.layerCount == 0) {
1877 char const str[] = "vkCmdBlitImage: number of layers in source subresource is zero";
1878 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Dave Houltoneba86e22017-03-02 14:56:23 -07001879 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1880 "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001881 }
1882 if (pRegions[i].dstSubresource.layerCount == 0) {
1883 char const str[] = "vkCmdBlitImage: number of layers in destination subresource is zero";
1884 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
Dave Houltoneba86e22017-03-02 14:56:23 -07001885 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, DRAWSTATE_MISMATCHED_IMAGE_ASPECT,
1886 "IMAGE", str);
Mark Lobodzinski23c81142017-02-06 15:04:23 -07001887 }
1888
1889 // Check that src/dst layercounts match
1890 if (pRegions[i].srcSubresource.layerCount != pRegions[i].dstSubresource.layerCount) {
1891 skip |=
1892 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1893 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01304, "IMAGE",
1894 "vkCmdBlitImage: layerCount in source and destination subresource of pRegions[%d] does not match. %s",
1895 i, validation_error_map[VALIDATION_ERROR_01304]);
1896 }
Mark Lobodzinskie7e85fd2017-02-07 13:44:57 -07001897
1898 if (pRegions[i].srcSubresource.aspectMask != pRegions[i].dstSubresource.aspectMask) {
1899 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1900 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_01303, "IMAGE",
1901 "vkCmdBlitImage: aspectMask members for pRegion[%d] do not match. %s", i,
1902 validation_error_map[VALIDATION_ERROR_01303]);
1903 }
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001904 }
1905
1906 VkFormat src_format = src_image_state->createInfo.format;
1907 VkFormat dst_format = dst_image_state->createInfo.format;
1908
1909 // Validate consistency for unsigned formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06001910 if (FormatIsUInt(src_format) != FormatIsUInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001911 std::stringstream ss;
1912 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has unsigned integer format, "
1913 << "the other one must also have unsigned integer format. "
1914 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
1915 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1916 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02191, "IMAGE", "%s. %s",
1917 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02191]);
1918 }
1919
1920 // Validate consistency for signed formats
Dave Houlton1d2022c2017-03-29 11:43:58 -06001921 if (FormatIsSInt(src_format) != FormatIsSInt(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001922 std::stringstream ss;
1923 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has signed integer format, "
1924 << "the other one must also have signed integer format. "
1925 << "Source format is " << string_VkFormat(src_format) << " Destination format is " << string_VkFormat(dst_format);
1926 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1927 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02190, "IMAGE", "%s. %s",
1928 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02190]);
1929 }
1930
1931 // Validate aspect bits and formats for depth/stencil images
Dave Houlton1d2022c2017-03-29 11:43:58 -06001932 if (FormatIsDepthOrStencil(src_format) || FormatIsDepthOrStencil(dst_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001933 if (src_format != dst_format) {
1934 std::stringstream ss;
1935 ss << "vkCmdBlitImage: If one of srcImage and dstImage images has a format of depth, stencil or depth "
1936 << "stencil, the other one must have exactly the same format. "
1937 << "Source format is " << string_VkFormat(src_format) << " Destination format is "
1938 << string_VkFormat(dst_format);
1939 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1940 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02192, "IMAGE",
1941 "%s. %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02192]);
1942 }
1943
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001944 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001945 VkImageAspectFlags srcAspect = pRegions[i].srcSubresource.aspectMask;
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001946
Dave Houlton1d2022c2017-03-29 11:43:58 -06001947 if (FormatIsDepthAndStencil(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001948 if ((srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
1949 std::stringstream ss;
1950 ss << "vkCmdBlitImage: Combination depth/stencil image formats must have only one of "
1951 "VK_IMAGE_ASPECT_DEPTH_BIT "
1952 << "and VK_IMAGE_ASPECT_STENCIL_BIT set in srcImage and dstImage";
1953 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1954 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__,
1955 DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
1956 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001957 } else if (FormatIsStencilOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001958 if (srcAspect != VK_IMAGE_ASPECT_STENCIL_BIT) {
1959 std::stringstream ss;
1960 ss << "vkCmdBlitImage: Stencil-only image formats must have only the VK_IMAGE_ASPECT_STENCIL_BIT "
1961 << "set in both the srcImage and dstImage";
1962 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1963 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__,
1964 DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
1965 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06001966 } else if (FormatIsDepthOnly(src_format)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001967 if (srcAspect != VK_IMAGE_ASPECT_DEPTH_BIT) {
1968 std::stringstream ss;
1969 ss << "vkCmdBlitImage: Depth-only image formats must have only the VK_IMAGE_ASPECT_DEPTH "
1970 << "set in both the srcImage and dstImage";
1971 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1972 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__,
1973 DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", "%s", ss.str().c_str());
1974 }
1975 }
1976 }
1977 }
1978
1979 // Validate filter
Dave Houlton1d2022c2017-03-29 11:43:58 -06001980 if (FormatIsDepthOrStencil(src_format) && (filter != VK_FILTER_NEAREST)) {
Mark Lobodzinski9ad96582017-02-06 14:01:54 -07001981 std::stringstream ss;
1982 ss << "vkCmdBlitImage: If the format of srcImage is a depth, stencil, or depth stencil "
1983 << "then filter must be VK_FILTER_NEAREST.";
1984 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1985 reinterpret_cast<uint64_t>(cb_node->commandBuffer), __LINE__, VALIDATION_ERROR_02193, "IMAGE", "%s. %s",
1986 ss.str().c_str(), validation_error_map[VALIDATION_ERROR_02193]);
1987 }
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001988 } else {
1989 assert(0);
1990 }
1991 return skip;
1992}
1993
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001994void PreCallRecordCmdBlitImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
1995 IMAGE_STATE *dst_image_state) {
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07001996 // Update bindings between images and cmd buffer
1997 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
1998 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
1999
2000 std::function<bool()> function = [=]() { return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdBlitImage()"); };
2001 cb_node->validate_functions.push_back(function);
2002 function = [=]() {
2003 SetImageMemoryValid(device_data, dst_image_state, true);
2004 return false;
2005 };
2006 cb_node->validate_functions.push_back(function);
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002007 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_BLITIMAGE);
Mark Lobodzinski8e0c0bf2017-02-06 11:06:26 -07002008}
2009
Tony Barbourdf013b92017-01-25 12:53:48 -07002010// This validates that the initial layout specified in the command buffer for
2011// the IMAGE is the same
2012// as the global IMAGE layout
Tony Barboure0c5cc92017-02-08 13:53:39 -07002013bool ValidateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB,
2014 std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> &imageLayoutMap) {
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002015 bool skip = false;
Tony Barbourdf013b92017-01-25 12:53:48 -07002016 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002017 for (auto cb_image_data : pCB->imageLayoutMap) {
2018 VkImageLayout imageLayout;
Tony Barbourdf013b92017-01-25 12:53:48 -07002019
Jeremy Hayes55b6c292017-02-28 09:44:45 -07002020 if (FindLayout(imageLayoutMap, cb_image_data.first, imageLayout)) {
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002021 if (cb_image_data.second.initialLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
2022 // TODO: Set memory invalid which is in mem_tracker currently
2023 } else if (imageLayout != cb_image_data.second.initialLayout) {
2024 if (cb_image_data.first.hasSubresource) {
Dave Houltoneba86e22017-03-02 14:56:23 -07002025 skip |= log_msg(
2026 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2027 reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2028 "Cannot submit cmd buffer using image (0x%" PRIx64
2029 ") [sub-resource: aspectMask 0x%X array layer %u, mip level %u], "
2030 "with layout %s when first use is %s.",
2031 reinterpret_cast<const uint64_t &>(cb_image_data.first.image), cb_image_data.first.subresource.aspectMask,
2032 cb_image_data.first.subresource.arrayLayer, cb_image_data.first.subresource.mipLevel,
2033 string_VkImageLayout(imageLayout), string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002034 } else {
Dave Houltoneba86e22017-03-02 14:56:23 -07002035 skip |=
2036 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2037 reinterpret_cast<uint64_t &>(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2038 "Cannot submit cmd buffer using image (0x%" PRIx64
2039 ") with layout %s when "
2040 "first use is %s.",
2041 reinterpret_cast<const uint64_t &>(cb_image_data.first.image), string_VkImageLayout(imageLayout),
2042 string_VkImageLayout(cb_image_data.second.initialLayout));
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002043 }
2044 }
Tony Barbourdf013b92017-01-25 12:53:48 -07002045 SetLayout(imageLayoutMap, cb_image_data.first, cb_image_data.second.layout);
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002046 }
2047 }
Mark Lobodzinskib0dd9472017-02-07 16:38:17 -07002048 return skip;
Mark Lobodzinski4a3065e2017-02-07 16:36:03 -07002049}
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002050
Tony Barbourdf013b92017-01-25 12:53:48 -07002051void UpdateCmdBufImageLayouts(layer_data *device_data, GLOBAL_CB_NODE *pCB) {
2052 for (auto cb_image_data : pCB->imageLayoutMap) {
2053 VkImageLayout imageLayout;
2054 FindGlobalLayout(device_data, cb_image_data.first, imageLayout);
2055 SetGlobalLayout(device_data, cb_image_data.first, cb_image_data.second.layout);
2056 }
2057}
2058
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002059// Print readable FlagBits in FlagMask
2060static std::string string_VkAccessFlags(VkAccessFlags accessMask) {
2061 std::string result;
2062 std::string separator;
2063
2064 if (accessMask == 0) {
2065 result = "[None]";
2066 } else {
2067 result = "[";
2068 for (auto i = 0; i < 32; i++) {
2069 if (accessMask & (1 << i)) {
2070 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
2071 separator = " | ";
2072 }
2073 }
2074 result = result + "]";
2075 }
2076 return result;
2077}
2078
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002079// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set. If required_bit is zero, accessMask
2080// must have at least one of 'optional_bits' set
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002081// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002082static bool ValidateMaskBits(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer, const VkAccessFlags &accessMask,
2083 const VkImageLayout &layout, VkAccessFlags required_bit, VkAccessFlags optional_bits,
2084 const char *type) {
2085 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2086 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002087
2088 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
2089 if (accessMask & ~(required_bit | optional_bits)) {
2090 // TODO: Verify against Valid Use
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002091 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2092 reinterpret_cast<uint64_t>(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002093 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2094 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002095 }
2096 } else {
2097 if (!required_bit) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002098 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2099 reinterpret_cast<uint64_t>(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002100 "%s AccessMask %d %s must contain at least one of access bits %d "
2101 "%s when layout is %s, unless the app has previously added a "
2102 "barrier for this transition.",
2103 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
2104 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002105 } else {
2106 std::string opt_bits;
2107 if (optional_bits != 0) {
2108 std::stringstream ss;
2109 ss << optional_bits;
2110 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
2111 }
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002112 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2113 reinterpret_cast<uint64_t>(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002114 "%s AccessMask %d %s must have required access bit %d %s %s when "
2115 "layout is %s, unless the app has previously added a barrier for "
2116 "this transition.",
2117 type, accessMask, string_VkAccessFlags(accessMask).c_str(), required_bit,
2118 string_VkAccessFlags(required_bit).c_str(), opt_bits.c_str(), string_VkImageLayout(layout));
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002119 }
2120 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002121 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002122}
2123
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002124bool ValidateMaskBitsFromLayouts(core_validation::layer_data *device_data, VkCommandBuffer cmdBuffer,
2125 const VkAccessFlags &accessMask, const VkImageLayout &layout, const char *type) {
2126 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002127
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002128 bool skip = false;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002129 switch (layout) {
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002130 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
2131 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2132 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2133 break;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002134 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002135 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
2136 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
2137 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, type);
2138 break;
2139 }
2140 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
2141 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
2142 break;
2143 }
2144 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
2145 skip |= ValidateMaskBits(
2146 device_data, cmdBuffer, accessMask, layout, 0,
2147 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
2148 type);
2149 break;
2150 }
2151 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
2152 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, 0,
2153 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT, type);
2154 break;
2155 }
2156 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
2157 skip |= ValidateMaskBits(device_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
2158 break;
2159 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002160 case VK_IMAGE_LAYOUT_UNDEFINED: {
2161 if (accessMask != 0) {
2162 // TODO: Verify against Valid Use section spec
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002163 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2164 reinterpret_cast<uint64_t>(cmdBuffer), __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002165 "Additional bits in %s accessMask 0x%X %s are specified when layout is %s.", type, accessMask,
2166 string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
2167 }
2168 break;
2169 }
Chris Forbesbfd831d2017-04-28 17:29:10 -07002170 case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
Dave Houlton1150cf52017-04-27 14:38:11 -06002171 // Notes: QueuePresentKHR performs automatic visibility operations,
2172 // so the app is /NOT/ required to include VK_ACCESS_MEMORY_READ_BIT
2173 // when transitioning to this layout.
2174 //
2175 // When transitioning /from/ this layout, the application needs to
2176 // avoid only a WAR hazard -- any writes need to be ordered after
2177 // the PE's reads. There is no need for a memory dependency for this
2178 // case.
2179 /* fallthrough */
Chris Forbesbfd831d2017-04-28 17:29:10 -07002180
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002181 case VK_IMAGE_LAYOUT_GENERAL:
2182 default: { break; }
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002183 }
Mark Lobodzinski9a8d40f2017-02-07 17:00:12 -07002184 return skip;
Mark Lobodzinskib3829a52017-02-07 16:55:53 -07002185}
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002186
2187// ValidateLayoutVsAttachmentDescription is a general function where we can validate various state associated with the
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002188// VkAttachmentDescription structs that are used by the sub-passes of a renderpass. Initial check is to make sure that READ_ONLY
2189// layout attachments don't have CLEAR as their loadOp.
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002190bool ValidateLayoutVsAttachmentDescription(const debug_report_data *report_data, const VkImageLayout first_layout,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002191 const uint32_t attachment, const VkAttachmentDescription &attachment_description) {
2192 bool skip = false;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002193 // Verify that initial loadOp on READ_ONLY attachments is not CLEAR
2194 if (attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
2195 if ((first_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL) ||
2196 (first_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)) {
Mark Lobodzinskieb9e73f2017-04-13 10:06:48 -06002197 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2198 VALIDATION_ERROR_02351, "DS", "Cannot clear attachment %d with invalid first layout %s. %s", attachment,
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002199 string_VkImageLayout(first_layout), validation_error_map[VALIDATION_ERROR_02351]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002200 }
2201 }
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002202 return skip;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002203}
2204
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002205bool ValidateLayouts(core_validation::layer_data *device_data, VkDevice device, const VkRenderPassCreateInfo *pCreateInfo) {
2206 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002207 bool skip = false;
2208
2209 // Track when we're observing the first use of an attachment
2210 std::vector<bool> attach_first_use(pCreateInfo->attachmentCount, true);
2211 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
2212 const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[i];
2213 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
2214 auto attach_index = subpass.pColorAttachments[j].attachment;
2215 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2216
2217 switch (subpass.pColorAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002218 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2219 // This is ideal.
2220 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002221
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002222 case VK_IMAGE_LAYOUT_GENERAL:
2223 // May not be optimal; TODO: reconsider this warning based on other constraints?
2224 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2225 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2226 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
2227 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002228
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002229 default:
2230 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2231 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2232 "Layout for color attachment is %s but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.",
2233 string_VkImageLayout(subpass.pColorAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002234 }
2235
2236 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002237 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pColorAttachments[j].layout, attach_index,
2238 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002239 }
2240 attach_first_use[attach_index] = false;
2241 }
2242 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
2243 switch (subpass.pDepthStencilAttachment->layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002244 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2245 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2246 // These are ideal.
2247 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002248
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002249 case VK_IMAGE_LAYOUT_GENERAL:
2250 // May not be optimal; TODO: reconsider this warning based on other constraints? GENERAL can be better than
2251 // doing a bunch of transitions.
2252 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2253 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2254 "GENERAL layout for depth attachment may not give optimal performance.");
2255 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002256
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002257 default:
2258 // No other layouts are acceptable
2259 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2260 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2261 "Layout for depth attachment is %s but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "
2262 "DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.",
2263 string_VkImageLayout(subpass.pDepthStencilAttachment->layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002264 }
2265
2266 auto attach_index = subpass.pDepthStencilAttachment->attachment;
2267 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002268 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pDepthStencilAttachment->layout, attach_index,
2269 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002270 }
2271 attach_first_use[attach_index] = false;
2272 }
2273 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
2274 auto attach_index = subpass.pInputAttachments[j].attachment;
2275 if (attach_index == VK_ATTACHMENT_UNUSED) continue;
2276
2277 switch (subpass.pInputAttachments[j].layout) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002278 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2279 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
2280 // These are ideal.
2281 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002282
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002283 case VK_IMAGE_LAYOUT_GENERAL:
2284 // May not be optimal. TODO: reconsider this warning based on other constraints.
2285 skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
2286 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2287 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
2288 break;
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002289
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002290 default:
2291 // No other layouts are acceptable
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002292 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2293 __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002294 "Layout for input attachment is %s but can only be READ_ONLY_OPTIMAL or GENERAL.",
2295 string_VkImageLayout(subpass.pInputAttachments[j].layout));
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002296 }
2297
2298 if (attach_first_use[attach_index]) {
Mark Lobodzinski552e4402017-02-07 17:14:53 -07002299 skip |= ValidateLayoutVsAttachmentDescription(report_data, subpass.pInputAttachments[j].layout, attach_index,
2300 pCreateInfo->pAttachments[attach_index]);
Mark Lobodzinskic679b032017-02-07 17:11:55 -07002301 }
2302 attach_first_use[attach_index] = false;
2303 }
2304 }
2305 return skip;
2306}
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002307
2308// For any image objects that overlap mapped memory, verify that their layouts are PREINIT or GENERAL
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002309bool ValidateMapImageLayouts(core_validation::layer_data *device_data, VkDevice device, DEVICE_MEM_INFO const *mem_info,
2310 VkDeviceSize offset, VkDeviceSize end_offset) {
2311 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2312 bool skip = false;
2313 // Iterate over all bound image ranges and verify that for any that overlap the map ranges, the layouts are
2314 // VK_IMAGE_LAYOUT_PREINITIALIZED or VK_IMAGE_LAYOUT_GENERAL
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002315 // TODO : This can be optimized if we store ranges based on starting address and early exit when we pass our range
2316 for (auto image_handle : mem_info->bound_images) {
2317 auto img_it = mem_info->bound_ranges.find(image_handle);
2318 if (img_it != mem_info->bound_ranges.end()) {
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002319 if (rangesIntersect(device_data, &img_it->second, offset, end_offset)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002320 std::vector<VkImageLayout> layouts;
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002321 if (FindLayouts(device_data, VkImage(image_handle), layouts)) {
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002322 for (auto layout : layouts) {
2323 if (layout != VK_IMAGE_LAYOUT_PREINITIALIZED && layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002324 skip |= log_msg(
2325 report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT,
2326 reinterpret_cast<const uint64_t &>(mem_info->mem), __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
2327 "Mapping an image with layout %s can result in undefined behavior if this memory is "
2328 "used by the device. Only GENERAL or PREINITIALIZED should be used.",
2329 string_VkImageLayout(layout));
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002330 }
2331 }
2332 }
2333 }
2334 }
2335 }
Mark Lobodzinskiac23ec82017-02-07 17:21:55 -07002336 return skip;
Mark Lobodzinski08f14fa2017-02-07 17:20:06 -07002337}
Mark Lobodzinski96210742017-02-09 10:33:46 -07002338
2339// Helper function to validate correct usage bits set for buffers or images. Verify that (actual & desired) flags != 0 or, if strict
2340// is true, verify that (actual & desired) flags == desired
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002341static bool validate_usage_flags(layer_data *device_data, VkFlags actual, VkFlags desired, VkBool32 strict, uint64_t obj_handle,
Mark Lobodzinski33826372017-04-13 11:10:11 -06002342 VulkanObjectType obj_type, int32_t const msgCode, char const *func_name, char const *usage_str) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002343 const debug_report_data *report_data = core_validation::GetReportData(device_data);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002344
2345 bool correct_usage = false;
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002346 bool skip = false;
Mark Lobodzinski33826372017-04-13 11:10:11 -06002347 const char *type_str = object_string[obj_type];
Mark Lobodzinski96210742017-02-09 10:33:46 -07002348 if (strict) {
2349 correct_usage = ((actual & desired) == desired);
2350 } else {
2351 correct_usage = ((actual & desired) != 0);
2352 }
2353 if (!correct_usage) {
2354 if (msgCode == -1) {
2355 // TODO: Fix callers with msgCode == -1 to use correct validation checks.
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002356 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, __LINE__,
Mark Lobodzinski33826372017-04-13 11:10:11 -06002357 MEMTRACK_INVALID_USAGE_FLAG, "MEM",
2358 "Invalid usage flag for %s 0x%" PRIxLEAST64
2359 " used by %s. In this case, %s should have %s set during creation.",
2360 type_str, obj_handle, func_name, type_str, usage_str);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002361 } else {
2362 const char *valid_usage = (msgCode == -1) ? "" : validation_error_map[msgCode];
Mark Lobodzinski33826372017-04-13 11:10:11 -06002363 skip = log_msg(
Mark Lobodzinskic51dbb72017-04-13 14:25:39 -06002364 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, get_debug_report_enum[obj_type], obj_handle, __LINE__, msgCode, "MEM",
Mark Lobodzinski33826372017-04-13 11:10:11 -06002365 "Invalid usage flag for %s 0x%" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation. %s",
2366 type_str, obj_handle, func_name, type_str, usage_str, valid_usage);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002367 }
2368 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002369 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002370}
2371
2372// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2373// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002374bool ValidateImageUsageFlags(layer_data *device_data, IMAGE_STATE const *image_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002375 int32_t const msgCode, char const *func_name, char const *usage_string) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002376 return validate_usage_flags(device_data, image_state->createInfo.usage, desired, strict,
Mark Lobodzinski33826372017-04-13 11:10:11 -06002377 reinterpret_cast<const uint64_t &>(image_state->image), kVulkanObjectTypeImage, msgCode, func_name,
2378 usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002379}
2380
2381// Helper function to validate usage flags for buffers. For given buffer_state send actual vs. desired usage off to helper above
2382// where an error will be flagged if usage is not correct
Chris Forbes8fdba302017-04-24 18:34:28 -07002383bool ValidateBufferUsageFlags(layer_data *device_data, BUFFER_STATE const *buffer_state, VkFlags desired, bool strict,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002384 int32_t const msgCode, char const *func_name, char const *usage_string) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002385 return validate_usage_flags(device_data, buffer_state->createInfo.usage, desired, strict,
Mark Lobodzinski33826372017-04-13 11:10:11 -06002386 reinterpret_cast<const uint64_t &>(buffer_state->buffer), kVulkanObjectTypeBuffer, msgCode,
2387 func_name, usage_string);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002388}
2389
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002390bool PreCallValidateCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo) {
Mark Lobodzinski96210742017-02-09 10:33:46 -07002391 bool skip = false;
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002392 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2393
Mark Lobodzinski96210742017-02-09 10:33:46 -07002394 // TODO: Add check for VALIDATION_ERROR_00658
Mark Lobodzinski96210742017-02-09 10:33:46 -07002395 // TODO: Add check for VALIDATION_ERROR_00667
2396 // TODO: Add check for VALIDATION_ERROR_00668
2397 // TODO: Add check for VALIDATION_ERROR_00669
Mark Lobodzinski847b60c2017-03-13 09:32:45 -06002398
2399 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!GetEnabledFeatures(device_data)->sparseBinding)) {
2400 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2401 VALIDATION_ERROR_00666, "DS",
2402 "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
2403 "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set. %s",
2404 validation_error_map[VALIDATION_ERROR_00666]);
2405 }
Mark Lobodzinskiaf355062017-03-13 09:35:01 -06002406
2407 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyBuffer)) {
2408 skip |=
2409 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2410 DRAWSTATE_INVALID_FEATURE, "DS",
2411 "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with the "
2412 "VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set.");
2413 }
Mark Lobodzinski035a4cf2017-03-13 09:45:07 -06002414
2415 if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!GetEnabledFeatures(device_data)->sparseResidencyAliased)) {
2416 skip |=
2417 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2418 DRAWSTATE_INVALID_FEATURE, "DS",
2419 "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with the "
2420 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set.");
2421 }
Mark Lobodzinski96210742017-02-09 10:33:46 -07002422 return skip;
2423}
2424
2425void PostCallRecordCreateBuffer(layer_data *device_data, const VkBufferCreateInfo *pCreateInfo, VkBuffer *pBuffer) {
2426 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
2427 GetBufferMap(device_data)
2428 ->insert(std::make_pair(*pBuffer, std::unique_ptr<BUFFER_STATE>(new BUFFER_STATE(*pBuffer, pCreateInfo))));
2429}
2430
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002431bool PreCallValidateCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo) {
2432 bool skip = false;
2433 BUFFER_STATE *buffer_state = GetBufferState(device_data, pCreateInfo->buffer);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002434 // If this isn't a sparse buffer, it needs to have memory backing it at CreateBufferView time
2435 if (buffer_state) {
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002436 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCreateBufferView()", VALIDATION_ERROR_02522);
Mark Lobodzinski96210742017-02-09 10:33:46 -07002437 // In order to create a valid buffer view, the buffer must have been created with at least one of the following flags:
2438 // UNIFORM_TEXEL_BUFFER_BIT or STORAGE_TEXEL_BUFFER_BIT
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002439 skip |= ValidateBufferUsageFlags(
2440 device_data, buffer_state, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, false,
Mark Lobodzinski96210742017-02-09 10:33:46 -07002441 VALIDATION_ERROR_00694, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT");
2442 }
Mark Lobodzinski95dbbe52017-02-09 10:40:41 -07002443 return skip;
Mark Lobodzinski96210742017-02-09 10:33:46 -07002444}
2445
2446void PostCallRecordCreateBufferView(layer_data *device_data, const VkBufferViewCreateInfo *pCreateInfo, VkBufferView *pView) {
2447 (*GetBufferViewMap(device_data))[*pView] = std::unique_ptr<BUFFER_VIEW_STATE>(new BUFFER_VIEW_STATE(*pView, pCreateInfo));
2448}
Mark Lobodzinski602de982017-02-09 11:01:33 -07002449
2450// For the given format verify that the aspect masks make sense
2451bool ValidateImageAspectMask(layer_data *device_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
2452 const char *func_name) {
2453 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2454 bool skip = false;
Dave Houlton1d2022c2017-03-29 11:43:58 -06002455 if (FormatIsColor(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002456 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
2457 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2458 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2459 "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
2460 validation_error_map[VALIDATION_ERROR_00741]);
2461 } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) {
2462 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2463 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2464 "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
2465 validation_error_map[VALIDATION_ERROR_00741]);
2466 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002467 } else if (FormatIsDepthAndStencil(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002468 if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) {
2469 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2470 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2471 "%s: Depth/stencil image formats must have "
2472 "at least one of VK_IMAGE_ASPECT_DEPTH_BIT "
2473 "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
2474 func_name, validation_error_map[VALIDATION_ERROR_00741]);
2475 } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) {
2476 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2477 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2478 "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and "
2479 "VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
2480 func_name, validation_error_map[VALIDATION_ERROR_00741]);
2481 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002482 } else if (FormatIsDepthOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002483 if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) {
2484 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2485 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2486 "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
2487 validation_error_map[VALIDATION_ERROR_00741]);
2488 } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) {
2489 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2490 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2491 "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
2492 validation_error_map[VALIDATION_ERROR_00741]);
2493 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06002494 } else if (FormatIsStencilOnly(format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002495 if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) {
2496 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2497 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2498 "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
2499 validation_error_map[VALIDATION_ERROR_00741]);
2500 } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) {
2501 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image,
2502 __LINE__, VALIDATION_ERROR_00741, "IMAGE",
2503 "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
2504 validation_error_map[VALIDATION_ERROR_00741]);
2505 }
2506 }
2507 return skip;
2508}
2509
2510bool ValidateImageSubrangeLevelLayerCounts(layer_data *device_data, const VkImageSubresourceRange &subresourceRange,
2511 const char *func_name) {
2512 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2513 bool skip = false;
2514 if (subresourceRange.levelCount == 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002515 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07002516 VALIDATION_ERROR_00768, "IMAGE", "%s called with 0 in subresourceRange.levelCount. %s", func_name,
2517 validation_error_map[VALIDATION_ERROR_00768]);
2518 }
2519 if (subresourceRange.layerCount == 0) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002520 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07002521 VALIDATION_ERROR_00769, "IMAGE", "%s called with 0 in subresourceRange.layerCount. %s", func_name,
2522 validation_error_map[VALIDATION_ERROR_00769]);
2523 }
2524 return skip;
2525}
2526
2527bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info) {
2528 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2529 bool skip = false;
2530 IMAGE_STATE *image_state = GetImageState(device_data, create_info->image);
2531 if (image_state) {
2532 skip |= ValidateImageUsageFlags(
2533 device_data, image_state,
2534 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
2535 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2536 false, -1, "vkCreateImageView()",
2537 "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT");
2538 // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time
2539 skip |= ValidateMemoryIsBoundToImage(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_02524);
2540 // Checks imported from image layer
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002541 if ((create_info->subresourceRange.baseMipLevel + create_info->subresourceRange.levelCount) >
2542 image_state->createInfo.mipLevels) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002543 std::stringstream ss;
2544 ss << "vkCreateImageView called with baseMipLevel " << create_info->subresourceRange.baseMipLevel << " for image "
2545 << create_info->image << " that only has " << image_state->createInfo.mipLevels << " mip levels.";
2546 skip |=
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002547 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07002548 VALIDATION_ERROR_00768, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00768]);
2549 }
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002550 if (!GetDeviceExtensions(device_data)->khr_maintenance1_enabled) {
2551 if (create_info->subresourceRange.baseArrayLayer >= image_state->createInfo.arrayLayers) {
2552 std::stringstream ss;
2553 ss << "vkCreateImageView called with baseArrayLayer " << create_info->subresourceRange.baseArrayLayer
2554 << " for image " << create_info->image << " that only has " << image_state->createInfo.arrayLayers
2555 << " array layers.";
2556 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2557 VALIDATION_ERROR_00769, "IMAGE", "%s %s", ss.str().c_str(),
2558 validation_error_map[VALIDATION_ERROR_00769]);
2559 }
Mark Lobodzinski602de982017-02-09 11:01:33 -07002560 }
2561 // TODO: Need new valid usage language for levelCount == 0 & layerCount == 0
2562 skip |= ValidateImageSubrangeLevelLayerCounts(device_data, create_info->subresourceRange, "vkCreateImageView()");
2563
2564 VkImageCreateFlags image_flags = image_state->createInfo.flags;
2565 VkFormat image_format = image_state->createInfo.format;
2566 VkFormat view_format = create_info->format;
2567 VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask;
2568
2569 // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
2570 if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
2571 // Format MUST be compatible (in the same format compatibility class) as the format the image was created with
Dave Houlton1d2022c2017-03-29 11:43:58 -06002572 if (FormatCompatibilityClass(image_format) != FormatCompatibilityClass(view_format)) {
Mark Lobodzinski602de982017-02-09 11:01:33 -07002573 std::stringstream ss;
2574 ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format)
2575 << " is not in the same format compatibility class as image (" << (uint64_t)create_info->image << ") format "
2576 << string_VkFormat(image_format) << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
2577 << "can support ImageViews with differing formats but they must be in the same compatibility class.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002578 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07002579 VALIDATION_ERROR_02171, "IMAGE", "%s %s", ss.str().c_str(),
2580 validation_error_map[VALIDATION_ERROR_02171]);
2581 }
2582 } else {
2583 // Format MUST be IDENTICAL to the format the image was created with
2584 if (image_format != view_format) {
2585 std::stringstream ss;
2586 ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image "
2587 << (uint64_t)create_info->image << " format " << string_VkFormat(image_format)
2588 << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.";
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06002589 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski602de982017-02-09 11:01:33 -07002590 VALIDATION_ERROR_02172, "IMAGE", "%s %s", ss.str().c_str(),
2591 validation_error_map[VALIDATION_ERROR_02172]);
2592 }
2593 }
2594
2595 // Validate correct image aspect bits for desired formats and format consistency
2596 skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
2597 }
2598 return skip;
2599}
2600
Mark Lobodzinskiefd933b2017-02-10 12:09:23 -07002601void PostCallRecordCreateImageView(layer_data *device_data, const VkImageViewCreateInfo *create_info, VkImageView view) {
2602 auto image_view_map = GetImageViewMap(device_data);
2603 (*image_view_map)[view] = std::unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info));
2604
2605 auto image_state = GetImageState(device_data, create_info->image);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06002606 auto &sub_res_range = (*image_view_map)[view].get()->create_info.subresourceRange;
Mark Lobodzinski903e5ff2017-03-23 09:43:35 -06002607 sub_res_range.levelCount = ResolveRemainingLevels(&sub_res_range, image_state->createInfo.mipLevels);
2608 sub_res_range.layerCount = ResolveRemainingLayers(&sub_res_range, image_state->createInfo.arrayLayers);
Mark Lobodzinski602de982017-02-09 11:01:33 -07002609}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002610
Mark Lobodzinski680421d2017-02-09 13:06:56 -07002611bool PreCallValidateCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
2612 BUFFER_STATE *dst_buffer_state) {
2613 bool skip = false;
2614 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02531);
2615 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyBuffer()", VALIDATION_ERROR_02532);
2616 // Validate that SRC & DST buffers have correct usage flags set
2617 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01164,
2618 "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2619 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01165,
2620 "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mike Schuchardt9c582402017-02-23 15:57:37 -07002621 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdCopyBuffer()",
2622 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_01171);
Mark Lobodzinski680421d2017-02-09 13:06:56 -07002623 skip |= ValidateCmd(device_data, cb_node, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
2624 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBuffer()", VALIDATION_ERROR_01172);
2625 return skip;
2626}
Mark Lobodzinskiab9be282017-02-09 12:01:27 -07002627
Mark Lobodzinski680421d2017-02-09 13:06:56 -07002628void PreCallRecordCmdCopyBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
2629 BUFFER_STATE *dst_buffer_state) {
2630 // Update bindings between buffers and cmd buffer
2631 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
2632 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
2633
2634 std::function<bool()> function = [=]() {
2635 return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBuffer()");
2636 };
2637 cb_node->validate_functions.push_back(function);
2638 function = [=]() {
2639 SetBufferMemoryValid(device_data, dst_buffer_state, true);
2640 return false;
2641 };
2642 cb_node->validate_functions.push_back(function);
2643 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFER);
2644}
Mark Lobodzinski306441e2017-02-10 13:48:38 -07002645
2646static bool validateIdleBuffer(layer_data *device_data, VkBuffer buffer) {
2647 const debug_report_data *report_data = core_validation::GetReportData(device_data);
2648 bool skip = false;
2649 auto buffer_state = GetBufferState(device_data, buffer);
2650 if (!buffer_state) {
2651 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer),
2652 __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
2653 "Cannot free buffer 0x%" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
2654 } else {
2655 if (buffer_state->in_use.load()) {
2656 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer),
2657 __LINE__, VALIDATION_ERROR_00676, "DS",
2658 "Cannot free buffer 0x%" PRIxLEAST64 " that is in use by a command buffer. %s", (uint64_t)(buffer),
2659 validation_error_map[VALIDATION_ERROR_00676]);
2660 }
2661 }
2662 return skip;
2663}
2664
2665bool PreCallValidateDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE **image_view_state,
2666 VK_OBJECT *obj_struct) {
2667 *image_view_state = GetImageViewState(device_data, image_view);
Mark Lobodzinski33826372017-04-13 11:10:11 -06002668 *obj_struct = {reinterpret_cast<uint64_t &>(image_view), kVulkanObjectTypeImageView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07002669 if (GetDisables(device_data)->destroy_image_view) return false;
2670 bool skip = false;
2671 if (*image_view_state) {
2672 skip |= ValidateObjectNotInUse(device_data, *image_view_state, *obj_struct, VALIDATION_ERROR_00776);
2673 }
2674 return skip;
2675}
2676
2677void PostCallRecordDestroyImageView(layer_data *device_data, VkImageView image_view, IMAGE_VIEW_STATE *image_view_state,
2678 VK_OBJECT obj_struct) {
2679 // Any bound cmd buffers are now invalid
2680 invalidateCommandBuffers(device_data, image_view_state->cb_bindings, obj_struct);
2681 (*GetImageViewMap(device_data)).erase(image_view);
2682}
2683
2684bool PreCallValidateDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE **buffer_state, VK_OBJECT *obj_struct) {
2685 *buffer_state = GetBufferState(device_data, buffer);
Dave Houlton1150cf52017-04-27 14:38:11 -06002686 *obj_struct = {reinterpret_cast<uint64_t &>(buffer), kVulkanObjectTypeBuffer};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07002687 if (GetDisables(device_data)->destroy_buffer) return false;
2688 bool skip = false;
2689 if (*buffer_state) {
2690 skip |= validateIdleBuffer(device_data, buffer);
2691 }
2692 return skip;
2693}
2694
2695void PostCallRecordDestroyBuffer(layer_data *device_data, VkBuffer buffer, BUFFER_STATE *buffer_state, VK_OBJECT obj_struct) {
2696 invalidateCommandBuffers(device_data, buffer_state->cb_bindings, obj_struct);
2697 for (auto mem_binding : buffer_state->GetBoundMemory()) {
2698 auto mem_info = GetMemObjInfo(device_data, mem_binding);
2699 if (mem_info) {
2700 core_validation::RemoveBufferMemoryRange(reinterpret_cast<uint64_t &>(buffer), mem_info);
2701 }
2702 }
Mark Lobodzinski33826372017-04-13 11:10:11 -06002703 ClearMemoryObjectBindings(device_data, reinterpret_cast<uint64_t &>(buffer), kVulkanObjectTypeBuffer);
Mark Lobodzinski306441e2017-02-10 13:48:38 -07002704 GetBufferMap(device_data)->erase(buffer_state->buffer);
2705}
2706
2707bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE **buffer_view_state,
2708 VK_OBJECT *obj_struct) {
2709 *buffer_view_state = GetBufferViewState(device_data, buffer_view);
Dave Houlton1150cf52017-04-27 14:38:11 -06002710 *obj_struct = {reinterpret_cast<uint64_t &>(buffer_view), kVulkanObjectTypeBufferView};
Mark Lobodzinski306441e2017-02-10 13:48:38 -07002711 if (GetDisables(device_data)->destroy_buffer_view) return false;
2712 bool skip = false;
2713 if (*buffer_view_state) {
2714 skip |= ValidateObjectNotInUse(device_data, *buffer_view_state, *obj_struct, VALIDATION_ERROR_00701);
2715 }
2716 return skip;
2717}
2718
2719void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state,
2720 VK_OBJECT obj_struct) {
2721 // Any bound cmd buffers are now invalid
2722 invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct);
2723 GetBufferViewMap(device_data)->erase(buffer_view);
2724}
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07002725
2726bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
2727 bool skip = false;
2728 skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_02529);
Mike Schuchardt9c582402017-02-23 15:57:37 -07002729 skip |= ValidateCmdQueueFlags(device_data, cb_node, "vkCmdFillBuffer()",
2730 VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_01141);
Mark Lobodzinskidf0acbf2017-02-10 14:01:27 -07002731 skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()");
2732 // Validate that DST buffer has correct usage flags set
2733 skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01137,
2734 "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
2735 skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_01142);
2736 return skip;
2737}
2738
2739void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) {
2740 std::function<bool()> function = [=]() {
2741 SetBufferMemoryValid(device_data, buffer_state, true);
2742 return false;
2743 };
2744 cb_node->validate_functions.push_back(function);
2745 // Update bindings between buffer and cmd buffer
2746 AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state);
2747 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER);
2748}
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002749
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002750bool ValidateBufferImageCopyData(const debug_report_data *report_data, uint32_t regionCount, const VkBufferImageCopy *pRegions,
2751 IMAGE_STATE *image_state, const char *function) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002752 bool skip = false;
2753
2754 for (uint32_t i = 0; i < regionCount; i++) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002755 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) {
2756 if ((pRegions[i].imageOffset.y != 0) || (pRegions[i].imageExtent.height != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002757 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002758 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01746, "IMAGE",
2759 "%s(): pRegion[%d] imageOffset.y is %d and imageExtent.height is %d. For 1D images these "
2760 "must be 0 and 1, respectively. %s",
2761 function, i, pRegions[i].imageOffset.y, pRegions[i].imageExtent.height,
2762 validation_error_map[VALIDATION_ERROR_01746]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002763 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002764 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002765
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002766 if ((image_state->createInfo.imageType == VK_IMAGE_TYPE_1D) || (image_state->createInfo.imageType == VK_IMAGE_TYPE_2D)) {
2767 if ((pRegions[i].imageOffset.z != 0) || (pRegions[i].imageExtent.depth != 1)) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002768 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002769 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01747, "IMAGE",
2770 "%s(): pRegion[%d] imageOffset.z is %d and imageExtent.depth is %d. For 1D and 2D images these "
2771 "must be 0 and 1, respectively. %s",
2772 function, i, pRegions[i].imageOffset.z, pRegions[i].imageExtent.depth,
2773 validation_error_map[VALIDATION_ERROR_01747]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002774 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002775 }
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002776
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002777 if (image_state->createInfo.imageType == VK_IMAGE_TYPE_3D) {
2778 if ((0 != pRegions[i].imageSubresource.baseArrayLayer) || (1 != pRegions[i].imageSubresource.layerCount)) {
2779 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2780 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01281, "IMAGE",
2781 "%s(): pRegion[%d] imageSubresource.baseArrayLayer is %d and imageSubresource.layerCount is "
2782 "%d. For 3D images these must be 0 and 1, respectively. %s",
2783 function, i, pRegions[i].imageSubresource.baseArrayLayer, pRegions[i].imageSubresource.layerCount,
2784 validation_error_map[VALIDATION_ERROR_01281]);
2785 }
2786 }
2787
2788 // If the the calling command's VkImage parameter's format is not a depth/stencil format,
2789 // then bufferOffset must be a multiple of the calling command's VkImage parameter's texel size
Dave Houlton1d2022c2017-03-29 11:43:58 -06002790 auto texel_size = FormatSize(image_state->createInfo.format);
Dave Houlton1150cf52017-04-27 14:38:11 -06002791 if (!FormatIsDepthAndStencil(image_state->createInfo.format) && SafeModulo(pRegions[i].bufferOffset, texel_size) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002792 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2793 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01263, "IMAGE",
2794 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64
2795 " must be a multiple of this format's texel size (" PRINTF_SIZE_T_SPECIFIER "). %s",
2796 function, i, pRegions[i].bufferOffset, texel_size, validation_error_map[VALIDATION_ERROR_01263]);
2797 }
2798
2799 // BufferOffset must be a multiple of 4
Dave Houlton1d2022c2017-03-29 11:43:58 -06002800 if (SafeModulo(pRegions[i].bufferOffset, 4) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002801 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2802 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01264, "IMAGE",
2803 "%s(): pRegion[%d] bufferOffset 0x%" PRIxLEAST64 " must be a multiple of 4. %s", function, i,
2804 pRegions[i].bufferOffset, validation_error_map[VALIDATION_ERROR_01264]);
2805 }
2806
2807 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
2808 if ((pRegions[i].bufferRowLength != 0) && (pRegions[i].bufferRowLength < pRegions[i].imageExtent.width)) {
2809 skip |= log_msg(
2810 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2811 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01265, "IMAGE",
2812 "%s(): pRegion[%d] bufferRowLength (%d) must be zero or greater-than-or-equal-to imageExtent.width (%d). %s",
2813 function, i, pRegions[i].bufferRowLength, pRegions[i].imageExtent.width,
2814 validation_error_map[VALIDATION_ERROR_01265]);
2815 }
2816
2817 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
2818 if ((pRegions[i].bufferImageHeight != 0) && (pRegions[i].bufferImageHeight < pRegions[i].imageExtent.height)) {
2819 skip |= log_msg(
2820 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2821 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01266, "IMAGE",
2822 "%s(): pRegion[%d] bufferImageHeight (%d) must be zero or greater-than-or-equal-to imageExtent.height (%d). %s",
2823 function, i, pRegions[i].bufferImageHeight, pRegions[i].imageExtent.height,
2824 validation_error_map[VALIDATION_ERROR_01266]);
2825 }
2826
2827 // subresource aspectMask must have exactly 1 bit set
2828 const int num_bits = sizeof(VkFlags) * CHAR_BIT;
2829 std::bitset<num_bits> aspect_mask_bits(pRegions[i].imageSubresource.aspectMask);
2830 if (aspect_mask_bits.count() != 1) {
2831 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2832 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01280, "IMAGE",
2833 "%s: aspectMasks for imageSubresource in each region must have only a single bit set. %s", function,
2834 validation_error_map[VALIDATION_ERROR_01280]);
2835 }
2836
2837 // image subresource aspect bit must match format
Dave Houlton4eaaf3a2017-03-14 11:31:20 -06002838 if (!VerifyAspectsPresent(pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002839 skip |= log_msg(
2840 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2841 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01279, "IMAGE",
2842 "%s(): pRegion[%d] subresource aspectMask 0x%x specifies aspects that are not present in image format 0x%x. %s",
2843 function, i, pRegions[i].imageSubresource.aspectMask, image_state->createInfo.format,
2844 validation_error_map[VALIDATION_ERROR_01279]);
2845 }
2846
2847 // Checks that apply only to compressed images
2848 // TODO: there is a comment in ValidateCopyBufferImageTransferGranularityRequirements() in core_validation.cpp that
2849 // reserves a place for these compressed image checks. This block of code could move there once the image
2850 // stuff is moved into core validation.
Dave Houlton1d2022c2017-03-29 11:43:58 -06002851 if (FormatIsCompressed(image_state->createInfo.format)) {
2852 auto block_size = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002853
2854 // BufferRowLength must be a multiple of block width
Dave Houlton1d2022c2017-03-29 11:43:58 -06002855 if (SafeModulo(pRegions[i].bufferRowLength, block_size.width) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002856 skip |= log_msg(
2857 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002858 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01271, "IMAGE",
2859 "%s(): pRegion[%d] bufferRowLength (%d) must be a multiple of the compressed image's texel width (%d). %s.",
2860 function, i, pRegions[i].bufferRowLength, block_size.width, validation_error_map[VALIDATION_ERROR_01271]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002861 }
2862
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002863 // BufferRowHeight must be a multiple of block height
Dave Houlton1d2022c2017-03-29 11:43:58 -06002864 if (SafeModulo(pRegions[i].bufferImageHeight, block_size.height) != 0) {
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002865 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002866 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01272, "IMAGE",
2867 "%s(): pRegion[%d] bufferImageHeight (%d) must be a multiple of the compressed image's texel "
2868 "height (%d). %s.",
2869 function, i, pRegions[i].bufferImageHeight, block_size.height,
2870 validation_error_map[VALIDATION_ERROR_01272]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002871 }
2872
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002873 // image offsets must be multiples of block dimensions
Dave Houlton1d2022c2017-03-29 11:43:58 -06002874 if ((SafeModulo(pRegions[i].imageOffset.x, block_size.width) != 0) ||
2875 (SafeModulo(pRegions[i].imageOffset.y, block_size.height) != 0) ||
2876 (SafeModulo(pRegions[i].imageOffset.z, block_size.depth) != 0)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002877 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2878 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01273, "IMAGE",
2879 "%s(): pRegion[%d] imageOffset(x,y) (%d, %d) must be multiples of the compressed image's texel "
2880 "width & height (%d, %d). %s.",
2881 function, i, pRegions[i].imageOffset.x, pRegions[i].imageOffset.y, block_size.width,
2882 block_size.height, validation_error_map[VALIDATION_ERROR_01273]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002883 }
2884
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002885 // bufferOffset must be a multiple of block size (linear bytes)
Dave Houlton1d2022c2017-03-29 11:43:58 -06002886 size_t block_size_in_bytes = FormatSize(image_state->createInfo.format);
2887 if (SafeModulo(pRegions[i].bufferOffset, block_size_in_bytes) != 0) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002888 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2889 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01274, "IMAGE",
2890 "%s(): pRegion[%d] bufferOffset (0x%" PRIxLEAST64
2891 ") must be a multiple of the compressed image's texel block "
2892 "size (" PRINTF_SIZE_T_SPECIFIER "). %s.",
2893 function, i, pRegions[i].bufferOffset, block_size_in_bytes,
2894 validation_error_map[VALIDATION_ERROR_01274]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002895 }
Dave Houlton67e9b532017-03-02 17:00:10 -07002896
2897 // imageExtent width must be a multiple of block width, or extent+offset width must equal subresource width
Dave Houlton75967fc2017-03-06 17:21:16 -07002898 VkExtent3D mip_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
Dave Houlton1d2022c2017-03-29 11:43:58 -06002899 if ((SafeModulo(pRegions[i].imageExtent.width, block_size.width) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07002900 (pRegions[i].imageExtent.width + pRegions[i].imageOffset.x != mip_extent.width)) {
2901 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2902 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01275, "IMAGE",
2903 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block width "
2904 "(%d), or when added to offset.x (%d) must equal the image subresource width (%d). %s.",
2905 function, i, pRegions[i].imageExtent.width, block_size.width, pRegions[i].imageOffset.x,
2906 mip_extent.width, validation_error_map[VALIDATION_ERROR_01275]);
Dave Houlton67e9b532017-03-02 17:00:10 -07002907 }
2908
2909 // imageExtent height must be a multiple of block height, or extent+offset height must equal subresource height
Dave Houlton1d2022c2017-03-29 11:43:58 -06002910 if ((SafeModulo(pRegions[i].imageExtent.height, block_size.height) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07002911 (pRegions[i].imageExtent.height + pRegions[i].imageOffset.y != mip_extent.height)) {
2912 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2913 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01276, "IMAGE",
2914 "%s(): pRegion[%d] extent height (%d) must be a multiple of the compressed texture block height "
2915 "(%d), or when added to offset.y (%d) must equal the image subresource height (%d). %s.",
2916 function, i, pRegions[i].imageExtent.height, block_size.height, pRegions[i].imageOffset.y,
2917 mip_extent.height, validation_error_map[VALIDATION_ERROR_01276]);
Dave Houlton67e9b532017-03-02 17:00:10 -07002918 }
2919
2920 // imageExtent depth must be a multiple of block depth, or extent+offset depth must equal subresource depth
Dave Houlton1d2022c2017-03-29 11:43:58 -06002921 if ((SafeModulo(pRegions[i].imageExtent.depth, block_size.depth) != 0) &&
Dave Houlton75967fc2017-03-06 17:21:16 -07002922 (pRegions[i].imageExtent.depth + pRegions[i].imageOffset.z != mip_extent.depth)) {
2923 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
2924 reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01277, "IMAGE",
2925 "%s(): pRegion[%d] extent width (%d) must be a multiple of the compressed texture block depth "
2926 "(%d), or when added to offset.z (%d) must equal the image subresource depth (%d). %s.",
2927 function, i, pRegions[i].imageExtent.depth, block_size.depth, pRegions[i].imageOffset.z,
2928 mip_extent.depth, validation_error_map[VALIDATION_ERROR_01277]);
Dave Houlton67e9b532017-03-02 17:00:10 -07002929 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002930 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002931 }
2932
2933 return skip;
2934}
2935
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002936static bool ValidateImageBounds(const debug_report_data *report_data, const IMAGE_STATE *image_state, const uint32_t regionCount,
2937 const VkBufferImageCopy *pRegions, const char *func_name, UNIQUE_VALIDATION_ERROR_CODE msg_code) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002938 bool skip = false;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002939 const VkImageCreateInfo *image_info = &(image_state->createInfo);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002940
2941 for (uint32_t i = 0; i < regionCount; i++) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002942 VkExtent3D extent = pRegions[i].imageExtent;
2943 VkOffset3D offset = pRegions[i].imageOffset;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002944
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002945 if (IsExtentSizeZero(&extent)) // Warn on zero area subresource
2946 {
2947 skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2948 (uint64_t)0, __LINE__, IMAGE_ZERO_AREA_SUBREGION, "IMAGE",
2949 "%s: pRegion[%d] imageExtent of {%1d, %1d, %1d} has zero area", func_name, i, extent.width,
2950 extent.height, extent.depth);
2951 }
2952
2953 VkExtent3D image_extent = GetImageSubresourceExtent(image_state, &(pRegions[i].imageSubresource));
2954
2955 // If we're using a compressed format, valid extent is rounded up to multiple of block size (per 18.1)
Dave Houlton1d2022c2017-03-29 11:43:58 -06002956 if (FormatIsCompressed(image_info->format)) {
2957 auto block_extent = FormatCompressedTexelBlockExtent(image_info->format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002958 if (image_extent.width % block_extent.width) {
2959 image_extent.width += (block_extent.width - (image_extent.width % block_extent.width));
2960 }
2961 if (image_extent.height % block_extent.height) {
2962 image_extent.height += (block_extent.height - (image_extent.height % block_extent.height));
2963 }
2964 if (image_extent.depth % block_extent.depth) {
2965 image_extent.depth += (block_extent.depth - (image_extent.depth % block_extent.depth));
2966 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002967 }
2968
Dave Houltonfc1a4052017-04-27 14:32:45 -06002969 if (0 != ExceedsBounds(&offset, &extent, &image_extent)) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002970 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
Dave Houlton9dae7ec2017-03-01 16:23:25 -07002971 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds image bounds. %s.", func_name, i,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002972 validation_error_map[msg_code]);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07002973 }
2974 }
2975
2976 return skip;
2977}
2978
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002979static inline bool ValidtateBufferBounds(const debug_report_data *report_data, IMAGE_STATE *image_state, BUFFER_STATE *buff_state,
2980 uint32_t regionCount, const VkBufferImageCopy *pRegions, const char *func_name,
2981 UNIQUE_VALIDATION_ERROR_CODE msg_code) {
2982 bool skip = false;
2983
2984 VkDeviceSize buffer_size = buff_state->createInfo.size;
2985
2986 for (uint32_t i = 0; i < regionCount; i++) {
2987 VkExtent3D copy_extent = pRegions[i].imageExtent;
2988
2989 VkDeviceSize buffer_width = (0 == pRegions[i].bufferRowLength ? copy_extent.width : pRegions[i].bufferRowLength);
2990 VkDeviceSize buffer_height = (0 == pRegions[i].bufferImageHeight ? copy_extent.height : pRegions[i].bufferImageHeight);
Dave Houlton1d2022c2017-03-29 11:43:58 -06002991 VkDeviceSize unit_size = FormatSize(image_state->createInfo.format); // size (bytes) of texel or block
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07002992
Dave Houltonf3229d52017-02-21 15:59:08 -07002993 // Handle special buffer packing rules for specific depth/stencil formats
2994 if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
Dave Houlton1d2022c2017-03-29 11:43:58 -06002995 unit_size = FormatSize(VK_FORMAT_S8_UINT);
Dave Houltonf3229d52017-02-21 15:59:08 -07002996 } else if (pRegions[i].imageSubresource.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2997 switch (image_state->createInfo.format) {
2998 case VK_FORMAT_D16_UNORM_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06002999 unit_size = FormatSize(VK_FORMAT_D16_UNORM);
Dave Houltonf3229d52017-02-21 15:59:08 -07003000 break;
3001 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Dave Houlton1d2022c2017-03-29 11:43:58 -06003002 unit_size = FormatSize(VK_FORMAT_D32_SFLOAT);
Dave Houltonf3229d52017-02-21 15:59:08 -07003003 break;
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003004 case VK_FORMAT_X8_D24_UNORM_PACK32: // Fall through
Dave Houltonf3229d52017-02-21 15:59:08 -07003005 case VK_FORMAT_D24_UNORM_S8_UINT:
3006 unit_size = 4;
3007 break;
3008 default:
3009 break;
3010 }
3011 }
3012
Dave Houlton1d2022c2017-03-29 11:43:58 -06003013 if (FormatIsCompressed(image_state->createInfo.format)) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003014 // Switch to texel block units, rounding up for any partially-used blocks
Dave Houlton1d2022c2017-03-29 11:43:58 -06003015 auto block_dim = FormatCompressedTexelBlockExtent(image_state->createInfo.format);
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003016 buffer_width = (buffer_width + block_dim.width - 1) / block_dim.width;
3017 buffer_height = (buffer_height + block_dim.height - 1) / block_dim.height;
3018
3019 copy_extent.width = (copy_extent.width + block_dim.width - 1) / block_dim.width;
3020 copy_extent.height = (copy_extent.height + block_dim.height - 1) / block_dim.height;
3021 copy_extent.depth = (copy_extent.depth + block_dim.depth - 1) / block_dim.depth;
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003022 }
3023
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003024 // Either depth or layerCount may be greater than 1 (not both). This is the number of 'slices' to copy
3025 uint32_t z_copies = std::max(copy_extent.depth, pRegions[i].imageSubresource.layerCount);
3026 if (IsExtentSizeZero(&copy_extent) || (0 == z_copies)) {
3027 // TODO: Issure warning here? Already warned in ValidateImageBounds()...
3028 } else {
3029 // Calculate buffer offset of final copied byte, + 1.
3030 VkDeviceSize max_buffer_offset = (z_copies - 1) * buffer_height * buffer_width; // offset to slice
3031 max_buffer_offset += ((copy_extent.height - 1) * buffer_width) + copy_extent.width; // add row,col
3032 max_buffer_offset *= unit_size; // convert to bytes
3033 max_buffer_offset += pRegions[i].bufferOffset; // add initial offset (bytes)
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003034
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003035 if (buffer_size < max_buffer_offset) {
3036 skip |=
3037 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)0,
3038 __LINE__, msg_code, "IMAGE", "%s: pRegion[%d] exceeds buffer size of %" PRIu64 " bytes. %s.", func_name,
3039 i, buffer_size, validation_error_map[msg_code]);
3040 }
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003041 }
3042 }
3043
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003044 return skip;
3045}
3046
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003047bool PreCallValidateCmdCopyImageToBuffer(layer_data *device_data, VkImageLayout srcImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003048 IMAGE_STATE *src_image_state, BUFFER_STATE *dst_buffer_state, uint32_t regionCount,
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003049 const VkBufferImageCopy *pRegions, const char *func_name) {
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003050 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3051 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, src_image_state, "vkCmdCopyImageToBuffer");
3052
3053 // Validate command buffer state
3054 if (CB_RECORDING != cb_node->state) {
3055 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3056 (uint64_t)cb_node->commandBuffer, __LINE__, VALIDATION_ERROR_01258, "DS",
3057 "Cannot call vkCmdCopyImageToBuffer() on command buffer which is not in recording state. %s.",
3058 validation_error_map[VALIDATION_ERROR_01258]);
3059 } else {
3060 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYIMAGETOBUFFER);
3061 }
3062
3063 // Command pool must support graphics, compute, or transfer operations
3064 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3065
3066 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3067 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3068 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3069 (uint64_t)cb_node->createInfo.commandPool, __LINE__, VALIDATION_ERROR_01259, "DS",
3070 "Cannot call vkCmdCopyImageToBuffer() on a command buffer allocated from a pool without graphics, compute, "
3071 "or transfer capabilities. %s.",
3072 validation_error_map[VALIDATION_ERROR_01259]);
3073 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003074 skip |= ValidateImageBounds(report_data, src_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003075 VALIDATION_ERROR_01245);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003076 skip |= ValidtateBufferBounds(report_data, src_image_state, dst_buffer_state, regionCount, pRegions, "vkCmdCopyImageToBuffer()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003077 VALIDATION_ERROR_01246);
3078
3079 skip |= ValidateImageSampleCount(device_data, src_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyImageToBuffer(): srcImage",
3080 VALIDATION_ERROR_01249);
3081 skip |= ValidateMemoryIsBoundToImage(device_data, src_image_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_02537);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003082 skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_02538);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003083
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003084 // Validate that SRC image & DST buffer have correct usage flags set
3085 skip |= ValidateImageUsageFlags(device_data, src_image_state, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01248,
3086 "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SRC_BIT");
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003087 skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01252,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003088 "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003089 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01260);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003090 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003091 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlisc8266452017-04-07 12:20:30 -06003092 skip |=
3093 VerifyImageLayout(device_data, cb_node, src_image_state, pRegions[i].imageSubresource, srcImageLayout,
3094 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "vkCmdCopyImageToBuffer()", VALIDATION_ERROR_01251, &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003095 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, src_image_state, &pRegions[i], i,
Tobin Ehlis2d85ec62017-03-14 15:38:48 -06003096 "vkCmdCopyImageToBuffer()");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003097 }
3098 return skip;
3099}
3100
3101void PreCallRecordCmdCopyImageToBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, IMAGE_STATE *src_image_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003102 BUFFER_STATE *dst_buffer_state, uint32_t region_count, const VkBufferImageCopy *regions,
3103 VkImageLayout src_image_layout) {
3104 // Make sure that all image slices are updated to correct layout
3105 for (uint32_t i = 0; i < region_count; ++i) {
3106 SetImageLayout(device_data, cb_node, src_image_state, regions[i].imageSubresource, src_image_layout);
3107 }
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003108 // Update bindings between buffer/image and cmd buffer
3109 AddCommandBufferBindingImage(device_data, cb_node, src_image_state);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003110 AddCommandBufferBindingBuffer(device_data, cb_node, dst_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003111
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003112 std::function<bool()> function = [=]() {
3113 return ValidateImageMemoryIsValid(device_data, src_image_state, "vkCmdCopyImageToBuffer()");
3114 };
3115 cb_node->validate_functions.push_back(function);
3116 function = [=]() {
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003117 SetBufferMemoryValid(device_data, dst_buffer_state, true);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003118 return false;
3119 };
3120 cb_node->validate_functions.push_back(function);
3121
3122 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYIMAGETOBUFFER);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003123}
3124
3125bool PreCallValidateCmdCopyBufferToImage(layer_data *device_data, VkImageLayout dstImageLayout, GLOBAL_CB_NODE *cb_node,
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003126 BUFFER_STATE *src_buffer_state, IMAGE_STATE *dst_image_state, uint32_t regionCount,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003127 const VkBufferImageCopy *pRegions, const char *func_name) {
3128 const debug_report_data *report_data = core_validation::GetReportData(device_data);
3129 bool skip = ValidateBufferImageCopyData(report_data, regionCount, pRegions, dst_image_state, "vkCmdCopyBufferToImage");
3130
3131 // Validate command buffer state
3132 if (CB_RECORDING != cb_node->state) {
3133 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3134 (uint64_t)cb_node->commandBuffer, __LINE__, VALIDATION_ERROR_01240, "DS",
3135 "Cannot call vkCmdCopyBufferToImage() on command buffer which is not in recording state. %s.",
3136 validation_error_map[VALIDATION_ERROR_01240]);
3137 } else {
3138 skip |= ValidateCmdSubpassState(device_data, cb_node, CMD_COPYBUFFERTOIMAGE);
3139 }
3140
3141 // Command pool must support graphics, compute, or transfer operations
3142 auto pPool = GetCommandPoolNode(device_data, cb_node->createInfo.commandPool);
3143 VkQueueFlags queue_flags = GetPhysDevProperties(device_data)->queue_family_properties[pPool->queueFamilyIndex].queueFlags;
3144 if (0 == (queue_flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))) {
3145 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
3146 (uint64_t)cb_node->createInfo.commandPool, __LINE__, VALIDATION_ERROR_01241, "DS",
3147 "Cannot call vkCmdCopyBufferToImage() on a command buffer allocated from a pool without graphics, compute, "
3148 "or transfer capabilities. %s.",
3149 validation_error_map[VALIDATION_ERROR_01241]);
3150 }
Dave Houlton9dae7ec2017-03-01 16:23:25 -07003151 skip |= ValidateImageBounds(report_data, dst_image_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003152 VALIDATION_ERROR_01228);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003153 skip |= ValidtateBufferBounds(report_data, dst_image_state, src_buffer_state, regionCount, pRegions, "vkCmdCopyBufferToImage()",
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003154 VALIDATION_ERROR_01227);
3155 skip |= ValidateImageSampleCount(device_data, dst_image_state, VK_SAMPLE_COUNT_1_BIT, "vkCmdCopyBufferToImage(): dstImage",
3156 VALIDATION_ERROR_01232);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003157 skip |= ValidateMemoryIsBoundToBuffer(device_data, src_buffer_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_02535);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003158 skip |= ValidateMemoryIsBoundToImage(device_data, dst_image_state, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_02536);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003159 skip |= ValidateBufferUsageFlags(device_data, src_buffer_state, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, true, VALIDATION_ERROR_01230,
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003160 "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
3161 skip |= ValidateImageUsageFlags(device_data, dst_image_state, VK_IMAGE_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01231,
3162 "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003163 skip |= insideRenderPass(device_data, cb_node, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01242);
Tobin Ehlisc8266452017-04-07 12:20:30 -06003164 bool hit_error = false;
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003165 for (uint32_t i = 0; i < regionCount; ++i) {
Tobin Ehlisc8266452017-04-07 12:20:30 -06003166 skip |=
3167 VerifyImageLayout(device_data, cb_node, dst_image_state, pRegions[i].imageSubresource, dstImageLayout,
3168 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "vkCmdCopyBufferToImage()", VALIDATION_ERROR_01234, &hit_error);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003169 skip |= ValidateCopyBufferImageTransferGranularityRequirements(device_data, cb_node, dst_image_state, &pRegions[i], i,
3170 "vkCmdCopyBufferToImage()");
3171 }
3172 return skip;
3173}
3174
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003175void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *src_buffer_state,
Tobin Ehlise35b66a2017-03-15 12:18:31 -06003176 IMAGE_STATE *dst_image_state, uint32_t region_count, const VkBufferImageCopy *regions,
3177 VkImageLayout dst_image_layout) {
3178 // Make sure that all image slices are updated to correct layout
3179 for (uint32_t i = 0; i < region_count; ++i) {
3180 SetImageLayout(device_data, cb_node, dst_image_state, regions[i].imageSubresource, dst_image_layout);
3181 }
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003182 AddCommandBufferBindingBuffer(device_data, cb_node, src_buffer_state);
Mark Lobodzinski033c90b2017-02-15 13:58:23 -07003183 AddCommandBufferBindingImage(device_data, cb_node, dst_image_state);
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003184 std::function<bool()> function = [=]() {
3185 SetImageMemoryValid(device_data, dst_image_state, true);
3186 return false;
3187 };
3188 cb_node->validate_functions.push_back(function);
Mark Lobodzinski1fe9b002017-02-15 14:11:12 -07003189 function = [=]() { return ValidateBufferMemoryIsValid(device_data, src_buffer_state, "vkCmdCopyBufferToImage()"); };
Mark Lobodzinskid2b2f612017-02-15 13:45:18 -07003190 cb_node->validate_functions.push_back(function);
3191
3192 core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFERTOIMAGE);
Mark Lobodzinskiab9ea3e2017-02-15 12:59:00 -07003193}
Mike Weiblen672b58b2017-02-21 14:32:53 -07003194
3195bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) {
3196 const auto report_data = core_validation::GetReportData(device_data);
3197 bool skip = false;
3198 const VkImageAspectFlags sub_aspect = pSubresource->aspectMask;
3199
3200 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
3201 const int num_bits = sizeof(sub_aspect) * CHAR_BIT;
3202 std::bitset<num_bits> aspect_mask_bits(sub_aspect);
3203 if (aspect_mask_bits.count() != 1) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003204 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3205 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00733, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003206 "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s",
3207 validation_error_map[VALIDATION_ERROR_00733]);
3208 }
3209
3210 IMAGE_STATE *image_entry = GetImageState(device_data, image);
3211 if (!image_entry) {
3212 return skip;
3213 }
3214
3215 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
3216 if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003217 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3218 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00732, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003219 "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s",
3220 validation_error_map[VALIDATION_ERROR_00732]);
3221 }
3222
3223 // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
3224 if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003225 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3226 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00739, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003227 "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s",
3228 pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_00739]);
3229 }
3230
3231 // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
3232 if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003233 skip |=
3234 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3235 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00740, "IMAGE",
3236 "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s",
3237 pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_00740]);
Mike Weiblen672b58b2017-02-21 14:32:53 -07003238 }
3239
3240 // VU 00741: subresource's aspect must be compatible with image's format.
3241 const VkFormat img_format = image_entry->createInfo.format;
Dave Houlton1d2022c2017-03-29 11:43:58 -06003242 if (FormatIsColor(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003243 if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) {
3244 skip |= log_msg(
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003245 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3246 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003247 "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s",
3248 validation_error_map[VALIDATION_ERROR_00741]);
3249 }
Dave Houlton1d2022c2017-03-29 11:43:58 -06003250 } else if (FormatIsDepthOrStencil(img_format)) {
Mike Weiblen672b58b2017-02-21 14:32:53 -07003251 if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinski0827aec2017-03-21 16:41:45 -06003252 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
3253 reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_00741, "IMAGE",
Mike Weiblen672b58b2017-02-21 14:32:53 -07003254 "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be "
3255 "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s",
3256 validation_error_map[VALIDATION_ERROR_00741]);
3257 }
3258 }
3259 return skip;
3260}