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
85 bool formatIsR64 (const vk::VkFormat& format);
86
87 std::vector<TestFormat> getTestFormats (const ImageType& imageType);
88
89 vk::VkImageType mapImageType (const ImageType imageType);
90
91 vk::VkImageViewType mapImageViewType (const ImageType imageType);
92
93 std::string getImageTypeName (const ImageType imageType);
94
95 std::string getShaderImageType (const tcu::TextureFormat& format,
96 const ImageType imageType);
97
98 std::string getShaderImageType (const vk::PlanarFormatDescription& description,
99 const ImageType imageType);
100
101 std::string getShaderImageDataType (const tcu::TextureFormat& format);
102
103 std::string getShaderImageDataType (const vk::PlanarFormatDescription& description);
104
105 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format);
106
107 std::string getShaderImageFormatQualifier (vk::VkFormat format);
108
109 std::string getImageFormatID (vk::VkFormat format);
110
111 std::string getShaderImageCoordinates (const ImageType imageType,
112 const std::string& x,
113 const std::string& xy,
114 const std::string& xyz);
115
116 //!< Size used for addresing image in a compute shader
117 tcu::UVec3 getShaderGridSize (const ImageType imageType,
118 const tcu::UVec3& imageSize,
119 const deUint32 mipLevel = 0);
120
121 //!< Size of a single image layer
122 tcu::UVec3 getLayerSize (const ImageType imageType,
123 const tcu::UVec3& imageSize);
124
125 //!< Number of array layers (for array and cube types)
126 deUint32 getNumLayers (const ImageType imageType,
127 const tcu::UVec3& imageSize);
128
129 //!< Number of texels in an image
130 deUint32 getNumPixels (const ImageType imageType,
131 const tcu::UVec3& imageSize);
132
133 //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
134 deUint32 getDimensions (const ImageType imageType);
135
136 //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
137 deUint32 getLayerDimensions (const ImageType imageType);
138
139 //!< Helper function for checking if requested image size does not exceed device limits
140 bool isImageSizeSupported (const vk::InstanceInterface& instance,
141 const vk::VkPhysicalDevice physicalDevice,
142 const ImageType imageType,
143 const tcu::UVec3& imageSize);
144
145 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
146 const deUint32 layersCount,
147 const tcu::TextureFormat& format,
148 const deUint32 mipmapLevel,
149 const deUint32 mipmapMemoryAlignment = 1u);
150
151 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
152 const deUint32 layersCount,
153 const tcu::TextureFormat& format,
154 const deUint32 mipmapLevelsCount = 1u,
155 const deUint32 mipmapMemoryAlignment = 1u);
156
157 deUint32 getImageMipLevelSizeInBytes (const vk::VkExtent3D& baseExtents,
158 const deUint32 layersCount,
159 const vk::PlanarFormatDescription& formatDescription,
160 const deUint32 planeNdx,
161 const deUint32 mipmapLevel,
162 const deUint32 mipmapMemoryAlignment = 1u);
163
164 deUint32 getImageSizeInBytes (const vk::VkExtent3D& baseExtents,
165 const deUint32 layersCount,
166 const vk::PlanarFormatDescription& formatDescription,
167 const deUint32 planeNdx,
168 const deUint32 mipmapLevelsCount =1u,
169 const deUint32 mipmapMemoryAlignment =1u);
170
171 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
172 const vk::VkDevice device,
173 const vk::VkPipelineLayout pipelineLayout,
174 const vk::VkShaderModule shaderModule,
175 const vk::VkSpecializationInfo* specializationInfo = 0);
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>
makeVkSharedPtr(vk::Move<T> vkMove)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>
makeDeSharedPtr(de::MovePtr<T> deMove)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>
sizeInBytes(const std::vector<T> & vec)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>
getDataOrNullptr(const std::vector<T> & vec,const std::size_t index=0u)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
282