1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2017 The Khronos Group Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Implementation of utility classes for various kinds of
22 * allocation memory for buffers and images
23 *//*--------------------------------------------------------------------*/
25 #include "vktApiBufferAndImageAllocationUtil.hpp"
28 #include "tcuVectorUtil.hpp"
29 #include "vkQueryUtil.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkRefUtil.hpp"
41 void BufferSuballocation::createTestBuffer (VkDeviceSize size,
42 VkBufferUsageFlags usage,
45 Move<VkBuffer>& buffer,
46 const MemoryRequirement& requirement,
47 de::MovePtr<Allocation>& memory) const
49 const VkDevice vkDevice = context.getDevice();
50 const DeviceInterface& vk = context.getDeviceInterface();
51 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
52 const VkBufferCreateInfo bufferParams =
54 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
55 DE_NULL, // const void* pNext;
56 0u, // VkBufferCreateFlags flags;
57 size, // VkDeviceSize size;
58 usage, // VkBufferUsageFlags usage;
59 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
60 1u, // deUint32 queueFamilyCount;
61 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
64 buffer = vk::createBuffer(vk, vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL);
65 memory = allocator.allocate(getBufferMemoryRequirements(vk, vkDevice, *buffer), requirement);
66 VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, memory->getMemory(), 0));
69 void BufferDedicatedAllocation::createTestBuffer (VkDeviceSize size,
70 VkBufferUsageFlags usage,
73 Move<VkBuffer>& buffer,
74 const MemoryRequirement& requirement,
75 de::MovePtr<Allocation>& memory) const
78 const std::vector<std::string>& extensions = context.getDeviceExtensions();
79 const deBool isSupported = std::find(extensions.begin(), extensions.end(), "VK_KHR_dedicated_allocation") != extensions.end();
82 TCU_THROW(NotSupportedError, "Not supported");
85 const InstanceInterface& vkInstance = context.getInstanceInterface();
86 const VkDevice vkDevice = context.getDevice();
87 const VkPhysicalDevice vkPhysicalDevice = context.getPhysicalDevice();
88 const DeviceInterface& vk = context.getDeviceInterface();
89 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
91 const VkBufferCreateInfo bufferParams =
93 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
94 DE_NULL, // const void* pNext;
95 0u, // VkBufferCreateFlags flags;
96 size, // VkDeviceSize size;
97 usage, // VkBufferUsageFlags usage;
98 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
99 1u, // deUint32 queueFamilyCount;
100 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
103 buffer = vk::createBuffer(vk, vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL);
104 memory = allocateDedicated(vkInstance, vk, vkPhysicalDevice, vkDevice, buffer.get(), requirement);
105 VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, memory->getMemory(), memory->getOffset()));
108 void ImageSuballocation::createTestImage (tcu::IVec2 size,
111 Allocator& allocator,
112 Move<VkImage>& image,
113 const MemoryRequirement& requirement,
114 de::MovePtr<Allocation>& memory) const
116 const VkDevice vkDevice = context.getDevice();
117 const DeviceInterface& vk = context.getDeviceInterface();
118 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
120 const VkImageCreateInfo colorImageParams =
122 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
123 DE_NULL, // const void* pNext;
124 0u, // VkImageCreateFlags flags;
125 VK_IMAGE_TYPE_2D, // VkImageType imageType;
126 format, // VkFormat format;
127 { (deUint32)size.x(), (deUint32)size.y(), 1u }, // VkExtent3D extent;
128 1u, // deUint32 mipLevels;
129 1u, // deUint32 arraySize;
130 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
131 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
132 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
133 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
134 1u, // deUint32 queueFamilyCount;
135 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
136 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
139 image = createImage(vk, vkDevice, &colorImageParams);
140 memory = allocator.allocate(getImageMemoryRequirements(vk, vkDevice, *image), requirement);
141 VK_CHECK(vk.bindImageMemory(vkDevice, *image, memory->getMemory(), memory->getOffset()));
144 void ImageDedicatedAllocation::createTestImage (tcu::IVec2 size,
147 Allocator& allocator,
148 Move<VkImage>& image,
149 const MemoryRequirement& requirement,
150 de::MovePtr<Allocation>& memory) const
153 const std::vector<std::string>& extensions = context.getDeviceExtensions();
154 const deBool isSupported = std::find(extensions.begin(), extensions.end(), "VK_KHR_dedicated_allocation") != extensions.end();
157 TCU_THROW(NotSupportedError, "Not supported");
160 const InstanceInterface& vkInstance = context.getInstanceInterface();
161 const VkDevice vkDevice = context.getDevice();
162 const VkPhysicalDevice vkPhysicalDevice = context.getPhysicalDevice();
163 const DeviceInterface& vk = context.getDeviceInterface();
164 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
166 const VkImageCreateInfo colorImageParams =
168 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
169 DE_NULL, // const void* pNext;
170 0u, // VkImageCreateFlags flags;
171 VK_IMAGE_TYPE_2D, // VkImageType imageType;
172 format, // VkFormat format;
173 { (deUint32)size.x(), (deUint32)size.y(), 1u }, // VkExtent3D extent;
174 1u, // deUint32 mipLevels;
175 1u, // deUint32 arraySize;
176 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
177 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
178 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
179 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
180 1u, // deUint32 queueFamilyCount;
181 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
182 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
185 image = createImage(vk, vkDevice, &colorImageParams);
186 memory = allocateDedicated(vkInstance, vk, vkPhysicalDevice, vkDevice, image.get(), requirement);
187 VK_CHECK(vk.bindImageMemory(vkDevice, *image, memory->getMemory(), memory->getOffset()));