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 Buffer View Creation Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktApiBufferViewCreateTests.hpp"
38 #include "deStringUtil.hpp"
39 #include "gluVarType.hpp"
40 #include "tcuTestLog.hpp"
41 #include "vkPrograms.hpp"
42 #include "vktTestCase.hpp"
55 struct BufferViewCaseParameters
60 VkBufferUsageFlags usage;
61 VkFormatFeatureFlags features;
64 class BufferViewTestInstance : public TestInstance
67 BufferViewTestInstance (Context& ctx,
68 BufferViewCaseParameters createInfo);
69 virtual tcu::TestStatus iterate (void);
72 BufferViewCaseParameters m_testCase;
75 class BufferViewTestCase : public TestCase
78 BufferViewTestCase (tcu::TestContext& testCtx,
79 const std::string& name,
80 const std::string& description,
81 BufferViewCaseParameters createInfo)
82 : TestCase (testCtx, name, description)
83 , m_testCase (createInfo)
86 virtual ~BufferViewTestCase (void) {}
87 virtual TestInstance* createInstance (Context& ctx) const
89 return new BufferViewTestInstance(ctx, m_testCase);
93 BufferViewCaseParameters m_testCase;
96 BufferViewTestInstance::BufferViewTestInstance (Context& ctx,
97 BufferViewCaseParameters createInfo)
99 , m_testCase (createInfo)
103 tcu::TestStatus BufferViewTestInstance::iterate (void)
106 const VkDevice vkDevice = m_context.getDevice();
107 const DeviceInterface& vk = m_context.getDeviceInterface();
108 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
109 const VkDeviceSize size = 16 * 1024;
111 VkMemoryRequirements memReqs;
112 VkFormatProperties properties;
113 const VkBufferCreateInfo bufferParams =
115 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
116 DE_NULL, // const void* pNext;
117 0u, // VkBufferCreateFlags flags;
118 size, // VkDeviceSize size;
119 m_testCase.usage, // VkBufferUsageFlags usage;
120 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
121 1u, // deUint32 queueFamilyCount;
122 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
125 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), m_testCase.format, &properties);
126 if (!(properties.bufferFeatures & m_testCase.features))
127 TCU_THROW(NotSupportedError, "Format not supported");
129 if (vk.createBuffer(vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL, &testBuffer) != VK_SUCCESS)
130 return tcu::TestStatus::fail("Buffer creation failed!");
132 vk.getBufferMemoryRequirements(vkDevice, testBuffer, &memReqs);
134 if (size > memReqs.size)
136 std::ostringstream errorMsg;
137 errorMsg << "Requied memory size (" << memReqs.size << " bytes) smaller than the buffer's size (" << size << " bytes)!";
138 return tcu::TestStatus::fail(errorMsg.str());
141 VkDeviceMemory memory;
142 const VkMemoryAllocateInfo memAlloc =
144 VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType
145 NULL, // const void* pNext
146 memReqs.size, // VkDeviceSize allocationSize
147 0 // deUint32 memoryTypeIndex
151 // Create buffer view.
152 VkBufferView bufferView;
153 const VkBufferViewCreateInfo bufferViewCreateInfo =
155 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
156 NULL, // const void* pNext;
157 (VkBufferViewCreateFlags)0,
158 testBuffer, // VkBuffer buffer;
159 m_testCase.format, // VkFormat format;
160 m_testCase.offset, // VkDeviceSize offset;
161 m_testCase.range, // VkDeviceSize range;
164 if (vk.allocateMemory(vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL, &memory) != VK_SUCCESS)
165 return tcu::TestStatus::fail("Alloc memory failed!");
167 if (vk.bindBufferMemory(vkDevice, testBuffer, memory, 0) != VK_SUCCESS)
168 return tcu::TestStatus::fail("Bind buffer memory failed!");
170 if (vk.createBufferView(vkDevice, &bufferViewCreateInfo, (const VkAllocationCallbacks*)DE_NULL, &bufferView) != VK_SUCCESS)
171 return tcu::TestStatus::fail("Buffer View creation failed!");
173 vk.destroyBufferView(vkDevice, bufferView, (const VkAllocationCallbacks*)DE_NULL);
176 // Testing complete view size.
178 VkBufferView completeBufferView;
179 VkBufferViewCreateInfo completeBufferViewCreateInfo =
181 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
182 NULL, // const void* pNext;
183 (VkBufferViewCreateFlags)0,
184 testBuffer, // VkBuffer buffer;
185 m_testCase.format, // VkFormat format;
186 m_testCase.offset, // VkDeviceSize offset;
187 size, // VkDeviceSize range;
190 if (vk.createBufferView(vkDevice, &completeBufferViewCreateInfo, (const VkAllocationCallbacks*)DE_NULL, &completeBufferView) != VK_SUCCESS)
191 return tcu::TestStatus::fail("Buffer View creation failed!");
193 vk.destroyBufferView(vkDevice, completeBufferView, (const VkAllocationCallbacks*)DE_NULL);
196 vk.freeMemory(vkDevice, memory, (const VkAllocationCallbacks*)DE_NULL);
197 vk.destroyBuffer(vkDevice, testBuffer, (const VkAllocationCallbacks*)DE_NULL);
199 return tcu::TestStatus::pass("BufferView test");
204 tcu::TestCaseGroup* createBufferViewCreateTests (tcu::TestContext& testCtx)
206 de::MovePtr<tcu::TestCaseGroup> bufferViewTests (new tcu::TestCaseGroup(testCtx, "create", "BufferView Construction Tests"));
208 const VkDeviceSize range = 96;
209 for (deUint32 format = VK_FORMAT_UNDEFINED + 1; format < VK_FORMAT_LAST; format++)
211 std::ostringstream testName;
212 std::ostringstream testDescription;
213 testName << "createBufferView_" << format;
214 testDescription << "vkBufferView test " << testName.str();
216 BufferViewCaseParameters testParams =
218 (VkFormat)format, // VkFormat format;
219 0, // VkDeviceSize offset;
220 range, // VkDeviceSize range;
221 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, // VkBufferUsageFlags usage;
222 VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT, // VkFormatFeatureFlags flags;
224 bufferViewTests->addChild(new BufferViewTestCase(testCtx, testName.str() + "_uniform", testDescription.str(), testParams));
227 BufferViewCaseParameters testParams =
229 (VkFormat)format, // VkFormat format;
230 0, // VkDeviceSize offset;
231 range, // VkDeviceSize range;
232 VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, // VkBufferUsageFlags usage;
233 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT, // VkFormatFeatureFlags flags;
235 bufferViewTests->addChild(new BufferViewTestCase(testCtx, testName.str() + "_storage", testDescription.str(), testParams));
239 return bufferViewTests.release();