xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/pipeline/vktPipelineImageUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTPIPELINEIMAGEUTIL_HPP
2 #define _VKTPIPELINEIMAGEUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Imagination Technologies Ltd.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Utilities for images.
25  *//*--------------------------------------------------------------------*/
26 
27 #include "tcuDefs.hpp"
28 #include "vkDefs.hpp"
29 #include "vkDefs.hpp"
30 #include "vkPlatform.hpp"
31 #include "vkMemUtil.hpp"
32 #include "vkRef.hpp"
33 #include "tcuTexture.hpp"
34 #include "tcuCompressedTexture.hpp"
35 #include "deSharedPtr.hpp"
36 
37 namespace vkt
38 {
39 namespace pipeline
40 {
41 
42 class TestTexture;
43 
44 enum BorderColor
45 {
46     BORDER_COLOR_OPAQUE_BLACK,
47     BORDER_COLOR_OPAQUE_WHITE,
48     BORDER_COLOR_TRANSPARENT_BLACK,
49     BORDER_COLOR_CUSTOM,
50 
51     BORDER_COLOR_COUNT
52 };
53 
54 bool isSupportedSamplableFormat(const vk::InstanceInterface &instanceInterface, vk::VkPhysicalDevice device,
55                                 vk::VkFormat format);
56 bool isLinearFilteringSupported(const vk::InstanceInterface &instanceInterface, vk::VkPhysicalDevice device,
57                                 vk::VkFormat format, vk::VkImageTiling tiling);
58 
59 bool isMinMaxFilteringSupported(const vk::InstanceInterface &instanceInterface, vk::VkPhysicalDevice device,
60                                 vk::VkFormat format, vk::VkImageTiling tiling);
61 
62 vk::VkBorderColor getFormatBorderColor(BorderColor color, vk::VkFormat format, bool useStencilAspect);
63 
64 rr::GenericVec4 getFormatCustomBorderColor(tcu::Vec4 floatValue, tcu::IVec4 intValue, vk::VkFormat format,
65                                            bool useStencilAspect);
66 
67 void getLookupScaleBias(vk::VkFormat format, tcu::Vec4 &lookupScale, tcu::Vec4 &lookupBias,
68                         bool useStencilAspect = false);
69 
70 /*--------------------------------------------------------------------*//*!
71  * Gets a tcu::TextureLevel initialized with data from a VK color
72  * attachment.
73  *
74  * The VkImage must be non-multisampled and able to be used as a source
75  * operand for transfer operations.
76  *//*--------------------------------------------------------------------*/
77 de::MovePtr<tcu::TextureLevel> readColorAttachment(
78     const vk::DeviceInterface &vk, vk::VkDevice device, vk::VkQueue queue, uint32_t queueFamilyIndex,
79     vk::Allocator &allocator, vk::VkImage image, vk::VkFormat format, const tcu::UVec2 &renderSize,
80     vk::VkImageLayout oldLayout = vk::VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
81 
82 /*--------------------------------------------------------------------*//*!
83  * Gets a tcu::TextureLevel initialized with data from a VK depth
84  * attachment.
85  *
86  * The VkImage must be non-multisampled and able to be used as a source
87  * operand for transfer operations.
88  *//*--------------------------------------------------------------------*/
89 de::MovePtr<tcu::TextureLevel> readDepthAttachment(
90     const vk::DeviceInterface &vk, vk::VkDevice device, vk::VkQueue queue, uint32_t queueFamilyIndex,
91     vk::Allocator &allocator, vk::VkImage image, vk::VkFormat format, const tcu::UVec2 &renderSize,
92     vk::VkImageLayout currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
93 
94 /*--------------------------------------------------------------------*//*!
95  * Gets a tcu::TextureLevel initialized with data from a VK stencil
96  * attachment.
97  *
98  * The VkImage must be non-multisampled and able to be used as a source
99  * operand for transfer operations.
100  *//*--------------------------------------------------------------------*/
101 de::MovePtr<tcu::TextureLevel> readStencilAttachment(
102     const vk::DeviceInterface &vk, vk::VkDevice device, vk::VkQueue queue, uint32_t queueFamilyIndex,
103     vk::Allocator &allocator, vk::VkImage image, vk::VkFormat format, const tcu::UVec2 &renderSize,
104     vk::VkImageLayout currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
105 
106 /*--------------------------------------------------------------------*//*!
107  * Uploads data from a test texture to a destination VK image.
108  *
109  * The VkImage must be non-multisampled and able to be used as a
110  * destination operand for transfer operations.
111  *//*--------------------------------------------------------------------*/
112 void uploadTestTexture(const vk::DeviceInterface &vk, vk::VkDevice device, vk::VkQueue queue, uint32_t queueFamilyIndex,
113                        vk::Allocator &allocator, const TestTexture &testTexture, vk::VkImage destImage,
114                        vk::VkImageLayout destImageLayout = vk::VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
115 
116 /*--------------------------------------------------------------------*//*!
117  * Uploads data from a test texture to a destination VK image using sparse
118  * binding.
119  *
120  * The VkImage must be non-multisampled and able to be used as a
121  * destination operand for transfer operations.
122  *//*--------------------------------------------------------------------*/
123 void uploadTestTextureSparse(const vk::DeviceInterface &vk, vk::VkDevice device,
124                              const vk::VkPhysicalDevice physicalDevice, const vk::InstanceInterface &instance,
125                              const vk::VkImageCreateInfo &imageCreateInfo, vk::VkQueue universalQueue,
126                              uint32_t universalQueueFamilyIndex, vk::VkQueue sparseQueue, vk::Allocator &allocator,
127                              std::vector<de::SharedPtr<vk::Allocation>> &allocations, const TestTexture &srcTexture,
128                              vk::VkImage destImage);
129 
130 class TestTexture
131 {
132 public:
133     TestTexture(const tcu::TextureFormat &format, int width, int height, int depth);
134     TestTexture(const tcu::CompressedTexFormat &format, int width, int height, int depth);
135     virtual ~TestTexture(void);
136 
137     virtual int getNumLevels(void) const = 0;
138     virtual uint32_t getSize(void) const;
getArraySize(void) const139     virtual int getArraySize(void) const
140     {
141         return 1;
142     }
143 
isCompressed(void) const144     virtual bool isCompressed(void) const
145     {
146         return !m_compressedLevels.empty();
147     }
148     virtual uint32_t getCompressedSize(void) const;
149 
150     virtual tcu::PixelBufferAccess getLevel(int level, int layer)                  = 0;
151     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const = 0;
152 
153     virtual tcu::CompressedTexture &getCompressedLevel(int level, int layer);
154     virtual const tcu::CompressedTexture &getCompressedLevel(int level, int layer) const;
155 
156     virtual std::vector<vk::VkBufferImageCopy> getBufferCopyRegions(void) const;
157     virtual void write(uint8_t *destPtr) const;
158     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const = 0;
159 
160     virtual const tcu::TextureFormat &getTextureFormat(void) const = 0;
161     virtual tcu::UVec3 getTextureDimension(void) const             = 0;
162 
163 protected:
164     void populateLevels(const std::vector<tcu::PixelBufferAccess> &levels);
165     void populateCompressedLevels(tcu::CompressedTexFormat format,
166                                   const std::vector<tcu::PixelBufferAccess> &decompressedLevels);
167 
168     static void fillWithGradient(const tcu::PixelBufferAccess &levelAccess);
169 
170     void copyToTexture(TestTexture &) const;
171 
172 protected:
173     std::vector<tcu::CompressedTexture *> m_compressedLevels;
174 };
175 
176 class TestTexture1D : public TestTexture
177 {
178 private:
179     tcu::Texture1D m_texture;
180 
181 public:
182     TestTexture1D(const tcu::TextureFormat &format, int width);
183     TestTexture1D(const tcu::CompressedTexFormat &format, int width);
184     virtual ~TestTexture1D(void);
185 
186     virtual int getNumLevels(void) const;
187     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
188     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
189     virtual const tcu::Texture1D &getTexture(void) const;
190     virtual tcu::Texture1D &getTexture(void);
getTextureFormat(void) const191     virtual const tcu::TextureFormat &getTextureFormat(void) const
192     {
193         return m_texture.getFormat();
194     }
getTextureDimension(void) const195     virtual tcu::UVec3 getTextureDimension(void) const
196     {
197         return tcu::UVec3(m_texture.getWidth(), 1, 1);
198     }
199 
200     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
201 };
202 
203 class TestTexture1DArray : public TestTexture
204 {
205 private:
206     tcu::Texture1DArray m_texture;
207 
208 public:
209     TestTexture1DArray(const tcu::TextureFormat &format, int width, int arraySize);
210     TestTexture1DArray(const tcu::CompressedTexFormat &format, int width, int arraySize);
211     virtual ~TestTexture1DArray(void);
212 
213     virtual int getNumLevels(void) const;
214     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
215     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
216     virtual const tcu::Texture1DArray &getTexture(void) const;
217     virtual tcu::Texture1DArray &getTexture(void);
218     virtual int getArraySize(void) const;
getTextureFormat(void) const219     virtual const tcu::TextureFormat &getTextureFormat(void) const
220     {
221         return m_texture.getFormat();
222     }
getTextureDimension(void) const223     virtual tcu::UVec3 getTextureDimension(void) const
224     {
225         return tcu::UVec3(m_texture.getWidth(), 1, 1);
226     }
227 
228     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
229 };
230 
231 class TestTexture2D : public TestTexture
232 {
233 private:
234     tcu::Texture2D m_texture;
235 
236 public:
237     TestTexture2D(const tcu::TextureFormat &format, int width, int height);
238     TestTexture2D(const tcu::TextureFormat &format, int width, int height, int miplevels);
239     TestTexture2D(const tcu::CompressedTexFormat &format, int width, int height);
240     virtual ~TestTexture2D(void);
241 
242     virtual int getNumLevels(void) const;
243     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
244     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
245     virtual const tcu::Texture2D &getTexture(void) const;
246     virtual tcu::Texture2D &getTexture(void);
getTextureFormat(void) const247     virtual const tcu::TextureFormat &getTextureFormat(void) const
248     {
249         return m_texture.getFormat();
250     }
getTextureDimension(void) const251     virtual tcu::UVec3 getTextureDimension(void) const
252     {
253         return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1);
254     }
255 
256     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
257 };
258 
259 class TestTexture2DArray : public TestTexture
260 {
261 private:
262     tcu::Texture2DArray m_texture;
263 
264 public:
265     TestTexture2DArray(const tcu::TextureFormat &format, int width, int height, int arraySize);
266     TestTexture2DArray(const tcu::CompressedTexFormat &format, int width, int height, int arraySize);
267     virtual ~TestTexture2DArray(void);
268 
269     virtual int getNumLevels(void) const;
270     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
271     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
272     virtual const tcu::Texture2DArray &getTexture(void) const;
273     virtual tcu::Texture2DArray &getTexture(void);
274     virtual int getArraySize(void) const;
getTextureFormat(void) const275     virtual const tcu::TextureFormat &getTextureFormat(void) const
276     {
277         return m_texture.getFormat();
278     }
getTextureDimension(void) const279     virtual tcu::UVec3 getTextureDimension(void) const
280     {
281         return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1);
282     }
283 
284     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
285 };
286 
287 class TestTexture3D : public TestTexture
288 {
289 private:
290     tcu::Texture3D m_texture;
291 
292 public:
293     TestTexture3D(const tcu::TextureFormat &format, int width, int height, int depth);
294     TestTexture3D(const tcu::CompressedTexFormat &format, int width, int height, int depth);
295     virtual ~TestTexture3D(void);
296 
297     virtual int getNumLevels(void) const;
298     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
299     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
300     virtual const tcu::Texture3D &getTexture(void) const;
301     virtual tcu::Texture3D &getTexture(void);
getTextureFormat(void) const302     virtual const tcu::TextureFormat &getTextureFormat(void) const
303     {
304         return m_texture.getFormat();
305     }
getTextureDimension(void) const306     virtual tcu::UVec3 getTextureDimension(void) const
307     {
308         return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth());
309     }
310 
311     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
312 };
313 
314 class TestTextureCube : public TestTexture
315 {
316 private:
317     tcu::TextureCube m_texture;
318 
319 public:
320     TestTextureCube(const tcu::TextureFormat &format, int size);
321     TestTextureCube(const tcu::CompressedTexFormat &format, int size);
322     virtual ~TestTextureCube(void);
323 
324     virtual int getNumLevels(void) const;
325     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
326     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
327     virtual int getArraySize(void) const;
328     virtual const tcu::TextureCube &getTexture(void) const;
329     virtual tcu::TextureCube &getTexture(void);
getTextureFormat(void) const330     virtual const tcu::TextureFormat &getTextureFormat(void) const
331     {
332         return m_texture.getFormat();
333     }
getTextureDimension(void) const334     virtual tcu::UVec3 getTextureDimension(void) const
335     {
336         return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1);
337     }
338 
339     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
340 };
341 
342 class TestTextureCubeArray : public TestTexture
343 {
344 private:
345     tcu::TextureCubeArray m_texture;
346 
347 public:
348     TestTextureCubeArray(const tcu::TextureFormat &format, int size, int arraySize);
349     TestTextureCubeArray(const tcu::CompressedTexFormat &format, int size, int arraySize);
350     virtual ~TestTextureCubeArray(void);
351 
352     virtual int getNumLevels(void) const;
353     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
354     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
355     virtual int getArraySize(void) const;
356     virtual const tcu::TextureCubeArray &getTexture(void) const;
357     virtual tcu::TextureCubeArray &getTexture(void);
getTextureFormat(void) const358     virtual const tcu::TextureFormat &getTextureFormat(void) const
359     {
360         return m_texture.getFormat();
361     }
getTextureDimension(void) const362     virtual tcu::UVec3 getTextureDimension(void) const
363     {
364         return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1);
365     }
366 
367     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
368 };
369 
370 } // namespace pipeline
371 } // namespace vkt
372 
373 #endif // _VKTPIPELINEIMAGEUTIL_HPP
374