1 #ifndef _VKTSPARSERESOURCESTESTSUTIL_HPP
2 #define _VKTSPARSERESOURCESTESTSUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2016 The Khronos Group Inc.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 * \file vktSparseResourcesTestsUtil.hpp
23 * \brief Sparse Resources Tests Utility Classes
24 *//*--------------------------------------------------------------------*/
27 #include "vkMemUtil.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkImageUtil.hpp"
32 #include "deSharedPtr.hpp"
33 #include "deUniquePtr.hpp"
40 typedef de::SharedPtr<vk::Unique<vk::VkDeviceMemory> > DeviceMemorySp;
50 IMAGE_TYPE_CUBE_ARRAY,
58 FEATURE_TESSELLATION_SHADER = 1u << 0,
59 FEATURE_GEOMETRY_SHADER = 1u << 1,
60 FEATURE_SHADER_FLOAT_64 = 1u << 2,
61 FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS = 1u << 3,
62 FEATURE_FRAGMENT_STORES_AND_ATOMICS = 1u << 4,
63 FEATURE_SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE = 1u << 5,
65 typedef deUint32 FeatureFlags;
69 BUFFER_IMAGE_COPY_OFFSET_GRANULARITY = 4u,
70 NO_MATCH_FOUND = ~((deUint32)0), //!< no matching index
73 vk::VkImageType mapImageType (const ImageType imageType);
75 vk::VkImageViewType mapImageViewType (const ImageType imageType);
77 std::string getImageTypeName (const ImageType imageType);
79 std::string getShaderImageType (const tcu::TextureFormat& format,
80 const ImageType imageType);
82 std::string getShaderImageDataType (const tcu::TextureFormat& format);
84 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format);
86 std::string getShaderImageCoordinates (const ImageType imageType,
88 const std::string& xy,
89 const std::string& xyz);
91 //!< Size used for addresing image in a compute shader
92 tcu::UVec3 getShaderGridSize (const ImageType imageType,
93 const tcu::UVec3& imageSize,
94 const deUint32 mipLevel = 0);
96 //!< Size of a single image layer
97 tcu::UVec3 getLayerSize (const ImageType imageType,
98 const tcu::UVec3& imageSize);
100 //!< Number of array layers (for array and cube types)
101 deUint32 getNumLayers (const ImageType imageType,
102 const tcu::UVec3& imageSize);
104 //!< Number of texels in an image
105 deUint32 getNumPixels (const ImageType imageType,
106 const tcu::UVec3& imageSize);
108 //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
109 deUint32 getDimensions (const ImageType imageType);
111 //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
112 deUint32 getLayerDimensions (const ImageType imageType);
114 //!< Helper function for checking if requested image size does not exceed device limits
115 bool isImageSizeSupported (const vk::InstanceInterface& instance,
116 const vk::VkPhysicalDevice physicalDevice,
117 const ImageType imageType,
118 const tcu::UVec3& imageSize);
120 vk::VkExtent3D mipLevelExtents (const vk::VkExtent3D& baseExtents,
121 const deUint32 mipLevel);
123 tcu::UVec3 mipLevelExtents (const tcu::UVec3& baseExtents,
124 const deUint32 mipLevel);
126 deUint32 getImageMaxMipLevels (const vk::VkImageFormatProperties& imageFormatProperties,
127 const vk::VkExtent3D& extent);
129 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
130 const deUint32 layersCount,
131 const tcu::TextureFormat& format,
132 const deUint32 mipmapLevel,
133 const deUint32 mipmapMemoryAlignment = 1u);
135 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
136 const deUint32 layersCount,
137 const tcu::TextureFormat& format,
138 const deUint32 mipmapLevelsCount = 1u,
139 const deUint32 mipmapMemoryAlignment = 1u);
141 vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk,
142 const vk::VkDevice device,
143 const deUint32 queueFamilyIndex);
145 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
146 const vk::VkDevice device,
147 const vk::VkDescriptorSetLayout descriptorSetLayout = DE_NULL);
149 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
150 const vk::VkDevice device,
151 const vk::VkPipelineLayout pipelineLayout,
152 const vk::VkShaderModule shaderModule,
153 const vk::VkSpecializationInfo* specializationInfo = 0);
155 vk::Move<vk::VkBufferView> makeBufferView (const vk::DeviceInterface& vk,
156 const vk::VkDevice device,
157 const vk::VkBuffer buffer,
158 const vk::VkFormat format,
159 const vk::VkDeviceSize offset,
160 const vk::VkDeviceSize size);
162 vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk,
163 const vk::VkDevice device,
164 const vk::VkImage image,
165 const vk::VkImageViewType imageViewType,
166 const vk::VkFormat format,
167 const vk::VkImageSubresourceRange subresourceRange);
169 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk,
170 const vk::VkDevice device,
171 const vk::VkDescriptorPool descriptorPool,
172 const vk::VkDescriptorSetLayout setLayout);
174 vk::Move<vk::VkFramebuffer> makeFramebuffer (const vk::DeviceInterface& vk,
175 const vk::VkDevice device,
176 const vk::VkRenderPass renderPass,
177 const deUint32 attachmentCount,
178 const vk::VkImageView* pAttachments,
179 const deUint32 width,
180 const deUint32 height,
181 const deUint32 layers = 1u);
183 de::MovePtr<vk::Allocation> bindImage (const vk::DeviceInterface& vk,
184 const vk::VkDevice device,
185 vk::Allocator& allocator,
186 const vk::VkImage image,
187 const vk::MemoryRequirement requirement);
189 de::MovePtr<vk::Allocation> bindBuffer (const vk::DeviceInterface& vk,
190 const vk::VkDevice device,
191 vk::Allocator& allocator,
192 const vk::VkBuffer buffer,
193 const vk::MemoryRequirement requirement);
195 vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize,
196 const vk::VkBufferUsageFlags usage);
198 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
199 const deUint32 layersCount,
200 const deUint32 mipmapLevel = 0u,
201 const vk::VkDeviceSize bufferOffset = 0ull);
203 vk::VkBufferMemoryBarrier makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
204 const vk::VkAccessFlags dstAccessMask,
205 const vk::VkBuffer buffer,
206 const vk::VkDeviceSize offset,
207 const vk::VkDeviceSize bufferSizeBytes);
209 vk::VkImageMemoryBarrier makeImageMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
210 const vk::VkAccessFlags dstAccessMask,
211 const vk::VkImageLayout oldLayout,
212 const vk::VkImageLayout newLayout,
213 const vk::VkImage image,
214 const vk::VkImageSubresourceRange subresourceRange);
216 vk::VkImageMemoryBarrier makeImageMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
217 const vk::VkAccessFlags dstAccessMask,
218 const vk::VkImageLayout oldLayout,
219 const vk::VkImageLayout newLayout,
220 const deUint32 srcQueueFamilyIndex,
221 const deUint32 destQueueFamilyIndex,
222 const vk::VkImage image,
223 const vk::VkImageSubresourceRange subresourceRange);
225 vk::VkMemoryBarrier makeMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
226 const vk::VkAccessFlags dstAccessMask);
228 vk::VkSparseImageMemoryBind makeSparseImageMemoryBind (const vk::DeviceInterface& vk,
229 const vk::VkDevice device,
230 const vk::VkDeviceSize allocationSize,
231 const deUint32 memoryType,
232 const vk::VkImageSubresource& subresource,
233 const vk::VkOffset3D& offset,
234 const vk::VkExtent3D& extent);
236 vk::VkSparseMemoryBind makeSparseMemoryBind (const vk::DeviceInterface& vk,
237 const vk::VkDevice device,
238 const vk::VkDeviceSize allocationSize,
239 const deUint32 memoryType,
240 const vk::VkDeviceSize resourceOffset,
241 const vk::VkSparseMemoryBindFlags flags = 0u);
243 void beginCommandBuffer (const vk::DeviceInterface& vk,
244 const vk::VkCommandBuffer cmdBuffer);
246 void endCommandBuffer (const vk::DeviceInterface& vk,
247 const vk::VkCommandBuffer cmdBuffer);
249 void submitCommands (const vk::DeviceInterface& vk,
250 const vk::VkQueue queue,
251 const vk::VkCommandBuffer cmdBuffer,
252 const deUint32 waitSemaphoreCount = 0,
253 const vk::VkSemaphore* pWaitSemaphores = DE_NULL,
254 const vk::VkPipelineStageFlags* pWaitDstStageMask = DE_NULL,
255 const deUint32 signalSemaphoreCount = 0,
256 const vk::VkSemaphore* pSignalSemaphores = DE_NULL);
258 void submitCommandsAndWait (const vk::DeviceInterface& vk,
259 const vk::VkDevice device,
260 const vk::VkQueue queue,
261 const vk::VkCommandBuffer cmdBuffer,
262 const deUint32 waitSemaphoreCount = 0,
263 const vk::VkSemaphore* pWaitSemaphores = DE_NULL,
264 const vk::VkPipelineStageFlags* pWaitDstStageMask = DE_NULL,
265 const deUint32 signalSemaphoreCount = 0,
266 const vk::VkSemaphore* pSignalSemaphores = DE_NULL);
268 void requireFeatures (const vk::InstanceInterface& vki,
269 const vk::VkPhysicalDevice physicalDevice,
270 const FeatureFlags flags);
272 deUint32 findMatchingMemoryType (const vk::InstanceInterface& instance,
273 const vk::VkPhysicalDevice physicalDevice,
274 const vk::VkMemoryRequirements& objectMemoryRequirements,
275 const vk::MemoryRequirement& memoryRequirement);
277 bool checkSparseSupportForImageType (const vk::InstanceInterface& instance,
278 const vk::VkPhysicalDevice physicalDevice,
279 const ImageType imageType);
281 bool checkSparseSupportForImageFormat (const vk::InstanceInterface& instance,
282 const vk::VkPhysicalDevice physicalDevice,
283 const vk::VkImageCreateInfo& imageInfo);
285 bool checkImageFormatFeatureSupport (const vk::InstanceInterface& instance,
286 const vk::VkPhysicalDevice physicalDevice,
287 const vk::VkFormat format,
288 const vk::VkFormatFeatureFlags featureFlags);
290 deUint32 getSparseAspectRequirementsIndex (const std::vector<vk::VkSparseImageMemoryRequirements>& requirements,
291 const vk::VkImageAspectFlags aspectFlags);
293 inline vk::Move<vk::VkBuffer> makeBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkBufferCreateInfo& createInfo)
295 return createBuffer(vk, device, &createInfo);
298 inline vk::Move<vk::VkImage> makeImage (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkImageCreateInfo& createInfo)
300 return createImage(vk, device, &createInfo);
304 inline de::SharedPtr<vk::Unique<T> > makeVkSharedPtr (vk::Move<T> vkMove)
306 return de::SharedPtr<vk::Unique<T> >(new vk::Unique<T>(vkMove));
310 inline de::SharedPtr<de::UniquePtr<T> > makeDeSharedPtr (de::MovePtr<T> deMove)
312 return de::SharedPtr<de::UniquePtr<T> >(new de::UniquePtr<T>(deMove));
316 inline std::size_t sizeInBytes (const std::vector<T>& vec)
318 return vec.size() * sizeof(vec[0]);
322 inline const T* getDataOrNullptr (const std::vector<T>& vec, const std::size_t index = 0u)
324 return (index < vec.size() ? &vec[index] : DE_NULL);
330 #endif // _VKTSPARSERESOURCESTESTSUTIL_HPP