1e5c31af7Sopenharmony_ci#ifndef _VKWSIUTIL_HPP
2e5c31af7Sopenharmony_ci#define _VKWSIUTIL_HPP
3e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
4e5c31af7Sopenharmony_ci * Vulkan CTS Framework
5e5c31af7Sopenharmony_ci * --------------------
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Copyright (c) 2016 Google Inc.
8e5c31af7Sopenharmony_ci *
9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
14e5c31af7Sopenharmony_ci *
15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
19e5c31af7Sopenharmony_ci * limitations under the License.
20e5c31af7Sopenharmony_ci *
21e5c31af7Sopenharmony_ci *//*!
22e5c31af7Sopenharmony_ci * \file
23e5c31af7Sopenharmony_ci * \brief Windowing System Integration (WSI) Utilities.
24e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
25e5c31af7Sopenharmony_ci
26e5c31af7Sopenharmony_ci#include "tcuCommandLine.hpp"
27e5c31af7Sopenharmony_ci#include "vkDefs.hpp"
28e5c31af7Sopenharmony_ci#include "vkWsiPlatform.hpp"
29e5c31af7Sopenharmony_ci#include "vkRef.hpp"
30e5c31af7Sopenharmony_ci#include "vkMemUtil.hpp"
31e5c31af7Sopenharmony_ci#include "vkPrograms.hpp"
32e5c31af7Sopenharmony_ci
33e5c31af7Sopenharmony_ci#include <vector>
34e5c31af7Sopenharmony_ci
35e5c31af7Sopenharmony_cinamespace vk
36e5c31af7Sopenharmony_ci{
37e5c31af7Sopenharmony_cinamespace wsi
38e5c31af7Sopenharmony_ci{
39e5c31af7Sopenharmony_ci
40e5c31af7Sopenharmony_cistruct PlatformProperties
41e5c31af7Sopenharmony_ci{
42e5c31af7Sopenharmony_ci	enum FeatureFlags
43e5c31af7Sopenharmony_ci	{
44e5c31af7Sopenharmony_ci		FEATURE_INITIAL_WINDOW_SIZE		= (1<<0),		//!< Platform honors initial window size request
45e5c31af7Sopenharmony_ci		FEATURE_RESIZE_WINDOW			= (1<<1),		//!< Platform supports resizing window
46e5c31af7Sopenharmony_ci	};
47e5c31af7Sopenharmony_ci
48e5c31af7Sopenharmony_ci	enum SwapchainExtent
49e5c31af7Sopenharmony_ci	{
50e5c31af7Sopenharmony_ci		SWAPCHAIN_EXTENT_MUST_MATCH_WINDOW_SIZE = 0,	//!< Swapchain extent must match window size
51e5c31af7Sopenharmony_ci		SWAPCHAIN_EXTENT_SETS_WINDOW_SIZE,				//!< Window will be resized to swapchain size when first image is presented
52e5c31af7Sopenharmony_ci		SWAPCHAIN_EXTENT_SCALED_TO_WINDOW_SIZE,			//!< Presented image contents will be scaled to window size
53e5c31af7Sopenharmony_ci
54e5c31af7Sopenharmony_ci		SWAPCHAIN_EXTENT_LAST
55e5c31af7Sopenharmony_ci	};
56e5c31af7Sopenharmony_ci
57e5c31af7Sopenharmony_ci	deUint32		features;
58e5c31af7Sopenharmony_ci	SwapchainExtent	swapchainExtent;
59e5c31af7Sopenharmony_ci	deUint32		maxDisplays;
60e5c31af7Sopenharmony_ci	deUint32		maxWindowsPerDisplay;
61e5c31af7Sopenharmony_ci};
62e5c31af7Sopenharmony_ci
63e5c31af7Sopenharmony_ciconst char*						getName									(Type wsiType);
64e5c31af7Sopenharmony_ciconst char*						getExtensionName						(Type wsiType);
65e5c31af7Sopenharmony_ci
66e5c31af7Sopenharmony_ciconst PlatformProperties&		getPlatformProperties					(Type wsiType);
67e5c31af7Sopenharmony_ci
68e5c31af7Sopenharmony_ciVkResult						createSurface							(const InstanceInterface&		vki,
69e5c31af7Sopenharmony_ci																		 VkInstance						instance,
70e5c31af7Sopenharmony_ci																		 Type							wsiType,
71e5c31af7Sopenharmony_ci																		 const Display&					nativeDisplay,
72e5c31af7Sopenharmony_ci																		 const Window&					nativeWindow,
73e5c31af7Sopenharmony_ci																		 const tcu::CommandLine&		cmdLine,
74e5c31af7Sopenharmony_ci																		 const VkAllocationCallbacks*	pAllocator,
75e5c31af7Sopenharmony_ci																		 VkSurfaceKHR*					pSurface);
76e5c31af7Sopenharmony_ci
77e5c31af7Sopenharmony_ciMove<VkSurfaceKHR>				createSurface							(const InstanceInterface&		vki,
78e5c31af7Sopenharmony_ci																		 VkInstance						instance,
79e5c31af7Sopenharmony_ci																		 Type							wsiType,
80e5c31af7Sopenharmony_ci																		 const Display&					nativeDisplay,
81e5c31af7Sopenharmony_ci																		 const Window&					nativeWindow,
82e5c31af7Sopenharmony_ci																		 const tcu::CommandLine&		cmdLine,
83e5c31af7Sopenharmony_ci																		 const VkAllocationCallbacks*	pAllocator = DE_NULL);
84e5c31af7Sopenharmony_ci
85e5c31af7Sopenharmony_ciVkBool32						getPhysicalDeviceSurfaceSupport			(const InstanceInterface&		vki,
86e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
87e5c31af7Sopenharmony_ci																		 deUint32						queueFamilyIndex,
88e5c31af7Sopenharmony_ci																		 VkSurfaceKHR					surface);
89e5c31af7Sopenharmony_ci
90e5c31af7Sopenharmony_ciVkBool32						getPhysicalDevicePresentationSupport	(const InstanceInterface&		vki,
91e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
92e5c31af7Sopenharmony_ci																		 deUint32						queueFamilyIndex,
93e5c31af7Sopenharmony_ci																		 Type							wsiType,
94e5c31af7Sopenharmony_ci																		 const Display&					nativeDisplay);
95e5c31af7Sopenharmony_ci
96e5c31af7Sopenharmony_ciVkSurfaceCapabilitiesKHR		getPhysicalDeviceSurfaceCapabilities	(const InstanceInterface&		vki,
97e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
98e5c31af7Sopenharmony_ci																		 VkSurfaceKHR					surface);
99e5c31af7Sopenharmony_ci
100e5c31af7Sopenharmony_ciVkSurfaceCapabilities2EXT		getPhysicalDeviceSurfaceCapabilities2EXT(const InstanceInterface&		vki,
101e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
102e5c31af7Sopenharmony_ci																		 VkSurfaceKHR					surface);
103e5c31af7Sopenharmony_ci
104e5c31af7Sopenharmony_cibool							sameSurfaceCapabilities					(const VkSurfaceCapabilitiesKHR&	khr,
105e5c31af7Sopenharmony_ci																		 const VkSurfaceCapabilities2EXT&	ext);
106e5c31af7Sopenharmony_ci
107e5c31af7Sopenharmony_cistd::vector<VkSurfaceFormatKHR>	getPhysicalDeviceSurfaceFormats			(const InstanceInterface&		vki,
108e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
109e5c31af7Sopenharmony_ci																		 VkSurfaceKHR					surface);
110e5c31af7Sopenharmony_ci
111e5c31af7Sopenharmony_cistd::vector<VkPresentModeKHR>	getPhysicalDeviceSurfacePresentModes	(const InstanceInterface&		vki,
112e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
113e5c31af7Sopenharmony_ci																		 VkSurfaceKHR					surface);
114e5c31af7Sopenharmony_ci
115e5c31af7Sopenharmony_cistd::vector<VkImage>			getSwapchainImages						(const DeviceInterface&			vkd,
116e5c31af7Sopenharmony_ci																		 VkDevice						device,
117e5c31af7Sopenharmony_ci																		 VkSwapchainKHR					swapchain);
118e5c31af7Sopenharmony_ci
119e5c31af7Sopenharmony_cideUint32						chooseQueueFamilyIndex					(const InstanceInterface&			vki,
120e5c31af7Sopenharmony_ci																		 VkPhysicalDevice					physicalDevice,
121e5c31af7Sopenharmony_ci																		 const std::vector<VkSurfaceKHR>&	surfaces);
122e5c31af7Sopenharmony_ci
123e5c31af7Sopenharmony_cideUint32						chooseQueueFamilyIndex					(const InstanceInterface&		vki,
124e5c31af7Sopenharmony_ci																		 VkPhysicalDevice				physicalDevice,
125e5c31af7Sopenharmony_ci																		 VkSurfaceKHR					surface);
126e5c31af7Sopenharmony_ci
127e5c31af7Sopenharmony_cistd::vector<deUint32>			getCompatibleQueueFamilyIndices			(const InstanceInterface&			vki,
128e5c31af7Sopenharmony_ci																		 VkPhysicalDevice					physicalDevice,
129e5c31af7Sopenharmony_ci																		 const std::vector<VkSurfaceKHR>&	surface);
130e5c31af7Sopenharmony_ci
131e5c31af7Sopenharmony_citcu::UVec2						getFullScreenSize						(const vk::wsi::Type			wsiType,
132e5c31af7Sopenharmony_ci																		 const vk::wsi::Display&		display,
133e5c31af7Sopenharmony_ci																		 const tcu::UVec2&				fallbackSize);
134e5c31af7Sopenharmony_ci
135e5c31af7Sopenharmony_ci
136e5c31af7Sopenharmony_ciVkBool32						isDisplaySurface						(Type							wsiType);
137e5c31af7Sopenharmony_ci
138e5c31af7Sopenharmony_ciclass WsiTriangleRenderer
139e5c31af7Sopenharmony_ci{
140e5c31af7Sopenharmony_cipublic:
141e5c31af7Sopenharmony_ci										WsiTriangleRenderer	(const DeviceInterface&		vkd,
142e5c31af7Sopenharmony_ci															 const VkDevice				device,
143e5c31af7Sopenharmony_ci															 Allocator&					allocator,
144e5c31af7Sopenharmony_ci															 const BinaryCollection&	binaryRegistry,
145e5c31af7Sopenharmony_ci															 bool						explicitLayoutTransitions,
146e5c31af7Sopenharmony_ci															 const std::vector<VkImage>	swapchainImages,
147e5c31af7Sopenharmony_ci															 const std::vector<VkImage>	aliasImages,
148e5c31af7Sopenharmony_ci															 const VkFormat				framebufferFormat,
149e5c31af7Sopenharmony_ci															 const tcu::UVec2&			renderSize);
150e5c31af7Sopenharmony_ci
151e5c31af7Sopenharmony_ci										WsiTriangleRenderer	(WsiTriangleRenderer&&		other);
152e5c31af7Sopenharmony_ci
153e5c31af7Sopenharmony_ci										~WsiTriangleRenderer(void);
154e5c31af7Sopenharmony_ci
155e5c31af7Sopenharmony_ci	void								recordFrame			(VkCommandBuffer			cmdBuffer,
156e5c31af7Sopenharmony_ci															 deUint32					imageNdx,
157e5c31af7Sopenharmony_ci															 deUint32					frameNdx) const;
158e5c31af7Sopenharmony_ci
159e5c31af7Sopenharmony_ci	void								recordDeviceGroupFrame (VkCommandBuffer			cmdBuffer,
160e5c31af7Sopenharmony_ci																deUint32				imageNdx,
161e5c31af7Sopenharmony_ci																deUint32				firstDeviceID,
162e5c31af7Sopenharmony_ci																deUint32				secondDeviceID,
163e5c31af7Sopenharmony_ci																deUint32				devicesCount,
164e5c31af7Sopenharmony_ci																deUint32				frameNdx) const;
165e5c31af7Sopenharmony_ci
166e5c31af7Sopenharmony_ci	static void							getPrograms			(SourceCollections& dst);
167e5c31af7Sopenharmony_ci
168e5c31af7Sopenharmony_ciprivate:
169e5c31af7Sopenharmony_ci	static Move<VkRenderPass>			createRenderPass	(const DeviceInterface&		vkd,
170e5c31af7Sopenharmony_ci															 const VkDevice				device,
171e5c31af7Sopenharmony_ci															 const VkFormat				colorAttachmentFormat,
172e5c31af7Sopenharmony_ci															 const bool					explicitLayoutTransitions);
173e5c31af7Sopenharmony_ci
174e5c31af7Sopenharmony_ci	static Move<VkPipelineLayout>		createPipelineLayout(const DeviceInterface&		vkd,
175e5c31af7Sopenharmony_ci															 VkDevice					device);
176e5c31af7Sopenharmony_ci
177e5c31af7Sopenharmony_ci	static Move<VkPipeline>				createPipeline		(const DeviceInterface&		vkd,
178e5c31af7Sopenharmony_ci															 const VkDevice				device,
179e5c31af7Sopenharmony_ci															 const VkRenderPass			renderPass,
180e5c31af7Sopenharmony_ci															 const VkPipelineLayout		pipelineLayout,
181e5c31af7Sopenharmony_ci															 const BinaryCollection&	binaryCollection,
182e5c31af7Sopenharmony_ci															 const tcu::UVec2&			renderSize);
183e5c31af7Sopenharmony_ci
184e5c31af7Sopenharmony_ci	static Move<VkImageView>			createAttachmentView(const DeviceInterface&		vkd,
185e5c31af7Sopenharmony_ci															 const VkDevice				device,
186e5c31af7Sopenharmony_ci															 const VkImage				image,
187e5c31af7Sopenharmony_ci															 const VkFormat				format);
188e5c31af7Sopenharmony_ci
189e5c31af7Sopenharmony_ci	static Move<VkFramebuffer>			createFramebuffer	(const DeviceInterface&		vkd,
190e5c31af7Sopenharmony_ci															 const VkDevice				device,
191e5c31af7Sopenharmony_ci															 const VkRenderPass			renderPass,
192e5c31af7Sopenharmony_ci															 const VkImageView			colorAttachment,
193e5c31af7Sopenharmony_ci															 const tcu::UVec2&			renderSize);
194e5c31af7Sopenharmony_ci
195e5c31af7Sopenharmony_ci	static Move<VkBuffer>				createBuffer		(const DeviceInterface&		vkd,
196e5c31af7Sopenharmony_ci															 VkDevice					device,
197e5c31af7Sopenharmony_ci															 VkDeviceSize				size,
198e5c31af7Sopenharmony_ci															 VkBufferUsageFlags			usage);
199e5c31af7Sopenharmony_ci
200e5c31af7Sopenharmony_ci	const DeviceInterface&				m_vkd;
201e5c31af7Sopenharmony_ci
202e5c31af7Sopenharmony_ci	bool								m_explicitLayoutTransitions;
203e5c31af7Sopenharmony_ci	std::vector<VkImage>				m_swapchainImages;
204e5c31af7Sopenharmony_ci	std::vector<VkImage>				m_aliasImages;
205e5c31af7Sopenharmony_ci	tcu::UVec2							m_renderSize;
206e5c31af7Sopenharmony_ci
207e5c31af7Sopenharmony_ci	Move<VkRenderPass>					m_renderPass;
208e5c31af7Sopenharmony_ci	Move<VkPipelineLayout>				m_pipelineLayout;
209e5c31af7Sopenharmony_ci	Move<VkPipeline>					m_pipeline;
210e5c31af7Sopenharmony_ci
211e5c31af7Sopenharmony_ci	Move<VkBuffer>						m_vertexBuffer;
212e5c31af7Sopenharmony_ci	de::MovePtr<Allocation>				m_vertexBufferMemory;
213e5c31af7Sopenharmony_ci
214e5c31af7Sopenharmony_ci	using ImageViewSp	= de::SharedPtr<Unique<VkImageView>>;
215e5c31af7Sopenharmony_ci	using FramebufferSp	= de::SharedPtr<Unique<VkFramebuffer>>;
216e5c31af7Sopenharmony_ci
217e5c31af7Sopenharmony_ci	std::vector<ImageViewSp>			m_attachmentViews;
218e5c31af7Sopenharmony_ci	mutable std::vector<VkImageLayout>	m_attachmentLayouts;
219e5c31af7Sopenharmony_ci	std::vector<FramebufferSp>			m_framebuffers;
220e5c31af7Sopenharmony_ci};
221e5c31af7Sopenharmony_ci
222e5c31af7Sopenharmony_ci} // wsi
223e5c31af7Sopenharmony_ci} // vk
224e5c31af7Sopenharmony_ci
225e5c31af7Sopenharmony_ci#endif // _VKWSIUTIL_HPP
226