• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Vulkan platform abstraction.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vkPlatform.hpp"
25 #include "tcuFunctionLibrary.hpp"
26 #ifdef CTS_USES_VULKANSC
27 #include "vkQueryUtil.hpp"
28 #include "vkSafetyCriticalUtil.hpp"
29 #endif // CTS_USES_VULKANSC
30 
31 #include "deMemory.h"
32 
33 namespace vk
34 {
35 
PlatformDriver(const tcu::FunctionLibrary & library)36 PlatformDriver::PlatformDriver (const tcu::FunctionLibrary& library)
37 {
38 	m_vk.getInstanceProcAddr	= (GetInstanceProcAddrFunc)library.getFunction("vkGetInstanceProcAddr");
39 
40 #define GET_PROC_ADDR(NAME) m_vk.getInstanceProcAddr(DE_NULL, NAME)
41 #include "vkInitPlatformFunctionPointers.inl"
42 #undef GET_PROC_ADDR
43 }
44 
~PlatformDriver(void)45 PlatformDriver::~PlatformDriver (void)
46 {
47 }
48 
InstanceDriver(const PlatformInterface & platformInterface,VkInstance instance)49 InstanceDriver::InstanceDriver (const PlatformInterface&		platformInterface,
50 								VkInstance						instance)
51 {
52 	loadFunctions(platformInterface, instance);
53 }
54 
loadFunctions(const PlatformInterface & platformInterface,VkInstance instance)55 void InstanceDriver::loadFunctions (const PlatformInterface&	platformInterface,
56 									VkInstance					instance)
57 {
58 #define GET_PROC_ADDR(NAME) platformInterface.getInstanceProcAddr(instance, NAME)
59 #include "vkInitInstanceFunctionPointers.inl"
60 #undef GET_PROC_ADDR
61 }
62 
~InstanceDriver(void)63 InstanceDriver::~InstanceDriver (void)
64 {
65 }
66 
67 #ifdef CTS_USES_VULKANSC
68 
InstanceDriverSC(const PlatformInterface & platformInterface,VkInstance instance,const tcu::CommandLine & cmdLine,de::SharedPtr<vk::ResourceInterface> resourceInterface)69 InstanceDriverSC::InstanceDriverSC (const PlatformInterface&				platformInterface,
70 									VkInstance								instance,
71 									const tcu::CommandLine&					cmdLine,
72 									de::SharedPtr<vk::ResourceInterface>	resourceInterface)
73 	: InstanceDriver(platformInterface, instance)
74 	, m_normalMode(cmdLine.isSubProcess())
75 	, m_resourceInterface(resourceInterface)
76 {
77 }
78 
prepareDeviceGroupPatch(const VkDeviceCreateInfo * pCreateInfo)79 std::pair<void**, void*> prepareDeviceGroupPatch (const VkDeviceCreateInfo* pCreateInfo)
80 {
81 	struct StructureBase
82 	{
83 		VkStructureType			sType;
84 		const StructureBase*	pNext;
85 	};
86 
87 	const StructureBase* prev = DE_NULL;
88 	const StructureBase* curr = reinterpret_cast<const StructureBase*>(pCreateInfo);
89 
90 	while (curr)
91 	{
92 		if (curr->sType == VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO)
93 		{
94 			if (prev != DE_NULL)
95 				return std::pair<void**, void*>((void**)&prev->pNext, (void*)curr);
96 		}
97 
98 		prev = curr;
99 		curr = reinterpret_cast<const StructureBase*>(curr->pNext);
100 	}
101 
102 	return std::pair<void**, void*>(DE_NULL, DE_NULL);
103 }
104 
createDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice) const105 VkResult InstanceDriverSC::createDevice (VkPhysicalDevice						physicalDevice,
106 										 const VkDeviceCreateInfo*				pCreateInfo,
107 										 const VkAllocationCallbacks*			pAllocator,
108 										 VkDevice*								pDevice) const
109 {
110 	std::pair<void*, void*>	patch		= prepareDeviceGroupPatch(pCreateInfo);
111 	const bool				patchNeeded	= patch.first != DE_NULL;
112 
113 	// Structure restored from JSON does not contain valid physicalDevice.
114 	// Workaround: set to delivered physicalDevice argument.
115 	if (patchNeeded && m_normalMode)
116 	{
117 		VkDeviceGroupDeviceCreateInfo* p = (VkDeviceGroupDeviceCreateInfo*)patch.second;
118 
119 		DE_ASSERT(p->physicalDeviceCount == 1);
120 
121 		if (p->physicalDeviceCount == 1 && p->pPhysicalDevices[0] == DE_NULL)
122 		{
123 			VkPhysicalDevice* v = const_cast<VkPhysicalDevice*>(p->pPhysicalDevices);
124 			v[0] = physicalDevice;
125 		}
126 	}
127 
128 	VkResult result = InstanceDriver::createDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
129 
130 	// Vulkan loader destroys pNext value when VkDeviceGroupDeviceCreateInfo is present in the chain.
131 	// Workaround: Set pNext value to VkDeviceGroupDeviceCreateInfo structure back.
132 	if (patchNeeded)
133 	{
134 		void** addr = (void**)patch.first;
135 		*addr = patch.second;
136 	}
137 
138 	if (result == VK_SUCCESS && !m_normalMode)
139 	{
140 		m_resourceInterface->registerDeviceFeatures(*pDevice, pCreateInfo);
141 	}
142 	return result;
143 }
144 
145 #endif // CTS_USES_VULKANSC
146 
DeviceDriver(const PlatformInterface & platformInterface,VkInstance instance,VkDevice device,uint32_t usedApiVersion)147 DeviceDriver::DeviceDriver (const PlatformInterface&	platformInterface,
148 							VkInstance					instance,
149 							VkDevice					device,
150 							uint32_t					usedApiVersion)
151 {
152 	deMemset(&m_vk, 0, sizeof(m_vk));
153 
154 	m_vk.getDeviceProcAddr = (GetDeviceProcAddrFunc)platformInterface.getInstanceProcAddr(instance, "vkGetDeviceProcAddr");
155 
156 #define GET_PROC_ADDR(NAME) m_vk.getDeviceProcAddr(device, NAME)
157 #include "vkInitDeviceFunctionPointers.inl"
158 #undef GET_PROC_ADDR
159 }
160 
~DeviceDriver(void)161 DeviceDriver::~DeviceDriver (void)
162 {
163 }
164 
165 #ifdef CTS_USES_VULKANSC
createShaderModule(VkDevice device,const VkShaderModuleCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkShaderModule * pShaderModule) const166 VkResult DeviceDriver::createShaderModule (VkDevice							device,
167 										   const VkShaderModuleCreateInfo*	pCreateInfo,
168 										   const VkAllocationCallbacks*		pAllocator,
169 										   VkShaderModule*					pShaderModule) const
170 {
171 	// this should not be called - Vulkan SC implementation uses DeviceDriverSC instead
172 	DE_UNREF(device);
173 	DE_UNREF(pCreateInfo);
174 	DE_UNREF(pAllocator);
175 	DE_UNREF(pShaderModule);
176 	TCU_THROW(InternalError, "Wrong DeviceDriver called in VulkanSC");
177 }
178 #endif
179 
180 #ifdef CTS_USES_VULKANSC
181 
DeviceDriverSC(const PlatformInterface & platformInterface,VkInstance instance,VkDevice device,const tcu::CommandLine & cmdLine,de::SharedPtr<vk::ResourceInterface> resourceInterface,const VkPhysicalDeviceVulkanSC10Properties & physicalDeviceVulkanSC10Properties,const VkPhysicalDeviceProperties & physicalDeviceProperties,const uint32_t usedApiVersion)182 DeviceDriverSC::DeviceDriverSC (const PlatformInterface&					platformInterface,
183 								VkInstance									instance,
184 								VkDevice									device,
185 								const tcu::CommandLine&						cmdLine,
186 								de::SharedPtr<vk::ResourceInterface>		resourceInterface,
187 								const VkPhysicalDeviceVulkanSC10Properties&	physicalDeviceVulkanSC10Properties,
188 								const VkPhysicalDeviceProperties&			physicalDeviceProperties,
189 								const uint32_t								usedApiVersion)
190 	: DeviceDriver(platformInterface, instance, device, usedApiVersion)
191 	, m_normalMode(cmdLine.isSubProcess())
192 	, m_resourceInterface(resourceInterface)
193 	, m_physicalDeviceVulkanSC10Properties(physicalDeviceVulkanSC10Properties)
194 	, m_physicalDeviceProperties(physicalDeviceProperties)
195 	, m_commandDefaultSize((VkDeviceSize)cmdLine.getCommandDefaultSize())
196 	, m_commandBufferMinimumSize( de::max((VkDeviceSize)cmdLine.getCommandDefaultSize(), (VkDeviceSize)cmdLine.getCommandBufferMinSize()))
197 	, m_commandPoolMinimumSize((VkDeviceSize)cmdLine.getCommandPoolMinSize())
198 {
199 	if(!cmdLine.isSubProcess())
200 		m_falseMemory.resize(64u * 1024u * 1024u, 0u);
201 	m_resourceInterface->initDevice(*this, device);
202 }
203 
~DeviceDriverSC(void)204 DeviceDriverSC::~DeviceDriverSC(void)
205 {
206 }
207 
destroyDeviceHandler(VkDevice device,const VkAllocationCallbacks * pAllocator) const208 void DeviceDriverSC::destroyDeviceHandler (VkDevice								device,
209 										   const VkAllocationCallbacks*			pAllocator) const
210 {
211 	DE_UNREF(pAllocator);
212 	m_resourceInterface->unregisterDeviceFeatures(device);
213 }
214 
createDescriptorSetLayoutHandlerNorm(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout) const215 VkResult DeviceDriverSC::createDescriptorSetLayoutHandlerNorm (VkDevice									device,
216 															   const VkDescriptorSetLayoutCreateInfo*	pCreateInfo,
217 															   const VkAllocationCallbacks*				pAllocator,
218 															   VkDescriptorSetLayout*					pSetLayout) const
219 {
220 	DDSTAT_LOCK();
221 	VkResult result = m_vk.createDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
222 	m_resourceInterface->registerObjectHash(pSetLayout->getInternal(), calculateDescriptorSetLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
223 	return result;
224 }
225 
createDescriptorSetLayoutHandlerStat(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout) const226 void DeviceDriverSC::createDescriptorSetLayoutHandlerStat (VkDevice									device,
227 														   const VkDescriptorSetLayoutCreateInfo*	pCreateInfo,
228 														   const VkAllocationCallbacks*				pAllocator,
229 														   VkDescriptorSetLayout*					pSetLayout) const
230 {
231 	DE_UNREF(device);
232 	DE_UNREF(pAllocator);
233 
234 	DDSTAT_LOCK();
235 	DDSTAT_HANDLE_CREATE(descriptorSetLayoutRequestCount,1);
236 	DDSTAT_HANDLE_CREATE(descriptorSetLayoutBindingRequestCount, pCreateInfo->bindingCount);
237 	deUint32 immutableSamplersCount = 0u;
238 	for (deUint32 i = 0; i < pCreateInfo->bindingCount; ++i)
239 	{
240 		m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit = de::max(m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit, pCreateInfo->pBindings[i].binding + 1);
241 		if( ( pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER )
242 			&& pCreateInfo->pBindings[i].pImmutableSamplers != DE_NULL )
243 			immutableSamplersCount += pCreateInfo->pBindings[i].descriptorCount;
244 	}
245 	m_resourceInterface->getStatMax().maxImmutableSamplersPerDescriptorSetLayout = de::max(m_resourceInterface->getStatMax().maxImmutableSamplersPerDescriptorSetLayout, immutableSamplersCount);
246 
247 	*pSetLayout = VkDescriptorSetLayout(m_resourceInterface->incResourceCounter());
248 	m_descriptorSetLayouts.insert({ *pSetLayout, *pCreateInfo });
249 	m_resourceInterface->registerObjectHash(pSetLayout->getInternal(), calculateDescriptorSetLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
250 	m_resourceInterface->createDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
251 }
252 
destroyDescriptorSetLayoutHandler(VkDevice device,VkDescriptorSetLayout descriptorSetLayout,const VkAllocationCallbacks * pAllocator) const253 void DeviceDriverSC::destroyDescriptorSetLayoutHandler (VkDevice								device,
254 														VkDescriptorSetLayout					descriptorSetLayout,
255 														const VkAllocationCallbacks*			pAllocator) const
256 {
257 	DE_UNREF(device);
258 	DE_UNREF(pAllocator);
259 
260 	DDSTAT_LOCK();
261 	auto it = m_descriptorSetLayouts.find(descriptorSetLayout);
262 	if (it != end(m_descriptorSetLayouts))
263 	{
264 		DDSTAT_HANDLE_DESTROY(descriptorSetLayoutRequestCount, 1);
265 		DDSTAT_HANDLE_DESTROY(descriptorSetLayoutBindingRequestCount, it->second.bindingCount);
266 		m_descriptorSetLayouts.erase(it);
267 	}
268 }
269 
allocateDescriptorSetsHandlerStat(VkDevice device,const VkDescriptorSetAllocateInfo * pAllocateInfo,VkDescriptorSet * pDescriptorSets) const270 void DeviceDriverSC::allocateDescriptorSetsHandlerStat (VkDevice							device,
271 														const VkDescriptorSetAllocateInfo*	pAllocateInfo,
272 														VkDescriptorSet*					pDescriptorSets) const
273 {
274 	DE_UNREF(device);
275 
276 	DDSTAT_LOCK();
277 	DDSTAT_HANDLE_CREATE(descriptorSetRequestCount, pAllocateInfo->descriptorSetCount);
278 	for (deUint32 i = 0; i < pAllocateInfo->descriptorSetCount; ++i)
279 		pDescriptorSets[i] = Handle<HANDLE_TYPE_DESCRIPTOR_SET>(m_resourceInterface->incResourceCounter());
280 	for (deUint32 i = 0; i < pAllocateInfo->descriptorSetCount; ++i)
281 		m_descriptorSetsInPool[pDescriptorSets[i]] = pAllocateInfo->descriptorPool;
282 }
283 
freeDescriptorSetsHandlerStat(VkDevice device,VkDescriptorPool descriptorPool,uint32_t descriptorSetCount,const VkDescriptorSet * pDescriptorSets) const284 void DeviceDriverSC::freeDescriptorSetsHandlerStat (VkDevice				device,
285 													VkDescriptorPool		descriptorPool,
286 													uint32_t				descriptorSetCount,
287 													const VkDescriptorSet*	pDescriptorSets) const
288 {
289 	DE_UNREF(device);
290 	DE_UNREF(descriptorPool);
291 
292 	DDSTAT_LOCK();
293 	for (deUint32 i = 0; i < descriptorSetCount; ++i)
294 		DDSTAT_HANDLE_DESTROY_IF(pDescriptorSets[i], descriptorSetRequestCount, 1);
295 	for (deUint32 i = 0; i < descriptorSetCount; ++i)
296 		m_descriptorSetsInPool.erase(pDescriptorSets[i]);
297 }
298 
resetDescriptorPoolHandlerStat(VkDevice device,VkDescriptorPool descriptorPool,VkDescriptorPoolResetFlags flags) const299 void DeviceDriverSC::resetDescriptorPoolHandlerStat (VkDevice					device,
300 													 VkDescriptorPool			descriptorPool,
301 													 VkDescriptorPoolResetFlags	flags) const
302 {
303 	DE_UNREF(device);
304 	DE_UNREF(flags);
305 
306 	DDSTAT_LOCK();
307 	deUint32 removedCount = 0u;
308 	for (auto it = begin(m_descriptorSetsInPool); it != end(m_descriptorSetsInPool);)
309 	{
310 		if (it->second.getInternal() == descriptorPool.getInternal())
311 		{
312 			m_descriptorSetsInPool.erase(it++);
313 			removedCount++;
314 		}
315 		else
316 			++it;
317 	}
318 	DDSTAT_HANDLE_DESTROY(descriptorSetRequestCount, removedCount);
319 }
320 
createImageViewHandler(VkDevice device,const VkImageViewCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImageView * pView) const321 void DeviceDriverSC::createImageViewHandler (VkDevice						device,
322 											 const VkImageViewCreateInfo*	pCreateInfo,
323 											 const VkAllocationCallbacks*	pAllocator,
324 											 VkImageView*					pView) const
325 {
326 	DE_UNREF(device);
327 	DE_UNREF(pAllocator);
328 
329 	DDSTAT_LOCK();
330 	DDSTAT_HANDLE_CREATE(imageViewRequestCount,1);
331 	if (pCreateInfo->subresourceRange.layerCount > 1)
332 		DDSTAT_HANDLE_CREATE(layeredImageViewRequestCount,1);
333 
334 	const auto& limits = m_physicalDeviceProperties.limits;
335 
336 	deUint32 levelCount = pCreateInfo->subresourceRange.levelCount;
337 	if (levelCount == VK_REMAINING_MIP_LEVELS)
338 	{
339 		deUint32 maxDimensions = limits.maxImageDimension1D;
340 		maxDimensions = de::max(maxDimensions, limits.maxImageDimension2D);
341 		maxDimensions = de::max(maxDimensions, limits.maxImageDimension3D);
342 		maxDimensions = de::max(maxDimensions, limits.maxImageDimensionCube);
343 		levelCount = deLog2Floor32(maxDimensions) + 1;
344 	}
345 
346 	uint32_t layerCount = pCreateInfo->subresourceRange.layerCount;
347 	if (layerCount == VK_REMAINING_ARRAY_LAYERS)
348 		layerCount = limits.maxImageArrayLayers;
349 
350 	m_resourceInterface->getStatMax().maxImageViewMipLevels		= de::max(m_resourceInterface->getStatMax().maxImageViewMipLevels, levelCount);
351 	m_resourceInterface->getStatMax().maxImageViewArrayLayers	= de::max(m_resourceInterface->getStatMax().maxImageViewArrayLayers, layerCount);
352 	if (pCreateInfo->subresourceRange.layerCount > 1)
353 		m_resourceInterface->getStatMax().maxLayeredImageViewMipLevels = de::max(m_resourceInterface->getStatMax().maxLayeredImageViewMipLevels, levelCount);
354 
355 	*pView = VkImageView(m_resourceInterface->incResourceCounter());
356 	m_imageViews.insert({ *pView, *pCreateInfo });
357 }
358 
destroyImageViewHandler(VkDevice device,VkImageView imageView,const VkAllocationCallbacks * pAllocator) const359 void DeviceDriverSC::destroyImageViewHandler (VkDevice						device,
360 											  VkImageView					imageView,
361 											  const VkAllocationCallbacks*	pAllocator) const
362 {
363 	DE_UNREF(device);
364 	DE_UNREF(pAllocator);
365 
366 	DDSTAT_LOCK();
367 	auto it = m_imageViews.find(imageView);
368 	if (it != end(m_imageViews))
369 	{
370 		DDSTAT_HANDLE_DESTROY(imageViewRequestCount, 1);
371 		if(it->second.subresourceRange.layerCount > 1)
372 			DDSTAT_HANDLE_DESTROY(layeredImageViewRequestCount,1);
373 		m_imageViews.erase(it);
374 	}
375 }
376 
createQueryPoolHandler(VkDevice device,const VkQueryPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkQueryPool * pQueryPool) const377 void DeviceDriverSC::createQueryPoolHandler (VkDevice						device,
378 											 const VkQueryPoolCreateInfo*	pCreateInfo,
379 											 const VkAllocationCallbacks*	pAllocator,
380 											 VkQueryPool*					pQueryPool) const
381 {
382 	DE_UNREF(device);
383 	DE_UNREF(pAllocator);
384 
385 	DDSTAT_LOCK();
386 	DDSTAT_HANDLE_CREATE(queryPoolRequestCount, 1);
387 	switch (pCreateInfo->queryType)
388 	{
389 		case VK_QUERY_TYPE_OCCLUSION:
390 			m_resourceInterface->getStatMax().maxOcclusionQueriesPerPool			= de::max(m_resourceInterface->getStatMax().maxOcclusionQueriesPerPool, pCreateInfo->queryCount);
391 			break;
392 		case VK_QUERY_TYPE_PIPELINE_STATISTICS:
393 			m_resourceInterface->getStatMax().maxPipelineStatisticsQueriesPerPool	= de::max(m_resourceInterface->getStatMax().maxPipelineStatisticsQueriesPerPool, pCreateInfo->queryCount);
394 			break;
395 		case VK_QUERY_TYPE_TIMESTAMP:
396 			m_resourceInterface->getStatMax().maxTimestampQueriesPerPool			= de::max(m_resourceInterface->getStatMax().maxTimestampQueriesPerPool, pCreateInfo->queryCount);
397 			break;
398 		default:
399 			break;
400 	}
401 	// We don't have to track queryPool resources as we do with image views because they're not removed from memory in Vulkan SC.
402 	*pQueryPool = VkQueryPool(m_resourceInterface->incResourceCounter());
403 }
404 
createPipelineLayoutHandlerNorm(VkDevice device,const VkPipelineLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkPipelineLayout * pPipelineLayout) const405 VkResult DeviceDriverSC::createPipelineLayoutHandlerNorm (VkDevice								device,
406 														  const VkPipelineLayoutCreateInfo*		pCreateInfo,
407 														  const VkAllocationCallbacks*			pAllocator,
408 														  VkPipelineLayout*						pPipelineLayout) const
409 {
410 	DDSTAT_LOCK();
411 	VkResult result = m_vk.createPipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
412 	m_resourceInterface->registerObjectHash(pPipelineLayout->getInternal(), calculatePipelineLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
413 	return result;
414 }
415 
createPipelineLayoutHandlerStat(VkDevice device,const VkPipelineLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkPipelineLayout * pPipelineLayout) const416 void DeviceDriverSC::createPipelineLayoutHandlerStat (VkDevice								device,
417 													  const VkPipelineLayoutCreateInfo*		pCreateInfo,
418 													  const VkAllocationCallbacks*			pAllocator,
419 													  VkPipelineLayout*						pPipelineLayout) const
420 {
421 	DDSTAT_LOCK();
422 	DDSTAT_HANDLE_CREATE(pipelineLayoutRequestCount, 1);
423 	*pPipelineLayout = VkPipelineLayout(m_resourceInterface->incResourceCounter());
424 	m_resourceInterface->registerObjectHash(pPipelineLayout->getInternal(), calculatePipelineLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
425 	m_resourceInterface->createPipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
426 }
427 
createGraphicsPipelinesHandlerNorm(VkDevice device,VkPipelineCache pipelineCache,deUint32 createInfoCount,const VkGraphicsPipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const428 VkResult DeviceDriverSC::createGraphicsPipelinesHandlerNorm (VkDevice								device,
429 															 VkPipelineCache						pipelineCache,
430 															 deUint32								createInfoCount,
431 															 const VkGraphicsPipelineCreateInfo*	pCreateInfos,
432 															 const VkAllocationCallbacks*			pAllocator,
433 															 VkPipeline*							pPipelines) const
434 {
435 	DDSTAT_LOCK();
436 	return m_resourceInterface->createGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines, m_normalMode);
437 }
438 
createGraphicsPipelinesHandlerStat(VkDevice device,VkPipelineCache pipelineCache,deUint32 createInfoCount,const VkGraphicsPipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const439 void DeviceDriverSC::createGraphicsPipelinesHandlerStat (VkDevice									device,
440 														 VkPipelineCache							pipelineCache,
441 														 deUint32									createInfoCount,
442 														 const VkGraphicsPipelineCreateInfo*		pCreateInfos,
443 														 const VkAllocationCallbacks*				pAllocator,
444 														 VkPipeline*								pPipelines) const
445 {
446 	DE_UNREF(device);
447 	DE_UNREF(pipelineCache);
448 	DE_UNREF(pAllocator);
449 
450 	DDSTAT_LOCK();
451 	DDSTAT_HANDLE_CREATE(graphicsPipelineRequestCount, createInfoCount);
452 	for (deUint32 i = 0; i < createInfoCount; ++i)
453 	{
454 		pPipelines[i] = VkPipeline(m_resourceInterface->incResourceCounter());
455 		m_graphicsPipelines.insert({ pPipelines[i], pCreateInfos[i] });
456 	}
457 
458 	m_resourceInterface->createGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines, m_normalMode);
459 }
460 
createComputePipelinesHandlerNorm(VkDevice device,VkPipelineCache pipelineCache,deUint32 createInfoCount,const VkComputePipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const461 VkResult DeviceDriverSC::createComputePipelinesHandlerNorm (VkDevice								device,
462 															VkPipelineCache							pipelineCache,
463 															deUint32								createInfoCount,
464 															const VkComputePipelineCreateInfo*		pCreateInfos,
465 															const VkAllocationCallbacks*			pAllocator,
466 															VkPipeline*								pPipelines) const
467 {
468 	DDSTAT_LOCK();
469 	return m_resourceInterface->createComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines, m_normalMode);
470 }
471 
createComputePipelinesHandlerStat(VkDevice device,VkPipelineCache pipelineCache,deUint32 createInfoCount,const VkComputePipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const472 void DeviceDriverSC::createComputePipelinesHandlerStat (VkDevice									device,
473 														VkPipelineCache								pipelineCache,
474 														deUint32									createInfoCount,
475 														const VkComputePipelineCreateInfo*			pCreateInfos,
476 														const VkAllocationCallbacks*				pAllocator,
477 														VkPipeline*									pPipelines) const
478 {
479 	DE_UNREF(device);
480 	DE_UNREF(pipelineCache);
481 	DE_UNREF(pAllocator);
482 
483 	DDSTAT_LOCK();
484 	DDSTAT_HANDLE_CREATE(computePipelineRequestCount, createInfoCount);
485 	for (deUint32 i = 0; i < createInfoCount; ++i)
486 	{
487 		pPipelines[i] = VkPipeline(m_resourceInterface->incResourceCounter());
488 		m_computePipelines.insert({ pPipelines[i], pCreateInfos[i] });
489 	}
490 
491 	m_resourceInterface->createComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines, m_normalMode);
492 }
493 
destroyPipelineHandler(VkDevice device,VkPipeline pipeline,const VkAllocationCallbacks * pAllocator) const494 void DeviceDriverSC::destroyPipelineHandler (VkDevice						device,
495 											 VkPipeline						pipeline,
496 											 const VkAllocationCallbacks*	pAllocator) const
497 {
498 	DE_UNREF(device);
499 	DE_UNREF(pAllocator);
500 
501 	DDSTAT_LOCK();
502 	auto it = m_graphicsPipelines.find(pipeline);
503 	if (it != end(m_graphicsPipelines))
504 	{
505 		DDSTAT_HANDLE_DESTROY(graphicsPipelineRequestCount, 1);
506 		m_graphicsPipelines.erase(it);
507 		m_resourceInterface->destroyPipeline(device, pipeline, pAllocator);
508 		return;
509 	}
510 
511 	auto it2 = m_computePipelines.find(pipeline);
512 	if (it2 != end(m_computePipelines))
513 	{
514 		DDSTAT_HANDLE_DESTROY(computePipelineRequestCount, 1);
515 		m_resourceInterface->destroyPipeline(device, pipeline, pAllocator);
516 		m_computePipelines.erase(it2);
517 	}
518 }
519 
createFramebufferHandlerNorm(VkDevice device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer) const520 VkResult DeviceDriverSC::createFramebufferHandlerNorm (VkDevice								device,
521 													   const VkFramebufferCreateInfo*		pCreateInfo,
522 													   const VkAllocationCallbacks*			pAllocator,
523 													   VkFramebuffer*						pFramebuffer) const
524 {
525 	DDSTAT_LOCK();
526 	checkFramebufferSupport(pCreateInfo);
527 	const VkResult result = m_vk.createFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
528 	return result;
529 }
530 
createFramebufferHandlerStat(VkDevice device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer) const531 void DeviceDriverSC::createFramebufferHandlerStat (VkDevice								device,
532 												   const VkFramebufferCreateInfo*		pCreateInfo,
533 												   const VkAllocationCallbacks*			pAllocator,
534 												   VkFramebuffer*						pFramebuffer) const
535 {
536 	DE_UNREF(device);
537 	DE_UNREF(pAllocator);
538 
539 	DDSTAT_LOCK();
540 	checkFramebufferSupport(pCreateInfo);
541 	DDSTAT_HANDLE_CREATE(framebufferRequestCount,1);
542 
543 	*pFramebuffer = Handle<HANDLE_TYPE_FRAMEBUFFER>(m_resourceInterface->incResourceCounter());
544 }
545 
createRenderPassHandlerNorm(VkDevice device,const VkRenderPassCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const546 VkResult DeviceDriverSC::createRenderPassHandlerNorm (VkDevice						device,
547 													  const VkRenderPassCreateInfo*	pCreateInfo,
548 													  const VkAllocationCallbacks*	pAllocator,
549 													  VkRenderPass*					pRenderPass) const
550 {
551 	DDSTAT_LOCK();
552 
553 	checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
554 	for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
555 		checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount, pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
556 
557 	VkResult result = m_vk.createRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
558 	m_resourceInterface->registerObjectHash(pRenderPass->getInternal(), calculateRenderPassHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
559 	return result;
560 }
561 
createRenderPassHandlerStat(VkDevice device,const VkRenderPassCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const562 void DeviceDriverSC::createRenderPassHandlerStat (VkDevice						device,
563 												  const VkRenderPassCreateInfo*	pCreateInfo,
564 												  const VkAllocationCallbacks*	pAllocator,
565 												  VkRenderPass*					pRenderPass) const
566 {
567 	DE_UNREF(device);
568 	DE_UNREF(pAllocator);
569 
570 	DDSTAT_LOCK();
571 
572 	checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
573 	for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
574 		checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount, pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
575 
576 	DDSTAT_HANDLE_CREATE(renderPassRequestCount, 1);
577 	DDSTAT_HANDLE_CREATE(subpassDescriptionRequestCount,	pCreateInfo->subpassCount);
578 	DDSTAT_HANDLE_CREATE(attachmentDescriptionRequestCount,	pCreateInfo->attachmentCount);
579 
580 	*pRenderPass = VkRenderPass(m_resourceInterface->incResourceCounter());
581 	m_renderPasses.insert({ *pRenderPass, *pCreateInfo });
582 	m_resourceInterface->registerObjectHash(pRenderPass->getInternal(), calculateRenderPassHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
583 	m_resourceInterface->createRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
584 }
585 
createRenderPass2HandlerNorm(VkDevice device,const VkRenderPassCreateInfo2 * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const586 VkResult DeviceDriverSC::createRenderPass2HandlerNorm (VkDevice							device,
587 													   const VkRenderPassCreateInfo2*	pCreateInfo,
588 													   const VkAllocationCallbacks*		pAllocator,
589 													   VkRenderPass*					pRenderPass) const
590 {
591 	DDSTAT_LOCK();
592 
593 	checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
594 	for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
595 		checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount, pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
596 
597 	VkResult result = m_vk.createRenderPass2(device, pCreateInfo, pAllocator, pRenderPass);
598 	m_resourceInterface->registerObjectHash(pRenderPass->getInternal(), calculateRenderPass2Hash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
599 	return result;
600 }
601 
createRenderPass2HandlerStat(VkDevice device,const VkRenderPassCreateInfo2 * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const602 void DeviceDriverSC::createRenderPass2HandlerStat (VkDevice							device,
603 												   const VkRenderPassCreateInfo2*	pCreateInfo,
604 												   const VkAllocationCallbacks*		pAllocator,
605 												   VkRenderPass*					pRenderPass) const
606 {
607 	DE_UNREF(device);
608 	DE_UNREF(pAllocator);
609 
610 	DDSTAT_LOCK();
611 
612 	checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
613 	for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
614 		checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount, pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
615 
616 	DDSTAT_HANDLE_CREATE(renderPassRequestCount, 1);
617 	DDSTAT_HANDLE_CREATE(subpassDescriptionRequestCount,	pCreateInfo->subpassCount);
618 	DDSTAT_HANDLE_CREATE(attachmentDescriptionRequestCount,	pCreateInfo->attachmentCount);
619 
620 	*pRenderPass = VkRenderPass(m_resourceInterface->incResourceCounter());
621 	m_renderPasses2.insert({ *pRenderPass, *pCreateInfo });
622 	m_resourceInterface->registerObjectHash(pRenderPass->getInternal(), calculateRenderPass2Hash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
623 	m_resourceInterface->createRenderPass2(device, pCreateInfo, pAllocator, pRenderPass);
624 }
625 
destroyRenderPassHandler(VkDevice device,VkRenderPass renderPass,const VkAllocationCallbacks * pAllocator) const626 void DeviceDriverSC::destroyRenderPassHandler (VkDevice						device,
627 											   VkRenderPass					renderPass,
628 											   const VkAllocationCallbacks*	pAllocator) const
629 {
630 	DE_UNREF(device);
631 	DE_UNREF(pAllocator);
632 
633 	DDSTAT_LOCK();
634 	auto it = m_renderPasses.find(renderPass);
635 	if (it != end(m_renderPasses))
636 	{
637 		DDSTAT_HANDLE_DESTROY(renderPassRequestCount, 1);
638 		DDSTAT_HANDLE_DESTROY(subpassDescriptionRequestCount, it->second.subpassCount);
639 		DDSTAT_HANDLE_DESTROY(attachmentDescriptionRequestCount, it->second.attachmentCount);
640 		m_renderPasses.erase(it);
641 		return;
642 	}
643 
644 	auto it2 = m_renderPasses2.find(renderPass);
645 	if (it2 != end(m_renderPasses2))
646 	{
647 		DDSTAT_HANDLE_DESTROY(renderPassRequestCount, 1);
648 		DDSTAT_HANDLE_DESTROY(subpassDescriptionRequestCount, it2->second.subpassCount);
649 		DDSTAT_HANDLE_DESTROY(attachmentDescriptionRequestCount, it2->second.attachmentCount);
650 		m_renderPasses2.erase(it2);
651 	}
652 }
653 
createSamplerHandlerNorm(VkDevice device,const VkSamplerCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSampler * pSampler) const654 VkResult DeviceDriverSC::createSamplerHandlerNorm (VkDevice							device,
655 												   const VkSamplerCreateInfo*		pCreateInfo,
656 												   const VkAllocationCallbacks*		pAllocator,
657 												   VkSampler*						pSampler) const
658 {
659 	DDSTAT_LOCK();
660 	VkResult result = m_vk.createSampler(device, pCreateInfo, pAllocator, pSampler);
661 	m_resourceInterface->registerObjectHash(pSampler->getInternal(), calculateSamplerHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
662 	return result;
663 }
664 
createSamplerHandlerStat(VkDevice device,const VkSamplerCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSampler * pSampler) const665 void DeviceDriverSC::createSamplerHandlerStat (VkDevice							device,
666 											   const VkSamplerCreateInfo*		pCreateInfo,
667 											   const VkAllocationCallbacks*		pAllocator,
668 											   VkSampler*						pSampler) const
669 {
670 	DDSTAT_LOCK();
671 	DDSTAT_HANDLE_CREATE(samplerRequestCount, 1);
672 	*pSampler = VkSampler(m_resourceInterface->incResourceCounter());
673 	m_resourceInterface->registerObjectHash(pSampler->getInternal(), calculateSamplerHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
674 	m_resourceInterface->createSampler(device, pCreateInfo, pAllocator, pSampler);
675 }
676 
createSamplerYcbcrConversionHandlerNorm(VkDevice device,const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversion * pYcbcrConversion) const677 VkResult DeviceDriverSC::createSamplerYcbcrConversionHandlerNorm (VkDevice								device,
678 																  const VkSamplerYcbcrConversionCreateInfo*	pCreateInfo,
679 																  const VkAllocationCallbacks*			pAllocator,
680 																  VkSamplerYcbcrConversion*				pYcbcrConversion) const
681 {
682 	DDSTAT_LOCK();
683 	VkResult result = m_vk.createSamplerYcbcrConversion(device, pCreateInfo, pAllocator, pYcbcrConversion);
684 	m_resourceInterface->registerObjectHash(pYcbcrConversion->getInternal(), calculateSamplerYcbcrConversionHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
685 	return result;
686 }
687 
createSamplerYcbcrConversionHandlerStat(VkDevice device,const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversion * pYcbcrConversion) const688 void DeviceDriverSC::createSamplerYcbcrConversionHandlerStat (VkDevice								device,
689 															  const VkSamplerYcbcrConversionCreateInfo*	pCreateInfo,
690 															  const VkAllocationCallbacks*			pAllocator,
691 															  VkSamplerYcbcrConversion*				pYcbcrConversion) const
692 {
693 	DDSTAT_LOCK();
694 	DDSTAT_HANDLE_CREATE(samplerYcbcrConversionRequestCount, 1);
695 	*pYcbcrConversion = VkSamplerYcbcrConversion(m_resourceInterface->incResourceCounter());
696 	m_resourceInterface->registerObjectHash(pYcbcrConversion->getInternal(), calculateSamplerYcbcrConversionHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
697 	m_resourceInterface->createSamplerYcbcrConversion(device, pCreateInfo, pAllocator, pYcbcrConversion);
698 }
699 
getDescriptorSetLayoutSupportHandler(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,VkDescriptorSetLayoutSupport * pSupport) const700 void DeviceDriverSC::getDescriptorSetLayoutSupportHandler (VkDevice									device,
701 														   const VkDescriptorSetLayoutCreateInfo*	pCreateInfo,
702 														   VkDescriptorSetLayoutSupport*			pSupport) const
703 {
704 	DE_UNREF(device);
705 
706 	DDSTAT_LOCK();
707 	for (deUint32 i = 0; i < pCreateInfo->bindingCount; ++i)
708 		m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit = de::max(m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit, pCreateInfo->pBindings[i].binding + 1);
709 	pSupport->supported = VK_TRUE;
710 }
711 
createShaderModule(VkDevice device,const VkShaderModuleCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkShaderModule * pShaderModule) const712 VkResult DeviceDriverSC::createShaderModule (VkDevice							device,
713 											 const VkShaderModuleCreateInfo*	pCreateInfo,
714 											 const VkAllocationCallbacks*		pAllocator,
715 											 VkShaderModule*					pShaderModule) const
716 {
717 	DDSTAT_LOCK();
718 	return m_resourceInterface->createShaderModule(device, pCreateInfo, pAllocator, pShaderModule, m_normalMode);
719 }
720 
createCommandPoolHandlerNorm(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool) const721 VkResult DeviceDriverSC::createCommandPoolHandlerNorm (VkDevice								device,
722 													   const VkCommandPoolCreateInfo*		pCreateInfo,
723 													   const VkAllocationCallbacks*			pAllocator,
724 													   VkCommandPool*						pCommandPool) const
725 {
726 	DDSTAT_LOCK();
727 	VkCommandPoolMemoryReservationCreateInfo* chainedMemoryReservation = (VkCommandPoolMemoryReservationCreateInfo*)findStructureInChain(pCreateInfo->pNext, VK_STRUCTURE_TYPE_COMMAND_POOL_MEMORY_RESERVATION_CREATE_INFO);
728 	// even if we deliver our own VkCommandPoolMemoryReservationCreateInfo - we have to call  ResourceInterface::getNextCommandPoolSize() and ignore its results
729 	vksc_server::VulkanCommandMemoryConsumption memC = m_resourceInterface->getNextCommandPoolSize();
730 
731 	VkCommandPoolCreateInfo						pCreateInfoCopy		= *pCreateInfo;
732 	VkCommandPoolMemoryReservationCreateInfo	cpMemReservationCI;
733 	if (chainedMemoryReservation == DE_NULL)
734 	{
735 		VkDeviceSize cmdPoolSize	= de::max(memC.maxCommandPoolReservedSize, m_commandPoolMinimumSize);
736 		cmdPoolSize					= de::max(cmdPoolSize, memC.commandBufferCount * m_commandBufferMinimumSize);
737 		if (m_physicalDeviceVulkanSC10Properties.maxCommandBufferSize < UINT64_MAX)
738 			cmdPoolSize = de::min(cmdPoolSize, m_physicalDeviceVulkanSC10Properties.maxCommandBufferSize * memC.commandBufferCount);
739 		cpMemReservationCI			=
740 		{
741 			VK_STRUCTURE_TYPE_COMMAND_POOL_MEMORY_RESERVATION_CREATE_INFO,			// VkStructureType		sType
742 			DE_NULL,																// const void*			pNext
743 			de::max(cmdPoolSize , m_commandBufferMinimumSize),						// VkDeviceSize			commandPoolReservedSize
744 			de::max(memC.commandBufferCount, 1u)									// uint32_t				commandPoolMaxCommandBuffers
745 		};
746 		cpMemReservationCI.pNext									= pCreateInfoCopy.pNext;
747 		pCreateInfoCopy.pNext										= &cpMemReservationCI;
748 	}
749 
750 	return m_vk.createCommandPool(device, &pCreateInfoCopy, pAllocator, pCommandPool);
751 }
752 
resetCommandPoolHandlerNorm(VkDevice device,VkCommandPool commandPool,VkCommandPoolResetFlags flags) const753 VkResult DeviceDriverSC::resetCommandPoolHandlerNorm (VkDevice								device,
754 													  VkCommandPool							commandPool,
755 													  VkCommandPoolResetFlags				flags) const
756 {
757 	return m_vk.resetCommandPool(device, commandPool, flags);
758 }
759 
createCommandPoolHandlerStat(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool) const760 void DeviceDriverSC::createCommandPoolHandlerStat (VkDevice							device,
761 												   const VkCommandPoolCreateInfo*	pCreateInfo,
762 												   const VkAllocationCallbacks*		pAllocator,
763 												   VkCommandPool*					pCommandPool) const
764 {
765 	DDSTAT_LOCK();
766 	DDSTAT_HANDLE_CREATE(commandPoolRequestCount, 1);
767 	// Ensure that this VUID is satisfied: VUID-VkCommandPoolMemoryReservationCreateInfo-commandPoolMaxCommandBuffers-05074
768 	m_resourceInterface->getStatMax().commandBufferRequestCount = de::max(m_resourceInterface->getStatMax().commandBufferRequestCount, m_resourceInterface->getStatMax().commandPoolRequestCount);
769 	// Increase maximum value of commandBufferRequestCount in case of VkCommandPoolMemoryReservationCreateInfo presence in pNext chain.
770 	// ( some of the dEQP-VKSC.sc.command_pool_memory_reservation.memory_consumption.*.reserved_size tests use VkCommandPoolMemoryReservationCreateInfo without really creating command buffers and as
771 	// a result - commandBufferRequestCount was too low )
772 	VkCommandPoolMemoryReservationCreateInfo* chainedMemoryReservation = (VkCommandPoolMemoryReservationCreateInfo*)findStructureInChain(pCreateInfo->pNext, VK_STRUCTURE_TYPE_COMMAND_POOL_MEMORY_RESERVATION_CREATE_INFO);
773 
774 	if (chainedMemoryReservation != DE_NULL)
775 		DDSTAT_HANDLE_CREATE(commandBufferRequestCount, chainedMemoryReservation->commandPoolMaxCommandBuffers);
776 	else
777 		DDSTAT_HANDLE_CREATE(commandBufferRequestCount, 1);
778 
779 	*pCommandPool = Handle<HANDLE_TYPE_COMMAND_POOL>(m_resourceInterface->incResourceCounter());
780 	m_resourceInterface->createCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
781 }
782 
resetCommandPoolHandlerStat(VkDevice device,VkCommandPool commandPool,VkCommandPoolResetFlags flags) const783 void DeviceDriverSC::resetCommandPoolHandlerStat (VkDevice					device,
784 												  VkCommandPool				commandPool,
785 												  VkCommandPoolResetFlags	flags) const
786 {
787 	m_resourceInterface->resetCommandPool(device, commandPool, flags);
788 }
789 
allocateCommandBuffersHandler(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers) const790 void DeviceDriverSC::allocateCommandBuffersHandler (VkDevice								device,
791 													const VkCommandBufferAllocateInfo*		pAllocateInfo,
792 													VkCommandBuffer*						pCommandBuffers) const
793 {
794 	DDSTAT_LOCK();
795 	DDSTAT_HANDLE_CREATE(commandBufferRequestCount, pAllocateInfo->commandBufferCount);
796 	for (deUint32 i = 0; i < pAllocateInfo->commandBufferCount; ++i)
797 		pCommandBuffers[i] = (VkCommandBuffer)m_resourceInterface->incResourceCounter();
798 	m_resourceInterface->allocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
799 }
800 
freeCommandBuffersHandler(VkDevice device,VkCommandPool commandPool,deUint32 commandBufferCount,const VkCommandBuffer * pCommandBuffers) const801 void DeviceDriverSC::freeCommandBuffersHandler (VkDevice								device,
802 												VkCommandPool							commandPool,
803 												deUint32								commandBufferCount,
804 												const VkCommandBuffer*					pCommandBuffers) const
805 {
806 	DE_UNREF(device);
807 	DE_UNREF(commandPool);
808 	DE_UNREF(commandBufferCount);
809 	DE_UNREF(pCommandBuffers);
810 }
811 
increaseCommandBufferSize(VkCommandBuffer commandBuffer,VkDeviceSize commandSize) const812 void DeviceDriverSC::increaseCommandBufferSize (VkCommandBuffer	commandBuffer,
813 												VkDeviceSize	commandSize) const
814 {
815 	DDSTAT_LOCK();
816 	VkDeviceSize finalSize = de::max( commandSize, m_commandDefaultSize );
817 	m_resourceInterface->increaseCommandBufferSize(commandBuffer, finalSize);
818 }
819 
checkFramebufferSupport(const VkFramebufferCreateInfo * pCreateInfo) const820 void DeviceDriverSC::checkFramebufferSupport (const VkFramebufferCreateInfo*		pCreateInfo) const
821 {
822 	if (m_resourceInterface->isVulkanSC())
823 	{
824 		if (pCreateInfo->attachmentCount > m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments)
825 		{
826 			const std::string	msg = "Requested framebuffer attachment count (" + de::toString(pCreateInfo->attachmentCount)
827 				+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments) + ")";
828 
829 			TCU_THROW(NotSupportedError, msg);
830 		}
831 		else if (pCreateInfo->layers > m_physicalDeviceProperties.limits.maxFramebufferLayers)
832 		{
833 			const std::string	msg = "Requested framebuffer layers (" + de::toString(pCreateInfo->layers)
834 				+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceProperties.limits.maxFramebufferLayers) + ")";
835 
836 			TCU_THROW(NotSupportedError, msg);
837 		}
838 	}
839 }
840 
checkRenderPassSupport(deUint32 attachmentCount,deUint32 subpassCount,deUint32 dependencyCount) const841 void DeviceDriverSC::checkRenderPassSupport (deUint32	attachmentCount,
842 											 deUint32	subpassCount,
843 											 deUint32	dependencyCount) const
844 {
845 	if (m_resourceInterface->isVulkanSC())
846 	{
847 		if (attachmentCount > m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments)
848 		{
849 			const std::string	msg = "Requested render pass attachment count (" + de::toString(attachmentCount)
850 				+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments) + ")";
851 
852 			TCU_THROW(NotSupportedError, msg);
853 		}
854 
855 		if (subpassCount > m_physicalDeviceVulkanSC10Properties.maxRenderPassSubpasses)
856 		{
857 			const std::string	msg	= "Requested subpassCount (" + de::toString(subpassCount)
858 									+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceVulkanSC10Properties.maxRenderPassSubpasses) + ")";
859 
860 			TCU_THROW(NotSupportedError, msg);
861 		}
862 
863 		if (dependencyCount > m_physicalDeviceVulkanSC10Properties.maxRenderPassDependencies)
864 		{
865 			const std::string	msg	= "Requested dependencyCount (" + de::toString(dependencyCount)
866 									+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceVulkanSC10Properties.maxRenderPassDependencies) + ")";
867 
868 			TCU_THROW(NotSupportedError, msg);
869 		}
870 	}
871 
872 }
873 
checkSubpassSupport(deUint32 inputAttachmentCount,deUint32 preserveAttachmentCount) const874 void DeviceDriverSC::checkSubpassSupport (deUint32	inputAttachmentCount,
875 										  deUint32	preserveAttachmentCount) const
876 {
877 	if (m_resourceInterface->isVulkanSC())
878 	{
879 		if (inputAttachmentCount > m_physicalDeviceVulkanSC10Properties.maxSubpassInputAttachments)
880 		{
881 			const std::string	msg = "Requested inputAttachmentCount (" + de::toString(inputAttachmentCount)
882 				+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceVulkanSC10Properties.maxSubpassInputAttachments) + ")";
883 
884 			TCU_THROW(NotSupportedError, msg);
885 		}
886 
887 		if (preserveAttachmentCount > m_physicalDeviceVulkanSC10Properties.maxSubpassPreserveAttachments)
888 		{
889 			const std::string	msg = "Requested preserveAttachmentCount (" + de::toString(preserveAttachmentCount)
890 				+ ") is greater than VulkanSC limits allow (" + de::toString(m_physicalDeviceVulkanSC10Properties.maxSubpassPreserveAttachments) + ")";
891 
892 			TCU_THROW(NotSupportedError, msg);
893 		}
894 	}
895 }
896 
gerResourceInterface() const897 de::SharedPtr<ResourceInterface> DeviceDriverSC::gerResourceInterface() const
898 {
899 	return m_resourceInterface;
900 }
901 
reset() const902 void DeviceDriverSC::reset() const
903 {
904 	// these objects should be empty when function is invoked, but we will clear it anyway
905 	m_imageViews.clear();
906 	m_renderPasses.clear();
907 	m_renderPasses2.clear();
908 	m_graphicsPipelines.clear();
909 	m_computePipelines.clear();
910 }
911 
912 #endif // CTS_USES_VULKANSC
913 
914 #include "vkPlatformDriverImpl.inl"
915 #include "vkInstanceDriverImpl.inl"
916 #include "vkDeviceDriverImpl.inl"
917 #ifdef CTS_USES_VULKANSC
918 #include "vkDeviceDriverSCImpl.inl"
919 #endif // CTS_USES_VULKANSC
920 
createWsiDisplay(wsi::Type) const921 wsi::Display* Platform::createWsiDisplay (wsi::Type) const
922 {
923 	TCU_THROW(NotSupportedError, "WSI not supported");
924 }
925 
hasDisplay(wsi::Type) const926 bool Platform::hasDisplay (wsi::Type) const
927 {
928 	return false;
929 }
930 
describePlatform(std::ostream & dst) const931 void Platform::describePlatform (std::ostream& dst) const
932 {
933 	dst << "vk::Platform::describePlatform() not implemented";
934 }
935 
936 } // vk
937