• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * 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
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
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.
21  *
22  *//*!
23  * \file
24  * \brief Image Object Util
25  *//*--------------------------------------------------------------------*/
26 
27 #include "vkDefs.hpp"
28 #include "vkMemUtil.hpp"
29 #include "vkRefUtil.hpp"
30 
31 #include "deSharedPtr.hpp"
32 
33 #include "tcuTexture.hpp"
34 
35 namespace vkt
36 {
37 namespace Draw
38 {
39 
40 class MemoryOp
41 {
42 public:
43 	static void pack	(int					pixelSize,
44 						 int					width,
45 						 int					height,
46 						 int					depth,
47 						 vk::VkDeviceSize		rowPitchOrZero,
48 						 vk::VkDeviceSize		depthPitchOrZero,
49 						 const void *			srcBuffer,
50 						 void *					destBuffer);
51 
52 	static void unpack	(int					pixelSize,
53 						 int					width,
54 						 int					height,
55 						 int					depth,
56 						 vk::VkDeviceSize		rowPitchOrZero,
57 						 vk::VkDeviceSize		depthPitchOrZero,
58 						 const void *			srcBuffer,
59 						 void *					destBuffer);
60 };
61 
62 class Image
63 {
64 public:
65 	static de::SharedPtr<Image> create				(const vk::DeviceInterface& vk, vk::VkDevice device, const vk::VkImageCreateInfo& createInfo, deUint32 queueFamilyIndex);
66 
67 	static de::SharedPtr<Image> createAndAlloc		(const vk::DeviceInterface&				vk,
68 													 vk::VkDevice							device,
69 													 const vk::VkImageCreateInfo&			createInfo,
70 													 vk::Allocator&							allocator,
71 													 deUint32								queueFamilyIndex,
72 													 vk::MemoryRequirement					memoryRequirement = vk::MemoryRequirement::Any);
73 
74 	tcu::ConstPixelBufferAccess readSurface			(vk::VkQueue							queue,
75 													 vk::Allocator&							allocator,
76 													 vk::VkImageLayout						layout,
77 													 vk::VkOffset3D							offset,
78 													 int									width,
79 													 int									height,
80 													 vk::VkImageAspectFlagBits				aspect,
81 													 unsigned int							mipLevel = 0,
82 													 unsigned int							arrayElement = 0);
83 
84 	tcu::ConstPixelBufferAccess readDepth			(vk::VkQueue							queue,
85 													 vk::Allocator&							allocator,
86 													 vk::VkImageLayout						layout,
87 													 vk::VkOffset3D							offset,
88 													 int									width,
89 													 int									height,
90 													 vk::VkImageAspectFlagBits				aspect,
91 													 unsigned int							mipLevel = 0,
92 													 unsigned int							arrayElement = 0);
93 
94 	tcu::ConstPixelBufferAccess readSurface1D		(vk::VkQueue							queue,
95 													 vk::Allocator&							allocator,
96 													 vk::VkImageLayout						layout,
97 													 vk::VkOffset3D							offset,
98 													 int									width,
99 													 vk::VkImageAspectFlagBits				aspect,
100 													 unsigned int							mipLevel = 0,
101 													 unsigned int							arrayElement = 0);
102 
103 	tcu::ConstPixelBufferAccess readVolume			(vk::VkQueue							queue,
104 													 vk::Allocator&							allocator,
105 													 vk::VkImageLayout						layout,
106 													 vk::VkOffset3D							offset,
107 													 int									width,
108 													 int									height,
109 													 int									depth,
110 													 vk::VkImageAspectFlagBits				aspect,
111 													 unsigned int							mipLevel = 0,
112 													 unsigned int							arrayElement = 0);
113 
114 	tcu::ConstPixelBufferAccess readSurfaceLinear	(vk::VkOffset3D							offset,
115 													 int									width,
116 													 int									height,
117 													 int									depth,
118 													 vk::VkImageAspectFlagBits				aspect,
119 													 unsigned int							mipLevel = 0,
120 													 unsigned int							arrayElement = 0);
121 
122 	void						read				(vk::VkQueue							queue,
123 													 vk::Allocator&							allocator,
124 													 vk::VkImageLayout						layout,
125 													 vk::VkOffset3D							offset,
126 													 int									width,
127 													 int									height,
128 													 int									depth,
129 													 unsigned int							mipLevel,
130 													 unsigned int							arrayElement,
131 													 vk::VkImageAspectFlagBits				aspect,
132 													 vk::VkImageType						type,
133 													 void *									data);
134 
135 	void						readUsingBuffer		(vk::VkQueue							queue,
136 													 vk::Allocator&							allocator,
137 													 vk::VkImageLayout						layout,
138 													 vk::VkOffset3D							offset,
139 													 int									width,
140 													 int									height,
141 													 int									depth,
142 													 unsigned int							mipLevel,
143 													 unsigned int							arrayElement,
144 													 vk::VkImageAspectFlagBits				aspect,
145 													 void *									data);
146 
147 	void						readLinear			(vk::VkOffset3D							offset,
148 													 int									width,
149 													 int									height,
150 													 int									depth,
151 													 unsigned int							mipLevel,
152 													 unsigned int							arrayElement,
153 													 vk::VkImageAspectFlagBits				aspect,
154 													 void *									data);
155 
156 	void						uploadVolume		(const tcu::ConstPixelBufferAccess&		access,
157 													 vk::VkQueue							queue,
158 													 vk::Allocator&							allocator,
159 													 vk::VkImageLayout						layout,
160 													 vk::VkOffset3D							offset,
161 													 vk::VkImageAspectFlagBits				aspect,
162 													 unsigned int							mipLevel = 0,
163 													 unsigned int							arrayElement = 0);
164 
165 	void						uploadSurface		 (const tcu::ConstPixelBufferAccess&	access,
166 														vk::VkQueue							queue,
167 														vk::Allocator&						allocator,
168 														vk::VkImageLayout					layout,
169 														vk::VkOffset3D						offset,
170 														vk::VkImageAspectFlagBits			aspect,
171 														unsigned int						mipLevel = 0,
172 														unsigned int						arrayElement = 0);
173 
174 	void						uploadSurface1D		(const tcu::ConstPixelBufferAccess&		access,
175 													 vk::VkQueue							queue,
176 													 vk::Allocator&							allocator,
177 													 vk::VkImageLayout						layout,
178 													 vk::VkOffset3D							offset,
179 													 vk::VkImageAspectFlagBits				aspect,
180 													 unsigned int							mipLevel = 0,
181 													 unsigned int							arrayElement = 0);
182 
183 	void						uploadSurfaceLinear	(const tcu::ConstPixelBufferAccess&		access,
184 													 vk::VkOffset3D							offset,
185 													 int									width,
186 													 int									height,
187 													 int									depth,
188 													 vk::VkImageAspectFlagBits				aspect,
189 													 unsigned int							mipLevel = 0,
190 													 unsigned int							arrayElement = 0);
191 
192 	void						upload				(vk::VkQueue							queue,
193 													 vk::Allocator&							allocator,
194 													 vk::VkImageLayout						layout,
195 													 vk::VkOffset3D							offset,
196 													 int									width,
197 													 int									height,
198 													 int									depth,
199 													 unsigned int							mipLevel,
200 													 unsigned int							arrayElement,
201 													 vk::VkImageAspectFlagBits				aspect,
202 													 vk::VkImageType						type,
203 													 const void *							data);
204 
205 	void						uploadUsingBuffer	(vk::VkQueue							queue,
206 													 vk::Allocator&							allocator,
207 													 vk::VkImageLayout						layout,
208 													 vk::VkOffset3D							offset,
209 													 int									width,
210 													 int									height,
211 													 int									depth,
212 													 unsigned int							mipLevel,
213 													 unsigned int							arrayElement,
214 													 vk::VkImageAspectFlagBits				aspect,
215 													 const void *							data);
216 
217 	void						uploadLinear		(vk::VkOffset3D							offset,
218 													 int									width,
219 													 int									height,
220 													 int									depth,
221 													 unsigned int							mipLevel,
222 													 unsigned int							arrayElement,
223 													 vk::VkImageAspectFlagBits				aspect,
224 													 const void *							data);
225 
226 	de::SharedPtr<Image>		copyToLinearImage	(vk::VkQueue							queue,
227 													 vk::Allocator&							allocator,
228 													 vk::VkImageLayout						layout,
229 													 vk::VkOffset3D							offset,
230 													 int									width,
231 													 int									height,
232 													 int									depth,
233 													 unsigned int							mipLevel,
234 													 unsigned int							arrayElement,
235 													 vk::VkImageAspectFlagBits				aspect,
236 													 vk::VkImageType						type);
237 
getFormat(void) const238 	const vk::VkFormat&			getFormat			(void) const											{ return m_format;		}
object(void) const239 	vk::VkImage					object				(void) const											{ return *m_object;		}
240 	void						bindMemory			(de::MovePtr<vk::Allocation>			allocation);
getBoundMemory(void) const241 	vk::Allocation				getBoundMemory		(void) const											{ return *m_allocation; }
242 
243 private:
244 								Image				(const vk::DeviceInterface&				vk,
245 													 vk::VkDevice							device,
246 													 deUint32								queueFamilyIndex,
247 													 vk::VkFormat							format,
248 													 const vk::VkExtent3D&					extend,
249 													 deUint32								levelCount,
250 													 deUint32								layerCount,
251 													 vk::Move<vk::VkImage>					object);
252 
253 	Image											(const Image& other);	// Not allowed!
254 	Image&						operator=			(const Image& other);	// Not allowed!
255 
256 	de::MovePtr<vk::Allocation>	m_allocation;
257 	vk::Unique<vk::VkImage>		m_object;
258 
259 	deUint32					m_queueFamilyIndex;
260 
261 	vk::VkFormat				m_format;
262 	vk::VkExtent3D				m_extent;
263 	deUint32					m_levelCount;
264 	deUint32					m_layerCount;
265 
266 	std::vector<deUint8>		m_pixelAccessData;
267 
268 	const vk::DeviceInterface&	m_vk;
269 	vk::VkDevice				m_device;
270 };
271 
272 void transition2DImage (const vk::DeviceInterface&	vk,
273 						vk::VkCommandBuffer			cmdBuffer,
274 						vk::VkImage					image,
275 						vk::VkImageAspectFlags		aspectMask,
276 						vk::VkImageLayout			oldLayout,
277 						vk::VkImageLayout			newLayout,
278 						vk::VkAccessFlags			srcAccessMask,
279 						vk::VkAccessFlags			dstAccessMask,
280 						vk::VkPipelineStageFlags	srcStageMask,
281 						vk::VkPipelineStageFlags	dstStageMask);
282 
283 void initialTransitionColor2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout,
284 									vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask);
285 
286 void initialTransitionDepth2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout,
287 									vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask);
288 
289 void initialTransitionStencil2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout,
290 									  vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask);
291 
292 void initialTransitionDepthStencil2DImage (const vk::DeviceInterface&	vk,
293 										   vk::VkCommandBuffer			cmdBuffer,
294 										   vk::VkImage					image,
295 										   vk::VkImageLayout			layout,
296 										   vk::VkAccessFlags			dstAccessMask,
297 										   vk::VkPipelineStageFlags		dstStageMask);
298 
299 } // Draw
300 } // vkt
301 
302 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP
303