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 * 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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * \brief Image Object Util
25 *//*--------------------------------------------------------------------*/
28 #include "vkMemUtil.hpp"
29 #include "vkRefUtil.hpp"
31 #include "deSharedPtr.hpp"
33 #include "tcuTexture.hpp"
43 static void pack (int pixelSize,
47 vk::VkDeviceSize rowPitchOrZero,
48 vk::VkDeviceSize depthPitchOrZero,
49 const void * srcBuffer,
52 static void unpack (int pixelSize,
56 vk::VkDeviceSize rowPitchOrZero,
57 vk::VkDeviceSize depthPitchOrZero,
58 const void * srcBuffer,
65 static de::SharedPtr<Image> create (const vk::DeviceInterface& vk, vk::VkDevice device, const vk::VkImageCreateInfo& createInfo);
67 static de::SharedPtr<Image> createAndAlloc (const vk::DeviceInterface& vk,
69 const vk::VkImageCreateInfo& createInfo,
70 vk::Allocator& allocator,
71 vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any);
73 tcu::ConstPixelBufferAccess readSurface (vk::VkQueue queue,
74 vk::Allocator& allocator,
75 vk::VkImageLayout layout,
76 vk::VkOffset3D offset,
79 vk::VkImageAspectFlagBits aspect,
80 unsigned int mipLevel = 0,
81 unsigned int arrayElement = 0);
83 tcu::ConstPixelBufferAccess readSurface1D (vk::VkQueue queue,
84 vk::Allocator& allocator,
85 vk::VkImageLayout layout,
86 vk::VkOffset3D offset,
88 vk::VkImageAspectFlagBits aspect,
89 unsigned int mipLevel = 0,
90 unsigned int arrayElement = 0);
92 tcu::ConstPixelBufferAccess readVolume (vk::VkQueue queue,
93 vk::Allocator& allocator,
94 vk::VkImageLayout layout,
95 vk::VkOffset3D offset,
99 vk::VkImageAspectFlagBits aspect,
100 unsigned int mipLevel = 0,
101 unsigned int arrayElement = 0);
103 tcu::ConstPixelBufferAccess readSurfaceLinear (vk::VkOffset3D offset,
107 vk::VkImageAspectFlagBits aspect,
108 unsigned int mipLevel = 0,
109 unsigned int arrayElement = 0);
111 void read (vk::VkQueue queue,
112 vk::Allocator& allocator,
113 vk::VkImageLayout layout,
114 vk::VkOffset3D offset,
118 unsigned int mipLevel,
119 unsigned int arrayElement,
120 vk::VkImageAspectFlagBits aspect,
121 vk::VkImageType type,
124 void readUsingBuffer (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,
136 void readLinear (vk::VkOffset3D offset,
140 unsigned int mipLevel,
141 unsigned int arrayElement,
142 vk::VkImageAspectFlagBits aspect,
145 void uploadVolume (const tcu::ConstPixelBufferAccess& access,
147 vk::Allocator& allocator,
148 vk::VkImageLayout layout,
149 vk::VkOffset3D offset,
150 vk::VkImageAspectFlagBits aspect,
151 unsigned int mipLevel = 0,
152 unsigned int arrayElement = 0);
154 void uploadSurface (const tcu::ConstPixelBufferAccess& access,
156 vk::Allocator& allocator,
157 vk::VkImageLayout layout,
158 vk::VkOffset3D offset,
159 vk::VkImageAspectFlagBits aspect,
160 unsigned int mipLevel = 0,
161 unsigned int arrayElement = 0);
163 void uploadSurface1D (const tcu::ConstPixelBufferAccess& access,
165 vk::Allocator& allocator,
166 vk::VkImageLayout layout,
167 vk::VkOffset3D offset,
168 vk::VkImageAspectFlagBits aspect,
169 unsigned int mipLevel = 0,
170 unsigned int arrayElement = 0);
172 void uploadSurfaceLinear (const tcu::ConstPixelBufferAccess& access,
173 vk::VkOffset3D offset,
177 vk::VkImageAspectFlagBits aspect,
178 unsigned int mipLevel = 0,
179 unsigned int arrayElement = 0);
181 void upload (vk::VkQueue queue,
182 vk::Allocator& allocator,
183 vk::VkImageLayout layout,
184 vk::VkOffset3D offset,
188 unsigned int mipLevel,
189 unsigned int arrayElement,
190 vk::VkImageAspectFlagBits aspect,
191 vk::VkImageType type,
194 void uploadUsingBuffer (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,
206 void uploadLinear (vk::VkOffset3D offset,
210 unsigned int mipLevel,
211 unsigned int arrayElement,
212 vk::VkImageAspectFlagBits aspect,
215 de::SharedPtr<Image> copyToLinearImage (vk::VkQueue queue,
216 vk::Allocator& allocator,
217 vk::VkImageLayout layout,
218 vk::VkOffset3D offset,
222 unsigned int mipLevel,
223 unsigned int arrayElement,
224 vk::VkImageAspectFlagBits aspect,
225 vk::VkImageType type);
227 const vk::VkFormat& getFormat (void) const { return m_format; }
228 vk::VkImage object (void) const { return *m_object; }
229 void bindMemory (de::MovePtr<vk::Allocation> allocation);
230 vk::Allocation getBoundMemory (void) const { return *m_allocation; }
233 Image (const vk::DeviceInterface& vk,
236 const vk::VkExtent3D& extend,
239 vk::Move<vk::VkImage> object);
241 Image (const Image& other); // Not allowed!
242 Image& operator= (const Image& other); // Not allowed!
244 de::MovePtr<vk::Allocation> m_allocation;
245 vk::Unique<vk::VkImage> m_object;
247 vk::VkFormat m_format;
248 vk::VkExtent3D m_extent;
249 deUint32 m_levelCount;
250 deUint32 m_layerCount;
252 std::vector<deUint8> m_pixelAccessData;
254 const vk::DeviceInterface& m_vk;
255 vk::VkDevice m_device;
258 void transition2DImage (const vk::DeviceInterface& vk,
259 vk::VkCommandBuffer cmdBuffer,
261 vk::VkImageAspectFlags aspectMask,
262 vk::VkImageLayout oldLayout,
263 vk::VkImageLayout newLayout,
264 vk::VkAccessFlags srcAccessMask = 0,
265 vk::VkAccessFlags dstAccessMask = 0);
267 void initialTransitionColor2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
269 void initialTransitionDepth2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
271 void initialTransitionStencil2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout);
273 void initialTransitionDepthStencil2DImage (const vk::DeviceInterface& vk,
274 vk::VkCommandBuffer cmdBuffer,
276 vk::VkImageLayout layout,
277 vk::VkAccessFlags srcAccessMask = 0,
278 vk::VkAccessFlags dstAccessMask = 0);
283 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP