1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group 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 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Buffer and image memory requirements tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktMemoryRequirementsTests.hpp"
25 #include "vktTestCaseUtil.hpp"
26 #include "vktTestGroupUtil.hpp"
27
28 #include "vkDefs.hpp"
29 #include "vkRef.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkMemUtil.hpp"
32 #include "vkQueryUtil.hpp"
33 #include "vkStrUtil.hpp"
34 #include "vkTypeUtil.hpp"
35 #include "vkImageUtil.hpp"
36
37 #include "deUniquePtr.hpp"
38 #include "deStringUtil.hpp"
39 #include "deSTLUtil.hpp"
40
41 #include "tcuResultCollector.hpp"
42 #include "tcuTestLog.hpp"
43
44 namespace vkt
45 {
46 namespace memory
47 {
48 namespace
49 {
50 using namespace vk;
51 using de::MovePtr;
52 using tcu::TestLog;
53
makeBuffer(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage)54 Move<VkBuffer> makeBuffer (const DeviceInterface& vk, const VkDevice device, const VkDeviceSize size, const VkBufferCreateFlags flags, const VkBufferUsageFlags usage)
55 {
56 const VkBufferCreateInfo createInfo =
57 {
58 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
59 DE_NULL, // const void* pNext;
60 flags, // VkBufferCreateFlags flags;
61 size, // VkDeviceSize size;
62 usage, // VkBufferUsageFlags usage;
63 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
64 0u, // uint32_t queueFamilyIndexCount;
65 DE_NULL, // const uint32_t* pQueueFamilyIndices;
66 };
67 return createBuffer(vk, device, &createInfo);
68 }
69
getBufferMemoryRequirements(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage)70 VkMemoryRequirements getBufferMemoryRequirements (const DeviceInterface& vk, const VkDevice device, const VkDeviceSize size, const VkBufferCreateFlags flags, const VkBufferUsageFlags usage)
71 {
72 const Unique<VkBuffer> buffer(makeBuffer(vk, device, size, flags, usage));
73 return getBufferMemoryRequirements(vk, device, *buffer);
74 }
75
getBufferMemoryRequirements2(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage,void * next=DE_NULL)76 VkMemoryRequirements getBufferMemoryRequirements2 (const DeviceInterface& vk, const VkDevice device, const VkDeviceSize size, const VkBufferCreateFlags flags, const VkBufferUsageFlags usage, void* next = DE_NULL)
77 {
78 const Unique<VkBuffer> buffer (makeBuffer(vk, device, size, flags, usage));
79 VkBufferMemoryRequirementsInfo2 info =
80 {
81 VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR, // VkStructureType sType
82 DE_NULL, // const void* pNext
83 *buffer // VkBuffer buffer
84 };
85 VkMemoryRequirements2 req2 =
86 {
87 VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, // VkStructureType sType
88 next, // void* pNext
89 {0, 0, 0} // VkMemoryRequirements memoryRequirements
90 };
91
92 vk.getBufferMemoryRequirements2(device, &info, &req2);
93
94 return req2.memoryRequirements;
95 }
96
getBufferCreateInfoMemoryRequirementsKHR(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage,void * next=DE_NULL)97 VkMemoryRequirements getBufferCreateInfoMemoryRequirementsKHR (const DeviceInterface& vk, const VkDevice device, const VkDeviceSize size, const VkBufferCreateFlags flags, const VkBufferUsageFlags usage, void* next = DE_NULL)
98 {
99 const VkBufferCreateInfo createInfo =
100 {
101 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
102 DE_NULL, // const void* pNext;
103 flags, // VkBufferCreateFlags flags;
104 size, // VkDeviceSize size;
105 usage, // VkBufferUsageFlags usage;
106 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
107 0u, // uint32_t queueFamilyIndexCount;
108 DE_NULL, // const uint32_t* pQueueFamilyIndices;
109 };
110 const VkDeviceBufferMemoryRequirementsKHR memoryInfo =
111 {
112 VK_STRUCTURE_TYPE_DEVICE_BUFFER_MEMORY_REQUIREMENTS_KHR,
113 DE_NULL,
114 &createInfo
115 };
116 VkMemoryRequirements2 req2 =
117 {
118 VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, // VkStructureType sType
119 next, // void* pNext
120 {0, 0, 0} // VkMemoryRequirements memoryRequirements
121 };
122
123 vk.getDeviceBufferMemoryRequirements(device, &memoryInfo, &req2);
124
125 return req2.memoryRequirements;
126 }
127
getImageMemoryRequirements2(const DeviceInterface & vk,const VkDevice device,const VkImageCreateInfo & createInfo,void * next=DE_NULL)128 VkMemoryRequirements getImageMemoryRequirements2 (const DeviceInterface& vk, const VkDevice device, const VkImageCreateInfo& createInfo, void* next = DE_NULL)
129 {
130 const Unique<VkImage> image(createImage(vk, device, &createInfo));
131
132 VkImageMemoryRequirementsInfo2 info =
133 {
134 VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR, // VkStructureType sType
135 DE_NULL, // const void* pNext
136 *image // VkImage image
137 };
138 VkMemoryRequirements2 req2 =
139 {
140 VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, // VkStructureType sType
141 next, // void* pNext
142 {0, 0, 0} // VkMemoryRequirements memoryRequirements
143 };
144
145 vk.getImageMemoryRequirements2(device, &info, &req2);
146
147 return req2.memoryRequirements;
148 }
149
getDeviceImageMemoryRequirements(const DeviceInterface & vk,const VkDevice device,const VkImageCreateInfo & createInfo,void * next=DE_NULL)150 VkMemoryRequirements getDeviceImageMemoryRequirements (const DeviceInterface& vk, const VkDevice device, const VkImageCreateInfo& createInfo, void* next = DE_NULL)
151 {
152 VkDeviceImageMemoryRequirementsKHR info =
153 {
154 VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS_KHR,
155 DE_NULL,
156 &createInfo,
157 VkImageAspectFlagBits(0)
158 };
159 VkMemoryRequirements2 req2 =
160 {
161 VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, // VkStructureType sType
162 next, // void* pNext
163 {0, 0, 0} // VkMemoryRequirements memoryRequirements
164 };
165
166 vk.getDeviceImageMemoryRequirements(device, &info, &req2);
167
168 return req2.memoryRequirements;
169 }
170
getImageCreateInfoSparseMemoryRequirements(const DeviceInterface & vk,VkDevice device,const VkImageCreateInfo & createInfo)171 std::vector<VkSparseImageMemoryRequirements> getImageCreateInfoSparseMemoryRequirements (const DeviceInterface& vk, VkDevice device, const VkImageCreateInfo& createInfo)
172 {
173 VkDeviceImageMemoryRequirementsKHR info =
174 {
175 VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS_KHR,
176 DE_NULL,
177 &createInfo,
178 VkImageAspectFlagBits(0)
179 };
180 deUint32 requirementsCount = 0;
181 std::vector<VkSparseImageMemoryRequirements> requirements;
182 std::vector<VkSparseImageMemoryRequirements2> requirements2;
183
184 vk.getDeviceImageSparseMemoryRequirements(device, &info, &requirementsCount, DE_NULL);
185
186 if (requirementsCount > 0)
187 {
188 requirements2.resize(requirementsCount);
189 for (deUint32 ndx = 0; ndx < requirementsCount; ++ndx)
190 {
191 requirements2[ndx].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2;
192 requirements2[ndx].pNext = DE_NULL;
193 }
194
195 vk.getDeviceImageSparseMemoryRequirements(device, &info, &requirementsCount, &requirements2[0]);
196
197 if ((size_t)requirementsCount != requirements2.size())
198 TCU_FAIL("Returned sparse image memory requirements count changes between queries");
199
200 requirements.resize(requirementsCount);
201 for (deUint32 ndx = 0; ndx < requirementsCount; ++ndx)
202 requirements[ndx] = requirements2[ndx].memoryRequirements;
203 }
204
205 return requirements;
206 }
207
208 //! Get an index of each set bit, starting from the least significant bit.
bitsToIndices(deUint32 bits)209 std::vector<deUint32> bitsToIndices (deUint32 bits)
210 {
211 std::vector<deUint32> indices;
212 for (deUint32 i = 0u; bits != 0u; ++i, bits >>= 1)
213 {
214 if (bits & 1u)
215 indices.push_back(i);
216 }
217 return indices;
218 }
219
220 template<typename T>
nextEnum(T value)221 T nextEnum (T value)
222 {
223 return static_cast<T>(static_cast<deUint32>(value) + 1);
224 }
225
226 template<typename T>
nextFlag(T value)227 T nextFlag (T value)
228 {
229 if (value)
230 return static_cast<T>(static_cast<deUint32>(value) << 1);
231 else
232 return static_cast<T>(1);
233 }
234
235 template<typename T>
nextFlagExcluding(T value,T excludedFlags)236 T nextFlagExcluding (T value, T excludedFlags)
237 {
238 deUint32 tmp = static_cast<deUint32>(value);
239 while ((tmp = nextFlag(tmp)) & static_cast<deUint32>(excludedFlags));
240 return static_cast<T>(tmp);
241 }
242
validValueVkBool32(const VkBool32 value)243 bool validValueVkBool32 (const VkBool32 value)
244 {
245 return (value == VK_FALSE || value == VK_TRUE);
246 }
247
248 class IBufferMemoryRequirements
249 {
250 public:
251 virtual void populateTestGroup (tcu::TestCaseGroup* group) = 0;
252
253 protected:
254 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
255 const std::string& name,
256 const std::string& desc,
257 VkBufferCreateFlags arg0) = 0;
258
259 virtual tcu::TestStatus execTest (Context& context,
260 const VkBufferCreateFlags bufferFlags) = 0;
261
262 virtual void updateMemoryRequirements (const DeviceInterface& vk,
263 const VkDevice device,
264 const VkDeviceSize size,
265 const VkBufferCreateFlags flags,
266 const VkBufferUsageFlags usage,
267 const bool all) = 0;
268
269 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
270 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
271 const VkPhysicalDeviceLimits& limits,
272 const VkBufferCreateFlags bufferFlags,
273 const VkBufferUsageFlags usage) = 0;
274 };
275
276 class BufferMemoryRequirementsOriginal : public IBufferMemoryRequirements
277 {
278 static tcu::TestStatus testEntryPoint (Context& context,
279 const VkBufferCreateFlags bufferFlags);
280
281 public:
282 virtual void populateTestGroup (tcu::TestCaseGroup* group);
283
284 protected:
285 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
286 const std::string& name,
287 const std::string& desc,
288 VkBufferCreateFlags arg0);
289
290 virtual tcu::TestStatus execTest (Context& context,
291 const VkBufferCreateFlags bufferFlags);
292
293 virtual void updateMemoryRequirements (const DeviceInterface& vk,
294 const VkDevice device,
295 const VkDeviceSize size,
296 const VkBufferCreateFlags flags,
297 const VkBufferUsageFlags usage,
298 const bool all);
299
300 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
301 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
302 const VkPhysicalDeviceLimits& limits,
303 const VkBufferCreateFlags bufferFlags,
304 const VkBufferUsageFlags usage);
305
306 protected:
307 VkMemoryRequirements m_allUsageFlagsRequirements;
308 VkMemoryRequirements m_currentTestRequirements;
309 };
310
311
testEntryPoint(Context & context,const VkBufferCreateFlags bufferFlags)312 tcu::TestStatus BufferMemoryRequirementsOriginal::testEntryPoint (Context& context, const VkBufferCreateFlags bufferFlags)
313 {
314 BufferMemoryRequirementsOriginal test;
315
316 return test.execTest(context, bufferFlags);
317 }
318
populateTestGroup(tcu::TestCaseGroup * group)319 void BufferMemoryRequirementsOriginal::populateTestGroup (tcu::TestCaseGroup* group)
320 {
321 const struct
322 {
323 VkBufferCreateFlags flags;
324 const char* const name;
325 } bufferCases[] =
326 {
327 { (VkBufferCreateFlags)0, "regular" },
328 { VK_BUFFER_CREATE_SPARSE_BINDING_BIT, "sparse" },
329 { VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT, "sparse_residency" },
330 { VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, "sparse_aliased" },
331 { VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, "sparse_residency_aliased" },
332 };
333
334 de::MovePtr<tcu::TestCaseGroup> bufferGroup(new tcu::TestCaseGroup(group->getTestContext(), "buffer", ""));
335
336 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(bufferCases); ++ndx)
337 addFunctionTestCase(bufferGroup.get(), bufferCases[ndx].name, "", bufferCases[ndx].flags);
338
339 group->addChild(bufferGroup.release());
340 }
341
checkSupportBufferMemoryRequirementsOriginal(Context & context,VkBufferCreateFlags flags)342 void checkSupportBufferMemoryRequirementsOriginal (Context& context, VkBufferCreateFlags flags)
343 {
344 if (flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
345 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_BINDING);
346
347 if (flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT)
348 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_BUFFER);
349
350 if (flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)
351 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_ALIASED);
352 }
353
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,VkBufferCreateFlags arg0)354 void BufferMemoryRequirementsOriginal::addFunctionTestCase (tcu::TestCaseGroup* group,
355 const std::string& name,
356 const std::string& desc,
357 VkBufferCreateFlags arg0)
358 {
359 addFunctionCase(group, name, desc, checkSupportBufferMemoryRequirementsOriginal, testEntryPoint, arg0);
360 }
361
execTest(Context & context,const VkBufferCreateFlags bufferFlags)362 tcu::TestStatus BufferMemoryRequirementsOriginal::execTest (Context& context, const VkBufferCreateFlags bufferFlags)
363 {
364 const DeviceInterface& vk = context.getDeviceInterface();
365 const InstanceInterface& vki = context.getInstanceInterface();
366 const VkDevice device = context.getDevice();
367 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
368
369 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(vki, physDevice);
370 const VkPhysicalDeviceLimits limits = getPhysicalDeviceProperties(vki, physDevice).limits;
371 const VkBufferUsageFlags allUsageFlags = static_cast<VkBufferUsageFlags>((VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT << 1) - 1);
372 tcu::TestLog& log = context.getTestContext().getLog();
373 bool allPass = true;
374
375 const VkDeviceSize sizeCases[] =
376 {
377 1 * 1024,
378 8 * 1024,
379 64 * 1024,
380 1024 * 1024,
381 };
382
383 // Updates m_allUsageFlags* fields
384 updateMemoryRequirements(vk, device, 1024, bufferFlags, allUsageFlags, true); // doesn't depend on size
385
386 for (VkBufferUsageFlags usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; usage <= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; usage = nextFlag(usage))
387 {
388 deUint32 previousMemoryTypeBits = 0u;
389 VkDeviceSize previousAlignment = 0u;
390
391 log << tcu::TestLog::Message << "Verify a buffer with usage flags: " << de::toString(getBufferUsageFlagsStr(usage)) << tcu::TestLog::EndMessage;
392
393 for (const VkDeviceSize* pSize = sizeCases; pSize < sizeCases + DE_LENGTH_OF_ARRAY(sizeCases); ++pSize)
394 {
395 log << tcu::TestLog::Message << "- size " << *pSize << " bytes" << tcu::TestLog::EndMessage;
396
397 tcu::ResultCollector result(log, "ERROR: ");
398
399 // Updates m_allUsageFlags* fields
400 updateMemoryRequirements(vk, device, *pSize, bufferFlags, usage, false);
401
402 // Check:
403 // - requirements for a particular buffer usage
404 // - memoryTypeBits are a subset of bits for requirements with all usage flags combined
405 verifyMemoryRequirements(result, memoryProperties, limits, bufferFlags, usage);
406
407 // Check that for the same usage and create flags:
408 // - memoryTypeBits are the same
409 // - alignment is the same
410 if (pSize > sizeCases)
411 {
412 result.check(m_currentTestRequirements.memoryTypeBits == previousMemoryTypeBits,
413 "memoryTypeBits differ from the ones in the previous buffer size");
414
415 result.check(m_currentTestRequirements.alignment == previousAlignment,
416 "alignment differs from the one in the previous buffer size");
417 }
418
419 if (result.getResult() != QP_TEST_RESULT_PASS)
420 allPass = false;
421
422 previousMemoryTypeBits = m_currentTestRequirements.memoryTypeBits;
423 previousAlignment = m_currentTestRequirements.alignment;
424 }
425
426 if (!allPass)
427 break;
428 }
429
430 return allPass ? tcu::TestStatus::pass("Pass") : tcu::TestStatus::fail("Some memory requirements were incorrect");
431 }
432
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage,const bool all)433 void BufferMemoryRequirementsOriginal::updateMemoryRequirements (const DeviceInterface& vk,
434 const VkDevice device,
435 const VkDeviceSize size,
436 const VkBufferCreateFlags flags,
437 const VkBufferUsageFlags usage,
438 const bool all)
439 {
440 if (all)
441 {
442 m_allUsageFlagsRequirements = getBufferMemoryRequirements(vk, device, size, flags, usage);
443 }
444 else
445 {
446 m_currentTestRequirements = getBufferMemoryRequirements(vk, device, size, flags, usage);
447 }
448 }
449
verifyMemoryRequirements(tcu::ResultCollector & result,const VkPhysicalDeviceMemoryProperties & deviceMemoryProperties,const VkPhysicalDeviceLimits & limits,const VkBufferCreateFlags bufferFlags,const VkBufferUsageFlags usage)450 void BufferMemoryRequirementsOriginal::verifyMemoryRequirements (tcu::ResultCollector& result,
451 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
452 const VkPhysicalDeviceLimits& limits,
453 const VkBufferCreateFlags bufferFlags,
454 const VkBufferUsageFlags usage)
455 {
456 if (result.check(m_currentTestRequirements.memoryTypeBits != 0, "VkMemoryRequirements memoryTypeBits has no bits set"))
457 {
458 typedef std::vector<deUint32>::const_iterator IndexIterator;
459 const std::vector<deUint32> usedMemoryTypeIndices = bitsToIndices(m_currentTestRequirements.memoryTypeBits);
460 bool deviceLocalMemoryFound = false;
461 bool hostVisibleCoherentMemoryFound = false;
462
463 for (IndexIterator memoryTypeNdx = usedMemoryTypeIndices.begin(); memoryTypeNdx != usedMemoryTypeIndices.end(); ++memoryTypeNdx)
464 {
465 if (*memoryTypeNdx >= deviceMemoryProperties.memoryTypeCount)
466 {
467 result.fail("VkMemoryRequirements memoryTypeBits contains bits for non-existing memory types");
468 continue;
469 }
470
471 const VkMemoryPropertyFlags memoryPropertyFlags = deviceMemoryProperties.memoryTypes[*memoryTypeNdx].propertyFlags;
472
473 if (memoryPropertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
474 deviceLocalMemoryFound = true;
475
476 if (memoryPropertyFlags & (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
477 hostVisibleCoherentMemoryFound = true;
478
479 result.check((memoryPropertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) == 0u,
480 "Memory type includes VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT");
481 }
482
483 result.check(deIsPowerOfTwo64(static_cast<deUint64>(m_currentTestRequirements.alignment)) == DE_TRUE,
484 "VkMemoryRequirements alignment isn't power of two");
485
486 if (usage & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT))
487 {
488 result.check(m_currentTestRequirements.alignment >= limits.minTexelBufferOffsetAlignment,
489 "VkMemoryRequirements alignment doesn't respect minTexelBufferOffsetAlignment");
490 }
491
492 if (usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
493 {
494 result.check(m_currentTestRequirements.alignment >= limits.minUniformBufferOffsetAlignment,
495 "VkMemoryRequirements alignment doesn't respect minUniformBufferOffsetAlignment");
496 }
497
498 if (usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)
499 {
500 result.check(m_currentTestRequirements.alignment >= limits.minStorageBufferOffsetAlignment,
501 "VkMemoryRequirements alignment doesn't respect minStorageBufferOffsetAlignment");
502 }
503
504 result.check(deviceLocalMemoryFound,
505 "None of the required memory types included VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT");
506
507 result.check((bufferFlags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) || hostVisibleCoherentMemoryFound,
508 "Required memory type doesn't include VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT");
509
510 result.check((m_currentTestRequirements.memoryTypeBits & m_allUsageFlagsRequirements.memoryTypeBits) == m_allUsageFlagsRequirements.memoryTypeBits,
511 "Memory type bits aren't a superset of memory type bits for all usage flags combined");
512 }
513 }
514
515 class BufferMemoryRequirementsExtended : public BufferMemoryRequirementsOriginal
516 {
517 static tcu::TestStatus testEntryPoint (Context& context,
518 const VkBufferCreateFlags bufferFlags);
519
520 protected:
521 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
522 const std::string& name,
523 const std::string& desc,
524 VkBufferCreateFlags arg0);
525
526 virtual void updateMemoryRequirements (const DeviceInterface& vk,
527 const VkDevice device,
528 const VkDeviceSize size,
529 const VkBufferCreateFlags flags,
530 const VkBufferUsageFlags usage,
531 const bool all);
532 };
533
testEntryPoint(Context & context,const VkBufferCreateFlags bufferFlags)534 tcu::TestStatus BufferMemoryRequirementsExtended::testEntryPoint (Context& context, const VkBufferCreateFlags bufferFlags)
535 {
536 BufferMemoryRequirementsExtended test;
537
538 return test.execTest(context, bufferFlags);
539 }
540
checkSupportBufferMemoryRequirementsExtended(Context & context,VkBufferCreateFlags flags)541 void checkSupportBufferMemoryRequirementsExtended (Context& context, VkBufferCreateFlags flags)
542 {
543 checkSupportBufferMemoryRequirementsOriginal(context, flags);
544
545 context.requireDeviceFunctionality("VK_KHR_get_memory_requirements2");
546 }
547
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,VkBufferCreateFlags arg0)548 void BufferMemoryRequirementsExtended::addFunctionTestCase (tcu::TestCaseGroup* group,
549 const std::string& name,
550 const std::string& desc,
551 VkBufferCreateFlags arg0)
552 {
553 addFunctionCase(group, name, desc, checkSupportBufferMemoryRequirementsExtended, testEntryPoint, arg0);
554 }
555
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage,const bool all)556 void BufferMemoryRequirementsExtended::updateMemoryRequirements (const DeviceInterface& vk,
557 const VkDevice device,
558 const VkDeviceSize size,
559 const VkBufferCreateFlags flags,
560 const VkBufferUsageFlags usage,
561 const bool all)
562 {
563 if (all)
564 {
565 m_allUsageFlagsRequirements = getBufferMemoryRequirements2(vk, device, size, flags, usage);
566 }
567 else
568 {
569 m_currentTestRequirements = getBufferMemoryRequirements2(vk, device, size, flags, usage);
570 }
571 }
572
573
574 class BufferMemoryRequirementsDedicatedAllocation : public BufferMemoryRequirementsExtended
575 {
576 static tcu::TestStatus testEntryPoint (Context& context,
577 const VkBufferCreateFlags bufferFlags);
578
579 protected:
580 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
581 const std::string& name,
582 const std::string& desc,
583 VkBufferCreateFlags arg0);
584
585 virtual void updateMemoryRequirements (const DeviceInterface& vk,
586 const VkDevice device,
587 const VkDeviceSize size,
588 const VkBufferCreateFlags flags,
589 const VkBufferUsageFlags usage,
590 const bool all);
591
592 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
593 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
594 const VkPhysicalDeviceLimits& limits,
595 const VkBufferCreateFlags bufferFlags,
596 const VkBufferUsageFlags usage);
597
598 protected:
599 VkBool32 m_allUsageFlagsPrefersDedicatedAllocation;
600 VkBool32 m_allUsageFlagsRequiresDedicatedAllocation;
601
602 VkBool32 m_currentTestPrefersDedicatedAllocation;
603 VkBool32 m_currentTestRequiresDedicatedAllocation;
604 };
605
606
testEntryPoint(Context & context,const VkBufferCreateFlags bufferFlags)607 tcu::TestStatus BufferMemoryRequirementsDedicatedAllocation::testEntryPoint(Context& context, const VkBufferCreateFlags bufferFlags)
608 {
609 BufferMemoryRequirementsDedicatedAllocation test;
610
611 return test.execTest(context, bufferFlags);
612 }
613
checkSupportBufferMemoryRequirementsDedicatedAllocation(Context & context,VkBufferCreateFlags flags)614 void checkSupportBufferMemoryRequirementsDedicatedAllocation (Context& context, VkBufferCreateFlags flags)
615 {
616 checkSupportBufferMemoryRequirementsExtended(context, flags);
617
618 context.requireDeviceFunctionality("VK_KHR_dedicated_allocation");
619 }
620
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,VkBufferCreateFlags arg0)621 void BufferMemoryRequirementsDedicatedAllocation::addFunctionTestCase (tcu::TestCaseGroup* group,
622 const std::string& name,
623 const std::string& desc,
624 VkBufferCreateFlags arg0)
625 {
626 addFunctionCase(group, name, desc, checkSupportBufferMemoryRequirementsDedicatedAllocation, testEntryPoint, arg0);
627 }
628
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage,const bool all)629 void BufferMemoryRequirementsDedicatedAllocation::updateMemoryRequirements (const DeviceInterface& vk,
630 const VkDevice device,
631 const VkDeviceSize size,
632 const VkBufferCreateFlags flags,
633 const VkBufferUsageFlags usage,
634 const bool all)
635 {
636 const deUint32 invalidVkBool32 = static_cast<deUint32>(~0);
637
638 VkMemoryDedicatedRequirements dedicatedRequirements =
639 {
640 VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, // VkStructureType sType
641 DE_NULL, // void* pNext
642 invalidVkBool32, // VkBool32 prefersDedicatedAllocation
643 invalidVkBool32 // VkBool32 requiresDedicatedAllocation
644 };
645
646 if (all)
647 {
648 m_allUsageFlagsRequirements = getBufferMemoryRequirements2(vk, device, size, flags, usage, &dedicatedRequirements);
649 m_allUsageFlagsPrefersDedicatedAllocation = dedicatedRequirements.prefersDedicatedAllocation;
650 m_allUsageFlagsRequiresDedicatedAllocation = dedicatedRequirements.requiresDedicatedAllocation;
651
652 TCU_CHECK(validValueVkBool32(m_allUsageFlagsPrefersDedicatedAllocation));
653 // Test design expects m_allUsageFlagsRequiresDedicatedAllocation to be false
654 TCU_CHECK(m_allUsageFlagsRequiresDedicatedAllocation == VK_FALSE);
655 }
656 else
657 {
658 m_currentTestRequirements = getBufferMemoryRequirements2(vk, device, size, flags, usage, &dedicatedRequirements);
659 m_currentTestPrefersDedicatedAllocation = dedicatedRequirements.prefersDedicatedAllocation;
660 m_currentTestRequiresDedicatedAllocation = dedicatedRequirements.requiresDedicatedAllocation;
661 }
662 }
663
verifyMemoryRequirements(tcu::ResultCollector & result,const VkPhysicalDeviceMemoryProperties & deviceMemoryProperties,const VkPhysicalDeviceLimits & limits,const VkBufferCreateFlags bufferFlags,const VkBufferUsageFlags usage)664 void BufferMemoryRequirementsDedicatedAllocation::verifyMemoryRequirements (tcu::ResultCollector& result,
665 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
666 const VkPhysicalDeviceLimits& limits,
667 const VkBufferCreateFlags bufferFlags,
668 const VkBufferUsageFlags usage)
669 {
670 BufferMemoryRequirementsExtended::verifyMemoryRequirements(result, deviceMemoryProperties, limits, bufferFlags, usage);
671
672 result.check(validValueVkBool32(m_currentTestPrefersDedicatedAllocation),
673 "Invalid VkBool32 value in m_currentTestPrefersDedicatedAllocation");
674
675 result.check(m_currentTestRequiresDedicatedAllocation == VK_FALSE,
676 "Regular (non-shared) objects must not require dedicated allocations");
677 }
678
679 class BufferMemoryRequirementsCreateInfo : public BufferMemoryRequirementsOriginal
680 {
681 static tcu::TestStatus testEntryPoint (Context& context,
682 const VkBufferCreateFlags bufferFlags);
683
684 protected:
685 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
686 const std::string& name,
687 const std::string& desc,
688 VkBufferCreateFlags arg0);
689
690 virtual void updateMemoryRequirements (const DeviceInterface& vk,
691 const VkDevice device,
692 const VkDeviceSize size,
693 const VkBufferCreateFlags flags,
694 const VkBufferUsageFlags usage,
695 const bool all);
696
697 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
698 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
699 const VkPhysicalDeviceLimits& limits,
700 const VkBufferCreateFlags bufferFlags,
701 const VkBufferUsageFlags usage);
702
703 protected:
704 VkMemoryRequirements m_currentTestOriginalRequirements;
705 VkMemoryRequirements m_currentTestHalfRequirements;
706 };
707
708
testEntryPoint(Context & context,const VkBufferCreateFlags bufferFlags)709 tcu::TestStatus BufferMemoryRequirementsCreateInfo::testEntryPoint(Context& context, const VkBufferCreateFlags bufferFlags)
710 {
711 BufferMemoryRequirementsCreateInfo test;
712
713 return test.execTest(context, bufferFlags);
714 }
715
checkSupportBufferMemoryRequirementsCreateInfo(Context & context,VkBufferCreateFlags flags)716 void checkSupportBufferMemoryRequirementsCreateInfo (Context& context, VkBufferCreateFlags flags)
717 {
718 checkSupportBufferMemoryRequirementsExtended(context, flags);
719
720 context.requireDeviceFunctionality("VK_KHR_maintenance4");
721 }
722
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,VkBufferCreateFlags arg0)723 void BufferMemoryRequirementsCreateInfo::addFunctionTestCase(tcu::TestCaseGroup* group,
724 const std::string& name,
725 const std::string& desc,
726 VkBufferCreateFlags arg0)
727 {
728 addFunctionCase(group, name, desc, checkSupportBufferMemoryRequirementsCreateInfo, testEntryPoint, arg0);
729 }
730
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize size,const VkBufferCreateFlags flags,const VkBufferUsageFlags usage,const bool all)731 void BufferMemoryRequirementsCreateInfo::updateMemoryRequirements (const DeviceInterface& vk,
732 const VkDevice device,
733 const VkDeviceSize size,
734 const VkBufferCreateFlags flags,
735 const VkBufferUsageFlags usage,
736 const bool all)
737 {
738 if (all)
739 {
740 m_allUsageFlagsRequirements = getBufferCreateInfoMemoryRequirementsKHR(vk, device, size, flags, usage);
741 }
742 else
743 {
744 m_currentTestRequirements = getBufferCreateInfoMemoryRequirementsKHR(vk, device, size, flags, usage);
745 m_currentTestHalfRequirements = getBufferCreateInfoMemoryRequirementsKHR(vk, device, size / 2, flags, usage);
746 }
747
748 m_currentTestOriginalRequirements = getBufferMemoryRequirements(vk, device, size, flags, usage);
749 }
750
verifyMemoryRequirements(tcu::ResultCollector & result,const VkPhysicalDeviceMemoryProperties & deviceMemoryProperties,const VkPhysicalDeviceLimits & limits,const VkBufferCreateFlags bufferFlags,const VkBufferUsageFlags usage)751 void BufferMemoryRequirementsCreateInfo::verifyMemoryRequirements (tcu::ResultCollector& result,
752 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties,
753 const VkPhysicalDeviceLimits& limits,
754 const VkBufferCreateFlags bufferFlags,
755 const VkBufferUsageFlags usage)
756 {
757 BufferMemoryRequirementsOriginal::verifyMemoryRequirements(result, deviceMemoryProperties, limits, bufferFlags, usage);
758
759 result.check(m_currentTestRequirements.alignment == m_currentTestOriginalRequirements.alignment,
760 "VkMemoryRequirements alignment queried from vkBufferCreateInfo does not match alignment from equivalent object");
761
762 result.check(m_currentTestRequirements.memoryTypeBits == m_currentTestOriginalRequirements.memoryTypeBits,
763 "VkMemoryRequirements memoryTypeBits queried from vkBufferCreateInfo does not match memoryTypeBits from equivalent object");
764
765 result.check(m_currentTestRequirements.size == m_currentTestOriginalRequirements.size,
766 "VkMemoryRequirements size queried from vkBufferCreateInfo does not match size from equivalent object");
767
768 result.check(m_currentTestRequirements.size >= m_currentTestHalfRequirements.size,
769 "VkMemoryRequirements size queried from vkBufferCreateInfo is larger for a smaller buffer");
770 }
771
772
773 struct ImageTestParams
774 {
ImageTestParamsvkt::memory::__anon117bb4d80111::ImageTestParams775 ImageTestParams (VkImageCreateFlags flags_,
776 VkImageTiling tiling_,
777 bool transient_,
778 bool useMaint4_ = false)
779 : flags (flags_)
780 , tiling (tiling_)
781 , transient (transient_)
782 , useMaint4 (useMaint4_)
783 {
784 }
785
ImageTestParamsvkt::memory::__anon117bb4d80111::ImageTestParams786 ImageTestParams (void)
787 {
788 }
789
790 VkImageCreateFlags flags;
791 VkImageTiling tiling;
792 bool transient;
793 bool useMaint4;
794 };
795
796 class IImageMemoryRequirements
797 {
798 public:
799 virtual void populateTestGroup (tcu::TestCaseGroup* group) = 0;
800
801 protected:
802 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
803 const std::string& name,
804 const std::string& desc,
805 const ImageTestParams arg0) = 0;
806
807 virtual tcu::TestStatus execTest (Context& context,
808 const ImageTestParams bufferFlags) = 0;
809
810 virtual void updateMemoryRequirements (const DeviceInterface& vk,
811 const VkDevice device) = 0;
812
813 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
814 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties) = 0;
815 };
816
817 class ImageMemoryRequirementsOriginal : public IImageMemoryRequirements
818 {
819 static tcu::TestStatus testEntryPoint (Context& context,
820 const ImageTestParams params);
821
822 public:
823 virtual void populateTestGroup (tcu::TestCaseGroup* group);
824
825 protected:
826 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
827 const std::string& name,
828 const std::string& desc,
829 const ImageTestParams arg0);
830
831 virtual tcu::TestStatus execTest (Context& context,
832 const ImageTestParams params);
833
834 virtual void updateMemoryRequirements (const DeviceInterface& vk,
835 const VkDevice device);
836
837 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
838 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties);
839
840 private:
841 virtual bool isImageSupported (const Context& context,
842 const InstanceInterface& vki,
843 const VkPhysicalDevice physDevice,
844 const VkImageCreateInfo& info);
845
846 virtual bool isFormatMatchingAspect (const VkFormat format,
847 const VkImageAspectFlags aspect);
848
849 protected:
850 VkImageCreateInfo m_currentTestImageInfo;
851 VkMemoryRequirements m_currentTestRequirements;
852 std::vector<VkSparseImageMemoryRequirements> m_currentTestSparseRequirements;
853 };
854
855
testEntryPoint(Context & context,const ImageTestParams params)856 tcu::TestStatus ImageMemoryRequirementsOriginal::testEntryPoint (Context& context, const ImageTestParams params)
857 {
858 ImageMemoryRequirementsOriginal test;
859
860 return test.execTest(context, params);
861 }
862
populateTestGroup(tcu::TestCaseGroup * group)863 void ImageMemoryRequirementsOriginal::populateTestGroup (tcu::TestCaseGroup* group)
864 {
865 const struct
866 {
867 VkImageCreateFlags flags;
868 bool transient;
869 const char* const name;
870 } imageFlagsCases[] =
871 {
872 { (VkImageCreateFlags)0, false, "regular" },
873 { (VkImageCreateFlags)0, true, "transient" },
874 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT, false, "sparse" },
875 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, false, "sparse_residency" },
876 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, false, "sparse_aliased" },
877 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, false, "sparse_residency_aliased" },
878 };
879
880 de::MovePtr<tcu::TestCaseGroup> imageGroup(new tcu::TestCaseGroup(group->getTestContext(), "image", ""));
881
882 for (int flagsNdx = 0; flagsNdx < DE_LENGTH_OF_ARRAY(imageFlagsCases); ++flagsNdx)
883 for (int tilingNdx = 0; tilingNdx <= 1; ++tilingNdx)
884 {
885 ImageTestParams params;
886 std::ostringstream caseName;
887
888 params.flags = imageFlagsCases[flagsNdx].flags;
889 params.transient = imageFlagsCases[flagsNdx].transient;
890 params.useMaint4 = false;
891 caseName << imageFlagsCases[flagsNdx].name;
892
893 if (tilingNdx != 0)
894 {
895 params.tiling = VK_IMAGE_TILING_OPTIMAL;
896 caseName << "_tiling_optimal";
897 }
898 else
899 {
900 params.tiling = VK_IMAGE_TILING_LINEAR;
901 caseName << "_tiling_linear";
902 }
903
904 if ((params.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) && (params.tiling == VK_IMAGE_TILING_LINEAR))
905 continue;
906
907 addFunctionTestCase(imageGroup.get(), caseName.str(), "", params);
908 }
909
910 group->addChild(imageGroup.release());
911 }
912
checkSupportImageMemoryRequirementsOriginal(Context & context,ImageTestParams params)913 void checkSupportImageMemoryRequirementsOriginal (Context& context, ImageTestParams params)
914 {
915 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(context.getInstanceInterface(), context.getPhysicalDevice());
916
917 if (params.flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
918 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_BINDING);
919
920 if (params.flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)
921 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_ALIASED);
922
923 if ((params.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) && !(features.sparseResidencyImage2D || features.sparseResidencyImage3D))
924 TCU_THROW(NotSupportedError, "Feature not supported: sparseResidencyImage (2D and 3D)");
925 }
926
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,const ImageTestParams arg0)927 void ImageMemoryRequirementsOriginal::addFunctionTestCase (tcu::TestCaseGroup* group,
928 const std::string& name,
929 const std::string& desc,
930 const ImageTestParams arg0)
931 {
932 addFunctionCase(group, name, desc, checkSupportImageMemoryRequirementsOriginal, testEntryPoint, arg0);
933 }
934
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device)935 void ImageMemoryRequirementsOriginal::updateMemoryRequirements (const DeviceInterface& vk,
936 const VkDevice device)
937 {
938 const Unique<VkImage> image(createImage(vk, device, &m_currentTestImageInfo));
939
940 m_currentTestRequirements = getImageMemoryRequirements(vk, device, *image);
941
942 if (m_currentTestImageInfo.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
943 m_currentTestSparseRequirements = getImageSparseMemoryRequirements(vk, device, *image);
944 }
945
verifyMemoryRequirements(tcu::ResultCollector & result,const VkPhysicalDeviceMemoryProperties & deviceMemoryProperties)946 void ImageMemoryRequirementsOriginal::verifyMemoryRequirements (tcu::ResultCollector& result,
947 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties)
948 {
949 if (result.check(m_currentTestRequirements.memoryTypeBits != 0, "VkMemoryRequirements memoryTypeBits has no bits set"))
950 {
951 typedef std::vector<deUint32>::const_iterator IndexIterator;
952 const std::vector<deUint32> usedMemoryTypeIndices = bitsToIndices(m_currentTestRequirements.memoryTypeBits);
953 bool deviceLocalMemoryFound = false;
954 bool hostVisibleCoherentMemoryFound = false;
955
956 for (IndexIterator memoryTypeNdx = usedMemoryTypeIndices.begin(); memoryTypeNdx != usedMemoryTypeIndices.end(); ++memoryTypeNdx)
957 {
958 if (*memoryTypeNdx >= deviceMemoryProperties.memoryTypeCount)
959 {
960 result.fail("VkMemoryRequirements memoryTypeBits contains bits for non-existing memory types");
961 continue;
962 }
963
964 const VkMemoryPropertyFlags memoryPropertyFlags = deviceMemoryProperties.memoryTypes[*memoryTypeNdx].propertyFlags;
965
966 if (memoryPropertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
967 deviceLocalMemoryFound = true;
968
969 if (memoryPropertyFlags & (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
970 hostVisibleCoherentMemoryFound = true;
971
972 if (memoryPropertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
973 {
974 result.check((m_currentTestImageInfo.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0u,
975 "Memory type includes VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT for a non-transient attachment image");
976 }
977 }
978
979 result.check(deIsPowerOfTwo64(static_cast<deUint64>(m_currentTestRequirements.alignment)) == DE_TRUE,
980 "VkMemoryRequirements alignment isn't power of two");
981
982 result.check(deviceLocalMemoryFound,
983 "None of the required memory types included VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT");
984
985 result.check(m_currentTestImageInfo.tiling == VK_IMAGE_TILING_OPTIMAL || hostVisibleCoherentMemoryFound,
986 "Required memory type doesn't include VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT");
987
988 if (m_currentTestImageInfo.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
989 {
990 for (const VkSparseImageMemoryRequirements &sparseRequirements : m_currentTestSparseRequirements)
991 {
992 result.check((sparseRequirements.imageMipTailSize % m_currentTestRequirements.alignment) == 0,
993 "VkSparseImageMemoryRequirements imageMipTailSize is not aligned with sparse block size");
994 }
995 }
996 }
997 }
998
isUsageMatchesFeatures(const VkImageUsageFlags usage,const VkFormatFeatureFlags featureFlags)999 bool isUsageMatchesFeatures (const VkImageUsageFlags usage, const VkFormatFeatureFlags featureFlags)
1000 {
1001 if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) && (featureFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
1002 return true;
1003 if ((usage & VK_IMAGE_USAGE_STORAGE_BIT) && (featureFlags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
1004 return true;
1005 if ((usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) && (featureFlags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
1006 return true;
1007 if ((usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && (featureFlags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1008 return true;
1009
1010 return false;
1011 }
1012
1013 //! This catches both invalid as well as legal but unsupported combinations of image parameters
isImageSupported(const Context & context,const InstanceInterface & vki,const VkPhysicalDevice physDevice,const VkImageCreateInfo & info)1014 bool ImageMemoryRequirementsOriginal::isImageSupported (const Context& context, const InstanceInterface& vki, const VkPhysicalDevice physDevice, const VkImageCreateInfo& info)
1015 {
1016 DE_ASSERT(info.extent.width >= 1u && info.extent.height >= 1u && info.extent.depth >= 1u);
1017
1018 if (isYCbCrFormat(info.format)
1019 && (info.imageType != VK_IMAGE_TYPE_2D
1020 || info.mipLevels != 1
1021 || info.arrayLayers != 1
1022 || info.samples != VK_SAMPLE_COUNT_1_BIT
1023 || !context.isDeviceFunctionalitySupported("VK_KHR_sampler_ycbcr_conversion")))
1024 {
1025 return false;
1026 }
1027
1028 if (info.imageType == VK_IMAGE_TYPE_1D)
1029 {
1030 DE_ASSERT(info.extent.height == 1u && info.extent.depth == 1u);
1031 }
1032 else if (info.imageType == VK_IMAGE_TYPE_2D)
1033 {
1034 DE_ASSERT(info.extent.depth == 1u);
1035
1036 if (info.flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
1037 {
1038 DE_ASSERT(info.extent.width == info.extent.height);
1039 DE_ASSERT(info.arrayLayers >= 6u && (info.arrayLayers % 6u) == 0u);
1040 }
1041 }
1042
1043 if ((info.flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && info.imageType != VK_IMAGE_TYPE_2D)
1044 return false;
1045
1046 if ((info.samples != VK_SAMPLE_COUNT_1_BIT) &&
1047 (info.imageType != VK_IMAGE_TYPE_2D || (info.flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) || info.tiling != VK_IMAGE_TILING_OPTIMAL || info.mipLevels > 1u))
1048 return false;
1049
1050 if ((info.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) &&
1051 (info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0u)
1052 return false;
1053
1054 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(vki, physDevice);
1055
1056 if (info.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)
1057 {
1058 DE_ASSERT(info.tiling == VK_IMAGE_TILING_OPTIMAL);
1059
1060 if (info.imageType == VK_IMAGE_TYPE_1D)
1061 return false;
1062
1063 if (info.imageType == VK_IMAGE_TYPE_2D && !features.sparseResidencyImage2D)
1064 return false;
1065 if (info.imageType == VK_IMAGE_TYPE_3D && !features.sparseResidencyImage3D)
1066 return false;
1067 if (info.samples == VK_SAMPLE_COUNT_2_BIT && !features.sparseResidency2Samples)
1068 return false;
1069 if (info.samples == VK_SAMPLE_COUNT_4_BIT && !features.sparseResidency4Samples)
1070 return false;
1071 if (info.samples == VK_SAMPLE_COUNT_8_BIT && !features.sparseResidency8Samples)
1072 return false;
1073 if (info.samples == VK_SAMPLE_COUNT_16_BIT && !features.sparseResidency16Samples)
1074 return false;
1075 if (info.samples == VK_SAMPLE_COUNT_32_BIT || info.samples == VK_SAMPLE_COUNT_64_BIT)
1076 return false;
1077 }
1078
1079 if (info.samples != VK_SAMPLE_COUNT_1_BIT && (info.usage & VK_IMAGE_USAGE_STORAGE_BIT) && !features.shaderStorageImageMultisample)
1080 return false;
1081
1082 switch (info.format)
1083 {
1084 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1085 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1086 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1087 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1088 case VK_FORMAT_BC2_UNORM_BLOCK:
1089 case VK_FORMAT_BC2_SRGB_BLOCK:
1090 case VK_FORMAT_BC3_UNORM_BLOCK:
1091 case VK_FORMAT_BC3_SRGB_BLOCK:
1092 case VK_FORMAT_BC4_UNORM_BLOCK:
1093 case VK_FORMAT_BC4_SNORM_BLOCK:
1094 case VK_FORMAT_BC5_UNORM_BLOCK:
1095 case VK_FORMAT_BC5_SNORM_BLOCK:
1096 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1097 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1098 case VK_FORMAT_BC7_UNORM_BLOCK:
1099 case VK_FORMAT_BC7_SRGB_BLOCK:
1100 if (!features.textureCompressionBC)
1101 return false;
1102 break;
1103
1104 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1105 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1106 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1107 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1108 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1109 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1110 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1111 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1112 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1113 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1114 if (!features.textureCompressionETC2)
1115 return false;
1116 break;
1117
1118 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1119 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1120 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1121 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1122 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1123 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1124 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1125 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1126 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1127 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1128 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1129 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1130 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1131 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1132 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1133 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1134 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1135 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1136 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1137 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1138 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1139 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1140 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1141 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1142 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1143 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1144 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1145 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1146 if (!features.textureCompressionASTC_LDR)
1147 return false;
1148 break;
1149
1150 default:
1151 break;
1152 }
1153
1154 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(vki, physDevice, info.format);
1155 const VkFormatFeatureFlags formatFeatures = (info.tiling == VK_IMAGE_TILING_LINEAR ? formatProperties.linearTilingFeatures
1156 : formatProperties.optimalTilingFeatures);
1157
1158 if (!isUsageMatchesFeatures(info.usage, formatFeatures))
1159 return false;
1160
1161 VkImageFormatProperties imageFormatProperties;
1162 const VkResult result = vki.getPhysicalDeviceImageFormatProperties(
1163 physDevice, info.format, info.imageType, info.tiling, info.usage, info.flags, &imageFormatProperties);
1164
1165 if (result == VK_SUCCESS)
1166 {
1167 if (info.arrayLayers > imageFormatProperties.maxArrayLayers)
1168 return false;
1169 if (info.mipLevels > imageFormatProperties.maxMipLevels)
1170 return false;
1171 if ((info.samples & imageFormatProperties.sampleCounts) == 0u)
1172 return false;
1173 }
1174
1175 if ((info.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && !checkSparseImageFormatSupport(physDevice, vki, info))
1176 return false;
1177
1178 return result == VK_SUCCESS;
1179 }
1180
makeExtentForImage(const VkImageType imageType)1181 VkExtent3D makeExtentForImage (const VkImageType imageType)
1182 {
1183 VkExtent3D extent = { 64u, 64u, 4u };
1184
1185 if (imageType == VK_IMAGE_TYPE_1D)
1186 extent.height = extent.depth = 1u;
1187 else if (imageType == VK_IMAGE_TYPE_2D)
1188 extent.depth = 1u;
1189
1190 return extent;
1191 }
1192
halfExtentForImage(const VkImageType imageType,VkExtent3D extent)1193 VkExtent3D halfExtentForImage (const VkImageType imageType, VkExtent3D extent)
1194 {
1195 VkExtent3D halfExtent = extent;
1196
1197 if (imageType == VK_IMAGE_TYPE_1D)
1198 halfExtent.width /= 2;
1199 else if (imageType == VK_IMAGE_TYPE_2D)
1200 halfExtent.height /= 2;
1201 else
1202 halfExtent.depth /= 2;
1203
1204 return halfExtent;
1205 }
1206
isFormatMatchingAspect(const VkFormat format,const VkImageAspectFlags aspect)1207 bool ImageMemoryRequirementsOriginal::isFormatMatchingAspect (const VkFormat format, const VkImageAspectFlags aspect)
1208 {
1209 DE_ASSERT(aspect == VK_IMAGE_ASPECT_COLOR_BIT || aspect == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT));
1210
1211 // D/S formats are laid out next to each other in the enum
1212 const bool isDepthStencilFormat = (format >= VK_FORMAT_D16_UNORM && format <= VK_FORMAT_D32_SFLOAT_S8_UINT);
1213
1214 return (aspect == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == isDepthStencilFormat;
1215 }
1216
getImageInfoString(const VkImageCreateInfo & imageInfo)1217 std::string getImageInfoString (const VkImageCreateInfo& imageInfo)
1218 {
1219 std::ostringstream str;
1220
1221 switch (imageInfo.imageType)
1222 {
1223 case VK_IMAGE_TYPE_1D: str << "1D "; break;
1224 case VK_IMAGE_TYPE_2D: str << "2D "; break;
1225 case VK_IMAGE_TYPE_3D: str << "3D "; break;
1226 default: break;
1227 }
1228
1229 switch (imageInfo.tiling)
1230 {
1231 case VK_IMAGE_TILING_OPTIMAL: str << "(optimal) "; break;
1232 case VK_IMAGE_TILING_LINEAR: str << "(linear) "; break;
1233 default: break;
1234 }
1235
1236 str << "extent:[" << imageInfo.extent.width << ", " << imageInfo.extent.height << ", " << imageInfo.extent.depth << "] ";
1237 str << imageInfo.format << " ";
1238 str << "samples:" << static_cast<deUint32>(imageInfo.samples) << " ";
1239 str << "flags:" << static_cast<deUint32>(imageInfo.flags) << " ";
1240 str << "usage:" << static_cast<deUint32>(imageInfo.usage) << " ";
1241
1242 return str.str();
1243 }
1244
execTest(Context & context,const ImageTestParams params)1245 tcu::TestStatus ImageMemoryRequirementsOriginal::execTest (Context& context, const ImageTestParams params)
1246 {
1247 const VkFormat formats[] =
1248 {
1249 VK_FORMAT_R4G4_UNORM_PACK8,
1250 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1251 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1252 VK_FORMAT_R5G6B5_UNORM_PACK16,
1253 VK_FORMAT_B5G6R5_UNORM_PACK16,
1254 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
1255 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
1256 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1257 VK_FORMAT_R8_UNORM,
1258 VK_FORMAT_R8_SNORM,
1259 VK_FORMAT_R8_USCALED,
1260 VK_FORMAT_R8_SSCALED,
1261 VK_FORMAT_R8_UINT,
1262 VK_FORMAT_R8_SINT,
1263 VK_FORMAT_R8_SRGB,
1264 VK_FORMAT_R8G8_UNORM,
1265 VK_FORMAT_R8G8_SNORM,
1266 VK_FORMAT_R8G8_USCALED,
1267 VK_FORMAT_R8G8_SSCALED,
1268 VK_FORMAT_R8G8_UINT,
1269 VK_FORMAT_R8G8_SINT,
1270 VK_FORMAT_R8G8_SRGB,
1271 VK_FORMAT_R8G8B8_UNORM,
1272 VK_FORMAT_R8G8B8_SNORM,
1273 VK_FORMAT_R8G8B8_USCALED,
1274 VK_FORMAT_R8G8B8_SSCALED,
1275 VK_FORMAT_R8G8B8_UINT,
1276 VK_FORMAT_R8G8B8_SINT,
1277 VK_FORMAT_R8G8B8_SRGB,
1278 VK_FORMAT_B8G8R8_UNORM,
1279 VK_FORMAT_B8G8R8_SNORM,
1280 VK_FORMAT_B8G8R8_USCALED,
1281 VK_FORMAT_B8G8R8_SSCALED,
1282 VK_FORMAT_B8G8R8_UINT,
1283 VK_FORMAT_B8G8R8_SINT,
1284 VK_FORMAT_B8G8R8_SRGB,
1285 VK_FORMAT_R8G8B8A8_UNORM,
1286 VK_FORMAT_R8G8B8A8_SNORM,
1287 VK_FORMAT_R8G8B8A8_USCALED,
1288 VK_FORMAT_R8G8B8A8_SSCALED,
1289 VK_FORMAT_R8G8B8A8_UINT,
1290 VK_FORMAT_R8G8B8A8_SINT,
1291 VK_FORMAT_R8G8B8A8_SRGB,
1292 VK_FORMAT_B8G8R8A8_UNORM,
1293 VK_FORMAT_B8G8R8A8_SNORM,
1294 VK_FORMAT_B8G8R8A8_USCALED,
1295 VK_FORMAT_B8G8R8A8_SSCALED,
1296 VK_FORMAT_B8G8R8A8_UINT,
1297 VK_FORMAT_B8G8R8A8_SINT,
1298 VK_FORMAT_B8G8R8A8_SRGB,
1299 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1300 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1301 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
1302 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
1303 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1304 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1305 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1306 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
1307 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
1308 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
1309 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
1310 VK_FORMAT_A2R10G10B10_UINT_PACK32,
1311 VK_FORMAT_A2R10G10B10_SINT_PACK32,
1312 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1313 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
1314 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
1315 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
1316 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1317 VK_FORMAT_A2B10G10R10_SINT_PACK32,
1318 VK_FORMAT_R16_UNORM,
1319 VK_FORMAT_R16_SNORM,
1320 VK_FORMAT_R16_USCALED,
1321 VK_FORMAT_R16_SSCALED,
1322 VK_FORMAT_R16_UINT,
1323 VK_FORMAT_R16_SINT,
1324 VK_FORMAT_R16_SFLOAT,
1325 VK_FORMAT_R16G16_UNORM,
1326 VK_FORMAT_R16G16_SNORM,
1327 VK_FORMAT_R16G16_USCALED,
1328 VK_FORMAT_R16G16_SSCALED,
1329 VK_FORMAT_R16G16_UINT,
1330 VK_FORMAT_R16G16_SINT,
1331 VK_FORMAT_R16G16_SFLOAT,
1332 VK_FORMAT_R16G16B16_UNORM,
1333 VK_FORMAT_R16G16B16_SNORM,
1334 VK_FORMAT_R16G16B16_USCALED,
1335 VK_FORMAT_R16G16B16_SSCALED,
1336 VK_FORMAT_R16G16B16_UINT,
1337 VK_FORMAT_R16G16B16_SINT,
1338 VK_FORMAT_R16G16B16_SFLOAT,
1339 VK_FORMAT_R16G16B16A16_UNORM,
1340 VK_FORMAT_R16G16B16A16_SNORM,
1341 VK_FORMAT_R16G16B16A16_USCALED,
1342 VK_FORMAT_R16G16B16A16_SSCALED,
1343 VK_FORMAT_R16G16B16A16_UINT,
1344 VK_FORMAT_R16G16B16A16_SINT,
1345 VK_FORMAT_R16G16B16A16_SFLOAT,
1346 VK_FORMAT_R32_UINT,
1347 VK_FORMAT_R32_SINT,
1348 VK_FORMAT_R32_SFLOAT,
1349 VK_FORMAT_R32G32_UINT,
1350 VK_FORMAT_R32G32_SINT,
1351 VK_FORMAT_R32G32_SFLOAT,
1352 VK_FORMAT_R32G32B32_UINT,
1353 VK_FORMAT_R32G32B32_SINT,
1354 VK_FORMAT_R32G32B32_SFLOAT,
1355 VK_FORMAT_R32G32B32A32_UINT,
1356 VK_FORMAT_R32G32B32A32_SINT,
1357 VK_FORMAT_R32G32B32A32_SFLOAT,
1358 VK_FORMAT_R64_UINT,
1359 VK_FORMAT_R64_SINT,
1360 VK_FORMAT_R64_SFLOAT,
1361 VK_FORMAT_R64G64_UINT,
1362 VK_FORMAT_R64G64_SINT,
1363 VK_FORMAT_R64G64_SFLOAT,
1364 VK_FORMAT_R64G64B64_UINT,
1365 VK_FORMAT_R64G64B64_SINT,
1366 VK_FORMAT_R64G64B64_SFLOAT,
1367 VK_FORMAT_R64G64B64A64_UINT,
1368 VK_FORMAT_R64G64B64A64_SINT,
1369 VK_FORMAT_R64G64B64A64_SFLOAT,
1370 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1371 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1372 VK_FORMAT_D16_UNORM,
1373 VK_FORMAT_X8_D24_UNORM_PACK32,
1374 VK_FORMAT_D32_SFLOAT,
1375 VK_FORMAT_S8_UINT,
1376 VK_FORMAT_D16_UNORM_S8_UINT,
1377 VK_FORMAT_D24_UNORM_S8_UINT,
1378 VK_FORMAT_D32_SFLOAT_S8_UINT,
1379 VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1380 VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1381 VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1382 VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1383 VK_FORMAT_BC2_UNORM_BLOCK,
1384 VK_FORMAT_BC2_SRGB_BLOCK,
1385 VK_FORMAT_BC3_UNORM_BLOCK,
1386 VK_FORMAT_BC3_SRGB_BLOCK,
1387 VK_FORMAT_BC4_UNORM_BLOCK,
1388 VK_FORMAT_BC4_SNORM_BLOCK,
1389 VK_FORMAT_BC5_UNORM_BLOCK,
1390 VK_FORMAT_BC5_SNORM_BLOCK,
1391 VK_FORMAT_BC6H_UFLOAT_BLOCK,
1392 VK_FORMAT_BC6H_SFLOAT_BLOCK,
1393 VK_FORMAT_BC7_UNORM_BLOCK,
1394 VK_FORMAT_BC7_SRGB_BLOCK,
1395 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1396 VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1397 VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1398 VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1399 VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1400 VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1401 VK_FORMAT_EAC_R11_UNORM_BLOCK,
1402 VK_FORMAT_EAC_R11_SNORM_BLOCK,
1403 VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1404 VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1405 VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1406 VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1407 VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1408 VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1409 VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1410 VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1411 VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1412 VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1413 VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1414 VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1415 VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1416 VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1417 VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1418 VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1419 VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1420 VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1421 VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1422 VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1423 VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1424 VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1425 VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1426 VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1427 VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1428 VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1429 VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1430 VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1431 VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1432 VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
1433 VK_FORMAT_G8B8G8R8_422_UNORM_KHR,
1434 VK_FORMAT_B8G8R8G8_422_UNORM_KHR,
1435 VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR,
1436 VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR,
1437 VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR,
1438 VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR,
1439 VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR,
1440 VK_FORMAT_R10X6_UNORM_PACK16_KHR,
1441 VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR,
1442 VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR,
1443 VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR,
1444 VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR,
1445 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR,
1446 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR,
1447 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR,
1448 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR,
1449 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR,
1450 VK_FORMAT_R12X4_UNORM_PACK16_KHR,
1451 VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR,
1452 VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR,
1453 VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR,
1454 VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR,
1455 VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR,
1456 VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR,
1457 VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR,
1458 VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR,
1459 VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR,
1460 VK_FORMAT_G16B16G16R16_422_UNORM_KHR,
1461 VK_FORMAT_B16G16R16G16_422_UNORM_KHR,
1462 VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR,
1463 VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR,
1464 VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR,
1465 VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR,
1466 VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR,
1467 VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT,
1468 VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT,
1469 VK_FORMAT_G8_B8R8_2PLANE_444_UNORM_EXT,
1470 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_444_UNORM_3PACK16_EXT,
1471 VK_FORMAT_G12X4_B12X4R12X4_2PLANE_444_UNORM_3PACK16_EXT,
1472 VK_FORMAT_G16_B16R16_2PLANE_444_UNORM_EXT,
1473 };
1474 const DeviceInterface& vk = context.getDeviceInterface();
1475 const InstanceInterface& vki = context.getInstanceInterface();
1476 const VkDevice device = context.getDevice();
1477 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
1478 const VkImageCreateFlags sparseFlags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
1479 const VkImageUsageFlags transientFlags = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
1480
1481 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(vki, physDevice);
1482 const deUint32 notInitializedBits = ~0u;
1483 const VkImageAspectFlags colorAspect = VK_IMAGE_ASPECT_COLOR_BIT;
1484 const VkImageAspectFlags depthStencilAspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
1485 const VkImageAspectFlags allAspects[2] = { colorAspect, depthStencilAspect };
1486 tcu::TestLog& log = context.getTestContext().getLog();
1487 bool allPass = true;
1488 deUint32 numCheckedImages = 0u;
1489
1490 log << tcu::TestLog::Message << "Verify memory requirements for the following parameter combinations:" << tcu::TestLog::EndMessage;
1491
1492 for (deUint32 loopAspectNdx = 0u; loopAspectNdx < DE_LENGTH_OF_ARRAY(allAspects); ++loopAspectNdx)
1493 {
1494 const VkImageAspectFlags aspect = allAspects[loopAspectNdx];
1495 deUint32 previousMemoryTypeBits = notInitializedBits;
1496
1497 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
1498 {
1499 const VkFormat format = formats[formatNdx];
1500
1501 if (isFormatMatchingAspect(format, aspect))
1502 {
1503 // memoryTypeBits may differ between depth/stencil formats
1504 if (aspect == depthStencilAspect)
1505 previousMemoryTypeBits = notInitializedBits;
1506
1507 for (VkImageType loopImageType = VK_IMAGE_TYPE_1D; loopImageType != VK_IMAGE_TYPE_LAST; loopImageType = nextEnum(loopImageType))
1508 for (VkImageCreateFlags loopCreateFlags = (VkImageCreateFlags)0; loopCreateFlags <= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; loopCreateFlags = nextFlagExcluding(loopCreateFlags, sparseFlags))
1509 for (VkImageUsageFlags loopUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; loopUsageFlags <= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; loopUsageFlags = nextFlagExcluding(loopUsageFlags, transientFlags))
1510 for (VkSampleCountFlagBits loopSampleCount = VK_SAMPLE_COUNT_1_BIT; loopSampleCount <= VK_SAMPLE_COUNT_16_BIT; loopSampleCount = nextFlag(loopSampleCount))
1511 {
1512 const VkImageCreateFlags actualCreateFlags = loopCreateFlags | params.flags;
1513 const VkImageUsageFlags actualUsageFlags = loopUsageFlags | (params.transient ? VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT : (VkImageUsageFlagBits)0);
1514 const bool isCube = (actualCreateFlags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) != 0u;
1515 const VkImageCreateInfo imageInfo =
1516 {
1517 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1518 DE_NULL, // const void* pNext;
1519 actualCreateFlags, // VkImageCreateFlags flags;
1520 loopImageType, // VkImageType imageType;
1521 format, // VkFormat format;
1522 makeExtentForImage(loopImageType), // VkExtent3D extent;
1523 1u, // uint32_t mipLevels;
1524 (isCube ? 6u : 1u), // uint32_t arrayLayers;
1525 loopSampleCount, // VkSampleCountFlagBits samples;
1526 params.tiling, // VkImageTiling tiling;
1527 actualUsageFlags, // VkImageUsageFlags usage;
1528 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1529 0u, // uint32_t queueFamilyIndexCount;
1530 DE_NULL, // const uint32_t* pQueueFamilyIndices;
1531 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1532 };
1533
1534 m_currentTestImageInfo = imageInfo;
1535
1536 if (!isImageSupported(context, vki, physDevice, m_currentTestImageInfo))
1537 continue;
1538
1539 log << tcu::TestLog::Message << "- " << getImageInfoString(m_currentTestImageInfo) << tcu::TestLog::EndMessage;
1540 ++numCheckedImages;
1541
1542 tcu::ResultCollector result(log, "ERROR: ");
1543
1544 updateMemoryRequirements(vk, device);
1545
1546 verifyMemoryRequirements(result, memoryProperties);
1547
1548 // For the same tiling, transient usage, and sparse flags, (and format, if D/S) memoryTypeBits must be the same for all images
1549 result.check((previousMemoryTypeBits == notInitializedBits) || (m_currentTestRequirements.memoryTypeBits == previousMemoryTypeBits),
1550 "memoryTypeBits differ from the ones in the previous image configuration");
1551
1552 if (result.getResult() != QP_TEST_RESULT_PASS)
1553 allPass = false;
1554
1555 previousMemoryTypeBits = m_currentTestRequirements.memoryTypeBits;
1556 }
1557 }
1558 }
1559 }
1560
1561 if (numCheckedImages == 0u)
1562 log << tcu::TestLog::Message << "NOTE: No supported image configurations -- nothing to check" << tcu::TestLog::EndMessage;
1563
1564 return allPass ? tcu::TestStatus::pass("Pass") : tcu::TestStatus::fail("Some memory requirements were incorrect");
1565 }
1566
1567
1568 class ImageMemoryRequirementsExtended : public ImageMemoryRequirementsOriginal
1569 {
1570 public:
1571 static tcu::TestStatus testEntryPoint (Context& context,
1572 const ImageTestParams params);
1573
1574 protected:
1575 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
1576 const std::string& name,
1577 const std::string& desc,
1578 const ImageTestParams arg0);
1579
1580 virtual void updateMemoryRequirements (const DeviceInterface& vk,
1581 const VkDevice device);
1582 };
1583
1584
testEntryPoint(Context & context,const ImageTestParams params)1585 tcu::TestStatus ImageMemoryRequirementsExtended::testEntryPoint (Context& context, const ImageTestParams params)
1586 {
1587 ImageMemoryRequirementsExtended test;
1588
1589 return test.execTest(context, params);
1590 }
1591
checkSupportImageMemoryRequirementsExtended(Context & context,ImageTestParams params)1592 void checkSupportImageMemoryRequirementsExtended (Context& context, ImageTestParams params)
1593 {
1594 checkSupportImageMemoryRequirementsOriginal(context, params);
1595
1596 context.requireDeviceFunctionality("VK_KHR_get_memory_requirements2");
1597 }
1598
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,const ImageTestParams arg0)1599 void ImageMemoryRequirementsExtended::addFunctionTestCase (tcu::TestCaseGroup* group,
1600 const std::string& name,
1601 const std::string& desc,
1602 const ImageTestParams arg0)
1603 {
1604 addFunctionCase(group, name, desc, checkSupportImageMemoryRequirementsExtended, testEntryPoint, arg0);
1605 }
1606
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device)1607 void ImageMemoryRequirementsExtended::updateMemoryRequirements (const DeviceInterface& vk,
1608 const VkDevice device)
1609 {
1610 m_currentTestRequirements = getImageMemoryRequirements2(vk, device, m_currentTestImageInfo);
1611 }
1612
1613
1614 class ImageMemoryRequirementsDedicatedAllocation : public ImageMemoryRequirementsExtended
1615 {
1616 public:
1617 static tcu::TestStatus testEntryPoint (Context& context,
1618 const ImageTestParams params);
1619
1620 protected:
1621 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
1622 const std::string& name,
1623 const std::string& desc,
1624 const ImageTestParams arg0);
1625
1626 virtual void updateMemoryRequirements (const DeviceInterface& vk,
1627 const VkDevice device);
1628
1629 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
1630 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties);
1631
1632 protected:
1633 VkBool32 m_currentTestPrefersDedicatedAllocation;
1634 VkBool32 m_currentTestRequiresDedicatedAllocation;
1635 };
1636
1637
testEntryPoint(Context & context,const ImageTestParams params)1638 tcu::TestStatus ImageMemoryRequirementsDedicatedAllocation::testEntryPoint (Context& context, const ImageTestParams params)
1639 {
1640 ImageMemoryRequirementsDedicatedAllocation test;
1641
1642 return test.execTest(context, params);
1643 }
1644
checkSupportImageMemoryRequirementsDedicatedAllocation(Context & context,ImageTestParams params)1645 void checkSupportImageMemoryRequirementsDedicatedAllocation (Context& context, ImageTestParams params)
1646 {
1647 checkSupportImageMemoryRequirementsExtended(context, params);
1648
1649 context.requireDeviceFunctionality("VK_KHR_dedicated_allocation");
1650 }
1651
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,const ImageTestParams arg0)1652 void ImageMemoryRequirementsDedicatedAllocation::addFunctionTestCase (tcu::TestCaseGroup* group,
1653 const std::string& name,
1654 const std::string& desc,
1655 const ImageTestParams arg0)
1656 {
1657 addFunctionCase(group, name, desc, checkSupportImageMemoryRequirementsDedicatedAllocation, testEntryPoint, arg0);
1658 }
1659
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device)1660 void ImageMemoryRequirementsDedicatedAllocation::updateMemoryRequirements (const DeviceInterface& vk,
1661 const VkDevice device)
1662 {
1663 const deUint32 invalidVkBool32 = static_cast<deUint32>(~0);
1664
1665 VkMemoryDedicatedRequirements dedicatedRequirements =
1666 {
1667 VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, // VkStructureType sType
1668 DE_NULL, // void* pNext
1669 invalidVkBool32, // VkBool32 prefersDedicatedAllocation
1670 invalidVkBool32 // VkBool32 requiresDedicatedAllocation
1671 };
1672
1673 m_currentTestRequirements = getImageMemoryRequirements2(vk, device, m_currentTestImageInfo, &dedicatedRequirements);
1674 m_currentTestPrefersDedicatedAllocation = dedicatedRequirements.prefersDedicatedAllocation;
1675 m_currentTestRequiresDedicatedAllocation = dedicatedRequirements.requiresDedicatedAllocation;
1676 }
1677
verifyMemoryRequirements(tcu::ResultCollector & result,const VkPhysicalDeviceMemoryProperties & deviceMemoryProperties)1678 void ImageMemoryRequirementsDedicatedAllocation::verifyMemoryRequirements (tcu::ResultCollector& result,
1679 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties)
1680 {
1681 ImageMemoryRequirementsExtended::verifyMemoryRequirements(result, deviceMemoryProperties);
1682
1683 result.check(validValueVkBool32(m_currentTestPrefersDedicatedAllocation),
1684 "Non-bool value in m_currentTestPrefersDedicatedAllocation");
1685
1686 result.check(m_currentTestRequiresDedicatedAllocation == VK_FALSE,
1687 "Test design expects m_currentTestRequiresDedicatedAllocation to be false");
1688 }
1689
1690 class ImageMemoryRequirementsCreateInfo : public ImageMemoryRequirementsExtended
1691 {
1692 public:
1693 static tcu::TestStatus testEntryPoint (Context& context,
1694 const ImageTestParams params);
1695
1696 protected:
1697 virtual void addFunctionTestCase (tcu::TestCaseGroup* group,
1698 const std::string& name,
1699 const std::string& desc,
1700 const ImageTestParams arg0);
1701
1702 virtual void updateMemoryRequirements (const DeviceInterface& vk,
1703 const VkDevice device);
1704
1705 virtual void verifyMemoryRequirements (tcu::ResultCollector& result,
1706 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties);
1707
1708 VkMemoryRequirements m_currentTestOriginalRequirements;
1709 VkMemoryRequirements m_currentTestHalfRequirements;
1710 std::vector<VkSparseImageMemoryRequirements> m_currentTestOriginalSparseRequirements;
1711 };
1712
1713
testEntryPoint(Context & context,const ImageTestParams params)1714 tcu::TestStatus ImageMemoryRequirementsCreateInfo::testEntryPoint (Context& context, const ImageTestParams params)
1715 {
1716 ImageMemoryRequirementsCreateInfo test;
1717
1718 return test.execTest(context, params);
1719 }
1720
checkSupportImageMemoryRequirementsCreateInfo(Context & context,ImageTestParams params)1721 void checkSupportImageMemoryRequirementsCreateInfo (Context& context, ImageTestParams params)
1722 {
1723 checkSupportImageMemoryRequirementsExtended(context, params);
1724
1725 context.requireDeviceFunctionality("VK_KHR_maintenance4");
1726 }
1727
addFunctionTestCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,const ImageTestParams arg0)1728 void ImageMemoryRequirementsCreateInfo::addFunctionTestCase (tcu::TestCaseGroup* group,
1729 const std::string& name,
1730 const std::string& desc,
1731 const ImageTestParams arg0)
1732 {
1733 addFunctionCase(group, name, desc, checkSupportImageMemoryRequirementsCreateInfo, testEntryPoint, arg0);
1734 }
1735
updateMemoryRequirements(const DeviceInterface & vk,const VkDevice device)1736 void ImageMemoryRequirementsCreateInfo::updateMemoryRequirements (const DeviceInterface& vk,
1737 const VkDevice device)
1738 {
1739 m_currentTestRequirements = getDeviceImageMemoryRequirements(vk, device, m_currentTestImageInfo);
1740
1741 const Unique<VkImage> image(createImage(vk, device, &m_currentTestImageInfo));
1742 m_currentTestOriginalRequirements = getImageMemoryRequirements(vk, device, *image);
1743
1744 VkImageCreateInfo halfImageCreateInfo = m_currentTestImageInfo;
1745 halfImageCreateInfo.extent = halfExtentForImage(m_currentTestImageInfo.imageType, m_currentTestImageInfo.extent);
1746 m_currentTestHalfRequirements = getDeviceImageMemoryRequirements(vk, device, halfImageCreateInfo);
1747
1748 if (m_currentTestImageInfo.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
1749 {
1750 m_currentTestSparseRequirements = getImageCreateInfoSparseMemoryRequirements(vk, device, m_currentTestImageInfo);
1751 m_currentTestOriginalSparseRequirements = getImageSparseMemoryRequirements(vk, device, *image);
1752 }
1753 }
1754
verifyMemoryRequirements(tcu::ResultCollector & result,const VkPhysicalDeviceMemoryProperties & deviceMemoryProperties)1755 void ImageMemoryRequirementsCreateInfo::verifyMemoryRequirements (tcu::ResultCollector& result,
1756 const VkPhysicalDeviceMemoryProperties& deviceMemoryProperties)
1757 {
1758 ImageMemoryRequirementsOriginal::verifyMemoryRequirements(result, deviceMemoryProperties);
1759
1760 result.check(m_currentTestRequirements.alignment == m_currentTestOriginalRequirements.alignment,
1761 "VkMemoryRequirements alignment queried from vkImageCreateInfo differs from equivalent object query");
1762
1763 result.check(m_currentTestRequirements.memoryTypeBits == m_currentTestOriginalRequirements.memoryTypeBits,
1764 "VkMemoryRequirements memoryTypeBits queried from vkImageCreateInfo differs from equivalent object query");
1765
1766 result.check(m_currentTestRequirements.size == m_currentTestOriginalRequirements.size,
1767 "VkMemoryRequirements size queried from vkImageCreateInfo differs from equivalent object query");
1768
1769 result.check(m_currentTestRequirements.size >= m_currentTestHalfRequirements.size,
1770 "VkMemoryRequirements size queried from vkImageCreateInfo is larger for a smaller image");
1771
1772 if (m_currentTestImageInfo.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
1773 {
1774 result.check(m_currentTestSparseRequirements.size() == m_currentTestOriginalSparseRequirements.size(),
1775 "VkSparseImageMemoryRequirements count queried from vkImageCreateInfo differs from equivalent object query");
1776
1777 for (deUint32 ndx = 0; ndx < m_currentTestSparseRequirements.size(); ++ndx)
1778 {
1779 const VkSparseImageMemoryRequirements &sparseRequirementsFromCreateInfo = m_currentTestSparseRequirements[ndx];
1780 const VkSparseImageMemoryRequirements &sparseRequirementsFromObject = m_currentTestOriginalSparseRequirements[ndx];
1781
1782 result.check(sparseRequirementsFromCreateInfo.formatProperties.aspectMask == sparseRequirementsFromObject.formatProperties.aspectMask,
1783 "VkSparseImageMemoryRequirements aspectMask queried from vkImageCreateInfo differs from equivalent object query");
1784
1785 result.check(sparseRequirementsFromCreateInfo.formatProperties.flags == sparseRequirementsFromObject.formatProperties.flags,
1786 "VkSparseImageMemoryRequirements flags queried from vkImageCreateInfo differs from equivalent object query");
1787
1788 result.check(sparseRequirementsFromCreateInfo.formatProperties.imageGranularity.width == sparseRequirementsFromObject.formatProperties.imageGranularity.width,
1789 "VkSparseImageMemoryRequirements imageGranularity queried from vkImageCreateInfo differs from equivalent object query");
1790 result.check(sparseRequirementsFromCreateInfo.formatProperties.imageGranularity.height == sparseRequirementsFromObject.formatProperties.imageGranularity.height,
1791 "VkSparseImageMemoryRequirements imageGranularity queried from vkImageCreateInfo differs from equivalent object query");
1792 result.check(sparseRequirementsFromCreateInfo.formatProperties.imageGranularity.depth == sparseRequirementsFromObject.formatProperties.imageGranularity.depth,
1793 "VkSparseImageMemoryRequirements imageGranularity queried from vkImageCreateInfo differs from equivalent object query");
1794
1795 result.check(sparseRequirementsFromCreateInfo.imageMipTailFirstLod == sparseRequirementsFromObject.imageMipTailFirstLod,
1796 "VkSparseImageMemoryRequirements imageMipTailFirstLod queried from vkImageCreateInfo differs from equivalent object query");
1797
1798 result.check(sparseRequirementsFromCreateInfo.imageMipTailSize == sparseRequirementsFromObject.imageMipTailSize,
1799 "VkSparseImageMemoryRequirements imageMipTailSize queried from vkImageCreateInfo differs from equivalent object query");
1800
1801 result.check(sparseRequirementsFromCreateInfo.imageMipTailOffset == sparseRequirementsFromObject.imageMipTailOffset,
1802 "VkSparseImageMemoryRequirements imageMipTailOffset queried from vkImageCreateInfo differs from equivalent object query");
1803
1804 result.check(sparseRequirementsFromCreateInfo.imageMipTailStride == sparseRequirementsFromObject.imageMipTailStride,
1805 "VkSparseImageMemoryRequirements imageMipTailStride queried from vkImageCreateInfo differs from equivalent object query");
1806 }
1807 }
1808 }
1809
populateCoreTestGroup(tcu::TestCaseGroup * group)1810 void populateCoreTestGroup (tcu::TestCaseGroup* group)
1811 {
1812 BufferMemoryRequirementsOriginal bufferTest;
1813 ImageMemoryRequirementsOriginal imageTest;
1814
1815 bufferTest.populateTestGroup(group);
1816 imageTest.populateTestGroup(group);
1817 }
1818
populateExtendedTestGroup(tcu::TestCaseGroup * group)1819 void populateExtendedTestGroup (tcu::TestCaseGroup* group)
1820 {
1821 BufferMemoryRequirementsExtended bufferTest;
1822 ImageMemoryRequirementsExtended imageTest;
1823
1824 bufferTest.populateTestGroup(group);
1825 imageTest.populateTestGroup(group);
1826 }
1827
populateDedicatedAllocationTestGroup(tcu::TestCaseGroup * group)1828 void populateDedicatedAllocationTestGroup (tcu::TestCaseGroup* group)
1829 {
1830 BufferMemoryRequirementsDedicatedAllocation bufferTest;
1831 ImageMemoryRequirementsDedicatedAllocation imageTest;
1832
1833 bufferTest.populateTestGroup(group);
1834 imageTest.populateTestGroup(group);
1835 }
1836
isMultiplaneImageSupported(const InstanceInterface & vki,const VkPhysicalDevice physicalDevice,const VkImageCreateInfo & info)1837 bool isMultiplaneImageSupported (const InstanceInterface& vki,
1838 const VkPhysicalDevice physicalDevice,
1839 const VkImageCreateInfo& info)
1840 {
1841 // cubemap requires arrayLayers > 1, which multiplane doesn't support
1842 if (info.flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
1843 return false;
1844
1845 if ((info.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) &&
1846 (info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) == 0u)
1847 return false;
1848
1849 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(vki, physicalDevice);
1850
1851 if (info.flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)
1852 {
1853 DE_ASSERT(info.tiling == VK_IMAGE_TILING_OPTIMAL);
1854
1855 if (info.imageType == VK_IMAGE_TYPE_2D && !features.sparseResidencyImage2D)
1856 return false;
1857 }
1858
1859 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(vki, physicalDevice, info.format);
1860 const VkFormatFeatureFlags formatFeatures = (info.tiling == VK_IMAGE_TILING_LINEAR ? formatProperties.linearTilingFeatures
1861 : formatProperties.optimalTilingFeatures);
1862
1863 if (!isUsageMatchesFeatures(info.usage, formatFeatures))
1864 return false;
1865
1866 VkImageFormatProperties imageFormatProperties;
1867 const VkResult result = vki.getPhysicalDeviceImageFormatProperties(
1868 physicalDevice, info.format, info.imageType, info.tiling, info.usage, info.flags, &imageFormatProperties);
1869
1870 if (result == VK_SUCCESS)
1871 {
1872 if (info.arrayLayers > imageFormatProperties.maxArrayLayers)
1873 return false;
1874 if (info.mipLevels > imageFormatProperties.maxMipLevels)
1875 return false;
1876 if ((info.samples & imageFormatProperties.sampleCounts) == 0u)
1877 return false;
1878 }
1879
1880 return result == VK_SUCCESS;
1881 }
1882
testMultiplaneImages(Context & context,ImageTestParams params)1883 tcu::TestStatus testMultiplaneImages (Context& context, ImageTestParams params)
1884 {
1885 const VkFormat multiplaneFormats[] =
1886 {
1887 VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR,
1888 VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR,
1889 VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR,
1890 VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR,
1891 VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR,
1892 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR,
1893 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR,
1894 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR,
1895 VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR,
1896 VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR,
1897 VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR,
1898 VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR,
1899 VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR,
1900 VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR,
1901 VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR,
1902 VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR,
1903 VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR,
1904 VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR,
1905 VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR
1906 };
1907
1908 const InstanceInterface& vki = context.getInstanceInterface();
1909 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
1910 const DeviceInterface& vk = context.getDeviceInterface();
1911 const VkDevice device = context.getDevice();
1912 const VkImageCreateFlags sparseFlags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
1913 const VkImageUsageFlags transientFlags = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
1914 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(vki, physicalDevice);
1915 tcu::TestLog& log = context.getTestContext().getLog();
1916 tcu::ResultCollector result (log, "ERROR: ");
1917
1918 log << TestLog::Message << "Memory properties: " << memoryProperties << TestLog::EndMessage;
1919
1920 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(multiplaneFormats); formatNdx++)
1921 {
1922 for (VkImageCreateFlags loopCreateFlags = (VkImageCreateFlags)0; loopCreateFlags <= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; loopCreateFlags = nextFlagExcluding(loopCreateFlags, sparseFlags))
1923 for (VkImageUsageFlags loopUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; loopUsageFlags <= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; loopUsageFlags = nextFlagExcluding(loopUsageFlags, transientFlags))
1924 {
1925 const VkFormat format = multiplaneFormats[formatNdx];
1926 const VkImageCreateFlags actualCreateFlags = loopCreateFlags | params.flags;
1927 const VkImageUsageFlags actualUsageFlags = loopUsageFlags | (params.transient ? VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT : (VkImageUsageFlagBits)0);
1928 const VkImageCreateInfo imageInfo =
1929 {
1930 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1931 DE_NULL, // const void* pNext;
1932 actualCreateFlags, // VkImageCreateFlags flags;
1933 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1934 format, // VkFormat format;
1935 { 64u, 64u, 1u, }, // VkExtent3D extent;
1936 1u, // uint32_t mipLevels;
1937 1u, // uint32_t arrayLayers;
1938 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1939 params.tiling, // VkImageTiling tiling;
1940 actualUsageFlags, // VkImageUsageFlags usage;
1941 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1942 0u, // uint32_t queueFamilyIndexCount;
1943 DE_NULL, // const uint32_t* pQueueFamilyIndices;
1944 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1945 };
1946
1947 if (isMultiplaneImageSupported(vki, physicalDevice, imageInfo))
1948 {
1949 const Unique<VkImage> image ((params.useMaint4) ? Move<VkImage>() : createImage(vk, device, &imageInfo));
1950
1951 log << tcu::TestLog::Message << "- " << getImageInfoString(imageInfo) << tcu::TestLog::EndMessage;
1952
1953 for (deUint32 planeNdx = 0; planeNdx < (deUint32)getPlaneCount(format); planeNdx++)
1954 {
1955 VkMemoryRequirements2 requirements =
1956 {
1957 VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
1958 DE_NULL,
1959 { 0u, 0u, 0u }
1960 };
1961 const VkImageAspectFlagBits aspect = getPlaneAspect(planeNdx);
1962
1963 if (params.useMaint4)
1964 {
1965 const VkDeviceImageMemoryRequirementsKHR info =
1966 {
1967 VK_STRUCTURE_TYPE_DEVICE_IMAGE_MEMORY_REQUIREMENTS_KHR,
1968 DE_NULL,
1969 &imageInfo,
1970 aspect
1971 };
1972 vk.getDeviceImageMemoryRequirements(device, &info, &requirements);
1973 }
1974 else
1975 {
1976 const VkImagePlaneMemoryRequirementsInfo aspectInfo =
1977 {
1978 VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO_KHR,
1979 DE_NULL,
1980 aspect
1981 };
1982 const VkImageMemoryRequirementsInfo2 info =
1983 {
1984 VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR,
1985 (actualCreateFlags & VK_IMAGE_CREATE_DISJOINT_BIT_KHR) == 0 ? DE_NULL : &aspectInfo,
1986 *image
1987 };
1988
1989 vk.getImageMemoryRequirements2(device, &info, &requirements);
1990 }
1991
1992 log << TestLog::Message << "Aspect: " << getImageAspectFlagsStr(aspect) << ", Requirements: " << requirements << TestLog::EndMessage;
1993
1994 result.check(deIsPowerOfTwo64(static_cast<deUint64>(requirements.memoryRequirements.alignment)), "VkMemoryRequirements alignment isn't power of two");
1995
1996 if (result.check(requirements.memoryRequirements.memoryTypeBits != 0, "No supported memory types"))
1997 {
1998 typedef std::vector<deUint32>::const_iterator IndexIterator;
1999 const std::vector<deUint32> usedMemoryTypeIndices = bitsToIndices(requirements.memoryRequirements.memoryTypeBits);
2000 bool hasHostVisibleType = false;
2001
2002 for (IndexIterator memoryTypeNdx = usedMemoryTypeIndices.begin(); memoryTypeNdx != usedMemoryTypeIndices.end(); ++memoryTypeNdx)
2003 {
2004 if (result.check(*memoryTypeNdx < memoryProperties.memoryTypeCount, "Unknown memory type bits set in memory requirements"))
2005 {
2006 const VkMemoryPropertyFlags propertyFlags (memoryProperties.memoryTypes[*memoryTypeNdx].propertyFlags);
2007
2008 if (propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
2009 hasHostVisibleType = true;
2010
2011 if (propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
2012 {
2013 result.check((imageInfo.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0u,
2014 "Memory type includes VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT for a non-transient attachment image");
2015 }
2016 }
2017 else
2018 break;
2019 }
2020
2021 result.check(params.tiling != VK_IMAGE_TILING_LINEAR || hasHostVisibleType, "Required memory type doesn't include VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2022 }
2023 }
2024 }
2025 }
2026 }
2027
2028 return tcu::TestStatus(result.getResult(), result.getMessage());
2029 }
2030
checkSupportMultiplane(Context & context,ImageTestParams params)2031 void checkSupportMultiplane (Context& context, ImageTestParams params)
2032 {
2033 checkSupportImageMemoryRequirementsOriginal(context, params);
2034
2035 context.requireDeviceFunctionality("VK_KHR_get_memory_requirements2");
2036 context.requireDeviceFunctionality("VK_KHR_sampler_ycbcr_conversion");
2037
2038 if (params.useMaint4)
2039 context.requireDeviceFunctionality("VK_KHR_maintenance4");
2040 }
2041
populateMultiplaneTestGroup(tcu::TestCaseGroup * group,bool useMaint4)2042 void populateMultiplaneTestGroup (tcu::TestCaseGroup* group, bool useMaint4)
2043 {
2044 const struct
2045 {
2046 VkImageCreateFlags flags;
2047 bool transient;
2048 const char* const name;
2049 } imageFlagsCases[] =
2050 {
2051 { (VkImageCreateFlags)0, false, "regular" },
2052 { (VkImageCreateFlags)0, true, "transient" },
2053 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT, false, "sparse" },
2054 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, false, "sparse_residency" },
2055 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, false, "sparse_aliased" },
2056 { VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, false, "sparse_residency_aliased" },
2057 };
2058 const struct
2059 {
2060 VkImageTiling value;
2061 const char* name;
2062 } tilings[] =
2063 {
2064 { VK_IMAGE_TILING_OPTIMAL, "optimal" },
2065 { VK_IMAGE_TILING_LINEAR, "linear" }
2066 };
2067
2068 for (size_t flagsNdx = 0; flagsNdx < DE_LENGTH_OF_ARRAY(imageFlagsCases); ++flagsNdx)
2069 for (size_t tilingNdx = 0; tilingNdx < DE_LENGTH_OF_ARRAY(tilings); ++tilingNdx)
2070 {
2071 const VkImageCreateFlags flags = imageFlagsCases[flagsNdx].flags;
2072 const bool transient = imageFlagsCases[flagsNdx].transient;
2073 const VkImageTiling tiling = tilings[tilingNdx].value;
2074 const ImageTestParams params (flags, tiling, transient, useMaint4);
2075 const std::string name = std::string(imageFlagsCases[flagsNdx].name) + "_" + tilings[tilingNdx].name;
2076
2077 if (tiling == VK_IMAGE_TILING_LINEAR && (flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != 0)
2078 continue;
2079
2080 addFunctionCase(group, name, name, checkSupportMultiplane, testMultiplaneImages, params);
2081 }
2082 }
2083
testVkMemoryPropertyFlags(Context & context)2084 tcu::TestStatus testVkMemoryPropertyFlags(Context& context)
2085 {
2086 VkMemoryPropertyFlags propertyFlagSets[] =
2087 {
2088 0,
2089 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
2090 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2091 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
2092 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2093 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
2094 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2095 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
2096 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT,
2097 VK_MEMORY_PROPERTY_PROTECTED_BIT,
2098 VK_MEMORY_PROPERTY_PROTECTED_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2099 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD,
2100 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD,
2101 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD,
2102 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD,
2103 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD,
2104 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD,
2105 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD,
2106 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD,
2107 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD,
2108 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD,
2109 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_RDMA_CAPABLE_BIT_NV
2110 };
2111
2112 const InstanceInterface& vki = context.getInstanceInterface();
2113 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
2114 VkPhysicalDeviceMemoryProperties memoryProperties;
2115 uint32_t matchingTypes = 0;
2116 tcu::TestLog& log = context.getTestContext().getLog();
2117 tcu::ResultCollector result (log, "ERROR: ");
2118
2119 vki.getPhysicalDeviceMemoryProperties(physicalDevice, &memoryProperties);
2120
2121 for (uint32_t ndx = 0; ndx < memoryProperties.memoryTypeCount; ndx++)
2122 {
2123 for (auto& flag : propertyFlagSets)
2124 {
2125 if (memoryProperties.memoryTypes[ndx].propertyFlags == flag) matchingTypes++;
2126 }
2127 }
2128
2129 std::string diffStr = std::to_string(int(memoryProperties.memoryTypeCount - matchingTypes));
2130
2131 result.check(matchingTypes == memoryProperties.memoryTypeCount, "Unknown memory type bits set in memory requirements: " + diffStr + " mismatch");
2132
2133 return tcu::TestStatus(result.getResult(), result.getMessage());
2134 }
2135
populateMemoryPropertyFlagsTestGroup(tcu::TestCaseGroup * group)2136 void populateMemoryPropertyFlagsTestGroup(tcu::TestCaseGroup* group)
2137 {
2138 addFunctionCase(group, "check_all", "", testVkMemoryPropertyFlags);
2139 }
2140
populateMultiplaneTestGroup(tcu::TestCaseGroup * group)2141 void populateMultiplaneTestGroup (tcu::TestCaseGroup* group)
2142 {
2143 populateMultiplaneTestGroup(group, false);
2144 }
2145
populateCreateInfoTestGroup(tcu::TestCaseGroup * group)2146 void populateCreateInfoTestGroup (tcu::TestCaseGroup* group)
2147 {
2148 BufferMemoryRequirementsCreateInfo bufferTest;
2149 ImageMemoryRequirementsCreateInfo imageTest;
2150
2151 bufferTest.populateTestGroup(group);
2152 imageTest.populateTestGroup(group);
2153
2154 de::MovePtr<tcu::TestCaseGroup> multiplaneGroup(new tcu::TestCaseGroup(group->getTestContext(), "multiplane_image", ""));
2155 populateMultiplaneTestGroup(multiplaneGroup.get(), true);
2156 group->addChild(multiplaneGroup.release());
2157 }
2158
2159 } // anonymous
2160
2161
createRequirementsTests(tcu::TestContext & testCtx)2162 tcu::TestCaseGroup* createRequirementsTests (tcu::TestContext& testCtx)
2163 {
2164 de::MovePtr<tcu::TestCaseGroup> requirementsGroup(new tcu::TestCaseGroup(testCtx, "requirements", "Buffer and image memory requirements"));
2165
2166 requirementsGroup->addChild(createTestGroup(testCtx, "core", "Memory requirements tests with core functionality", populateCoreTestGroup));
2167 requirementsGroup->addChild(createTestGroup(testCtx, "extended", "Memory requirements tests with extension VK_KHR_get_memory_requirements2", populateExtendedTestGroup));
2168 requirementsGroup->addChild(createTestGroup(testCtx, "dedicated_allocation", "Memory requirements tests with extension VK_KHR_dedicated_allocation", populateDedicatedAllocationTestGroup));
2169 requirementsGroup->addChild(createTestGroup(testCtx, "multiplane_image", "Memory requirements tests with vkGetImagePlaneMemoryRequirements", populateMultiplaneTestGroup));
2170 requirementsGroup->addChild(createTestGroup(testCtx, "memory_property_flags", "Memory requirements tests with vkGetPhysicalDeviceMemoryProperties", populateMemoryPropertyFlagsTestGroup));
2171 requirementsGroup->addChild(createTestGroup(testCtx, "create_info", "Memory requirements tests with extension VK_KHR_maintenance4", populateCreateInfoTestGroup));
2172
2173 return requirementsGroup.release();
2174 }
2175
2176 } // memory
2177 } // vkt
2178