1 #ifndef _VKTDRAWIMAGEOBJECTUTIL_HPP
2 #define _VKTDRAWIMAGEOBJECTUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 The Khronos Group Inc.
8 * Copyright (c) 2015 Intel Corporation
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:
18 * The above copyright notice(s) and this permission notice shall be included
19 * in all copies or substantial portions of the Materials.
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.
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.
35 * \brief Image Object Util
36 *//*--------------------------------------------------------------------*/
39 #include "vkMemUtil.hpp"
40 #include "vkRefUtil.hpp"
42 #include "deSharedPtr.hpp"
44 #include "tcuTexture.hpp"
54 static void pack (int pixelSize,
58 vk::VkDeviceSize rowPitch,
59 vk::VkDeviceSize depthPitch,
60 const void * srcBuffer,
63 static void unpack (int pixelSize,
67 vk::VkDeviceSize rowPitch,
68 vk::VkDeviceSize depthPitch,
69 const void * srcBuffer,
77 static de::SharedPtr<Image> create (const vk::DeviceInterface &vk, vk::VkDevice device, const vk::VkImageCreateInfo &createInfo);
79 static de::SharedPtr<Image> createAndAlloc (const vk::DeviceInterface& vk,
81 const vk::VkImageCreateInfo& createInfo,
82 vk::Allocator& allocator,
83 vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any);
85 tcu::ConstPixelBufferAccess readSurface (vk::VkQueue queue,
86 vk::Allocator& allocator,
87 vk::VkImageLayout layout,
88 vk::VkOffset3D offset,
91 vk::VkImageAspectFlagBits aspect,
92 unsigned int mipLevel = 0,
93 unsigned int arrayElement = 0);
95 tcu::ConstPixelBufferAccess readSurface1D (vk::VkQueue queue,
96 vk::Allocator& allocator,
97 vk::VkImageLayout layout,
98 vk::VkOffset3D offset,
100 vk::VkImageAspectFlagBits aspect,
101 unsigned int mipLevel = 0,
102 unsigned int arrayElement = 0);
104 tcu::ConstPixelBufferAccess readVolume (vk::VkQueue queue,
105 vk::Allocator& allocator,
106 vk::VkImageLayout layout,
107 vk::VkOffset3D offset,
111 vk::VkImageAspectFlagBits aspect,
112 unsigned int mipLevel = 0,
113 unsigned int arrayElement = 0);
116 tcu::ConstPixelBufferAccess readSurfaceLinear (vk::VkOffset3D offset,
120 vk::VkImageAspectFlagBits aspect,
121 unsigned int mipLevel = 0,
122 unsigned int arrayElement = 0);
124 void read (vk::VkQueue queue,
125 vk::Allocator& allocator,
126 vk::VkImageLayout layout,
127 vk::VkOffset3D offset,
131 unsigned int mipLevel,
132 unsigned int arrayElement,
133 vk::VkImageAspectFlagBits aspect,
134 vk::VkImageType type,
137 void readUsingBuffer (vk::VkQueue queue,
138 vk::Allocator& allocator,
139 vk::VkImageLayout layout,
140 vk::VkOffset3D offset,
144 unsigned int mipLevel,
145 unsigned int arrayElement,
146 vk::VkImageAspectFlagBits aspect,
149 void readLinear (vk::VkOffset3D offset,
153 unsigned int mipLevel,
154 unsigned int arrayElement,
155 vk::VkImageAspectFlagBits aspect,
158 void uploadVolume (const tcu::ConstPixelBufferAccess& access,
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);
167 void uploadSurface (const tcu::ConstPixelBufferAccess& access,
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);
176 void uploadSurface1D (const tcu::ConstPixelBufferAccess& access,
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);
185 void uploadSurfaceLinear (const tcu::ConstPixelBufferAccess& access,
186 vk::VkOffset3D offset,
190 vk::VkImageAspectFlagBits aspect,
191 unsigned int mipLevel = 0,
192 unsigned int arrayElement = 0);
194 void upload (vk::VkQueue queue,
195 vk::Allocator& allocator,
196 vk::VkImageLayout layout,
197 vk::VkOffset3D offset,
201 unsigned int mipLevel,
202 unsigned int arrayElement,
203 vk::VkImageAspectFlagBits aspect,
204 vk::VkImageType type,
207 void uploadUsingBuffer (vk::VkQueue queue,
208 vk::Allocator& allocator,
209 vk::VkImageLayout layout,
210 vk::VkOffset3D offset,
214 unsigned int mipLevel,
215 unsigned int arrayElement,
216 vk::VkImageAspectFlagBits aspect,
219 void uploadLinear (vk::VkOffset3D offset,
223 unsigned int mipLevel,
224 unsigned int arrayElement,
225 vk::VkImageAspectFlagBits aspect,
228 de::SharedPtr<Image> copyToLinearImage (vk::VkQueue queue,
229 vk::Allocator& allocator,
230 vk::VkImageLayout layout,
231 vk::VkOffset3D offset,
235 unsigned int mipLevel,
236 unsigned int arrayElement,
237 vk::VkImageAspectFlagBits aspect,
238 vk::VkImageType type);
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; }
246 vk::VkDeviceSize getPixelOffset (vk::VkOffset3D offset,
247 vk::VkDeviceSize rowPitch,
248 vk::VkDeviceSize depthPitch,
249 unsigned int mipLevel,
250 unsigned int arrayElement);
252 Image (const vk::DeviceInterface& vk,
255 const vk::VkExtent3D& extend,
258 vk::Move<vk::VkImage> object);
260 Image (const Image &other); // Not allowed!
261 Image &operator= (const Image &other); // Not allowed!
263 de::MovePtr<vk::Allocation> m_allocation;
264 vk::Unique<vk::VkImage> m_object;
266 vk::VkFormat m_format;
267 vk::VkExtent3D m_extent;
268 deUint32 m_levelCount;
269 deUint32 m_layerCount;
271 std::vector<deUint8> m_pixelAccessData;
273 const vk::DeviceInterface& m_vk;
274 vk::VkDevice m_device;
277 void transition2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageAspectFlags aspectMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout);
279 void initialTransitionColor2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
281 void initialTransitionDepth2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
283 void initialTransitionStencil2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
285 void initialTransitionDepthStencil2DImage (const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
290 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP