1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Vulkan Buffers Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktApiBufferTests.hpp"
38 #include "deStringUtil.hpp"
39 #include "gluVarType.hpp"
40 #include "tcuTestLog.hpp"
41 #include "vkPrograms.hpp"
42 #include "vkQueryUtil.hpp"
43 #include "vktTestCase.hpp"
56 struct BufferCaseParameters
58 VkBufferUsageFlags usage;
59 VkBufferCreateFlags flags;
60 VkSharingMode sharingMode;
63 class BufferTestInstance : public TestInstance
66 BufferTestInstance (Context& ctx,
67 BufferCaseParameters testCase)
69 , m_testCase (testCase)
71 virtual tcu::TestStatus iterate (void);
72 tcu::TestStatus bufferCreateAndAllocTest (VkDeviceSize size);
75 BufferCaseParameters m_testCase;
78 class BuffersTestCase : public TestCase
81 BuffersTestCase (tcu::TestContext& testCtx,
82 const std::string& name,
83 const std::string& description,
84 BufferCaseParameters testCase)
85 : TestCase(testCtx, name, description)
86 , m_testCase(testCase)
89 virtual ~BuffersTestCase (void) {}
90 virtual TestInstance* createInstance (Context& ctx) const
92 tcu::TestLog& log = m_testCtx.getLog();
93 log << tcu::TestLog::Message << getBufferUsageFlagsStr(m_testCase.usage) << tcu::TestLog::EndMessage;
94 return new BufferTestInstance(ctx, m_testCase);
98 BufferCaseParameters m_testCase;
101 tcu::TestStatus BufferTestInstance::bufferCreateAndAllocTest (VkDeviceSize size)
103 const VkDevice vkDevice = m_context.getDevice();
104 const DeviceInterface& vk = m_context.getDeviceInterface();
106 VkMemoryRequirements memReqs;
107 VkDeviceMemory memory;
108 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
112 const VkBufferCreateInfo bufferParams =
114 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
119 m_testCase.sharingMode,
120 1u, // deUint32 queueFamilyCount;
124 if (vk.createBuffer(vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL, &testBuffer) != VK_SUCCESS)
125 return tcu::TestStatus::fail("Buffer creation failed! (requested memory size: " + de::toString(size) + ")");
127 vk.getBufferMemoryRequirements(vkDevice, testBuffer, &memReqs);
129 if (size > memReqs.size)
131 std::ostringstream errorMsg;
132 errorMsg << "Requied memory size (" << memReqs.size << " bytes) smaller than the buffer's size (" << size << " bytes)!";
133 return tcu::TestStatus::fail(errorMsg.str());
137 // Allocate and bind memory
139 const VkMemoryAllocateInfo memAlloc =
141 VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
144 0 // deUint32 memoryTypeIndex
147 if (vk.allocateMemory(vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL, &memory) != VK_SUCCESS)
148 return tcu::TestStatus::fail("Alloc memory failed! (requested memory size: " + de::toString(size) + ")");
151 if ((m_testCase.flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) ||
152 (m_testCase.flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) ||
153 (m_testCase.flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT))
157 vk.getDeviceQueue(vkDevice, queueFamilyIndex, 0, &queue);
159 const VkSparseMemoryBind sparseMemoryBind =
161 0, // VkDeviceSize resourceOffset;
162 memReqs.size, // VkDeviceSize size;
163 memory, // VkDeviceMemory memory;
164 0, // VkDeviceSize memoryOffset;
165 0 // VkSparseMemoryBindFlags flags;
168 const VkSparseBufferMemoryBindInfo sparseBufferMemoryBindInfo =
170 testBuffer, // VkBuffer buffer;
171 1u, // deUint32 bindCount;
172 &sparseMemoryBind // const VkSparseMemoryBind* pBinds;
175 const VkBindSparseInfo bindSparseInfo =
177 VK_STRUCTURE_TYPE_BIND_SPARSE_INFO, // VkStructureType sType;
178 DE_NULL, // const void* pNext;
179 0, // deUint32 waitSemaphoreCount;
180 DE_NULL, // const VkSemaphore* pWaitSemaphores;
181 1u, // deUint32 bufferBindCount;
182 &sparseBufferMemoryBindInfo, // const VkSparseBufferMemoryBindInfo* pBufferBinds;
183 0, // deUint32 imageOpaqueBindCount;
184 DE_NULL, // const VkSparseImageOpaqueMemoryBindInfo* pImageOpaqueBinds;
185 0, // deUint32 imageBindCount;
186 DE_NULL, // const VkSparseImageMemoryBindInfo* pImageBinds;
187 0, // deUint32 signalSemaphoreCount;
188 DE_NULL, // const VkSemaphore* pSignalSemaphores;
191 if (vk.queueBindSparse(queue, 1, &bindSparseInfo, DE_NULL) != VK_SUCCESS)
192 return tcu::TestStatus::fail("Bind sparse buffer memory failed! (requested memory size: " + de::toString(size) + ")");
194 if (vk.bindBufferMemory(vkDevice, testBuffer, memory, 0) != VK_SUCCESS)
195 return tcu::TestStatus::fail("Bind buffer memory failed! (requested memory size: " + de::toString(size) + ")");
198 vk.freeMemory(vkDevice, memory, (const VkAllocationCallbacks*)DE_NULL);
199 vk.destroyBuffer(vkDevice, testBuffer, (const VkAllocationCallbacks*)DE_NULL);
201 return tcu::TestStatus::pass("Buffer test");
204 tcu::TestStatus BufferTestInstance::iterate (void)
206 const VkPhysicalDeviceFeatures& physicalDeviceFeatures = m_context.getDeviceFeatures();
208 if ((m_testCase.flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT ) && !physicalDeviceFeatures.sparseBinding)
209 TCU_THROW(NotSupportedError, "Sparse bindings feature is not supported");
211 if ((m_testCase.flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT ) && !physicalDeviceFeatures.sparseResidencyBuffer)
212 TCU_THROW(NotSupportedError, "Sparse buffer residency feature is not supported");
214 if ((m_testCase.flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT ) && !physicalDeviceFeatures.sparseResidencyAliased)
215 TCU_THROW(NotSupportedError, "Sparse aliased residency feature is not supported");
217 const VkDeviceSize testSizes[] =
224 tcu::TestStatus testStatus = tcu::TestStatus::pass("Buffer test");
226 for (int i = 0; i < DE_LENGTH_OF_ARRAY(testSizes); i++)
228 if ((testStatus = bufferCreateAndAllocTest(testSizes[i])).getCode() != QP_TEST_RESULT_PASS)
232 if (m_testCase.usage & (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT))
234 const VkPhysicalDevice vkPhysicalDevice = m_context.getPhysicalDevice();
235 const InstanceInterface& vkInstance = m_context.getInstanceInterface();
236 const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(vkInstance, vkPhysicalDevice);
237 VkPhysicalDeviceProperties props;
239 vkInstance.getPhysicalDeviceProperties(vkPhysicalDevice, &props);
241 const VkDeviceSize maxTestBufferSize = de::min((VkDeviceSize) props.limits.maxTexelBufferElements, memoryProperties.memoryHeaps[memoryProperties.memoryTypes[0].heapIndex].size / 16);
243 testStatus = bufferCreateAndAllocTest(maxTestBufferSize);
251 tcu::TestCaseGroup* createBufferTests (tcu::TestContext& testCtx)
253 const VkBufferUsageFlags bufferUsageModes[] =
255 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
256 VK_BUFFER_USAGE_TRANSFER_DST_BIT,
257 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT,
258 VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
259 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
260 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
261 VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
262 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
263 VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
266 const VkBufferCreateFlags bufferCreateFlags[] =
268 VK_BUFFER_CREATE_SPARSE_BINDING_BIT,
269 VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT,
270 VK_BUFFER_CREATE_SPARSE_ALIASED_BIT
273 de::MovePtr<tcu::TestCaseGroup> buffersTests (new tcu::TestCaseGroup(testCtx, "buffer", "Buffer Tests"));
275 deUint32 numberOfBufferUsageFlags = DE_LENGTH_OF_ARRAY(bufferUsageModes);
276 deUint32 numberOfBufferCreateFlags = DE_LENGTH_OF_ARRAY(bufferCreateFlags);
277 deUint32 maximumValueOfBufferUsageFlags = (1 << (numberOfBufferUsageFlags - 1)) - 1;
278 deUint32 maximumValueOfBufferCreateFlags = (1 << (numberOfBufferCreateFlags)) - 1;
280 for (deUint32 combinedBufferCreateFlags = 0; combinedBufferCreateFlags <= maximumValueOfBufferCreateFlags; combinedBufferCreateFlags++)
282 for (deUint32 combinedBufferUsageFlags = 1; combinedBufferUsageFlags <= maximumValueOfBufferUsageFlags; combinedBufferUsageFlags++)
284 BufferCaseParameters testParams =
286 combinedBufferUsageFlags,
287 combinedBufferCreateFlags,
288 VK_SHARING_MODE_EXCLUSIVE
290 std::ostringstream testName;
291 std::ostringstream testDescription;
292 testName << "createBuffer_" << combinedBufferUsageFlags << "_" << combinedBufferCreateFlags;
293 testDescription << "vkCreateBuffer test " << combinedBufferUsageFlags << " " << combinedBufferCreateFlags;
294 buffersTests->addChild(new BuffersTestCase(testCtx, testName.str(), testDescription.str(), testParams));
298 return buffersTests.release();