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;
85 std::vector<TestFormat> getTestFormats (const ImageType& imageType);
87 vk::VkImageType mapImageType (const ImageType imageType);
89 vk::VkImageViewType mapImageViewType (const ImageType imageType);
91 std::string getImageTypeName (const ImageType imageType);
93 std::string getShaderImageType (const tcu::TextureFormat& format,
94 const ImageType imageType);
96 std::string getShaderImageType (const vk::PlanarFormatDescription& description,
97 const ImageType imageType);
99 std::string getShaderImageDataType (const tcu::TextureFormat& format);
101 std::string getShaderImageDataType (const vk::PlanarFormatDescription& description);
103 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format);
105 std::string getShaderImageFormatQualifier (vk::VkFormat format);
107 std::string getImageFormatID (vk::VkFormat format);
109 std::string getShaderImageCoordinates (const ImageType imageType,
110 const std::string& x,
111 const std::string& xy,
112 const std::string& xyz);
114 //!< Size used for addresing image in a compute shader
115 tcu::UVec3 getShaderGridSize (const ImageType imageType,
116 const tcu::UVec3& imageSize,
117 const deUint32 mipLevel = 0);
119 //!< Size of a single image layer
120 tcu::UVec3 getLayerSize (const ImageType imageType,
121 const tcu::UVec3& imageSize);
123 //!< Number of array layers (for array and cube types)
124 deUint32 getNumLayers (const ImageType imageType,
125 const tcu::UVec3& imageSize);
127 //!< Number of texels in an image
128 deUint32 getNumPixels (const ImageType imageType,
129 const tcu::UVec3& imageSize);
131 //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
132 deUint32 getDimensions (const ImageType imageType);
134 //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
135 deUint32 getLayerDimensions (const ImageType imageType);
137 //!< Helper function for checking if requested image size does not exceed device limits
138 bool isImageSizeSupported (const vk::InstanceInterface& instance,
139 const vk::VkPhysicalDevice physicalDevice,
140 const ImageType imageType,
141 const tcu::UVec3& imageSize);
143 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
144 const deUint32 layersCount,
145 const tcu::TextureFormat& format,
146 const deUint32 mipmapLevel,
147 const deUint32 mipmapMemoryAlignment = 1u);
149 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
150 const deUint32 layersCount,
151 const tcu::TextureFormat& format,
152 const deUint32 mipmapLevelsCount = 1u,
153 const deUint32 mipmapMemoryAlignment = 1u);
155 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
156 const deUint32 layersCount,
157 const vk::PlanarFormatDescription& formatDescription,
158 const deUint32 planeNdx,
159 const deUint32 mipmapLevel,
160 const deUint32 mipmapMemoryAlignment = 1u);
162 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
163 const deUint32 layersCount,
164 const vk::PlanarFormatDescription& formatDescription,
165 const deUint32 planeNdx,
166 const deUint32 mipmapLevelsCount =1u,
167 const deUint32 mipmapMemoryAlignment =1u);
169 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
170 const vk::VkDevice device,
171 const vk::VkPipelineLayout pipelineLayout,
172 const vk::VkShaderModule shaderModule,
173 const vk::VkSpecializationInfo* specializationInfo = 0);
175 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
176 const deUint32 layersCount,
177 const deUint32 mipmapLevel = 0u,
178 const vk::VkDeviceSize bufferOffset = 0ull);
180 vk::VkSparseImageMemoryBind makeSparseImageMemoryBind (const vk::DeviceInterface& vk,
181 const vk::VkDevice device,
182 const vk::VkDeviceSize allocationSize,
183 const deUint32 memoryType,
184 const vk::VkImageSubresource& subresource,
185 const vk::VkOffset3D& offset,
186 const vk::VkExtent3D& extent);
188 vk::VkSparseMemoryBind makeSparseMemoryBind (const vk::DeviceInterface& vk,
189 const vk::VkDevice device,
190 const vk::VkDeviceSize allocationSize,
191 const deUint32 memoryType,
192 const vk::VkDeviceSize resourceOffset,
193 const vk::VkSparseMemoryBindFlags flags = 0u);
195 void submitCommands (const vk::DeviceInterface& vk,
196 const vk::VkQueue queue,
197 const vk::VkCommandBuffer cmdBuffer,
198 const deUint32 waitSemaphoreCount = 0,
199 const vk::VkSemaphore* pWaitSemaphores = DE_NULL,
200 const vk::VkPipelineStageFlags* pWaitDstStageMask = DE_NULL,
201 const deUint32 signalSemaphoreCount = 0,
202 const vk::VkSemaphore* pSignalSemaphores = DE_NULL);
204 void submitCommandsAndWait (const vk::DeviceInterface& vk,
205 const vk::VkDevice device,
206 const vk::VkQueue queue,
207 const vk::VkCommandBuffer cmdBuffer,
208 const deUint32 waitSemaphoreCount = 0,
209 const vk::VkSemaphore* pWaitSemaphores = DE_NULL,
210 const vk::VkPipelineStageFlags* pWaitDstStageMask = DE_NULL,
211 const deUint32 signalSemaphoreCount = 0,
212 const vk::VkSemaphore* pSignalSemaphores = DE_NULL,
213 const bool useDeviceGroups = false,
214 const deUint32 physicalDeviceID = 0);
216 void requireFeatures (const vk::InstanceInterface& vki,
217 const vk::VkPhysicalDevice physicalDevice,
218 const FeatureFlags flags);
220 deUint32 findMatchingMemoryType (const vk::InstanceInterface& instance,
221 const vk::VkPhysicalDevice physicalDevice,
222 const vk::VkMemoryRequirements& objectMemoryRequirements,
223 const vk::MemoryRequirement& memoryRequirement);
225 deUint32 getHeapIndexForMemoryType (const vk::InstanceInterface& instance,
226 const vk::VkPhysicalDevice physicalDevice,
227 const deUint32 memoryType);
229 bool checkSparseSupportForImageType (const vk::InstanceInterface& instance,
230 const vk::VkPhysicalDevice physicalDevice,
231 const ImageType imageType);
233 bool checkSparseSupportForImageFormat (const vk::InstanceInterface& instance,
234 const vk::VkPhysicalDevice physicalDevice,
235 const vk::VkImageCreateInfo& imageInfo);
237 bool checkImageFormatFeatureSupport (const vk::InstanceInterface& instance,
238 const vk::VkPhysicalDevice physicalDevice,
239 const vk::VkFormat format,
240 const vk::VkFormatFeatureFlags featureFlags);
242 deUint32 getSparseAspectRequirementsIndex (const std::vector<vk::VkSparseImageMemoryRequirements>& requirements,
243 const vk::VkImageAspectFlags aspectFlags);
245 vk::VkFormat getPlaneCompatibleFormatForWriting (const vk::PlanarFormatDescription& formatInfo,
248 bool areLsb6BitsDontCare(vk::VkFormat format);
250 bool areLsb4BitsDontCare(vk::VkFormat format);
253 inline de::SharedPtr<vk::Unique<T> > makeVkSharedPtr (vk::Move<T> vkMove)
255 return de::SharedPtr<vk::Unique<T> >(new vk::Unique<T>(vkMove));
259 inline de::SharedPtr<de::UniquePtr<T> > makeDeSharedPtr (de::MovePtr<T> deMove)
261 return de::SharedPtr<de::UniquePtr<T> >(new de::UniquePtr<T>(deMove));
265 inline std::size_t sizeInBytes (const std::vector<T>& vec)
267 return vec.size() * sizeof(vec[0]);
271 inline const T* getDataOrNullptr (const std::vector<T>& vec, const std::size_t index = 0u)
273 return (index < vec.size() ? &vec[index] : DE_NULL);
279 #endif // _VKTSPARSERESOURCESTESTSUTIL_HPP