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 "vktTestCase.hpp"
55 struct BufferCaseParameters
57 VkBufferUsageFlags usage;
58 VkBufferCreateFlags flags;
59 VkSharingMode sharingMode;
62 class BufferTestInstance : public TestInstance
65 BufferTestInstance (Context& ctx,
66 BufferCaseParameters testCase)
68 , m_testCase (testCase)
70 virtual tcu::TestStatus iterate (void);
71 tcu::TestStatus bufferCreateAndAllocTest (VkDeviceSize size);
74 BufferCaseParameters m_testCase;
77 class BuffersTestCase : public TestCase
80 BuffersTestCase (tcu::TestContext& testCtx,
81 const std::string& name,
82 const std::string& description,
83 BufferCaseParameters testCase)
84 : TestCase(testCtx, name, description)
85 , m_testCase(testCase)
88 virtual ~BuffersTestCase (void) {}
89 virtual TestInstance* createInstance (Context& ctx) const
91 tcu::TestLog& log = m_testCtx.getLog();
92 log << tcu::TestLog::Message << getBufferUsageFlagsStr(m_testCase.usage) << tcu::TestLog::EndMessage;
93 return new BufferTestInstance(ctx, m_testCase);
97 BufferCaseParameters m_testCase;
100 tcu::TestStatus BufferTestInstance::bufferCreateAndAllocTest (VkDeviceSize size)
102 const VkDevice vkDevice = m_context.getDevice();
103 const DeviceInterface& vk = m_context.getDeviceInterface();
105 VkMemoryRequirements memReqs;
106 VkDeviceMemory memory;
110 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
111 const VkBufferCreateInfo bufferParams =
113 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
118 m_testCase.sharingMode,
119 1u, // deUint32 queueFamilyCount;
123 if (vk.createBuffer(vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL, &testBuffer) != VK_SUCCESS)
124 return tcu::TestStatus::fail("Buffer creation failed! (requested memory size: " + de::toString(size) + ")");
126 vk.getBufferMemoryRequirements(vkDevice, testBuffer, &memReqs);
128 if (size > memReqs.size)
130 std::ostringstream errorMsg;
131 errorMsg << "Requied memory size (" << memReqs.size << " bytes) smaller than the buffer's size (" << size << " bytes)!";
132 return tcu::TestStatus::fail(errorMsg.str());
136 // Allocate and bind memory
138 const VkMemoryAllocateInfo memAlloc =
140 VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
143 0 // deUint32 memoryTypeIndex
146 if (vk.allocateMemory(vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL, &memory) != VK_SUCCESS)
147 return tcu::TestStatus::fail("Alloc memory failed! (requested memory size: " + de::toString(size) + ")");
149 if (vk.bindBufferMemory(vkDevice, testBuffer, memory, 0) != VK_SUCCESS)
150 return tcu::TestStatus::fail("Bind buffer memory failed! (requested memory size: " + de::toString(size) + ")");
153 vk.freeMemory(vkDevice, memory, (const VkAllocationCallbacks*)DE_NULL);
154 vk.destroyBuffer(vkDevice, testBuffer, (const VkAllocationCallbacks*)DE_NULL);
156 return tcu::TestStatus::pass("Buffer test");
159 tcu::TestStatus BufferTestInstance::iterate (void)
161 const VkDeviceSize testSizes[] =
168 tcu::TestStatus testStatus = tcu::TestStatus::pass("Buffer test");
170 for (int i = 0; i < DE_LENGTH_OF_ARRAY(testSizes); i++)
172 if ((testStatus = bufferCreateAndAllocTest(testSizes[i])).getCode() != QP_TEST_RESULT_PASS)
176 if (m_testCase.usage & (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT))
178 const VkPhysicalDevice vkPhysicalDevice = m_context.getPhysicalDevice();
179 const InstanceInterface& vkInstance = m_context.getInstanceInterface();
180 VkPhysicalDeviceProperties props;
182 vkInstance.getPhysicalDeviceProperties(vkPhysicalDevice, &props);
184 testStatus = bufferCreateAndAllocTest(props.limits.maxTexelBufferElements);
192 tcu::TestCaseGroup* createBufferTests (tcu::TestContext& testCtx)
194 const VkBufferUsageFlags bufferUsageModes[] =
196 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
197 VK_BUFFER_USAGE_TRANSFER_DST_BIT,
198 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT,
199 VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
200 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
201 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
202 VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
203 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
204 VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
207 const VkBufferCreateFlags bufferCreateFlags[] =
209 VK_BUFFER_CREATE_SPARSE_BINDING_BIT,
210 VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT,
211 VK_BUFFER_CREATE_SPARSE_ALIASED_BIT
214 de::MovePtr<tcu::TestCaseGroup> buffersTests (new tcu::TestCaseGroup(testCtx, "buffer", "Buffer Tests"));
216 deUint32 numberOfBufferUsageFlags = DE_LENGTH_OF_ARRAY(bufferUsageModes);
217 deUint32 numberOfBufferCreateFlags = DE_LENGTH_OF_ARRAY(bufferCreateFlags);
218 deUint32 maximumValueOfBufferUsageFlags = (1 << (numberOfBufferUsageFlags - 1)) - 1;
219 deUint32 maximumValueOfBufferCreateFlags = (1 << (numberOfBufferCreateFlags)) - 1;
221 for (deUint32 combinedBufferCreateFlags = 0; combinedBufferCreateFlags <= maximumValueOfBufferCreateFlags; combinedBufferCreateFlags++)
223 for (deUint32 combinedBufferUsageFlags = 1; combinedBufferUsageFlags <= maximumValueOfBufferUsageFlags; combinedBufferUsageFlags++)
225 BufferCaseParameters testParams =
227 combinedBufferUsageFlags,
228 combinedBufferCreateFlags,
229 VK_SHARING_MODE_EXCLUSIVE
231 std::ostringstream testName;
232 std::ostringstream testDescription;
233 testName << "createBuffer_" << combinedBufferUsageFlags << "_" << combinedBufferCreateFlags;
234 testDescription << "vkCreateBuffer test " << combinedBufferUsageFlags << " " << combinedBufferCreateFlags;
235 buffersTests->addChild(new BuffersTestCase(testCtx, testName.str(), testDescription.str(), testParams));
239 return buffersTests.release();