1 /*
2  * Copyright (c) 2015-2019 The Khronos Group Inc.
3  * Copyright (c) 2015-2019 Valve Corporation
4  * Copyright (c) 2015-2019 LunarG, Inc.
5  * Copyright (c) 2015-2019 Google, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Author: Chia-I Wu <olvaffe@gmail.com>
14  * Author: Chris Forbes <chrisf@ijw.co.nz>
15  * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16  * Author: Mark Lobodzinski <mark@lunarg.com>
17  * Author: Mike Stroyan <mike@LunarG.com>
18  * Author: Tobin Ehlis <tobine@google.com>
19  * Author: Tony Barbour <tony@LunarG.com>
20  * Author: Cody Northrop <cnorthrop@google.com>
21  * Author: Dave Houlton <daveh@lunarg.com>
22  * Author: Jeremy Kniager <jeremyk@lunarg.com>
23  * Author: Shannon McPherson <shannon@lunarg.com>
24  * Author: John Zulauf <jzulauf@lunarg.com>
25  */
26 
27 #include "cast_utils.h"
28 #include "layer_validation_tests.h"
29 
TEST_F(VkLayerTest,MirrorClampToEdgeNotEnabled)30 TEST_F(VkLayerTest, MirrorClampToEdgeNotEnabled) {
31     TEST_DESCRIPTION("Validation should catch using CLAMP_TO_EDGE addressing mode if the extension is not enabled.");
32 
33     ASSERT_NO_FATAL_FAILURE(Init());
34 
35     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkSamplerCreateInfo-addressModeU-01079");
36     VkSampler sampler = VK_NULL_HANDLE;
37     VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
38     // Set the modes to cause the error
39     sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
40     sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
41     sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
42 
43     vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
44     m_errorMonitor->VerifyFound();
45 }
46 
TEST_F(VkLayerTest,AnisotropyFeatureDisabled)47 TEST_F(VkLayerTest, AnisotropyFeatureDisabled) {
48     TEST_DESCRIPTION("Validation should check anisotropy parameters are correct with samplerAnisotropy disabled.");
49 
50     // Determine if required device features are available
51     VkPhysicalDeviceFeatures device_features = {};
52     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
53     ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
54     device_features.samplerAnisotropy = VK_FALSE;  // force anisotropy off
55     ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
56 
57     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkSamplerCreateInfo-anisotropyEnable-01070");
58     VkSamplerCreateInfo sampler_info = SafeSaneSamplerCreateInfo();
59     // With the samplerAnisotropy disable, the sampler must not enable it.
60     sampler_info.anisotropyEnable = VK_TRUE;
61     VkSampler sampler = VK_NULL_HANDLE;
62 
63     VkResult err;
64     err = vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
65     m_errorMonitor->VerifyFound();
66     if (VK_SUCCESS == err) {
67         vkDestroySampler(m_device->device(), sampler, NULL);
68     }
69     sampler = VK_NULL_HANDLE;
70 }
71 
TEST_F(VkLayerTest,AnisotropyFeatureEnabled)72 TEST_F(VkLayerTest, AnisotropyFeatureEnabled) {
73     TEST_DESCRIPTION("Validation must check several conditions that apply only when Anisotropy is enabled.");
74 
75     // Determine if required device features are available
76     VkPhysicalDeviceFeatures device_features = {};
77     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
78     ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
79 
80     // These tests require that the device support anisotropic filtering
81     if (VK_TRUE != device_features.samplerAnisotropy) {
82         printf("%s Test requires unsupported samplerAnisotropy feature. Skipped.\n", kSkipPrefix);
83         return;
84     }
85 
86     bool cubic_support = false;
87     if (DeviceExtensionSupported(gpu(), nullptr, "VK_IMG_filter_cubic")) {
88         m_device_extension_names.push_back("VK_IMG_filter_cubic");
89         cubic_support = true;
90     }
91 
92     VkSamplerCreateInfo sampler_info_ref = SafeSaneSamplerCreateInfo();
93     sampler_info_ref.anisotropyEnable = VK_TRUE;
94     VkSamplerCreateInfo sampler_info = sampler_info_ref;
95     ASSERT_NO_FATAL_FAILURE(InitState());
96 
97     // maxAnisotropy out-of-bounds low.
98     sampler_info.maxAnisotropy = NearestSmaller(1.0F);
99     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-anisotropyEnable-01071");
100     sampler_info.maxAnisotropy = sampler_info_ref.maxAnisotropy;
101 
102     // maxAnisotropy out-of-bounds high.
103     sampler_info.maxAnisotropy = NearestGreater(m_device->phy().properties().limits.maxSamplerAnisotropy);
104     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-anisotropyEnable-01071");
105     sampler_info.maxAnisotropy = sampler_info_ref.maxAnisotropy;
106 
107     // Both anisotropy and unnormalized coords enabled
108     sampler_info.unnormalizedCoordinates = VK_TRUE;
109     // If unnormalizedCoordinates is VK_TRUE, minLod and maxLod must be zero
110     sampler_info.minLod = 0;
111     sampler_info.maxLod = 0;
112     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01076");
113     sampler_info.unnormalizedCoordinates = sampler_info_ref.unnormalizedCoordinates;
114 
115     // Both anisotropy and cubic filtering enabled
116     if (cubic_support) {
117         sampler_info.minFilter = VK_FILTER_CUBIC_IMG;
118         CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-magFilter-01081");
119         sampler_info.minFilter = sampler_info_ref.minFilter;
120 
121         sampler_info.magFilter = VK_FILTER_CUBIC_IMG;
122         CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-magFilter-01081");
123         sampler_info.magFilter = sampler_info_ref.magFilter;
124     } else {
125         printf("%s Test requires unsupported extension \"VK_IMG_filter_cubic\". Skipped.\n", kSkipPrefix);
126     }
127 }
128 
TEST_F(VkLayerTest,UnnormalizedCoordinatesEnabled)129 TEST_F(VkLayerTest, UnnormalizedCoordinatesEnabled) {
130     TEST_DESCRIPTION("Validate restrictions on sampler parameters when unnormalizedCoordinates is true.");
131 
132     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
133     VkSamplerCreateInfo sampler_info_ref = SafeSaneSamplerCreateInfo();
134     sampler_info_ref.unnormalizedCoordinates = VK_TRUE;
135     sampler_info_ref.minLod = 0.0f;
136     sampler_info_ref.maxLod = 0.0f;
137     VkSamplerCreateInfo sampler_info = sampler_info_ref;
138     ASSERT_NO_FATAL_FAILURE(InitState());
139 
140     // min and mag filters must be the same
141     sampler_info.minFilter = VK_FILTER_NEAREST;
142     sampler_info.magFilter = VK_FILTER_LINEAR;
143     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01072");
144     std::swap(sampler_info.minFilter, sampler_info.magFilter);
145     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01072");
146     sampler_info = sampler_info_ref;
147 
148     // mipmapMode must be NEAREST
149     sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
150     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01073");
151     sampler_info = sampler_info_ref;
152 
153     // minlod and maxlod must be zero
154     sampler_info.maxLod = 3.14159f;
155     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074");
156     sampler_info.minLod = 2.71828f;
157     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074");
158     sampler_info = sampler_info_ref;
159 
160     // addressModeU and addressModeV must both be CLAMP_TO_EDGE or CLAMP_TO_BORDER
161     // checks all 12 invalid combinations out of 16 total combinations
162     const std::array<VkSamplerAddressMode, 4> kAddressModes = {{
163         VK_SAMPLER_ADDRESS_MODE_REPEAT,
164         VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
165         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
166         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
167     }};
168     for (const auto umode : kAddressModes) {
169         for (const auto vmode : kAddressModes) {
170             if ((umode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && umode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
171                 (vmode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE && vmode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
172                 sampler_info.addressModeU = umode;
173                 sampler_info.addressModeV = vmode;
174                 CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01075");
175             }
176         }
177     }
178     sampler_info = sampler_info_ref;
179 
180     // VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01076 is tested in AnisotropyFeatureEnabled above
181     // Since it requires checking/enabling the anisotropic filtering feature, it's easier to do it
182     // with the other anisotropic tests.
183 
184     // compareEnable must be VK_FALSE
185     sampler_info.compareEnable = VK_TRUE;
186     CreateSamplerTest(*this, &sampler_info, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01077");
187     sampler_info = sampler_info_ref;
188 }
189 
TEST_F(VkLayerTest,UpdateBufferAlignment)190 TEST_F(VkLayerTest, UpdateBufferAlignment) {
191     TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
192     uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
193 
194     ASSERT_NO_FATAL_FAILURE(Init());
195 
196     VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
197     VkBufferObj buffer;
198     buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
199 
200     m_commandBuffer->begin();
201     // Introduce failure by using dstOffset that is not multiple of 4
202     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
203     m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
204     m_errorMonitor->VerifyFound();
205 
206     // Introduce failure by using dataSize that is not multiple of 4
207     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
208     m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
209     m_errorMonitor->VerifyFound();
210 
211     // Introduce failure by using dataSize that is < 0
212     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
213                                          "must be greater than zero and less than or equal to 65536");
214     m_commandBuffer->UpdateBuffer(buffer.handle(), 0, (VkDeviceSize)-44, updateData);
215     m_errorMonitor->VerifyFound();
216 
217     // Introduce failure by using dataSize that is > 65536
218     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
219                                          "must be greater than zero and less than or equal to 65536");
220     m_commandBuffer->UpdateBuffer(buffer.handle(), 0, (VkDeviceSize)80000, updateData);
221     m_errorMonitor->VerifyFound();
222 
223     m_commandBuffer->end();
224 }
225 
TEST_F(VkLayerTest,FillBufferAlignment)226 TEST_F(VkLayerTest, FillBufferAlignment) {
227     TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
228 
229     ASSERT_NO_FATAL_FAILURE(Init());
230 
231     VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
232     VkBufferObj buffer;
233     buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
234 
235     m_commandBuffer->begin();
236 
237     // Introduce failure by using dstOffset that is not multiple of 4
238     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
239     m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
240     m_errorMonitor->VerifyFound();
241 
242     // Introduce failure by using size that is not multiple of 4
243     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
244     m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
245     m_errorMonitor->VerifyFound();
246 
247     // Introduce failure by using size that is zero
248     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
249     m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
250     m_errorMonitor->VerifyFound();
251 
252     m_commandBuffer->end();
253 }
254 
TEST_F(VkLayerTest,SparseBindingImageBufferCreate)255 TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
256     TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
257 
258     ASSERT_NO_FATAL_FAILURE(Init());
259 
260     VkBufferCreateInfo buf_info = {};
261     buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
262     buf_info.pNext = NULL;
263     buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
264     buf_info.size = 2048;
265     buf_info.queueFamilyIndexCount = 0;
266     buf_info.pQueueFamilyIndices = NULL;
267     buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
268 
269     if (m_device->phy().features().sparseResidencyBuffer) {
270         buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
271         CreateBufferTest(*this, &buf_info, "VUID-VkBufferCreateInfo-flags-00918");
272     } else {
273         printf("%s Test requires unsupported sparseResidencyBuffer feature. Skipped.\n", kSkipPrefix);
274         return;
275     }
276 
277     if (m_device->phy().features().sparseResidencyAliased) {
278         buf_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
279         CreateBufferTest(*this, &buf_info, "VUID-VkBufferCreateInfo-flags-00918");
280     } else {
281         printf("%s Test requires unsupported sparseResidencyAliased feature. Skipped.\n", kSkipPrefix);
282         return;
283     }
284 
285     VkImageCreateInfo image_create_info = {};
286     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
287     image_create_info.pNext = NULL;
288     image_create_info.imageType = VK_IMAGE_TYPE_2D;
289     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
290     image_create_info.extent.width = 512;
291     image_create_info.extent.height = 64;
292     image_create_info.extent.depth = 1;
293     image_create_info.mipLevels = 1;
294     image_create_info.arrayLayers = 1;
295     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
296     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
297     image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
298     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
299     image_create_info.queueFamilyIndexCount = 0;
300     image_create_info.pQueueFamilyIndices = NULL;
301     image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
302 
303     if (m_device->phy().features().sparseResidencyImage2D) {
304         image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
305         CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-flags-00987");
306     } else {
307         printf("%s Test requires unsupported sparseResidencyImage2D feature. Skipped.\n", kSkipPrefix);
308         return;
309     }
310 
311     if (m_device->phy().features().sparseResidencyAliased) {
312         image_create_info.flags = VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
313         CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-flags-00987");
314     } else {
315         printf("%s Test requires unsupported sparseResidencyAliased feature. Skipped.\n", kSkipPrefix);
316         return;
317     }
318 }
319 
TEST_F(VkLayerTest,SparseResidencyImageCreateUnsupportedTypes)320 TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
321     TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
322 
323     // Determine which device feature are available
324     VkPhysicalDeviceFeatures device_features = {};
325     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
326     ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
327 
328     // Mask out device features we don't want and initialize device state
329     device_features.sparseResidencyImage2D = VK_FALSE;
330     device_features.sparseResidencyImage3D = VK_FALSE;
331     ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
332 
333     if (!m_device->phy().features().sparseBinding) {
334         printf("%s Test requires unsupported sparseBinding feature. Skipped.\n", kSkipPrefix);
335         return;
336     }
337 
338     VkImageCreateInfo image_create_info = {};
339     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
340     image_create_info.pNext = NULL;
341     image_create_info.imageType = VK_IMAGE_TYPE_1D;
342     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
343     image_create_info.extent.width = 512;
344     image_create_info.extent.height = 1;
345     image_create_info.extent.depth = 1;
346     image_create_info.mipLevels = 1;
347     image_create_info.arrayLayers = 1;
348     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
349     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
350     image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
351     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
352     image_create_info.queueFamilyIndexCount = 0;
353     image_create_info.pQueueFamilyIndices = NULL;
354     image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
355     image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
356 
357     // 1D image w/ sparse residency is an error
358     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00970");
359 
360     // 2D image w/ sparse residency when feature isn't available
361     image_create_info.imageType = VK_IMAGE_TYPE_2D;
362     image_create_info.extent.height = 64;
363     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00971");
364 
365     // 3D image w/ sparse residency when feature isn't available
366     image_create_info.imageType = VK_IMAGE_TYPE_3D;
367     image_create_info.extent.depth = 8;
368     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00972");
369 }
370 
TEST_F(VkLayerTest,SparseResidencyImageCreateUnsupportedSamples)371 TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
372     TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
373 
374     // Determine which device feature are available
375     VkPhysicalDeviceFeatures device_features = {};
376     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
377     ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
378 
379     // These tests require that the device support sparse residency for 2D images
380     if (VK_TRUE != device_features.sparseResidencyImage2D) {
381         printf("%s Test requires unsupported SparseResidencyImage2D feature. Skipped.\n", kSkipPrefix);
382         return;
383     }
384 
385     // Mask out device features we don't want and initialize device state
386     device_features.sparseResidency2Samples = VK_FALSE;
387     device_features.sparseResidency4Samples = VK_FALSE;
388     device_features.sparseResidency8Samples = VK_FALSE;
389     device_features.sparseResidency16Samples = VK_FALSE;
390     ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
391 
392     VkImageCreateInfo image_create_info = {};
393     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
394     image_create_info.pNext = NULL;
395     image_create_info.imageType = VK_IMAGE_TYPE_2D;
396     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
397     image_create_info.extent.width = 64;
398     image_create_info.extent.height = 64;
399     image_create_info.extent.depth = 1;
400     image_create_info.mipLevels = 1;
401     image_create_info.arrayLayers = 1;
402     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
403     image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
404     image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
405     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
406     image_create_info.queueFamilyIndexCount = 0;
407     image_create_info.pQueueFamilyIndices = NULL;
408     image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
409     image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
410 
411     // 2D image w/ sparse residency and linear tiling is an error
412     CreateImageTest(*this, &image_create_info,
413                     "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
414     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
415 
416     // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
417     image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
418     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00973");
419 
420     image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
421     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00974");
422 
423     image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
424     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00975");
425 
426     image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
427     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-imageType-00976");
428 }
429 
TEST_F(VkLayerTest,InvalidMemoryMapping)430 TEST_F(VkLayerTest, InvalidMemoryMapping) {
431     TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
432     VkResult err;
433     bool pass;
434     ASSERT_NO_FATAL_FAILURE(Init());
435 
436     VkBuffer buffer;
437     VkDeviceMemory mem;
438     VkMemoryRequirements mem_reqs;
439 
440     const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
441 
442     VkBufferCreateInfo buf_info = {};
443     buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
444     buf_info.pNext = NULL;
445     buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
446     buf_info.size = 256;
447     buf_info.queueFamilyIndexCount = 0;
448     buf_info.pQueueFamilyIndices = NULL;
449     buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
450     buf_info.flags = 0;
451     err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
452     ASSERT_VK_SUCCESS(err);
453 
454     vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
455     VkMemoryAllocateInfo alloc_info = {};
456     alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
457     alloc_info.pNext = NULL;
458     alloc_info.memoryTypeIndex = 0;
459 
460     // Ensure memory is big enough for both bindings
461     static const VkDeviceSize allocation_size = 0x10000;
462     alloc_info.allocationSize = allocation_size;
463     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
464     if (!pass) {
465         printf("%s Failed to set memory type.\n", kSkipPrefix);
466         vkDestroyBuffer(m_device->device(), buffer, NULL);
467         return;
468     }
469     err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
470     ASSERT_VK_SUCCESS(err);
471 
472     uint8_t *pData;
473     // Attempt to map memory size 0 is invalid
474     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
475     err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
476     m_errorMonitor->VerifyFound();
477     // Map memory twice
478     err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
479     ASSERT_VK_SUCCESS(err);
480     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-CoreValidation-MemTrack-InvalidMap");
481     err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
482     m_errorMonitor->VerifyFound();
483 
484     // Unmap the memory to avoid re-map error
485     vkUnmapMemory(m_device->device(), mem);
486     // overstep allocation with VK_WHOLE_SIZE
487     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
488                                          " with size of VK_WHOLE_SIZE oversteps total array size 0x");
489     err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
490     m_errorMonitor->VerifyFound();
491     // overstep allocation w/o VK_WHOLE_SIZE
492     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
493     err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
494     m_errorMonitor->VerifyFound();
495     // Now error due to unmapping memory that's not mapped
496     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
497     vkUnmapMemory(m_device->device(), mem);
498     m_errorMonitor->VerifyFound();
499 
500     // Now map memory and cause errors due to flushing invalid ranges
501     err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
502     ASSERT_VK_SUCCESS(err);
503     VkMappedMemoryRange mmr = {};
504     mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
505     mmr.memory = mem;
506     mmr.offset = atom_size;  // Error b/c offset less than offset of mapped mem
507     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkMappedMemoryRange-size-00685");
508     vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
509     m_errorMonitor->VerifyFound();
510 
511     // Now flush range that oversteps mapped range
512     vkUnmapMemory(m_device->device(), mem);
513     err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
514     ASSERT_VK_SUCCESS(err);
515     mmr.offset = atom_size;
516     mmr.size = 4 * atom_size;  // Flushing bounds exceed mapped bounds
517     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkMappedMemoryRange-size-00685");
518     vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
519     m_errorMonitor->VerifyFound();
520 
521     // Now flush range with VK_WHOLE_SIZE that oversteps offset
522     vkUnmapMemory(m_device->device(), mem);
523     err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
524     ASSERT_VK_SUCCESS(err);
525     mmr.offset = atom_size;
526     mmr.size = VK_WHOLE_SIZE;
527     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkMappedMemoryRange-size-00686");
528     vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
529     m_errorMonitor->VerifyFound();
530 
531     // Some platforms have an atomsize of 1 which makes the test meaningless
532     if (atom_size > 3) {
533         // Now with an offset NOT a multiple of the device limit
534         vkUnmapMemory(m_device->device(), mem);
535         err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
536         ASSERT_VK_SUCCESS(err);
537         mmr.offset = 3;  // Not a multiple of atom_size
538         mmr.size = VK_WHOLE_SIZE;
539         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkMappedMemoryRange-offset-00687");
540         vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
541         m_errorMonitor->VerifyFound();
542 
543         // Now with a size NOT a multiple of the device limit
544         vkUnmapMemory(m_device->device(), mem);
545         err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
546         ASSERT_VK_SUCCESS(err);
547         mmr.offset = atom_size;
548         mmr.size = 2 * atom_size + 1;  // Not a multiple of atom_size
549         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkMappedMemoryRange-size-01390");
550         vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
551         m_errorMonitor->VerifyFound();
552     }
553 
554     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
555                                            VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
556     if (!pass) {
557         printf("%s Failed to set memory type.\n", kSkipPrefix);
558         vkFreeMemory(m_device->device(), mem, NULL);
559         vkDestroyBuffer(m_device->device(), buffer, NULL);
560         return;
561     }
562     // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
563     //  kVUID_Core_MemTrack_InvalidMap in validateAndCopyNoncoherentMemoryToDriver()
564 
565     vkDestroyBuffer(m_device->device(), buffer, NULL);
566     vkFreeMemory(m_device->device(), mem, NULL);
567 }
568 
TEST_F(VkLayerTest,MapMemWithoutHostVisibleBit)569 TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
570     TEST_DESCRIPTION("Allocate memory that is not mappable and then attempt to map it.");
571     VkResult err;
572     bool pass;
573 
574     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkMapMemory-memory-00682");
575     ASSERT_NO_FATAL_FAILURE(Init());
576 
577     VkMemoryAllocateInfo mem_alloc = {};
578     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
579     mem_alloc.pNext = NULL;
580     mem_alloc.allocationSize = 1024;
581 
582     pass = m_device->phy().set_memory_type(0xFFFFFFFF, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
583     if (!pass) {  // If we can't find any unmappable memory this test doesn't
584                   // make sense
585         printf("%s No unmappable memory types found, skipping test\n", kSkipPrefix);
586         return;
587     }
588 
589     VkDeviceMemory mem;
590     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
591     ASSERT_VK_SUCCESS(err);
592 
593     void *mappedAddress = NULL;
594     err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
595     m_errorMonitor->VerifyFound();
596 
597     vkFreeMemory(m_device->device(), mem, NULL);
598 }
599 
TEST_F(VkLayerTest,RebindMemory)600 TEST_F(VkLayerTest, RebindMemory) {
601     VkResult err;
602     bool pass;
603 
604     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-image-01044");
605 
606     ASSERT_NO_FATAL_FAILURE(Init());
607 
608     // Create an image, allocate memory, free it, and then try to bind it
609     VkImage image;
610     VkDeviceMemory mem1;
611     VkDeviceMemory mem2;
612     VkMemoryRequirements mem_reqs;
613 
614     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
615     const int32_t tex_width = 32;
616     const int32_t tex_height = 32;
617 
618     VkImageCreateInfo image_create_info = {};
619     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
620     image_create_info.pNext = NULL;
621     image_create_info.imageType = VK_IMAGE_TYPE_2D;
622     image_create_info.format = tex_format;
623     image_create_info.extent.width = tex_width;
624     image_create_info.extent.height = tex_height;
625     image_create_info.extent.depth = 1;
626     image_create_info.mipLevels = 1;
627     image_create_info.arrayLayers = 1;
628     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
629     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
630     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
631     image_create_info.flags = 0;
632 
633     VkMemoryAllocateInfo mem_alloc = {};
634     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
635     mem_alloc.pNext = NULL;
636     mem_alloc.allocationSize = 0;
637     mem_alloc.memoryTypeIndex = 0;
638 
639     // Introduce failure, do NOT set memProps to
640     // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
641     mem_alloc.memoryTypeIndex = 1;
642     err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
643     ASSERT_VK_SUCCESS(err);
644 
645     vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
646 
647     mem_alloc.allocationSize = mem_reqs.size;
648     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
649     ASSERT_TRUE(pass);
650 
651     // allocate 2 memory objects
652     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
653     ASSERT_VK_SUCCESS(err);
654     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
655     ASSERT_VK_SUCCESS(err);
656 
657     // Bind first memory object to Image object
658     err = vkBindImageMemory(m_device->device(), image, mem1, 0);
659     ASSERT_VK_SUCCESS(err);
660 
661     // Introduce validation failure, try to bind a different memory object to
662     // the same image object
663     err = vkBindImageMemory(m_device->device(), image, mem2, 0);
664 
665     m_errorMonitor->VerifyFound();
666 
667     vkDestroyImage(m_device->device(), image, NULL);
668     vkFreeMemory(m_device->device(), mem1, NULL);
669     vkFreeMemory(m_device->device(), mem2, NULL);
670 }
671 
TEST_F(VkLayerTest,QueryMemoryCommitmentWithoutLazyProperty)672 TEST_F(VkLayerTest, QueryMemoryCommitmentWithoutLazyProperty) {
673     TEST_DESCRIPTION("Attempt to query memory commitment on memory without lazy allocation");
674     ASSERT_NO_FATAL_FAILURE(Init());
675 
676     auto image_ci = vk_testing::Image::create_info();
677     image_ci.imageType = VK_IMAGE_TYPE_2D;
678     image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
679     image_ci.extent.width = 32;
680     image_ci.extent.height = 32;
681     image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
682     image_ci.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
683     VkImageObj image(m_device);
684     image.init_no_mem(*m_device, image_ci);
685 
686     auto mem_reqs = image.memory_requirements();
687     // memory_type_index is set to 0 here, but is set properly below
688     auto image_alloc_info = vk_testing::DeviceMemory::alloc_info(mem_reqs.size, 0);
689 
690     bool pass;
691     // the last argument is the "forbid" argument for set_memory_type, disallowing
692     // that particular memory type rather than requiring it
693     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &image_alloc_info, 0, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT);
694     if (!pass) {
695         printf("%s Failed to set memory type.\n", kSkipPrefix);
696         return;
697     }
698     vk_testing::DeviceMemory mem;
699     mem.init(*m_device, image_alloc_info);
700 
701     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetDeviceMemoryCommitment-memory-00690");
702     VkDeviceSize size;
703     vkGetDeviceMemoryCommitment(m_device->device(), mem.handle(), &size);
704     m_errorMonitor->VerifyFound();
705 }
706 
TEST_F(VkLayerTest,InvalidUsageBits)707 TEST_F(VkLayerTest, InvalidUsageBits) {
708     TEST_DESCRIPTION(
709         "Specify wrong usage for image then create conflicting view of image Initialize buffer with wrong usage then perform copy "
710         "expecting errors from both the image and the buffer (2 calls)");
711 
712     ASSERT_NO_FATAL_FAILURE(Init());
713     auto format = FindSupportedDepthStencilFormat(gpu());
714     if (!format) {
715         printf("%s No Depth + Stencil format found. Skipped.\n", kSkipPrefix);
716         return;
717     }
718 
719     VkImageObj image(m_device);
720     // Initialize image with transfer source usage
721     image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
722     ASSERT_TRUE(image.initialized());
723 
724     VkImageView dsv;
725     VkImageViewCreateInfo dsvci = {};
726     dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
727     dsvci.image = image.handle();
728     dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
729     dsvci.format = format;
730     dsvci.subresourceRange.layerCount = 1;
731     dsvci.subresourceRange.baseMipLevel = 0;
732     dsvci.subresourceRange.levelCount = 1;
733     dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
734 
735     // Create a view with depth / stencil aspect for image with different usage
736     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-CoreValidation-MemTrack-InvalidUsageFlag");
737     vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
738     m_errorMonitor->VerifyFound();
739 
740     // Initialize buffer with TRANSFER_DST usage
741     VkBufferObj buffer;
742     VkMemoryPropertyFlags reqs = 0;
743     buffer.init_as_dst(*m_device, 128 * 128, reqs);
744     VkBufferImageCopy region = {};
745     region.bufferRowLength = 128;
746     region.bufferImageHeight = 128;
747     region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
748     region.imageSubresource.layerCount = 1;
749     region.imageExtent.height = 16;
750     region.imageExtent.width = 16;
751     region.imageExtent.depth = 1;
752 
753     // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
754     m_commandBuffer->begin();
755 
756     // two separate errors from this call:
757     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdCopyBufferToImage-dstImage-00177");
758     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdCopyBufferToImage-srcBuffer-00174");
759 
760     vkCmdCopyBufferToImage(m_commandBuffer->handle(), buffer.handle(), image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
761                            &region);
762     m_errorMonitor->VerifyFound();
763 }
764 
TEST_F(VkLayerTest,CopyBufferToCompressedImage)765 TEST_F(VkLayerTest, CopyBufferToCompressedImage) {
766     TEST_DESCRIPTION("Copy buffer to compressed image when buffer is larger than image.");
767     ASSERT_NO_FATAL_FAILURE(Init());
768 
769     // Verify format support
770     if (!ImageFormatAndFeaturesSupported(gpu(), VK_FORMAT_BC1_RGBA_SRGB_BLOCK, VK_IMAGE_TILING_OPTIMAL,
771                                          VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR)) {
772         printf("%s Required formats/features not supported - CopyBufferToCompressedImage skipped.\n", kSkipPrefix);
773         return;
774     }
775 
776     VkImageObj width_image(m_device);
777     VkImageObj height_image(m_device);
778     VkBufferObj buffer;
779     VkMemoryPropertyFlags reqs = 0;
780     buffer.init_as_src(*m_device, 8 * 4 * 2, reqs);
781     VkBufferImageCopy region = {};
782     region.bufferRowLength = 0;
783     region.bufferImageHeight = 0;
784     region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
785     region.imageSubresource.layerCount = 1;
786     region.imageExtent.width = 8;
787     region.imageExtent.height = 4;
788     region.imageExtent.depth = 1;
789 
790     width_image.Init(5, 4, 1, VK_FORMAT_BC1_RGBA_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
791     height_image.Init(8, 3, 1, VK_FORMAT_BC1_RGBA_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
792     if (!width_image.initialized() || (!height_image.initialized())) {
793         printf("%s Unable to initialize surfaces - UncompressedToCompressedImageCopy skipped.\n", kSkipPrefix);
794         return;
795     }
796     m_commandBuffer->begin();
797 
798     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBufferImageCopy-imageOffset-00197");
799     vkCmdCopyBufferToImage(m_commandBuffer->handle(), buffer.handle(), width_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1, &region);
800     m_errorMonitor->VerifyFound();
801 
802     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBufferImageCopy-imageOffset-00200");
803     m_errorMonitor->SetUnexpectedError("VUID-vkCmdCopyBufferToImage-pRegions-00172");
804 
805     VkResult err;
806     VkImageCreateInfo depth_image_create_info = {};
807     depth_image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
808     depth_image_create_info.pNext = NULL;
809     depth_image_create_info.imageType = VK_IMAGE_TYPE_3D;
810     depth_image_create_info.format = VK_FORMAT_BC1_RGBA_SRGB_BLOCK;
811     depth_image_create_info.extent.width = 8;
812     depth_image_create_info.extent.height = 4;
813     depth_image_create_info.extent.depth = 1;
814     depth_image_create_info.mipLevels = 1;
815     depth_image_create_info.arrayLayers = 1;
816     depth_image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
817     depth_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
818     depth_image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
819     depth_image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
820     depth_image_create_info.queueFamilyIndexCount = 0;
821     depth_image_create_info.pQueueFamilyIndices = NULL;
822 
823     VkImage depth_image = VK_NULL_HANDLE;
824     err = vkCreateImage(m_device->handle(), &depth_image_create_info, NULL, &depth_image);
825     ASSERT_VK_SUCCESS(err);
826 
827     VkDeviceMemory mem1;
828     VkMemoryRequirements mem_reqs;
829     mem_reqs.memoryTypeBits = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
830     VkMemoryAllocateInfo mem_alloc = {};
831     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
832     mem_alloc.pNext = NULL;
833     mem_alloc.allocationSize = 0;
834     mem_alloc.memoryTypeIndex = 0;
835     mem_alloc.memoryTypeIndex = 1;
836     vkGetImageMemoryRequirements(m_device->device(), depth_image, &mem_reqs);
837     mem_alloc.allocationSize = mem_reqs.size;
838     bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
839     ASSERT_TRUE(pass);
840     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
841     ASSERT_VK_SUCCESS(err);
842     err = vkBindImageMemory(m_device->device(), depth_image, mem1, 0);
843 
844     region.imageExtent.depth = 2;
845     vkCmdCopyBufferToImage(m_commandBuffer->handle(), buffer.handle(), depth_image, VK_IMAGE_LAYOUT_GENERAL, 1, &region);
846     m_errorMonitor->VerifyFound();
847 
848     vkDestroyImage(m_device->device(), depth_image, NULL);
849     vkFreeMemory(m_device->device(), mem1, NULL);
850     m_commandBuffer->end();
851 }
852 
TEST_F(VkLayerTest,CreateUnknownObject)853 TEST_F(VkLayerTest, CreateUnknownObject) {
854     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageMemoryRequirements-image-parameter");
855 
856     TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
857 
858     ASSERT_NO_FATAL_FAILURE(Init());
859 
860     // Pass bogus handle into GetImageMemoryRequirements
861     VkMemoryRequirements mem_reqs;
862     uint64_t fakeImageHandle = 0xCADECADE;
863     VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
864 
865     vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
866 
867     m_errorMonitor->VerifyFound();
868 }
869 
TEST_F(VkLayerTest,BindImageInvalidMemoryType)870 TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
871     VkResult err;
872 
873     TEST_DESCRIPTION("Test validation check for an invalid memory type index during bind[Buffer|Image]Memory time");
874 
875     ASSERT_NO_FATAL_FAILURE(Init());
876 
877     // Create an image, allocate memory, set a bad typeIndex and then try to
878     // bind it
879     VkImage image;
880     VkDeviceMemory mem;
881     VkMemoryRequirements mem_reqs;
882     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
883     const int32_t tex_width = 32;
884     const int32_t tex_height = 32;
885 
886     VkImageCreateInfo image_create_info = {};
887     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
888     image_create_info.pNext = NULL;
889     image_create_info.imageType = VK_IMAGE_TYPE_2D;
890     image_create_info.format = tex_format;
891     image_create_info.extent.width = tex_width;
892     image_create_info.extent.height = tex_height;
893     image_create_info.extent.depth = 1;
894     image_create_info.mipLevels = 1;
895     image_create_info.arrayLayers = 1;
896     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
897     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
898     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
899     image_create_info.flags = 0;
900 
901     VkMemoryAllocateInfo mem_alloc = {};
902     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
903     mem_alloc.pNext = NULL;
904     mem_alloc.allocationSize = 0;
905     mem_alloc.memoryTypeIndex = 0;
906 
907     err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
908     ASSERT_VK_SUCCESS(err);
909 
910     vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
911     mem_alloc.allocationSize = mem_reqs.size;
912 
913     // Introduce Failure, select invalid TypeIndex
914     VkPhysicalDeviceMemoryProperties memory_info;
915 
916     vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
917     unsigned int i;
918     for (i = 0; i < memory_info.memoryTypeCount; i++) {
919         if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
920             mem_alloc.memoryTypeIndex = i;
921             break;
922         }
923     }
924     if (i >= memory_info.memoryTypeCount) {
925         printf("%s No invalid memory type index could be found; skipped.\n", kSkipPrefix);
926         vkDestroyImage(m_device->device(), image, NULL);
927         return;
928     }
929 
930     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
931 
932     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
933     ASSERT_VK_SUCCESS(err);
934 
935     err = vkBindImageMemory(m_device->device(), image, mem, 0);
936     (void)err;
937 
938     m_errorMonitor->VerifyFound();
939 
940     vkDestroyImage(m_device->device(), image, NULL);
941     vkFreeMemory(m_device->device(), mem, NULL);
942 }
943 
TEST_F(VkLayerTest,BindInvalidMemory)944 TEST_F(VkLayerTest, BindInvalidMemory) {
945     VkResult err;
946     bool pass;
947 
948     ASSERT_NO_FATAL_FAILURE(Init());
949 
950     const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
951     const int32_t tex_width = 256;
952     const int32_t tex_height = 256;
953 
954     VkImageCreateInfo image_create_info = {};
955     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
956     image_create_info.pNext = NULL;
957     image_create_info.imageType = VK_IMAGE_TYPE_2D;
958     image_create_info.format = tex_format;
959     image_create_info.extent.width = tex_width;
960     image_create_info.extent.height = tex_height;
961     image_create_info.extent.depth = 1;
962     image_create_info.mipLevels = 1;
963     image_create_info.arrayLayers = 1;
964     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
965     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
966     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
967     image_create_info.flags = 0;
968 
969     VkBufferCreateInfo buffer_create_info = {};
970     buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
971     buffer_create_info.pNext = NULL;
972     buffer_create_info.flags = 0;
973     buffer_create_info.size = 4 * 1024 * 1024;
974     buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
975     buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
976 
977     // Create an image/buffer, allocate memory, free it, and then try to bind it
978     {
979         VkImage image = VK_NULL_HANDLE;
980         VkBuffer buffer = VK_NULL_HANDLE;
981         err = vkCreateImage(device(), &image_create_info, NULL, &image);
982         ASSERT_VK_SUCCESS(err);
983         err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
984         ASSERT_VK_SUCCESS(err);
985         VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
986         vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
987         vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
988 
989         VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
990         image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
991         image_mem_alloc.allocationSize = image_mem_reqs.size;
992         pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
993         ASSERT_TRUE(pass);
994         buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
995         buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
996         pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
997         ASSERT_TRUE(pass);
998 
999         VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
1000         err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
1001         ASSERT_VK_SUCCESS(err);
1002         err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
1003         ASSERT_VK_SUCCESS(err);
1004 
1005         vkFreeMemory(device(), image_mem, NULL);
1006         vkFreeMemory(device(), buffer_mem, NULL);
1007 
1008         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-memory-parameter");
1009         err = vkBindImageMemory(device(), image, image_mem, 0);
1010         (void)err;  // This may very well return an error.
1011         m_errorMonitor->VerifyFound();
1012 
1013         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-memory-parameter");
1014         err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
1015         (void)err;  // This may very well return an error.
1016         m_errorMonitor->VerifyFound();
1017 
1018         vkDestroyImage(m_device->device(), image, NULL);
1019         vkDestroyBuffer(m_device->device(), buffer, NULL);
1020     }
1021 
1022     // Try to bind memory to an object that already has a memory binding
1023     {
1024         VkImage image = VK_NULL_HANDLE;
1025         err = vkCreateImage(device(), &image_create_info, NULL, &image);
1026         ASSERT_VK_SUCCESS(err);
1027         VkBuffer buffer = VK_NULL_HANDLE;
1028         err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
1029         ASSERT_VK_SUCCESS(err);
1030         VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
1031         vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
1032         vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
1033         VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
1034         image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1035         image_alloc_info.allocationSize = image_mem_reqs.size;
1036         buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1037         buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
1038         pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
1039         ASSERT_TRUE(pass);
1040         pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
1041         ASSERT_TRUE(pass);
1042         VkDeviceMemory image_mem, buffer_mem;
1043         err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
1044         ASSERT_VK_SUCCESS(err);
1045         err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
1046         ASSERT_VK_SUCCESS(err);
1047 
1048         err = vkBindImageMemory(device(), image, image_mem, 0);
1049         ASSERT_VK_SUCCESS(err);
1050         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-image-01044");
1051         err = vkBindImageMemory(device(), image, image_mem, 0);
1052         (void)err;  // This may very well return an error.
1053         m_errorMonitor->VerifyFound();
1054 
1055         err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
1056         ASSERT_VK_SUCCESS(err);
1057         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-buffer-01029");
1058         err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
1059         (void)err;  // This may very well return an error.
1060         m_errorMonitor->VerifyFound();
1061 
1062         vkFreeMemory(device(), image_mem, NULL);
1063         vkFreeMemory(device(), buffer_mem, NULL);
1064         vkDestroyImage(device(), image, NULL);
1065         vkDestroyBuffer(device(), buffer, NULL);
1066     }
1067 
1068     // Try to bind memory to an object with an invalid memoryOffset
1069     {
1070         VkImage image = VK_NULL_HANDLE;
1071         err = vkCreateImage(device(), &image_create_info, NULL, &image);
1072         ASSERT_VK_SUCCESS(err);
1073         VkBuffer buffer = VK_NULL_HANDLE;
1074         err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
1075         ASSERT_VK_SUCCESS(err);
1076         VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
1077         vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
1078         vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
1079         VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
1080         image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1081         // Leave some extra space for alignment wiggle room
1082         image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
1083         buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1084         buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
1085         pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
1086         ASSERT_TRUE(pass);
1087         pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
1088         ASSERT_TRUE(pass);
1089         VkDeviceMemory image_mem, buffer_mem;
1090         err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
1091         ASSERT_VK_SUCCESS(err);
1092         err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
1093         ASSERT_VK_SUCCESS(err);
1094 
1095         // Test unaligned memory offset
1096         {
1097             if (image_mem_reqs.alignment > 1) {
1098                 VkDeviceSize image_offset = 1;
1099                 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-memoryOffset-01048");
1100                 err = vkBindImageMemory(device(), image, image_mem, image_offset);
1101                 (void)err;  // This may very well return an error.
1102                 m_errorMonitor->VerifyFound();
1103             }
1104 
1105             if (buffer_mem_reqs.alignment > 1) {
1106                 VkDeviceSize buffer_offset = 1;
1107                 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-memoryOffset-01036");
1108                 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
1109                 (void)err;  // This may very well return an error.
1110                 m_errorMonitor->VerifyFound();
1111             }
1112         }
1113 
1114         // Test memory offsets outside the memory allocation
1115         {
1116             VkDeviceSize image_offset =
1117                 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
1118             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-memoryOffset-01046");
1119             err = vkBindImageMemory(device(), image, image_mem, image_offset);
1120             (void)err;  // This may very well return an error.
1121             m_errorMonitor->VerifyFound();
1122 
1123             VkDeviceSize buffer_offset =
1124                 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
1125             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-memoryOffset-01031");
1126             err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
1127             (void)err;  // This may very well return an error.
1128             m_errorMonitor->VerifyFound();
1129         }
1130 
1131         // Test memory offsets within the memory allocation, but which leave too little memory for
1132         // the resource.
1133         {
1134             VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
1135             if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
1136                 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-size-01049");
1137                 err = vkBindImageMemory(device(), image, image_mem, image_offset);
1138                 (void)err;  // This may very well return an error.
1139                 m_errorMonitor->VerifyFound();
1140             }
1141 
1142             VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
1143             if (buffer_offset > 0) {
1144                 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-size-01037");
1145                 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
1146                 (void)err;  // This may very well return an error.
1147                 m_errorMonitor->VerifyFound();
1148             }
1149         }
1150 
1151         vkFreeMemory(device(), image_mem, NULL);
1152         vkFreeMemory(device(), buffer_mem, NULL);
1153         vkDestroyImage(device(), image, NULL);
1154         vkDestroyBuffer(device(), buffer, NULL);
1155     }
1156 
1157     // Try to bind memory to an object with an invalid memory type
1158     {
1159         VkImage image = VK_NULL_HANDLE;
1160         err = vkCreateImage(device(), &image_create_info, NULL, &image);
1161         ASSERT_VK_SUCCESS(err);
1162         VkBuffer buffer = VK_NULL_HANDLE;
1163         err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
1164         ASSERT_VK_SUCCESS(err);
1165         VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
1166         vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
1167         vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
1168         VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
1169         image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1170         image_alloc_info.allocationSize = image_mem_reqs.size;
1171         buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1172         buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
1173         // Create a mask of available memory types *not* supported by these resources,
1174         // and try to use one of them.
1175         VkPhysicalDeviceMemoryProperties memory_properties = {};
1176         vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
1177         VkDeviceMemory image_mem, buffer_mem;
1178 
1179         uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
1180         if (image_unsupported_mem_type_bits != 0) {
1181             pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
1182             ASSERT_TRUE(pass);
1183             err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
1184             ASSERT_VK_SUCCESS(err);
1185             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-memory-01047");
1186             err = vkBindImageMemory(device(), image, image_mem, 0);
1187             (void)err;  // This may very well return an error.
1188             m_errorMonitor->VerifyFound();
1189             vkFreeMemory(device(), image_mem, NULL);
1190         }
1191 
1192         uint32_t buffer_unsupported_mem_type_bits =
1193             ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
1194         if (buffer_unsupported_mem_type_bits != 0) {
1195             pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
1196             ASSERT_TRUE(pass);
1197             err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
1198             ASSERT_VK_SUCCESS(err);
1199             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-memory-01035");
1200             err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
1201             (void)err;  // This may very well return an error.
1202             m_errorMonitor->VerifyFound();
1203             vkFreeMemory(device(), buffer_mem, NULL);
1204         }
1205 
1206         vkDestroyImage(device(), image, NULL);
1207         vkDestroyBuffer(device(), buffer, NULL);
1208     }
1209 
1210     // Try to bind memory to an image created with sparse memory flags
1211     {
1212         VkImageCreateInfo sparse_image_create_info = image_create_info;
1213         sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
1214         VkImageFormatProperties image_format_properties = {};
1215         err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
1216                                                        sparse_image_create_info.imageType, sparse_image_create_info.tiling,
1217                                                        sparse_image_create_info.usage, sparse_image_create_info.flags,
1218                                                        &image_format_properties);
1219         if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
1220             // most likely means sparse formats aren't supported here; skip this test.
1221         } else {
1222             ASSERT_VK_SUCCESS(err);
1223             if (image_format_properties.maxExtent.width == 0) {
1224                 printf("%s Sparse image format not supported; skipped.\n", kSkipPrefix);
1225                 return;
1226             } else {
1227                 VkImage sparse_image = VK_NULL_HANDLE;
1228                 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
1229                 ASSERT_VK_SUCCESS(err);
1230                 VkMemoryRequirements sparse_mem_reqs = {};
1231                 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
1232                 if (sparse_mem_reqs.memoryTypeBits != 0) {
1233                     VkMemoryAllocateInfo sparse_mem_alloc = {};
1234                     sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1235                     sparse_mem_alloc.pNext = NULL;
1236                     sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
1237                     sparse_mem_alloc.memoryTypeIndex = 0;
1238                     pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
1239                     ASSERT_TRUE(pass);
1240                     VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
1241                     err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
1242                     ASSERT_VK_SUCCESS(err);
1243                     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-image-01045");
1244                     err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
1245                     // This may very well return an error.
1246                     (void)err;
1247                     m_errorMonitor->VerifyFound();
1248                     vkFreeMemory(m_device->device(), sparse_mem, NULL);
1249                 }
1250                 vkDestroyImage(m_device->device(), sparse_image, NULL);
1251             }
1252         }
1253     }
1254 
1255     // Try to bind memory to a buffer created with sparse memory flags
1256     {
1257         VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
1258         sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
1259         if (!m_device->phy().features().sparseResidencyBuffer) {
1260             // most likely means sparse formats aren't supported here; skip this test.
1261         } else {
1262             VkBuffer sparse_buffer = VK_NULL_HANDLE;
1263             err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
1264             ASSERT_VK_SUCCESS(err);
1265             VkMemoryRequirements sparse_mem_reqs = {};
1266             vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
1267             if (sparse_mem_reqs.memoryTypeBits != 0) {
1268                 VkMemoryAllocateInfo sparse_mem_alloc = {};
1269                 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1270                 sparse_mem_alloc.pNext = NULL;
1271                 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
1272                 sparse_mem_alloc.memoryTypeIndex = 0;
1273                 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
1274                 ASSERT_TRUE(pass);
1275                 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
1276                 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
1277                 ASSERT_VK_SUCCESS(err);
1278                 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-buffer-01030");
1279                 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
1280                 // This may very well return an error.
1281                 (void)err;
1282                 m_errorMonitor->VerifyFound();
1283                 vkFreeMemory(m_device->device(), sparse_mem, NULL);
1284             }
1285             vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
1286         }
1287     }
1288 }
1289 
TEST_F(VkLayerTest,BindMemoryToDestroyedObject)1290 TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
1291     VkResult err;
1292     bool pass;
1293 
1294     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-image-parameter");
1295 
1296     ASSERT_NO_FATAL_FAILURE(Init());
1297 
1298     // Create an image object, allocate memory, destroy the object and then try
1299     // to bind it
1300     VkImage image;
1301     VkDeviceMemory mem;
1302     VkMemoryRequirements mem_reqs;
1303 
1304     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1305     const int32_t tex_width = 32;
1306     const int32_t tex_height = 32;
1307 
1308     VkImageCreateInfo image_create_info = {};
1309     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1310     image_create_info.pNext = NULL;
1311     image_create_info.imageType = VK_IMAGE_TYPE_2D;
1312     image_create_info.format = tex_format;
1313     image_create_info.extent.width = tex_width;
1314     image_create_info.extent.height = tex_height;
1315     image_create_info.extent.depth = 1;
1316     image_create_info.mipLevels = 1;
1317     image_create_info.arrayLayers = 1;
1318     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1319     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1320     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1321     image_create_info.flags = 0;
1322 
1323     VkMemoryAllocateInfo mem_alloc = {};
1324     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1325     mem_alloc.pNext = NULL;
1326     mem_alloc.allocationSize = 0;
1327     mem_alloc.memoryTypeIndex = 0;
1328 
1329     err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1330     ASSERT_VK_SUCCESS(err);
1331 
1332     vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1333 
1334     mem_alloc.allocationSize = mem_reqs.size;
1335     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
1336     ASSERT_TRUE(pass);
1337 
1338     // Allocate memory
1339     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
1340     ASSERT_VK_SUCCESS(err);
1341 
1342     // Introduce validation failure, destroy Image object before binding
1343     vkDestroyImage(m_device->device(), image, NULL);
1344     ASSERT_VK_SUCCESS(err);
1345 
1346     // Now Try to bind memory to this destroyed object
1347     err = vkBindImageMemory(m_device->device(), image, mem, 0);
1348     // This may very well return an error.
1349     (void)err;
1350 
1351     m_errorMonitor->VerifyFound();
1352 
1353     vkFreeMemory(m_device->device(), mem, NULL);
1354 }
1355 
TEST_F(VkLayerTest,ExceedMemoryAllocationCount)1356 TEST_F(VkLayerTest, ExceedMemoryAllocationCount) {
1357     VkResult err = VK_SUCCESS;
1358     const int max_mems = 32;
1359     VkDeviceMemory mems[max_mems + 1];
1360 
1361     if (!EnableDeviceProfileLayer()) {
1362         printf("%s Failed to enable device profile layer.\n", kSkipPrefix);
1363         return;
1364     }
1365 
1366     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
1367 
1368     PFN_vkSetPhysicalDeviceLimitsEXT fpvkSetPhysicalDeviceLimitsEXT =
1369         (PFN_vkSetPhysicalDeviceLimitsEXT)vkGetInstanceProcAddr(instance(), "vkSetPhysicalDeviceLimitsEXT");
1370     PFN_vkGetOriginalPhysicalDeviceLimitsEXT fpvkGetOriginalPhysicalDeviceLimitsEXT =
1371         (PFN_vkGetOriginalPhysicalDeviceLimitsEXT)vkGetInstanceProcAddr(instance(), "vkGetOriginalPhysicalDeviceLimitsEXT");
1372 
1373     if (!(fpvkSetPhysicalDeviceLimitsEXT) || !(fpvkGetOriginalPhysicalDeviceLimitsEXT)) {
1374         printf("%s Can't find device_profile_api functions; skipped.\n", kSkipPrefix);
1375         return;
1376     }
1377     VkPhysicalDeviceProperties props;
1378     fpvkGetOriginalPhysicalDeviceLimitsEXT(gpu(), &props.limits);
1379     if (props.limits.maxMemoryAllocationCount > max_mems) {
1380         props.limits.maxMemoryAllocationCount = max_mems;
1381         fpvkSetPhysicalDeviceLimitsEXT(gpu(), &props.limits);
1382     }
1383     ASSERT_NO_FATAL_FAILURE(InitState());
1384     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1385                                          "Number of currently valid memory objects is not less than the maximum allowed");
1386 
1387     VkMemoryAllocateInfo mem_alloc = {};
1388     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1389     mem_alloc.pNext = NULL;
1390     mem_alloc.memoryTypeIndex = 0;
1391     mem_alloc.allocationSize = 4;
1392 
1393     int i;
1394     for (i = 0; i <= max_mems; i++) {
1395         err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mems[i]);
1396         if (err != VK_SUCCESS) {
1397             break;
1398         }
1399     }
1400     m_errorMonitor->VerifyFound();
1401 
1402     for (int j = 0; j < i; j++) {
1403         vkFreeMemory(m_device->device(), mems[j], NULL);
1404     }
1405 }
1406 
TEST_F(VkLayerTest,ImageSampleCounts)1407 TEST_F(VkLayerTest, ImageSampleCounts) {
1408     TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
1409     ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1410 
1411     VkMemoryPropertyFlags reqs = 0;
1412     VkImageCreateInfo image_create_info = {};
1413     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1414     image_create_info.pNext = NULL;
1415     image_create_info.imageType = VK_IMAGE_TYPE_2D;
1416     image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
1417     image_create_info.extent.width = 256;
1418     image_create_info.extent.height = 256;
1419     image_create_info.extent.depth = 1;
1420     image_create_info.mipLevels = 1;
1421     image_create_info.arrayLayers = 1;
1422     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1423     image_create_info.flags = 0;
1424 
1425     VkImageBlit blit_region = {};
1426     blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1427     blit_region.srcSubresource.baseArrayLayer = 0;
1428     blit_region.srcSubresource.layerCount = 1;
1429     blit_region.srcSubresource.mipLevel = 0;
1430     blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1431     blit_region.dstSubresource.baseArrayLayer = 0;
1432     blit_region.dstSubresource.layerCount = 1;
1433     blit_region.dstSubresource.mipLevel = 0;
1434     blit_region.srcOffsets[0] = {0, 0, 0};
1435     blit_region.srcOffsets[1] = {256, 256, 1};
1436     blit_region.dstOffsets[0] = {0, 0, 0};
1437     blit_region.dstOffsets[1] = {128, 128, 1};
1438 
1439     // Create two images, the source with sampleCount = 4, and attempt to blit
1440     // between them
1441     {
1442         image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1443         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1444         VkImageObj src_image(m_device);
1445         src_image.init(&image_create_info);
1446         src_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
1447         image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1448         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1449         VkImageObj dst_image(m_device);
1450         dst_image.init(&image_create_info);
1451         dst_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1452         m_commandBuffer->begin();
1453         // TODO: These 2 VUs are redundant - expect one of them to go away
1454         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00233");
1455         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00228");
1456         vkCmdBlitImage(m_commandBuffer->handle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst_image.handle(),
1457                        VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
1458         m_errorMonitor->VerifyFound();
1459         m_commandBuffer->end();
1460     }
1461 
1462     // Create two images, the dest with sampleCount = 4, and attempt to blit
1463     // between them
1464     {
1465         image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1466         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1467         VkImageObj src_image(m_device);
1468         src_image.init(&image_create_info);
1469         src_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
1470         image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1471         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1472         VkImageObj dst_image(m_device);
1473         dst_image.init(&image_create_info);
1474         dst_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1475         m_commandBuffer->begin();
1476         // TODO: These 2 VUs are redundant - expect one of them to go away
1477         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-00234");
1478         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00228");
1479         vkCmdBlitImage(m_commandBuffer->handle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst_image.handle(),
1480                        VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
1481         m_errorMonitor->VerifyFound();
1482         m_commandBuffer->end();
1483     }
1484 
1485     VkBufferImageCopy copy_region = {};
1486     copy_region.bufferRowLength = 128;
1487     copy_region.bufferImageHeight = 128;
1488     copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1489     copy_region.imageSubresource.layerCount = 1;
1490     copy_region.imageExtent.height = 64;
1491     copy_region.imageExtent.width = 64;
1492     copy_region.imageExtent.depth = 1;
1493 
1494     // Create src buffer and dst image with sampleCount = 4 and attempt to copy
1495     // buffer to image
1496     {
1497         VkBufferObj src_buffer;
1498         src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
1499         image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1500         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1501         VkImageObj dst_image(m_device);
1502         dst_image.init(&image_create_info);
1503         dst_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1504         m_commandBuffer->begin();
1505         m_errorMonitor->SetDesiredFailureMsg(
1506             VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507             "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
1508         vkCmdCopyBufferToImage(m_commandBuffer->handle(), src_buffer.handle(), dst_image.handle(),
1509                                VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
1510         m_errorMonitor->VerifyFound();
1511         m_commandBuffer->end();
1512     }
1513 
1514     // Create dst buffer and src image with sampleCount = 4 and attempt to copy
1515     // image to buffer
1516     {
1517         VkBufferObj dst_buffer;
1518         dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
1519         image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1520         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1521         vk_testing::Image src_image;
1522         src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
1523         m_commandBuffer->begin();
1524         m_errorMonitor->SetDesiredFailureMsg(
1525             VK_DEBUG_REPORT_ERROR_BIT_EXT,
1526             "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
1527         vkCmdCopyImageToBuffer(m_commandBuffer->handle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1528                                dst_buffer.handle(), 1, &copy_region);
1529         m_errorMonitor->VerifyFound();
1530         m_commandBuffer->end();
1531     }
1532 }
1533 
TEST_F(VkLayerTest,BlitImageFormatTypes)1534 TEST_F(VkLayerTest, BlitImageFormatTypes) {
1535     ASSERT_NO_FATAL_FAILURE(Init());
1536 
1537     VkFormat f_unsigned = VK_FORMAT_R8G8B8A8_UINT;
1538     VkFormat f_signed = VK_FORMAT_R8G8B8A8_SINT;
1539     VkFormat f_float = VK_FORMAT_R32_SFLOAT;
1540     VkFormat f_depth = VK_FORMAT_D32_SFLOAT_S8_UINT;
1541     VkFormat f_depth2 = VK_FORMAT_D32_SFLOAT;
1542 
1543     if (!ImageFormatIsSupported(gpu(), f_unsigned, VK_IMAGE_TILING_OPTIMAL) ||
1544         !ImageFormatIsSupported(gpu(), f_signed, VK_IMAGE_TILING_OPTIMAL) ||
1545         !ImageFormatIsSupported(gpu(), f_float, VK_IMAGE_TILING_OPTIMAL) ||
1546         !ImageFormatIsSupported(gpu(), f_depth, VK_IMAGE_TILING_OPTIMAL) ||
1547         !ImageFormatIsSupported(gpu(), f_depth2, VK_IMAGE_TILING_OPTIMAL)) {
1548         printf("%s Requested formats not supported - BlitImageFormatTypes skipped.\n", kSkipPrefix);
1549         return;
1550     }
1551 
1552     // Note any missing feature bits
1553     bool usrc = !ImageFormatAndFeaturesSupported(gpu(), f_unsigned, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_SRC_BIT);
1554     bool udst = !ImageFormatAndFeaturesSupported(gpu(), f_unsigned, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_DST_BIT);
1555     bool ssrc = !ImageFormatAndFeaturesSupported(gpu(), f_signed, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_SRC_BIT);
1556     bool sdst = !ImageFormatAndFeaturesSupported(gpu(), f_signed, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_DST_BIT);
1557     bool fsrc = !ImageFormatAndFeaturesSupported(gpu(), f_float, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_SRC_BIT);
1558     bool fdst = !ImageFormatAndFeaturesSupported(gpu(), f_float, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_DST_BIT);
1559     bool d1dst = !ImageFormatAndFeaturesSupported(gpu(), f_depth, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_DST_BIT);
1560     bool d2src = !ImageFormatAndFeaturesSupported(gpu(), f_depth2, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_SRC_BIT);
1561 
1562     VkImageObj unsigned_image(m_device);
1563     unsigned_image.Init(64, 64, 1, f_unsigned, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1564                         VK_IMAGE_TILING_OPTIMAL, 0);
1565     ASSERT_TRUE(unsigned_image.initialized());
1566     unsigned_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL);
1567 
1568     VkImageObj signed_image(m_device);
1569     signed_image.Init(64, 64, 1, f_signed, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1570                       VK_IMAGE_TILING_OPTIMAL, 0);
1571     ASSERT_TRUE(signed_image.initialized());
1572     signed_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL);
1573 
1574     VkImageObj float_image(m_device);
1575     float_image.Init(64, 64, 1, f_float, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL,
1576                      0);
1577     ASSERT_TRUE(float_image.initialized());
1578     float_image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL);
1579 
1580     VkImageObj depth_image(m_device);
1581     depth_image.Init(64, 64, 1, f_depth, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL,
1582                      0);
1583     ASSERT_TRUE(depth_image.initialized());
1584     depth_image.SetLayout(VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_GENERAL);
1585 
1586     VkImageObj depth_image2(m_device);
1587     depth_image2.Init(64, 64, 1, f_depth2, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1588                       VK_IMAGE_TILING_OPTIMAL, 0);
1589     ASSERT_TRUE(depth_image2.initialized());
1590     depth_image2.SetLayout(VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_GENERAL);
1591 
1592     VkImageBlit blitRegion = {};
1593     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1594     blitRegion.srcSubresource.baseArrayLayer = 0;
1595     blitRegion.srcSubresource.layerCount = 1;
1596     blitRegion.srcSubresource.mipLevel = 0;
1597     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1598     blitRegion.dstSubresource.baseArrayLayer = 0;
1599     blitRegion.dstSubresource.layerCount = 1;
1600     blitRegion.dstSubresource.mipLevel = 0;
1601     blitRegion.srcOffsets[0] = {0, 0, 0};
1602     blitRegion.srcOffsets[1] = {64, 64, 1};
1603     blitRegion.dstOffsets[0] = {0, 0, 0};
1604     blitRegion.dstOffsets[1] = {32, 32, 1};
1605 
1606     m_commandBuffer->begin();
1607 
1608     // Unsigned int vs not an int
1609     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00230");
1610     if (usrc) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1611     if (fdst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1612     vkCmdBlitImage(m_commandBuffer->handle(), unsigned_image.image(), unsigned_image.Layout(), float_image.image(),
1613                    float_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1614     m_errorMonitor->VerifyFound();
1615     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00230");
1616     if (fsrc) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1617     if (udst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1618     vkCmdBlitImage(m_commandBuffer->handle(), float_image.image(), float_image.Layout(), unsigned_image.image(),
1619                    unsigned_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1620     m_errorMonitor->VerifyFound();
1621 
1622     // Signed int vs not an int,
1623     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00229");
1624     if (ssrc) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1625     if (fdst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1626     vkCmdBlitImage(m_commandBuffer->handle(), signed_image.image(), signed_image.Layout(), float_image.image(),
1627                    float_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1628     m_errorMonitor->VerifyFound();
1629     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00229");
1630     if (fsrc) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1631     if (sdst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1632     vkCmdBlitImage(m_commandBuffer->handle(), float_image.image(), float_image.Layout(), signed_image.image(),
1633                    signed_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1634     m_errorMonitor->VerifyFound();
1635 
1636     // Signed vs Unsigned int - generates both VUs
1637     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00229");
1638     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00230");
1639     if (ssrc) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1640     if (udst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1641     vkCmdBlitImage(m_commandBuffer->handle(), signed_image.image(), signed_image.Layout(), unsigned_image.image(),
1642                    unsigned_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1643     m_errorMonitor->VerifyFound();
1644     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00229");
1645     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00230");
1646     if (usrc) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1647     if (sdst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1648     vkCmdBlitImage(m_commandBuffer->handle(), unsigned_image.image(), unsigned_image.Layout(), signed_image.image(),
1649                    signed_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1650     m_errorMonitor->VerifyFound();
1651 
1652     // Depth vs any non-identical depth format
1653     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00231");
1654     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1655     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1656     if (d2src) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-01999");
1657     if (d1dst) m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
1658     vkCmdBlitImage(m_commandBuffer->handle(), depth_image2.image(), depth_image2.Layout(), depth_image.image(),
1659                    depth_image.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
1660     m_errorMonitor->VerifyFound();
1661 
1662     m_commandBuffer->end();
1663 }
1664 
TEST_F(VkLayerTest,BlitImageFilters)1665 TEST_F(VkLayerTest, BlitImageFilters) {
1666     bool cubic_support = false;
1667     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
1668     if (DeviceExtensionSupported(gpu(), nullptr, "VK_IMG_filter_cubic")) {
1669         m_device_extension_names.push_back("VK_IMG_filter_cubic");
1670         cubic_support = true;
1671     }
1672     ASSERT_NO_FATAL_FAILURE(InitState());
1673 
1674     VkFormat fmt = VK_FORMAT_R8_UINT;
1675     if (!ImageFormatIsSupported(gpu(), fmt, VK_IMAGE_TILING_OPTIMAL)) {
1676         printf("%s No R8_UINT format support - BlitImageFilters skipped.\n", kSkipPrefix);
1677         return;
1678     }
1679 
1680     // Create 2D images
1681     VkImageObj src2D(m_device);
1682     VkImageObj dst2D(m_device);
1683     src2D.Init(64, 64, 1, fmt, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
1684     dst2D.Init(64, 64, 1, fmt, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
1685     ASSERT_TRUE(src2D.initialized());
1686     ASSERT_TRUE(dst2D.initialized());
1687     src2D.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL);
1688     dst2D.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL);
1689 
1690     // Create 3D image
1691     VkImageCreateInfo ci;
1692     ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1693     ci.pNext = NULL;
1694     ci.flags = 0;
1695     ci.imageType = VK_IMAGE_TYPE_3D;
1696     ci.format = fmt;
1697     ci.extent = {64, 64, 4};
1698     ci.mipLevels = 1;
1699     ci.arrayLayers = 1;
1700     ci.samples = VK_SAMPLE_COUNT_1_BIT;
1701     ci.tiling = VK_IMAGE_TILING_OPTIMAL;
1702     ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1703     ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1704     ci.queueFamilyIndexCount = 0;
1705     ci.pQueueFamilyIndices = NULL;
1706     ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1707 
1708     VkImageObj src3D(m_device);
1709     src3D.init(&ci);
1710     ASSERT_TRUE(src3D.initialized());
1711 
1712     VkImageBlit blitRegion = {};
1713     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1714     blitRegion.srcSubresource.baseArrayLayer = 0;
1715     blitRegion.srcSubresource.layerCount = 1;
1716     blitRegion.srcSubresource.mipLevel = 0;
1717     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1718     blitRegion.dstSubresource.baseArrayLayer = 0;
1719     blitRegion.dstSubresource.layerCount = 1;
1720     blitRegion.dstSubresource.mipLevel = 0;
1721     blitRegion.srcOffsets[0] = {0, 0, 0};
1722     blitRegion.srcOffsets[1] = {48, 48, 1};
1723     blitRegion.dstOffsets[0] = {0, 0, 0};
1724     blitRegion.dstOffsets[1] = {64, 64, 1};
1725 
1726     m_commandBuffer->begin();
1727 
1728     // UINT format should not support linear filtering, but check to be sure
1729     if (!ImageFormatAndFeaturesSupported(gpu(), fmt, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) {
1730         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-filter-02001");
1731         vkCmdBlitImage(m_commandBuffer->handle(), src2D.image(), src2D.Layout(), dst2D.image(), dst2D.Layout(), 1, &blitRegion,
1732                        VK_FILTER_LINEAR);
1733         m_errorMonitor->VerifyFound();
1734     }
1735 
1736     if (cubic_support && !ImageFormatAndFeaturesSupported(gpu(), fmt, VK_IMAGE_TILING_OPTIMAL,
1737                                                           VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG)) {
1738         // Invalid filter CUBIC_IMG
1739         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-filter-02002");
1740         vkCmdBlitImage(m_commandBuffer->handle(), src3D.image(), src3D.Layout(), dst2D.image(), dst2D.Layout(), 1, &blitRegion,
1741                        VK_FILTER_CUBIC_IMG);
1742         m_errorMonitor->VerifyFound();
1743 
1744         // Invalid filter CUBIC_IMG + invalid 2D source image
1745         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-filter-02002");
1746         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-filter-00237");
1747         vkCmdBlitImage(m_commandBuffer->handle(), src2D.image(), src2D.Layout(), dst2D.image(), dst2D.Layout(), 1, &blitRegion,
1748                        VK_FILTER_CUBIC_IMG);
1749         m_errorMonitor->VerifyFound();
1750     }
1751 
1752     m_commandBuffer->end();
1753 }
1754 
TEST_F(VkLayerTest,BlitImageLayout)1755 TEST_F(VkLayerTest, BlitImageLayout) {
1756     TEST_DESCRIPTION("Incorrect vkCmdBlitImage layouts");
1757 
1758     ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1759 
1760     VkResult err;
1761     VkFormat fmt = VK_FORMAT_R8G8B8A8_UNORM;
1762 
1763     VkSubmitInfo submit_info = {};
1764     submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1765     submit_info.commandBufferCount = 1;
1766     submit_info.pCommandBuffers = &m_commandBuffer->handle();
1767 
1768     // Create images
1769     VkImageObj img_src_transfer(m_device);
1770     VkImageObj img_dst_transfer(m_device);
1771     VkImageObj img_general(m_device);
1772     VkImageObj img_color(m_device);
1773 
1774     img_src_transfer.InitNoLayout(64, 64, 1, fmt, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1775                                   VK_IMAGE_TILING_OPTIMAL, 0);
1776     img_dst_transfer.InitNoLayout(64, 64, 1, fmt, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1777                                   VK_IMAGE_TILING_OPTIMAL, 0);
1778     img_general.InitNoLayout(64, 64, 1, fmt, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1779                              VK_IMAGE_TILING_OPTIMAL, 0);
1780     img_color.InitNoLayout(64, 64, 1, fmt,
1781                            VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
1782                            VK_IMAGE_TILING_OPTIMAL, 0);
1783 
1784     ASSERT_TRUE(img_src_transfer.initialized());
1785     ASSERT_TRUE(img_dst_transfer.initialized());
1786     ASSERT_TRUE(img_general.initialized());
1787     ASSERT_TRUE(img_color.initialized());
1788 
1789     img_src_transfer.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
1790     img_dst_transfer.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1791     img_general.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL);
1792     img_color.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
1793 
1794     VkImageBlit blit_region = {};
1795     blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1796     blit_region.srcSubresource.baseArrayLayer = 0;
1797     blit_region.srcSubresource.layerCount = 1;
1798     blit_region.srcSubresource.mipLevel = 0;
1799     blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1800     blit_region.dstSubresource.baseArrayLayer = 0;
1801     blit_region.dstSubresource.layerCount = 1;
1802     blit_region.dstSubresource.mipLevel = 0;
1803     blit_region.srcOffsets[0] = {0, 0, 0};
1804     blit_region.srcOffsets[1] = {48, 48, 1};
1805     blit_region.dstOffsets[0] = {0, 0, 0};
1806     blit_region.dstOffsets[1] = {64, 64, 1};
1807 
1808     m_commandBuffer->begin();
1809 
1810     // Illegal srcImageLayout
1811     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImageLayout-00222");
1812     vkCmdBlitImage(m_commandBuffer->handle(), img_src_transfer.image(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1813                    img_dst_transfer.image(), img_dst_transfer.Layout(), 1, &blit_region, VK_FILTER_LINEAR);
1814     m_errorMonitor->VerifyFound();
1815 
1816     // Illegal destImageLayout
1817     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImageLayout-00227");
1818     vkCmdBlitImage(m_commandBuffer->handle(), img_src_transfer.image(), img_src_transfer.Layout(), img_dst_transfer.image(),
1819                    VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_LINEAR);
1820 
1821     m_commandBuffer->end();
1822     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1823     m_errorMonitor->VerifyFound();
1824 
1825     err = vkQueueWaitIdle(m_device->m_queue);
1826     ASSERT_VK_SUCCESS(err);
1827 
1828     m_commandBuffer->reset(0);
1829     m_commandBuffer->begin();
1830 
1831     // Source image in invalid layout at start of the CB
1832     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout");
1833     vkCmdBlitImage(m_commandBuffer->handle(), img_src_transfer.image(), img_src_transfer.Layout(), img_color.image(),
1834                    VK_IMAGE_LAYOUT_GENERAL, 1, &blit_region, VK_FILTER_LINEAR);
1835 
1836     m_commandBuffer->end();
1837     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1838     m_errorMonitor->VerifyFound();
1839     err = vkQueueWaitIdle(m_device->m_queue);
1840     ASSERT_VK_SUCCESS(err);
1841 
1842     m_commandBuffer->reset(0);
1843     m_commandBuffer->begin();
1844 
1845     // Destination image in invalid layout at start of the CB
1846     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout");
1847     vkCmdBlitImage(m_commandBuffer->handle(), img_color.image(), VK_IMAGE_LAYOUT_GENERAL, img_dst_transfer.image(),
1848                    img_dst_transfer.Layout(), 1, &blit_region, VK_FILTER_LINEAR);
1849 
1850     m_commandBuffer->end();
1851     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1852     m_errorMonitor->VerifyFound();
1853     err = vkQueueWaitIdle(m_device->m_queue);
1854     ASSERT_VK_SUCCESS(err);
1855 
1856     // Source image in invalid layout in the middle of CB
1857     m_commandBuffer->reset(0);
1858     m_commandBuffer->begin();
1859 
1860     VkImageMemoryBarrier img_barrier = {};
1861     img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
1862     img_barrier.pNext = nullptr;
1863     img_barrier.srcAccessMask = 0;
1864     img_barrier.dstAccessMask = 0;
1865     img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
1866     img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
1867     img_barrier.image = img_general.handle();
1868     img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1869     img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1870     img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1871     img_barrier.subresourceRange.baseArrayLayer = 0;
1872     img_barrier.subresourceRange.baseMipLevel = 0;
1873     img_barrier.subresourceRange.layerCount = 1;
1874     img_barrier.subresourceRange.levelCount = 1;
1875 
1876     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0,
1877                          nullptr, 0, nullptr, 1, &img_barrier);
1878 
1879     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImageLayout-00221");
1880     vkCmdBlitImage(m_commandBuffer->handle(), img_general.image(), VK_IMAGE_LAYOUT_GENERAL, img_dst_transfer.image(),
1881                    img_dst_transfer.Layout(), 1, &blit_region, VK_FILTER_LINEAR);
1882 
1883     m_commandBuffer->end();
1884     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1885     m_errorMonitor->VerifyFound();
1886     err = vkQueueWaitIdle(m_device->m_queue);
1887     ASSERT_VK_SUCCESS(err);
1888 
1889     // Destination image in invalid layout in the middle of CB
1890     m_commandBuffer->reset(0);
1891     m_commandBuffer->begin();
1892 
1893     img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
1894     img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1895     img_barrier.image = img_dst_transfer.handle();
1896 
1897     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0,
1898                          nullptr, 0, nullptr, 1, &img_barrier);
1899 
1900     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImageLayout-00226");
1901     vkCmdBlitImage(m_commandBuffer->handle(), img_src_transfer.image(), img_src_transfer.Layout(), img_dst_transfer.image(),
1902                    VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit_region, VK_FILTER_LINEAR);
1903 
1904     m_commandBuffer->end();
1905     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1906     m_errorMonitor->VerifyFound();
1907     err = vkQueueWaitIdle(m_device->m_queue);
1908     ASSERT_VK_SUCCESS(err);
1909 }
1910 
TEST_F(VkLayerTest,BlitImageOffsets)1911 TEST_F(VkLayerTest, BlitImageOffsets) {
1912     ASSERT_NO_FATAL_FAILURE(Init());
1913 
1914     VkFormat fmt = VK_FORMAT_R8G8B8A8_UNORM;
1915     if (!ImageFormatAndFeaturesSupported(gpu(), fmt, VK_IMAGE_TILING_OPTIMAL,
1916                                          VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT)) {
1917         printf("%s No blit feature bits - BlitImageOffsets skipped.\n", kSkipPrefix);
1918         return;
1919     }
1920 
1921     VkImageCreateInfo ci;
1922     ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1923     ci.pNext = NULL;
1924     ci.flags = 0;
1925     ci.imageType = VK_IMAGE_TYPE_1D;
1926     ci.format = fmt;
1927     ci.extent = {64, 1, 1};
1928     ci.mipLevels = 1;
1929     ci.arrayLayers = 1;
1930     ci.samples = VK_SAMPLE_COUNT_1_BIT;
1931     ci.tiling = VK_IMAGE_TILING_OPTIMAL;
1932     ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1933     ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1934     ci.queueFamilyIndexCount = 0;
1935     ci.pQueueFamilyIndices = NULL;
1936     ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1937 
1938     VkImageObj image_1D(m_device);
1939     image_1D.init(&ci);
1940     ASSERT_TRUE(image_1D.initialized());
1941 
1942     ci.imageType = VK_IMAGE_TYPE_2D;
1943     ci.extent = {64, 64, 1};
1944     VkImageObj image_2D(m_device);
1945     image_2D.init(&ci);
1946     ASSERT_TRUE(image_2D.initialized());
1947 
1948     ci.imageType = VK_IMAGE_TYPE_3D;
1949     ci.extent = {64, 64, 64};
1950     VkImageObj image_3D(m_device);
1951     image_3D.init(&ci);
1952     ASSERT_TRUE(image_3D.initialized());
1953 
1954     VkImageBlit blit_region = {};
1955     blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1956     blit_region.srcSubresource.baseArrayLayer = 0;
1957     blit_region.srcSubresource.layerCount = 1;
1958     blit_region.srcSubresource.mipLevel = 0;
1959     blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1960     blit_region.dstSubresource.baseArrayLayer = 0;
1961     blit_region.dstSubresource.layerCount = 1;
1962     blit_region.dstSubresource.mipLevel = 0;
1963 
1964     m_commandBuffer->begin();
1965 
1966     // 1D, with src/dest y offsets other than (0,1)
1967     blit_region.srcOffsets[0] = {0, 1, 0};
1968     blit_region.srcOffsets[1] = {30, 1, 1};
1969     blit_region.dstOffsets[0] = {32, 0, 0};
1970     blit_region.dstOffsets[1] = {64, 1, 1};
1971     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcImage-00245");
1972     vkCmdBlitImage(m_commandBuffer->handle(), image_1D.image(), image_1D.Layout(), image_1D.image(), image_1D.Layout(), 1,
1973                    &blit_region, VK_FILTER_NEAREST);
1974     m_errorMonitor->VerifyFound();
1975 
1976     blit_region.srcOffsets[0] = {0, 0, 0};
1977     blit_region.dstOffsets[0] = {32, 1, 0};
1978     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-dstImage-00250");
1979     vkCmdBlitImage(m_commandBuffer->handle(), image_1D.image(), image_1D.Layout(), image_1D.image(), image_1D.Layout(), 1,
1980                    &blit_region, VK_FILTER_NEAREST);
1981     m_errorMonitor->VerifyFound();
1982 
1983     // 2D, with src/dest z offsets other than (0,1)
1984     blit_region.srcOffsets[0] = {0, 0, 1};
1985     blit_region.srcOffsets[1] = {24, 31, 1};
1986     blit_region.dstOffsets[0] = {32, 32, 0};
1987     blit_region.dstOffsets[1] = {64, 64, 1};
1988     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcImage-00247");
1989     vkCmdBlitImage(m_commandBuffer->handle(), image_2D.image(), image_2D.Layout(), image_2D.image(), image_2D.Layout(), 1,
1990                    &blit_region, VK_FILTER_NEAREST);
1991     m_errorMonitor->VerifyFound();
1992 
1993     blit_region.srcOffsets[0] = {0, 0, 0};
1994     blit_region.dstOffsets[0] = {32, 32, 1};
1995     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-dstImage-00252");
1996     vkCmdBlitImage(m_commandBuffer->handle(), image_2D.image(), image_2D.Layout(), image_2D.image(), image_2D.Layout(), 1,
1997                    &blit_region, VK_FILTER_NEAREST);
1998     m_errorMonitor->VerifyFound();
1999 
2000     // Source offsets exceeding source image dimensions
2001     blit_region.srcOffsets[0] = {0, 0, 0};
2002     blit_region.srcOffsets[1] = {65, 64, 1};  // src x
2003     blit_region.dstOffsets[0] = {0, 0, 0};
2004     blit_region.dstOffsets[1] = {64, 64, 1};
2005     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcOffset-00243");    // x
2006     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-pRegions-00215");  // src region
2007     vkCmdBlitImage(m_commandBuffer->handle(), image_3D.image(), image_3D.Layout(), image_2D.image(), image_2D.Layout(), 1,
2008                    &blit_region, VK_FILTER_NEAREST);
2009     m_errorMonitor->VerifyFound();
2010 
2011     blit_region.srcOffsets[1] = {64, 65, 1};                                                                    // src y
2012     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcOffset-00244");    // y
2013     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-pRegions-00215");  // src region
2014     vkCmdBlitImage(m_commandBuffer->handle(), image_3D.image(), image_3D.Layout(), image_2D.image(), image_2D.Layout(), 1,
2015                    &blit_region, VK_FILTER_NEAREST);
2016     m_errorMonitor->VerifyFound();
2017 
2018     blit_region.srcOffsets[0] = {0, 0, 65};  // src z
2019     blit_region.srcOffsets[1] = {64, 64, 64};
2020     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcOffset-00246");    // z
2021     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-pRegions-00215");  // src region
2022     vkCmdBlitImage(m_commandBuffer->handle(), image_3D.image(), image_3D.Layout(), image_2D.image(), image_2D.Layout(), 1,
2023                    &blit_region, VK_FILTER_NEAREST);
2024     m_errorMonitor->VerifyFound();
2025 
2026     // Dest offsets exceeding source image dimensions
2027     blit_region.srcOffsets[0] = {0, 0, 0};
2028     blit_region.srcOffsets[1] = {64, 64, 1};
2029     blit_region.dstOffsets[0] = {96, 64, 32};  // dst x
2030     blit_region.dstOffsets[1] = {64, 0, 33};
2031     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-dstOffset-00248");    // x
2032     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-pRegions-00216");  // dst region
2033     vkCmdBlitImage(m_commandBuffer->handle(), image_2D.image(), image_2D.Layout(), image_3D.image(), image_3D.Layout(), 1,
2034                    &blit_region, VK_FILTER_NEAREST);
2035     m_errorMonitor->VerifyFound();
2036 
2037     blit_region.dstOffsets[0] = {0, 65, 32};                                                                    // dst y
2038     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-dstOffset-00249");    // y
2039     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-pRegions-00216");  // dst region
2040     vkCmdBlitImage(m_commandBuffer->handle(), image_2D.image(), image_2D.Layout(), image_3D.image(), image_3D.Layout(), 1,
2041                    &blit_region, VK_FILTER_NEAREST);
2042     m_errorMonitor->VerifyFound();
2043 
2044     blit_region.dstOffsets[0] = {0, 64, 65};  // dst z
2045     blit_region.dstOffsets[1] = {64, 0, 64};
2046     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-dstOffset-00251");    // z
2047     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-pRegions-00216");  // dst region
2048     vkCmdBlitImage(m_commandBuffer->handle(), image_2D.image(), image_2D.Layout(), image_3D.image(), image_3D.Layout(), 1,
2049                    &blit_region, VK_FILTER_NEAREST);
2050     m_errorMonitor->VerifyFound();
2051 
2052     m_commandBuffer->end();
2053 }
2054 
TEST_F(VkLayerTest,MiscBlitImageTests)2055 TEST_F(VkLayerTest, MiscBlitImageTests) {
2056     ASSERT_NO_FATAL_FAILURE(Init());
2057 
2058     VkFormat f_color = VK_FORMAT_R32_SFLOAT;  // Need features ..BLIT_SRC_BIT & ..BLIT_DST_BIT
2059 
2060     if (!ImageFormatAndFeaturesSupported(gpu(), f_color, VK_IMAGE_TILING_OPTIMAL,
2061                                          VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT)) {
2062         printf("%s Requested format features unavailable - MiscBlitImageTests skipped.\n", kSkipPrefix);
2063         return;
2064     }
2065 
2066     VkImageCreateInfo ci;
2067     ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2068     ci.pNext = NULL;
2069     ci.flags = 0;
2070     ci.imageType = VK_IMAGE_TYPE_2D;
2071     ci.format = f_color;
2072     ci.extent = {64, 64, 1};
2073     ci.mipLevels = 1;
2074     ci.arrayLayers = 1;
2075     ci.samples = VK_SAMPLE_COUNT_1_BIT;
2076     ci.tiling = VK_IMAGE_TILING_OPTIMAL;
2077     ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2078     ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
2079     ci.queueFamilyIndexCount = 0;
2080     ci.pQueueFamilyIndices = NULL;
2081     ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2082 
2083     // 2D color image
2084     VkImageObj color_img(m_device);
2085     color_img.init(&ci);
2086     ASSERT_TRUE(color_img.initialized());
2087 
2088     // 2D multi-sample image
2089     ci.samples = VK_SAMPLE_COUNT_4_BIT;
2090     VkImageObj ms_img(m_device);
2091     ms_img.init(&ci);
2092     ASSERT_TRUE(ms_img.initialized());
2093 
2094     // 3D color image
2095     ci.samples = VK_SAMPLE_COUNT_1_BIT;
2096     ci.imageType = VK_IMAGE_TYPE_3D;
2097     ci.extent = {64, 64, 8};
2098     VkImageObj color_3D_img(m_device);
2099     color_3D_img.init(&ci);
2100     ASSERT_TRUE(color_3D_img.initialized());
2101 
2102     VkImageBlit blitRegion = {};
2103     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2104     blitRegion.srcSubresource.baseArrayLayer = 0;
2105     blitRegion.srcSubresource.layerCount = 1;
2106     blitRegion.srcSubresource.mipLevel = 0;
2107     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2108     blitRegion.dstSubresource.baseArrayLayer = 0;
2109     blitRegion.dstSubresource.layerCount = 1;
2110     blitRegion.dstSubresource.mipLevel = 0;
2111     blitRegion.srcOffsets[0] = {0, 0, 0};
2112     blitRegion.srcOffsets[1] = {16, 16, 1};
2113     blitRegion.dstOffsets[0] = {32, 32, 0};
2114     blitRegion.dstOffsets[1] = {64, 64, 1};
2115 
2116     m_commandBuffer->begin();
2117 
2118     // Blit with aspectMask errors
2119     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
2120     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
2121     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-aspectMask-00241");
2122     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-aspectMask-00242");
2123     vkCmdBlitImage(m_commandBuffer->handle(), color_img.image(), color_img.Layout(), color_img.image(), color_img.Layout(), 1,
2124                    &blitRegion, VK_FILTER_NEAREST);
2125     m_errorMonitor->VerifyFound();
2126 
2127     // Blit with invalid src mip level
2128     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2129     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2130     blitRegion.srcSubresource.mipLevel = ci.mipLevels;
2131     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2132                                          "VUID-vkCmdBlitImage-srcSubresource-01705");  // invalid srcSubresource.mipLevel
2133     // Redundant unavoidable errors
2134     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2135                                          "VUID-VkImageBlit-srcOffset-00243");  // out-of-bounds srcOffset.x
2136     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2137                                          "VUID-VkImageBlit-srcOffset-00244");  // out-of-bounds srcOffset.y
2138     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2139                                          "VUID-VkImageBlit-srcOffset-00246");  // out-of-bounds srcOffset.z
2140     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2141                                          "VUID-vkCmdBlitImage-pRegions-00215");  // region not contained within src image
2142     vkCmdBlitImage(m_commandBuffer->handle(), color_img.image(), color_img.Layout(), color_img.image(), color_img.Layout(), 1,
2143                    &blitRegion, VK_FILTER_NEAREST);
2144     m_errorMonitor->VerifyFound();
2145 
2146     // Blit with invalid dst mip level
2147     blitRegion.srcSubresource.mipLevel = 0;
2148     blitRegion.dstSubresource.mipLevel = ci.mipLevels;
2149     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2150                                          "VUID-vkCmdBlitImage-dstSubresource-01706");  // invalid dstSubresource.mipLevel
2151     // Redundant unavoidable errors
2152     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2153                                          "VUID-VkImageBlit-dstOffset-00248");  // out-of-bounds dstOffset.x
2154     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2155                                          "VUID-VkImageBlit-dstOffset-00249");  // out-of-bounds dstOffset.y
2156     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2157                                          "VUID-VkImageBlit-dstOffset-00251");  // out-of-bounds dstOffset.z
2158     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2159                                          "VUID-vkCmdBlitImage-pRegions-00216");  // region not contained within dst image
2160     vkCmdBlitImage(m_commandBuffer->handle(), color_img.image(), color_img.Layout(), color_img.image(), color_img.Layout(), 1,
2161                    &blitRegion, VK_FILTER_NEAREST);
2162     m_errorMonitor->VerifyFound();
2163 
2164     // Blit with invalid src array layer
2165     blitRegion.dstSubresource.mipLevel = 0;
2166     blitRegion.srcSubresource.baseArrayLayer = ci.arrayLayers;
2167     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2168                                          "VUID-vkCmdBlitImage-srcSubresource-01707");  // invalid srcSubresource layer range
2169     vkCmdBlitImage(m_commandBuffer->handle(), color_img.image(), color_img.Layout(), color_img.image(), color_img.Layout(), 1,
2170                    &blitRegion, VK_FILTER_NEAREST);
2171     m_errorMonitor->VerifyFound();
2172 
2173     // Blit with invalid dst array layer
2174     blitRegion.srcSubresource.baseArrayLayer = 0;
2175     blitRegion.dstSubresource.baseArrayLayer = ci.arrayLayers;
2176     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2177                                          "VUID-vkCmdBlitImage-dstSubresource-01708");  // invalid dstSubresource layer range
2178                                                                                        // Redundant unavoidable errors
2179     vkCmdBlitImage(m_commandBuffer->handle(), color_img.image(), color_img.Layout(), color_img.image(), color_img.Layout(), 1,
2180                    &blitRegion, VK_FILTER_NEAREST);
2181     m_errorMonitor->VerifyFound();
2182 
2183     blitRegion.dstSubresource.baseArrayLayer = 0;
2184 
2185     // Blit multi-sample image
2186     // TODO: redundant VUs, one (1c8) or two (1d2 & 1d4) should be eliminated.
2187     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00228");
2188     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-srcImage-00233");
2189     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-00234");
2190     vkCmdBlitImage(m_commandBuffer->handle(), ms_img.image(), ms_img.Layout(), ms_img.image(), ms_img.Layout(), 1, &blitRegion,
2191                    VK_FILTER_NEAREST);
2192     m_errorMonitor->VerifyFound();
2193 
2194     // Blit 3D with baseArrayLayer != 0 or layerCount != 1
2195     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2196     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2197     blitRegion.srcSubresource.baseArrayLayer = 1;
2198     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcImage-00240");
2199     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2200                                          "VUID-vkCmdBlitImage-srcSubresource-01707");  // base+count > total layer count
2201     vkCmdBlitImage(m_commandBuffer->handle(), color_3D_img.image(), color_3D_img.Layout(), color_3D_img.image(),
2202                    color_3D_img.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2203     m_errorMonitor->VerifyFound();
2204     blitRegion.srcSubresource.baseArrayLayer = 0;
2205     blitRegion.srcSubresource.layerCount = 0;
2206     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageBlit-srcImage-00240");
2207     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2208                                          "VUID-VkImageSubresourceLayers-layerCount-01700");  // layer count == 0 (src)
2209     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2210                                          "VUID-VkImageBlit-layerCount-00239");  // src/dst layer count mismatch
2211     vkCmdBlitImage(m_commandBuffer->handle(), color_3D_img.image(), color_3D_img.Layout(), color_3D_img.image(),
2212                    color_3D_img.Layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2213     m_errorMonitor->VerifyFound();
2214 
2215     m_commandBuffer->end();
2216 }
2217 
TEST_F(VkLayerTest,BlitToDepthImageTests)2218 TEST_F(VkLayerTest, BlitToDepthImageTests) {
2219     ASSERT_NO_FATAL_FAILURE(Init());
2220 
2221     // Need feature ..BLIT_SRC_BIT but not ..BLIT_DST_BIT
2222     // TODO: provide more choices here; supporting D32_SFLOAT as BLIT_DST isn't unheard of.
2223     VkFormat f_depth = VK_FORMAT_D32_SFLOAT;
2224 
2225     if (!ImageFormatAndFeaturesSupported(gpu(), f_depth, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_SRC_BIT) ||
2226         ImageFormatAndFeaturesSupported(gpu(), f_depth, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_BLIT_DST_BIT)) {
2227         printf("%s Requested format features unavailable - BlitToDepthImageTests skipped.\n", kSkipPrefix);
2228         return;
2229     }
2230 
2231     VkImageCreateInfo ci;
2232     ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2233     ci.pNext = NULL;
2234     ci.flags = 0;
2235     ci.imageType = VK_IMAGE_TYPE_2D;
2236     ci.format = f_depth;
2237     ci.extent = {64, 64, 1};
2238     ci.mipLevels = 1;
2239     ci.arrayLayers = 1;
2240     ci.samples = VK_SAMPLE_COUNT_1_BIT;
2241     ci.tiling = VK_IMAGE_TILING_OPTIMAL;
2242     ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2243     ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
2244     ci.queueFamilyIndexCount = 0;
2245     ci.pQueueFamilyIndices = NULL;
2246     ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2247 
2248     // 2D depth image
2249     VkImageObj depth_img(m_device);
2250     depth_img.init(&ci);
2251     ASSERT_TRUE(depth_img.initialized());
2252 
2253     VkImageBlit blitRegion = {};
2254     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2255     blitRegion.srcSubresource.baseArrayLayer = 0;
2256     blitRegion.srcSubresource.layerCount = 1;
2257     blitRegion.srcSubresource.mipLevel = 0;
2258     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2259     blitRegion.dstSubresource.baseArrayLayer = 0;
2260     blitRegion.dstSubresource.layerCount = 1;
2261     blitRegion.dstSubresource.mipLevel = 0;
2262     blitRegion.srcOffsets[0] = {0, 0, 0};
2263     blitRegion.srcOffsets[1] = {16, 16, 1};
2264     blitRegion.dstOffsets[0] = {32, 32, 0};
2265     blitRegion.dstOffsets[1] = {64, 64, 1};
2266 
2267     m_commandBuffer->begin();
2268 
2269     // Blit depth image - has SRC_BIT but not DST_BIT
2270     blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
2271     blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
2272     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBlitImage-dstImage-02000");
2273     vkCmdBlitImage(m_commandBuffer->handle(), depth_img.image(), depth_img.Layout(), depth_img.image(), depth_img.Layout(), 1,
2274                    &blitRegion, VK_FILTER_NEAREST);
2275     m_errorMonitor->VerifyFound();
2276 
2277     m_commandBuffer->end();
2278 }
2279 
TEST_F(VkLayerTest,MinImageTransferGranularity)2280 TEST_F(VkLayerTest, MinImageTransferGranularity) {
2281     TEST_DESCRIPTION("Tests for validation of Queue Family property minImageTransferGranularity.");
2282     ASSERT_NO_FATAL_FAILURE(Init());
2283 
2284     auto queue_family_properties = m_device->phy().queue_properties();
2285     auto large_granularity_family =
2286         std::find_if(queue_family_properties.begin(), queue_family_properties.end(), [](VkQueueFamilyProperties family_properties) {
2287             VkExtent3D family_granularity = family_properties.minImageTransferGranularity;
2288             // We need a queue family that supports copy operations and has a large enough minImageTransferGranularity for the tests
2289             // below to make sense.
2290             return (family_properties.queueFlags & VK_QUEUE_TRANSFER_BIT || family_properties.queueFlags & VK_QUEUE_GRAPHICS_BIT ||
2291                     family_properties.queueFlags & VK_QUEUE_COMPUTE_BIT) &&
2292                    family_granularity.depth >= 4 && family_granularity.width >= 4 && family_granularity.height >= 4;
2293         });
2294 
2295     if (large_granularity_family == queue_family_properties.end()) {
2296         printf("%s No queue family has a large enough granularity for this test to be meaningful, skipping test\n", kSkipPrefix);
2297         return;
2298     }
2299     const size_t queue_family_index = std::distance(queue_family_properties.begin(), large_granularity_family);
2300     VkExtent3D granularity = queue_family_properties[queue_family_index].minImageTransferGranularity;
2301     VkCommandPoolObj command_pool(m_device, queue_family_index, 0);
2302 
2303     // Create two images of different types and try to copy between them
2304     VkImage srcImage;
2305     VkImage dstImage;
2306 
2307     VkImageCreateInfo image_create_info = {};
2308     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2309     image_create_info.pNext = NULL;
2310     image_create_info.imageType = VK_IMAGE_TYPE_3D;
2311     image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2312     image_create_info.extent.width = granularity.width * 2;
2313     image_create_info.extent.height = granularity.height * 2;
2314     image_create_info.extent.depth = granularity.depth * 2;
2315     image_create_info.mipLevels = 1;
2316     image_create_info.arrayLayers = 1;
2317     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2318     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2319     image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
2320     image_create_info.flags = 0;
2321 
2322     VkImageObj src_image_obj(m_device);
2323     src_image_obj.init(&image_create_info);
2324     ASSERT_TRUE(src_image_obj.initialized());
2325     srcImage = src_image_obj.handle();
2326 
2327     image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2328 
2329     VkImageObj dst_image_obj(m_device);
2330     dst_image_obj.init(&image_create_info);
2331     ASSERT_TRUE(dst_image_obj.initialized());
2332     dstImage = dst_image_obj.handle();
2333 
2334     VkCommandBufferObj command_buffer(m_device, &command_pool);
2335     ASSERT_TRUE(command_buffer.initialized());
2336     command_buffer.begin();
2337 
2338     VkImageCopy copyRegion;
2339     copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2340     copyRegion.srcSubresource.mipLevel = 0;
2341     copyRegion.srcSubresource.baseArrayLayer = 0;
2342     copyRegion.srcSubresource.layerCount = 1;
2343     copyRegion.srcOffset.x = 0;
2344     copyRegion.srcOffset.y = 0;
2345     copyRegion.srcOffset.z = 0;
2346     copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2347     copyRegion.dstSubresource.mipLevel = 0;
2348     copyRegion.dstSubresource.baseArrayLayer = 0;
2349     copyRegion.dstSubresource.layerCount = 1;
2350     copyRegion.dstOffset.x = 0;
2351     copyRegion.dstOffset.y = 0;
2352     copyRegion.dstOffset.z = 0;
2353     copyRegion.extent.width = granularity.width;
2354     copyRegion.extent.height = granularity.height;
2355     copyRegion.extent.depth = granularity.depth;
2356 
2357     // Introduce failure by setting srcOffset to a bad granularity value
2358     copyRegion.srcOffset.y = 3;
2359     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2360                                          "VUID-vkCmdCopyImage-srcOffset-01783");  // srcOffset image transfer granularity
2361     command_buffer.CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
2362     m_errorMonitor->VerifyFound();
2363 
2364     // Introduce failure by setting extent to a granularity value that is bad
2365     // for both the source and destination image.
2366     copyRegion.srcOffset.y = 0;
2367     copyRegion.extent.width = 3;
2368     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2369                                          "VUID-vkCmdCopyImage-srcOffset-01783");  // src extent image transfer granularity
2370     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2371                                          "VUID-vkCmdCopyImage-dstOffset-01784");  // dst extent image transfer granularity
2372     command_buffer.CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
2373     m_errorMonitor->VerifyFound();
2374 
2375     // Now do some buffer/image copies
2376     VkBufferObj buffer;
2377     VkMemoryPropertyFlags reqs = 0;
2378     buffer.init_as_src_and_dst(*m_device, 8 * granularity.height * granularity.width * granularity.depth, reqs);
2379     VkBufferImageCopy region = {};
2380     region.bufferOffset = 0;
2381     region.bufferRowLength = 0;
2382     region.bufferImageHeight = 0;
2383     region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2384     region.imageSubresource.layerCount = 1;
2385     region.imageExtent.height = granularity.height;
2386     region.imageExtent.width = granularity.width;
2387     region.imageExtent.depth = granularity.depth;
2388     region.imageOffset.x = 0;
2389     region.imageOffset.y = 0;
2390     region.imageOffset.z = 0;
2391 
2392     // Introduce failure by setting imageExtent to a bad granularity value
2393     region.imageExtent.width = 3;
2394     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2395                                          "VUID-vkCmdCopyImageToBuffer-imageOffset-01794");  // image transfer granularity
2396     vkCmdCopyImageToBuffer(command_buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer.handle(), 1, &region);
2397     m_errorMonitor->VerifyFound();
2398     region.imageExtent.width = granularity.width;
2399 
2400     // Introduce failure by setting imageOffset to a bad granularity value
2401     region.imageOffset.z = 3;
2402     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2403                                          "VUID-vkCmdCopyBufferToImage-imageOffset-01793");  // image transfer granularity
2404     vkCmdCopyBufferToImage(command_buffer.handle(), buffer.handle(), dstImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
2405     m_errorMonitor->VerifyFound();
2406 
2407     command_buffer.end();
2408 }
2409 
TEST_F(VkLayerTest,ImageBarrierSubpassConflicts)2410 TEST_F(VkLayerTest, ImageBarrierSubpassConflicts) {
2411     TEST_DESCRIPTION("Add a pipeline barrier within a subpass that has conflicting state");
2412     ASSERT_NO_FATAL_FAILURE(Init());
2413 
2414     // A renderpass with a single subpass that declared a self-dependency
2415     VkAttachmentDescription attach[] = {
2416         {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2417          VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
2418          VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
2419     };
2420     VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
2421     VkSubpassDescription subpasses[] = {
2422         {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
2423     };
2424     VkSubpassDependency dep = {0,
2425                                0,
2426                                VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2427                                VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2428                                VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2429                                VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2430                                VK_DEPENDENCY_BY_REGION_BIT};
2431     VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, subpasses, 1, &dep};
2432     VkRenderPass rp;
2433     VkRenderPass rp_noselfdep;
2434 
2435     VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2436     ASSERT_VK_SUCCESS(err);
2437     rpci.dependencyCount = 0;
2438     rpci.pDependencies = nullptr;
2439     err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp_noselfdep);
2440     ASSERT_VK_SUCCESS(err);
2441 
2442     VkImageObj image(m_device);
2443     image.InitNoLayout(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2444     VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2445 
2446     VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
2447     VkFramebuffer fb;
2448     err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2449     ASSERT_VK_SUCCESS(err);
2450 
2451     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2452     m_commandBuffer->begin();
2453     VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
2454                                   nullptr,
2455                                   rp_noselfdep,
2456                                   fb,
2457                                   {{
2458                                        0,
2459                                        0,
2460                                    },
2461                                    {32, 32}},
2462                                   0,
2463                                   nullptr};
2464 
2465     vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2466     VkMemoryBarrier mem_barrier = {};
2467     mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
2468     mem_barrier.pNext = NULL;
2469     mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
2470     mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
2471     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
2472                          &mem_barrier, 0, nullptr, 0, nullptr);
2473     m_errorMonitor->VerifyFound();
2474     vkCmdEndRenderPass(m_commandBuffer->handle());
2475 
2476     rpbi.renderPass = rp;
2477     vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2478     VkImageMemoryBarrier img_barrier = {};
2479     img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
2480     img_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
2481     img_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
2482     img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2483     img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2484     img_barrier.image = image.handle();
2485     img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
2486     img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
2487     img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2488     img_barrier.subresourceRange.baseArrayLayer = 0;
2489     img_barrier.subresourceRange.baseMipLevel = 0;
2490     img_barrier.subresourceRange.layerCount = 1;
2491     img_barrier.subresourceRange.levelCount = 1;
2492     // Mis-match src stage mask
2493     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2494     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2495     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2496                          VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
2497     m_errorMonitor->VerifyFound();
2498     // Now mis-match dst stage mask
2499     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2500     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2501     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_HOST_BIT,
2502                          VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
2503     m_errorMonitor->VerifyFound();
2504     // Set srcQueueFamilyIndex to something other than IGNORED
2505     img_barrier.srcQueueFamilyIndex = 0;
2506     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-srcQueueFamilyIndex-01182");
2507     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2508                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
2509                          &img_barrier);
2510     m_errorMonitor->VerifyFound();
2511     img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
2512     // Mis-match mem barrier src access mask
2513     mem_barrier = {};
2514     mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
2515     mem_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
2516     mem_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
2517     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2518     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2519     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2520                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 1, &mem_barrier, 0, nullptr, 0,
2521                          nullptr);
2522     m_errorMonitor->VerifyFound();
2523     // Mis-match mem barrier dst access mask. Also set srcAccessMask to 0 which should not cause an error
2524     mem_barrier.srcAccessMask = 0;
2525     mem_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
2526     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2527     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2528     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2529                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 1, &mem_barrier, 0, nullptr, 0,
2530                          nullptr);
2531     m_errorMonitor->VerifyFound();
2532     // Mis-match image barrier src access mask
2533     img_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
2534     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2535     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2536     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2537                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
2538                          &img_barrier);
2539     m_errorMonitor->VerifyFound();
2540     // Mis-match image barrier dst access mask
2541     img_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
2542     img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
2543     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2544     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2545     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2546                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
2547                          &img_barrier);
2548     m_errorMonitor->VerifyFound();
2549     // Mis-match dependencyFlags
2550     img_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
2551     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-pDependencies-02285");
2552     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2553                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0 /* wrong */, 0, nullptr, 0, nullptr, 1, &img_barrier);
2554     m_errorMonitor->VerifyFound();
2555     // Send non-zero bufferMemoryBarrierCount
2556     // Construct a valid BufferMemoryBarrier to avoid any parameter errors
2557     // First we need a valid buffer to reference
2558     VkBufferObj buffer;
2559     VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
2560     buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
2561     VkBufferMemoryBarrier bmb = {};
2562     bmb.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
2563     bmb.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
2564     bmb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
2565     bmb.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
2566     bmb.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
2567     bmb.buffer = buffer.handle();
2568     bmb.offset = 0;
2569     bmb.size = VK_WHOLE_SIZE;
2570     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-bufferMemoryBarrierCount-01178");
2571     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2572                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 1, &bmb, 0,
2573                          nullptr);
2574     m_errorMonitor->VerifyFound();
2575     // Add image barrier w/ image handle that's not in framebuffer
2576     VkImageObj lone_image(m_device);
2577     lone_image.InitNoLayout(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2578     img_barrier.image = lone_image.handle();
2579     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-image-02635");
2580     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2581                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
2582                          &img_barrier);
2583     m_errorMonitor->VerifyFound();
2584     // Have image barrier with mis-matched layouts
2585     img_barrier.image = image.handle();
2586     img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2587     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-oldLayout-01181");
2588     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2589                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
2590                          &img_barrier);
2591     m_errorMonitor->VerifyFound();
2592 
2593     img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
2594     img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
2595     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-oldLayout-02636");
2596     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2597                          VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
2598                          &img_barrier);
2599     m_errorMonitor->VerifyFound();
2600     vkCmdEndRenderPass(m_commandBuffer->handle());
2601 
2602     vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2603     vkDestroyRenderPass(m_device->device(), rp, nullptr);
2604     vkDestroyRenderPass(m_device->device(), rp_noselfdep, nullptr);
2605 }
2606 
TEST_F(VkLayerTest,InvalidCmdBufferBufferDestroyed)2607 TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
2608     TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid due to a buffer dependency being destroyed.");
2609     ASSERT_NO_FATAL_FAILURE(Init());
2610 
2611     VkBuffer buffer;
2612     VkDeviceMemory mem;
2613     VkMemoryRequirements mem_reqs;
2614 
2615     VkBufferCreateInfo buf_info = {};
2616     buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2617     buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
2618     buf_info.size = 256;
2619     buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
2620     VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
2621     ASSERT_VK_SUCCESS(err);
2622 
2623     vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
2624 
2625     VkMemoryAllocateInfo alloc_info = {};
2626     alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627     alloc_info.allocationSize = mem_reqs.size;
2628     bool pass = false;
2629     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2630     if (!pass) {
2631         printf("%s Failed to set memory type.\n", kSkipPrefix);
2632         vkDestroyBuffer(m_device->device(), buffer, NULL);
2633         return;
2634     }
2635     err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2636     ASSERT_VK_SUCCESS(err);
2637 
2638     err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2639     ASSERT_VK_SUCCESS(err);
2640 
2641     m_commandBuffer->begin();
2642     vkCmdFillBuffer(m_commandBuffer->handle(), buffer, 0, VK_WHOLE_SIZE, 0);
2643     m_commandBuffer->end();
2644 
2645     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2646                                          "UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkBuffer");
2647     // Destroy buffer dependency prior to submit to cause ERROR
2648     vkDestroyBuffer(m_device->device(), buffer, NULL);
2649 
2650     VkSubmitInfo submit_info = {};
2651     submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2652     submit_info.commandBufferCount = 1;
2653     submit_info.pCommandBuffers = &m_commandBuffer->handle();
2654     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2655 
2656     m_errorMonitor->VerifyFound();
2657     vkQueueWaitIdle(m_device->m_queue);
2658     vkFreeMemory(m_device->handle(), mem, NULL);
2659 }
2660 
TEST_F(VkLayerTest,InvalidCmdBufferBufferViewDestroyed)2661 TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
2662     TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
2663 
2664     ASSERT_NO_FATAL_FAILURE(Init());
2665     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2666 
2667     OneOffDescriptorSet descriptor_set(m_device,
2668                                        {
2669                                            {0, VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr},
2670                                        });
2671     CreatePipelineHelper pipe(*this);
2672     VkBufferCreateInfo buffer_create_info = {};
2673     VkBufferViewCreateInfo bvci = {};
2674     VkBufferView view;
2675 
2676     {
2677         uint32_t queue_family_index = 0;
2678         buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2679         buffer_create_info.size = 1024;
2680         buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
2681         buffer_create_info.queueFamilyIndexCount = 1;
2682         buffer_create_info.pQueueFamilyIndices = &queue_family_index;
2683         VkBufferObj buffer;
2684         buffer.init(*m_device, buffer_create_info);
2685 
2686         bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
2687         bvci.buffer = buffer.handle();
2688         bvci.format = VK_FORMAT_R32_SFLOAT;
2689         bvci.range = VK_WHOLE_SIZE;
2690 
2691         VkResult err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
2692         ASSERT_VK_SUCCESS(err);
2693 
2694         descriptor_set.WriteDescriptorBufferView(0, view);
2695         descriptor_set.UpdateDescriptorSets();
2696 
2697         char const *fsSource =
2698             "#version 450\n"
2699             "\n"
2700             "layout(set=0, binding=0, r32f) uniform readonly imageBuffer s;\n"
2701             "layout(location=0) out vec4 x;\n"
2702             "void main(){\n"
2703             "   x = imageLoad(s, 0);\n"
2704             "}\n";
2705         VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
2706         VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2707 
2708         pipe.InitInfo();
2709         pipe.InitState();
2710         pipe.shader_stages_ = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
2711         pipe.pipeline_layout_ = VkPipelineLayoutObj(m_device, {&descriptor_set.layout_});
2712         pipe.CreateGraphicsPipeline();
2713 
2714         m_commandBuffer->begin();
2715         m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
2716 
2717         VkViewport viewport = {0, 0, 16, 16, 0, 1};
2718         vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
2719         VkRect2D scissor = {{0, 0}, {16, 16}};
2720         vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
2721         // Bind pipeline to cmd buffer - This causes crash on Mali
2722         vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
2723         vkCmdBindDescriptorSets(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_layout_.handle(), 0, 1,
2724                                 &descriptor_set.set_, 0, nullptr);
2725     }
2726     // buffer is released.
2727     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Descriptor in binding #0 index 0 is using buffer");
2728     m_commandBuffer->Draw(1, 0, 0, 0);
2729     m_errorMonitor->VerifyFound();
2730 
2731     vkDestroyBufferView(m_device->device(), view, NULL);
2732     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Descriptor in binding #0 index 0 is using bufferView");
2733     m_commandBuffer->Draw(1, 0, 0, 0);
2734     m_errorMonitor->VerifyFound();
2735 
2736     VkBufferObj buffer;
2737     buffer.init(*m_device, buffer_create_info);
2738 
2739     bvci.buffer = buffer.handle();
2740     VkResult err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
2741     ASSERT_VK_SUCCESS(err);
2742     descriptor_set.descriptor_writes.clear();
2743     descriptor_set.WriteDescriptorBufferView(0, view);
2744     descriptor_set.UpdateDescriptorSets();
2745 
2746     vkCmdBindDescriptorSets(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_layout_.handle(), 0, 1,
2747                             &descriptor_set.set_, 0, nullptr);
2748     m_commandBuffer->Draw(1, 0, 0, 0);
2749     m_commandBuffer->EndRenderPass();
2750     m_commandBuffer->end();
2751 
2752     // Delete BufferView in order to invalidate cmd buffer
2753     vkDestroyBufferView(m_device->device(), view, NULL);
2754     // Now attempt submit of cmd buffer
2755     VkSubmitInfo submit_info = {};
2756     submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2757     submit_info.commandBufferCount = 1;
2758     submit_info.pCommandBuffers = &m_commandBuffer->handle();
2759     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2760                                          "UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkBufferView");
2761     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2762     m_errorMonitor->VerifyFound();
2763 }
2764 
TEST_F(VkLayerTest,InvalidCmdBufferImageDestroyed)2765 TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
2766     TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid due to an image dependency being destroyed.");
2767     ASSERT_NO_FATAL_FAILURE(Init());
2768     {
2769         const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2770         VkImageCreateInfo image_create_info = {};
2771         image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2772         image_create_info.pNext = NULL;
2773         image_create_info.imageType = VK_IMAGE_TYPE_2D;
2774         image_create_info.format = tex_format;
2775         image_create_info.extent.width = 32;
2776         image_create_info.extent.height = 32;
2777         image_create_info.extent.depth = 1;
2778         image_create_info.mipLevels = 1;
2779         image_create_info.arrayLayers = 1;
2780         image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2781         image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2782         image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2783         image_create_info.flags = 0;
2784         VkImageObj image(m_device);
2785         image.init(&image_create_info);
2786 
2787         m_commandBuffer->begin();
2788         VkClearColorValue ccv;
2789         ccv.float32[0] = 1.0f;
2790         ccv.float32[1] = 1.0f;
2791         ccv.float32[2] = 1.0f;
2792         ccv.float32[3] = 1.0f;
2793         VkImageSubresourceRange isr = {};
2794         isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795         isr.baseArrayLayer = 0;
2796         isr.baseMipLevel = 0;
2797         isr.layerCount = 1;
2798         isr.levelCount = 1;
2799         vkCmdClearColorImage(m_commandBuffer->handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
2800         m_commandBuffer->end();
2801     }
2802     // Destroy image dependency prior to submit to cause ERROR
2803     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2804                                          "UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkImage");
2805     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2806                                          "UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkDeviceMemory");
2807 
2808     VkSubmitInfo submit_info = {};
2809     submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2810     submit_info.commandBufferCount = 1;
2811     submit_info.pCommandBuffers = &m_commandBuffer->handle();
2812     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2813 
2814     m_errorMonitor->VerifyFound();
2815 }
2816 
TEST_F(VkLayerTest,InvalidCmdBufferFramebufferImageDestroyed)2817 TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
2818     TEST_DESCRIPTION(
2819         "Attempt to draw with a command buffer that is invalid due to a framebuffer image dependency being destroyed.");
2820     ASSERT_NO_FATAL_FAILURE(Init());
2821     VkFormatProperties format_properties;
2822     VkResult err = VK_SUCCESS;
2823     vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
2824     if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
2825         printf("%s Image format doesn't support required features.\n", kSkipPrefix);
2826         return;
2827     }
2828     VkFramebuffer fb;
2829     VkImageView view;
2830 
2831     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2832     {
2833         VkImageCreateInfo image_ci = {};
2834         image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2835         image_ci.pNext = NULL;
2836         image_ci.imageType = VK_IMAGE_TYPE_2D;
2837         image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
2838         image_ci.extent.width = 32;
2839         image_ci.extent.height = 32;
2840         image_ci.extent.depth = 1;
2841         image_ci.mipLevels = 1;
2842         image_ci.arrayLayers = 1;
2843         image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
2844         image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
2845         image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
2846         image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2847         image_ci.flags = 0;
2848         VkImageObj image(m_device);
2849         image.init(&image_ci);
2850 
2851         VkImageViewCreateInfo ivci = {
2852             VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
2853             nullptr,
2854             0,
2855             image.handle(),
2856             VK_IMAGE_VIEW_TYPE_2D,
2857             VK_FORMAT_B8G8R8A8_UNORM,
2858             {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
2859             {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
2860         };
2861         err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
2862         ASSERT_VK_SUCCESS(err);
2863 
2864         VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
2865         err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
2866         ASSERT_VK_SUCCESS(err);
2867 
2868         // Just use default renderpass with our framebuffer
2869         m_renderPassBeginInfo.framebuffer = fb;
2870         m_renderPassBeginInfo.renderArea.extent.width = 32;
2871         m_renderPassBeginInfo.renderArea.extent.height = 32;
2872         // Create Null cmd buffer for submit
2873         m_commandBuffer->begin();
2874         m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
2875         m_commandBuffer->EndRenderPass();
2876         m_commandBuffer->end();
2877     }
2878     // Destroy image attached to framebuffer to invalidate cmd buffer
2879     // Now attempt to submit cmd buffer and verify error
2880     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2881                                          "UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkImage");
2882     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2883                                          "UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkDeviceMemory");
2884     m_commandBuffer->QueueCommandBuffer(false);
2885     m_errorMonitor->VerifyFound();
2886 
2887     vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2888     vkDestroyImageView(m_device->device(), view, nullptr);
2889 }
2890 
TEST_F(VkLayerTest,ImageMemoryNotBound)2891 TEST_F(VkLayerTest, ImageMemoryNotBound) {
2892     TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
2893     ASSERT_NO_FATAL_FAILURE(Init());
2894 
2895     VkImage image;
2896     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2897     VkImageCreateInfo image_create_info = {};
2898     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2899     image_create_info.pNext = NULL;
2900     image_create_info.imageType = VK_IMAGE_TYPE_2D;
2901     image_create_info.format = tex_format;
2902     image_create_info.extent.width = 32;
2903     image_create_info.extent.height = 32;
2904     image_create_info.extent.depth = 1;
2905     image_create_info.mipLevels = 1;
2906     image_create_info.arrayLayers = 1;
2907     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2908     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2909     image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2910     image_create_info.flags = 0;
2911     VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2912     ASSERT_VK_SUCCESS(err);
2913     // Have to bind memory to image before recording cmd in cmd buffer using it
2914     VkMemoryRequirements mem_reqs;
2915     VkDeviceMemory image_mem;
2916     bool pass;
2917     VkMemoryAllocateInfo mem_alloc = {};
2918     mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2919     mem_alloc.pNext = NULL;
2920     mem_alloc.memoryTypeIndex = 0;
2921     vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2922     mem_alloc.allocationSize = mem_reqs.size;
2923     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
2924     ASSERT_TRUE(pass);
2925     err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
2926     ASSERT_VK_SUCCESS(err);
2927 
2928     // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
2929     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2930                                          " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
2931 
2932     m_commandBuffer->begin();
2933     VkClearColorValue ccv;
2934     ccv.float32[0] = 1.0f;
2935     ccv.float32[1] = 1.0f;
2936     ccv.float32[2] = 1.0f;
2937     ccv.float32[3] = 1.0f;
2938     VkImageSubresourceRange isr = {};
2939     isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2940     isr.baseArrayLayer = 0;
2941     isr.baseMipLevel = 0;
2942     isr.layerCount = 1;
2943     isr.levelCount = 1;
2944     vkCmdClearColorImage(m_commandBuffer->handle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
2945     m_commandBuffer->end();
2946 
2947     m_errorMonitor->VerifyFound();
2948     vkDestroyImage(m_device->device(), image, NULL);
2949     vkFreeMemory(m_device->device(), image_mem, nullptr);
2950 }
2951 
TEST_F(VkLayerTest,BufferMemoryNotBound)2952 TEST_F(VkLayerTest, BufferMemoryNotBound) {
2953     TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
2954     ASSERT_NO_FATAL_FAILURE(Init());
2955 
2956     VkImageObj image(m_device);
2957     image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
2958                VK_IMAGE_TILING_OPTIMAL, 0);
2959     ASSERT_TRUE(image.initialized());
2960 
2961     VkBuffer buffer;
2962     VkDeviceMemory mem;
2963     VkMemoryRequirements mem_reqs;
2964 
2965     VkBufferCreateInfo buf_info = {};
2966     buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2967     buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
2968     buf_info.size = 1024;
2969     buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
2970     VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
2971     ASSERT_VK_SUCCESS(err);
2972 
2973     vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
2974 
2975     VkMemoryAllocateInfo alloc_info = {};
2976     alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2977     alloc_info.allocationSize = 1024;
2978     bool pass = false;
2979     pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2980     if (!pass) {
2981         printf("%s Failed to set memory type.\n", kSkipPrefix);
2982         vkDestroyBuffer(m_device->device(), buffer, NULL);
2983         return;
2984     }
2985     err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2986     ASSERT_VK_SUCCESS(err);
2987 
2988     // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2989     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2990                                          " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
2991     VkBufferImageCopy region = {};
2992     region.bufferRowLength = 16;
2993     region.bufferImageHeight = 16;
2994     region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2995 
2996     region.imageSubresource.layerCount = 1;
2997     region.imageExtent.height = 4;
2998     region.imageExtent.width = 4;
2999     region.imageExtent.depth = 1;
3000     m_commandBuffer->begin();
3001     vkCmdCopyBufferToImage(m_commandBuffer->handle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
3002     m_commandBuffer->end();
3003 
3004     m_errorMonitor->VerifyFound();
3005 
3006     vkDestroyBuffer(m_device->device(), buffer, NULL);
3007     vkFreeMemory(m_device->handle(), mem, NULL);
3008 }
3009 
TEST_F(VkLayerTest,MultiplaneImageLayoutBadAspectFlags)3010 TEST_F(VkLayerTest, MultiplaneImageLayoutBadAspectFlags) {
3011     TEST_DESCRIPTION("Query layout of a multiplane image using illegal aspect flag masks");
3012 
3013     // Enable KHR multiplane req'd extensions
3014     bool mp_extensions = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
3015                                                     VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION);
3016     if (mp_extensions) {
3017         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
3018     }
3019     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
3020     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
3021     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
3022     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
3023     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
3024     if (mp_extensions) {
3025         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
3026         m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
3027         m_device_extension_names.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
3028         m_device_extension_names.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
3029     } else {
3030         printf("%s test requires KHR multiplane extensions, not available.  Skipping.\n", kSkipPrefix);
3031         return;
3032     }
3033     ASSERT_NO_FATAL_FAILURE(InitState());
3034 
3035     VkImageCreateInfo ci = {};
3036     ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3037     ci.pNext = NULL;
3038     ci.flags = 0;
3039     ci.imageType = VK_IMAGE_TYPE_2D;
3040     ci.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
3041     ci.extent = {128, 128, 1};
3042     ci.mipLevels = 1;
3043     ci.arrayLayers = 1;
3044     ci.samples = VK_SAMPLE_COUNT_1_BIT;
3045     ci.tiling = VK_IMAGE_TILING_LINEAR;
3046     ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
3047     ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3048     ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3049 
3050     // Verify formats
3051     bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
3052     ci.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR;
3053     supported = supported && ImageFormatAndFeaturesSupported(instance(), gpu(), ci, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
3054     if (!supported) {
3055         printf("%s Multiplane image format not supported.  Skipping test.\n", kSkipPrefix);
3056         return;  // Assume there's low ROI on searching for different mp formats
3057     }
3058 
3059     VkImage image_2plane, image_3plane;
3060     ci.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
3061     VkResult err = vkCreateImage(device(), &ci, NULL, &image_2plane);
3062     ASSERT_VK_SUCCESS(err);
3063 
3064     ci.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR;
3065     err = vkCreateImage(device(), &ci, NULL, &image_3plane);
3066     ASSERT_VK_SUCCESS(err);
3067 
3068     // Query layout of 3rd plane, for a 2-plane image
3069     VkImageSubresource subres = {};
3070     subres.aspectMask = VK_IMAGE_ASPECT_PLANE_2_BIT_KHR;
3071     subres.mipLevel = 0;
3072     subres.arrayLayer = 0;
3073     VkSubresourceLayout layout = {};
3074 
3075     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageSubresourceLayout-format-01581");
3076     vkGetImageSubresourceLayout(device(), image_2plane, &subres, &layout);
3077     m_errorMonitor->VerifyFound();
3078 
3079     // Query layout using color aspect, for a 3-plane image
3080     subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3081     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageSubresourceLayout-format-01582");
3082     vkGetImageSubresourceLayout(device(), image_3plane, &subres, &layout);
3083     m_errorMonitor->VerifyFound();
3084 
3085     // Clean up
3086     vkDestroyImage(device(), image_2plane, NULL);
3087     vkDestroyImage(device(), image_3plane, NULL);
3088 }
3089 
TEST_F(VkLayerTest,InvalidBufferViewObject)3090 TEST_F(VkLayerTest, InvalidBufferViewObject) {
3091     // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
3092     // First, cause the bufferView to be invalid due to underlying buffer being destroyed
3093     // Then destroy view itself and verify that same error is hit
3094     VkResult err;
3095 
3096     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkWriteDescriptorSet-descriptorType-00323");
3097     ASSERT_NO_FATAL_FAILURE(Init());
3098 
3099     OneOffDescriptorSet descriptor_set(m_device, {
3100                                                      {0, VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
3101                                                  });
3102     VkBufferView view;
3103     {
3104         // Create a valid bufferView to start with
3105         uint32_t queue_family_index = 0;
3106         VkBufferCreateInfo buffer_create_info = {};
3107         buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3108         buffer_create_info.size = 1024;
3109         buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3110         buffer_create_info.queueFamilyIndexCount = 1;
3111         buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3112         VkBufferObj buffer;
3113         buffer.init(*m_device, buffer_create_info);
3114 
3115         VkBufferViewCreateInfo bvci = {};
3116         bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
3117         bvci.buffer = buffer.handle();
3118         bvci.format = VK_FORMAT_R32_SFLOAT;
3119         bvci.range = VK_WHOLE_SIZE;
3120 
3121         err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
3122         ASSERT_VK_SUCCESS(err);
3123     }
3124     // First Destroy buffer underlying view which should hit error in CV
3125 
3126     VkWriteDescriptorSet descriptor_write;
3127     memset(&descriptor_write, 0, sizeof(descriptor_write));
3128     descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3129     descriptor_write.dstSet = descriptor_set.set_;
3130     descriptor_write.dstBinding = 0;
3131     descriptor_write.descriptorCount = 1;
3132     descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3133     descriptor_write.pTexelBufferView = &view;
3134 
3135     vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3136     m_errorMonitor->VerifyFound();
3137 
3138     // Now destroy view itself and verify same error, which is hit in PV this time
3139     vkDestroyBufferView(m_device->device(), view, NULL);
3140     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkWriteDescriptorSet-descriptorType-00323");
3141     vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3142     m_errorMonitor->VerifyFound();
3143 }
3144 
TEST_F(VkLayerTest,CreateBufferViewNoMemoryBoundToBuffer)3145 TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
3146     TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
3147 
3148     VkResult err;
3149     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3150                                          " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
3151 
3152     ASSERT_NO_FATAL_FAILURE(Init());
3153 
3154     // Create a buffer with no bound memory and then attempt to create
3155     // a buffer view.
3156     VkBufferCreateInfo buff_ci = {};
3157     buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3158     buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
3159     buff_ci.size = 256;
3160     buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3161     VkBuffer buffer;
3162     err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
3163     ASSERT_VK_SUCCESS(err);
3164 
3165     VkBufferViewCreateInfo buff_view_ci = {};
3166     buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
3167     buff_view_ci.buffer = buffer;
3168     buff_view_ci.format = VK_FORMAT_R8_UNORM;
3169     buff_view_ci.range = VK_WHOLE_SIZE;
3170     VkBufferView buff_view;
3171     err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
3172 
3173     m_errorMonitor->VerifyFound();
3174     vkDestroyBuffer(m_device->device(), buffer, NULL);
3175     // If last error is success, it still created the view, so delete it.
3176     if (err == VK_SUCCESS) {
3177         vkDestroyBufferView(m_device->device(), buff_view, NULL);
3178     }
3179 }
3180 
TEST_F(VkLayerTest,InvalidBufferViewCreateInfoEntries)3181 TEST_F(VkLayerTest, InvalidBufferViewCreateInfoEntries) {
3182     TEST_DESCRIPTION("Attempt to create a buffer view with invalid create info.");
3183 
3184     ASSERT_NO_FATAL_FAILURE(Init());
3185 
3186     const VkPhysicalDeviceLimits &dev_limits = m_device->props.limits;
3187     const VkDeviceSize minTexelBufferOffsetAlignment = dev_limits.minTexelBufferOffsetAlignment;
3188     if (minTexelBufferOffsetAlignment == 1) {
3189         printf("%s Test requires minTexelOffsetAlignment to not be equal to 1. \n", kSkipPrefix);
3190         return;
3191     }
3192 
3193     const VkFormat format_with_uniform_texel_support = VK_FORMAT_R8G8B8A8_UNORM;
3194     const char *format_with_uniform_texel_support_string = "VK_FORMAT_R8G8B8A8_UNORM";
3195     const VkFormat format_without_texel_support = VK_FORMAT_R8G8B8_UNORM;
3196     const char *format_without_texel_support_string = "VK_FORMAT_R8G8B8_UNORM";
3197     VkFormatProperties format_properties;
3198     vkGetPhysicalDeviceFormatProperties(gpu(), format_with_uniform_texel_support, &format_properties);
3199     if (!(format_properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)) {
3200         printf("%s Test requires %s to support VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT\n", kSkipPrefix,
3201                format_with_uniform_texel_support_string);
3202         return;
3203     }
3204     vkGetPhysicalDeviceFormatProperties(gpu(), format_without_texel_support, &format_properties);
3205     if ((format_properties.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ||
3206         (format_properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)) {
3207         printf(
3208             "%s Test requires %s to not support VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT nor "
3209             "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT\n",
3210             kSkipPrefix, format_without_texel_support_string);
3211         return;
3212     }
3213 
3214     // Create a test buffer--buffer must have been created using VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or
3215     // VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, so use a different usage value instead to cause an error
3216     const VkDeviceSize resource_size = 1024;
3217     const VkBufferCreateInfo bad_buffer_info = VkBufferObj::create_info(resource_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
3218     VkBufferObj bad_buffer;
3219     bad_buffer.init(*m_device, bad_buffer_info, (VkMemoryPropertyFlags)VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
3220 
3221     // Create a test buffer view
3222     VkBufferViewCreateInfo buff_view_ci = {};
3223     buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
3224     buff_view_ci.buffer = bad_buffer.handle();
3225     buff_view_ci.format = format_with_uniform_texel_support;
3226     buff_view_ci.range = VK_WHOLE_SIZE;
3227     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-buffer-00932"});
3228 
3229     // Create a better test buffer
3230     const VkBufferCreateInfo buffer_info = VkBufferObj::create_info(resource_size, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT);
3231     VkBufferObj buffer;
3232     buffer.init(*m_device, buffer_info, (VkMemoryPropertyFlags)VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
3233 
3234     // Offset must be less than the size of the buffer, so set it equal to the buffer size to cause an error
3235     buff_view_ci.buffer = buffer.handle();
3236     buff_view_ci.offset = buffer.create_info().size;
3237     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-offset-00925"});
3238 
3239     // Offset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment so add 1 to ensure it is not
3240     buff_view_ci.offset = minTexelBufferOffsetAlignment + 1;
3241     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-offset-02749"});
3242 
3243     // Set offset to acceptable value for range tests
3244     buff_view_ci.offset = minTexelBufferOffsetAlignment;
3245     // Setting range equal to 0 will cause an error to occur
3246     buff_view_ci.range = 0;
3247     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-range-00928"});
3248 
3249     uint32_t format_size = FormatElementSize(buff_view_ci.format);
3250     // Range must be a multiple of the element size of format, so add one to ensure it is not
3251     buff_view_ci.range = format_size + 1;
3252     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-range-00929"});
3253 
3254     // Twice the element size of format multiplied by VkPhysicalDeviceLimits::maxTexelBufferElements guarantees range divided by the
3255     // element size is greater than maxTexelBufferElements, causing failure
3256     buff_view_ci.range = 2 * format_size * dev_limits.maxTexelBufferElements;
3257     CreateBufferViewTest(*this, &buff_view_ci,
3258                          {"VUID-VkBufferViewCreateInfo-range-00930", "VUID-VkBufferViewCreateInfo-offset-00931"});
3259 
3260     // Set rage to acceptable value for buffer tests
3261     buff_view_ci.format = format_without_texel_support;
3262     buff_view_ci.range = VK_WHOLE_SIZE;
3263 
3264     // `buffer` was created using VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT so we can use that for the first buffer test
3265     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-buffer-00933"});
3266 
3267     // Create a new buffer using VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
3268     const VkBufferCreateInfo storage_buffer_info =
3269         VkBufferObj::create_info(resource_size, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT);
3270     VkBufferObj storage_buffer;
3271     storage_buffer.init(*m_device, storage_buffer_info, (VkMemoryPropertyFlags)VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
3272 
3273     buff_view_ci.buffer = storage_buffer.handle();
3274     CreateBufferViewTest(*this, &buff_view_ci, {"VUID-VkBufferViewCreateInfo-buffer-00934"});
3275 }
3276 
TEST_F(VkLayerTest,InvalidTexelBufferAlignment)3277 TEST_F(VkLayerTest, InvalidTexelBufferAlignment) {
3278     TEST_DESCRIPTION("Test VK_EXT_texel_buffer_alignment.");
3279 
3280     if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
3281         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
3282     } else {
3283         printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
3284                VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
3285         return;
3286     }
3287 
3288     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
3289     std::array<const char *, 1> required_device_extensions = {{VK_EXT_TEXEL_BUFFER_ALIGNMENT_EXTENSION_NAME}};
3290     for (auto device_extension : required_device_extensions) {
3291         if (DeviceExtensionSupported(gpu(), nullptr, device_extension)) {
3292             m_device_extension_names.push_back(device_extension);
3293         } else {
3294             printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, device_extension);
3295             return;
3296         }
3297     }
3298 
3299     if (DeviceIsMockICD() || DeviceSimulation()) {
3300         printf("%s MockICD does not support this feature, skipping tests\n", kSkipPrefix);
3301         return;
3302     }
3303 
3304     PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR =
3305         (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR");
3306     ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
3307 
3308     // Create a device that enables texel_buffer_alignment
3309     auto texel_buffer_alignment_features = lvl_init_struct<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>();
3310     auto features2 = lvl_init_struct<VkPhysicalDeviceFeatures2KHR>(&texel_buffer_alignment_features);
3311     vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
3312     texel_buffer_alignment_features.texelBufferAlignment = VK_TRUE;
3313 
3314     VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT align_props = {};
3315     align_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT;
3316     VkPhysicalDeviceProperties2 pd_props2 = {};
3317     pd_props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
3318     pd_props2.pNext = &align_props;
3319     vkGetPhysicalDeviceProperties2(gpu(), &pd_props2);
3320 
3321     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
3322     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3323 
3324     const VkFormat format_with_uniform_texel_support = VK_FORMAT_R8G8B8A8_UNORM;
3325 
3326     const VkDeviceSize resource_size = 1024;
3327     VkBufferCreateInfo buffer_info = VkBufferObj::create_info(
3328         resource_size, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT);
3329     VkBufferObj buffer;
3330     buffer.init(*m_device, buffer_info, (VkMemoryPropertyFlags)VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
3331 
3332     // Create a test buffer view
3333     VkBufferViewCreateInfo buff_view_ci = {};
3334     buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
3335     buff_view_ci.buffer = buffer.handle();
3336     buff_view_ci.format = format_with_uniform_texel_support;
3337     buff_view_ci.range = VK_WHOLE_SIZE;
3338 
3339     buff_view_ci.offset = 1;
3340     std::vector<std::string> expectedErrors;
3341     if (buff_view_ci.offset < align_props.storageTexelBufferOffsetAlignmentBytes) {
3342         expectedErrors.push_back("VUID-VkBufferViewCreateInfo-buffer-02750");
3343     }
3344     if (buff_view_ci.offset < align_props.uniformTexelBufferOffsetAlignmentBytes) {
3345         expectedErrors.push_back("VUID-VkBufferViewCreateInfo-buffer-02751");
3346     }
3347     CreateBufferViewTest(*this, &buff_view_ci, expectedErrors);
3348     expectedErrors.clear();
3349 
3350     buff_view_ci.offset = 4;
3351     if (buff_view_ci.offset < align_props.storageTexelBufferOffsetAlignmentBytes &&
3352         !align_props.storageTexelBufferOffsetSingleTexelAlignment) {
3353         expectedErrors.push_back("VUID-VkBufferViewCreateInfo-buffer-02750");
3354     }
3355     if (buff_view_ci.offset < align_props.uniformTexelBufferOffsetAlignmentBytes &&
3356         !align_props.uniformTexelBufferOffsetSingleTexelAlignment) {
3357         expectedErrors.push_back("VUID-VkBufferViewCreateInfo-buffer-02751");
3358     }
3359     CreateBufferViewTest(*this, &buff_view_ci, expectedErrors);
3360     expectedErrors.clear();
3361 
3362     // Test a 3-component format
3363     VkFormatProperties format_properties;
3364     vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_R32G32B32_SFLOAT, &format_properties);
3365     if (format_properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) {
3366         buffer_info.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
3367         VkBufferObj buffer2;
3368         buffer2.init(*m_device, buffer_info, (VkMemoryPropertyFlags)VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
3369 
3370         // Create a test buffer view
3371         buff_view_ci.buffer = buffer2.handle();
3372 
3373         buff_view_ci.format = VK_FORMAT_R32G32B32_SFLOAT;
3374         buff_view_ci.offset = 1;
3375         if (buff_view_ci.offset < align_props.uniformTexelBufferOffsetAlignmentBytes) {
3376             expectedErrors.push_back("VUID-VkBufferViewCreateInfo-buffer-02751");
3377         }
3378         CreateBufferViewTest(*this, &buff_view_ci, expectedErrors);
3379         expectedErrors.clear();
3380 
3381         buff_view_ci.offset = 4;
3382         if (buff_view_ci.offset < align_props.uniformTexelBufferOffsetAlignmentBytes &&
3383             !align_props.uniformTexelBufferOffsetSingleTexelAlignment) {
3384             expectedErrors.push_back("VUID-VkBufferViewCreateInfo-buffer-02751");
3385         }
3386         CreateBufferViewTest(*this, &buff_view_ci, expectedErrors);
3387         expectedErrors.clear();
3388     }
3389 }
3390 
TEST_F(VkLayerTest,FillBufferWithinRenderPass)3391 TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
3392     // Call CmdFillBuffer within an active renderpass
3393     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdFillBuffer-renderpass");
3394 
3395     ASSERT_NO_FATAL_FAILURE(Init());
3396     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3397 
3398     m_commandBuffer->begin();
3399     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
3400 
3401     VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3402     VkBufferObj dstBuffer;
3403     dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
3404 
3405     m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
3406 
3407     m_errorMonitor->VerifyFound();
3408 
3409     m_commandBuffer->EndRenderPass();
3410     m_commandBuffer->end();
3411 }
3412 
TEST_F(VkLayerTest,UpdateBufferWithinRenderPass)3413 TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
3414     // Call CmdUpdateBuffer within an active renderpass
3415     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdUpdateBuffer-renderpass");
3416 
3417     ASSERT_NO_FATAL_FAILURE(Init());
3418     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3419 
3420     m_commandBuffer->begin();
3421     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
3422 
3423     VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3424     VkBufferObj dstBuffer;
3425     dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
3426 
3427     VkDeviceSize dstOffset = 0;
3428     uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
3429     VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
3430     vkCmdUpdateBuffer(m_commandBuffer->handle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
3431 
3432     m_errorMonitor->VerifyFound();
3433 
3434     m_commandBuffer->EndRenderPass();
3435     m_commandBuffer->end();
3436 }
3437 
TEST_F(VkLayerTest,ClearColorImageWithBadRange)3438 TEST_F(VkLayerTest, ClearColorImageWithBadRange) {
3439     TEST_DESCRIPTION("Record clear color with an invalid VkImageSubresourceRange");
3440 
3441     ASSERT_NO_FATAL_FAILURE(Init());
3442     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3443 
3444     VkImageObj image(m_device);
3445     image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
3446     ASSERT_TRUE(image.create_info().arrayLayers == 1);
3447     ASSERT_TRUE(image.initialized());
3448     image.SetLayout(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
3449 
3450     const VkClearColorValue clear_color = {{0.0f, 0.0f, 0.0f, 1.0f}};
3451 
3452     m_commandBuffer->begin();
3453     const auto cb_handle = m_commandBuffer->handle();
3454 
3455     // Try baseMipLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
3456     {
3457         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-baseMipLevel-01470");
3458         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
3459         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3460         m_errorMonitor->VerifyFound();
3461     }
3462 
3463     // Try baseMipLevel >= image.mipLevels without VK_REMAINING_MIP_LEVELS
3464     {
3465         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-baseMipLevel-01470");
3466         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-pRanges-01692");
3467         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
3468         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3469         m_errorMonitor->VerifyFound();
3470     }
3471 
3472     // Try levelCount = 0
3473     {
3474         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-pRanges-01692");
3475         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
3476         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3477         m_errorMonitor->VerifyFound();
3478     }
3479 
3480     // Try baseMipLevel + levelCount > image.mipLevels
3481     {
3482         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-pRanges-01692");
3483         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 2, 0, 1};
3484         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3485         m_errorMonitor->VerifyFound();
3486     }
3487 
3488     // Try baseArrayLayer >= image.arrayLayers with VK_REMAINING_ARRAY_LAYERS
3489     {
3490         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-baseArrayLayer-01472");
3491         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
3492         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3493         m_errorMonitor->VerifyFound();
3494     }
3495 
3496     // Try baseArrayLayer >= image.arrayLayers without VK_REMAINING_ARRAY_LAYERS
3497     {
3498         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-baseArrayLayer-01472");
3499         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-pRanges-01693");
3500         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
3501         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3502         m_errorMonitor->VerifyFound();
3503     }
3504 
3505     // Try layerCount = 0
3506     {
3507         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-pRanges-01693");
3508         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
3509         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3510         m_errorMonitor->VerifyFound();
3511     }
3512 
3513     // Try baseArrayLayer + layerCount > image.arrayLayers
3514     {
3515         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-pRanges-01693");
3516         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2};
3517         vkCmdClearColorImage(cb_handle, image.handle(), image.Layout(), &clear_color, 1, &range);
3518         m_errorMonitor->VerifyFound();
3519     }
3520 }
3521 
TEST_F(VkLayerTest,ClearDepthStencilWithBadRange)3522 TEST_F(VkLayerTest, ClearDepthStencilWithBadRange) {
3523     TEST_DESCRIPTION("Record clear depth with an invalid VkImageSubresourceRange");
3524 
3525     ASSERT_NO_FATAL_FAILURE(Init());
3526     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3527 
3528     const auto depth_format = FindSupportedDepthStencilFormat(gpu());
3529     if (!depth_format) {
3530         printf("%s No Depth + Stencil format found. Skipped.\n", kSkipPrefix);
3531         return;
3532     }
3533 
3534     VkImageObj image(m_device);
3535     image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
3536     ASSERT_TRUE(image.create_info().arrayLayers == 1);
3537     ASSERT_TRUE(image.initialized());
3538     const VkImageAspectFlags ds_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3539     image.SetLayout(ds_aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
3540 
3541     const VkClearDepthStencilValue clear_value = {};
3542 
3543     m_commandBuffer->begin();
3544     const auto cb_handle = m_commandBuffer->handle();
3545 
3546     // Try baseMipLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
3547     {
3548         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-baseMipLevel-01474");
3549         const VkImageSubresourceRange range = {ds_aspect, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
3550         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3551         m_errorMonitor->VerifyFound();
3552     }
3553 
3554     // Try baseMipLevel >= image.mipLevels without VK_REMAINING_MIP_LEVELS
3555     {
3556         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-baseMipLevel-01474");
3557         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-pRanges-01694");
3558         const VkImageSubresourceRange range = {ds_aspect, 1, 1, 0, 1};
3559         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3560         m_errorMonitor->VerifyFound();
3561     }
3562 
3563     // Try levelCount = 0
3564     {
3565         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-pRanges-01694");
3566         const VkImageSubresourceRange range = {ds_aspect, 0, 0, 0, 1};
3567         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3568         m_errorMonitor->VerifyFound();
3569     }
3570 
3571     // Try baseMipLevel + levelCount > image.mipLevels
3572     {
3573         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-pRanges-01694");
3574         const VkImageSubresourceRange range = {ds_aspect, 0, 2, 0, 1};
3575         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3576         m_errorMonitor->VerifyFound();
3577     }
3578 
3579     // Try baseArrayLayer >= image.arrayLayers with VK_REMAINING_ARRAY_LAYERS
3580     {
3581         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3582                                              "VUID-vkCmdClearDepthStencilImage-baseArrayLayer-01476");
3583         const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
3584         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3585         m_errorMonitor->VerifyFound();
3586     }
3587 
3588     // Try baseArrayLayer >= image.arrayLayers without VK_REMAINING_ARRAY_LAYERS
3589     {
3590         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3591                                              "VUID-vkCmdClearDepthStencilImage-baseArrayLayer-01476");
3592         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-pRanges-01695");
3593         const VkImageSubresourceRange range = {ds_aspect, 0, 1, 1, 1};
3594         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3595         m_errorMonitor->VerifyFound();
3596     }
3597 
3598     // Try layerCount = 0
3599     {
3600         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-pRanges-01695");
3601         const VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 0};
3602         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3603         m_errorMonitor->VerifyFound();
3604     }
3605 
3606     // Try baseArrayLayer + layerCount > image.arrayLayers
3607     {
3608         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-pRanges-01695");
3609         const VkImageSubresourceRange range = {ds_aspect, 0, 1, 0, 2};
3610         vkCmdClearDepthStencilImage(cb_handle, image.handle(), image.Layout(), &clear_value, 1, &range);
3611         m_errorMonitor->VerifyFound();
3612     }
3613 }
3614 
TEST_F(VkLayerTest,ClearColorImageWithinRenderPass)3615 TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
3616     // Call CmdClearColorImage within an active RenderPass
3617     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-renderpass");
3618 
3619     ASSERT_NO_FATAL_FAILURE(Init());
3620     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3621 
3622     m_commandBuffer->begin();
3623     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
3624 
3625     VkClearColorValue clear_color;
3626     memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
3627     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3628     const int32_t tex_width = 32;
3629     const int32_t tex_height = 32;
3630     VkImageCreateInfo image_create_info = {};
3631     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3632     image_create_info.pNext = NULL;
3633     image_create_info.imageType = VK_IMAGE_TYPE_2D;
3634     image_create_info.format = tex_format;
3635     image_create_info.extent.width = tex_width;
3636     image_create_info.extent.height = tex_height;
3637     image_create_info.extent.depth = 1;
3638     image_create_info.mipLevels = 1;
3639     image_create_info.arrayLayers = 1;
3640     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3641     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3642     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3643 
3644     VkImageObj dstImage(m_device);
3645     dstImage.init(&image_create_info);
3646 
3647     const VkImageSubresourceRange range = VkImageObj::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
3648 
3649     vkCmdClearColorImage(m_commandBuffer->handle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
3650 
3651     m_errorMonitor->VerifyFound();
3652 
3653     m_commandBuffer->EndRenderPass();
3654     m_commandBuffer->end();
3655 }
3656 
TEST_F(VkLayerTest,ClearDepthStencilImageErrors)3657 TEST_F(VkLayerTest, ClearDepthStencilImageErrors) {
3658     // Hit errors related to vkCmdClearDepthStencilImage()
3659     // 1. Use an image that doesn't have VK_IMAGE_USAGE_TRANSFER_DST_BIT set
3660     // 2. Call CmdClearDepthStencilImage within an active RenderPass
3661 
3662     ASSERT_NO_FATAL_FAILURE(Init());
3663     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3664 
3665     auto depth_format = FindSupportedDepthStencilFormat(gpu());
3666     if (!depth_format) {
3667         printf("%s No Depth + Stencil format found. Skipped.\n", kSkipPrefix);
3668         return;
3669     }
3670 
3671     VkClearDepthStencilValue clear_value = {0};
3672     VkImageCreateInfo image_create_info = VkImageObj::create_info();
3673     image_create_info.imageType = VK_IMAGE_TYPE_2D;
3674     image_create_info.format = depth_format;
3675     image_create_info.extent.width = 64;
3676     image_create_info.extent.height = 64;
3677     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3678     // Error here is that VK_IMAGE_USAGE_TRANSFER_DST_BIT is excluded for DS image that we'll call Clear on below
3679     image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3680 
3681     VkImageObj dst_image_bad_usage(m_device);
3682     dst_image_bad_usage.init(&image_create_info);
3683     const VkImageSubresourceRange range = VkImageObj::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
3684 
3685     m_commandBuffer->begin();
3686     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-image-00009");
3687     vkCmdClearDepthStencilImage(m_commandBuffer->handle(), dst_image_bad_usage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
3688                                 &range);
3689     m_errorMonitor->VerifyFound();
3690 
3691     // Fix usage for next test case
3692     image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3693     VkImageObj dst_image(m_device);
3694     dst_image.init(&image_create_info);
3695 
3696     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
3697 
3698     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-renderpass");
3699     vkCmdClearDepthStencilImage(m_commandBuffer->handle(), dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1, &range);
3700     m_errorMonitor->VerifyFound();
3701 
3702     m_commandBuffer->EndRenderPass();
3703     m_commandBuffer->end();
3704 }
3705 
TEST_F(VkLayerTest,BufferMemoryBarrierNoBuffer)3706 TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
3707     // Try to add a buffer memory barrier with no buffer.
3708     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3709                                          "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
3710 
3711     ASSERT_NO_FATAL_FAILURE(Init());
3712     m_commandBuffer->begin();
3713 
3714     VkBufferMemoryBarrier buf_barrier = {};
3715     buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
3716     buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
3717     buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
3718     buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
3719     buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
3720     buf_barrier.buffer = VK_NULL_HANDLE;
3721     buf_barrier.offset = 0;
3722     buf_barrier.size = VK_WHOLE_SIZE;
3723     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
3724                          1, &buf_barrier, 0, nullptr);
3725 
3726     m_errorMonitor->VerifyFound();
3727 }
3728 
TEST_F(VkLayerTest,InvalidBarriers)3729 TEST_F(VkLayerTest, InvalidBarriers) {
3730     TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
3731 
3732     ASSERT_NO_FATAL_FAILURE(Init());
3733     auto depth_format = FindSupportedDepthStencilFormat(gpu());
3734     if (!depth_format) {
3735         printf("%s No Depth + Stencil format found. Skipped.\n", kSkipPrefix);
3736         return;
3737     }
3738     // Add a token self-dependency for this test to avoid unexpected errors
3739     m_addRenderPassSelfDependency = true;
3740     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3741 
3742     const uint32_t submit_family = m_device->graphics_queue_node_index_;
3743     const uint32_t invalid = static_cast<uint32_t>(m_device->queue_props.size());
3744     const uint32_t other_family = submit_family != 0 ? 0 : 1;
3745     const bool only_one_family = (invalid == 1) || (m_device->queue_props[other_family].queueCount == 0);
3746     std::vector<uint32_t> qf_indices{{submit_family, other_family}};
3747     if (only_one_family) {
3748         qf_indices.resize(1);
3749     }
3750     BarrierQueueFamilyTestHelper::Context test_context(this, qf_indices);
3751 
3752     // Use image unbound to memory in barrier
3753     // Use buffer unbound to memory in barrier
3754     BarrierQueueFamilyTestHelper conc_test(&test_context);
3755     conc_test.Init(nullptr, false, false);
3756 
3757     conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
3758     conc_test(" used with no memory bound. Memory should be bound by calling vkBindImageMemory()",
3759               " used with no memory bound. Memory should be bound by calling vkBindBufferMemory()");
3760 
3761     VkBufferObj buffer;
3762     VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
3763     buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
3764     conc_test.buffer_barrier_.buffer = buffer.handle();
3765 
3766     VkImageObj image(m_device);
3767     image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
3768     conc_test.image_barrier_.image = image.handle();
3769 
3770     // New layout can't be UNDEFINED
3771     conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3772     conc_test("VUID-VkImageMemoryBarrier-newLayout-01198", "");
3773 
3774     // Transition image to color attachment optimal
3775     conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
3776     conc_test("");
3777 
3778     // TODO: this looks vestigal or incomplete...
3779     m_commandBuffer->begin();
3780     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
3781 
3782     // Can't send buffer memory barrier during a render pass
3783     vkCmdEndRenderPass(m_commandBuffer->handle());
3784 
3785     // Duplicate barriers that change layout
3786     VkImageMemoryBarrier img_barrier = {};
3787     img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3788     img_barrier.pNext = NULL;
3789     img_barrier.image = image.handle();
3790     img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3791     img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3792     img_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
3793     img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
3794     img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
3795     img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
3796     img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3797     img_barrier.subresourceRange.baseArrayLayer = 0;
3798     img_barrier.subresourceRange.baseMipLevel = 0;
3799     img_barrier.subresourceRange.layerCount = 1;
3800     img_barrier.subresourceRange.levelCount = 1;
3801     VkImageMemoryBarrier img_barriers[2] = {img_barrier, img_barrier};
3802 
3803     // Transitions from UNDEFINED  are valid, even if duplicated
3804     m_errorMonitor->ExpectSuccess();
3805     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3806                          VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 2,
3807                          img_barriers);
3808     m_errorMonitor->VerifyNotFound();
3809 
3810     // Duplication of layout transitions (not from undefined) are not valid
3811     img_barriers[0].oldLayout = VK_IMAGE_LAYOUT_GENERAL;
3812     img_barriers[0].newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
3813     img_barriers[1].oldLayout = img_barriers[0].oldLayout;
3814     img_barriers[1].newLayout = img_barriers[0].newLayout;
3815     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-oldLayout-01197");
3816     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3817                          VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 2,
3818                          img_barriers);
3819     m_errorMonitor->VerifyFound();
3820 
3821     // Exceed the buffer size
3822     conc_test.buffer_barrier_.offset = conc_test.buffer_.create_info().size + 1;
3823     conc_test("", "VUID-VkBufferMemoryBarrier-offset-01187");
3824 
3825     conc_test.buffer_barrier_.offset = 0;
3826     conc_test.buffer_barrier_.size = conc_test.buffer_.create_info().size + 1;
3827     // Size greater than total size
3828     conc_test("", "VUID-VkBufferMemoryBarrier-size-01189");
3829 
3830     conc_test.buffer_barrier_.size = VK_WHOLE_SIZE;
3831 
3832     // Now exercise barrier aspect bit errors, first DS
3833     VkDepthStencilObj ds_image(m_device);
3834     ds_image.Init(m_device, 128, 128, depth_format);
3835     ASSERT_TRUE(ds_image.initialized());
3836 
3837     conc_test.image_barrier_.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3838     conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3839     conc_test.image_barrier_.image = ds_image.handle();
3840 
3841     // Not having DEPTH or STENCIL set is an error
3842     conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
3843 
3844     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageSubresource-aspectMask-parameter");
3845     conc_test("VUID-VkImageMemoryBarrier-image-01207");
3846 
3847     // Having only one of depth or stencil set for DS image is an error
3848     conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
3849     conc_test("VUID-VkImageMemoryBarrier-image-01207");
3850 
3851     // Having anything other than DEPTH and STENCIL is an error
3852     conc_test.image_barrier_.subresourceRange.aspectMask =
3853         VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
3854     conc_test("VUID-VkImageSubresource-aspectMask-parameter");
3855 
3856     // Now test depth-only
3857     VkFormatProperties format_props;
3858     vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
3859     if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
3860         VkDepthStencilObj d_image(m_device);
3861         d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
3862         ASSERT_TRUE(d_image.initialized());
3863 
3864         conc_test.image_barrier_.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3865         conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3866         conc_test.image_barrier_.image = d_image.handle();
3867 
3868         // DEPTH bit must be set
3869         conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
3870         conc_test("Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
3871 
3872         // No bits other than DEPTH may be set
3873         conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
3874         conc_test("Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
3875     }
3876 
3877     // Now test stencil-only
3878     vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
3879     if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
3880         VkDepthStencilObj s_image(m_device);
3881         s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
3882         ASSERT_TRUE(s_image.initialized());
3883 
3884         conc_test.image_barrier_.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3885         conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3886         conc_test.image_barrier_.image = s_image.handle();
3887 
3888         // Use of COLOR aspect on depth image is error
3889         conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3890         conc_test("Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
3891     }
3892 
3893     // Finally test color
3894     VkImageObj c_image(m_device);
3895     c_image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
3896     ASSERT_TRUE(c_image.initialized());
3897     conc_test.image_barrier_.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
3898     conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3899     conc_test.image_barrier_.image = c_image.handle();
3900 
3901     // COLOR bit must be set
3902     conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
3903     conc_test("Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
3904 
3905     // No bits other than COLOR may be set
3906     conc_test.image_barrier_.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
3907     conc_test("Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
3908 
3909     // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
3910     {
3911         VkImageObj img_color(m_device);
3912         img_color.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
3913         ASSERT_TRUE(img_color.initialized());
3914 
3915         VkImageObj img_ds(m_device);
3916         img_ds.Init(128, 128, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
3917         ASSERT_TRUE(img_ds.initialized());
3918 
3919         VkImageObj img_xfer_src(m_device);
3920         img_xfer_src.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
3921         ASSERT_TRUE(img_xfer_src.initialized());
3922 
3923         VkImageObj img_xfer_dst(m_device);
3924         img_xfer_dst.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
3925         ASSERT_TRUE(img_xfer_dst.initialized());
3926 
3927         VkImageObj img_sampled(m_device);
3928         img_sampled.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
3929         ASSERT_TRUE(img_sampled.initialized());
3930 
3931         VkImageObj img_input(m_device);
3932         img_input.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
3933         ASSERT_TRUE(img_input.initialized());
3934 
3935         const struct {
3936             VkImageObj &image_obj;
3937             VkImageLayout bad_layout;
3938             std::string msg_code;
3939         } bad_buffer_layouts[] = {
3940             // clang-format off
3941             // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
3942             {img_ds,       VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01208"},
3943             {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01208"},
3944             {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01208"},
3945             {img_sampled,  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01208"},
3946             {img_input,    VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01208"},
3947             // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
3948             {img_color,    VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "VUID-VkImageMemoryBarrier-oldLayout-01209"},
3949             {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "VUID-VkImageMemoryBarrier-oldLayout-01209"},
3950             {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "VUID-VkImageMemoryBarrier-oldLayout-01209"},
3951             {img_sampled,  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "VUID-VkImageMemoryBarrier-oldLayout-01209"},
3952             {img_input,    VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, "VUID-VkImageMemoryBarrier-oldLayout-01209"},
3953             {img_color,    VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,  "VUID-VkImageMemoryBarrier-oldLayout-01210"},
3954             {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,  "VUID-VkImageMemoryBarrier-oldLayout-01210"},
3955             {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,  "VUID-VkImageMemoryBarrier-oldLayout-01210"},
3956             {img_sampled,  VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,  "VUID-VkImageMemoryBarrier-oldLayout-01210"},
3957             {img_input,    VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,  "VUID-VkImageMemoryBarrier-oldLayout-01210"},
3958             // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
3959             {img_color,    VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01211"},
3960             {img_ds,       VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01211"},
3961             {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01211"},
3962             {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,         "VUID-VkImageMemoryBarrier-oldLayout-01211"},
3963             // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
3964             {img_color,    VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01212"},
3965             {img_ds,       VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01212"},
3966             {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01212"},
3967             {img_sampled,  VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01212"},
3968             {img_input,    VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01212"},
3969             // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
3970             {img_color,    VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01213"},
3971             {img_ds,       VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01213"},
3972             {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01213"},
3973             {img_sampled,  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01213"},
3974             {img_input,    VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,             "VUID-VkImageMemoryBarrier-oldLayout-01213"},
3975             // clang-format on
3976         };
3977         const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
3978 
3979         for (uint32_t i = 0; i < layout_count; ++i) {
3980             conc_test.image_barrier_.image = bad_buffer_layouts[i].image_obj.handle();
3981             const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
3982             conc_test.image_barrier_.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
3983                                                                        ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
3984                                                                        : VK_IMAGE_ASPECT_COLOR_BIT;
3985 
3986             conc_test.image_barrier_.oldLayout = bad_buffer_layouts[i].bad_layout;
3987             conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3988             conc_test(bad_buffer_layouts[i].msg_code);
3989 
3990             conc_test.image_barrier_.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
3991             conc_test.image_barrier_.newLayout = bad_buffer_layouts[i].bad_layout;
3992             conc_test(bad_buffer_layouts[i].msg_code);
3993         }
3994 
3995         conc_test.image_barrier_.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
3996         conc_test.image_barrier_.newLayout = VK_IMAGE_LAYOUT_GENERAL;
3997         conc_test.image_barrier_.image = image.handle();
3998     }
3999 
4000     // Attempt barrier where srcAccessMask is not supported by srcStageMask
4001     // Have lower-order bit that's supported (shader write), but higher-order bit not supported to verify multi-bit validation
4002     conc_test.buffer_barrier_.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
4003     conc_test.buffer_barrier_.offset = 0;
4004     conc_test.buffer_barrier_.size = VK_WHOLE_SIZE;
4005     conc_test("", "VUID-vkCmdPipelineBarrier-pMemoryBarriers-01184");
4006 
4007     // Attempt barrier where dstAccessMask is not supported by dstStageMask
4008     conc_test.buffer_barrier_.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
4009     conc_test.buffer_barrier_.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
4010     conc_test("", "VUID-vkCmdPipelineBarrier-pMemoryBarriers-01185");
4011 
4012     // Attempt to mismatch barriers/waitEvents calls with incompatible queues
4013     // Create command pool with incompatible queueflags
4014     const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
4015     uint32_t queue_family_index = m_device->QueueFamilyMatching(VK_QUEUE_GRAPHICS_BIT, VK_QUEUE_COMPUTE_BIT);
4016     if (queue_family_index == UINT32_MAX) {
4017         printf("%s No non-compute queue supporting graphics found; skipped.\n", kSkipPrefix);
4018         return;  // NOTE: this exits the test function!
4019     }
4020 
4021     VkBufferMemoryBarrier buf_barrier = {};
4022     buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
4023     buf_barrier.pNext = NULL;
4024     buf_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
4025     buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4026     buf_barrier.buffer = buffer.handle();
4027     buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
4028     buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
4029     buf_barrier.offset = 0;
4030     buf_barrier.size = VK_WHOLE_SIZE;
4031 
4032     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdPipelineBarrier-srcStageMask-01183");
4033 
4034     VkCommandPoolObj command_pool(m_device, queue_family_index, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
4035     VkCommandBufferObj bad_command_buffer(m_device, &command_pool);
4036 
4037     bad_command_buffer.begin();
4038     buf_barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
4039     // Set two bits that should both be supported as a bonus positive check
4040     buf_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT;
4041     vkCmdPipelineBarrier(bad_command_buffer.handle(), VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
4042                          VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 1, &buf_barrier, 0, nullptr);
4043     m_errorMonitor->VerifyFound();
4044 
4045     // Check for error for trying to wait on pipeline stage not supported by this queue. Specifically since our queue is not a
4046     // compute queue, vkCmdWaitEvents cannot have it's source stage mask be VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
4047     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdWaitEvents-srcStageMask-01164");
4048     VkEvent event;
4049     VkEventCreateInfo event_create_info{};
4050     event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4051     vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4052     vkCmdWaitEvents(bad_command_buffer.handle(), 1, &event, /*source stage mask*/ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
4053                     VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0, nullptr, 0, nullptr);
4054     m_errorMonitor->VerifyFound();
4055     bad_command_buffer.end();
4056 
4057     vkDestroyEvent(m_device->device(), event, nullptr);
4058 }
4059 
TEST_F(VkLayerTest,InvalidBarrierQueueFamily)4060 TEST_F(VkLayerTest, InvalidBarrierQueueFamily) {
4061     TEST_DESCRIPTION("Create and submit barriers with invalid queue families");
4062     ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
4063 
4064     // Find queues of two families
4065     const uint32_t submit_family = m_device->graphics_queue_node_index_;
4066     const uint32_t invalid = static_cast<uint32_t>(m_device->queue_props.size());
4067     const uint32_t other_family = submit_family != 0 ? 0 : 1;
4068     const bool only_one_family = (invalid == 1) || (m_device->queue_props[other_family].queueCount == 0);
4069 
4070     std::vector<uint32_t> qf_indices{{submit_family, other_family}};
4071     if (only_one_family) {
4072         qf_indices.resize(1);
4073     }
4074     BarrierQueueFamilyTestHelper::Context test_context(this, qf_indices);
4075 
4076     if (m_device->props.apiVersion >= VK_API_VERSION_1_1) {
4077         printf(
4078             "%s Device has apiVersion greater than 1.0 -- skipping test cases that require external memory "
4079             "to be "
4080             "disabled.\n",
4081             kSkipPrefix);
4082     } else {
4083         if (only_one_family) {
4084             printf("%s Single queue family found -- VK_SHARING_MODE_CONCURRENT testcases skipped.\n", kSkipPrefix);
4085         } else {
4086             std::vector<uint32_t> families = {submit_family, other_family};
4087             BarrierQueueFamilyTestHelper conc_test(&test_context);
4088             conc_test.Init(&families);
4089             // core_validation::barrier_queue_families::kSrcAndDestMustBeIgnore
4090             conc_test("VUID-VkImageMemoryBarrier-image-01199", "VUID-VkBufferMemoryBarrier-buffer-01190", VK_QUEUE_FAMILY_IGNORED,
4091                       submit_family);
4092             conc_test("VUID-VkImageMemoryBarrier-image-01199", "VUID-VkBufferMemoryBarrier-buffer-01190", submit_family,
4093                       VK_QUEUE_FAMILY_IGNORED);
4094             conc_test("VUID-VkImageMemoryBarrier-image-01199", "VUID-VkBufferMemoryBarrier-buffer-01190", submit_family,
4095                       submit_family);
4096             // true -> positive test
4097             conc_test("VUID-VkImageMemoryBarrier-image-01199", "VUID-VkBufferMemoryBarrier-buffer-01190", VK_QUEUE_FAMILY_IGNORED,
4098                       VK_QUEUE_FAMILY_IGNORED, true);
4099         }
4100 
4101         BarrierQueueFamilyTestHelper excl_test(&test_context);
4102         excl_test.Init(nullptr);  // no queue families means *exclusive* sharing mode.
4103 
4104         // core_validation::barrier_queue_families::kBothIgnoreOrBothValid
4105         excl_test("VUID-VkImageMemoryBarrier-image-01200", "VUID-VkBufferMemoryBarrier-buffer-01192", VK_QUEUE_FAMILY_IGNORED,
4106                   submit_family);
4107         excl_test("VUID-VkImageMemoryBarrier-image-01200", "VUID-VkBufferMemoryBarrier-buffer-01192", submit_family,
4108                   VK_QUEUE_FAMILY_IGNORED);
4109         // true -> positive test
4110         excl_test("VUID-VkImageMemoryBarrier-image-01200", "VUID-VkBufferMemoryBarrier-buffer-01192", submit_family, submit_family,
4111                   true);
4112         excl_test("VUID-VkImageMemoryBarrier-image-01200", "VUID-VkBufferMemoryBarrier-buffer-01192", VK_QUEUE_FAMILY_IGNORED,
4113                   VK_QUEUE_FAMILY_IGNORED, true);
4114     }
4115 
4116     if (only_one_family) {
4117         printf("%s Single queue family found -- VK_SHARING_MODE_EXCLUSIVE submit testcases skipped.\n", kSkipPrefix);
4118     } else {
4119         BarrierQueueFamilyTestHelper excl_test(&test_context);
4120         excl_test.Init(nullptr);
4121 
4122         // core_validation::barrier_queue_families::kSubmitQueueMustMatchSrcOrDst
4123         excl_test("VUID-VkImageMemoryBarrier-image-01205", "VUID-VkBufferMemoryBarrier-buffer-01196", other_family, other_family,
4124                   false, submit_family);
4125 
4126         // true -> positive test (testing both the index logic and the QFO transfer tracking.
4127         excl_test("POSITIVE_TEST", "POSITIVE_TEST", submit_family, other_family, true, submit_family);
4128         excl_test("POSITIVE_TEST", "POSITIVE_TEST", submit_family, other_family, true, other_family);
4129         excl_test("POSITIVE_TEST", "POSITIVE_TEST", other_family, submit_family, true, other_family);
4130         excl_test("POSITIVE_TEST", "POSITIVE_TEST", other_family, submit_family, true, submit_family);
4131 
4132         // negative testing for QFO transfer tracking
4133         // Duplicate release in one CB
4134         excl_test("UNASSIGNED-VkImageMemoryBarrier-image-00001", "UNASSIGNED-VkBufferMemoryBarrier-buffer-00001", submit_family,
4135                   other_family, false, submit_family, BarrierQueueFamilyTestHelper::DOUBLE_RECORD);
4136         // Duplicate pending release
4137         excl_test("UNASSIGNED-VkImageMemoryBarrier-image-00003", "UNASSIGNED-VkBufferMemoryBarrier-buffer-00003", submit_family,
4138                   other_family, false, submit_family);
4139         // Duplicate acquire in one CB
4140         excl_test("UNASSIGNED-VkImageMemoryBarrier-image-00001", "UNASSIGNED-VkBufferMemoryBarrier-buffer-00001", submit_family,
4141                   other_family, false, other_family, BarrierQueueFamilyTestHelper::DOUBLE_RECORD);
4142         // No pending release
4143         excl_test("UNASSIGNED-VkImageMemoryBarrier-image-00004", "UNASSIGNED-VkBufferMemoryBarrier-buffer-00004", submit_family,
4144                   other_family, false, other_family);
4145         // Duplicate release in two CB
4146         excl_test("UNASSIGNED-VkImageMemoryBarrier-image-00002", "UNASSIGNED-VkBufferMemoryBarrier-buffer-00002", submit_family,
4147                   other_family, false, submit_family, BarrierQueueFamilyTestHelper::DOUBLE_COMMAND_BUFFER);
4148         // Duplicate acquire in two CB
4149         excl_test("POSITIVE_TEST", "POSITIVE_TEST", submit_family, other_family, true, submit_family);  // need a succesful release
4150         excl_test("UNASSIGNED-VkImageMemoryBarrier-image-00002", "UNASSIGNED-VkBufferMemoryBarrier-buffer-00002", submit_family,
4151                   other_family, false, other_family, BarrierQueueFamilyTestHelper::DOUBLE_COMMAND_BUFFER);
4152     }
4153 }
4154 
TEST_F(VkLayerTest,InvalidBarrierQueueFamilyWithMemExt)4155 TEST_F(VkLayerTest, InvalidBarrierQueueFamilyWithMemExt) {
4156     TEST_DESCRIPTION("Create and submit barriers with invalid queue families when memory extension is enabled ");
4157     std::vector<const char *> reqd_instance_extensions = {
4158         {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME}};
4159     for (auto extension_name : reqd_instance_extensions) {
4160         if (InstanceExtensionSupported(extension_name)) {
4161             m_instance_extension_names.push_back(extension_name);
4162         } else {
4163             printf("%s Required instance extension %s not supported, skipping test\n", kSkipPrefix, extension_name);
4164             return;
4165         }
4166     }
4167 
4168     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
4169     // Check for external memory device extensions
4170     if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME)) {
4171         m_device_extension_names.push_back(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME);
4172     } else {
4173         printf("%s External memory extension not supported, skipping test\n", kSkipPrefix);
4174         return;
4175     }
4176 
4177     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
4178 
4179     // Find queues of two families
4180     const uint32_t submit_family = m_device->graphics_queue_node_index_;
4181     const uint32_t invalid = static_cast<uint32_t>(m_device->queue_props.size());
4182     const uint32_t other_family = submit_family != 0 ? 0 : 1;
4183     const bool only_one_family = (invalid == 1) || (m_device->queue_props[other_family].queueCount == 0);
4184 
4185     std::vector<uint32_t> qf_indices{{submit_family, other_family}};
4186     if (only_one_family) {
4187         qf_indices.resize(1);
4188     }
4189     BarrierQueueFamilyTestHelper::Context test_context(this, qf_indices);
4190 
4191     if (only_one_family) {
4192         printf("%s Single queue family found -- VK_SHARING_MODE_CONCURRENT testcases skipped.\n", kSkipPrefix);
4193     } else {
4194         std::vector<uint32_t> families = {submit_family, other_family};
4195         BarrierQueueFamilyTestHelper conc_test(&test_context);
4196 
4197         // core_validation::barrier_queue_families::kSrcOrDstMustBeIgnore
4198         conc_test.Init(&families);
4199         conc_test("VUID-VkImageMemoryBarrier-image-01381", "VUID-VkBufferMemoryBarrier-buffer-01191", submit_family, submit_family);
4200         // true -> positive test
4201         conc_test("VUID-VkImageMemoryBarrier-image-01381", "VUID-VkBufferMemoryBarrier-buffer-01191", VK_QUEUE_FAMILY_IGNORED,
4202                   VK_QUEUE_FAMILY_IGNORED, true);
4203         conc_test("VUID-VkImageMemoryBarrier-image-01381", "VUID-VkBufferMemoryBarrier-buffer-01191", VK_QUEUE_FAMILY_IGNORED,
4204                   VK_QUEUE_FAMILY_EXTERNAL_KHR, true);
4205         conc_test("VUID-VkImageMemoryBarrier-image-01381", "VUID-VkBufferMemoryBarrier-buffer-01191", VK_QUEUE_FAMILY_EXTERNAL_KHR,
4206                   VK_QUEUE_FAMILY_IGNORED, true);
4207 
4208         // core_validation::barrier_queue_families::kSpecialOrIgnoreOnly
4209         conc_test("VUID-VkImageMemoryBarrier-image-01766", "VUID-VkBufferMemoryBarrier-buffer-01763", submit_family,
4210                   VK_QUEUE_FAMILY_IGNORED);
4211         conc_test("VUID-VkImageMemoryBarrier-image-01766", "VUID-VkBufferMemoryBarrier-buffer-01763", VK_QUEUE_FAMILY_IGNORED,
4212                   submit_family);
4213         // This is to flag the errors that would be considered only "unexpected" in the parallel case above
4214         // true -> positive test
4215         conc_test("VUID-VkImageMemoryBarrier-image-01766", "VUID-VkBufferMemoryBarrier-buffer-01763", VK_QUEUE_FAMILY_IGNORED,
4216                   VK_QUEUE_FAMILY_EXTERNAL_KHR, true);
4217         conc_test("VUID-VkImageMemoryBarrier-image-01766", "VUID-VkBufferMemoryBarrier-buffer-01763", VK_QUEUE_FAMILY_EXTERNAL_KHR,
4218                   VK_QUEUE_FAMILY_IGNORED, true);
4219     }
4220 
4221     BarrierQueueFamilyTestHelper excl_test(&test_context);
4222     excl_test.Init(nullptr);  // no queue families means *exclusive* sharing mode.
4223 
4224     // core_validation::barrier_queue_families::kSrcIgnoreRequiresDstIgnore
4225     excl_test("VUID-VkImageMemoryBarrier-image-01201", "VUID-VkBufferMemoryBarrier-buffer-01193", VK_QUEUE_FAMILY_IGNORED,
4226               submit_family);
4227     excl_test("VUID-VkImageMemoryBarrier-image-01201", "VUID-VkBufferMemoryBarrier-buffer-01193", VK_QUEUE_FAMILY_IGNORED,
4228               VK_QUEUE_FAMILY_EXTERNAL_KHR);
4229     // true -> positive test
4230     excl_test("VUID-VkImageMemoryBarrier-image-01201", "VUID-VkBufferMemoryBarrier-buffer-01193", VK_QUEUE_FAMILY_IGNORED,
4231               VK_QUEUE_FAMILY_IGNORED, true);
4232 
4233     // core_validation::barrier_queue_families::kDstValidOrSpecialIfNotIgnore
4234     excl_test("VUID-VkImageMemoryBarrier-image-01768", "VUID-VkBufferMemoryBarrier-buffer-01765", submit_family, invalid);
4235     // true -> positive test
4236     excl_test("VUID-VkImageMemoryBarrier-image-01768", "VUID-VkBufferMemoryBarrier-buffer-01765", submit_family, submit_family,
4237               true);
4238     excl_test("VUID-VkImageMemoryBarrier-image-01768", "VUID-VkBufferMemoryBarrier-buffer-01765", submit_family,
4239               VK_QUEUE_FAMILY_IGNORED, true);
4240     excl_test("VUID-VkImageMemoryBarrier-image-01768", "VUID-VkBufferMemoryBarrier-buffer-01765", submit_family,
4241               VK_QUEUE_FAMILY_EXTERNAL_KHR, true);
4242 
4243     // core_validation::barrier_queue_families::kSrcValidOrSpecialIfNotIgnore
4244     excl_test("VUID-VkImageMemoryBarrier-image-01767", "VUID-VkBufferMemoryBarrier-buffer-01764", invalid, submit_family);
4245     // true -> positive test
4246     excl_test("VUID-VkImageMemoryBarrier-image-01767", "VUID-VkBufferMemoryBarrier-buffer-01764", submit_family, submit_family,
4247               true);
4248     excl_test("VUID-VkImageMemoryBarrier-image-01767", "VUID-VkBufferMemoryBarrier-buffer-01764", VK_QUEUE_FAMILY_IGNORED,
4249               VK_QUEUE_FAMILY_IGNORED, true);
4250     excl_test("VUID-VkImageMemoryBarrier-image-01767", "VUID-VkBufferMemoryBarrier-buffer-01764", VK_QUEUE_FAMILY_EXTERNAL_KHR,
4251               submit_family, true);
4252 }
4253 
TEST_F(VkLayerTest,ImageBarrierWithBadRange)4254 TEST_F(VkLayerTest, ImageBarrierWithBadRange) {
4255     TEST_DESCRIPTION("VkImageMemoryBarrier with an invalid subresourceRange");
4256 
4257     ASSERT_NO_FATAL_FAILURE(Init());
4258     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4259 
4260     VkImageMemoryBarrier img_barrier_template = {};
4261     img_barrier_template.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4262     img_barrier_template.pNext = NULL;
4263     img_barrier_template.srcAccessMask = 0;
4264     img_barrier_template.dstAccessMask = 0;
4265     img_barrier_template.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4266     img_barrier_template.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
4267     img_barrier_template.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
4268     img_barrier_template.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
4269     // subresourceRange to be set later for the for the purposes of this test
4270     img_barrier_template.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4271     img_barrier_template.subresourceRange.baseArrayLayer = 0;
4272     img_barrier_template.subresourceRange.baseMipLevel = 0;
4273     img_barrier_template.subresourceRange.layerCount = 0;
4274     img_barrier_template.subresourceRange.levelCount = 0;
4275 
4276     const uint32_t submit_family = m_device->graphics_queue_node_index_;
4277     const uint32_t invalid = static_cast<uint32_t>(m_device->queue_props.size());
4278     const uint32_t other_family = submit_family != 0 ? 0 : 1;
4279     const bool only_one_family = (invalid == 1) || (m_device->queue_props[other_family].queueCount == 0);
4280     std::vector<uint32_t> qf_indices{{submit_family, other_family}};
4281     if (only_one_family) {
4282         qf_indices.resize(1);
4283     }
4284     BarrierQueueFamilyTestHelper::Context test_context(this, qf_indices);
4285 
4286     // Use image unbound to memory in barrier
4287     // Use buffer unbound to memory in barrier
4288     BarrierQueueFamilyTestHelper conc_test(&test_context);
4289     conc_test.Init(nullptr);
4290     img_barrier_template.image = conc_test.image_.handle();
4291     conc_test.image_barrier_ = img_barrier_template;
4292     // Nested scope here confuses clang-format, somehow
4293     // clang-format off
4294 
4295     // try for vkCmdPipelineBarrier
4296     {
4297         // Try baseMipLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
4298         {
4299             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
4300             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01486");
4301         }
4302 
4303         // Try baseMipLevel >= image.mipLevels without VK_REMAINING_MIP_LEVELS
4304         {
4305             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
4306             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01724");
4307             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01486");
4308         }
4309 
4310         // Try levelCount = 0
4311         {
4312             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
4313             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01724");
4314         }
4315 
4316         // Try baseMipLevel + levelCount > image.mipLevels
4317         {
4318             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 2, 0, 1};
4319             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01724");
4320         }
4321 
4322         // Try baseArrayLayer >= image.arrayLayers with VK_REMAINING_ARRAY_LAYERS
4323         {
4324             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
4325             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01488");
4326         }
4327 
4328         // Try baseArrayLayer >= image.arrayLayers without VK_REMAINING_ARRAY_LAYERS
4329         {
4330             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
4331             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01725");
4332             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01488");
4333         }
4334 
4335         // Try layerCount = 0
4336         {
4337             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
4338             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01725");
4339         }
4340 
4341         // Try baseArrayLayer + layerCount > image.arrayLayers
4342         {
4343             conc_test.image_barrier_.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2};
4344             conc_test("VUID-VkImageMemoryBarrier-subresourceRange-01725");
4345         }
4346     }
4347 
4348     m_commandBuffer->begin();
4349     // try for vkCmdWaitEvents
4350     {
4351         VkEvent event;
4352         VkEventCreateInfo eci{VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, NULL, 0};
4353         VkResult err = vkCreateEvent(m_device->handle(), &eci, nullptr, &event);
4354         ASSERT_VK_SUCCESS(err);
4355 
4356         // Try baseMipLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
4357         {
4358             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01486");
4359             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
4360             VkImageMemoryBarrier img_barrier = img_barrier_template;
4361             img_barrier.subresourceRange = range;
4362             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4363                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4364             m_errorMonitor->VerifyFound();
4365         }
4366 
4367         // Try baseMipLevel >= image.mipLevels without VK_REMAINING_MIP_LEVELS
4368         {
4369             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01486");
4370             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01724");
4371             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
4372             VkImageMemoryBarrier img_barrier = img_barrier_template;
4373             img_barrier.subresourceRange = range;
4374             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4375                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4376             m_errorMonitor->VerifyFound();
4377         }
4378 
4379         // Try levelCount = 0
4380         {
4381             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01724");
4382             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
4383             VkImageMemoryBarrier img_barrier = img_barrier_template;
4384             img_barrier.subresourceRange = range;
4385             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4386                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4387             m_errorMonitor->VerifyFound();
4388         }
4389 
4390         // Try baseMipLevel + levelCount > image.mipLevels
4391         {
4392             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01724");
4393             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 2, 0, 1};
4394             VkImageMemoryBarrier img_barrier = img_barrier_template;
4395             img_barrier.subresourceRange = range;
4396             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4397                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4398             m_errorMonitor->VerifyFound();
4399         }
4400 
4401         // Try baseArrayLayer >= image.arrayLayers with VK_REMAINING_ARRAY_LAYERS
4402         {
4403             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01488");
4404             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
4405             VkImageMemoryBarrier img_barrier = img_barrier_template;
4406             img_barrier.subresourceRange = range;
4407             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4408                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4409             m_errorMonitor->VerifyFound();
4410         }
4411 
4412         // Try baseArrayLayer >= image.arrayLayers without VK_REMAINING_ARRAY_LAYERS
4413         {
4414             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01488");
4415             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01725");
4416             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
4417             VkImageMemoryBarrier img_barrier = img_barrier_template;
4418             img_barrier.subresourceRange = range;
4419             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4420                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4421             m_errorMonitor->VerifyFound();
4422         }
4423 
4424         // Try layerCount = 0
4425         {
4426             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01725");
4427             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
4428             VkImageMemoryBarrier img_barrier = img_barrier_template;
4429             img_barrier.subresourceRange = range;
4430             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4431                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4432             m_errorMonitor->VerifyFound();
4433         }
4434 
4435         // Try baseArrayLayer + layerCount > image.arrayLayers
4436         {
4437             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-subresourceRange-01725");
4438             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2};
4439             VkImageMemoryBarrier img_barrier = img_barrier_template;
4440             img_barrier.subresourceRange = range;
4441             vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4442                             VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 1, &img_barrier);
4443             m_errorMonitor->VerifyFound();
4444         }
4445 
4446         vkDestroyEvent(m_device->handle(), event, nullptr);
4447     }
4448     // clang-format on
4449 }
4450 
TEST_F(VkLayerTest,IdxBufferAlignmentError)4451 TEST_F(VkLayerTest, IdxBufferAlignmentError) {
4452     // Bind a BeginRenderPass within an active RenderPass
4453     ASSERT_NO_FATAL_FAILURE(Init());
4454     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4455 
4456     uint32_t const indices[] = {0};
4457     VkBufferCreateInfo buf_info = {};
4458     buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4459     buf_info.size = 1024;
4460     buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
4461     buf_info.queueFamilyIndexCount = 1;
4462     buf_info.pQueueFamilyIndices = indices;
4463 
4464     VkBufferObj buffer;
4465     buffer.init(*m_device, buf_info);
4466 
4467     m_commandBuffer->begin();
4468 
4469     // vkCmdBindPipeline(m_commandBuffer->handle(),
4470     // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4471     // Should error before calling to driver so don't care about actual data
4472     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
4473     vkCmdBindIndexBuffer(m_commandBuffer->handle(), buffer.handle(), 7, VK_INDEX_TYPE_UINT16);
4474     m_errorMonitor->VerifyFound();
4475 }
4476 
TEST_F(VkLayerTest,Bad2DArrayImageType)4477 TEST_F(VkLayerTest, Bad2DArrayImageType) {
4478     TEST_DESCRIPTION("Create an image with a flag specifying 2D_ARRAY_COMPATIBLE but not of imageType 3D.");
4479 
4480     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
4481     if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
4482         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
4483     } else {
4484         printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
4485         return;
4486     }
4487     ASSERT_NO_FATAL_FAILURE(InitState());
4488 
4489     // Trigger check by setting imagecreateflags to 2d_array_compat and imageType to 2D
4490     VkImageCreateInfo ici = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
4491                              nullptr,
4492                              VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR,
4493                              VK_IMAGE_TYPE_2D,
4494                              VK_FORMAT_R8G8B8A8_UNORM,
4495                              {32, 32, 1},
4496                              1,
4497                              1,
4498                              VK_SAMPLE_COUNT_1_BIT,
4499                              VK_IMAGE_TILING_OPTIMAL,
4500                              VK_IMAGE_USAGE_SAMPLED_BIT,
4501                              VK_SHARING_MODE_EXCLUSIVE,
4502                              0,
4503                              nullptr,
4504                              VK_IMAGE_LAYOUT_UNDEFINED};
4505     CreateImageTest(*this, &ici, "VUID-VkImageCreateInfo-flags-00950");
4506 }
4507 
TEST_F(VkLayerTest,VertexBufferInvalid)4508 TEST_F(VkLayerTest, VertexBufferInvalid) {
4509     TEST_DESCRIPTION(
4510         "Submit a command buffer using deleted vertex buffer, delete a buffer twice, use an invalid offset for each buffer type, "
4511         "and attempt to bind a null buffer");
4512 
4513     ASSERT_NO_FATAL_FAILURE(Init());
4514     ASSERT_NO_FATAL_FAILURE(InitViewport());
4515     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4516 
4517     CreatePipelineHelper pipe(*this);
4518     pipe.InitInfo();
4519     pipe.InitState();
4520     pipe.CreateGraphicsPipeline();
4521 
4522     m_commandBuffer->begin();
4523     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4524     vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
4525     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CoreValidation-DrawState-InvalidCommandBuffer-VkBuffer");
4526     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4527                                          "CoreValidation-DrawState-InvalidCommandBuffer-VkDeviceMemory");
4528 
4529     {
4530         // Create and bind a vertex buffer in a reduced scope, which will cause it to be deleted upon leaving this scope
4531         const float vbo_data[3] = {1.f, 0.f, 1.f};
4532         VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data[0]), sizeof(vbo_data) / sizeof(vbo_data[0]), vbo_data);
4533         draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
4534         draw_verticies.AddVertexInputToPipeHelpr(&pipe);
4535 
4536         m_commandBuffer->Draw(1, 0, 0, 0);
4537 
4538         m_commandBuffer->EndRenderPass();
4539     }
4540 
4541     vkEndCommandBuffer(m_commandBuffer->handle());
4542     m_errorMonitor->VerifyFound();
4543 
4544     {
4545         // Create and bind a vertex buffer in a reduced scope, and delete it
4546         // twice, the second through the destructor
4547         VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
4548         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkDestroyBuffer-buffer-parameter");
4549         buffer_test.TestDoubleDestroy();
4550     }
4551     m_errorMonitor->VerifyFound();
4552 
4553     m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
4554     if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
4555         // Create and bind a memory buffer with an invalid offset.
4556         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-memoryOffset-01036");
4557         m_errorMonitor->SetUnexpectedError(
4558             "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
4559             "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
4560         VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
4561         (void)buffer_test;
4562         m_errorMonitor->VerifyFound();
4563     }
4564 
4565     {
4566         // Attempt to bind a null buffer.
4567         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4568                                              "vkBindBufferMemory: required parameter buffer specified as VK_NULL_HANDLE");
4569         VkBufferTest buffer_test(m_device, 0, VkBufferTest::eBindNullBuffer);
4570         (void)buffer_test;
4571         m_errorMonitor->VerifyFound();
4572     }
4573 
4574     {
4575         // Attempt to bind a fake buffer.
4576         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-buffer-parameter");
4577         VkBufferTest buffer_test(m_device, 0, VkBufferTest::eBindFakeBuffer);
4578         (void)buffer_test;
4579         m_errorMonitor->VerifyFound();
4580     }
4581 
4582     {
4583         // Attempt to use an invalid handle to delete a buffer.
4584         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkFreeMemory-memory-parameter");
4585         VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
4586         (void)buffer_test;
4587     }
4588     m_errorMonitor->VerifyFound();
4589 }
4590 
TEST_F(VkLayerTest,BadVertexBufferOffset)4591 TEST_F(VkLayerTest, BadVertexBufferOffset) {
4592     TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
4593 
4594     ASSERT_NO_FATAL_FAILURE(Init());
4595     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4596     static const float vbo_data[3] = {1.f, 0.f, 1.f};
4597     VkConstantBufferObj vbo(m_device, sizeof(vbo_data), (const void *)&vbo_data, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
4598     m_commandBuffer->begin();
4599     m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4600     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdBindVertexBuffers-pOffsets-00626");
4601     m_commandBuffer->BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1);  // Offset at the end of the buffer
4602     m_errorMonitor->VerifyFound();
4603 
4604     m_commandBuffer->EndRenderPass();
4605     m_commandBuffer->end();
4606 }
4607 
4608 // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
TEST_F(VkLayerTest,InvalidImageLayout)4609 TEST_F(VkLayerTest, InvalidImageLayout) {
4610     TEST_DESCRIPTION(
4611         "Hit all possible validation checks associated with the UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout error. "
4612         "Generally these involve having images in the wrong layout when they're copied or transitioned.");
4613     // 3 in ValidateCmdBufImageLayouts
4614     // *  -1 Attempt to submit cmd buf w/ deleted image
4615     // *  -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
4616     // *  -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
4617 
4618     ASSERT_NO_FATAL_FAILURE(Init());
4619     auto depth_format = FindSupportedDepthStencilFormat(gpu());
4620     if (!depth_format) {
4621         printf("%s No Depth + Stencil format found. Skipped.\n", kSkipPrefix);
4622         return;
4623     }
4624     // Create src & dst images to use for copy operations
4625     VkImageObj src_image(m_device);
4626     VkImageObj dst_image(m_device);
4627     VkImageObj depth_image(m_device);
4628 
4629     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4630     const int32_t tex_width = 32;
4631     const int32_t tex_height = 32;
4632 
4633     VkImageCreateInfo image_create_info = {};
4634     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4635     image_create_info.pNext = NULL;
4636     image_create_info.imageType = VK_IMAGE_TYPE_2D;
4637     image_create_info.format = tex_format;
4638     image_create_info.extent.width = tex_width;
4639     image_create_info.extent.height = tex_height;
4640     image_create_info.extent.depth = 1;
4641     image_create_info.mipLevels = 1;
4642     image_create_info.arrayLayers = 4;
4643     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4644     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4645     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4646     image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4647     image_create_info.flags = 0;
4648 
4649     src_image.init(&image_create_info);
4650 
4651     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4652     dst_image.init(&image_create_info);
4653 
4654     image_create_info.format = VK_FORMAT_D16_UNORM;
4655     image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4656     depth_image.init(&image_create_info);
4657 
4658     m_commandBuffer->begin();
4659     VkImageCopy copy_region;
4660     copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4661     copy_region.srcSubresource.mipLevel = 0;
4662     copy_region.srcSubresource.baseArrayLayer = 0;
4663     copy_region.srcSubresource.layerCount = 1;
4664     copy_region.srcOffset.x = 0;
4665     copy_region.srcOffset.y = 0;
4666     copy_region.srcOffset.z = 0;
4667     copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4668     copy_region.dstSubresource.mipLevel = 0;
4669     copy_region.dstSubresource.baseArrayLayer = 0;
4670     copy_region.dstSubresource.layerCount = 1;
4671     copy_region.dstOffset.x = 0;
4672     copy_region.dstOffset.y = 0;
4673     copy_region.dstOffset.z = 0;
4674     copy_region.extent.width = 1;
4675     copy_region.extent.height = 1;
4676     copy_region.extent.depth = 1;
4677 
4678     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4679                                          "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
4680     m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
4681 
4682     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_GENERAL, dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
4683                                &copy_region);
4684     m_errorMonitor->VerifyFound();
4685     // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
4686     // update layer state
4687     m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
4688     m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
4689     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_GENERAL, dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
4690                                &copy_region);
4691     // Now cause error due to src image layout changing
4692     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdCopyImage-srcImageLayout-00128");
4693     m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
4694     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_UNDEFINED, dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
4695                                &copy_region);
4696     m_errorMonitor->VerifyFound();
4697     // Final src error is due to bad layout type
4698     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdCopyImage-srcImageLayout-00129");
4699     m_errorMonitor->SetUnexpectedError(
4700         "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the previously used layout VK_IMAGE_LAYOUT_GENERAL.");
4701     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_UNDEFINED, dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
4702                                &copy_region);
4703     m_errorMonitor->VerifyFound();
4704     // Now verify same checks for dst
4705     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4706                                          "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
4707     m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
4708     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_GENERAL, dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
4709                                &copy_region);
4710     m_errorMonitor->VerifyFound();
4711     // Now cause error due to src image layout changing
4712     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdCopyImage-dstImageLayout-00133");
4713     m_errorMonitor->SetUnexpectedError(
4714         "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
4715     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_GENERAL, dst_image.handle(), VK_IMAGE_LAYOUT_UNDEFINED, 1,
4716                                &copy_region);
4717     m_errorMonitor->VerifyFound();
4718     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdCopyImage-dstImageLayout-00134");
4719     m_errorMonitor->SetUnexpectedError(
4720         "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the previously used layout VK_IMAGE_LAYOUT_GENERAL.");
4721     m_commandBuffer->CopyImage(src_image.handle(), VK_IMAGE_LAYOUT_GENERAL, dst_image.handle(), VK_IMAGE_LAYOUT_UNDEFINED, 1,
4722                                &copy_region);
4723     m_errorMonitor->VerifyFound();
4724 
4725     // Convert dst and depth images to TRANSFER_DST for subsequent tests
4726     VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
4727     transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4728     transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4729     transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4730     transfer_dst_image_barrier[0].srcAccessMask = 0;
4731     transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
4732     transfer_dst_image_barrier[0].image = dst_image.handle();
4733     transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
4734     transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
4735     transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4736     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
4737                          NULL, 0, NULL, 1, transfer_dst_image_barrier);
4738     transfer_dst_image_barrier[0].image = depth_image.handle();
4739     transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
4740     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
4741                          NULL, 0, NULL, 1, transfer_dst_image_barrier);
4742 
4743     // Cause errors due to clearing with invalid image layouts
4744     VkClearColorValue color_clear_value = {};
4745     VkImageSubresourceRange clear_range;
4746     clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4747     clear_range.baseMipLevel = 0;
4748     clear_range.baseArrayLayer = 0;
4749     clear_range.layerCount = 1;
4750     clear_range.levelCount = 1;
4751 
4752     // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
4753     // Since the image is currently not in UNDEFINED layout, this will emit two errors.
4754     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-imageLayout-00005");
4755     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-imageLayout-00004");
4756     m_commandBuffer->ClearColorImage(dst_image.handle(), VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
4757     m_errorMonitor->VerifyFound();
4758     // Fail due to provided layout not matching actual current layout for color clear.
4759     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearColorImage-imageLayout-00004");
4760     m_commandBuffer->ClearColorImage(dst_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
4761     m_errorMonitor->VerifyFound();
4762 
4763     VkClearDepthStencilValue depth_clear_value = {};
4764     clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
4765 
4766     // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
4767     // Since the image is currently not in UNDEFINED layout, this will emit two errors.
4768     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-imageLayout-00012");
4769     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-imageLayout-00011");
4770     m_commandBuffer->ClearDepthStencilImage(depth_image.handle(), VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
4771     m_errorMonitor->VerifyFound();
4772     // Fail due to provided layout not matching actual current layout for depth clear.
4773     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkCmdClearDepthStencilImage-imageLayout-00011");
4774     m_commandBuffer->ClearDepthStencilImage(depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
4775     m_errorMonitor->VerifyFound();
4776 
4777     // Now cause error due to bad image layout transition in PipelineBarrier
4778     VkImageMemoryBarrier image_barrier[1] = {};
4779     image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4780     image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
4781     image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4782     image_barrier[0].image = src_image.handle();
4783     image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
4784     image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
4785     image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4786     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-oldLayout-01197");
4787     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageMemoryBarrier-oldLayout-01210");
4788     vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
4789                          NULL, 0, NULL, 1, image_barrier);
4790     m_errorMonitor->VerifyFound();
4791 
4792     // Finally some layout errors at RenderPass create time
4793     // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
4794     VkAttachmentReference attach = {};
4795     // perf warning for GENERAL layout w/ non-DS input attachment
4796     attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4797     VkSubpassDescription subpass = {};
4798     subpass.inputAttachmentCount = 1;
4799     subpass.pInputAttachments = &attach;
4800     VkRenderPassCreateInfo rpci = {};
4801     rpci.subpassCount = 1;
4802     rpci.pSubpasses = &subpass;
4803     rpci.attachmentCount = 1;
4804     VkAttachmentDescription attach_desc = {};
4805     attach_desc.format = VK_FORMAT_UNDEFINED;
4806     attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4807     attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
4808     rpci.pAttachments = &attach_desc;
4809     rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4810     VkRenderPass rp;
4811     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4812                                          "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
4813     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4814     m_errorMonitor->VerifyFound();
4815     // error w/ non-general layout
4816     attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4817 
4818     m_errorMonitor->SetDesiredFailureMsg(
4819         VK_DEBUG_REPORT_ERROR_BIT_EXT,
4820         "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
4821     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4822     m_errorMonitor->VerifyFound();
4823     subpass.inputAttachmentCount = 0;
4824     subpass.colorAttachmentCount = 1;
4825     subpass.pColorAttachments = &attach;
4826     attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4827     // perf warning for GENERAL layout on color attachment
4828     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4829                                          "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
4830     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4831     m_errorMonitor->VerifyFound();
4832     // error w/ non-color opt or GENERAL layout for color attachment
4833     attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4834     m_errorMonitor->SetDesiredFailureMsg(
4835         VK_DEBUG_REPORT_ERROR_BIT_EXT,
4836         "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
4837     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4838     m_errorMonitor->VerifyFound();
4839     subpass.colorAttachmentCount = 0;
4840     subpass.pDepthStencilAttachment = &attach;
4841     attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4842     // perf warning for GENERAL layout on DS attachment
4843     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
4844                                          "GENERAL layout for depth attachment may not give optimal performance.");
4845     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4846     m_errorMonitor->VerifyFound();
4847     // error w/ non-ds opt or GENERAL layout for color attachment
4848     attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4849     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4850                                          "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
4851                                          "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
4852     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4853     m_errorMonitor->VerifyFound();
4854     // For this error we need a valid renderpass so create default one
4855     attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
4856     attach.attachment = 0;
4857     attach_desc.format = depth_format;
4858     attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4859     attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
4860     attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4861     attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4862     // Can't do a CLEAR load on READ_ONLY initialLayout
4863     attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4864     attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
4865     attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
4866     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4867                                          "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
4868     vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4869     m_errorMonitor->VerifyFound();
4870 }
4871 
TEST_F(VkLayerTest,InvalidStorageImageLayout)4872 TEST_F(VkLayerTest, InvalidStorageImageLayout) {
4873     TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
4874 
4875     ASSERT_NO_FATAL_FAILURE(Init());
4876 
4877     const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
4878     VkImageTiling tiling;
4879     VkFormatProperties format_properties;
4880     vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
4881     if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
4882         tiling = VK_IMAGE_TILING_LINEAR;
4883     } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
4884         tiling = VK_IMAGE_TILING_OPTIMAL;
4885     } else {
4886         printf("%s Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n", kSkipPrefix);
4887         return;
4888     }
4889 
4890     OneOffDescriptorSet descriptor_set(m_device,
4891                                        {
4892                                            {0, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr},
4893                                        });
4894 
4895     VkImageObj image(m_device);
4896     image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
4897     ASSERT_TRUE(image.initialized());
4898     VkImageView view = image.targetView(tex_format);
4899 
4900     descriptor_set.WriteDescriptorImageInfo(0, view, VK_NULL_HANDLE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE);
4901 
4902     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4903                                          " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
4904                                          "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
4905     descriptor_set.UpdateDescriptorSets();
4906     m_errorMonitor->VerifyFound();
4907 }
4908 
TEST_F(VkLayerTest,CreateImageViewBreaksParameterCompatibilityRequirements)4909 TEST_F(VkLayerTest, CreateImageViewBreaksParameterCompatibilityRequirements) {
4910     TEST_DESCRIPTION(
4911         "Attempts to create an Image View with a view type that does not match the image type it is being created from.");
4912 
4913     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
4914     if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
4915         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
4916     }
4917     ASSERT_NO_FATAL_FAILURE(InitState());
4918 
4919     VkPhysicalDeviceMemoryProperties memProps;
4920     vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memProps);
4921 
4922     // Test mismatch detection for image of type VK_IMAGE_TYPE_1D
4923     VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
4924                                  nullptr,
4925                                  VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
4926                                  VK_IMAGE_TYPE_1D,
4927                                  VK_FORMAT_R8G8B8A8_UNORM,
4928                                  {1, 1, 1},
4929                                  1,
4930                                  1,
4931                                  VK_SAMPLE_COUNT_1_BIT,
4932                                  VK_IMAGE_TILING_OPTIMAL,
4933                                  VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
4934                                  VK_SHARING_MODE_EXCLUSIVE,
4935                                  0,
4936                                  nullptr,
4937                                  VK_IMAGE_LAYOUT_UNDEFINED};
4938     VkImageObj image1D(m_device);
4939     image1D.init(&imgInfo);
4940     ASSERT_TRUE(image1D.initialized());
4941 
4942     // Initialize VkImageViewCreateInfo with mismatched viewType
4943     VkImageViewCreateInfo ivci = {};
4944     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4945     ivci.image = image1D.handle();
4946     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4947     ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
4948     ivci.subresourceRange.layerCount = 1;
4949     ivci.subresourceRange.baseMipLevel = 0;
4950     ivci.subresourceRange.levelCount = 1;
4951     ivci.subresourceRange.baseArrayLayer = 0;
4952     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4953 
4954     // Test for error message
4955     CreateImageViewTest(*this, &ivci,
4956                         "vkCreateImageView(): pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_2D is not compatible with image");
4957 
4958     // Test mismatch detection for image of type VK_IMAGE_TYPE_2D
4959     imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
4960                nullptr,
4961                VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
4962                VK_IMAGE_TYPE_2D,
4963                VK_FORMAT_R8G8B8A8_UNORM,
4964                {1, 1, 1},
4965                1,
4966                6,
4967                VK_SAMPLE_COUNT_1_BIT,
4968                VK_IMAGE_TILING_OPTIMAL,
4969                VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
4970                VK_SHARING_MODE_EXCLUSIVE,
4971                0,
4972                nullptr,
4973                VK_IMAGE_LAYOUT_UNDEFINED};
4974     VkImageObj image2D(m_device);
4975     image2D.init(&imgInfo);
4976     ASSERT_TRUE(image2D.initialized());
4977 
4978     // Initialize VkImageViewCreateInfo with mismatched viewType
4979     ivci = {};
4980     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4981     ivci.image = image2D.handle();
4982     ivci.viewType = VK_IMAGE_VIEW_TYPE_3D;
4983     ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
4984     ivci.subresourceRange.layerCount = 1;
4985     ivci.subresourceRange.baseMipLevel = 0;
4986     ivci.subresourceRange.levelCount = 1;
4987     ivci.subresourceRange.baseArrayLayer = 0;
4988     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4989 
4990     // Test for error message
4991     CreateImageViewTest(*this, &ivci,
4992                         "vkCreateImageView(): pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_3D is not compatible with image");
4993 
4994     // Change VkImageViewCreateInfo to different mismatched viewType
4995     ivci.viewType = VK_IMAGE_VIEW_TYPE_CUBE;
4996     ivci.subresourceRange.layerCount = 6;
4997 
4998     // Test for error message
4999     CreateImageViewTest(*this, &ivci, "VUID-VkImageViewCreateInfo-image-01003");
5000 
5001     // Test mismatch detection for image of type VK_IMAGE_TYPE_3D
5002     imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
5003                nullptr,
5004                VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
5005                VK_IMAGE_TYPE_3D,
5006                VK_FORMAT_R8G8B8A8_UNORM,
5007                {1, 1, 1},
5008                1,
5009                1,
5010                VK_SAMPLE_COUNT_1_BIT,
5011                VK_IMAGE_TILING_OPTIMAL,
5012                VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
5013                VK_SHARING_MODE_EXCLUSIVE,
5014                0,
5015                nullptr,
5016                VK_IMAGE_LAYOUT_UNDEFINED};
5017     VkImageObj image3D(m_device);
5018     image3D.init(&imgInfo);
5019     ASSERT_TRUE(image3D.initialized());
5020 
5021     // Initialize VkImageViewCreateInfo with mismatched viewType
5022     ivci = {};
5023     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5024     ivci.image = image3D.handle();
5025     ivci.viewType = VK_IMAGE_VIEW_TYPE_1D;
5026     ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
5027     ivci.subresourceRange.layerCount = 1;
5028     ivci.subresourceRange.baseMipLevel = 0;
5029     ivci.subresourceRange.levelCount = 1;
5030     ivci.subresourceRange.baseArrayLayer = 0;
5031     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5032 
5033     // Test for error message
5034     CreateImageViewTest(*this, &ivci,
5035                         "vkCreateImageView(): pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_1D is not compatible with image");
5036 
5037     // Change VkImageViewCreateInfo to different mismatched viewType
5038     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
5039 
5040     // Test for error message
5041     if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
5042         CreateImageViewTest(*this, &ivci, "VUID-VkImageViewCreateInfo-image-01005");
5043     } else {
5044         CreateImageViewTest(*this, &ivci, "VUID-VkImageViewCreateInfo-subResourceRange-01021");
5045     }
5046 
5047     // Check if the device can make the image required for this test case.
5048     VkImageFormatProperties formProps = {{0, 0, 0}, 0, 0, 0, 0};
5049     VkResult res = vkGetPhysicalDeviceImageFormatProperties(
5050         m_device->phy().handle(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_3D, VK_IMAGE_TILING_OPTIMAL,
5051         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
5052         VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR | VK_IMAGE_CREATE_SPARSE_BINDING_BIT,
5053         &formProps);
5054 
5055     // If not, skip this part of the test.
5056     if (res || !m_device->phy().features().sparseBinding ||
5057         !DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
5058         printf("%s %s is not supported.\n", kSkipPrefix, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
5059         return;
5060     }
5061 
5062     // Initialize VkImageCreateInfo with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR and VK_IMAGE_CREATE_SPARSE_BINDING_BIT which
5063     // are incompatible create flags.
5064     imgInfo = {
5065         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
5066         nullptr,
5067         VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR | VK_IMAGE_CREATE_SPARSE_BINDING_BIT,
5068         VK_IMAGE_TYPE_3D,
5069         VK_FORMAT_R8G8B8A8_UNORM,
5070         {1, 1, 1},
5071         1,
5072         1,
5073         VK_SAMPLE_COUNT_1_BIT,
5074         VK_IMAGE_TILING_OPTIMAL,
5075         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
5076         VK_SHARING_MODE_EXCLUSIVE,
5077         0,
5078         nullptr,
5079         VK_IMAGE_LAYOUT_UNDEFINED};
5080     VkImage imageSparse;
5081 
5082     // Creating a sparse image means we should not bind memory to it.
5083     res = vkCreateImage(m_device->device(), &imgInfo, NULL, &imageSparse);
5084     ASSERT_FALSE(res);
5085 
5086     // Initialize VkImageViewCreateInfo to create a view that will attempt to utilize VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR.
5087     ivci = {};
5088     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5089     ivci.image = imageSparse;
5090     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
5091     ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
5092     ivci.subresourceRange.layerCount = 1;
5093     ivci.subresourceRange.baseMipLevel = 0;
5094     ivci.subresourceRange.levelCount = 1;
5095     ivci.subresourceRange.baseArrayLayer = 0;
5096     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5097 
5098     // Test for error message
5099     CreateImageViewTest(*this, &ivci,
5100                         " when the VK_IMAGE_CREATE_SPARSE_BINDING_BIT, VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, or "
5101                         "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled.");
5102 
5103     // Clean up
5104     vkDestroyImage(m_device->device(), imageSparse, nullptr);
5105 }
5106 
TEST_F(VkLayerTest,CreateImageViewFormatFeatureMismatch)5107 TEST_F(VkLayerTest, CreateImageViewFormatFeatureMismatch) {
5108     TEST_DESCRIPTION("Create view with a format that does not have the same features as the image format.");
5109 
5110     if (!EnableDeviceProfileLayer()) {
5111         printf("%s Failed to enable device profile layer.\n", kSkipPrefix);
5112         return;
5113     }
5114 
5115     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
5116     ASSERT_NO_FATAL_FAILURE(InitState());
5117 
5118     PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT = nullptr;
5119     PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT = nullptr;
5120 
5121     // Load required functions
5122     if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceFormatPropertiesEXT, fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) {
5123         printf("%s Failed to device profile layer.\n", kSkipPrefix);
5124         return;
5125     }
5126 
5127     // List of features to be tested
5128     VkFormatFeatureFlagBits features[] = {VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT,
5129                                           VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT};
5130     uint32_t feature_count = 4;
5131     // List of usage cases for each feature test
5132     VkImageUsageFlags usages[] = {VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
5133                                   VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT};
5134     // List of errors that will be thrown in order of tests run
5135     std::string optimal_error_codes[] = {
5136         "VUID-VkImageViewCreateInfo-usage-02274",
5137         "VUID-VkImageViewCreateInfo-usage-02275",
5138         "VUID-VkImageViewCreateInfo-usage-02276",
5139         "VUID-VkImageViewCreateInfo-usage-02277",
5140     };
5141 
5142     VkFormatProperties formatProps;
5143 
5144     // First three tests
5145     uint32_t i = 0;
5146     for (i = 0; i < (feature_count - 1); i++) {
5147         // Modify formats to have mismatched features
5148 
5149         // Format for image
5150         fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_UINT, &formatProps);
5151         formatProps.optimalTilingFeatures |= features[i];
5152         fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_UINT, formatProps);
5153 
5154         memset(&formatProps, 0, sizeof(formatProps));
5155 
5156         // Format for view
5157         fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_SINT, &formatProps);
5158         formatProps.optimalTilingFeatures = features[(i + 1) % feature_count];
5159         fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_SINT, formatProps);
5160 
5161         // Create image with modified format
5162         VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
5163                                      nullptr,
5164                                      VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
5165                                      VK_IMAGE_TYPE_2D,
5166                                      VK_FORMAT_R32G32B32A32_UINT,
5167                                      {1, 1, 1},
5168                                      1,
5169                                      1,
5170                                      VK_SAMPLE_COUNT_1_BIT,
5171                                      VK_IMAGE_TILING_OPTIMAL,
5172                                      usages[i],
5173                                      VK_SHARING_MODE_EXCLUSIVE,
5174                                      0,
5175                                      nullptr,
5176                                      VK_IMAGE_LAYOUT_UNDEFINED};
5177         VkImageObj image(m_device);
5178         image.init(&imgInfo);
5179         ASSERT_TRUE(image.initialized());
5180 
5181         // Initialize VkImageViewCreateInfo with modified format
5182         VkImageViewCreateInfo ivci = {};
5183         ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5184         ivci.image = image.handle();
5185         ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
5186         ivci.format = VK_FORMAT_R32G32B32A32_SINT;
5187         ivci.subresourceRange.layerCount = 1;
5188         ivci.subresourceRange.baseMipLevel = 0;
5189         ivci.subresourceRange.levelCount = 1;
5190         ivci.subresourceRange.baseArrayLayer = 0;
5191         ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5192 
5193         // Test for error message
5194         CreateImageViewTest(*this, &ivci, optimal_error_codes[i]);
5195     }
5196 
5197     // Test for VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT.  Needs special formats
5198 
5199     // Only run this test if format supported
5200     if (!ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
5201         printf("%s VK_FORMAT_D24_UNORM_S8_UINT format not supported - skipped.\n", kSkipPrefix);
5202         return;
5203     }
5204     // Modify formats to have mismatched features
5205 
5206     // Format for image
5207     fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, &formatProps);
5208     formatProps.optimalTilingFeatures |= features[i];
5209     fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, formatProps);
5210 
5211     memset(&formatProps, 0, sizeof(formatProps));
5212 
5213     // Format for view
5214     fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &formatProps);
5215     formatProps.optimalTilingFeatures = features[(i + 1) % feature_count];
5216     fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, formatProps);
5217 
5218     // Create image with modified format
5219     VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
5220                                  nullptr,
5221                                  VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
5222                                  VK_IMAGE_TYPE_2D,
5223                                  VK_FORMAT_D24_UNORM_S8_UINT,
5224                                  {1, 1, 1},
5225                                  1,
5226                                  1,
5227                                  VK_SAMPLE_COUNT_1_BIT,
5228                                  VK_IMAGE_TILING_OPTIMAL,
5229                                  usages[i],
5230                                  VK_SHARING_MODE_EXCLUSIVE,
5231                                  0,
5232                                  nullptr,
5233                                  VK_IMAGE_LAYOUT_UNDEFINED};
5234     VkImageObj image(m_device);
5235     image.init(&imgInfo);
5236     ASSERT_TRUE(image.initialized());
5237 
5238     // Initialize VkImageViewCreateInfo with modified format
5239     VkImageViewCreateInfo ivci = {};
5240     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5241     ivci.image = image.handle();
5242     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
5243     ivci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
5244     ivci.subresourceRange.layerCount = 1;
5245     ivci.subresourceRange.baseMipLevel = 0;
5246     ivci.subresourceRange.levelCount = 1;
5247     ivci.subresourceRange.baseArrayLayer = 0;
5248     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
5249 
5250     // Test for error message
5251     CreateImageViewTest(*this, &ivci, optimal_error_codes[i]);
5252 }
5253 
TEST_F(VkLayerTest,InvalidImageViewUsageCreateInfo)5254 TEST_F(VkLayerTest, InvalidImageViewUsageCreateInfo) {
5255     TEST_DESCRIPTION("Usage modification via a chained VkImageViewUsageCreateInfo struct");
5256 
5257     if (!EnableDeviceProfileLayer()) {
5258         printf("%s Test requires DeviceProfileLayer, unavailable - skipped.\n", kSkipPrefix);
5259         return;
5260     }
5261 
5262     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
5263     if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE2_EXTENSION_NAME)) {
5264         printf("%s Test requires API >= 1.1 or KHR_MAINTENANCE2 extension, unavailable - skipped.\n", kSkipPrefix);
5265         return;
5266     }
5267     m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
5268     ASSERT_NO_FATAL_FAILURE(InitState());
5269 
5270     PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT = nullptr;
5271     PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT = nullptr;
5272 
5273     // Load required functions
5274     if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceFormatPropertiesEXT, fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) {
5275         printf("%s Required extensions are not avaiable.\n", kSkipPrefix);
5276         return;
5277     }
5278 
5279     VkFormatProperties formatProps;
5280 
5281     // Ensure image format claims support for sampled and storage, excludes color attachment
5282     memset(&formatProps, 0, sizeof(formatProps));
5283     fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_UINT, &formatProps);
5284     formatProps.optimalTilingFeatures |= (VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
5285     formatProps.optimalTilingFeatures = formatProps.optimalTilingFeatures & ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5286     fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_UINT, formatProps);
5287 
5288     // Create image with sampled and storage usages
5289     VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
5290                                  nullptr,
5291                                  VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
5292                                  VK_IMAGE_TYPE_2D,
5293                                  VK_FORMAT_R32G32B32A32_UINT,
5294                                  {1, 1, 1},
5295                                  1,
5296                                  1,
5297                                  VK_SAMPLE_COUNT_1_BIT,
5298                                  VK_IMAGE_TILING_OPTIMAL,
5299                                  VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
5300                                  VK_SHARING_MODE_EXCLUSIVE,
5301                                  0,
5302                                  nullptr,
5303                                  VK_IMAGE_LAYOUT_UNDEFINED};
5304     VkImageObj image(m_device);
5305     image.init(&imgInfo);
5306     ASSERT_TRUE(image.initialized());
5307 
5308     // Force the imageview format to exclude storage feature, include color attachment
5309     memset(&formatProps, 0, sizeof(formatProps));
5310     fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_SINT, &formatProps);
5311     formatProps.optimalTilingFeatures |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5312     formatProps.optimalTilingFeatures = (formatProps.optimalTilingFeatures & ~VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
5313     fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_SINT, formatProps);
5314 
5315     VkImageViewCreateInfo ivci = {};
5316     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5317     ivci.image = image.handle();
5318     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
5319     ivci.format = VK_FORMAT_R32G32B32A32_SINT;
5320     ivci.subresourceRange.layerCount = 1;
5321     ivci.subresourceRange.baseMipLevel = 0;
5322     ivci.subresourceRange.levelCount = 1;
5323     ivci.subresourceRange.baseArrayLayer = 0;
5324     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5325 
5326     // ImageView creation should fail because view format doesn't support all the underlying image's usages
5327     CreateImageViewTest(*this, &ivci, "VUID-VkImageViewCreateInfo-usage-02275");
5328 
5329     // Add a chained VkImageViewUsageCreateInfo to override original image usage bits, removing storage
5330     VkImageViewUsageCreateInfo usage_ci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO, nullptr, VK_IMAGE_USAGE_SAMPLED_BIT};
5331     // Link the VkImageViewUsageCreateInfo struct into the view's create info pNext chain
5332     ivci.pNext = &usage_ci;
5333 
5334     // ImageView should now succeed without error
5335     CreateImageViewTest(*this, &ivci);
5336 
5337     // Try a zero usage field
5338     usage_ci.usage = 0;
5339     CreateImageViewTest(*this, &ivci, "VUID-VkImageViewUsageCreateInfo-usage-requiredbitmask");
5340 
5341     // Try an illegal bit in usage field
5342     usage_ci.usage = 0x10000000 | VK_IMAGE_USAGE_SAMPLED_BIT;
5343     CreateImageViewTest(*this, &ivci, "VUID-VkImageViewUsageCreateInfo-usage-parameter");
5344 }
5345 
TEST_F(VkLayerTest,CreateImageViewNoMemoryBoundToImage)5346 TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
5347     VkResult err;
5348 
5349     ASSERT_NO_FATAL_FAILURE(Init());
5350 
5351     // Create an image and try to create a view with no memory backing the image
5352     VkImage image;
5353 
5354     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5355     const int32_t tex_width = 32;
5356     const int32_t tex_height = 32;
5357 
5358     VkImageCreateInfo image_create_info = {};
5359     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5360     image_create_info.pNext = NULL;
5361     image_create_info.imageType = VK_IMAGE_TYPE_2D;
5362     image_create_info.format = tex_format;
5363     image_create_info.extent.width = tex_width;
5364     image_create_info.extent.height = tex_height;
5365     image_create_info.extent.depth = 1;
5366     image_create_info.mipLevels = 1;
5367     image_create_info.arrayLayers = 1;
5368     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5369     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5370     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5371     image_create_info.flags = 0;
5372 
5373     err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5374     ASSERT_VK_SUCCESS(err);
5375 
5376     VkImageViewCreateInfo image_view_create_info = {};
5377     image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5378     image_view_create_info.image = image;
5379     image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5380     image_view_create_info.format = tex_format;
5381     image_view_create_info.subresourceRange.layerCount = 1;
5382     image_view_create_info.subresourceRange.baseMipLevel = 0;
5383     image_view_create_info.subresourceRange.levelCount = 1;
5384     image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5385 
5386     CreateImageViewTest(*this, &image_view_create_info,
5387                         " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
5388     vkDestroyImage(m_device->device(), image, NULL);
5389 }
5390 
TEST_F(VkLayerTest,InvalidImageViewAspect)5391 TEST_F(VkLayerTest, InvalidImageViewAspect) {
5392     TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
5393 
5394     ASSERT_NO_FATAL_FAILURE(Init());
5395 
5396     const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5397     VkImageObj image(m_device);
5398     image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
5399     ASSERT_TRUE(image.initialized());
5400 
5401     VkImageViewCreateInfo image_view_create_info = {};
5402     image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5403     image_view_create_info.image = image.handle();
5404     image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5405     image_view_create_info.format = tex_format;
5406     image_view_create_info.subresourceRange.baseMipLevel = 0;
5407     image_view_create_info.subresourceRange.levelCount = 1;
5408     image_view_create_info.subresourceRange.layerCount = 1;
5409     // Cause an error by setting an invalid image aspect
5410     image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
5411 
5412     CreateImageViewTest(*this, &image_view_create_info, "VUID-VkImageSubresource-aspectMask-parameter");
5413     m_errorMonitor->VerifyFound();
5414 }
5415 
TEST_F(VkLayerTest,ExerciseGetImageSubresourceLayout)5416 TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
5417     TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
5418 
5419     ASSERT_NO_FATAL_FAILURE(Init());
5420     VkSubresourceLayout subres_layout = {};
5421 
5422     // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
5423     {
5424         const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL;  // ERROR: violates VU 00732
5425         VkImageObj img(m_device);
5426         img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
5427         ASSERT_TRUE(img.initialized());
5428 
5429         VkImageSubresource subres = {};
5430         subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5431         subres.mipLevel = 0;
5432         subres.arrayLayer = 0;
5433 
5434         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageSubresourceLayout-image-00996");
5435         vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
5436         m_errorMonitor->VerifyFound();
5437     }
5438 
5439     // VU 00733: The aspectMask member of pSubresource must only have a single bit set
5440     {
5441         VkImageObj img(m_device);
5442         img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
5443         ASSERT_TRUE(img.initialized());
5444 
5445         VkImageSubresource subres = {};
5446         subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT;  // ERROR: triggers VU 00733
5447         subres.mipLevel = 0;
5448         subres.arrayLayer = 0;
5449 
5450         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageSubresourceLayout-aspectMask-00997");
5451         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageSubresource-aspectMask-parameter");
5452         vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
5453         m_errorMonitor->VerifyFound();
5454     }
5455 
5456     // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
5457     {
5458         VkImageObj img(m_device);
5459         img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
5460         ASSERT_TRUE(img.initialized());
5461 
5462         VkImageSubresource subres = {};
5463         subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5464         subres.mipLevel = 1;  // ERROR: triggers VU 00739
5465         subres.arrayLayer = 0;
5466 
5467         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageSubresourceLayout-mipLevel-01716");
5468         vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
5469         m_errorMonitor->VerifyFound();
5470     }
5471 
5472     // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
5473     {
5474         VkImageObj img(m_device);
5475         img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
5476         ASSERT_TRUE(img.initialized());
5477 
5478         VkImageSubresource subres = {};
5479         subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5480         subres.mipLevel = 0;
5481         subres.arrayLayer = 1;  // ERROR: triggers VU 00740
5482 
5483         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetImageSubresourceLayout-arrayLayer-01717");
5484         vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
5485         m_errorMonitor->VerifyFound();
5486     }
5487 }
5488 
TEST_F(VkLayerTest,ImageLayerUnsupportedFormat)5489 TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
5490     TEST_DESCRIPTION("Creating images with unsupported formats ");
5491 
5492     ASSERT_NO_FATAL_FAILURE(Init());
5493     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5494 
5495     // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
5496     VkImageCreateInfo image_create_info = {};
5497     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5498     image_create_info.imageType = VK_IMAGE_TYPE_2D;
5499     image_create_info.format = VK_FORMAT_UNDEFINED;
5500     image_create_info.extent.width = 32;
5501     image_create_info.extent.height = 32;
5502     image_create_info.extent.depth = 1;
5503     image_create_info.mipLevels = 1;
5504     image_create_info.arrayLayers = 1;
5505     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5506     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5507     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
5508 
5509     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-00943");
5510 }
5511 
TEST_F(VkLayerTest,CreateImageViewFormatMismatchUnrelated)5512 TEST_F(VkLayerTest, CreateImageViewFormatMismatchUnrelated) {
5513     TEST_DESCRIPTION("Create an image with a color format, then try to create a depth view of it");
5514 
5515     if (!EnableDeviceProfileLayer()) {
5516         printf("%s Failed to enable device profile layer.\n", kSkipPrefix);
5517         return;
5518     }
5519 
5520     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
5521     ASSERT_NO_FATAL_FAILURE(InitState());
5522 
5523     // Load required functions
5524     PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT =
5525         (PFN_vkSetPhysicalDeviceFormatPropertiesEXT)vkGetInstanceProcAddr(instance(), "vkSetPhysicalDeviceFormatPropertiesEXT");
5526     PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT =
5527         (PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT)vkGetInstanceProcAddr(instance(),
5528                                                                                   "vkGetOriginalPhysicalDeviceFormatPropertiesEXT");
5529 
5530     if (!(fpvkSetPhysicalDeviceFormatPropertiesEXT) || !(fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) {
5531         printf("%s Can't find device_profile_api functions; skipped.\n", kSkipPrefix);
5532         return;
5533     }
5534 
5535     auto depth_format = FindSupportedDepthStencilFormat(gpu());
5536     if (!depth_format) {
5537         printf("%s Couldn't find depth stencil image format.\n", kSkipPrefix);
5538         return;
5539     }
5540 
5541     VkFormatProperties formatProps;
5542 
5543     fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), depth_format, &formatProps);
5544     formatProps.optimalTilingFeatures |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5545     fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), depth_format, formatProps);
5546 
5547     VkImageObj image(m_device);
5548     image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5549     ASSERT_TRUE(image.initialized());
5550 
5551     VkImageViewCreateInfo imgViewInfo = {};
5552     imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5553     imgViewInfo.image = image.handle();
5554     imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
5555     imgViewInfo.format = depth_format;
5556     imgViewInfo.subresourceRange.layerCount = 1;
5557     imgViewInfo.subresourceRange.baseMipLevel = 0;
5558     imgViewInfo.subresourceRange.levelCount = 1;
5559     imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5560 
5561     // Can't use depth format for view into color image - Expect INVALID_FORMAT
5562     CreateImageViewTest(*this, &imgViewInfo,
5563                         "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
5564 }
5565 
TEST_F(VkLayerTest,CreateImageViewNoMutableFormatBit)5566 TEST_F(VkLayerTest, CreateImageViewNoMutableFormatBit) {
5567     TEST_DESCRIPTION("Create an image view with a different format, when the image does not have MUTABLE_FORMAT bit");
5568 
5569     if (!EnableDeviceProfileLayer()) {
5570         printf("%s Couldn't enable device profile layer.\n", kSkipPrefix);
5571         return;
5572     }
5573 
5574     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
5575     ASSERT_NO_FATAL_FAILURE(InitState());
5576 
5577     PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhysicalDeviceFormatPropertiesEXT = nullptr;
5578     PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT = nullptr;
5579 
5580     // Load required functions
5581     if (!LoadDeviceProfileLayer(fpvkSetPhysicalDeviceFormatPropertiesEXT, fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) {
5582         printf("%s Required extensions are not present.\n", kSkipPrefix);
5583         return;
5584     }
5585 
5586     VkImageObj image(m_device);
5587     image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5588     ASSERT_TRUE(image.initialized());
5589 
5590     VkFormatProperties formatProps;
5591 
5592     fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_B8G8R8A8_UINT, &formatProps);
5593     formatProps.optimalTilingFeatures |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5594     fpvkSetPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_B8G8R8A8_UINT, formatProps);
5595 
5596     VkImageViewCreateInfo imgViewInfo = {};
5597     imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5598     imgViewInfo.image = image.handle();
5599     imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
5600     imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
5601     imgViewInfo.subresourceRange.layerCount = 1;
5602     imgViewInfo.subresourceRange.baseMipLevel = 0;
5603     imgViewInfo.subresourceRange.levelCount = 1;
5604     imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5605 
5606     // Same compatibility class but no MUTABLE_FORMAT bit - Expect
5607     // VIEW_CREATE_ERROR
5608     CreateImageViewTest(*this, &imgViewInfo, "VUID-VkImageViewCreateInfo-image-01019");
5609 }
5610 
TEST_F(VkLayerTest,CreateImageViewDifferentClass)5611 TEST_F(VkLayerTest, CreateImageViewDifferentClass) {
5612     TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
5613 
5614     ASSERT_NO_FATAL_FAILURE(Init());
5615 
5616     if (!(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
5617         printf("%s Device does not support R8_UINT as color attachment; skipped", kSkipPrefix);
5618         return;
5619     }
5620 
5621     VkImageCreateInfo mutImgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
5622                                     nullptr,
5623                                     VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
5624                                     VK_IMAGE_TYPE_2D,
5625                                     VK_FORMAT_R8_UINT,
5626                                     {128, 128, 1},
5627                                     1,
5628                                     1,
5629                                     VK_SAMPLE_COUNT_1_BIT,
5630                                     VK_IMAGE_TILING_OPTIMAL,
5631                                     VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
5632                                     VK_SHARING_MODE_EXCLUSIVE,
5633                                     0,
5634                                     nullptr,
5635                                     VK_IMAGE_LAYOUT_UNDEFINED};
5636     VkImageObj mutImage(m_device);
5637     mutImage.init(&mutImgInfo);
5638     ASSERT_TRUE(mutImage.initialized());
5639 
5640     VkImageViewCreateInfo imgViewInfo = {};
5641     imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5642     imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
5643     imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
5644     imgViewInfo.subresourceRange.layerCount = 1;
5645     imgViewInfo.subresourceRange.baseMipLevel = 0;
5646     imgViewInfo.subresourceRange.levelCount = 1;
5647     imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5648     imgViewInfo.image = mutImage.handle();
5649 
5650     CreateImageViewTest(*this, &imgViewInfo, "VUID-VkImageViewCreateInfo-image-01018");
5651 }
5652 
TEST_F(VkLayerTest,MultiplaneIncompatibleViewFormat)5653 TEST_F(VkLayerTest, MultiplaneIncompatibleViewFormat) {
5654     TEST_DESCRIPTION("Postive/negative tests of multiplane imageview format compatibility");
5655 
5656     // Enable KHR multiplane req'd extensions
5657     bool mp_extensions = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
5658                                                     VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION);
5659     if (mp_extensions) {
5660         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
5661     }
5662     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
5663     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
5664     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
5665     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
5666     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
5667     if (mp_extensions) {
5668         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
5669         m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
5670         m_device_extension_names.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
5671         m_device_extension_names.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
5672     } else {
5673         printf("%s test requires KHR multiplane extensions, not available.  Skipping.\n", kSkipPrefix);
5674         return;
5675     }
5676     ASSERT_NO_FATAL_FAILURE(InitState());
5677 
5678     VkImageCreateInfo ci = {};
5679     ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5680     ci.pNext = NULL;
5681     ci.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
5682     ci.imageType = VK_IMAGE_TYPE_2D;
5683     ci.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
5684     ci.tiling = VK_IMAGE_TILING_OPTIMAL;
5685     ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5686     ci.extent = {128, 128, 1};
5687     ci.mipLevels = 1;
5688     ci.arrayLayers = 1;
5689     ci.samples = VK_SAMPLE_COUNT_1_BIT;
5690     ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5691     ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5692 
5693     // Verify format
5694     VkFormatFeatureFlags features = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
5695     bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, features);
5696     if (!supported) {
5697         printf("%s Multiplane image format not supported.  Skipping test.\n", kSkipPrefix);
5698         return;
5699     }
5700 
5701     VkImageObj image_obj(m_device);
5702     image_obj.init(&ci);
5703     ASSERT_TRUE(image_obj.initialized());
5704 
5705     VkImageViewCreateInfo ivci = {};
5706     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5707     ivci.image = image_obj.image();
5708     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
5709     ivci.format = VK_FORMAT_R8_SNORM;  // Compat is VK_FORMAT_R8_UNORM
5710     ivci.subresourceRange.layerCount = 1;
5711     ivci.subresourceRange.baseMipLevel = 0;
5712     ivci.subresourceRange.levelCount = 1;
5713     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_PLANE_1_BIT;
5714 
5715     // Incompatible format error
5716     CreateImageViewTest(*this, &ivci, "VUID-VkImageViewCreateInfo-image-01586");
5717 
5718     // Correct format succeeds
5719     ivci.format = VK_FORMAT_R8_UNORM;
5720     CreateImageViewTest(*this, &ivci);
5721 
5722     // Try a multiplane imageview
5723     ivci.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
5724     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5725     CreateImageViewTest(*this, &ivci);
5726 }
5727 
TEST_F(VkLayerTest,CreateImageViewInvalidSubresourceRange)5728 TEST_F(VkLayerTest, CreateImageViewInvalidSubresourceRange) {
5729     TEST_DESCRIPTION("Passing bad image subrange to CreateImageView");
5730 
5731     ASSERT_NO_FATAL_FAILURE(Init());
5732 
5733     VkImageObj image(m_device);
5734     image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
5735     ASSERT_TRUE(image.create_info().arrayLayers == 1);
5736     ASSERT_TRUE(image.initialized());
5737 
5738     VkImageViewCreateInfo img_view_info_template = {};
5739     img_view_info_template.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5740     img_view_info_template.image = image.handle();
5741     img_view_info_template.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
5742     img_view_info_template.format = image.format();
5743     // subresourceRange to be filled later for the purposes of this test
5744     img_view_info_template.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5745     img_view_info_template.subresourceRange.baseMipLevel = 0;
5746     img_view_info_template.subresourceRange.levelCount = 0;
5747     img_view_info_template.subresourceRange.baseArrayLayer = 0;
5748     img_view_info_template.subresourceRange.layerCount = 0;
5749 
5750     // Try baseMipLevel >= image.mipLevels with VK_REMAINING_MIP_LEVELS
5751     {
5752         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, VK_REMAINING_MIP_LEVELS, 0, 1};
5753         VkImageViewCreateInfo img_view_info = img_view_info_template;
5754         img_view_info.subresourceRange = range;
5755         CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01478");
5756     }
5757 
5758     // Try baseMipLevel >= image.mipLevels without VK_REMAINING_MIP_LEVELS
5759     {
5760         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 1, 1, 0, 1};
5761         VkImageViewCreateInfo img_view_info = img_view_info_template;
5762         img_view_info.subresourceRange = range;
5763         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageViewCreateInfo-subresourceRange-01718");
5764         CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01478");
5765     }
5766 
5767     // Try levelCount = 0
5768     {
5769         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 0, 1};
5770         VkImageViewCreateInfo img_view_info = img_view_info_template;
5771         img_view_info.subresourceRange = range;
5772         CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01718");
5773     }
5774 
5775     // Try baseMipLevel + levelCount > image.mipLevels
5776     {
5777         const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 2, 0, 1};
5778         VkImageViewCreateInfo img_view_info = img_view_info_template;
5779         img_view_info.subresourceRange = range;
5780         CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01718");
5781     }
5782 
5783     // These tests rely on having the Maintenance1 extension not being enabled, and are invalid on all but version 1.0
5784     if (m_device->props.apiVersion < VK_API_VERSION_1_1) {
5785         // Try baseArrayLayer >= image.arrayLayers with VK_REMAINING_ARRAY_LAYERS
5786         {
5787             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, VK_REMAINING_ARRAY_LAYERS};
5788             VkImageViewCreateInfo img_view_info = img_view_info_template;
5789             img_view_info.subresourceRange = range;
5790             CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01480");
5791         }
5792 
5793         // Try baseArrayLayer >= image.arrayLayers without VK_REMAINING_ARRAY_LAYERS
5794         {
5795             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 1, 1};
5796             VkImageViewCreateInfo img_view_info = img_view_info_template;
5797             img_view_info.subresourceRange = range;
5798             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5799                                                  "VUID-VkImageViewCreateInfo-subresourceRange-01719");
5800             CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01480");
5801         }
5802 
5803         // Try layerCount = 0
5804         {
5805             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 0};
5806             VkImageViewCreateInfo img_view_info = img_view_info_template;
5807             img_view_info.subresourceRange = range;
5808             CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01719");
5809         }
5810 
5811         // Try baseArrayLayer + layerCount > image.arrayLayers
5812         {
5813             const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2};
5814             VkImageViewCreateInfo img_view_info = img_view_info_template;
5815             img_view_info.subresourceRange = range;
5816             CreateImageViewTest(*this, &img_view_info, "VUID-VkImageViewCreateInfo-subresourceRange-01719");
5817         }
5818     }
5819 }
5820 
TEST_F(VkLayerTest,CreateImageMiscErrors)5821 TEST_F(VkLayerTest, CreateImageMiscErrors) {
5822     TEST_DESCRIPTION("Misc leftover valid usage errors in VkImageCreateInfo struct");
5823 
5824     VkPhysicalDeviceFeatures features{};
5825     ASSERT_NO_FATAL_FAILURE(Init(&features));
5826 
5827     VkImageCreateInfo tmp_img_ci = {};
5828     tmp_img_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5829     tmp_img_ci.flags = 0;                          // assumably any is supported
5830     tmp_img_ci.imageType = VK_IMAGE_TYPE_2D;       // any is supported
5831     tmp_img_ci.format = VK_FORMAT_R8G8B8A8_UNORM;  // has mandatory support for all usages
5832     tmp_img_ci.extent = {64, 64, 1};               // limit is 256 for 3D, or 4096
5833     tmp_img_ci.mipLevels = 1;                      // any is supported
5834     tmp_img_ci.arrayLayers = 1;                    // limit is 256
5835     tmp_img_ci.samples = VK_SAMPLE_COUNT_1_BIT;    // needs to be 1 if TILING_LINEAR
5836     // if VK_IMAGE_TILING_LINEAR imageType must be 2D, usage must be TRANSFER, and levels layers samplers all 1
5837     tmp_img_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
5838     tmp_img_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;  // depends on format
5839     tmp_img_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5840     const VkImageCreateInfo safe_image_ci = tmp_img_ci;
5841 
5842     ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &safe_image_ci));
5843 
5844     {
5845         VkImageCreateInfo image_ci = safe_image_ci;
5846         image_ci.sharingMode = VK_SHARING_MODE_CONCURRENT;
5847         image_ci.queueFamilyIndexCount = 2;
5848         image_ci.pQueueFamilyIndices = nullptr;
5849         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-sharingMode-00941");
5850     }
5851 
5852     {
5853         VkImageCreateInfo image_ci = safe_image_ci;
5854         image_ci.sharingMode = VK_SHARING_MODE_CONCURRENT;
5855         image_ci.queueFamilyIndexCount = 1;
5856         const uint32_t queue_family = 0;
5857         image_ci.pQueueFamilyIndices = &queue_family;
5858         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-sharingMode-00942");
5859     }
5860 
5861     {
5862         VkImageCreateInfo image_ci = safe_image_ci;
5863         image_ci.format = VK_FORMAT_UNDEFINED;
5864         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-format-00943");
5865     }
5866 
5867     {
5868         VkImageCreateInfo image_ci = safe_image_ci;
5869         image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
5870         image_ci.arrayLayers = 6;
5871         image_ci.imageType = VK_IMAGE_TYPE_1D;
5872         m_errorMonitor->SetUnexpectedError("VUID-VkImageCreateInfo-imageType-00954");
5873         image_ci.extent = {64, 1, 1};
5874         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-flags-00949");
5875 
5876         image_ci = safe_image_ci;
5877         image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
5878         image_ci.imageType = VK_IMAGE_TYPE_3D;
5879         m_errorMonitor->SetUnexpectedError("VUID-VkImageCreateInfo-imageType-00954");
5880         image_ci.extent = {4, 4, 4};
5881         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-flags-00949");
5882 
5883         image_ci = safe_image_ci;
5884         image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
5885         image_ci.imageType = VK_IMAGE_TYPE_2D;
5886         image_ci.extent = {8, 6, 1};
5887         image_ci.arrayLayers = 6;
5888         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-imageType-00954");
5889 
5890         image_ci = safe_image_ci;
5891         image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
5892         image_ci.imageType = VK_IMAGE_TYPE_2D;
5893         image_ci.extent = {8, 8, 1};
5894         image_ci.arrayLayers = 4;
5895         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-imageType-00954");
5896     }
5897 
5898     {
5899         VkImageCreateInfo image_ci = safe_image_ci;
5900         image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;  // always has 4 samples support
5901         image_ci.samples = VK_SAMPLE_COUNT_4_BIT;
5902         image_ci.imageType = VK_IMAGE_TYPE_3D;
5903         image_ci.extent = {4, 4, 4};
5904         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-samples-02257");
5905 
5906         image_ci = safe_image_ci;
5907         image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;  // always has 4 samples support
5908         image_ci.samples = VK_SAMPLE_COUNT_4_BIT;
5909         image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
5910         image_ci.arrayLayers = 6;
5911         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-samples-02257");
5912 
5913         image_ci = safe_image_ci;
5914         image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;  // always has 4 samples support
5915         image_ci.samples = VK_SAMPLE_COUNT_4_BIT;
5916         image_ci.tiling = VK_IMAGE_TILING_LINEAR;
5917         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-samples-02257");
5918 
5919         image_ci = safe_image_ci;
5920         image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;  // always has 4 samples support
5921         image_ci.samples = VK_SAMPLE_COUNT_4_BIT;
5922         image_ci.mipLevels = 2;
5923         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-samples-02257");
5924     }
5925 
5926     {
5927         VkImageCreateInfo image_ci = safe_image_ci;
5928         image_ci.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5929         image_ci.usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
5930         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-00963");
5931 
5932         image_ci.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
5933         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-00966");
5934 
5935         image_ci.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
5936         image_ci.usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
5937         m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageCreateInfo-usage-00963");
5938         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-00966");
5939     }
5940 
5941     {
5942         VkImageCreateInfo image_ci = safe_image_ci;
5943         image_ci.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
5944         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-flags-00969");
5945     }
5946 
5947     // InitialLayout not VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREDEFINED
5948     {
5949         VkImageCreateInfo image_ci = safe_image_ci;
5950         image_ci.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5951         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-initialLayout-00993");
5952     }
5953 }
5954 
TEST_F(VkLayerTest,CreateImageMinLimitsViolation)5955 TEST_F(VkLayerTest, CreateImageMinLimitsViolation) {
5956     TEST_DESCRIPTION("Create invalid image with invalid parameters violation minimum limit, such as being zero.");
5957 
5958     ASSERT_NO_FATAL_FAILURE(Init());
5959 
5960     VkImage null_image;  // throwaway target for all the vkCreateImage
5961 
5962     VkImageCreateInfo tmp_img_ci = {};
5963     tmp_img_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5964     tmp_img_ci.flags = 0;                          // assumably any is supported
5965     tmp_img_ci.imageType = VK_IMAGE_TYPE_2D;       // any is supported
5966     tmp_img_ci.format = VK_FORMAT_R8G8B8A8_UNORM;  // has mandatory support for all usages
5967     tmp_img_ci.extent = {1, 1, 1};                 // limit is 256 for 3D, or 4096
5968     tmp_img_ci.mipLevels = 1;                      // any is supported
5969     tmp_img_ci.arrayLayers = 1;                    // limit is 256
5970     tmp_img_ci.samples = VK_SAMPLE_COUNT_1_BIT;    // needs to be 1 if TILING_LINEAR
5971     // if VK_IMAGE_TILING_LINEAR imageType must be 2D, usage must be TRANSFER, and levels layers samplers all 1
5972     tmp_img_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
5973     tmp_img_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;  // depends on format
5974     tmp_img_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5975     const VkImageCreateInfo safe_image_ci = tmp_img_ci;
5976 
5977     enum Dimension { kWidth = 0x1, kHeight = 0x2, kDepth = 0x4 };
5978 
5979     for (underlying_type<Dimension>::type bad_dimensions = 0x1; bad_dimensions < 0x8; ++bad_dimensions) {
5980         VkExtent3D extent = {1, 1, 1};
5981 
5982         if (bad_dimensions & kWidth) {
5983             extent.width = 0;
5984             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageCreateInfo-extent-00944");
5985         }
5986 
5987         if (bad_dimensions & kHeight) {
5988             extent.height = 0;
5989             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageCreateInfo-extent-00945");
5990         }
5991 
5992         if (bad_dimensions & kDepth) {
5993             extent.depth = 0;
5994             m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageCreateInfo-extent-00946");
5995         }
5996 
5997         VkImageCreateInfo bad_image_ci = safe_image_ci;
5998         bad_image_ci.imageType = VK_IMAGE_TYPE_3D;  // has to be 3D otherwise it might trigger the non-1 error instead
5999         bad_image_ci.extent = extent;
6000 
6001         vkCreateImage(m_device->device(), &bad_image_ci, NULL, &null_image);
6002 
6003         m_errorMonitor->VerifyFound();
6004     }
6005 
6006     {
6007         VkImageCreateInfo bad_image_ci = safe_image_ci;
6008         bad_image_ci.mipLevels = 0;
6009         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-mipLevels-00947");
6010     }
6011 
6012     {
6013         VkImageCreateInfo bad_image_ci = safe_image_ci;
6014         bad_image_ci.arrayLayers = 0;
6015         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-arrayLayers-00948");
6016     }
6017 
6018     {
6019         VkImageCreateInfo bad_image_ci = safe_image_ci;
6020         bad_image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
6021         bad_image_ci.arrayLayers = 5;
6022         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00954");
6023 
6024         bad_image_ci.arrayLayers = 6;
6025         bad_image_ci.extent = {64, 63, 1};
6026         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00954");
6027     }
6028 
6029     {
6030         VkImageCreateInfo bad_image_ci = safe_image_ci;
6031         bad_image_ci.imageType = VK_IMAGE_TYPE_1D;
6032         bad_image_ci.extent = {64, 2, 1};
6033         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00956");
6034 
6035         bad_image_ci.imageType = VK_IMAGE_TYPE_1D;
6036         bad_image_ci.extent = {64, 1, 2};
6037         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00956");
6038 
6039         bad_image_ci.imageType = VK_IMAGE_TYPE_2D;
6040         bad_image_ci.extent = {64, 64, 2};
6041         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00957");
6042 
6043         bad_image_ci.imageType = VK_IMAGE_TYPE_2D;
6044         bad_image_ci.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
6045         bad_image_ci.arrayLayers = 6;
6046         bad_image_ci.extent = {64, 64, 2};
6047         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00957");
6048     }
6049 
6050     {
6051         VkImageCreateInfo bad_image_ci = safe_image_ci;
6052         bad_image_ci.imageType = VK_IMAGE_TYPE_3D;
6053         bad_image_ci.arrayLayers = 2;
6054         CreateImageTest(*this, &bad_image_ci, "VUID-VkImageCreateInfo-imageType-00961");
6055     }
6056 }
6057 
TEST_F(VkLayerTest,CreateImageMaxLimitsViolation)6058 TEST_F(VkLayerTest, CreateImageMaxLimitsViolation) {
6059     TEST_DESCRIPTION("Create invalid image with invalid parameters exceeding physical device limits.");
6060 
6061     // Check for VK_KHR_get_physical_device_properties2
6062     bool push_physical_device_properties_2_support =
6063         InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6064     if (push_physical_device_properties_2_support) {
6065         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6066     }
6067 
6068     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6069 
6070     bool push_fragment_density_support = false;
6071 
6072     if (push_physical_device_properties_2_support) {
6073         push_fragment_density_support = DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
6074         if (push_fragment_density_support) m_device_extension_names.push_back(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
6075     }
6076 
6077     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, 0));
6078 
6079     VkImageCreateInfo tmp_img_ci = {};
6080     tmp_img_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6081     tmp_img_ci.flags = 0;                          // assumably any is supported
6082     tmp_img_ci.imageType = VK_IMAGE_TYPE_2D;       // any is supported
6083     tmp_img_ci.format = VK_FORMAT_R8G8B8A8_UNORM;  // has mandatory support for all usages
6084     tmp_img_ci.extent = {1, 1, 1};                 // limit is 256 for 3D, or 4096
6085     tmp_img_ci.mipLevels = 1;                      // any is supported
6086     tmp_img_ci.arrayLayers = 1;                    // limit is 256
6087     tmp_img_ci.samples = VK_SAMPLE_COUNT_1_BIT;    // needs to be 1 if TILING_LINEAR
6088     // if VK_IMAGE_TILING_LINEAR imageType must be 2D, usage must be TRANSFER, and levels layers samplers all 1
6089     tmp_img_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
6090     tmp_img_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;  // depends on format
6091     tmp_img_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6092     const VkImageCreateInfo safe_image_ci = tmp_img_ci;
6093 
6094     ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &safe_image_ci));
6095 
6096     const VkPhysicalDeviceLimits &dev_limits = m_device->props.limits;
6097 
6098     {
6099         VkImageCreateInfo image_ci = safe_image_ci;
6100         image_ci.extent = {8, 8, 1};
6101         image_ci.mipLevels = 4 + 1;  // 4 = log2(8) + 1
6102         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-mipLevels-00958");
6103 
6104         image_ci.extent = {8, 15, 1};
6105         image_ci.mipLevels = 4 + 1;  // 4 = floor(log2(15)) + 1
6106         CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-mipLevels-00958");
6107     }
6108 
6109     {
6110         VkImageCreateInfo image_ci = safe_image_ci;
6111         image_ci.tiling = VK_IMAGE_TILING_LINEAR;
6112         image_ci.extent = {64, 64, 1};
6113         image_ci.format = FindFormatLinearWithoutMips(gpu(), image_ci);
6114         image_ci.mipLevels = 2;
6115 
6116         if (image_ci.format != VK_FORMAT_UNDEFINED) {
6117             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-mipLevels-02255");
6118         } else {
6119             printf("%s Cannot find a format to test maxMipLevels limit; skipping part of test.\n", kSkipPrefix);
6120         }
6121     }
6122 
6123     {
6124         VkImageCreateInfo image_ci = safe_image_ci;
6125 
6126         VkImageFormatProperties img_limits;
6127         ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &image_ci, &img_limits));
6128 
6129         if (img_limits.maxArrayLayers != UINT32_MAX) {
6130             image_ci.arrayLayers = img_limits.maxArrayLayers + 1;
6131             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-arrayLayers-02256");
6132         } else {
6133             printf("%s VkImageFormatProperties::maxArrayLayers is already UINT32_MAX; skipping part of test.\n", kSkipPrefix);
6134         }
6135     }
6136 
6137     {
6138         VkImageCreateInfo image_ci = safe_image_ci;
6139         bool found = FindFormatWithoutSamples(gpu(), image_ci);
6140 
6141         if (found) {
6142             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-samples-02258");
6143         } else {
6144             printf("%s Could not find a format with some unsupported samples; skipping part of test.\n", kSkipPrefix);
6145         }
6146     }
6147 
6148     {
6149         VkImageCreateInfo image_ci = safe_image_ci;
6150         image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;  // (any attachment bit)
6151 
6152         VkImageFormatProperties img_limits;
6153         ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &image_ci, &img_limits));
6154 
6155         if (dev_limits.maxFramebufferWidth != UINT32_MAX) {
6156             image_ci.extent = {dev_limits.maxFramebufferWidth + 1, 64, 1};
6157             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-00964");
6158         } else {
6159             printf("%s VkPhysicalDeviceLimits::maxFramebufferWidth is already UINT32_MAX; skipping part of test.\n", kSkipPrefix);
6160         }
6161 
6162         if (dev_limits.maxFramebufferHeight != UINT32_MAX) {
6163             image_ci.usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;  // try different one too
6164             image_ci.extent = {64, dev_limits.maxFramebufferHeight + 1, 1};
6165             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-00965");
6166         } else {
6167             printf("%s VkPhysicalDeviceLimits::maxFramebufferHeight is already UINT32_MAX; skipping part of test.\n", kSkipPrefix);
6168         }
6169     }
6170 
6171     {
6172         if (!push_fragment_density_support) {
6173             printf("%s VK_EXT_fragment_density_map Extension not supported, skipping tests\n", kSkipPrefix);
6174         } else {
6175             VkImageCreateInfo image_ci = safe_image_ci;
6176             image_ci.usage = VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT;
6177             VkImageFormatProperties img_limits;
6178             ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &image_ci, &img_limits));
6179 
6180             image_ci.extent = {dev_limits.maxFramebufferWidth + 1, 64, 1};
6181             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-02559");
6182 
6183             image_ci.extent = {64, dev_limits.maxFramebufferHeight + 1, 1};
6184             CreateImageTest(*this, &image_ci, "VUID-VkImageCreateInfo-usage-02560");
6185         }
6186     }
6187 }
6188 
TEST_F(VkLayerTest,MultiplaneImageSamplerConversionMismatch)6189 TEST_F(VkLayerTest, MultiplaneImageSamplerConversionMismatch) {
6190     TEST_DESCRIPTION(
6191         "Create sampler with ycbcr conversion and use with an image created without ycrcb conversion or immutable sampler");
6192 
6193     // Enable KHR multiplane req'd extensions
6194     bool mp_extensions = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
6195                                                     VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION);
6196     if (mp_extensions) {
6197         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6198     }
6199     SetTargetApiVersion(VK_API_VERSION_1_1);
6200     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6201     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
6202     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
6203     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
6204     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6205     if (mp_extensions) {
6206         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
6207         m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
6208         m_device_extension_names.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
6209         m_device_extension_names.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6210     } else {
6211         printf("%s test requires KHR multiplane extensions, not available.  Skipping.\n", kSkipPrefix);
6212         return;
6213     }
6214 
6215     // Enable Ycbcr Conversion Features
6216     VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcr_features = {};
6217     ycbcr_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
6218     ycbcr_features.samplerYcbcrConversion = VK_TRUE;
6219     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &ycbcr_features));
6220 
6221     PFN_vkCreateSamplerYcbcrConversionKHR vkCreateSamplerYcbcrConversionFunction = nullptr;
6222     PFN_vkDestroySamplerYcbcrConversionKHR vkDestroySamplerYcbcrConversionFunction = nullptr;
6223 
6224     if (DeviceValidationVersion() >= VK_API_VERSION_1_1) {
6225         vkCreateSamplerYcbcrConversionFunction = vkCreateSamplerYcbcrConversion;
6226         vkDestroySamplerYcbcrConversionFunction = vkDestroySamplerYcbcrConversion;
6227     } else {
6228         vkCreateSamplerYcbcrConversionFunction =
6229             (PFN_vkCreateSamplerYcbcrConversionKHR)vkGetDeviceProcAddr(m_device->handle(), "vkCreateSamplerYcbcrConversionKHR");
6230         vkDestroySamplerYcbcrConversionFunction =
6231             (PFN_vkDestroySamplerYcbcrConversionKHR)vkGetDeviceProcAddr(m_device->handle(), "vkDestroySamplerYcbcrConversionKHR");
6232     }
6233 
6234     if (!vkCreateSamplerYcbcrConversionFunction || !vkDestroySamplerYcbcrConversionFunction) {
6235         printf("%s Did not find required device extension %s; test skipped.\n", kSkipPrefix,
6236                VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6237         return;
6238     }
6239 
6240     ASSERT_NO_FATAL_FAILURE(InitViewport());
6241     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6242 
6243     const VkImageCreateInfo ci = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
6244                                   NULL,
6245                                   0,
6246                                   VK_IMAGE_TYPE_2D,
6247                                   VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR,
6248                                   {128, 128, 1},
6249                                   1,
6250                                   1,
6251                                   VK_SAMPLE_COUNT_1_BIT,
6252                                   VK_IMAGE_TILING_LINEAR,
6253                                   VK_IMAGE_USAGE_SAMPLED_BIT,
6254                                   VK_SHARING_MODE_EXCLUSIVE,
6255                                   VK_IMAGE_LAYOUT_UNDEFINED};
6256 
6257     // Verify formats
6258     bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), ci, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
6259     if (!supported) {
6260         printf("%s Multiplane image format not supported.  Skipping test.\n", kSkipPrefix);
6261         return;
6262     }
6263 
6264     // Create Ycbcr conversion
6265     VkSamplerYcbcrConversionCreateInfo ycbcr_create_info = {VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
6266                                                             NULL,
6267                                                             VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR,
6268                                                             VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
6269                                                             VK_SAMPLER_YCBCR_RANGE_ITU_FULL,
6270                                                             {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
6271                                                              VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY},
6272                                                             VK_CHROMA_LOCATION_COSITED_EVEN,
6273                                                             VK_CHROMA_LOCATION_COSITED_EVEN,
6274                                                             VK_FILTER_NEAREST,
6275                                                             false};
6276     VkSamplerYcbcrConversion conversions[2];
6277     vkCreateSamplerYcbcrConversionFunction(m_device->handle(), &ycbcr_create_info, nullptr, &conversions[0]);
6278     ycbcr_create_info.components.r = VK_COMPONENT_SWIZZLE_ZERO;  // Just anything different than above
6279     vkCreateSamplerYcbcrConversionFunction(m_device->handle(), &ycbcr_create_info, nullptr, &conversions[1]);
6280 
6281     VkSamplerYcbcrConversionInfo ycbcr_info = {};
6282     ycbcr_info.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
6283     ycbcr_info.conversion = conversions[0];
6284 
6285     // Create a sampler using conversion
6286     VkSamplerCreateInfo sci = SafeSaneSamplerCreateInfo();
6287     sci.pNext = &ycbcr_info;
6288     // Create two samplers with two different conversions, such that one will mismatch
6289     // It will make the second sampler fail to see if the log prints the second sampler or the first sampler.
6290     VkSampler samplers[2];
6291     VkResult err = vkCreateSampler(m_device->device(), &sci, NULL, &samplers[0]);
6292     ASSERT_VK_SUCCESS(err);
6293     ycbcr_info.conversion = conversions[1];  // Need two samplers with different conversions
6294     err = vkCreateSampler(m_device->device(), &sci, NULL, &samplers[1]);
6295     ASSERT_VK_SUCCESS(err);
6296 
6297     // Create an image without a Ycbcr conversion
6298     VkImageObj mpimage(m_device);
6299     mpimage.init(&ci);
6300 
6301     VkImageView view;
6302     VkImageViewCreateInfo ivci = {};
6303     ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6304     ycbcr_info.conversion = conversions[0];  // Need two samplers with different conversions
6305     ivci.pNext = &ycbcr_info;
6306     ivci.image = mpimage.handle();
6307     ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
6308     ivci.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR;
6309     ivci.subresourceRange.layerCount = 1;
6310     ivci.subresourceRange.baseMipLevel = 0;
6311     ivci.subresourceRange.levelCount = 1;
6312     ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6313     vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6314 
6315     // Use the image and sampler together in a descriptor set
6316     OneOffDescriptorSet descriptor_set(m_device,
6317                                        {
6318                                            {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_SHADER_STAGE_ALL, samplers},
6319                                        });
6320 
6321     // Use the same image view twice, using the same sampler, with the *second* mismatched with the *second* immutable sampler
6322     VkDescriptorImageInfo image_infos[2];
6323     image_infos[0] = {};
6324     image_infos[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6325     image_infos[0].imageView = view;
6326     image_infos[0].sampler = samplers[0];
6327     image_infos[1] = image_infos[0];
6328 
6329     // Update the descriptor set expecting to get an error
6330     VkWriteDescriptorSet descriptor_write = {};
6331     descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6332     descriptor_write.dstSet = descriptor_set.set_;
6333     descriptor_write.dstBinding = 0;
6334     descriptor_write.descriptorCount = 2;
6335     descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6336     descriptor_write.pImageInfo = image_infos;
6337 
6338     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkWriteDescriptorSet-descriptorType-01948");
6339     vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6340     m_errorMonitor->VerifyFound();
6341 
6342     // pImmutableSamplers = nullptr causes an error , VUID-VkWriteDescriptorSet-descriptorType-02738.
6343     // Because if pNext chains a VkSamplerYcbcrConversionInfo, the sampler has to be a immutable sampler.
6344     OneOffDescriptorSet descriptor_set_1947(m_device,
6345                                             {
6346                                                 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, nullptr},
6347                                             });
6348     descriptor_write.dstSet = descriptor_set_1947.set_;
6349     descriptor_write.descriptorCount = 1;
6350     descriptor_write.pImageInfo = &image_infos[0];
6351     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkWriteDescriptorSet-descriptorType-02738");
6352     vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6353     m_errorMonitor->VerifyFound();
6354 
6355     vkDestroySamplerYcbcrConversionFunction(m_device->device(), conversions[0], nullptr);
6356     vkDestroySamplerYcbcrConversionFunction(m_device->device(), conversions[1], nullptr);
6357     vkDestroyImageView(m_device->device(), view, NULL);
6358     vkDestroySampler(m_device->device(), samplers[0], nullptr);
6359     vkDestroySampler(m_device->device(), samplers[1], nullptr);
6360 }
6361 
TEST_F(VkLayerTest,DepthStencilImageViewWithColorAspectBitError)6362 TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
6363     // Create a single Image descriptor and cause it to first hit an error due
6364     //  to using a DS format, then cause it to hit error due to COLOR_BIT not
6365     //  set in aspect
6366     // The image format check comes 2nd in validation so we trigger it first,
6367     //  then when we cause aspect fail next, bad format check will be preempted
6368 
6369     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6370                                          "Combination depth/stencil image formats can have only the ");
6371 
6372     ASSERT_NO_FATAL_FAILURE(Init());
6373     auto depth_format = FindSupportedDepthStencilFormat(gpu());
6374     if (!depth_format) {
6375         printf("%s Couldn't find depth stencil format.\n", kSkipPrefix);
6376         return;
6377     }
6378 
6379     VkImageObj image_bad(m_device);
6380     VkImageObj image_good(m_device);
6381     // One bad format and one good format for Color attachment
6382     const VkFormat tex_format_bad = depth_format;
6383     const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
6384     const int32_t tex_width = 32;
6385     const int32_t tex_height = 32;
6386 
6387     VkImageCreateInfo image_create_info = {};
6388     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6389     image_create_info.pNext = NULL;
6390     image_create_info.imageType = VK_IMAGE_TYPE_2D;
6391     image_create_info.format = tex_format_bad;
6392     image_create_info.extent.width = tex_width;
6393     image_create_info.extent.height = tex_height;
6394     image_create_info.extent.depth = 1;
6395     image_create_info.mipLevels = 1;
6396     image_create_info.arrayLayers = 1;
6397     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6398     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6399     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
6400     image_create_info.flags = 0;
6401 
6402     image_bad.init(&image_create_info);
6403 
6404     image_create_info.format = tex_format_good;
6405     image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
6406     image_good.init(&image_create_info);
6407 
6408     VkImageViewCreateInfo image_view_create_info = {};
6409     image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6410     image_view_create_info.image = image_bad.handle();
6411     image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6412     image_view_create_info.format = tex_format_bad;
6413     image_view_create_info.subresourceRange.baseArrayLayer = 0;
6414     image_view_create_info.subresourceRange.baseMipLevel = 0;
6415     image_view_create_info.subresourceRange.layerCount = 1;
6416     image_view_create_info.subresourceRange.levelCount = 1;
6417     image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
6418 
6419     VkImageView view;
6420     vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6421     m_errorMonitor->VerifyFound();
6422 }
6423 
TEST_F(VkLayerTest,ExtensionNotEnabled)6424 TEST_F(VkLayerTest, ExtensionNotEnabled) {
6425     TEST_DESCRIPTION("Validate that using an API from an unenabled extension returns an error");
6426 
6427     if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
6428         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6429     } else {
6430         printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
6431                VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6432         return;
6433     }
6434     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6435 
6436     // Required extensions except VK_KHR_GET_MEMORY_REQUIREMENTS_2 -- to create the needed error
6437     std::vector<const char *> required_device_extensions = {VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_BIND_MEMORY_2_EXTENSION_NAME,
6438                                                             VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME};
6439     for (auto dev_ext : required_device_extensions) {
6440         if (DeviceExtensionSupported(gpu(), nullptr, dev_ext)) {
6441             m_device_extension_names.push_back(dev_ext);
6442         } else {
6443             printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, dev_ext);
6444             break;
6445         }
6446     }
6447 
6448     // Need to ignore this error to get to the one we're testing
6449     m_errorMonitor->SetUnexpectedError("VUID-vkCreateDevice-ppEnabledExtensionNames-01387");
6450     ASSERT_NO_FATAL_FAILURE(InitState());
6451 
6452     // Find address of extension API
6453     auto vkCreateSamplerYcbcrConversionKHR =
6454         (PFN_vkCreateSamplerYcbcrConversionKHR)vkGetDeviceProcAddr(m_device->handle(), "vkCreateSamplerYcbcrConversionKHR");
6455     if (vkCreateSamplerYcbcrConversionKHR == nullptr) {
6456         printf("%s VK_KHR_sampler_ycbcr_conversion not supported by device; skipped.\n", kSkipPrefix);
6457         return;
6458     }
6459     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-GeneralParameterError-ExtensionNotEnabled");
6460     VkSamplerYcbcrConversionCreateInfo ycbcr_info = {VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO,
6461                                                      NULL,
6462                                                      VK_FORMAT_UNDEFINED,
6463                                                      VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY,
6464                                                      VK_SAMPLER_YCBCR_RANGE_ITU_FULL,
6465                                                      {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
6466                                                       VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY},
6467                                                      VK_CHROMA_LOCATION_COSITED_EVEN,
6468                                                      VK_CHROMA_LOCATION_COSITED_EVEN,
6469                                                      VK_FILTER_NEAREST,
6470                                                      false};
6471     VkSamplerYcbcrConversion conversion;
6472     vkCreateSamplerYcbcrConversionKHR(m_device->handle(), &ycbcr_info, nullptr, &conversion);
6473     m_errorMonitor->VerifyFound();
6474 }
6475 
TEST_F(VkLayerTest,InvalidCreateBufferSize)6476 TEST_F(VkLayerTest, InvalidCreateBufferSize) {
6477     TEST_DESCRIPTION("Attempt to create VkBuffer with size of zero");
6478 
6479     ASSERT_NO_FATAL_FAILURE(Init());
6480 
6481     VkBufferCreateInfo info = {};
6482     info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6483     info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
6484     info.size = 0;
6485     CreateBufferTest(*this, &info, "VUID-VkBufferCreateInfo-size-00912");
6486 }
6487 
TEST_F(VkLayerTest,DuplicateValidPNextStructures)6488 TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
6489     TEST_DESCRIPTION("Create a pNext chain containing valid structures, but with a duplicate structure type");
6490 
6491     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6492     if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME)) {
6493         m_device_extension_names.push_back(VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME);
6494     } else {
6495         printf("%s VK_NV_dedicated_allocation extension not supported, skipping test\n", kSkipPrefix);
6496         return;
6497     }
6498     ASSERT_NO_FATAL_FAILURE(InitState());
6499 
6500     // Create two pNext structures which by themselves would be valid
6501     VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
6502     VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
6503     dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
6504     dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
6505     dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
6506 
6507     dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
6508     dedicated_buffer_create_info_2.pNext = nullptr;
6509     dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
6510 
6511     uint32_t queue_family_index = 0;
6512     VkBufferCreateInfo buffer_create_info = {};
6513     buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6514     buffer_create_info.pNext = &dedicated_buffer_create_info;
6515     buffer_create_info.size = 1024;
6516     buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6517     buffer_create_info.queueFamilyIndexCount = 1;
6518     buffer_create_info.pQueueFamilyIndices = &queue_family_index;
6519 
6520     CreateBufferTest(*this, &buffer_create_info, "chain contains duplicate structure types");
6521 }
6522 
TEST_F(VkLayerTest,DedicatedAllocation)6523 TEST_F(VkLayerTest, DedicatedAllocation) {
6524     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6525     if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME)) {
6526         m_device_extension_names.push_back(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
6527         m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
6528     } else {
6529         printf("%s Dedicated allocation extension not supported, skipping test\n", kSkipPrefix);
6530         return;
6531     }
6532     ASSERT_NO_FATAL_FAILURE(InitState());
6533 
6534     VkMemoryPropertyFlags mem_flags = 0;
6535     const VkDeviceSize resource_size = 1024;
6536     auto buffer_info = VkBufferObj::create_info(resource_size, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
6537     VkBufferObj buffer;
6538     buffer.init_no_mem(*m_device, buffer_info);
6539     auto buffer_alloc_info = vk_testing::DeviceMemory::get_resource_alloc_info(*m_device, buffer.memory_requirements(), mem_flags);
6540     auto buffer_dedicated_info = lvl_init_struct<VkMemoryDedicatedAllocateInfoKHR>();
6541     buffer_dedicated_info.buffer = buffer.handle();
6542     buffer_alloc_info.pNext = &buffer_dedicated_info;
6543     vk_testing::DeviceMemory dedicated_buffer_memory;
6544     dedicated_buffer_memory.init(*m_device, buffer_alloc_info);
6545 
6546     VkBufferObj wrong_buffer;
6547     wrong_buffer.init_no_mem(*m_device, buffer_info);
6548 
6549     // Bind with wrong buffer
6550     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindBufferMemory-memory-01508");
6551     vkBindBufferMemory(m_device->handle(), wrong_buffer.handle(), dedicated_buffer_memory.handle(), 0);
6552     m_errorMonitor->VerifyFound();
6553 
6554     // Bind with non-zero offset (same VUID)
6555     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6556                                          "VUID-vkBindBufferMemory-memory-01508");  // offset must be zero
6557     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6558                                          "VUID-vkBindBufferMemory-size-01037");  // offset pushes us past size
6559     auto offset = buffer.memory_requirements().alignment;
6560     vkBindBufferMemory(m_device->handle(), buffer.handle(), dedicated_buffer_memory.handle(), offset);
6561     m_errorMonitor->VerifyFound();
6562 
6563     // Bind correctly (depends on the "skip" above)
6564     m_errorMonitor->ExpectSuccess();
6565     vkBindBufferMemory(m_device->handle(), buffer.handle(), dedicated_buffer_memory.handle(), 0);
6566     m_errorMonitor->VerifyNotFound();
6567 
6568     // And for images...
6569     VkImageObj image(m_device);
6570     VkImageObj wrong_image(m_device);
6571     auto image_info = VkImageObj::create_info();
6572     image_info.extent.width = resource_size;
6573     image_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
6574     image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
6575     image.init_no_mem(*m_device, image_info);
6576     wrong_image.init_no_mem(*m_device, image_info);
6577 
6578     auto image_dedicated_info = lvl_init_struct<VkMemoryDedicatedAllocateInfoKHR>();
6579     image_dedicated_info.image = image.handle();
6580     auto image_alloc_info = vk_testing::DeviceMemory::get_resource_alloc_info(*m_device, image.memory_requirements(), mem_flags);
6581     image_alloc_info.pNext = &image_dedicated_info;
6582     vk_testing::DeviceMemory dedicated_image_memory;
6583     dedicated_image_memory.init(*m_device, image_alloc_info);
6584 
6585     // Bind with wrong image
6586     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkBindImageMemory-memory-01509");
6587     vkBindImageMemory(m_device->handle(), wrong_image.handle(), dedicated_image_memory.handle(), 0);
6588     m_errorMonitor->VerifyFound();
6589 
6590     // Bind with non-zero offset (same VUID)
6591     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6592                                          "VUID-vkBindImageMemory-memory-01509");  // offset must be zero
6593     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6594                                          "VUID-vkBindImageMemory-size-01049");  // offset pushes us past size
6595     auto image_offset = image.memory_requirements().alignment;
6596     vkBindImageMemory(m_device->handle(), image.handle(), dedicated_image_memory.handle(), image_offset);
6597     m_errorMonitor->VerifyFound();
6598 
6599     // Bind correctly (depends on the "skip" above)
6600     m_errorMonitor->ExpectSuccess();
6601     vkBindImageMemory(m_device->handle(), image.handle(), dedicated_image_memory.handle(), 0);
6602     m_errorMonitor->VerifyNotFound();
6603 }
6604 
TEST_F(VkLayerTest,CornerSampledImageNV)6605 TEST_F(VkLayerTest, CornerSampledImageNV) {
6606     TEST_DESCRIPTION("Test VK_NV_corner_sampled_image.");
6607 
6608     if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
6609         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6610     } else {
6611         printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
6612                VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6613         return;
6614     }
6615     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6616     std::array<const char *, 1> required_device_extensions = {{VK_NV_CORNER_SAMPLED_IMAGE_EXTENSION_NAME}};
6617     for (auto device_extension : required_device_extensions) {
6618         if (DeviceExtensionSupported(gpu(), nullptr, device_extension)) {
6619             m_device_extension_names.push_back(device_extension);
6620         } else {
6621             printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, device_extension);
6622             return;
6623         }
6624     }
6625 
6626     PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR =
6627         (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR");
6628     ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
6629 
6630     // Create a device that enables exclusive scissor but disables multiViewport
6631     auto corner_sampled_image_features = lvl_init_struct<VkPhysicalDeviceCornerSampledImageFeaturesNV>();
6632     auto features2 = lvl_init_struct<VkPhysicalDeviceFeatures2KHR>(&corner_sampled_image_features);
6633     vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
6634 
6635     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
6636 
6637     VkImageCreateInfo image_create_info = {};
6638     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6639     image_create_info.pNext = NULL;
6640     image_create_info.imageType = VK_IMAGE_TYPE_1D;
6641     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
6642     image_create_info.extent.width = 2;
6643     image_create_info.extent.height = 1;
6644     image_create_info.extent.depth = 1;
6645     image_create_info.mipLevels = 1;
6646     image_create_info.arrayLayers = 1;
6647     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6648     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6649     image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6650     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
6651     image_create_info.queueFamilyIndexCount = 0;
6652     image_create_info.pQueueFamilyIndices = NULL;
6653     image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6654     image_create_info.flags = VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV;
6655 
6656     // image type must be 2D or 3D
6657     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-flags-02050");
6658 
6659     // cube/depth not supported
6660     image_create_info.imageType = VK_IMAGE_TYPE_2D;
6661     image_create_info.extent.height = 2;
6662     image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6663     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-flags-02051");
6664 
6665     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
6666 
6667     // 2D width/height must be > 1
6668     image_create_info.imageType = VK_IMAGE_TYPE_2D;
6669     image_create_info.extent.height = 1;
6670     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-flags-02052");
6671 
6672     // 3D width/height/depth must be > 1
6673     image_create_info.imageType = VK_IMAGE_TYPE_3D;
6674     image_create_info.extent.height = 2;
6675     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-flags-02053");
6676 
6677     image_create_info.imageType = VK_IMAGE_TYPE_2D;
6678 
6679     // Valid # of mip levels
6680     image_create_info.extent = {7, 7, 1};
6681     image_create_info.mipLevels = 3;  // 3 = ceil(log2(7))
6682     CreateImageTest(*this, &image_create_info);
6683 
6684     image_create_info.extent = {8, 8, 1};
6685     image_create_info.mipLevels = 3;  // 3 = ceil(log2(8))
6686     CreateImageTest(*this, &image_create_info);
6687 
6688     image_create_info.extent = {9, 9, 1};
6689     image_create_info.mipLevels = 3;  // 4 = ceil(log2(9))
6690     CreateImageTest(*this, &image_create_info);
6691 
6692     // Invalid # of mip levels
6693     image_create_info.extent = {8, 8, 1};
6694     image_create_info.mipLevels = 4;  // 3 = ceil(log2(8))
6695     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-mipLevels-00958");
6696 }
6697 
TEST_F(VkLayerTest,CreateYCbCrSampler)6698 TEST_F(VkLayerTest, CreateYCbCrSampler) {
6699     TEST_DESCRIPTION("Verify YCbCr sampler creation.");
6700 
6701     // Test requires API 1.1 or (API 1.0 + SamplerYCbCr extension). Request API 1.1
6702     SetTargetApiVersion(VK_API_VERSION_1_1);
6703     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6704 
6705     // In case we don't have API 1.1+, try enabling the extension directly (and it's dependencies)
6706     if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME)) {
6707         m_device_extension_names.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6708         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
6709         m_device_extension_names.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
6710         m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
6711     }
6712 
6713     ASSERT_NO_FATAL_FAILURE(InitState());
6714     VkDevice dev = m_device->device();
6715 
6716     PFN_vkCreateSamplerYcbcrConversionKHR vkCreateSamplerYcbcrConversionFunction = nullptr;
6717     if (DeviceValidationVersion() >= VK_API_VERSION_1_1) {
6718         vkCreateSamplerYcbcrConversionFunction = vkCreateSamplerYcbcrConversion;
6719     } else {
6720         vkCreateSamplerYcbcrConversionFunction =
6721             (PFN_vkCreateSamplerYcbcrConversionKHR)vkGetDeviceProcAddr(m_device->handle(), "vkCreateSamplerYcbcrConversionKHR");
6722     }
6723 
6724     if (!vkCreateSamplerYcbcrConversionFunction) {
6725         printf("%s Did not find required device support for YcbcrSamplerConversion; test skipped.\n", kSkipPrefix);
6726         return;
6727     }
6728 
6729     // Verify we have the requested support
6730     bool ycbcr_support = (DeviceExtensionEnabled(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME) ||
6731                           (DeviceValidationVersion() >= VK_API_VERSION_1_1));
6732     if (!ycbcr_support) {
6733         printf("%s Did not find required device extension %s; test skipped.\n", kSkipPrefix,
6734                VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6735         return;
6736     }
6737 
6738     VkSamplerYcbcrConversion ycbcr_conv = VK_NULL_HANDLE;
6739     VkSamplerYcbcrConversionCreateInfo sycci = {};
6740     sycci.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO;
6741     sycci.format = VK_FORMAT_UNDEFINED;
6742     sycci.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
6743     sycci.ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
6744 
6745     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkSamplerYcbcrConversionCreateInfo-format-01649");
6746     vkCreateSamplerYcbcrConversionFunction(dev, &sycci, NULL, &ycbcr_conv);
6747     m_errorMonitor->VerifyFound();
6748 }
6749 
TEST_F(VkLayerTest,BufferDeviceAddressEXT)6750 TEST_F(VkLayerTest, BufferDeviceAddressEXT) {
6751     TEST_DESCRIPTION("Test VK_EXT_buffer_device_address.");
6752 
6753     if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
6754         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6755     } else {
6756         printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
6757                VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6758         return;
6759     }
6760     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6761     std::array<const char *, 1> required_device_extensions = {{VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME}};
6762     for (auto device_extension : required_device_extensions) {
6763         if (DeviceExtensionSupported(gpu(), nullptr, device_extension)) {
6764             m_device_extension_names.push_back(device_extension);
6765         } else {
6766             printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, device_extension);
6767             return;
6768         }
6769     }
6770 
6771     if (DeviceIsMockICD() || DeviceSimulation()) {
6772         printf("%s MockICD does not support this feature, skipping tests\n", kSkipPrefix);
6773         return;
6774     }
6775 
6776     PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR =
6777         (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR");
6778     ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
6779 
6780     // Create a device that enables buffer_device_address
6781     auto buffer_device_address_features = lvl_init_struct<VkPhysicalDeviceBufferAddressFeaturesEXT>();
6782     auto features2 = lvl_init_struct<VkPhysicalDeviceFeatures2KHR>(&buffer_device_address_features);
6783     vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
6784     buffer_device_address_features.bufferDeviceAddressCaptureReplay = VK_FALSE;
6785 
6786     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
6787     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6788 
6789     PFN_vkGetBufferDeviceAddressEXT vkGetBufferDeviceAddressEXT =
6790         (PFN_vkGetBufferDeviceAddressEXT)vkGetInstanceProcAddr(instance(), "vkGetBufferDeviceAddressEXT");
6791 
6792     VkBufferCreateInfo buffer_create_info = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
6793     buffer_create_info.size = sizeof(uint32_t);
6794     buffer_create_info.usage = VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_EXT;
6795     buffer_create_info.flags = VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_EXT;
6796     CreateBufferTest(*this, &buffer_create_info, "VUID-VkBufferCreateInfo-flags-02605");
6797 
6798     buffer_create_info.flags = 0;
6799     VkBufferDeviceAddressCreateInfoEXT addr_ci = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_CREATE_INFO_EXT};
6800     addr_ci.deviceAddress = 1;
6801     buffer_create_info.pNext = &addr_ci;
6802     CreateBufferTest(*this, &buffer_create_info, "VUID-VkBufferCreateInfo-deviceAddress-02604");
6803 
6804     buffer_create_info.pNext = nullptr;
6805     VkBuffer buffer;
6806     VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
6807     ASSERT_VK_SUCCESS(err);
6808 
6809     VkBufferDeviceAddressInfoEXT info = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_EXT};
6810     info.buffer = buffer;
6811 
6812     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBufferDeviceAddressInfoEXT-buffer-02600");
6813     vkGetBufferDeviceAddressEXT(m_device->device(), &info);
6814     m_errorMonitor->VerifyFound();
6815 
6816     vkDestroyBuffer(m_device->device(), buffer, NULL);
6817 }
6818 
TEST_F(VkLayerTest,BufferDeviceAddressEXTDisabled)6819 TEST_F(VkLayerTest, BufferDeviceAddressEXTDisabled) {
6820     TEST_DESCRIPTION("Test VK_EXT_buffer_device_address.");
6821 
6822     if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
6823         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6824     } else {
6825         printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
6826                VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6827         return;
6828     }
6829     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6830     std::array<const char *, 1> required_device_extensions = {{VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME}};
6831     for (auto device_extension : required_device_extensions) {
6832         if (DeviceExtensionSupported(gpu(), nullptr, device_extension)) {
6833             m_device_extension_names.push_back(device_extension);
6834         } else {
6835             printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, device_extension);
6836             return;
6837         }
6838     }
6839 
6840     if (DeviceIsMockICD() || DeviceSimulation()) {
6841         printf("%s MockICD does not support this feature, skipping tests\n", kSkipPrefix);
6842         return;
6843     }
6844 
6845     PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR =
6846         (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR");
6847     ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
6848 
6849     // Create a device that disables buffer_device_address
6850     auto buffer_device_address_features = lvl_init_struct<VkPhysicalDeviceBufferAddressFeaturesEXT>();
6851     auto features2 = lvl_init_struct<VkPhysicalDeviceFeatures2KHR>(&buffer_device_address_features);
6852     vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
6853     buffer_device_address_features.bufferDeviceAddress = VK_FALSE;
6854     buffer_device_address_features.bufferDeviceAddressCaptureReplay = VK_FALSE;
6855 
6856     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
6857     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6858 
6859     PFN_vkGetBufferDeviceAddressEXT vkGetBufferDeviceAddressEXT =
6860         (PFN_vkGetBufferDeviceAddressEXT)vkGetInstanceProcAddr(instance(), "vkGetBufferDeviceAddressEXT");
6861 
6862     VkBufferCreateInfo buffer_create_info = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
6863     buffer_create_info.size = sizeof(uint32_t);
6864     buffer_create_info.usage = VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_EXT;
6865     CreateBufferTest(*this, &buffer_create_info, "VUID-VkBufferCreateInfo-usage-02606");
6866 
6867     buffer_create_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6868     VkBuffer buffer;
6869     VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
6870     ASSERT_VK_SUCCESS(err);
6871 
6872     VkBufferDeviceAddressInfoEXT info = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_EXT};
6873     info.buffer = buffer;
6874 
6875     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-vkGetBufferDeviceAddressEXT-None-02598");
6876     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBufferDeviceAddressInfoEXT-buffer-02601");
6877     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBufferDeviceAddressInfoEXT-buffer-02600");
6878     vkGetBufferDeviceAddressEXT(m_device->device(), &info);
6879     m_errorMonitor->VerifyFound();
6880 
6881     vkDestroyBuffer(m_device->device(), buffer, NULL);
6882 }
6883 
TEST_F(VkLayerTest,CreateImageYcbcrArrayLayers)6884 TEST_F(VkLayerTest, CreateImageYcbcrArrayLayers) {
6885     TEST_DESCRIPTION("Creating images with out-of-range arrayLayers ");
6886 
6887     // Enable KHR multiplane req'd extensions
6888     bool mp_extensions = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
6889                                                     VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION);
6890     if (mp_extensions) {
6891         m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
6892     }
6893     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6894     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
6895     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
6896     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
6897     mp_extensions = mp_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6898     if (mp_extensions) {
6899         m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
6900         m_device_extension_names.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
6901         m_device_extension_names.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME);
6902         m_device_extension_names.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
6903     } else {
6904         printf("%s test requires KHR multiplane extensions, not available.  Skipping.\n", kSkipPrefix);
6905         return;
6906     }
6907 
6908     ASSERT_NO_FATAL_FAILURE(InitState());
6909     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6910 
6911     // Create ycbcr image with unsupported arrayLayers
6912     VkImageCreateInfo image_create_info = {};
6913     image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6914     image_create_info.imageType = VK_IMAGE_TYPE_2D;
6915     image_create_info.format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
6916     image_create_info.extent.width = 32;
6917     image_create_info.extent.height = 32;
6918     image_create_info.extent.depth = 1;
6919     image_create_info.mipLevels = 1;
6920     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6921     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6922     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6923 
6924     bool supported = ImageFormatAndFeaturesSupported(instance(), gpu(), image_create_info, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
6925     if (!supported) {
6926         printf("%s Multiplane image format not supported.  Skipping test.\n", kSkipPrefix);
6927         return;
6928     }
6929 
6930     VkImageFormatProperties img_limits;
6931     ASSERT_VK_SUCCESS(GPDIFPHelper(gpu(), &image_create_info, &img_limits));
6932     if (img_limits.maxArrayLayers == 1) {
6933         return;
6934     }
6935     image_create_info.arrayLayers = img_limits.maxArrayLayers;
6936 
6937     CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-format-02653");
6938     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkImageCreateInfo-format-02653");
6939 }
6940 
TEST_F(VkLayerTest,BindImageMemorySwapchain)6941 TEST_F(VkLayerTest, BindImageMemorySwapchain) {
6942     TEST_DESCRIPTION("Invalid bind image with a swapchain");
6943     SetTargetApiVersion(VK_API_VERSION_1_1);
6944 
6945     if (!AddSurfaceInstanceExtension()) {
6946         printf("%s surface extensions not supported, skipping BindSwapchainImageMemory test\n", kSkipPrefix);
6947         return;
6948     }
6949 
6950     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
6951 
6952     if (!AddSwapchainDeviceExtension()) {
6953         printf("%s swapchain extensions not supported, skipping BindSwapchainImageMemory test\n", kSkipPrefix);
6954         return;
6955     }
6956 
6957     if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
6958         printf("%s VkBindImageMemoryInfo requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
6959         return;
6960     }
6961 
6962     ASSERT_NO_FATAL_FAILURE(InitState());
6963     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6964     if (!InitSwapchain()) {
6965         printf("%s Cannot create surface or swapchain, skipping BindSwapchainImageMemory test\n", kSkipPrefix);
6966         return;
6967     }
6968 
6969     auto image_create_info = lvl_init_struct<VkImageCreateInfo>();
6970     image_create_info.imageType = VK_IMAGE_TYPE_2D;
6971     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
6972     image_create_info.extent.width = 64;
6973     image_create_info.extent.height = 64;
6974     image_create_info.extent.depth = 1;
6975     image_create_info.mipLevels = 1;
6976     image_create_info.arrayLayers = 1;
6977     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6978     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6979     image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
6980     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6981     image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6982 
6983     auto image_swapchain_create_info = lvl_init_struct<VkImageSwapchainCreateInfoKHR>();
6984     image_swapchain_create_info.swapchain = m_swapchain;
6985     image_create_info.pNext = &image_swapchain_create_info;
6986 
6987     VkImage image_from_swapchain;
6988     vkCreateImage(device(), &image_create_info, NULL, &image_from_swapchain);
6989 
6990     VkMemoryRequirements mem_reqs = {};
6991     vkGetImageMemoryRequirements(device(), image_from_swapchain, &mem_reqs);
6992 
6993     auto alloc_info = lvl_init_struct<VkMemoryAllocateInfo>();
6994     alloc_info.memoryTypeIndex = 0;
6995     alloc_info.allocationSize = mem_reqs.size;
6996 
6997     bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, 0);
6998     ASSERT_TRUE(pass);
6999 
7000     VkDeviceMemory mem;
7001     VkResult err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
7002     ASSERT_VK_SUCCESS(err);
7003 
7004     auto bind_info = lvl_init_struct<VkBindImageMemoryInfo>();
7005     bind_info.image = image_from_swapchain;
7006     bind_info.memory = VK_NULL_HANDLE;
7007     bind_info.memoryOffset = 0;
7008 
7009     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBindImageMemoryInfo-image-01630");
7010     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBindImageMemoryInfo-pNext-01632");
7011     vkBindImageMemory2(m_device->device(), 1, &bind_info);
7012     m_errorMonitor->VerifyFound();
7013 
7014     auto bind_swapchain_info = lvl_init_struct<VkBindImageMemorySwapchainInfoKHR>();
7015     bind_swapchain_info.swapchain = VK_NULL_HANDLE;
7016     bind_swapchain_info.imageIndex = 0;
7017     bind_info.pNext = &bind_swapchain_info;
7018 
7019     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-GeneralParameterError-RequiredParameter");
7020     vkBindImageMemory2(m_device->device(), 1, &bind_info);
7021     m_errorMonitor->VerifyFound();
7022 
7023     bind_info.memory = mem;
7024     bind_swapchain_info.swapchain = m_swapchain;
7025     bind_swapchain_info.imageIndex = UINT32_MAX;
7026 
7027     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBindImageMemoryInfo-pNext-01631");
7028     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkBindImageMemorySwapchainInfoKHR-imageIndex-01644");
7029     vkBindImageMemory2(m_device->device(), 1, &bind_info);
7030     m_errorMonitor->VerifyFound();
7031 
7032     vkDestroyImage(m_device->device(), image_from_swapchain, NULL);
7033     vkFreeMemory(m_device->device(), mem, NULL);
7034     DestroySwapchain();
7035 }
7036 
TEST_F(VkLayerTest,TransferImageToSwapchainWithInvalidLayoutDeviceGroup)7037 TEST_F(VkLayerTest, TransferImageToSwapchainWithInvalidLayoutDeviceGroup) {
7038     TEST_DESCRIPTION("Transfer an image to a swapchain's image with a invalid layout between device group");
7039 
7040 #if defined(VK_USE_PLATFORM_ANDROID_KHR)
7041     printf(
7042         "%s According to VUID-01631, VkBindImageMemoryInfo-memory should be NULL. But Android will crash if memory is NULL, "
7043         "skipping test\n",
7044         kSkipPrefix);
7045     return;
7046 #endif
7047 
7048     SetTargetApiVersion(VK_API_VERSION_1_1);
7049 
7050     if (!AddSurfaceInstanceExtension()) {
7051         printf("%s surface extensions not supported, skipping test\n", kSkipPrefix);
7052         return;
7053     }
7054 
7055     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
7056 
7057     if (!AddSwapchainDeviceExtension()) {
7058         printf("%s swapchain extensions not supported, skipping test\n", kSkipPrefix);
7059         return;
7060     }
7061 
7062     if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
7063         printf("%s VkBindImageMemoryInfo requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
7064         return;
7065     }
7066     uint32_t physical_device_group_count = 0;
7067     vkEnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, nullptr);
7068 
7069     if (physical_device_group_count == 0) {
7070         printf("%s physical_device_group_count is 0, skipping test\n", kSkipPrefix);
7071         return;
7072     }
7073 
7074     std::vector<VkPhysicalDeviceGroupProperties> physical_device_group(physical_device_group_count,
7075                                                                        {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
7076     vkEnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, physical_device_group.data());
7077     VkDeviceGroupDeviceCreateInfo create_device_pnext = {};
7078     create_device_pnext.sType = VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO;
7079     create_device_pnext.physicalDeviceCount = physical_device_group[0].physicalDeviceCount;
7080     create_device_pnext.pPhysicalDevices = physical_device_group[0].physicalDevices;
7081     ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &create_device_pnext));
7082     ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7083     if (!InitSwapchain(VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
7084         printf("%s Cannot create surface or swapchain, skipping test\n", kSkipPrefix);
7085         return;
7086     }
7087 
7088     auto image_create_info = lvl_init_struct<VkImageCreateInfo>();
7089     image_create_info.imageType = VK_IMAGE_TYPE_2D;
7090     image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
7091     image_create_info.extent.width = 64;
7092     image_create_info.extent.height = 64;
7093     image_create_info.extent.depth = 1;
7094     image_create_info.mipLevels = 1;
7095     image_create_info.arrayLayers = 1;
7096     image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7097     image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7098     image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7099     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7100     image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7101 
7102     VkImageObj src_Image(m_device);
7103     src_Image.init(&image_create_info);
7104 
7105     image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
7106     image_create_info.flags = VK_IMAGE_CREATE_ALIAS_BIT;
7107 
7108     auto image_swapchain_create_info = lvl_init_struct<VkImageSwapchainCreateInfoKHR>();
7109     image_swapchain_create_info.swapchain = m_swapchain;
7110     image_create_info.pNext = &image_swapchain_create_info;
7111 
7112     VkImage peer_image;
7113     vkCreateImage(device(), &image_create_info, NULL, &peer_image);
7114 
7115     auto bind_devicegroup_info = lvl_init_struct<VkBindImageMemoryDeviceGroupInfo>();
7116     bind_devicegroup_info.deviceIndexCount = 2;
7117     std::array<uint32_t, 2> deviceIndices = {0, 0};
7118     bind_devicegroup_info.pDeviceIndices = deviceIndices.data();
7119     bind_devicegroup_info.splitInstanceBindRegionCount = 0;
7120     bind_devicegroup_info.pSplitInstanceBindRegions = nullptr;
7121 
7122     auto bind_swapchain_info = lvl_init_struct<VkBindImageMemorySwapchainInfoKHR>(&bind_devicegroup_info);
7123     bind_swapchain_info.swapchain = m_swapchain;
7124     bind_swapchain_info.imageIndex = 0;
7125 
7126     auto bind_info = lvl_init_struct<VkBindImageMemoryInfo>(&bind_swapchain_info);
7127     bind_info.image = peer_image;
7128     bind_info.memory = VK_NULL_HANDLE;
7129     bind_info.memoryOffset = 0;
7130 
7131     vkBindImageMemory2(m_device->device(), 1, &bind_info);
7132 
7133     uint32_t swapchain_images_count = 0;
7134     vkGetSwapchainImagesKHR(device(), m_swapchain, &swapchain_images_count, nullptr);
7135     std::vector<VkImage> swapchain_images;
7136     swapchain_images.resize(swapchain_images_count);
7137     vkGetSwapchainImagesKHR(device(), m_swapchain, &swapchain_images_count, swapchain_images.data());
7138 
7139     m_commandBuffer->begin();
7140 
7141     VkImageCopy copy_region = {};
7142     copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7143     copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7144     copy_region.srcSubresource.mipLevel = 0;
7145     copy_region.dstSubresource.mipLevel = 0;
7146     copy_region.srcSubresource.baseArrayLayer = 0;
7147     copy_region.dstSubresource.baseArrayLayer = 0;
7148     copy_region.srcSubresource.layerCount = 1;
7149     copy_region.dstSubresource.layerCount = 1;
7150     copy_region.srcOffset = {0, 0, 0};
7151     copy_region.dstOffset = {0, 0, 0};
7152     copy_region.extent = {10, 10, 1};
7153     vkCmdCopyImage(m_commandBuffer->handle(), src_Image.handle(), VK_IMAGE_LAYOUT_GENERAL, peer_image,
7154                    VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
7155 
7156     m_commandBuffer->end();
7157 
7158     VkSubmitInfo submit_info = {};
7159     submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7160     submit_info.commandBufferCount = 1;
7161     submit_info.pCommandBuffers = &m_commandBuffer->handle();
7162 
7163     m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout");
7164     vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7165     m_errorMonitor->VerifyFound();
7166 
7167     vkDestroyImage(m_device->device(), peer_image, NULL);
7168     DestroySwapchain();
7169 }
7170