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