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