1 #ifndef _VKWSIUTIL_HPP
2 #define _VKWSIUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2016 Google 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 Windowing System Integration (WSI) Utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkDefs.hpp"
27 #include "vkWsiPlatform.hpp"
28 #include "vkRef.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkPrograms.hpp"
31 
32 #include <vector>
33 
34 namespace vk
35 {
36 namespace wsi
37 {
38 
39 struct PlatformProperties
40 {
41 	enum FeatureFlags
42 	{
43 		FEATURE_INITIAL_WINDOW_SIZE		= (1<<0),		//!< Platform honors initial window size request
44 		FEATURE_RESIZE_WINDOW			= (1<<1),		//!< Platform supports resizing window
45 	};
46 
47 	enum SwapchainExtent
48 	{
49 		SWAPCHAIN_EXTENT_MUST_MATCH_WINDOW_SIZE = 0,	//!< Swapchain extent must match window size
50 		SWAPCHAIN_EXTENT_SETS_WINDOW_SIZE,				//!< Window will be resized to swapchain size when first image is presented
51 		SWAPCHAIN_EXTENT_SCALED_TO_WINDOW_SIZE,			//!< Presented image contents will be scaled to window size
52 
53 		SWAPCHAIN_EXTENT_LAST
54 	};
55 
56 	deUint32		features;
57 	SwapchainExtent	swapchainExtent;
58 	deUint32		maxDisplays;
59 	deUint32		maxWindowsPerDisplay;
60 };
61 
62 const char*						getName									(Type wsiType);
63 const char*						getExtensionName						(Type wsiType);
64 
65 const PlatformProperties&		getPlatformProperties					(Type wsiType);
66 
67 VkResult						createSurface							(const InstanceInterface&		vki,
68 																		 VkInstance						instance,
69 																		 Type							wsiType,
70 																		 const Display&					nativeDisplay,
71 																		 const Window&					nativeWindow,
72 																		 const VkAllocationCallbacks*	pAllocator,
73 																		 VkSurfaceKHR*					pSurface);
74 
75 Move<VkSurfaceKHR>				createSurface							(const InstanceInterface&		vki,
76 																		 VkInstance						instance,
77 																		 Type							wsiType,
78 																		 const Display&					nativeDisplay,
79 																		 const Window&					nativeWindow,
80 																		 const VkAllocationCallbacks*	pAllocator = DE_NULL);
81 
82 VkBool32						getPhysicalDeviceSurfaceSupport			(const InstanceInterface&		vki,
83 																		 VkPhysicalDevice				physicalDevice,
84 																		 deUint32						queueFamilyIndex,
85 																		 VkSurfaceKHR					surface);
86 
87 VkBool32						getPhysicalDevicePresentationSupport	(const InstanceInterface&		vki,
88 																		 VkPhysicalDevice				physicalDevice,
89 																		 deUint32						queueFamilyIndex,
90 																		 Type							wsiType,
91 																		 const Display&					nativeDisplay);
92 
93 VkSurfaceCapabilitiesKHR		getPhysicalDeviceSurfaceCapabilities	(const InstanceInterface&		vki,
94 																		 VkPhysicalDevice				physicalDevice,
95 																		 VkSurfaceKHR					surface);
96 
97 VkSurfaceCapabilities2EXT		getPhysicalDeviceSurfaceCapabilities2EXT(const InstanceInterface&		vki,
98 																		 VkPhysicalDevice				physicalDevice,
99 																		 VkSurfaceKHR					surface);
100 
101 bool							sameSurfaceCapabilities					(const VkSurfaceCapabilitiesKHR&	khr,
102 																		 const VkSurfaceCapabilities2EXT&	ext);
103 
104 std::vector<VkSurfaceFormatKHR>	getPhysicalDeviceSurfaceFormats			(const InstanceInterface&		vki,
105 																		 VkPhysicalDevice				physicalDevice,
106 																		 VkSurfaceKHR					surface);
107 
108 std::vector<VkPresentModeKHR>	getPhysicalDeviceSurfacePresentModes	(const InstanceInterface&		vki,
109 																		 VkPhysicalDevice				physicalDevice,
110 																		 VkSurfaceKHR					surface);
111 
112 std::vector<VkImage>			getSwapchainImages						(const DeviceInterface&			vkd,
113 																		 VkDevice						device,
114 																		 VkSwapchainKHR					swapchain);
115 
116 deUint32						chooseQueueFamilyIndex					(const InstanceInterface&			vki,
117 																		 VkPhysicalDevice					physicalDevice,
118 																		 const std::vector<VkSurfaceKHR>&	surfaces);
119 
120 deUint32						chooseQueueFamilyIndex					(const InstanceInterface&		vki,
121 																		 VkPhysicalDevice				physicalDevice,
122 																		 VkSurfaceKHR					surface);
123 
124 std::vector<deUint32>			getCompatibleQueueFamilyIndices			(const InstanceInterface&			vki,
125 																		 VkPhysicalDevice					physicalDevice,
126 																		 const std::vector<VkSurfaceKHR>&	surface);
127 
128 tcu::UVec2						getFullScreenSize						(const vk::wsi::Type			wsiType,
129 																		 const vk::wsi::Display&		display,
130 																		 const tcu::UVec2&				fallbackSize);
131 
132 class WsiTriangleRenderer
133 {
134 public:
135 										WsiTriangleRenderer	(const DeviceInterface&		vkd,
136 															 const VkDevice				device,
137 															 Allocator&					allocator,
138 															 const BinaryCollection&	binaryRegistry,
139 															 bool						explicitLayoutTransitions,
140 															 const std::vector<VkImage>	swapchainImages,
141 															 const std::vector<VkImage>	aliasImages,
142 															 const VkFormat				framebufferFormat,
143 															 const tcu::UVec2&			renderSize);
144 
145 										WsiTriangleRenderer	(WsiTriangleRenderer&&		other);
146 
147 										~WsiTriangleRenderer(void);
148 
149 	void								recordFrame			(VkCommandBuffer			cmdBuffer,
150 															 deUint32					imageNdx,
151 															 deUint32					frameNdx) const;
152 
153 	void								recordDeviceGroupFrame (VkCommandBuffer			cmdBuffer,
154 																deUint32				imageNdx,
155 																deUint32				firstDeviceID,
156 																deUint32				secondDeviceID,
157 																deUint32				devicesCount,
158 																deUint32				frameNdx) const;
159 
160 	static void							getPrograms			(SourceCollections& dst);
161 
162 private:
163 	static Move<VkRenderPass>			createRenderPass	(const DeviceInterface&		vkd,
164 															 const VkDevice				device,
165 															 const VkFormat				colorAttachmentFormat,
166 															 const bool					explicitLayoutTransitions);
167 
168 	static Move<VkPipelineLayout>		createPipelineLayout(const DeviceInterface&		vkd,
169 															 VkDevice					device);
170 
171 	static Move<VkPipeline>				createPipeline		(const DeviceInterface&		vkd,
172 															 const VkDevice				device,
173 															 const VkRenderPass			renderPass,
174 															 const VkPipelineLayout		pipelineLayout,
175 															 const BinaryCollection&	binaryCollection,
176 															 const tcu::UVec2&			renderSize);
177 
178 	static Move<VkImageView>			createAttachmentView(const DeviceInterface&		vkd,
179 															 const VkDevice				device,
180 															 const VkImage				image,
181 															 const VkFormat				format);
182 
183 	static Move<VkFramebuffer>			createFramebuffer	(const DeviceInterface&		vkd,
184 															 const VkDevice				device,
185 															 const VkRenderPass			renderPass,
186 															 const VkImageView			colorAttachment,
187 															 const tcu::UVec2&			renderSize);
188 
189 	static Move<VkBuffer>				createBuffer		(const DeviceInterface&		vkd,
190 															 VkDevice					device,
191 															 VkDeviceSize				size,
192 															 VkBufferUsageFlags			usage);
193 
194 	const DeviceInterface&				m_vkd;
195 
196 	bool								m_explicitLayoutTransitions;
197 	std::vector<VkImage>				m_swapchainImages;
198 	std::vector<VkImage>				m_aliasImages;
199 	tcu::UVec2							m_renderSize;
200 
201 	Move<VkRenderPass>					m_renderPass;
202 	Move<VkPipelineLayout>				m_pipelineLayout;
203 	Move<VkPipeline>					m_pipeline;
204 
205 	Move<VkBuffer>						m_vertexBuffer;
206 	de::MovePtr<Allocation>				m_vertexBufferMemory;
207 
208 	using ImageViewSp	= de::SharedPtr<Unique<VkImageView>>;
209 	using FramebufferSp	= de::SharedPtr<Unique<VkFramebuffer>>;
210 
211 	std::vector<ImageViewSp>			m_attachmentViews;
212 	mutable std::vector<VkImageLayout>	m_attachmentLayouts;
213 	std::vector<FramebufferSp>			m_framebuffers;
214 };
215 
216 } // wsi
217 } // vk
218 
219 #endif // _VKWSIUTIL_HPP
220