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, deUint32 queueFamilyIndex);
67 static de::SharedPtr<Image> createAndAlloc (const vk::DeviceInterface& vk,
69 const vk::VkImageCreateInfo& createInfo,
70 vk::Allocator& allocator,
71 deUint32 queueFamilyIndex,
72 vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any);
74 tcu::ConstPixelBufferAccess readSurface (vk::VkQueue queue,
75 vk::Allocator& allocator,
76 vk::VkImageLayout layout,
77 vk::VkOffset3D offset,
80 vk::VkImageAspectFlagBits aspect,
81 unsigned int mipLevel = 0,
82 unsigned int arrayElement = 0);
84 tcu::ConstPixelBufferAccess readSurface1D (vk::VkQueue queue,
85 vk::Allocator& allocator,
86 vk::VkImageLayout layout,
87 vk::VkOffset3D offset,
89 vk::VkImageAspectFlagBits aspect,
90 unsigned int mipLevel = 0,
91 unsigned int arrayElement = 0);
93 tcu::ConstPixelBufferAccess readVolume (vk::VkQueue queue,
94 vk::Allocator& allocator,
95 vk::VkImageLayout layout,
96 vk::VkOffset3D offset,
100 vk::VkImageAspectFlagBits aspect,
101 unsigned int mipLevel = 0,
102 unsigned int arrayElement = 0);
104 tcu::ConstPixelBufferAccess readSurfaceLinear (vk::VkOffset3D offset,
108 vk::VkImageAspectFlagBits aspect,
109 unsigned int mipLevel = 0,
110 unsigned int arrayElement = 0);
112 void read (vk::VkQueue queue,
113 vk::Allocator& allocator,
114 vk::VkImageLayout layout,
115 vk::VkOffset3D offset,
119 unsigned int mipLevel,
120 unsigned int arrayElement,
121 vk::VkImageAspectFlagBits aspect,
122 vk::VkImageType type,
125 void readUsingBuffer (vk::VkQueue queue,
126 vk::Allocator& allocator,
127 vk::VkImageLayout layout,
128 vk::VkOffset3D offset,
132 unsigned int mipLevel,
133 unsigned int arrayElement,
134 vk::VkImageAspectFlagBits aspect,
137 void readLinear (vk::VkOffset3D offset,
141 unsigned int mipLevel,
142 unsigned int arrayElement,
143 vk::VkImageAspectFlagBits aspect,
146 void uploadVolume (const tcu::ConstPixelBufferAccess& access,
148 vk::Allocator& allocator,
149 vk::VkImageLayout layout,
150 vk::VkOffset3D offset,
151 vk::VkImageAspectFlagBits aspect,
152 unsigned int mipLevel = 0,
153 unsigned int arrayElement = 0);
155 void uploadSurface (const tcu::ConstPixelBufferAccess& access,
157 vk::Allocator& allocator,
158 vk::VkImageLayout layout,
159 vk::VkOffset3D offset,
160 vk::VkImageAspectFlagBits aspect,
161 unsigned int mipLevel = 0,
162 unsigned int arrayElement = 0);
164 void uploadSurface1D (const tcu::ConstPixelBufferAccess& access,
166 vk::Allocator& allocator,
167 vk::VkImageLayout layout,
168 vk::VkOffset3D offset,
169 vk::VkImageAspectFlagBits aspect,
170 unsigned int mipLevel = 0,
171 unsigned int arrayElement = 0);
173 void uploadSurfaceLinear (const tcu::ConstPixelBufferAccess& access,
174 vk::VkOffset3D offset,
178 vk::VkImageAspectFlagBits aspect,
179 unsigned int mipLevel = 0,
180 unsigned int arrayElement = 0);
182 void upload (vk::VkQueue queue,
183 vk::Allocator& allocator,
184 vk::VkImageLayout layout,
185 vk::VkOffset3D offset,
189 unsigned int mipLevel,
190 unsigned int arrayElement,
191 vk::VkImageAspectFlagBits aspect,
192 vk::VkImageType type,
195 void uploadUsingBuffer (vk::VkQueue queue,
196 vk::Allocator& allocator,
197 vk::VkImageLayout layout,
198 vk::VkOffset3D offset,
202 unsigned int mipLevel,
203 unsigned int arrayElement,
204 vk::VkImageAspectFlagBits aspect,
207 void uploadLinear (vk::VkOffset3D offset,
211 unsigned int mipLevel,
212 unsigned int arrayElement,
213 vk::VkImageAspectFlagBits aspect,
216 de::SharedPtr<Image> copyToLinearImage (vk::VkQueue queue,
217 vk::Allocator& allocator,
218 vk::VkImageLayout layout,
219 vk::VkOffset3D offset,
223 unsigned int mipLevel,
224 unsigned int arrayElement,
225 vk::VkImageAspectFlagBits aspect,
226 vk::VkImageType type);
228 const vk::VkFormat& getFormat (void) const { return m_format; }
229 vk::VkImage object (void) const { return *m_object; }
230 void bindMemory (de::MovePtr<vk::Allocation> allocation);
231 vk::Allocation getBoundMemory (void) const { return *m_allocation; }
234 Image (const vk::DeviceInterface& vk,
236 deUint32 queueFamilyIndex,
238 const vk::VkExtent3D& extend,
241 vk::Move<vk::VkImage> object);
243 Image (const Image& other); // Not allowed!
244 Image& operator= (const Image& other); // Not allowed!
246 de::MovePtr<vk::Allocation> m_allocation;
247 vk::Unique<vk::VkImage> m_object;
249 deUint32 m_queueFamilyIndex;
251 vk::VkFormat m_format;
252 vk::VkExtent3D m_extent;
253 deUint32 m_levelCount;
254 deUint32 m_layerCount;
256 std::vector<deUint8> m_pixelAccessData;
258 const vk::DeviceInterface& m_vk;
259 vk::VkDevice m_device;
262 void transition2DImage (const vk::DeviceInterface& vk,
263 vk::VkCommandBuffer cmdBuffer,
265 vk::VkImageAspectFlags aspectMask,
266 vk::VkImageLayout oldLayout,
267 vk::VkImageLayout newLayout,
268 vk::VkAccessFlags srcAccessMask,
269 vk::VkAccessFlags dstAccessMask,
270 vk::VkPipelineStageFlags srcStageMask,
271 vk::VkPipelineStageFlags dstStageMask);
273 void initialTransitionColor2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout,
274 vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask);
276 void initialTransitionDepth2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout,
277 vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask);
279 void initialTransitionStencil2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout,
280 vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask);
282 void initialTransitionDepthStencil2DImage (const vk::DeviceInterface& vk,
283 vk::VkCommandBuffer cmdBuffer,
285 vk::VkImageLayout layout,
286 vk::VkAccessFlags dstAccessMask,
287 vk::VkPipelineStageFlags dstStageMask);
292 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP