xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/image/vktImageTestsUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTIMAGETESTSUTIL_HPP
2 #define _VKTIMAGETESTSUTIL_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
23  * \brief Image Tests Utility Classes
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkDefs.hpp"
27 #include "vkMemUtil.hpp"
28 #include "vkRef.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkTypeUtil.hpp"
32 #include "vkImageUtil.hpp"
33 
34 namespace vkt
35 {
36 namespace image
37 {
38 
39 enum ImageType
40 {
41     IMAGE_TYPE_1D = 0,
42     IMAGE_TYPE_1D_ARRAY,
43     IMAGE_TYPE_2D,
44     IMAGE_TYPE_2D_ARRAY,
45     IMAGE_TYPE_3D,
46     IMAGE_TYPE_CUBE,
47     IMAGE_TYPE_CUBE_ARRAY,
48     IMAGE_TYPE_BUFFER,
49 
50     IMAGE_TYPE_LAST
51 };
52 
53 vk::VkImageType mapImageType(const ImageType imageType);
54 vk::VkImageViewType mapImageViewType(const ImageType imageType);
55 std::string getImageTypeName(const ImageType imageType);
56 std::string getFormatPrefix(const tcu::TextureFormat &format);
57 std::string getShaderImageType(const tcu::TextureFormat &format, const ImageType imageType,
58                                const bool multisample = false);
59 std::string getShaderImageFormatQualifier(const tcu::TextureFormat &format);
60 std::string getGlslSamplerType(const tcu::TextureFormat &format, vk::VkImageViewType type);
61 const char *getGlslInputFormatType(const vk::VkFormat format);
62 const char *getGlslFormatType(const vk::VkFormat format);
63 const char *getGlslAttachmentType(const vk::VkFormat format);
64 const char *getGlslInputAttachmentType(const vk::VkFormat format);
65 bool isPackedType(const vk::VkFormat format);
66 bool isComponentSwizzled(const vk::VkFormat format);
67 int getNumUsedChannels(const vk::VkFormat format);
68 bool isFormatImageLoadStoreCapable(const vk::VkFormat format);
69 
70 class Image
71 {
72 public:
73     Image(const vk::DeviceInterface &vk, const vk::VkDevice device, vk::Allocator &allocator,
74           const vk::VkImageCreateInfo &imageCreateInfo, const vk::MemoryRequirement memoryRequirement);
~Image(void)75     virtual ~Image(void)
76     {
77     }
78 
get(void) const79     const vk::VkImage &get(void) const
80     {
81         return *m_image;
82     }
operator *(void) const83     const vk::VkImage &operator*(void) const
84     {
85         return get();
86     }
87 
getSemaphore(void) const88     virtual vk::VkSemaphore getSemaphore(void) const
89     {
90         return DE_NULL;
91     }
92 
93     Image(const Image &)            = delete;
94     Image &operator=(const Image &) = delete;
95 
96 protected:
97     using AllocationsVec = std::vector<de::SharedPtr<vk::Allocation>>;
98 
99     Image(void);
100 
101     AllocationsVec m_allocations;
102     vk::Move<vk::VkImage> m_image;
103 };
104 
105 #ifndef CTS_USES_VULKANSC
106 class SparseImage : public Image
107 {
108 public:
109     SparseImage(const vk::DeviceInterface &vkd, vk::VkDevice device, vk::VkPhysicalDevice physicalDevice,
110                 const vk::InstanceInterface &vki, const vk::VkImageCreateInfo &createInfo,
111                 const vk::VkQueue sparseQueue, vk::Allocator &allocator, const tcu::TextureFormat &format);
112 
getSemaphore(void) const113     virtual vk::VkSemaphore getSemaphore(void) const
114     {
115         return m_semaphore.get();
116     }
117 
118     SparseImage(const SparseImage &)            = delete;
119     SparseImage &operator=(const SparseImage &) = delete;
120 
121 protected:
122     vk::Move<vk::VkSemaphore> m_semaphore;
123 };
124 #endif // CTS_USES_VULKANSC
125 
126 tcu::UVec3 getShaderGridSize(const ImageType imageType,
127                              const tcu::UVec3 &imageSize); //!< Size used for addresing image in a shader
128 tcu::UVec3 getLayerSize(const ImageType imageType, const tcu::UVec3 &imageSize); //!< Size of a single layer
129 uint32_t getNumLayers(const ImageType imageType,
130                       const tcu::UVec3 &imageSize); //!< Number of array layers (for array and cube types)
131 uint32_t getNumPixels(const ImageType imageType, const tcu::UVec3 &imageSize); //!< Number of texels in an image
132 uint32_t getDimensions(
133     const ImageType imageType); //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
134 uint32_t getLayerDimensions(
135     const ImageType imageType); //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
136 
137 vk::Move<vk::VkPipeline> makeGraphicsPipeline(const vk::DeviceInterface &vk, const vk::VkDevice device,
138                                               const vk::VkPipelineLayout pipelineLayout,
139                                               const vk::VkRenderPass renderPass, const vk::VkShaderModule vertexModule,
140                                               const vk::VkShaderModule fragmentModule, const vk::VkExtent2D renderSize,
141                                               const uint32_t colorAttachmentCount, const bool dynamicSize = false);
142 
143 vk::Move<vk::VkRenderPass> makeRenderPass(const vk::DeviceInterface &vk, const vk::VkDevice device,
144                                           const vk::VkFormat inputFormat, const vk::VkFormat colorFormat);
145 
146 vk::VkBufferImageCopy makeBufferImageCopy(const vk::VkExtent3D extent, const uint32_t arraySize);
147 
148 vk::VkImageViewUsageCreateInfo makeImageViewUsageCreateInfo(const vk::VkImageUsageFlags imageUsageFlags);
149 
150 vk::VkSamplerCreateInfo makeSamplerCreateInfo();
151 
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)152 inline vk::VkDeviceSize getImageSizeBytes(const tcu::IVec3 &imageSize, const vk::VkFormat format)
153 {
154     return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
155 }
156 
157 tcu::UVec3 getCompressedImageResolutionInBlocks(const vk::VkFormat format, const tcu::UVec3 &size);
158 tcu::UVec3 getCompressedImageResolutionBlockCeil(const vk::VkFormat format, const tcu::UVec3 &size);
159 vk::VkDeviceSize getCompressedImageSizeInBytes(const vk::VkFormat format, const tcu::UVec3 &size);
160 vk::VkDeviceSize getUncompressedImageSizeInBytes(const vk::VkFormat format, const tcu::UVec3 &size);
161 
162 std::string getFormatShortString(const vk::VkFormat format);
163 
164 std::vector<tcu::Vec4> createFullscreenQuad(void);
165 
166 vk::VkBufferImageCopy makeBufferImageCopy(const uint32_t imageWidth, const uint32_t imageHeight,
167                                           const uint32_t mipLevel = 0u, const uint32_t layer = 0u);
168 vk::VkBufferImageCopy makeBufferImageCopy(const uint32_t imageWidth, const uint32_t imageHeight,
169                                           const uint32_t mipLevel, const uint32_t layer, const uint32_t bufferRowLength,
170                                           const uint32_t bufferImageHeight);
171 
172 void beginRenderPass(const vk::DeviceInterface &vk, const vk::VkCommandBuffer commandBuffer,
173                      const vk::VkRenderPass renderPass, const vk::VkFramebuffer framebuffer,
174                      const vk::VkExtent2D &renderSize);
175 
176 } // namespace image
177 } // namespace vkt
178 
179 #endif // _VKTIMAGETESTSUTIL_HPP
180