• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTRENDERPASSTESTSUTIL_HPP
2 #define _VKTRENDERPASSTESTSUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2018 The Khronos Group Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief RenderPass test utils
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "vkRef.hpp"
28 #include "vkDefs.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkTypeUtil.hpp"
31 
32 #include <vector>
33 
34 namespace vkt
35 {
36 namespace renderpass
37 {
38 
39 using namespace vk;
40 
41 enum RenderingType
42 {
43 	RENDERING_TYPE_RENDERPASS_LEGACY = 0,
44 	RENDERING_TYPE_RENDERPASS2,
45 	RENDERING_TYPE_DYNAMIC_RENDERING
46 };
47 
48 enum SynchronizationType
49 {
50 	SYNCHRONIZATION_TYPE_LEGACY = 0,
51 	SYNCHRONIZATION_TYPE_SYNCHRONIZATION2,
52 };
53 
54 class AttachmentDescription1 : public vk::VkAttachmentDescription
55 {
56 public:
57 	AttachmentDescription1	(const void*					pNext,
58 							 VkAttachmentDescriptionFlags	flags,
59 							 VkFormat						format,
60 							 VkSampleCountFlagBits			samples,
61 							 VkAttachmentLoadOp				loadOp,
62 							 VkAttachmentStoreOp			storeOp,
63 							 VkAttachmentLoadOp				stencilLoadOp,
64 							 VkAttachmentStoreOp			stencilStoreOp,
65 							 VkImageLayout					initialLayout,
66 							 VkImageLayout					finalLayout);
67 };
68 
69 class AttachmentDescription2 : public vk::VkAttachmentDescription2
70 {
71 public:
72 	AttachmentDescription2	(const void*					pNext,
73 							 VkAttachmentDescriptionFlags	flags,
74 							 VkFormat						format,
75 							 VkSampleCountFlagBits			samples,
76 							 VkAttachmentLoadOp				loadOp,
77 							 VkAttachmentStoreOp			storeOp,
78 							 VkAttachmentLoadOp				stencilLoadOp,
79 							 VkAttachmentStoreOp			stencilStoreOp,
80 							 VkImageLayout					initialLayout,
81 							 VkImageLayout					finalLayout);
82 };
83 
84 class AttachmentReference1 : public vk::VkAttachmentReference
85 {
86 public:
87 	AttachmentReference1	(const void*		pNext,
88 							 deUint32			attachment,
89 							 VkImageLayout		layout,
90 							 VkImageAspectFlags	aspectMask);
91 };
92 
93 class AttachmentReference2 : public vk::VkAttachmentReference2
94 {
95 public:
96 	AttachmentReference2	(const void*		pNext,
97 							 deUint32			attachment,
98 							 VkImageLayout		layout,
99 							 VkImageAspectFlags	aspectMask);
100 };
101 
102 class SubpassDescription1 : public vk::VkSubpassDescription
103 {
104 public:
105 	SubpassDescription1	(const void*						pNext,
106 						 VkSubpassDescriptionFlags			flags,
107 						 VkPipelineBindPoint				pipelineBindPoint,
108 						 deUint32							viewMask,
109 						 deUint32							inputAttachmentCount,
110 						 const VkAttachmentReference*		pInputAttachments,
111 						 deUint32							colorAttachmentCount,
112 						 const VkAttachmentReference*		pColorAttachments,
113 						 const VkAttachmentReference*		pResolveAttachments,
114 						 const VkAttachmentReference*		pDepthStencilAttachment,
115 						 deUint32							preserveAttachmentCount,
116 						 const deUint32*					pPreserveAttachments);
117 };
118 
119 class SubpassDescription2 : public vk::VkSubpassDescription2
120 {
121 public:
122 	SubpassDescription2	(const void*						pNext,
123 						 VkSubpassDescriptionFlags			flags,
124 						 VkPipelineBindPoint				pipelineBindPoint,
125 						 deUint32							viewMask,
126 						 deUint32							inputAttachmentCount,
127 						 const VkAttachmentReference2*		pInputAttachments,
128 						 deUint32							colorAttachmentCount,
129 						 const VkAttachmentReference2*		pColorAttachments,
130 						 const VkAttachmentReference2*		pResolveAttachments,
131 						 const VkAttachmentReference2*		pDepthStencilAttachment,
132 						 deUint32							preserveAttachmentCount,
133 						 const deUint32*					pPreserveAttachments);
134 };
135 
136 class SubpassDependency1 : public vk::VkSubpassDependency
137 {
138 public:
139 	SubpassDependency1	(const void*			pNext,
140 						 deUint32				srcSubpass,
141 						 deUint32				dstSubpass,
142 						 VkPipelineStageFlags	srcStageMask,
143 						 VkPipelineStageFlags	dstStageMask,
144 						 VkAccessFlags			srcAccessMask,
145 						 VkAccessFlags			dstAccessMask,
146 						 VkDependencyFlags		dependencyFlags,
147 						 deInt32				viewOffset);
148 };
149 
150 class SubpassDependency2 : public vk::VkSubpassDependency2
151 {
152 public:
153 	SubpassDependency2	(const void*			pNext,
154 						 deUint32				srcSubpass,
155 						 deUint32				dstSubpass,
156 						 VkPipelineStageFlags	srcStageMask,
157 						 VkPipelineStageFlags	dstStageMask,
158 						 VkAccessFlags			srcAccessMask,
159 						 VkAccessFlags			dstAccessMask,
160 						 VkDependencyFlags		dependencyFlags,
161 						 deInt32				viewOffset);
162 };
163 
164 class RenderPassCreateInfo1 : public VkRenderPassCreateInfo
165 {
166 public:
167 							RenderPassCreateInfo1	(const void*						pNext,
168 													 VkRenderPassCreateFlags			flags,
169 													 deUint32							attachmentCount,
170 													 const VkAttachmentDescription*		pAttachments,
171 													 deUint32							subpassCount,
172 													 const VkSubpassDescription*		pSubpasses,
173 													 deUint32							dependencyCount,
174 													 const VkSubpassDependency*			pDependencies,
175 													 deUint32							correlatedViewMaskCount,
176 													 const deUint32*					pCorrelatedViewMasks);
177 
178 	Move<VkRenderPass>		createRenderPass		(const DeviceInterface& vk,
179 													 VkDevice device) const;
180 };
181 
182 class RenderPassCreateInfo2 : public VkRenderPassCreateInfo2
183 {
184 public:
185 							RenderPassCreateInfo2	(const void*						pNext,
186 													 VkRenderPassCreateFlags			flags,
187 													 deUint32							attachmentCount,
188 													 const VkAttachmentDescription2*	pAttachments,
189 													 deUint32							subpassCount,
190 													 const VkSubpassDescription2*		pSubpasses,
191 													 deUint32							dependencyCount,
192 													 const VkSubpassDependency2*		pDependencies,
193 													 deUint32							correlatedViewMaskCount,
194 													 const deUint32*					pCorrelatedViewMasks);
195 
196 	Move<VkRenderPass>		createRenderPass		(const DeviceInterface& vk,
197 													 VkDevice device) const;
198 };
199 
200 class SubpassBeginInfo1
201 {
202 public:
203 						SubpassBeginInfo1	(const void*		pNext,
204 											 VkSubpassContents	contents);
205 
206 	VkSubpassContents	contents;
207 };
208 
209 class SubpassBeginInfo2 : public VkSubpassBeginInfo
210 {
211 public:
212 						SubpassBeginInfo2	(const void*		pNext,
213 											 VkSubpassContents	contents);
214 };
215 
216 class SubpassEndInfo1
217 {
218 public:
219 						SubpassEndInfo1	(const void*	pNext);
220 };
221 
222 class SubpassEndInfo2 : public VkSubpassEndInfo
223 {
224 public:
225 						SubpassEndInfo2	(const void*	pNext);
226 };
227 
228 class RenderpassSubpass1
229 {
230 public:
231 	typedef SubpassBeginInfo1		SubpassBeginInfo;
232 	typedef SubpassEndInfo1			SubpassEndInfo;
233 
234 	static void	cmdBeginRenderPass	(const DeviceInterface&			vk,
235 									 VkCommandBuffer				cmdBuffer,
236 									 const VkRenderPassBeginInfo*	pRenderPassBegin,
237 									 const SubpassBeginInfo*		pSubpassBeginInfo);
238 
239 	static void	cmdNextSubpass		(const DeviceInterface&			vk,
240 									 VkCommandBuffer				cmdBuffer,
241 									 const SubpassBeginInfo*		pSubpassBeginInfo,
242 									 const SubpassEndInfo*			pSubpassEndInfo);
243 
244 	static void	cmdEndRenderPass	(const DeviceInterface&			vk,
245 									 VkCommandBuffer				cmdBuffer,
246 									 const SubpassEndInfo*			pSubpassEndInfo);
247 };
248 
249 class RenderpassSubpass2
250 {
251 public:
252 	typedef SubpassBeginInfo2		SubpassBeginInfo;
253 	typedef SubpassEndInfo2			SubpassEndInfo;
254 
255 	static void	cmdBeginRenderPass	(const DeviceInterface&			vk,
256 									 VkCommandBuffer				cmdBuffer,
257 									 const VkRenderPassBeginInfo*	pRenderPassBegin,
258 									 const SubpassBeginInfo*		pSubpassBeginInfo);
259 
260 	static void	cmdNextSubpass		(const DeviceInterface&			vk,
261 									 VkCommandBuffer				cmdBuffer,
262 									 const SubpassBeginInfo*		pSubpassBeginInfo,
263 									 const SubpassEndInfo*			pSubpassEndInfo);
264 
265 	static void	cmdEndRenderPass	(const DeviceInterface&			vk,
266 									 VkCommandBuffer				cmdBuffer,
267 									 const SubpassEndInfo*			pSubpassEndInfo);
268 };
269 
270 // For internal to RP/RP2 conversions
271 
272 class AttachmentReference
273 {
274 public:
275 						AttachmentReference	(deUint32			attachment,
276 											 VkImageLayout		layout,
277 											 VkImageAspectFlags	aspectMask = static_cast<VkImageAspectFlags>(0u));
278 
279 	deUint32			getAttachment		(void) const;
280 	VkImageLayout		getImageLayout		(void) const;
281 	VkImageAspectFlags	getAspectMask		(void) const;
282 	void				setImageLayout		(VkImageLayout layout);
283 
284 private:
285 	deUint32			m_attachment;
286 	VkImageLayout		m_layout;
287 	VkImageAspectFlags	m_aspectMask;
288 };
289 
290 class Subpass
291 {
292 public:
293 											Subpass						(VkPipelineBindPoint					pipelineBindPoint,
294 																		VkSubpassDescriptionFlags				flags,
295 																		const std::vector<AttachmentReference>&	inputAttachments,
296 																		const std::vector<AttachmentReference>&	colorAttachments,
297 																		const std::vector<AttachmentReference>&	resolveAttachments,
298 																		AttachmentReference						depthStencilAttachment,
299 																		const std::vector<deUint32>&			preserveAttachments,
300 																		bool									omitBlendState = false);
301 
302 	VkPipelineBindPoint						getPipelineBindPoint		(void) const;
303 	VkSubpassDescriptionFlags				getFlags					(void) const;
304 	const std::vector<AttachmentReference>&	getInputAttachments			(void) const;
305 	const std::vector<AttachmentReference>&	getColorAttachments			(void) const;
306 	const std::vector<AttachmentReference>&	getResolveAttachments		(void) const;
307 	const AttachmentReference&				getDepthStencilAttachment	(void) const;
308 	const std::vector<deUint32>&			getPreserveAttachments		(void) const;
309 	bool									getOmitBlendState			(void) const;
310 
311 private:
312 	VkPipelineBindPoint						m_pipelineBindPoint;
313 	VkSubpassDescriptionFlags				m_flags;
314 
315 	std::vector<AttachmentReference>		m_inputAttachments;
316 	std::vector<AttachmentReference>		m_colorAttachments;
317 	std::vector<AttachmentReference>		m_resolveAttachments;
318 	AttachmentReference						m_depthStencilAttachment;
319 
320 	std::vector<deUint32>					m_preserveAttachments;
321 	bool									m_omitBlendState;
322 };
323 
324 class SubpassDependency
325 {
326 public:
327 							SubpassDependency	(deUint32				srcPass,
328 												 deUint32				dstPass,
329 
330 												 VkPipelineStageFlags	srcStageMask,
331 												 VkPipelineStageFlags	dstStageMask,
332 
333 												 VkAccessFlags			srcAccessMask,
334 												 VkAccessFlags			dstAccessMask,
335 
336 												 VkDependencyFlags		flags);
337 
338 	deUint32				getSrcPass			(void) const;
339 	deUint32				getDstPass			(void) const;
340 
341 	VkPipelineStageFlags	getSrcStageMask		(void) const;
342 	VkPipelineStageFlags	getDstStageMask		(void) const;
343 
344 	VkAccessFlags			getSrcAccessMask	(void) const;
345 	VkAccessFlags			getDstAccessMask	(void) const;
346 
347 	VkDependencyFlags		getFlags			(void) const;
348 
349 private:
350 	deUint32				m_srcPass;
351 	deUint32				m_dstPass;
352 
353 	VkPipelineStageFlags	m_srcStageMask;
354 	VkPipelineStageFlags	m_dstStageMask;
355 
356 	VkAccessFlags			m_srcAccessMask;
357 	VkAccessFlags			m_dstAccessMask;
358 	VkDependencyFlags		m_flags;
359 };
360 
361 class Attachment
362 {
363 public:
364 							Attachment			(VkFormat				format,
365 												 VkSampleCountFlagBits	samples,
366 
367 												 VkAttachmentLoadOp		loadOp,
368 												 VkAttachmentStoreOp	storeOp,
369 
370 												 VkAttachmentLoadOp		stencilLoadOp,
371 												 VkAttachmentStoreOp	stencilStoreOp,
372 
373 												 VkImageLayout			initialLayout,
374 												 VkImageLayout			finalLayout);
375 
376 	VkFormat				getFormat			(void) const;
377 	VkSampleCountFlagBits	getSamples			(void) const;
378 
379 	VkAttachmentLoadOp		getLoadOp			(void) const;
380 	VkAttachmentStoreOp		getStoreOp			(void) const;
381 
382 	VkAttachmentLoadOp		getStencilLoadOp	(void) const;
383 	VkAttachmentStoreOp		getStencilStoreOp	(void) const;
384 
385 	VkImageLayout			getInitialLayout	(void) const;
386 	VkImageLayout			getFinalLayout		(void) const;
387 
388 private:
389 	VkFormat				m_format;
390 	VkSampleCountFlagBits	m_samples;
391 
392 	VkAttachmentLoadOp		m_loadOp;
393 	VkAttachmentStoreOp		m_storeOp;
394 
395 	VkAttachmentLoadOp		m_stencilLoadOp;
396 	VkAttachmentStoreOp		m_stencilStoreOp;
397 
398 	VkImageLayout			m_initialLayout;
399 	VkImageLayout			m_finalLayout;
400 };
401 
402 class RenderPass
403 {
404 public:
405 															RenderPass		(const std::vector<Attachment>&							attachments,
406 																			 const std::vector<Subpass>&							subpasses,
407 																			 const std::vector<SubpassDependency>&					dependencies,
408 																			 const std::vector<VkInputAttachmentAspectReference>	inputAspects = std::vector<VkInputAttachmentAspectReference>());
409 
410 	const std::vector<Attachment>&							getAttachments	(void) const;
411 	const std::vector<Subpass>&								getSubpasses	(void) const;
412 	const std::vector<SubpassDependency>&					getDependencies	(void) const;
413 	const std::vector<VkInputAttachmentAspectReference>&	getInputAspects	(void) const;
414 
415 private:
416 	std::vector<Attachment>									m_attachments;
417 	std::vector<Subpass>									m_subpasses;
418 	std::vector<SubpassDependency>							m_dependencies;
419 	std::vector<VkInputAttachmentAspectReference>			m_inputAspects;
420 };
421 
422 Move<VkRenderPass> createRenderPass (const DeviceInterface&	vk,
423 									 VkDevice				device,
424 									 const RenderPass&		renderPassInfo,
425 									 RenderingType			renderingType,
426 									 SynchronizationType	synchronizationType = SYNCHRONIZATION_TYPE_LEGACY);
427 
428 } // renderpass
429 
430 } // vkt
431 
432 #endif // _VKTRENDERPASSTESTSUTIL_HPP
433