• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void populateCompressedLevelsVoidExtent(tcu::CompressedTexFormat format,
168                                             const std::vector<tcu::PixelBufferAccess> &decompressedLevels);
169 
170     static void fillWithGradient(const tcu::PixelBufferAccess &levelAccess);
171 
172     void copyToTexture(TestTexture &) const;
173 
174 protected:
175     std::vector<tcu::CompressedTexture *> m_compressedLevels;
176 };
177 
178 class TestTexture1D : public TestTexture
179 {
180 private:
181     tcu::Texture1D m_texture;
182 
183 public:
184     TestTexture1D(const tcu::TextureFormat &format, int width);
185     TestTexture1D(const tcu::CompressedTexFormat &format, int width);
186     virtual ~TestTexture1D(void);
187 
188     virtual int getNumLevels(void) const;
189     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
190     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
191     virtual const tcu::Texture1D &getTexture(void) const;
192     virtual tcu::Texture1D &getTexture(void);
getTextureFormat(void) const193     virtual const tcu::TextureFormat &getTextureFormat(void) const
194     {
195         return m_texture.getFormat();
196     }
getTextureDimension(void) const197     virtual tcu::UVec3 getTextureDimension(void) const
198     {
199         return tcu::UVec3(m_texture.getWidth(), 1, 1);
200     }
201 
202     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
203 };
204 
205 class TestTexture1DArray : public TestTexture
206 {
207 private:
208     tcu::Texture1DArray m_texture;
209 
210 public:
211     TestTexture1DArray(const tcu::TextureFormat &format, int width, int arraySize);
212     TestTexture1DArray(const tcu::CompressedTexFormat &format, int width, int arraySize);
213     virtual ~TestTexture1DArray(void);
214 
215     virtual int getNumLevels(void) const;
216     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
217     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
218     virtual const tcu::Texture1DArray &getTexture(void) const;
219     virtual tcu::Texture1DArray &getTexture(void);
220     virtual int getArraySize(void) const;
getTextureFormat(void) const221     virtual const tcu::TextureFormat &getTextureFormat(void) const
222     {
223         return m_texture.getFormat();
224     }
getTextureDimension(void) const225     virtual tcu::UVec3 getTextureDimension(void) const
226     {
227         return tcu::UVec3(m_texture.getWidth(), 1, 1);
228     }
229 
230     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
231 };
232 
233 class TestTexture2D : public TestTexture
234 {
235 private:
236     tcu::Texture2D m_texture;
237 
238 public:
239     TestTexture2D(const tcu::TextureFormat &format, int width, int height);
240     TestTexture2D(const tcu::TextureFormat &format, int width, int height, int miplevels);
241     TestTexture2D(const tcu::CompressedTexFormat &format, int width, int height, bool voidExtent = false);
242     virtual ~TestTexture2D(void);
243 
244     virtual int getNumLevels(void) const;
245     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
246     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
247     virtual const tcu::Texture2D &getTexture(void) const;
248     virtual tcu::Texture2D &getTexture(void);
getTextureFormat(void) const249     virtual const tcu::TextureFormat &getTextureFormat(void) const
250     {
251         return m_texture.getFormat();
252     }
getTextureDimension(void) const253     virtual tcu::UVec3 getTextureDimension(void) const
254     {
255         return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1);
256     }
257 
258     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
259 };
260 
261 class TestTexture2DArray : public TestTexture
262 {
263 private:
264     tcu::Texture2DArray m_texture;
265 
266 public:
267     TestTexture2DArray(const tcu::TextureFormat &format, int width, int height, int arraySize);
268     TestTexture2DArray(const tcu::CompressedTexFormat &format, int width, int height, int arraySize);
269     virtual ~TestTexture2DArray(void);
270 
271     virtual int getNumLevels(void) const;
272     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
273     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
274     virtual const tcu::Texture2DArray &getTexture(void) const;
275     virtual tcu::Texture2DArray &getTexture(void);
276     virtual int getArraySize(void) const;
getTextureFormat(void) const277     virtual const tcu::TextureFormat &getTextureFormat(void) const
278     {
279         return m_texture.getFormat();
280     }
getTextureDimension(void) const281     virtual tcu::UVec3 getTextureDimension(void) const
282     {
283         return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1);
284     }
285 
286     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
287 };
288 
289 class TestTexture3D : public TestTexture
290 {
291 private:
292     tcu::Texture3D m_texture;
293 
294 public:
295     TestTexture3D(const tcu::TextureFormat &format, int width, int height, int depth);
296     TestTexture3D(const tcu::CompressedTexFormat &format, int width, int height, int depth);
297     virtual ~TestTexture3D(void);
298 
299     virtual int getNumLevels(void) const;
300     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
301     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
302     virtual const tcu::Texture3D &getTexture(void) const;
303     virtual tcu::Texture3D &getTexture(void);
getTextureFormat(void) const304     virtual const tcu::TextureFormat &getTextureFormat(void) const
305     {
306         return m_texture.getFormat();
307     }
getTextureDimension(void) const308     virtual tcu::UVec3 getTextureDimension(void) const
309     {
310         return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth());
311     }
312 
313     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
314 };
315 
316 class TestTextureCube : public TestTexture
317 {
318 private:
319     tcu::TextureCube m_texture;
320 
321 public:
322     TestTextureCube(const tcu::TextureFormat &format, int size);
323     TestTextureCube(const tcu::CompressedTexFormat &format, int size);
324     virtual ~TestTextureCube(void);
325 
326     virtual int getNumLevels(void) const;
327     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
328     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
329     virtual int getArraySize(void) const;
330     virtual const tcu::TextureCube &getTexture(void) const;
331     virtual tcu::TextureCube &getTexture(void);
getTextureFormat(void) const332     virtual const tcu::TextureFormat &getTextureFormat(void) const
333     {
334         return m_texture.getFormat();
335     }
getTextureDimension(void) const336     virtual tcu::UVec3 getTextureDimension(void) const
337     {
338         return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1);
339     }
340 
341     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
342 };
343 
344 class TestTextureCubeArray : public TestTexture
345 {
346 private:
347     tcu::TextureCubeArray m_texture;
348 
349 public:
350     TestTextureCubeArray(const tcu::TextureFormat &format, int size, int arraySize);
351     TestTextureCubeArray(const tcu::CompressedTexFormat &format, int size, int arraySize);
352     virtual ~TestTextureCubeArray(void);
353 
354     virtual int getNumLevels(void) const;
355     virtual tcu::PixelBufferAccess getLevel(int level, int layer);
356     virtual const tcu::ConstPixelBufferAccess getLevel(int level, int layer) const;
357     virtual int getArraySize(void) const;
358     virtual const tcu::TextureCubeArray &getTexture(void) const;
359     virtual tcu::TextureCubeArray &getTexture(void);
getTextureFormat(void) const360     virtual const tcu::TextureFormat &getTextureFormat(void) const
361     {
362         return m_texture.getFormat();
363     }
getTextureDimension(void) const364     virtual tcu::UVec3 getTextureDimension(void) const
365     {
366         return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1);
367     }
368 
369     virtual de::MovePtr<TestTexture> copy(const tcu::TextureFormat) const;
370 };
371 
372 } // namespace pipeline
373 } // namespace vkt
374 
375 #endif // _VKTPIPELINEIMAGEUTIL_HPP
376