Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / sparse_resources / vktSparseResourcesTestsUtil.hpp
1 #ifndef _VKTSPARSERESOURCESTESTSUTIL_HPP
2 #define _VKTSPARSERESOURCESTESTSUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *//*!
22  * \file  vktSparseResourcesTestsUtil.hpp
23  * \brief Sparse Resources Tests Utility Classes
24  *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27 #include "vkObjUtil.hpp"
28 #include "vkMemUtil.hpp"
29 #include "vkRef.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkMemUtil.hpp"
32 #include "vkImageUtil.hpp"
33 #include "deSharedPtr.hpp"
34 #include "deUniquePtr.hpp"
35
36 namespace vkt
37 {
38 namespace sparse
39 {
40
41 typedef de::SharedPtr<vk::Unique<vk::VkDeviceMemory> > DeviceMemorySp;
42
43 enum ImageType
44 {
45         IMAGE_TYPE_1D = 0,
46         IMAGE_TYPE_1D_ARRAY,
47         IMAGE_TYPE_2D,
48         IMAGE_TYPE_2D_ARRAY,
49         IMAGE_TYPE_3D,
50         IMAGE_TYPE_CUBE,
51         IMAGE_TYPE_CUBE_ARRAY,
52         IMAGE_TYPE_BUFFER,
53
54         IMAGE_TYPE_LAST
55 };
56
57 enum FeatureFlagBits
58 {
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,
65 };
66 typedef deUint32 FeatureFlags;
67
68 enum
69 {
70         NO_MATCH_FOUND                                                  = ~((deUint32)0),       //!< no matching index
71 };
72
73 struct TestFormat
74 {
75         vk::VkFormat    format;
76 };
77
78 struct TestImageParameters
79 {
80         ImageType                               imageType;
81         std::vector<tcu::UVec3> imageSizes;
82         std::vector<TestFormat> formats;
83
84         TestImageParameters (ImageType imageType_, const std::vector<tcu::UVec3>& imageSizes_, const std::vector<TestFormat>& formats_)
85                 : imageType             (imageType_)
86                 , imageSizes    (imageSizes_)
87                 , formats               (formats_)
88                 {}
89 };
90
91 bool                                                    formatIsR64                                                     (const vk::VkFormat& format);
92
93 std::vector<TestFormat>                 getTestFormats                                          (const ImageType& imageType);
94
95 vk::VkImageType                                 mapImageType                                            (const ImageType                                        imageType);
96
97 vk::VkImageViewType                             mapImageViewType                                        (const ImageType                                        imageType);
98
99 std::string                                             getImageTypeName                                        (const ImageType                                        imageType);
100
101 std::string                                             getShaderImageType                                      (const tcu::TextureFormat&                      format,
102                                                                                                                                          const ImageType                                        imageType);
103
104 std::string                                             getShaderImageType                                      (const vk::PlanarFormatDescription& description,
105                                                                                                                                          const ImageType imageType);
106
107 std::string                                             getShaderImageDataType                          (const tcu::TextureFormat&                      format);
108
109 std::string                                             getShaderImageDataType                          (const vk::PlanarFormatDescription& description);
110
111 std::string                                             getShaderImageFormatQualifier           (const tcu::TextureFormat&                      format);
112
113 std::string                                             getShaderImageFormatQualifier           (vk::VkFormat                                           format);
114
115 std::string                                             getImageFormatID                                        (vk::VkFormat                                           format);
116
117 std::string                                             getShaderImageCoordinates                       (const ImageType                                        imageType,
118                                                                                                                                          const std::string&                                     x,
119                                                                                                                                          const std::string&                                     xy,
120                                                                                                                                          const std::string&                                     xyz);
121
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);
126
127 //!< Size of a single image layer
128 tcu::UVec3                                              getLayerSize                                            (const ImageType                                        imageType,
129                                                                                                                                          const tcu::UVec3&                                      imageSize);
130
131 //!< Number of array layers (for array and cube types)
132 deUint32                                                getNumLayers                                            (const ImageType                                        imageType,
133                                                                                                                                          const tcu::UVec3&                                      imageSize);
134
135 //!< Number of texels in an image
136 deUint32                                                getNumPixels                                            (const ImageType                                        imageType,
137                                                                                                                                          const tcu::UVec3&                                      imageSize);
138
139 //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
140 deUint32                                                getDimensions                                           (const ImageType                                        imageType);
141
142 //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
143 deUint32                                                getLayerDimensions                                      (const ImageType                                        imageType);
144
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);
150
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);
156
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);
162
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);
169
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);
176
177 vk::VkBufferImageCopy                   makeBufferImageCopy                                     (const vk::VkExtent3D                           extent,
178                                                                                                                                          const deUint32                                         layersCount,
179                                                                                                                                          const deUint32                                         mipmapLevel             = 0u,
180                                                                                                                                          const vk::VkDeviceSize                         bufferOffset    = 0ull);
181
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);
189
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);
196
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);
205
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);
217
218 void                                                    requireFeatures                                         (const vk::InstanceInterface&           vki,
219                                                                                                                                          const vk::VkPhysicalDevice                     physicalDevice,
220                                                                                                                                          const FeatureFlags                                     flags);
221
222 deUint32                                                findMatchingMemoryType                          (const vk::InstanceInterface&           instance,
223                                                                                                                                          const vk::VkPhysicalDevice                     physicalDevice,
224                                                                                                                                          const vk::VkMemoryRequirements&        objectMemoryRequirements,
225                                                                                                                                          const vk::MemoryRequirement&           memoryRequirement);
226
227 deUint32                                                getHeapIndexForMemoryType                       (const vk::InstanceInterface&           instance,
228                                                                                                                                          const vk::VkPhysicalDevice                     physicalDevice,
229                                                                                                                                          const deUint32                                         memoryType);
230
231 bool                                                    checkSparseSupportForImageType          (const vk::InstanceInterface&           instance,
232                                                                                                                                          const vk::VkPhysicalDevice                     physicalDevice,
233                                                                                                                                          const ImageType                                        imageType);
234
235 bool                                                    checkSparseSupportForImageFormat        (const vk::InstanceInterface&           instance,
236                                                                                                                                          const vk::VkPhysicalDevice                     physicalDevice,
237                                                                                                                                          const vk::VkImageCreateInfo&           imageInfo);
238
239 bool                                                    checkImageFormatFeatureSupport          (const vk::InstanceInterface&           instance,
240                                                                                                                                          const vk::VkPhysicalDevice                     physicalDevice,
241                                                                                                                                          const vk::VkFormat                                     format,
242                                                                                                                                          const vk::VkFormatFeatureFlags         featureFlags);
243
244 deUint32                                                getSparseAspectRequirementsIndex        (const std::vector<vk::VkSparseImageMemoryRequirements>&        requirements,
245                                                                                                                                          const vk::VkImageAspectFlags                                                           aspectFlags);
246
247 vk::VkFormat                                    getPlaneCompatibleFormatForWriting      (const vk::PlanarFormatDescription&     formatInfo,
248                                                                                                                                          deUint32                                                       planeNdx);
249
250 bool                                                    areLsb6BitsDontCare(vk::VkFormat format);
251
252 bool                                                    areLsb4BitsDontCare(vk::VkFormat format);
253
254 template<typename T>
255 inline de::SharedPtr<vk::Unique<T> > makeVkSharedPtr (vk::Move<T> vkMove)
256 {
257         return de::SharedPtr<vk::Unique<T> >(new vk::Unique<T>(vkMove));
258 }
259
260 template<typename T>
261 inline de::SharedPtr<de::UniquePtr<T> > makeDeSharedPtr (de::MovePtr<T> deMove)
262 {
263         return de::SharedPtr<de::UniquePtr<T> >(new de::UniquePtr<T>(deMove));
264 }
265
266 template<typename T>
267 inline std::size_t sizeInBytes (const std::vector<T>& vec)
268 {
269         return vec.size() * sizeof(vec[0]);
270 }
271
272 template<typename T>
273 inline const T* getDataOrNullptr (const std::vector<T>& vec, const std::size_t index = 0u)
274 {
275         return (index < vec.size() ? &vec[index] : DE_NULL);
276 }
277
278 } // sparse
279 } // vkt
280
281 #endif // _VKTSPARSERESOURCESTESTSUTIL_HPP