Merge branch 'jekstrand_renderpass_transfer_bit_fix' into 'master'
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / pipeline / vktPipelineImageUtil.hpp
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  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and/or associated documentation files (the
12  * "Materials"), to deal in the Materials without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Materials, and to
15  * permit persons to whom the Materials are furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice(s) and this permission notice shall be included
19  * in all copies or substantial portions of the Materials.
20  *
21  * The Materials are Confidential Information as defined by the
22  * Khronos Membership Agreement until designated non-confidential by Khronos,
23  * at which point this condition clause shall be removed.
24  *
25  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
29  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
30  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32  *
33  *//*!
34  * \file
35  * \brief Utilities for images.
36  *//*--------------------------------------------------------------------*/
37
38 #include "tcuDefs.hpp"
39 #include "vkDefs.hpp"
40 #include "vkDefs.hpp"
41 #include "vkPlatform.hpp"
42 #include "vkMemUtil.hpp"
43 #include "vkRef.hpp"
44 #include "tcuTexture.hpp"
45 #include "tcuCompressedTexture.hpp"
46
47 namespace vkt
48 {
49 namespace pipeline
50 {
51
52 class TestTexture;
53
54 enum BorderColor
55 {
56         BORDER_COLOR_OPAQUE_BLACK,
57         BORDER_COLOR_OPAQUE_WHITE,
58         BORDER_COLOR_TRANSPARENT_BLACK,
59
60         BORDER_COLOR_COUNT
61 };
62
63 bool                                                    isSupportedSamplableFormat      (const vk::InstanceInterface& instanceInterface,
64                                                                                                                          vk::VkPhysicalDevice device,
65                                                                                                                          vk::VkFormat format);
66
67 vk::VkBorderColor                               getFormatBorderColor            (BorderColor color, vk::VkFormat format);
68
69 /*--------------------------------------------------------------------*//*!
70  * Gets a tcu::TextureLevel initialized with data from a VK color
71  * attachment.
72  *
73  * The VkImage must be non-multisampled and able to be used as a source
74  * operand for transfer operations.
75  *//*--------------------------------------------------------------------*/
76 de::MovePtr<tcu::TextureLevel>  readColorAttachment                      (const vk::DeviceInterface&    vk,
77                                                                                                                           vk::VkDevice                                  device,
78                                                                                                                           vk::VkQueue                                   queue,
79                                                                                                                           deUint32                                              queueFamilyIndex,
80                                                                                                                           vk::Allocator&                                allocator,
81                                                                                                                           vk::VkImage                                   image,
82                                                                                                                           vk::VkFormat                                  format,
83                                                                                                                           const tcu::UVec2&                             renderSize);
84
85 /*--------------------------------------------------------------------*//*!
86  * Uploads data from a test texture to a destination VK image.
87  *
88  * The VkImage must be non-multisampled and able to be used as a
89  * destination operand for transfer operations.
90  *//*--------------------------------------------------------------------*/
91 void                                                    uploadTestTexture                       (const vk::DeviceInterface&             vk,
92                                                                                                                          vk::VkDevice                                   device,
93                                                                                                                          vk::VkQueue                                    queue,
94                                                                                                                          deUint32                                               queueFamilyIndex,
95                                                                                                                          vk::Allocator&                                 allocator,
96                                                                                                                          const TestTexture&                             testTexture,
97                                                                                                                          vk::VkImage                                    destImage);
98
99 class TestTexture
100 {
101 public:
102                                                                                                 TestTexture                                     (const tcu::TextureFormat& format, int width, int height, int depth);
103                                                                                                 TestTexture                                     (const tcu::CompressedTexFormat& format, int width, int height, int depth);
104         virtual                                                                         ~TestTexture                            (void);
105
106         virtual int                                                                     getNumLevels                            (void) const = 0;
107         virtual deUint32                                                        getSize                                         (void) const;
108         virtual int                                                                     getArraySize                            (void) const { return 1; }
109
110         virtual bool                                                            isCompressed                            (void) const { return !m_compressedLevels.empty(); }
111         virtual deUint32                                                        getCompressedSize                       (void) const;
112
113         virtual tcu::PixelBufferAccess                          getLevel                                        (int level, int layer) = 0;
114         virtual const tcu::ConstPixelBufferAccess       getLevel                                        (int level, int layer) const = 0;
115
116         virtual tcu::CompressedTexture&                         getCompressedLevel                      (int level, int layer);
117         virtual const tcu::CompressedTexture&           getCompressedLevel                      (int level, int layer) const;
118
119         virtual std::vector<vk::VkBufferImageCopy>      getBufferCopyRegions            (void) const;
120         virtual void                                                            write                                           (deUint8* destPtr) const;
121
122 protected:
123         void                                                                            populateLevels                          (const std::vector<tcu::PixelBufferAccess>& levels);
124         void                                                                            populateCompressedLevels        (const tcu::CompressedTexFormat& format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
125
126         static void                                                                     fillWithGradient                        (const tcu::PixelBufferAccess& levelAccess);
127
128 protected:
129         std::vector<tcu::CompressedTexture*>            m_compressedLevels;
130 };
131
132 class TestTexture1D : public TestTexture
133 {
134 private:
135         tcu::Texture1D                                                          m_texture;
136
137 public:
138                                                                                                 TestTexture1D   (const tcu::TextureFormat& format, int width);
139                                                                                                 TestTexture1D   (const tcu::CompressedTexFormat& format, int width);
140         virtual                                                                         ~TestTexture1D  (void);
141
142         virtual int getNumLevels (void) const;
143         virtual tcu::PixelBufferAccess                          getLevel                (int level, int layer);
144         virtual const tcu::ConstPixelBufferAccess       getLevel                (int level, int layer) const;
145         virtual const tcu::Texture1D&                           getTexture              (void) const;
146 };
147
148 class TestTexture1DArray : public TestTexture
149 {
150 private:
151         tcu::Texture1DArray                                                     m_texture;
152
153 public:
154                                                                                                 TestTexture1DArray      (const tcu::TextureFormat& format, int width, int arraySize);
155                                                                                                 TestTexture1DArray      (const tcu::CompressedTexFormat& format, int width, int arraySize);
156         virtual                                                                         ~TestTexture1DArray     (void);
157
158         virtual int                                                                     getNumLevels            (void) const;
159         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
160         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
161         virtual const tcu::Texture1DArray&                      getTexture                      (void) const;
162         virtual int                                                                     getArraySize            (void) const;
163 };
164
165 class TestTexture2D : public TestTexture
166 {
167 private:
168         tcu::Texture2D                                                          m_texture;
169
170 public:
171                                                                                                 TestTexture2D           (const tcu::TextureFormat& format, int width, int height);
172                                                                                                 TestTexture2D           (const tcu::CompressedTexFormat& format, int width, int height);
173         virtual                                                                         ~TestTexture2D          (void);
174
175         virtual int                                                                     getNumLevels            (void) const;
176         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
177         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
178         virtual const tcu::Texture2D&                           getTexture                      (void) const;
179 };
180
181 class TestTexture2DArray : public TestTexture
182 {
183 private:
184         tcu::Texture2DArray     m_texture;
185
186 public:
187                                                                                                 TestTexture2DArray      (const tcu::TextureFormat& format, int width, int height, int arraySize);
188                                                                                                 TestTexture2DArray      (const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
189         virtual                                                                         ~TestTexture2DArray     (void);
190
191         virtual int                                                                     getNumLevels            (void) const;
192         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
193         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
194         virtual const tcu::Texture2DArray&                      getTexture                      (void) const;
195         virtual int                                                                     getArraySize            (void) const;
196 };
197
198 class TestTexture3D : public TestTexture
199 {
200 private:
201         tcu::Texture3D  m_texture;
202
203 public:
204                                                                                                 TestTexture3D           (const tcu::TextureFormat& format, int width, int height, int depth);
205                                                                                                 TestTexture3D           (const tcu::CompressedTexFormat& format, int width, int height, int depth);
206         virtual                                                                         ~TestTexture3D          (void);
207
208         virtual int                                                                     getNumLevels            (void) const;
209         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
210         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
211         virtual const tcu::Texture3D&                           getTexture                      (void) const;
212 };
213
214 class TestTextureCube : public TestTexture
215 {
216 private:
217         tcu::TextureCube                                                        m_texture;
218
219 public:
220                                                                                                 TestTextureCube                 (const tcu::TextureFormat& format, int size);
221                                                                                                 TestTextureCube                 (const tcu::CompressedTexFormat& format, int size);
222         virtual                                                                         ~TestTextureCube                (void);
223
224         virtual int                                                                     getNumLevels                    (void) const;
225         virtual tcu::PixelBufferAccess                          getLevel                                (int level, int layer);
226         virtual const tcu::ConstPixelBufferAccess       getLevel                                (int level, int layer) const;
227         virtual int                                                                     getArraySize                    (void) const;
228         virtual const tcu::TextureCube&                         getTexture                              (void) const;
229 };
230
231 class TestTextureCubeArray: public TestTexture
232 {
233 private:
234         tcu::TextureCubeArray                                           m_texture;
235
236 public:
237                                                                                                 TestTextureCubeArray    (const tcu::TextureFormat& format, int size, int arraySize);
238                                                                                                 TestTextureCubeArray    (const tcu::CompressedTexFormat& format, int size, int arraySize);
239         virtual                                                                         ~TestTextureCubeArray   (void);
240
241         virtual int                                                                     getNumLevels                    (void) const;
242         virtual tcu::PixelBufferAccess                          getLevel                                (int level, int layer);
243         virtual const tcu::ConstPixelBufferAccess       getLevel                                (int level, int layer) const;
244         virtual int                                                                     getArraySize                    (void) const;
245         virtual const tcu::TextureCubeArray&            getTexture                              (void) const;
246 };
247
248 } // pipeline
249 } // vkt
250
251 #endif // _VKTPIPELINEIMAGEUTIL_HPP