• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKPLATFORM_HPP
2 #define _VKPLATFORM_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2015 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 Vulkan platform abstraction.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkDefs.hpp"
27 #include "deUniquePtr.hpp"
28 
29 #include <ostream>
30 #include <deSharedPtr.hpp>
31 #ifdef CTS_USES_VULKANSC
32 #include <mutex>
33 	#include <vector>
34 	#include <map>
35 	#include "vkResourceInterface.hpp"
36 #include "tcuCommandLine.hpp"
37 #endif // CTS_USES_VULKANSC
38 
39 namespace tcu
40 {
41 class FunctionLibrary;
42 }
43 
44 namespace vk
45 {
46 
47 class Library
48 {
49 public:
Library(void)50 										Library					(void) {}
~Library(void)51 	virtual								~Library				(void) {}
52 
53 	virtual const PlatformInterface&	getPlatformInterface	(void) const = 0;
54 	virtual const tcu::FunctionLibrary&	getFunctionLibrary		(void) const = 0;
55 };
56 
57 class PlatformDriver : public PlatformInterface
58 {
59 public:
60 				PlatformDriver	(const tcu::FunctionLibrary& library);
61 				~PlatformDriver	(void);
62 
63 #include "vkConcretePlatformInterface.inl"
64 
getGetInstanceProcAddr() const65 				virtual	GetInstanceProcAddrFunc	getGetInstanceProcAddr  () const {
66 					return m_vk.getInstanceProcAddr;
67 				}
68 
69 protected:
70 	struct Functions
71 	{
72 #include "vkPlatformFunctionPointers.inl"
73 	};
74 
75 	Functions	m_vk;
76 };
77 
78 class InstanceDriver : public InstanceInterface
79 {
80 public:
81 						InstanceDriver		(const PlatformInterface&	platformInterface,
82 											 VkInstance					instance);
83 	virtual				~InstanceDriver		(void);
84 
85 #include "vkConcreteInstanceInterface.inl"
86 
87 protected:
88 	void				loadFunctions		(const PlatformInterface&	platformInterface,
89 											 VkInstance					instance);
90 
91 	struct Functions
92 	{
93 #include "vkInstanceFunctionPointers.inl"
94 	};
95 
96 	Functions	m_vk;
97 };
98 
99 #ifdef CTS_USES_VULKANSC
100 
101 class InstanceDriverSC : public InstanceDriver
102 {
103 public:
104 						InstanceDriverSC	(const PlatformInterface&				platformInterface,
105 											 VkInstance								instance,
106 											 const tcu::CommandLine&				cmdLine,
107 											 de::SharedPtr<vk::ResourceInterface>	resourceInterface);
108 
109 	virtual VkResult	createDevice		(VkPhysicalDevice						physicalDevice,
110 											 const VkDeviceCreateInfo*				pCreateInfo,
111 											 const VkAllocationCallbacks*			pAllocator,
112 											 VkDevice*								pDevice) const;
113 protected:
114 	mutable std::mutex						functionMutex;
115 	bool									m_normalMode;
116 	de::SharedPtr<vk::ResourceInterface>	m_resourceInterface;
117 };
118 
119 #endif // CTS_USES_VULKANSC
120 
121 class DeviceDriver : public DeviceInterface
122 {
123 public:
124 						DeviceDriver		(const PlatformInterface&			platformInterface,
125 											 VkInstance							instance,
126 											 VkDevice							device);
127 	virtual				~DeviceDriver		(void);
128 
129 #include "vkConcreteDeviceInterface.inl"
130 
131 #ifdef CTS_USES_VULKANSC
132 	virtual VkResult	createShaderModule	(VkDevice							device,
133 											 const VkShaderModuleCreateInfo*	pCreateInfo,
134 											 const VkAllocationCallbacks*		pAllocator,
135 											 VkShaderModule*					pShaderModule) const;
136 #endif // CTS_USES_VULKANSC
137 
138 protected:
139 	struct Functions
140 	{
141 #include "vkDeviceFunctionPointers.inl"
142 	};
143 
144 	Functions	m_vk;
145 };
146 
147 #ifdef CTS_USES_VULKANSC
148 
149 #define DDSTAT_LOCK() std::lock_guard<std::mutex> statLock(m_resourceInterface->getStatMutex())
150 #define DDSTAT_HANDLE_CREATE(VAR_NAME,VAR_VALUE) do { m_resourceInterface->getStatCurrent().VAR_NAME += (VAR_VALUE); m_resourceInterface->getStatMax().VAR_NAME = de::max(m_resourceInterface->getStatMax().VAR_NAME, m_resourceInterface->getStatCurrent().VAR_NAME); } while(0)
151 #define DDSTAT_HANDLE_DESTROY_IF(VAR_VARIABLE,VAR_NAME,VAR_VALUE) if(VAR_VARIABLE.getInternal()!=DE_NULL && m_resourceInterface->isEnabledHandleDestroy()) m_resourceInterface->getStatCurrent().VAR_NAME -= (VAR_VALUE)
152 #define DDSTAT_HANDLE_DESTROY(VAR_NAME,VAR_VALUE) if( m_resourceInterface->isEnabledHandleDestroy() ) m_resourceInterface->getStatCurrent().VAR_NAME -= (VAR_VALUE)
153 
154 class DeviceDriverSC : public DeviceDriver
155 {
156 public:
157 										DeviceDriverSC						(const		PlatformInterface&					platformInterface,
158 																			 VkInstance										instance,
159 																			 VkDevice										device,
160 																			 const tcu::CommandLine&						cmdLine,
161 																			 de::SharedPtr<vk::ResourceInterface>			resourceInterface,
162 																			 const VkPhysicalDeviceVulkanSC10Properties&	physicalDeviceVulkanSC10Properties,
163 																			 const VkPhysicalDeviceProperties&				physicalDeviceProperties);
164 	virtual								~DeviceDriverSC						(void);
165 
166 #include "vkConcreteDeviceInterface.inl"
167 
168 	// Functions ending with Handler() and HandlerStat() work only when we gather statistics ( in a main process ).
169 	// Functions ending with HandlerNorm() work in normal mode ( in subprocess, when real test is performed )
170 	// Method createShaderModule() works in both modes, and ResourceInterface is responsible for distinguishing modes
171 	void								destroyDeviceHandler					(VkDevice								device,
172 																				 const VkAllocationCallbacks*			pAllocator) const;
173 	VkResult							createDescriptorSetLayoutHandlerNorm	(VkDevice								device,
174 																				 const VkDescriptorSetLayoutCreateInfo*	pCreateInfo,
175 																				 const VkAllocationCallbacks*			pAllocator,
176 																				 VkDescriptorSetLayout*					pSetLayout) const;
177 	void								createDescriptorSetLayoutHandlerStat	(VkDevice								device,
178 																				 const VkDescriptorSetLayoutCreateInfo*	pCreateInfo,
179 																				 const VkAllocationCallbacks*			pAllocator,
180 																				 VkDescriptorSetLayout*					pSetLayout) const;
181 	void								destroyDescriptorSetLayoutHandler		(VkDevice								device,
182 																				 VkDescriptorSetLayout					descriptorSetLayout,
183 																				 const VkAllocationCallbacks*			pAllocator) const;
184 	void								allocateDescriptorSetsHandlerStat		(VkDevice								device,
185 																				 const VkDescriptorSetAllocateInfo*		pAllocateInfo,
186 																				 VkDescriptorSet*						pDescriptorSets) const;
187 	void								freeDescriptorSetsHandlerStat			(VkDevice								device,
188 																				 VkDescriptorPool						descriptorPool,
189 																				 uint32_t								descriptorSetCount,
190 																				 const VkDescriptorSet*					pDescriptorSets) const;
191 	void								resetDescriptorPoolHandlerStat			(VkDevice								device,
192 																				 VkDescriptorPool						descriptorPool,
193 																				 VkDescriptorPoolResetFlags				flags) const;
194 	void								createImageViewHandler					(VkDevice								device,
195 																				 const VkImageViewCreateInfo*			pCreateInfo,
196 																				 const VkAllocationCallbacks*			pAllocator,
197 																				 VkImageView*							pView) const;
198 	void								destroyImageViewHandler					(VkDevice								device,
199 																				 VkImageView							imageView,
200 																				 const VkAllocationCallbacks*			pAllocator) const;
201 	void								createQueryPoolHandler					(VkDevice								device,
202 																				 const VkQueryPoolCreateInfo*			pCreateInfo,
203 																				 const VkAllocationCallbacks*			pAllocator,
204 																				 VkQueryPool*							pQueryPool) const ;
205 	VkResult							createPipelineLayoutHandlerNorm			(VkDevice								device,
206 																				 const VkPipelineLayoutCreateInfo*		pCreateInfo,
207 																				 const VkAllocationCallbacks*			pAllocator,
208 																				 VkPipelineLayout*						pPipelineLayout) const;
209 	void								createPipelineLayoutHandlerStat			(VkDevice								device,
210 																				 const VkPipelineLayoutCreateInfo*		pCreateInfo,
211 																				 const VkAllocationCallbacks*			pAllocator,
212 																				 VkPipelineLayout*						pPipelineLayout) const;
213 	VkResult							createGraphicsPipelinesHandlerNorm		(VkDevice								device,
214 																				 VkPipelineCache						pipelineCache,
215 																				 deUint32								createInfoCount,
216 																				 const VkGraphicsPipelineCreateInfo*	pCreateInfos,
217 																				 const VkAllocationCallbacks*			pAllocator,
218 																				 VkPipeline*							pPipelines) const;
219 	void								createGraphicsPipelinesHandlerStat		(VkDevice								device,
220 																				 VkPipelineCache						pipelineCache,
221 																				 deUint32								createInfoCount,
222 																				 const VkGraphicsPipelineCreateInfo*	pCreateInfos,
223 																				 const VkAllocationCallbacks*			pAllocator,
224 																				 VkPipeline*							pPipelines) const;
225 	VkResult							createComputePipelinesHandlerNorm		(VkDevice								device,
226 																				 VkPipelineCache						pipelineCache,
227 																				 deUint32								createInfoCount,
228 																				 const VkComputePipelineCreateInfo*		pCreateInfos,
229 																				 const VkAllocationCallbacks*			pAllocator,
230 																				 VkPipeline*							pPipelines) const;
231 	void								createComputePipelinesHandlerStat		(VkDevice								device,
232 																				 VkPipelineCache						pipelineCache,
233 																				 deUint32								createInfoCount,
234 																				 const VkComputePipelineCreateInfo*		pCreateInfos,
235 																				 const VkAllocationCallbacks*			pAllocator,
236 																				 VkPipeline*							pPipelines) const;
237 	void								destroyPipelineHandler					(VkDevice								device,
238 																				 VkPipeline								pipeline,
239 																				 const VkAllocationCallbacks*			pAllocator) const;
240 	VkResult							createFramebufferHandlerNorm			(VkDevice								device,
241 																				 const VkFramebufferCreateInfo*			pCreateInfo,
242 																				 const VkAllocationCallbacks*			pAllocator,
243 																				 VkFramebuffer*							pFramebuffer) const;
244 	void								createFramebufferHandlerStat			(VkDevice								device,
245 																				 const VkFramebufferCreateInfo*			pCreateInfo,
246 																				 const VkAllocationCallbacks*			pAllocator,
247 																				 VkFramebuffer*							pFramebuffer) const;
248 	VkResult							createRenderPassHandlerNorm				(VkDevice								device,
249 																				 const VkRenderPassCreateInfo*			pCreateInfo,
250 																				 const VkAllocationCallbacks*			pAllocator,
251 																				 VkRenderPass*							pRenderPass) const;
252 	void								createRenderPassHandlerStat				(VkDevice								device,
253 																				 const VkRenderPassCreateInfo*			pCreateInfo,
254 																				 const VkAllocationCallbacks*			pAllocator,
255 																				 VkRenderPass*							pRenderPass) const;
256 	VkResult							createRenderPass2HandlerNorm			(VkDevice								device,
257 																				 const VkRenderPassCreateInfo2*			pCreateInfo,
258 																				 const VkAllocationCallbacks*			pAllocator,
259 																				 VkRenderPass*							pRenderPass) const;
260 	void								createRenderPass2HandlerStat			(VkDevice								device,
261 																				 const VkRenderPassCreateInfo2*			pCreateInfo,
262 																				 const VkAllocationCallbacks*			pAllocator,
263 																				 VkRenderPass*							pRenderPass) const;
264 	void								destroyRenderPassHandler				(VkDevice								device,
265 																				 VkRenderPass							renderPass,
266 																				 const VkAllocationCallbacks*			pAllocator) const;
267 	VkResult							createSamplerHandlerNorm				(VkDevice								device,
268 																				 const VkSamplerCreateInfo*				pCreateInfo,
269 																				 const VkAllocationCallbacks*			pAllocator,
270 																				 VkSampler*								pSampler) const;
271 	void								createSamplerHandlerStat				(VkDevice								device,
272 																				 const VkSamplerCreateInfo*				pCreateInfo,
273 																				 const VkAllocationCallbacks*			pAllocator,
274 																				 VkSampler*								pSampler) const;
275 	VkResult							createSamplerYcbcrConversionHandlerNorm	(VkDevice								device,
276 																				 const VkSamplerYcbcrConversionCreateInfo*	pCreateInfo,
277 																				 const VkAllocationCallbacks*			pAllocator,
278 																				 VkSamplerYcbcrConversion*				pYcbcrConversion) const;
279 	void								createSamplerYcbcrConversionHandlerStat	(VkDevice								device,
280 																				 const VkSamplerYcbcrConversionCreateInfo*	pCreateInfo,
281 																				 const VkAllocationCallbacks*			pAllocator,
282 																				 VkSamplerYcbcrConversion*				pYcbcrConversion) const;
283 	void								getDescriptorSetLayoutSupportHandler	(VkDevice								device,
284 																				 const VkDescriptorSetLayoutCreateInfo*	pCreateInfo,
285 																				 VkDescriptorSetLayoutSupport*			pSupport) const;
286 	virtual VkResult					createShaderModule						(VkDevice								device,
287 																				 const	VkShaderModuleCreateInfo*		pCreateInfo,
288 																				 const VkAllocationCallbacks*			pAllocator,
289 																				 VkShaderModule*						pShaderModule) const;
290 
291 	VkResult							createCommandPoolHandlerNorm			(VkDevice								device,
292 																				 const VkCommandPoolCreateInfo*			pCreateInfo,
293 																				 const VkAllocationCallbacks*			pAllocator,
294 																				 VkCommandPool*							pCommandPool) const;
295 	VkResult							resetCommandPoolHandlerNorm				(VkDevice								device,
296 																				 VkCommandPool							commandPool,
297 																				 VkCommandPoolResetFlags				flags) const;
298 	void								createCommandPoolHandlerStat			(VkDevice								device,
299 																				 const VkCommandPoolCreateInfo*			pCreateInfo,
300 																				 const VkAllocationCallbacks*			pAllocator,
301 																				 VkCommandPool*							pCommandPool) const;
302 	void								resetCommandPoolHandlerStat				(VkDevice								device,
303 																				 VkCommandPool							commandPool,
304 																				 VkCommandPoolResetFlags				flags) const;
305 	void								allocateCommandBuffersHandler			(VkDevice								device,
306 																				 const VkCommandBufferAllocateInfo*		pAllocateInfo,
307 																				 VkCommandBuffer*						pCommandBuffers) const;
308 	void								freeCommandBuffersHandler				(VkDevice								device,
309 																				 VkCommandPool							commandPool,
310 																				 deUint32								commandBufferCount,
311 																				 const VkCommandBuffer*					pCommandBuffers) const;
312 	void								increaseCommandBufferSize				(VkCommandBuffer						commandBuffer,
313 																				 VkDeviceSize							commandSize) const;
314 	void								checkFramebufferSupport					(const VkFramebufferCreateInfo*			pCreateInfo) const;
315 	void								checkRenderPassSupport					(deUint32								attachmentCount,
316 																				 deUint32								subpassCount,
317 																				 deUint32								dependencyCount) const;
318 	void								checkSubpassSupport						(deUint32								inputAttachmentCount,
319 																				 deUint32								preserveAttachmentCount) const;
320 
321 
322 	de::SharedPtr<ResourceInterface>	gerResourceInterface					() const;
323 	void								reset									() const;
324 
325 protected:
326 	mutable std::mutex															functionMutex;
327 	bool																		m_normalMode;
328 
329 	de::SharedPtr<vk::ResourceInterface>										m_resourceInterface;
330 
331 	mutable std::vector<deUint8>												m_falseMemory;
332 	mutable std::map<VkImageView, VkImageViewCreateInfo>						m_imageViews;
333 	mutable std::map<VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>	m_descriptorSetLayouts;
334 	mutable std::map<VkRenderPass, VkRenderPassCreateInfo>						m_renderPasses;
335 	mutable std::map<VkRenderPass, VkRenderPassCreateInfo2>						m_renderPasses2;
336 	mutable std::map<VkPipeline, VkGraphicsPipelineCreateInfo>					m_graphicsPipelines;
337 	mutable std::map<VkPipeline, VkComputePipelineCreateInfo>					m_computePipelines;
338 	mutable std::map<VkDescriptorSet, VkDescriptorPool>							m_descriptorSetsInPool;
339 	VkPhysicalDeviceVulkanSC10Properties										m_physicalDeviceVulkanSC10Properties;
340 	VkPhysicalDeviceProperties													m_physicalDeviceProperties;
341 
342 	VkDeviceSize																m_commandDefaultSize;
343 	VkDeviceSize																m_commandBufferMinimumSize;
344 	VkDeviceSize																m_commandPoolMinimumSize;
345 };
346 
347 class DeinitDeviceDeleter : public Deleter<DeviceDriverSC>
348 {
349 public:
DeinitDeviceDeleter(ResourceInterface * resourceInterface,const VkDevice & device)350 										DeinitDeviceDeleter					(ResourceInterface* resourceInterface, const VkDevice& device)
351 		: m_resourceInterface(resourceInterface)
352 		, m_device(device)
353 	{
354 	}
DeinitDeviceDeleter(void)355 										DeinitDeviceDeleter					(void)
356 		: m_resourceInterface(DE_NULL)
357 		, m_device(DE_NULL)
358 	{}
359 
operator ()(DeviceDriverSC * obj) const360 	void								operator()							(DeviceDriverSC* obj) const
361 	{
362 		if (m_resourceInterface != DE_NULL)
363 			m_resourceInterface->deinitDevice(m_device);
364 		delete obj;
365 	}
366 private:
367 	ResourceInterface*	m_resourceInterface;
368 	VkDevice			m_device;
369 };
370 
371 #endif // CTS_USES_VULKANSC
372 
373 // Single device driver pointer type which will differ in SC and non-SC mode helping clearing the code
374 #ifndef CTS_USES_VULKANSC
375 typedef de::MovePtr<DeviceDriver> DeviceDriverPtr;
376 #else
377 typedef de::MovePtr<DeviceDriverSC, vk::DeinitDeviceDeleter> DeviceDriverPtr;
378 #endif // CTS_USES_VULKANSC
379 
380 // Defined in vkWsiPlatform.hpp
381 namespace wsi
382 {
383 class Display;
384 } // wsi
385 
386 /*--------------------------------------------------------------------*//*!
387  * \brief Vulkan platform interface
388  *//*--------------------------------------------------------------------*/
389 class Platform
390 {
391 public:
392 	enum LibraryType
393 	{
394 		LIBRARY_TYPE_VULKAN						= 0,
395 		LIBRARY_TYPE_VULKAN_VIDEO_DECODE_PARSER,
396 
397 		LIBRARY_TYPE_LAST
398 	};
399 
Platform(void)400 							Platform			(void) {}
~Platform(void)401 							~Platform			(void) {}
402 #if (DE_OS == DE_OS_WIN32) || (DE_OS == DE_OS_UNIX)
403 	virtual Library*		createLibrary		(LibraryType libraryType = LIBRARY_TYPE_VULKAN, const char* libraryPath = DE_NULL) const = 0;
404 #else
405 	virtual Library*		createLibrary		(const char* libraryPath = DE_NULL) const = 0;
406 #endif
407 
408 	virtual wsi::Display*	createWsiDisplay	(wsi::Type wsiType) const;
409 	virtual bool			hasDisplay			(wsi::Type wsiType) const;
410 	virtual void			describePlatform	(std::ostream& dst) const;
411 };
412 
413 } // vk
414 
415 #endif // _VKPLATFORM_HPP
416