1#ifndef _VKTDRAWCREATEINFOUTIL_HPP
2#define _VKTDRAWCREATEINFOUTIL_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 CreateInfo utilities
25 *//*--------------------------------------------------------------------*/
26
27#include "vkDefs.hpp"
28#include "tcuVector.hpp"
29#include "deSharedPtr.hpp"
30#include <vector>
31
32namespace vkt
33{
34namespace Draw
35{
36
37class ImageSubresourceRange : public vk::VkImageSubresourceRange
38{
39public:
40	ImageSubresourceRange		(vk::VkImageAspectFlags	aspectMask,
41								 deUint32				baseMipLevel	= 0,
42								 deUint32				levelCount		= 1,
43								 deUint32				baseArrayLayer	= 0,
44								 deUint32				layerCount		= 1);
45};
46
47class ComponentMapping : public vk::VkComponentMapping
48{
49public:
50	ComponentMapping			(vk::VkComponentSwizzle r = vk::VK_COMPONENT_SWIZZLE_R,
51								 vk::VkComponentSwizzle g = vk::VK_COMPONENT_SWIZZLE_G,
52								 vk::VkComponentSwizzle b = vk::VK_COMPONENT_SWIZZLE_B,
53								 vk::VkComponentSwizzle a = vk::VK_COMPONENT_SWIZZLE_A);
54};
55
56class ImageViewCreateInfo : public vk::VkImageViewCreateInfo
57{
58public:
59	ImageViewCreateInfo			(vk::VkImage						image,
60								 vk::VkImageViewType				viewType,
61								 vk::VkFormat						format,
62								 const vk::VkImageSubresourceRange&	subresourceRange,
63								 const vk::VkComponentMapping&		components			= ComponentMapping(),
64								 vk::VkImageViewCreateFlags			flags				= 0);
65
66	ImageViewCreateInfo			(vk::VkImage						image,
67								 vk::VkImageViewType				viewType,
68								 vk::VkFormat						format,
69								 const vk::VkComponentMapping&		components			= ComponentMapping(),
70								 vk::VkImageViewCreateFlags			flags				= 0);
71};
72
73class BufferViewCreateInfo : public vk::VkBufferViewCreateInfo
74{
75public:
76	BufferViewCreateInfo		 (vk::VkBuffer		buffer,
77								  vk::VkFormat		format,
78								  vk::VkDeviceSize	offset,
79								  vk::VkDeviceSize	range);
80};
81
82class BufferCreateInfo : public vk::VkBufferCreateInfo
83{
84public:
85	BufferCreateInfo			(vk::VkDeviceSize			size,
86								 vk::VkBufferCreateFlags	usage,
87								 vk::VkSharingMode			sharingMode				= vk::VK_SHARING_MODE_EXCLUSIVE,
88								 deUint32					queueFamilyIndexCount	= 0,
89								 const deUint32*			pQueueFamilyIndices		= DE_NULL,
90								 vk::VkBufferCreateFlags	flags					= 0);
91
92	BufferCreateInfo			(const BufferCreateInfo&	other);
93	BufferCreateInfo& operator=	(const BufferCreateInfo&	other);
94
95private:
96	std::vector<deUint32> m_queueFamilyIndices;
97};
98
99class ImageCreateInfo : public vk::VkImageCreateInfo
100{
101public:
102	ImageCreateInfo				(vk::VkImageType			imageType,
103								 vk::VkFormat				format,
104								 vk::VkExtent3D				extent,
105								 deUint32					mipLevels,
106								 deUint32					arrayLayers,
107								 vk::VkSampleCountFlagBits	samples,
108								 vk::VkImageTiling			tiling,
109								 vk::VkImageUsageFlags		usage,
110								 vk::VkSharingMode			sharingMode				= vk::VK_SHARING_MODE_EXCLUSIVE,
111								 deUint32					queueFamilyIndexCount	= 0,
112								 const deUint32*			pQueueFamilyIndices		= DE_NULL,
113								 vk::VkImageCreateFlags		flags					= 0,
114								 vk::VkImageLayout			initialLayout			= vk::VK_IMAGE_LAYOUT_UNDEFINED);
115
116private:
117	ImageCreateInfo				(const ImageCreateInfo&		other);
118	ImageCreateInfo& operator=	(const ImageCreateInfo&		other);
119
120	std::vector<deUint32> m_queueFamilyIndices;
121};
122
123class FramebufferCreateInfo : public vk::VkFramebufferCreateInfo
124{
125public:
126	FramebufferCreateInfo		(vk::VkRenderPass						renderPass,
127								 const std::vector<vk::VkImageView>&	attachments,
128								 deUint32								width,
129								 deUint32								height,
130								 deUint32								layers);
131};
132
133class AttachmentDescription : public vk::VkAttachmentDescription
134{
135public:
136	AttachmentDescription	(vk::VkFormat				format,
137							 vk::VkSampleCountFlagBits	samples,
138							 vk::VkAttachmentLoadOp		loadOp,
139							 vk::VkAttachmentStoreOp	storeOp,
140							 vk::VkAttachmentLoadOp		stencilLoadOp,
141							 vk::VkAttachmentStoreOp	stencilStoreOp,
142							 vk::VkImageLayout			initialLayout,
143							 vk::VkImageLayout			finalLayout);
144
145	AttachmentDescription	(const vk::VkAttachmentDescription &);
146};
147
148class AttachmentReference : public vk::VkAttachmentReference
149{
150public:
151	AttachmentReference		(deUint32 attachment, vk::VkImageLayout layout);
152	AttachmentReference		(void);
153};
154
155class SubpassDescription : public vk::VkSubpassDescription
156{
157public:
158	SubpassDescription				(vk::VkPipelineBindPoint			pipelineBindPoint,
159									 vk::VkSubpassDescriptionFlags		flags,
160									 deUint32							inputAttachmentCount,
161									 const vk::VkAttachmentReference*	inputAttachments,
162									 deUint32							colorAttachmentCount,
163									 const vk::VkAttachmentReference*	colorAttachments,
164									 const vk::VkAttachmentReference*	resolveAttachments,
165									 vk::VkAttachmentReference			depthStencilAttachment,
166									 deUint32							preserveAttachmentCount,
167									 const deUint32*					preserveAttachments);
168
169	SubpassDescription				(const vk::VkSubpassDescription&	other);
170	SubpassDescription				(const SubpassDescription&			other);
171	SubpassDescription& operator=	(const SubpassDescription&			other);
172
173private:
174	std::vector<vk::VkAttachmentReference>	m_inputAttachments;
175	std::vector<vk::VkAttachmentReference>	m_colorAttachments;
176	std::vector<vk::VkAttachmentReference>	m_resolveAttachments;
177	std::vector<deUint32>					m_preserveAttachments;
178
179	vk::VkAttachmentReference				m_depthStencilAttachment;
180};
181
182class SubpassDependency : public vk::VkSubpassDependency
183{
184public:
185	SubpassDependency (	deUint32					srcSubpass,
186						deUint32					dstSubpass,
187						vk::VkPipelineStageFlags	srcStageMask,
188						vk::VkPipelineStageFlags	dstStageMask,
189						vk::VkAccessFlags			srcAccessMask,
190						vk::VkAccessFlags			dstAccessMask,
191						vk::VkDependencyFlags		dependencyFlags);
192
193	SubpassDependency (const vk::VkSubpassDependency& other);
194};
195
196class RenderPassCreateInfo : public vk::VkRenderPassCreateInfo
197{
198public:
199	RenderPassCreateInfo (const std::vector<vk::VkAttachmentDescription>&	attachments,
200						  const std::vector<vk::VkSubpassDescription>&		subpasses,
201						  const std::vector<vk::VkSubpassDependency>&		dependiences		= std::vector<vk::VkSubpassDependency>());
202
203	RenderPassCreateInfo (deUint32											attachmentCount	= 0,
204						  const vk::VkAttachmentDescription*				pAttachments	= DE_NULL,
205						  deUint32											subpassCount	= 0,
206						  const vk::VkSubpassDescription*					pSubpasses		= DE_NULL,
207						  deUint32											dependencyCount	= 0,
208						  const vk::VkSubpassDependency*					pDependiences	= DE_NULL);
209
210	void addAttachment	(vk::VkAttachmentDescription						attachment);
211	void addSubpass		(vk::VkSubpassDescription							subpass);
212	void addDependency	(vk::VkSubpassDependency							dependency);
213
214private:
215	std::vector<AttachmentDescription>			m_attachments;
216	std::vector<SubpassDescription>				m_subpasses;
217	std::vector<SubpassDependency>				m_dependiences;
218
219	std::vector<vk::VkAttachmentDescription>	m_attachmentsStructs;
220	std::vector<vk::VkSubpassDescription>		m_subpassesStructs;
221	std::vector<vk::VkSubpassDependency>		m_dependiencesStructs;
222
223	RenderPassCreateInfo			(const RenderPassCreateInfo &other); //Not allowed!
224	RenderPassCreateInfo& operator= (const RenderPassCreateInfo &other); //Not allowed!
225};
226
227class RenderPassBeginInfo : public vk::VkRenderPassBeginInfo
228{
229public:
230	RenderPassBeginInfo (vk::VkRenderPass						renderPass,
231						 vk::VkFramebuffer						framebuffer,
232						 vk::VkRect2D							renderArea,
233						 const std::vector<vk::VkClearValue>&	clearValues = std::vector<vk::VkClearValue>());
234
235private:
236	std::vector<vk::VkClearValue> m_clearValues;
237
238	RenderPassBeginInfo				(const RenderPassBeginInfo&	other); //Not allowed!
239	RenderPassBeginInfo& operator=	(const RenderPassBeginInfo&	other); //Not allowed!
240};
241
242class CmdPoolCreateInfo : public vk::VkCommandPoolCreateInfo
243{
244public:
245	CmdPoolCreateInfo (deUint32						queueFamilyIndex,
246					   vk::VkCommandPoolCreateFlags flags				= vk::VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
247};
248
249class CmdBufferBeginInfo : public vk::VkCommandBufferBeginInfo
250{
251public:
252	CmdBufferBeginInfo (vk::VkCommandBufferUsageFlags		flags					= 0);
253};
254
255class DescriptorPoolSize : public vk::VkDescriptorPoolSize
256{
257public:
258	DescriptorPoolSize (vk::VkDescriptorType _type, deUint32 _descriptorCount)
259	{
260		type			= _type;
261		descriptorCount = _descriptorCount;
262	}
263};
264
265class DescriptorPoolCreateInfo : public vk::VkDescriptorPoolCreateInfo
266{
267public:
268	DescriptorPoolCreateInfo (const std::vector<vk::VkDescriptorPoolSize>&	poolSizeCounts,
269							  vk::VkDescriptorPoolCreateFlags				flags,
270							  deUint32										maxSets);
271
272	DescriptorPoolCreateInfo& addDescriptors (vk::VkDescriptorType type, deUint32 count);
273
274private:
275	std::vector<vk::VkDescriptorPoolSize> m_poolSizeCounts;
276};
277
278class DescriptorSetLayoutCreateInfo : public vk::VkDescriptorSetLayoutCreateInfo
279{
280public:
281	DescriptorSetLayoutCreateInfo (deUint32 bindingCount, const vk::VkDescriptorSetLayoutBinding* pBindings);
282};
283
284class PipelineLayoutCreateInfo : public vk::VkPipelineLayoutCreateInfo
285{
286public:
287	PipelineLayoutCreateInfo (deUint32										descriptorSetCount,
288							  const vk::VkDescriptorSetLayout*				pSetLayouts,
289							  deUint32										pushConstantRangeCount	= 0,
290							  const vk::VkPushConstantRange*				pPushConstantRanges		= DE_NULL);
291
292	PipelineLayoutCreateInfo (const std::vector<vk::VkDescriptorSetLayout>&	setLayouts				= std::vector<vk::VkDescriptorSetLayout>(),
293							  deUint32										pushConstantRangeCount	= 0,
294							  const vk::VkPushConstantRange*				pPushConstantRanges		= DE_NULL);
295
296private:
297	std::vector<vk::VkDescriptorSetLayout>	m_setLayouts;
298	std::vector<vk::VkPushConstantRange>	m_pushConstantRanges;
299};
300
301class PipelineCreateInfo : public vk::VkGraphicsPipelineCreateInfo
302{
303public:
304	class VertexInputState : public vk::VkPipelineVertexInputStateCreateInfo
305	{
306	public:
307		VertexInputState (deUint32										vertexBindingDescriptionCount	= 0,
308						  const vk::VkVertexInputBindingDescription*	pVertexBindingDescriptions		= NULL,
309						  deUint32										vertexAttributeDescriptionCount	= 0,
310						  const vk::VkVertexInputAttributeDescription*	pVertexAttributeDescriptions	= NULL);
311	};
312
313	class InputAssemblerState : public vk::VkPipelineInputAssemblyStateCreateInfo
314	{
315	public:
316		InputAssemblerState (vk::VkPrimitiveTopology topology, vk::VkBool32 primitiveRestartEnable = false);
317	};
318
319	class TessellationState : public vk::VkPipelineTessellationStateCreateInfo
320	{
321	public:
322		TessellationState (deUint32 patchControlPoints = 0);
323	};
324
325	class ViewportState : public vk::VkPipelineViewportStateCreateInfo
326	{
327	public:
328		ViewportState				(deUint32						viewportCount,
329									 std::vector<vk::VkViewport>	viewports		= std::vector<vk::VkViewport>(0),
330									 std::vector<vk::VkRect2D>		scissors		= std::vector<vk::VkRect2D>(0));
331
332		ViewportState				(const ViewportState&			other);
333		ViewportState& operator=	(const ViewportState&			other);
334
335		std::vector<vk::VkViewport> m_viewports;
336		std::vector<vk::VkRect2D>	m_scissors;
337	};
338
339	class RasterizerState : public vk::VkPipelineRasterizationStateCreateInfo
340	{
341	public:
342		RasterizerState (vk::VkBool32			depthClampEnable		= false,
343						 vk::VkBool32			rasterizerDiscardEnable = false,
344						 vk::VkPolygonMode		polygonMode				= vk::VK_POLYGON_MODE_FILL,
345						 vk::VkCullModeFlags	cullMode				= vk::VK_CULL_MODE_NONE,
346						 vk::VkFrontFace		frontFace				= vk::VK_FRONT_FACE_CLOCKWISE,
347						 vk::VkBool32			depthBiasEnable			= true,
348						 float					depthBiasConstantFactor	= 0.0f,
349						 float					depthBiasClamp			= 0.0f,
350						 float					depthBiasSlopeFactor	= 0.0f,
351						 float					lineWidth				= 1.0f);
352	};
353
354	class MultiSampleState : public vk::VkPipelineMultisampleStateCreateInfo
355	{
356	public:
357		MultiSampleState			(vk::VkSampleCountFlagBits				rasterizationSamples		= vk::VK_SAMPLE_COUNT_1_BIT,
358									 vk::VkBool32							sampleShadingEnable			= false,
359									 float									minSampleShading			= 0.0f,
360									 const std::vector<vk::VkSampleMask>&	sampleMask					= std::vector<vk::VkSampleMask>(1, 0xffffffffu),
361									 bool									alphaToCoverageEnable		= false,
362									 bool									alphaToOneEnable			= false);
363
364		MultiSampleState			(const MultiSampleState&				other);
365		MultiSampleState& operator= (const MultiSampleState&				other);
366
367	private:
368		std::vector<vk::VkSampleMask> m_sampleMask;
369	};
370
371	class ColorBlendState : public vk::VkPipelineColorBlendStateCreateInfo
372	{
373	public:
374		class Attachment : public vk::VkPipelineColorBlendAttachmentState
375		{
376		public:
377			Attachment (vk::VkBool32				blendEnable			= false,
378						vk::VkBlendFactor			srcColorBlendFactor	= vk::VK_BLEND_FACTOR_SRC_COLOR,
379						vk::VkBlendFactor			dstColorBlendFactor	= vk::VK_BLEND_FACTOR_DST_COLOR,
380						vk::VkBlendOp				colorBlendOp		= vk::VK_BLEND_OP_ADD,
381						vk::VkBlendFactor			srcAlphaBlendFactor	= vk::VK_BLEND_FACTOR_SRC_COLOR,
382						vk::VkBlendFactor			dstAlphaBlendFactor	= vk::VK_BLEND_FACTOR_DST_COLOR,
383						vk::VkBlendOp				alphaBlendOp		= vk::VK_BLEND_OP_ADD,
384						vk::VkColorComponentFlags	colorWriteMask		= vk::VK_COLOR_COMPONENT_R_BIT|
385																		  vk::VK_COLOR_COMPONENT_G_BIT|
386																		  vk::VK_COLOR_COMPONENT_B_BIT|
387																		  vk::VK_COLOR_COMPONENT_A_BIT);
388		};
389
390		ColorBlendState (const std::vector<vk::VkPipelineColorBlendAttachmentState>&	attachments,
391						 vk::VkBool32													alphaToCoverageEnable	= false,
392						 vk::VkLogicOp													logicOp					= vk::VK_LOGIC_OP_COPY);
393
394		ColorBlendState (deUint32														attachmentCount,
395						 const vk::VkPipelineColorBlendAttachmentState*					attachments,
396						 vk::VkBool32													logicOpEnable			= false,
397						 vk::VkLogicOp													logicOp					= vk::VK_LOGIC_OP_COPY);
398
399		ColorBlendState (const vk::VkPipelineColorBlendStateCreateInfo&					createInfo);
400		ColorBlendState (const ColorBlendState&											createInfo,
401						 std::vector<float>												blendConstants			= std::vector<float>(4));
402
403	private:
404		std::vector<vk::VkPipelineColorBlendAttachmentState> m_attachments;
405	};
406
407	class DepthStencilState : public vk::VkPipelineDepthStencilStateCreateInfo
408	{
409	public:
410		class StencilOpState : public vk::VkStencilOpState
411		{
412		public:
413			StencilOpState (vk::VkStencilOp failOp					= vk::VK_STENCIL_OP_REPLACE,
414							vk::VkStencilOp passOp					= vk::VK_STENCIL_OP_REPLACE,
415							vk::VkStencilOp depthFailOp				= vk::VK_STENCIL_OP_REPLACE,
416							vk::VkCompareOp compareOp				= vk::VK_COMPARE_OP_ALWAYS,
417							deUint32		compareMask				= 0xffffffffu,
418							deUint32		writeMask				= 0xffffffffu,
419							deUint32		reference				= 0u);
420		};
421
422		DepthStencilState (vk::VkBool32		depthTestEnable			= false,
423						   vk::VkBool32		depthWriteEnable		= false,
424						   vk::VkCompareOp	depthCompareOp			= vk::VK_COMPARE_OP_ALWAYS,
425						   vk::VkBool32		depthBoundsTestEnable	= false,
426						   vk::VkBool32		stencilTestEnable		= false,
427						   StencilOpState	front					= StencilOpState(),
428						   StencilOpState	back					= StencilOpState(),
429						   float			minDepthBounds			= 0.0f,
430						   float			maxDepthBounds			= 1.0f);
431	};
432
433	class PipelineShaderStage : public vk::VkPipelineShaderStageCreateInfo
434	{
435	public:
436		PipelineShaderStage (vk::VkShaderModule shaderModule, const char* pName, vk::VkShaderStageFlagBits stage);
437	};
438
439	class DynamicState : public vk::VkPipelineDynamicStateCreateInfo
440	{
441	public:
442		DynamicState			(const std::vector<vk::VkDynamicState>& dynamicStates = std::vector<vk::VkDynamicState>(0));
443
444		DynamicState			(const DynamicState& other);
445		DynamicState& operator= (const DynamicState& other);
446
447		std::vector<vk::VkDynamicState> m_dynamicStates;
448	};
449
450	PipelineCreateInfo				(vk::VkPipelineLayout								layout,
451								     vk::VkRenderPass									renderPass,
452									 int												subpass,
453									 vk::VkPipelineCreateFlags							flags);
454
455	PipelineCreateInfo& addShader	(const vk::VkPipelineShaderStageCreateInfo&			shader);
456
457	PipelineCreateInfo& addState	(const vk::VkPipelineVertexInputStateCreateInfo&	state);
458	PipelineCreateInfo& addState	(const vk::VkPipelineInputAssemblyStateCreateInfo&	state);
459	PipelineCreateInfo& addState	(const vk::VkPipelineColorBlendStateCreateInfo&		state);
460	PipelineCreateInfo& addState	(const vk::VkPipelineViewportStateCreateInfo&		state);
461	PipelineCreateInfo& addState	(const vk::VkPipelineDepthStencilStateCreateInfo&	state);
462	PipelineCreateInfo& addState	(const vk::VkPipelineTessellationStateCreateInfo&	state);
463	PipelineCreateInfo& addState	(const vk::VkPipelineRasterizationStateCreateInfo&	state);
464	PipelineCreateInfo& addState	(const vk::VkPipelineMultisampleStateCreateInfo&	state);
465	PipelineCreateInfo& addState	(const vk::VkPipelineDynamicStateCreateInfo&		state);
466
467private:
468	std::vector<vk::VkPipelineShaderStageCreateInfo>		m_shaders;
469
470	vk::VkPipelineVertexInputStateCreateInfo				m_vertexInputState;
471	vk::VkPipelineInputAssemblyStateCreateInfo				m_inputAssemblyState;
472	std::vector<vk::VkPipelineColorBlendAttachmentState>	m_colorBlendStateAttachments;
473	vk::VkPipelineColorBlendStateCreateInfo					m_colorBlendState;
474	vk::VkPipelineViewportStateCreateInfo					m_viewportState;
475	vk::VkPipelineDepthStencilStateCreateInfo				m_dynamicDepthStencilState;
476	vk::VkPipelineTessellationStateCreateInfo				m_tessState;
477	vk::VkPipelineRasterizationStateCreateInfo				m_rasterState;
478	vk::VkPipelineMultisampleStateCreateInfo				m_multisampleState;
479	vk::VkPipelineDynamicStateCreateInfo					m_dynamicState;
480
481	std::vector<vk::VkDynamicState>							m_dynamicStates;
482	std::vector<vk::VkViewport>								m_viewports;
483	std::vector<vk::VkRect2D>								m_scissors;
484	std::vector<vk::VkSampleMask>							m_multisampleStateSampleMask;
485};
486
487class SamplerCreateInfo : public vk::VkSamplerCreateInfo
488{
489public:
490	SamplerCreateInfo (vk::VkFilter				magFilter				= vk::VK_FILTER_NEAREST,
491					   vk::VkFilter				minFilter				= vk::VK_FILTER_NEAREST,
492					   vk::VkSamplerMipmapMode	mipmapMode				= vk::VK_SAMPLER_MIPMAP_MODE_NEAREST,
493					   vk::VkSamplerAddressMode	addressU				= vk::VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
494					   vk::VkSamplerAddressMode	addressV				= vk::VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
495					   vk::VkSamplerAddressMode	addressW				= vk::VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
496					   float					mipLodBias				= 0.0f,
497					   vk::VkBool32				anisotropyEnable		= VK_FALSE,
498					   float					maxAnisotropy			= 1.0f,
499					   vk::VkBool32				compareEnable			= false,
500					   vk::VkCompareOp			compareOp				= vk::VK_COMPARE_OP_ALWAYS,
501					   float					minLod					= 0.0f,
502					   float					maxLod					= 16.0f,
503					   vk::VkBorderColor		borderColor				= vk::VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
504					   vk::VkBool32				unnormalizedCoordinates	= false);
505};
506
507} // Draw
508} // vkt
509
510#endif // _VKTDRAWCREATEINFOUTIL_HPP
511