d85d0147d370cf1b73773d268cf410598b206235
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / draw / vktDrawImageObjectUtil.hpp
1 #ifndef _VKTDRAWIMAGEOBJECTUTIL_HPP
2 #define _VKTDRAWIMAGEOBJECTUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Intel Corporation
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 Image Object Util
36  *//*--------------------------------------------------------------------*/
37
38 #include "vkDefs.hpp"
39 #include "vkMemUtil.hpp"
40 #include "vkRefUtil.hpp"
41
42 #include "deSharedPtr.hpp"
43
44 #include "tcuTexture.hpp"
45
46 namespace vkt
47 {
48 namespace Draw
49 {
50
51 class MemoryOp
52 {
53 public:
54         static void pack        (int                                    pixelSize,
55                                                  int                                    width,
56                                                  int                                    height,
57                                                  int                                    depth,
58                                                  vk::VkDeviceSize               rowPitch,
59                                                  vk::VkDeviceSize               depthPitch,
60                                                  const void *                   srcBuffer,
61                                                  void *                                 destBuffer);
62
63         static void unpack      (int                                    pixelSize,
64                                                  int                                    width,
65                                                  int                                    height,
66                                                  int                                    depth,
67                                                  vk::VkDeviceSize               rowPitch,
68                                                  vk::VkDeviceSize               depthPitch,
69                                                  const void *                   srcBuffer,
70                                                  void *                                 destBuffer);
71 };
72
73
74 class Image
75 {
76 public:
77         static de::SharedPtr<Image> create                              (const vk::DeviceInterface &vk, vk::VkDevice device, const vk::VkImageCreateInfo &createInfo);
78
79         static de::SharedPtr<Image> createAndAlloc              (const vk::DeviceInterface&                             vk,
80                                                                                                          vk::VkDevice                                                   device,
81                                                                                                          const vk::VkImageCreateInfo&                   createInfo,
82                                                                                                          vk::Allocator&                                                 allocator,
83                                                                                                          vk::MemoryRequirement                                  memoryRequirement = vk::MemoryRequirement::Any);
84
85         tcu::ConstPixelBufferAccess readSurface                 (vk::VkQueue                                                    queue,
86                                                                                                          vk::Allocator&                                                 allocator,
87                                                                                                          vk::VkImageLayout                                              layout,
88                                                                                                          vk::VkOffset3D                                                 offset,
89                                                                                                          int                                                                    width,
90                                                                                                          int                                                                    height,
91                                                                                                          vk::VkImageAspectFlagBits                              aspect,
92                                                                                                          unsigned int                                                   mipLevel = 0,
93                                                                                                          unsigned int                                                   arrayElement = 0);
94
95         tcu::ConstPixelBufferAccess readSurface1D               (vk::VkQueue                                                    queue,
96                                                                                                          vk::Allocator&                                                 allocator,
97                                                                                                          vk::VkImageLayout                                              layout,
98                                                                                                          vk::VkOffset3D                                                 offset,
99                                                                                                          int                                                                    width,
100                                                                                                          vk::VkImageAspectFlagBits                              aspect,
101                                                                                                          unsigned int                                                   mipLevel = 0,
102                                                                                                          unsigned int                                                   arrayElement = 0);
103
104         tcu::ConstPixelBufferAccess readVolume                  (vk::VkQueue                                                    queue,
105                                                                                                          vk::Allocator&                                                 allocator,
106                                                                                                          vk::VkImageLayout                                              layout,
107                                                                                                          vk::VkOffset3D                                                 offset,
108                                                                                                          int                                                                    width,
109                                                                                                          int                                                                    height,
110                                                                                                          int                                                                    depth,
111                                                                                                          vk::VkImageAspectFlagBits                              aspect,
112                                                                                                          unsigned int                                                   mipLevel = 0,
113                                                                                                          unsigned int                                                   arrayElement = 0);
114
115
116         tcu::ConstPixelBufferAccess readSurfaceLinear   (vk::VkOffset3D                                                 offset,
117                                                                                                          int                                                                    width,
118                                                                                                          int                                                                    height,
119                                                                                                          int                                                                    depth,
120                                                                                                          vk::VkImageAspectFlagBits                              aspect,
121                                                                                                          unsigned int                                                   mipLevel = 0,
122                                                                                                          unsigned int                                                   arrayElement = 0);
123
124         void                                            read                            (vk::VkQueue                                                    queue,
125                                                                                                          vk::Allocator&                                                 allocator,
126                                                                                                          vk::VkImageLayout                                              layout,
127                                                                                                          vk::VkOffset3D                                                 offset,
128                                                                                                          int                                                                    width,
129                                                                                                          int                                                                    height,
130                                                                                                          int                                                                    depth,
131                                                                                                          unsigned int                                                   mipLevel,
132                                                                                                          unsigned int                                                   arrayElement,
133                                                                                                          vk::VkImageAspectFlagBits                              aspect,
134                                                                                                          vk::VkImageType                                                type,
135                                                                                                          void *                                                                 data);
136
137         void                                            readUsingBuffer         (vk::VkQueue                                                    queue,
138                                                                                                          vk::Allocator&                                                 allocator,
139                                                                                                          vk::VkImageLayout                                              layout,
140                                                                                                          vk::VkOffset3D                                                 offset,
141                                                                                                          int                                                                    width,
142                                                                                                          int                                                                    height,
143                                                                                                          int                                                                    depth,
144                                                                                                          unsigned int                                                   mipLevel,
145                                                                                                          unsigned int                                                   arrayElement,
146                                                                                                          vk::VkImageAspectFlagBits                              aspect,
147                                                                                                          void *                                                                 data);
148
149         void                                            readLinear                      (vk::VkOffset3D                                                 offset,
150                                                                                                          int                                                                    width,
151                                                                                                          int                                                                    height,
152                                                                                                          int                                                                    depth,
153                                                                                                          unsigned int                                                   mipLevel,
154                                                                                                          unsigned int                                                   arrayElement,
155                                                                                                          vk::VkImageAspectFlagBits                              aspect,
156                                                                                                          void *                                                                 data);
157
158         void                                            uploadVolume            (const tcu::ConstPixelBufferAccess&             access,
159                                                                                                          vk::VkQueue                                                    queue,
160                                                                                                          vk::Allocator&                                                 allocator,
161                                                                                                          vk::VkImageLayout                                              layout,
162                                                                                                          vk::VkOffset3D                                                 offset,
163                                                                                                          vk::VkImageAspectFlagBits                              aspect,
164                                                                                                          unsigned int                                                   mipLevel = 0,
165                                                                                                          unsigned int                                                   arrayElement = 0);
166
167         void                                            uploadSurface            (const tcu::ConstPixelBufferAccess&    access,
168                                                                                                                 vk::VkQueue                                                     queue,
169                                                                                                                 vk::Allocator&                                          allocator,
170                                                                                                                 vk::VkImageLayout                                       layout,
171                                                                                                                 vk::VkOffset3D                                          offset,
172                                                                                                                 vk::VkImageAspectFlagBits                       aspect,
173                                                                                                                 unsigned int                                            mipLevel = 0,
174                                                                                                                 unsigned int                                            arrayElement = 0);
175
176         void                                            uploadSurface1D         (const tcu::ConstPixelBufferAccess&             access,
177                                                                                                          vk::VkQueue                                                    queue,
178                                                                                                          vk::Allocator&                                                 allocator,
179                                                                                                          vk::VkImageLayout                                              layout,
180                                                                                                          vk::VkOffset3D                                                 offset,
181                                                                                                          vk::VkImageAspectFlagBits                              aspect,
182                                                                                                          unsigned int                                                   mipLevel = 0,
183                                                                                                          unsigned int                                                   arrayElement = 0);
184
185         void                                            uploadSurfaceLinear     (const tcu::ConstPixelBufferAccess&             access,
186                                                                                                          vk::VkOffset3D                                                 offset,
187                                                                                                          int                                                                    width,
188                                                                                                          int                                                                    height,
189                                                                                                          int                                                                    depth,
190                                                                                                          vk::VkImageAspectFlagBits                              aspect,
191                                                                                                          unsigned int                                                   mipLevel = 0,
192                                                                                                          unsigned int                                                   arrayElement = 0);
193
194         void                                            upload                          (vk::VkQueue                                                    queue,
195                                                                                                          vk::Allocator&                                                 allocator,
196                                                                                                          vk::VkImageLayout                                              layout,
197                                                                                                          vk::VkOffset3D                                                 offset,
198                                                                                                          int                                                                    width,
199                                                                                                          int                                                                    height,
200                                                                                                          int                                                                    depth,
201                                                                                                          unsigned int                                                   mipLevel,
202                                                                                                          unsigned int                                                   arrayElement,
203                                                                                                          vk::VkImageAspectFlagBits                              aspect,
204                                                                                                          vk::VkImageType                                                type,
205                                                                                                          const void *                                                   data);
206
207         void                                            uploadUsingBuffer       (vk::VkQueue                                                    queue,
208                                                                                                          vk::Allocator&                                                 allocator,
209                                                                                                          vk::VkImageLayout                                              layout,
210                                                                                                          vk::VkOffset3D                                                 offset,
211                                                                                                          int                                                                    width,
212                                                                                                          int                                                                    height,
213                                                                                                          int                                                                    depth,
214                                                                                                          unsigned int                                                   mipLevel,
215                                                                                                          unsigned int                                                   arrayElement,
216                                                                                                          vk::VkImageAspectFlagBits                              aspect,
217                                                                                                          const void *                                                   data);
218
219         void                                            uploadLinear            (vk::VkOffset3D                                                 offset,
220                                                                                                          int                                                                    width,
221                                                                                                          int                                                                    height,
222                                                                                                          int                                                                    depth,
223                                                                                                          unsigned int                                                   mipLevel,
224                                                                                                          unsigned int                                                   arrayElement,
225                                                                                                          vk::VkImageAspectFlagBits                              aspect,
226                                                                                                          const void *                                                   data);
227
228         de::SharedPtr<Image>            copyToLinearImage       (vk::VkQueue                                                    queue,
229                                                                                                          vk::Allocator&                                                 allocator,
230                                                                                                          vk::VkImageLayout                                              layout,
231                                                                                                          vk::VkOffset3D                                                 offset,
232                                                                                                          int                                                                    width,
233                                                                                                          int                                                                    height,
234                                                                                                          int                                                                    depth,
235                                                                                                          unsigned int                                                   mipLevel,
236                                                                                                          unsigned int                                                   arrayElement,
237                                                                                                          vk::VkImageAspectFlagBits                              aspect,
238                                                                                                          vk::VkImageType                                                type);
239
240         const vk::VkFormat&                     getFormat                       (void) const                                                                                    { return m_format;              }
241         vk::VkImage                                     object                          (void) const                                                                                    { return *m_object;             }
242         void                                            bindMemory                      (de::MovePtr<vk::Allocation>                    allocation);
243         vk::Allocation                          getBoundMemory          (void) const                                                                                    { return *m_allocation; }
244
245 private:
246         vk::VkDeviceSize                        getPixelOffset          (vk::VkOffset3D                                                 offset,
247                                                                                                          vk::VkDeviceSize                                               rowPitch,
248                                                                                                          vk::VkDeviceSize                                               depthPitch,
249                                                                                                          unsigned int                                                   mipLevel,
250                                                                                                          unsigned int                                                   arrayElement);
251
252                                                                 Image                           (const vk::DeviceInterface&                             vk,
253                                                                                                          vk::VkDevice                                                   device,
254                                                                                                          vk::VkFormat                                                   format,
255                                                                                                          const vk::VkExtent3D&                                  extend,
256                                                                                                          deUint32                                                               levelCount,
257                                                                                                          deUint32                                                               layerCount,
258                                                                                                          vk::Move<vk::VkImage>                                  object);
259
260         Image                                                                                   (const Image &other);   // Not allowed!
261         Image                                            &operator=                     (const Image &other);   // Not allowed!
262
263         de::MovePtr<vk::Allocation>     m_allocation;    
264         vk::Unique<vk::VkImage>         m_object;
265
266         vk::VkFormat                            m_format;
267         vk::VkExtent3D                          m_extent;
268         deUint32                                        m_levelCount;
269         deUint32                                        m_layerCount;
270
271         std::vector<deUint8>            m_pixelAccessData;
272
273         const vk::DeviceInterface&      m_vk;
274         vk::VkDevice                            m_device;
275 };
276
277 void transition2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageAspectFlags aspectMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout);
278
279 void initialTransitionColor2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
280
281 void initialTransitionDepth2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
282
283 void initialTransitionStencil2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
284
285 void initialTransitionDepthStencil2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
286
287 } //Draw
288 } //vkt
289
290 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP