Check for linear filtering support in pipeline.sampler tests
[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 bool                                                    isLinearFilteringSupported      (const vk::InstanceInterface&   instanceInterface,
67                                                                                                                          vk::VkPhysicalDevice                   device,
68                                                                                                                          vk::VkFormat                                   format,
69                                                                                                                          vk::VkImageTiling                              tiling);
70
71 vk::VkBorderColor                               getFormatBorderColor            (BorderColor color, vk::VkFormat format);
72
73 /*--------------------------------------------------------------------*//*!
74  * Gets a tcu::TextureLevel initialized with data from a VK color
75  * attachment.
76  *
77  * The VkImage must be non-multisampled and able to be used as a source
78  * operand for transfer operations.
79  *//*--------------------------------------------------------------------*/
80 de::MovePtr<tcu::TextureLevel>  readColorAttachment                      (const vk::DeviceInterface&    vk,
81                                                                                                                           vk::VkDevice                                  device,
82                                                                                                                           vk::VkQueue                                   queue,
83                                                                                                                           deUint32                                              queueFamilyIndex,
84                                                                                                                           vk::Allocator&                                allocator,
85                                                                                                                           vk::VkImage                                   image,
86                                                                                                                           vk::VkFormat                                  format,
87                                                                                                                           const tcu::UVec2&                             renderSize);
88
89 /*--------------------------------------------------------------------*//*!
90  * Uploads data from a test texture to a destination VK image.
91  *
92  * The VkImage must be non-multisampled and able to be used as a
93  * destination operand for transfer operations.
94  *//*--------------------------------------------------------------------*/
95 void                                                    uploadTestTexture                       (const vk::DeviceInterface&             vk,
96                                                                                                                          vk::VkDevice                                   device,
97                                                                                                                          vk::VkQueue                                    queue,
98                                                                                                                          deUint32                                               queueFamilyIndex,
99                                                                                                                          vk::Allocator&                                 allocator,
100                                                                                                                          const TestTexture&                             testTexture,
101                                                                                                                          vk::VkImage                                    destImage);
102
103 class TestTexture
104 {
105 public:
106                                                                                                 TestTexture                                     (const tcu::TextureFormat& format, int width, int height, int depth);
107                                                                                                 TestTexture                                     (const tcu::CompressedTexFormat& format, int width, int height, int depth);
108         virtual                                                                         ~TestTexture                            (void);
109
110         virtual int                                                                     getNumLevels                            (void) const = 0;
111         virtual deUint32                                                        getSize                                         (void) const;
112         virtual int                                                                     getArraySize                            (void) const { return 1; }
113
114         virtual bool                                                            isCompressed                            (void) const { return !m_compressedLevels.empty(); }
115         virtual deUint32                                                        getCompressedSize                       (void) const;
116
117         virtual tcu::PixelBufferAccess                          getLevel                                        (int level, int layer) = 0;
118         virtual const tcu::ConstPixelBufferAccess       getLevel                                        (int level, int layer) const = 0;
119
120         virtual tcu::CompressedTexture&                         getCompressedLevel                      (int level, int layer);
121         virtual const tcu::CompressedTexture&           getCompressedLevel                      (int level, int layer) const;
122
123         virtual std::vector<vk::VkBufferImageCopy>      getBufferCopyRegions            (void) const;
124         virtual void                                                            write                                           (deUint8* destPtr) const;
125
126 protected:
127         void                                                                            populateLevels                          (const std::vector<tcu::PixelBufferAccess>& levels);
128         void                                                                            populateCompressedLevels        (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
129
130         static void                                                                     fillWithGradient                        (const tcu::PixelBufferAccess& levelAccess);
131
132 protected:
133         std::vector<tcu::CompressedTexture*>            m_compressedLevels;
134 };
135
136 class TestTexture1D : public TestTexture
137 {
138 private:
139         tcu::Texture1D                                                          m_texture;
140
141 public:
142                                                                                                 TestTexture1D   (const tcu::TextureFormat& format, int width);
143                                                                                                 TestTexture1D   (const tcu::CompressedTexFormat& format, int width);
144         virtual                                                                         ~TestTexture1D  (void);
145
146         virtual int getNumLevels (void) const;
147         virtual tcu::PixelBufferAccess                          getLevel                (int level, int layer);
148         virtual const tcu::ConstPixelBufferAccess       getLevel                (int level, int layer) const;
149         virtual const tcu::Texture1D&                           getTexture              (void) const;
150 };
151
152 class TestTexture1DArray : public TestTexture
153 {
154 private:
155         tcu::Texture1DArray                                                     m_texture;
156
157 public:
158                                                                                                 TestTexture1DArray      (const tcu::TextureFormat& format, int width, int arraySize);
159                                                                                                 TestTexture1DArray      (const tcu::CompressedTexFormat& format, int width, int arraySize);
160         virtual                                                                         ~TestTexture1DArray     (void);
161
162         virtual int                                                                     getNumLevels            (void) const;
163         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
164         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
165         virtual const tcu::Texture1DArray&                      getTexture                      (void) const;
166         virtual int                                                                     getArraySize            (void) const;
167 };
168
169 class TestTexture2D : public TestTexture
170 {
171 private:
172         tcu::Texture2D                                                          m_texture;
173
174 public:
175                                                                                                 TestTexture2D           (const tcu::TextureFormat& format, int width, int height);
176                                                                                                 TestTexture2D           (const tcu::CompressedTexFormat& format, int width, int height);
177         virtual                                                                         ~TestTexture2D          (void);
178
179         virtual int                                                                     getNumLevels            (void) const;
180         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
181         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
182         virtual const tcu::Texture2D&                           getTexture                      (void) const;
183 };
184
185 class TestTexture2DArray : public TestTexture
186 {
187 private:
188         tcu::Texture2DArray     m_texture;
189
190 public:
191                                                                                                 TestTexture2DArray      (const tcu::TextureFormat& format, int width, int height, int arraySize);
192                                                                                                 TestTexture2DArray      (const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
193         virtual                                                                         ~TestTexture2DArray     (void);
194
195         virtual int                                                                     getNumLevels            (void) const;
196         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
197         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
198         virtual const tcu::Texture2DArray&                      getTexture                      (void) const;
199         virtual int                                                                     getArraySize            (void) const;
200 };
201
202 class TestTexture3D : public TestTexture
203 {
204 private:
205         tcu::Texture3D  m_texture;
206
207 public:
208                                                                                                 TestTexture3D           (const tcu::TextureFormat& format, int width, int height, int depth);
209                                                                                                 TestTexture3D           (const tcu::CompressedTexFormat& format, int width, int height, int depth);
210         virtual                                                                         ~TestTexture3D          (void);
211
212         virtual int                                                                     getNumLevels            (void) const;
213         virtual tcu::PixelBufferAccess                          getLevel                        (int level, int layer);
214         virtual const tcu::ConstPixelBufferAccess       getLevel                        (int level, int layer) const;
215         virtual const tcu::Texture3D&                           getTexture                      (void) const;
216 };
217
218 class TestTextureCube : public TestTexture
219 {
220 private:
221         tcu::TextureCube                                                        m_texture;
222
223 public:
224                                                                                                 TestTextureCube                 (const tcu::TextureFormat& format, int size);
225                                                                                                 TestTextureCube                 (const tcu::CompressedTexFormat& format, int size);
226         virtual                                                                         ~TestTextureCube                (void);
227
228         virtual int                                                                     getNumLevels                    (void) const;
229         virtual tcu::PixelBufferAccess                          getLevel                                (int level, int layer);
230         virtual const tcu::ConstPixelBufferAccess       getLevel                                (int level, int layer) const;
231         virtual int                                                                     getArraySize                    (void) const;
232         virtual const tcu::TextureCube&                         getTexture                              (void) const;
233 };
234
235 class TestTextureCubeArray: public TestTexture
236 {
237 private:
238         tcu::TextureCubeArray                                           m_texture;
239
240 public:
241                                                                                                 TestTextureCubeArray    (const tcu::TextureFormat& format, int size, int arraySize);
242                                                                                                 TestTextureCubeArray    (const tcu::CompressedTexFormat& format, int size, int arraySize);
243         virtual                                                                         ~TestTextureCubeArray   (void);
244
245         virtual int                                                                     getNumLevels                    (void) const;
246         virtual tcu::PixelBufferAccess                          getLevel                                (int level, int layer);
247         virtual const tcu::ConstPixelBufferAccess       getLevel                                (int level, int layer) const;
248         virtual int                                                                     getArraySize                    (void) const;
249         virtual const tcu::TextureCubeArray&            getTexture                              (void) const;
250 };
251
252 } // pipeline
253 } // vkt
254
255 #endif // _VKTPIPELINEIMAGEUTIL_HPP