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 "vkObjUtil.hpp"
28 #include "vkMemUtil.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkMemUtil.hpp"
32 #include "vkImageUtil.hpp"
33 #include "deSharedPtr.hpp"
34 #include "deUniquePtr.hpp"
41 typedef de::SharedPtr<vk::Unique<vk::VkDeviceMemory> > DeviceMemorySp;
51 IMAGE_TYPE_CUBE_ARRAY,
59 FEATURE_TESSELLATION_SHADER = 1u << 0,
60 FEATURE_GEOMETRY_SHADER = 1u << 1,
61 FEATURE_SHADER_FLOAT_64 = 1u << 2,
62 FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS = 1u << 3,
63 FEATURE_FRAGMENT_STORES_AND_ATOMICS = 1u << 4,
64 FEATURE_SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE = 1u << 5,
66 typedef deUint32 FeatureFlags;
70 NO_MATCH_FOUND = ~((deUint32)0), //!< no matching index
78 struct TestImageParameters
81 std::vector<tcu::UVec3> imageSizes;
82 std::vector<TestFormat> formats;
84 TestImageParameters (ImageType imageType_, const std::vector<tcu::UVec3>& imageSizes_, const std::vector<TestFormat>& formats_)
85 : imageType (imageType_)
86 , imageSizes (imageSizes_)
91 bool formatIsR64 (const vk::VkFormat& format);
93 std::vector<TestFormat> getTestFormats (const ImageType& imageType);
95 vk::VkImageType mapImageType (const ImageType imageType);
97 vk::VkImageViewType mapImageViewType (const ImageType imageType);
99 std::string getImageTypeName (const ImageType imageType);
101 std::string getShaderImageType (const tcu::TextureFormat& format,
102 const ImageType imageType);
104 std::string getShaderImageType (const vk::PlanarFormatDescription& description,
105 const ImageType imageType);
107 std::string getShaderImageDataType (const tcu::TextureFormat& format);
109 std::string getShaderImageDataType (const vk::PlanarFormatDescription& description);
111 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format);
113 std::string getShaderImageFormatQualifier (vk::VkFormat format);
115 std::string getImageFormatID (vk::VkFormat format);
117 std::string getShaderImageCoordinates (const ImageType imageType,
118 const std::string& x,
119 const std::string& xy,
120 const std::string& xyz);
122 //!< Size used for addresing image in a compute shader
123 tcu::UVec3 getShaderGridSize (const ImageType imageType,
124 const tcu::UVec3& imageSize,
125 const deUint32 mipLevel = 0);
127 //!< Size of a single image layer
128 tcu::UVec3 getLayerSize (const ImageType imageType,
129 const tcu::UVec3& imageSize);
131 //!< Number of array layers (for array and cube types)
132 deUint32 getNumLayers (const ImageType imageType,
133 const tcu::UVec3& imageSize);
135 //!< Number of texels in an image
136 deUint32 getNumPixels (const ImageType imageType,
137 const tcu::UVec3& imageSize);
139 //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
140 deUint32 getDimensions (const ImageType imageType);
142 //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
143 deUint32 getLayerDimensions (const ImageType imageType);
145 //!< Helper function for checking if requested image size does not exceed device limits
146 bool isImageSizeSupported (const vk::InstanceInterface& instance,
147 const vk::VkPhysicalDevice physicalDevice,
148 const ImageType imageType,
149 const tcu::UVec3& imageSize);
151 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
152 const deUint32 layersCount,
153 const tcu::TextureFormat& format,
154 const deUint32 mipmapLevel,
155 const deUint32 mipmapMemoryAlignment = 1u);
157 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
158 const deUint32 layersCount,
159 const tcu::TextureFormat& format,
160 const deUint32 mipmapLevelsCount = 1u,
161 const deUint32 mipmapMemoryAlignment = 1u);
163 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
164 const deUint32 layersCount,
165 const vk::PlanarFormatDescription& formatDescription,
166 const deUint32 planeNdx,
167 const deUint32 mipmapLevel,
168 const deUint32 mipmapMemoryAlignment = 1u);
170 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
171 const deUint32 layersCount,
172 const vk::PlanarFormatDescription& formatDescription,
173 const deUint32 planeNdx,
174 const deUint32 mipmapLevelsCount =1u,
175 const deUint32 mipmapMemoryAlignment =1u);
177 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
178 const deUint32 layersCount,
179 const deUint32 mipmapLevel = 0u,
180 const vk::VkDeviceSize bufferOffset = 0ull);
182 vk::VkSparseImageMemoryBind makeSparseImageMemoryBind (const vk::DeviceInterface& vk,
183 const vk::VkDevice device,
184 const vk::VkDeviceSize allocationSize,
185 const deUint32 memoryType,
186 const vk::VkImageSubresource& subresource,
187 const vk::VkOffset3D& offset,
188 const vk::VkExtent3D& extent);
190 vk::VkSparseMemoryBind makeSparseMemoryBind (const vk::DeviceInterface& vk,
191 const vk::VkDevice device,
192 const vk::VkDeviceSize allocationSize,
193 const deUint32 memoryType,
194 const vk::VkDeviceSize resourceOffset,
195 const vk::VkSparseMemoryBindFlags flags = 0u);
197 void submitCommands (const vk::DeviceInterface& vk,
198 const vk::VkQueue queue,
199 const vk::VkCommandBuffer cmdBuffer,
200 const deUint32 waitSemaphoreCount = 0,
201 const vk::VkSemaphore* pWaitSemaphores = DE_NULL,
202 const vk::VkPipelineStageFlags* pWaitDstStageMask = DE_NULL,
203 const deUint32 signalSemaphoreCount = 0,
204 const vk::VkSemaphore* pSignalSemaphores = DE_NULL);
206 void submitCommandsAndWait (const vk::DeviceInterface& vk,
207 const vk::VkDevice device,
208 const vk::VkQueue queue,
209 const vk::VkCommandBuffer cmdBuffer,
210 const deUint32 waitSemaphoreCount = 0,
211 const vk::VkSemaphore* pWaitSemaphores = DE_NULL,
212 const vk::VkPipelineStageFlags* pWaitDstStageMask = DE_NULL,
213 const deUint32 signalSemaphoreCount = 0,
214 const vk::VkSemaphore* pSignalSemaphores = DE_NULL,
215 const bool useDeviceGroups = false,
216 const deUint32 physicalDeviceID = 0);
218 void requireFeatures (const vk::InstanceInterface& vki,
219 const vk::VkPhysicalDevice physicalDevice,
220 const FeatureFlags flags);
222 deUint32 findMatchingMemoryType (const vk::InstanceInterface& instance,
223 const vk::VkPhysicalDevice physicalDevice,
224 const vk::VkMemoryRequirements& objectMemoryRequirements,
225 const vk::MemoryRequirement& memoryRequirement);
227 deUint32 getHeapIndexForMemoryType (const vk::InstanceInterface& instance,
228 const vk::VkPhysicalDevice physicalDevice,
229 const deUint32 memoryType);
231 bool checkSparseSupportForImageType (const vk::InstanceInterface& instance,
232 const vk::VkPhysicalDevice physicalDevice,
233 const ImageType imageType);
235 bool checkSparseSupportForImageFormat (const vk::InstanceInterface& instance,
236 const vk::VkPhysicalDevice physicalDevice,
237 const vk::VkImageCreateInfo& imageInfo);
239 bool checkImageFormatFeatureSupport (const vk::InstanceInterface& instance,
240 const vk::VkPhysicalDevice physicalDevice,
241 const vk::VkFormat format,
242 const vk::VkFormatFeatureFlags featureFlags);
244 deUint32 getSparseAspectRequirementsIndex (const std::vector<vk::VkSparseImageMemoryRequirements>& requirements,
245 const vk::VkImageAspectFlags aspectFlags);
247 vk::VkFormat getPlaneCompatibleFormatForWriting (const vk::PlanarFormatDescription& formatInfo,
250 bool areLsb6BitsDontCare(vk::VkFormat format);
252 bool areLsb4BitsDontCare(vk::VkFormat format);
255 inline de::SharedPtr<vk::Unique<T> > makeVkSharedPtr (vk::Move<T> vkMove)
257 return de::SharedPtr<vk::Unique<T> >(new vk::Unique<T>(vkMove));
261 inline de::SharedPtr<de::UniquePtr<T> > makeDeSharedPtr (de::MovePtr<T> deMove)
263 return de::SharedPtr<de::UniquePtr<T> >(new de::UniquePtr<T>(deMove));
267 inline std::size_t sizeInBytes (const std::vector<T>& vec)
269 return vec.size() * sizeof(vec[0]);
273 inline const T* getDataOrNullptr (const std::vector<T>& vec, const std::size_t index = 0u)
275 return (index < vec.size() ? &vec[index] : DE_NULL);
281 #endif // _VKTSPARSERESOURCESTESTSUTIL_HPP