Add test for sparse render target.
[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  * 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
50         BORDER_COLOR_COUNT
51 };
52
53 bool                                                    isSupportedSamplableFormat      (const vk::InstanceInterface&   instanceInterface,
54                                                                                                                          vk::VkPhysicalDevice                   device,
55                                                                                                                          vk::VkFormat                                   format);
56 bool                                                    isLinearFilteringSupported      (const vk::InstanceInterface&   instanceInterface,
57                                                                                                                          vk::VkPhysicalDevice                   device,
58                                                                                                                          vk::VkFormat                                   format,
59                                                                                                                          vk::VkImageTiling                              tiling);
60
61 vk::VkBorderColor                               getFormatBorderColor            (BorderColor color, vk::VkFormat format);
62
63 void                                                    getLookupScaleBias                      (vk::VkFormat                                   format,
64                                                                                                                          tcu::Vec4&                                             lookupScale,
65                                                                                                                          tcu::Vec4&                                             lookupBias);
66
67 /*--------------------------------------------------------------------*//*!
68  * Gets a tcu::TextureLevel initialized with data from a VK color
69  * attachment.
70  *
71  * The VkImage must be non-multisampled and able to be used as a source
72  * operand for transfer operations.
73  *//*--------------------------------------------------------------------*/
74 de::MovePtr<tcu::TextureLevel>  readColorAttachment                      (const vk::DeviceInterface&    vk,
75                                                                                                                           vk::VkDevice                                  device,
76                                                                                                                           vk::VkQueue                                   queue,
77                                                                                                                           deUint32                                              queueFamilyIndex,
78                                                                                                                           vk::Allocator&                                allocator,
79                                                                                                                           vk::VkImage                                   image,
80                                                                                                                           vk::VkFormat                                  format,
81                                                                                                                           const tcu::UVec2&                             renderSize);
82
83 /*--------------------------------------------------------------------*//*!
84  * Uploads data from a test texture to a destination VK image.
85  *
86  * The VkImage must be non-multisampled and able to be used as a
87  * destination operand for transfer operations.
88  *//*--------------------------------------------------------------------*/
89 void                                                    uploadTestTexture                       (const vk::DeviceInterface&             vk,
90                                                                                                                          vk::VkDevice                                   device,
91                                                                                                                          vk::VkQueue                                    queue,
92                                                                                                                          deUint32                                               queueFamilyIndex,
93                                                                                                                          vk::Allocator&                                 allocator,
94                                                                                                                          const TestTexture&                             testTexture,
95                                                                                                                          vk::VkImage                                    destImage);
96
97 /*--------------------------------------------------------------------*//*!
98  * Uploads data from a test texture to a destination VK image using sparse
99  * binding.
100  *
101  * The VkImage must be non-multisampled and able to be used as a
102  * destination operand for transfer operations.
103  *//*--------------------------------------------------------------------*/
104 void                                                    uploadTestTextureSparse         (const vk::DeviceInterface&                                             vk,
105                                                                                                                          vk::VkDevice                                                                   device,
106                                                                                                                          const vk::VkPhysicalDevice                                             physicalDevice,
107                                                                                                                          const vk::InstanceInterface&                                   instance,
108                                                                                                                          const vk::VkImageCreateInfo&                                   imageCreateInfo,
109                                                                                                                          vk::VkQueue                                                                    queue,
110                                                                                                                          deUint32                                                                               queueFamilyIndex,
111                                                                                                                          vk::Allocator&                                                                 allocator,
112                                                                                                                          std::vector<de::SharedPtr<vk::Allocation> >&   allocations,
113                                                                                                                          const TestTexture&                                                             srcTexture,
114                                                                                                                          vk::VkImage                                                                    destImage);
115
116
117
118 /*--------------------------------------------------------------------*//*!
119  * Allocates memory for a sparse image and handles the memory binding.
120  *//*--------------------------------------------------------------------*/
121 void                                                    allocateAndBindSparseImage      (const vk::DeviceInterface&                                             vk,
122                                                                                                                          vk::VkDevice                                                                   device,
123                                                                                                                          const vk::VkPhysicalDevice                                             physicalDevice,
124                                                                                                                          const vk::InstanceInterface&                                   instance,
125                                                                                                                          const vk::VkImageCreateInfo&                                   imageCreateInfo,
126                                                                                                                          const vk::VkSemaphore&                                                 signalSemaphore,
127                                                                                                                          vk::VkQueue                                                                    queue,
128                                                                                                                          vk::Allocator&                                                                 allocator,
129                                                                                                                          std::vector<de::SharedPtr<vk::Allocation> >&   allocations,
130                                                                                                                          tcu::TextureFormat                                                             format,
131                                                                                                                          vk::VkImage                                                                    destImage);
132
133 class TestTexture
134 {
135 public:
136                                                                                                 TestTexture                                     (const tcu::TextureFormat& format, int width, int height, int depth);
137                                                                                                 TestTexture                                     (const tcu::CompressedTexFormat& format, int width, int height, int depth);
138         virtual                                                                         ~TestTexture                            (void);
139
140         virtual int                                                                     getNumLevels                            (void) const = 0;
141         virtual deUint32                                                        getSize                                         (void) const;
142         virtual int                                                                     getArraySize                            (void) const { return 1; }
143
144         virtual bool                                                            isCompressed                            (void) const { return !m_compressedLevels.empty(); }
145         virtual deUint32                                                        getCompressedSize                       (void) const;
146
147         virtual tcu::PixelBufferAccess                          getLevel                                        (int level, int layer) = 0;
148         virtual const tcu::ConstPixelBufferAccess       getLevel                                        (int level, int layer) const = 0;
149
150         virtual tcu::CompressedTexture&                         getCompressedLevel                      (int level, int layer);
151         virtual const tcu::CompressedTexture&           getCompressedLevel                      (int level, int layer) const;
152
153         virtual std::vector<vk::VkBufferImageCopy>      getBufferCopyRegions            (void) const;
154         virtual void                                                            write                                           (deUint8* destPtr) const;
155         virtual de::MovePtr<TestTexture>                        copy                                            (const tcu::TextureFormat) const = 0;
156
157         virtual const tcu::TextureFormat&                       getTextureFormat                        (void) const = 0;
158         virtual tcu::UVec3                                                      getTextureDimension                     (void) const = 0;
159
160 protected:
161         void                                                                            populateLevels                          (const std::vector<tcu::PixelBufferAccess>& levels);
162         void                                                                            populateCompressedLevels        (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
163
164         static void                                                                     fillWithGradient                        (const tcu::PixelBufferAccess& levelAccess);
165
166         void                                                                            copyToTexture                           (TestTexture&) const;
167
168 protected:
169         std::vector<tcu::CompressedTexture*>            m_compressedLevels;
170 };
171
172 class TestTexture1D : public TestTexture
173 {
174 private:
175         tcu::Texture1D                                                          m_texture;
176
177 public:
178                                                                                                 TestTexture1D           (const tcu::TextureFormat& format, int width);
179                                                                                                 TestTexture1D           (const tcu::CompressedTexFormat& format, int width);
180         virtual                                                                         ~TestTexture1D          (void);
181
182         virtual int getNumLevels (void) const;
183         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
184         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
185         virtual const tcu::Texture1D&                           getTexture                      (void) const;
186         virtual tcu::Texture1D&                                         getTexture                      (void);
187         virtual const tcu::TextureFormat&                       getTextureFormat        (void) const { return m_texture.getFormat(); }
188         virtual tcu::UVec3                                                      getTextureDimension     (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
189
190         virtual de::MovePtr<TestTexture>                        copy                            (const tcu::TextureFormat) const;
191 };
192
193 class TestTexture1DArray : public TestTexture
194 {
195 private:
196         tcu::Texture1DArray                                                     m_texture;
197
198 public:
199                                                                                                 TestTexture1DArray      (const tcu::TextureFormat& format, int width, int arraySize);
200                                                                                                 TestTexture1DArray      (const tcu::CompressedTexFormat& format, int width, int arraySize);
201         virtual                                                                         ~TestTexture1DArray     (void);
202
203         virtual int                                                                     getNumLevels            (void) const;
204         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
205         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
206         virtual const tcu::Texture1DArray&                      getTexture                      (void) const;
207         virtual tcu::Texture1DArray&                            getTexture                      (void);
208         virtual int                                                                     getArraySize            (void) const;
209         virtual const tcu::TextureFormat&                       getTextureFormat        (void) const { return m_texture.getFormat(); }
210         virtual tcu::UVec3                                                      getTextureDimension     (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
211
212         virtual de::MovePtr<TestTexture>                        copy                            (const tcu::TextureFormat) const;
213 };
214
215 class TestTexture2D : public TestTexture
216 {
217 private:
218         tcu::Texture2D                                                          m_texture;
219
220 public:
221                                                                                                 TestTexture2D           (const tcu::TextureFormat& format, int width, int height);
222                                                                                                 TestTexture2D           (const tcu::CompressedTexFormat& format, int width, int height);
223         virtual                                                                         ~TestTexture2D          (void);
224
225         virtual int                                                                     getNumLevels            (void) const;
226         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
227         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
228         virtual const tcu::Texture2D&                           getTexture                      (void) const;
229         virtual tcu::Texture2D&                                         getTexture                      (void);
230         virtual const tcu::TextureFormat&                       getTextureFormat        (void) const { return m_texture.getFormat(); }
231         virtual tcu::UVec3                                                      getTextureDimension     (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
232
233         virtual de::MovePtr<TestTexture>                        copy                            (const tcu::TextureFormat) const;
234 };
235
236 class TestTexture2DArray : public TestTexture
237 {
238 private:
239         tcu::Texture2DArray     m_texture;
240
241 public:
242                                                                                                 TestTexture2DArray      (const tcu::TextureFormat& format, int width, int height, int arraySize);
243                                                                                                 TestTexture2DArray      (const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
244         virtual                                                                         ~TestTexture2DArray     (void);
245
246         virtual int                                                                     getNumLevels            (void) const;
247         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
248         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
249         virtual const tcu::Texture2DArray&                      getTexture                      (void) const;
250         virtual tcu::Texture2DArray&                            getTexture                      (void);
251         virtual int                                                                     getArraySize            (void) const;
252         virtual const tcu::TextureFormat&                       getTextureFormat        (void) const { return m_texture.getFormat(); }
253         virtual tcu::UVec3                                                      getTextureDimension     (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
254
255         virtual de::MovePtr<TestTexture>                        copy                            (const tcu::TextureFormat) const;
256 };
257
258 class TestTexture3D : public TestTexture
259 {
260 private:
261         tcu::Texture3D  m_texture;
262
263 public:
264                                                                                                 TestTexture3D           (const tcu::TextureFormat& format, int width, int height, int depth);
265                                                                                                 TestTexture3D           (const tcu::CompressedTexFormat& format, int width, int height, int depth);
266         virtual                                                                         ~TestTexture3D          (void);
267
268         virtual int                                                                     getNumLevels            (void) const;
269         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
270         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
271         virtual const tcu::Texture3D&                           getTexture                      (void) const;
272         virtual tcu::Texture3D&                                         getTexture                      (void);
273         virtual const tcu::TextureFormat&                       getTextureFormat        (void) const { return m_texture.getFormat(); }
274         virtual tcu::UVec3                                                      getTextureDimension     (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
275
276         virtual de::MovePtr<TestTexture>                        copy                            (const tcu::TextureFormat) const;
277 };
278
279 class TestTextureCube : public TestTexture
280 {
281 private:
282         tcu::TextureCube                                                        m_texture;
283
284 public:
285                                                                                                 TestTextureCube                 (const tcu::TextureFormat& format, int size);
286                                                                                                 TestTextureCube                 (const tcu::CompressedTexFormat& format, int size);
287         virtual                                                                         ~TestTextureCube                (void);
288
289         virtual int                                                                     getNumLevels                    (void) const;
290         virtual tcu::PixelBufferAccess                          getLevel                                (int level, int layer);
291         virtual const tcu::ConstPixelBufferAccess       getLevel                                (int level, int layer) const;
292         virtual int                                                                     getArraySize                    (void) const;
293         virtual const tcu::TextureCube&                         getTexture                              (void) const;
294         virtual tcu::TextureCube&                                       getTexture                              (void);
295         virtual const tcu::TextureFormat&                       getTextureFormat                (void) const { return m_texture.getFormat(); }
296         virtual tcu::UVec3                                                      getTextureDimension             (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
297
298         virtual de::MovePtr<TestTexture>                        copy                                    (const tcu::TextureFormat) const;
299 };
300
301 class TestTextureCubeArray: public TestTexture
302 {
303 private:
304         tcu::TextureCubeArray                                           m_texture;
305
306 public:
307                                                                                                 TestTextureCubeArray    (const tcu::TextureFormat& format, int size, int arraySize);
308                                                                                                 TestTextureCubeArray    (const tcu::CompressedTexFormat& format, int size, int arraySize);
309         virtual                                                                         ~TestTextureCubeArray   (void);
310
311         virtual int                                                                     getNumLevels                    (void) const;
312         virtual tcu::PixelBufferAccess                          getLevel                                (int level, int layer);
313         virtual const tcu::ConstPixelBufferAccess       getLevel                                (int level, int layer) const;
314         virtual int                                                                     getArraySize                    (void) const;
315         virtual const tcu::TextureCubeArray&            getTexture                              (void) const;
316         virtual tcu::TextureCubeArray&                          getTexture                              (void);
317         virtual const tcu::TextureFormat&                       getTextureFormat                (void) const { return m_texture.getFormat(); }
318         virtual tcu::UVec3                                                      getTextureDimension             (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
319
320         virtual de::MovePtr<TestTexture>                        copy                                    (const tcu::TextureFormat) const;
321 };
322
323 } // pipeline
324 } // vkt
325
326 #endif // _VKTPIPELINEIMAGEUTIL_HPP