xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkPlatform.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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, VkInstance instance)
50 {
51     loadFunctions(platformInterface, instance);
52 }
53 
loadFunctions(const PlatformInterface & platformInterface,VkInstance instance)54 void InstanceDriver::loadFunctions(const PlatformInterface &platformInterface, VkInstance instance){
55 #define GET_PROC_ADDR(NAME) platformInterface.getInstanceProcAddr(instance, NAME)
56 #include "vkInitInstanceFunctionPointers.inl"
57 #undef GET_PROC_ADDR
58 }
59 
~InstanceDriver(void)60 InstanceDriver::~InstanceDriver(void)
61 {
62 }
63 
64 #ifdef CTS_USES_VULKANSC
65 
InstanceDriverSC(const PlatformInterface & platformInterface,VkInstance instance,const tcu::CommandLine & cmdLine,de::SharedPtr<vk::ResourceInterface> resourceInterface)66 InstanceDriverSC::InstanceDriverSC(const PlatformInterface &platformInterface, VkInstance instance,
67                                    const tcu::CommandLine &cmdLine,
68                                    de::SharedPtr<vk::ResourceInterface> resourceInterface)
69     : InstanceDriver(platformInterface, instance)
70     , m_normalMode(cmdLine.isSubProcess())
71     , m_resourceInterface(resourceInterface)
72 {
73 }
74 
prepareDeviceGroupPatch(const VkDeviceCreateInfo * pCreateInfo)75 std::pair<void **, void *> prepareDeviceGroupPatch(const VkDeviceCreateInfo *pCreateInfo)
76 {
77     struct StructureBase
78     {
79         VkStructureType sType;
80         const StructureBase *pNext;
81     };
82 
83     const StructureBase *prev = DE_NULL;
84     const StructureBase *curr = reinterpret_cast<const StructureBase *>(pCreateInfo);
85 
86     while (curr)
87     {
88         if (curr->sType == VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO)
89         {
90             if (prev != DE_NULL)
91                 return std::pair<void **, void *>((void **)&prev->pNext, (void *)curr);
92         }
93 
94         prev = curr;
95         curr = reinterpret_cast<const StructureBase *>(curr->pNext);
96     }
97 
98     return std::pair<void **, void *>(DE_NULL, DE_NULL);
99 }
100 
createDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice) const101 VkResult InstanceDriverSC::createDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
102                                         const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) const
103 {
104     std::pair<void *, void *> patch = prepareDeviceGroupPatch(pCreateInfo);
105     const bool patchNeeded          = patch.first != DE_NULL;
106 
107     // Structure restored from JSON does not contain valid physicalDevice.
108     // Workaround: set to delivered physicalDevice argument.
109     if (patchNeeded && m_normalMode)
110     {
111         VkDeviceGroupDeviceCreateInfo *p = (VkDeviceGroupDeviceCreateInfo *)patch.second;
112 
113         DE_ASSERT(p->physicalDeviceCount == 1);
114 
115         if (p->physicalDeviceCount == 1 && p->pPhysicalDevices[0] == DE_NULL)
116         {
117             VkPhysicalDevice *v = const_cast<VkPhysicalDevice *>(p->pPhysicalDevices);
118             v[0]                = physicalDevice;
119         }
120     }
121 
122     VkResult result = InstanceDriver::createDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
123 
124     // Vulkan loader destroys pNext value when VkDeviceGroupDeviceCreateInfo is present in the chain.
125     // Workaround: Set pNext value to VkDeviceGroupDeviceCreateInfo structure back.
126     if (patchNeeded)
127     {
128         void **addr = (void **)patch.first;
129         *addr       = patch.second;
130     }
131 
132     if (result == VK_SUCCESS && !m_normalMode)
133     {
134         m_resourceInterface->registerDeviceFeatures(*pDevice, pCreateInfo);
135     }
136     return result;
137 }
138 
139 #endif // CTS_USES_VULKANSC
140 
DeviceDriver(const PlatformInterface & platformInterface,VkInstance instance,VkDevice device,uint32_t usedApiVersion,const tcu::CommandLine & cmdLine)141 DeviceDriver::DeviceDriver(const PlatformInterface &platformInterface, VkInstance instance, VkDevice device,
142                            uint32_t usedApiVersion, const tcu::CommandLine &cmdLine)
143     : m_computeOnlyMode(cmdLine.isComputeOnly())
144 {
145     deMemset(&m_vk, 0, sizeof(m_vk));
146 
147     m_vk.getDeviceProcAddr =
148         (GetDeviceProcAddrFunc)platformInterface.getInstanceProcAddr(instance, "vkGetDeviceProcAddr");
149 
150 #define GET_PROC_ADDR(NAME) m_vk.getDeviceProcAddr(device, NAME)
151 #include "vkInitDeviceFunctionPointers.inl"
152 #undef GET_PROC_ADDR
153 }
154 
~DeviceDriver(void)155 DeviceDriver::~DeviceDriver(void)
156 {
157 }
158 
159 #ifdef CTS_USES_VULKANSC
createShaderModule(VkDevice device,const VkShaderModuleCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkShaderModule * pShaderModule) const160 VkResult DeviceDriver::createShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
161                                           const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule) const
162 {
163     // this should not be called - Vulkan SC implementation uses DeviceDriverSC instead
164     DE_UNREF(device);
165     DE_UNREF(pCreateInfo);
166     DE_UNREF(pAllocator);
167     DE_UNREF(pShaderModule);
168     TCU_THROW(InternalError, "Wrong DeviceDriver called in VulkanSC");
169 }
170 #endif
171 
172 #ifdef CTS_USES_VULKANSC
173 
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)174 DeviceDriverSC::DeviceDriverSC(const PlatformInterface &platformInterface, VkInstance instance, VkDevice device,
175                                const tcu::CommandLine &cmdLine, de::SharedPtr<vk::ResourceInterface> resourceInterface,
176                                const VkPhysicalDeviceVulkanSC10Properties &physicalDeviceVulkanSC10Properties,
177                                const VkPhysicalDeviceProperties &physicalDeviceProperties,
178                                const uint32_t usedApiVersion)
179     : DeviceDriver(platformInterface, instance, device, usedApiVersion, cmdLine)
180     , m_normalMode(cmdLine.isSubProcess())
181     , m_resourceInterface(resourceInterface)
182     , m_physicalDeviceVulkanSC10Properties(physicalDeviceVulkanSC10Properties)
183     , m_physicalDeviceProperties(physicalDeviceProperties)
184     , m_commandDefaultSize((VkDeviceSize)cmdLine.getCommandDefaultSize())
185     , m_commandBufferMinimumSize(
186           de::max((VkDeviceSize)cmdLine.getCommandDefaultSize(), (VkDeviceSize)cmdLine.getCommandBufferMinSize()))
187     , m_commandPoolMinimumSize((VkDeviceSize)cmdLine.getCommandPoolMinSize())
188 {
189     if (!cmdLine.isSubProcess())
190         m_falseMemory.resize(64u * 1024u * 1024u, 0u);
191     m_resourceInterface->initDevice(*this, device);
192 }
193 
~DeviceDriverSC(void)194 DeviceDriverSC::~DeviceDriverSC(void)
195 {
196 }
197 
destroyDeviceHandler(VkDevice device,const VkAllocationCallbacks * pAllocator) const198 void DeviceDriverSC::destroyDeviceHandler(VkDevice device, const VkAllocationCallbacks *pAllocator) const
199 {
200     DE_UNREF(pAllocator);
201     m_resourceInterface->unregisterDeviceFeatures(device);
202 }
203 
createDescriptorSetLayoutHandlerNorm(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout) const204 VkResult DeviceDriverSC::createDescriptorSetLayoutHandlerNorm(VkDevice device,
205                                                               const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
206                                                               const VkAllocationCallbacks *pAllocator,
207                                                               VkDescriptorSetLayout *pSetLayout) const
208 {
209     DDSTAT_LOCK();
210     VkResult result = m_vk.createDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
211     m_resourceInterface->registerObjectHash(
212         pSetLayout->getInternal(),
213         calculateDescriptorSetLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
214     return result;
215 }
216 
createDescriptorSetLayoutHandlerStat(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout) const217 void DeviceDriverSC::createDescriptorSetLayoutHandlerStat(VkDevice device,
218                                                           const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
219                                                           const VkAllocationCallbacks *pAllocator,
220                                                           VkDescriptorSetLayout *pSetLayout) const
221 {
222     DE_UNREF(device);
223     DE_UNREF(pAllocator);
224 
225     DDSTAT_LOCK();
226     DDSTAT_HANDLE_CREATE(descriptorSetLayoutRequestCount, 1);
227     DDSTAT_HANDLE_CREATE(descriptorSetLayoutBindingRequestCount, pCreateInfo->bindingCount);
228     uint32_t immutableSamplersCount = 0u;
229     for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i)
230     {
231         m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit = de::max(
232             m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit, pCreateInfo->pBindings[i].binding + 1);
233         if ((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
234              pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) &&
235             pCreateInfo->pBindings[i].pImmutableSamplers != DE_NULL)
236             immutableSamplersCount += pCreateInfo->pBindings[i].descriptorCount;
237     }
238     m_resourceInterface->getStatMax().maxImmutableSamplersPerDescriptorSetLayout =
239         de::max(m_resourceInterface->getStatMax().maxImmutableSamplersPerDescriptorSetLayout, immutableSamplersCount);
240 
241     *pSetLayout = VkDescriptorSetLayout(m_resourceInterface->incResourceCounter());
242     m_descriptorSetLayouts.insert({*pSetLayout, *pCreateInfo});
243     m_resourceInterface->registerObjectHash(
244         pSetLayout->getInternal(),
245         calculateDescriptorSetLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
246     m_resourceInterface->createDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
247 }
248 
destroyDescriptorSetLayoutHandler(VkDevice device,VkDescriptorSetLayout descriptorSetLayout,const VkAllocationCallbacks * pAllocator) const249 void DeviceDriverSC::destroyDescriptorSetLayoutHandler(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
250                                                        const VkAllocationCallbacks *pAllocator) const
251 {
252     DE_UNREF(device);
253     DE_UNREF(pAllocator);
254 
255     DDSTAT_LOCK();
256     auto it = m_descriptorSetLayouts.find(descriptorSetLayout);
257     if (it != end(m_descriptorSetLayouts))
258     {
259         DDSTAT_HANDLE_DESTROY(descriptorSetLayoutRequestCount, 1);
260         DDSTAT_HANDLE_DESTROY(descriptorSetLayoutBindingRequestCount, it->second.bindingCount);
261         m_descriptorSetLayouts.erase(it);
262     }
263 }
264 
allocateDescriptorSetsHandlerStat(VkDevice device,const VkDescriptorSetAllocateInfo * pAllocateInfo,VkDescriptorSet * pDescriptorSets) const265 void DeviceDriverSC::allocateDescriptorSetsHandlerStat(VkDevice device,
266                                                        const VkDescriptorSetAllocateInfo *pAllocateInfo,
267                                                        VkDescriptorSet *pDescriptorSets) const
268 {
269     DE_UNREF(device);
270 
271     DDSTAT_LOCK();
272     DDSTAT_HANDLE_CREATE(descriptorSetRequestCount, pAllocateInfo->descriptorSetCount);
273     for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; ++i)
274         pDescriptorSets[i] = Handle<HANDLE_TYPE_DESCRIPTOR_SET>(m_resourceInterface->incResourceCounter());
275     for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; ++i)
276         m_descriptorSetsInPool[pDescriptorSets[i]] = pAllocateInfo->descriptorPool;
277 }
278 
freeDescriptorSetsHandlerStat(VkDevice device,VkDescriptorPool descriptorPool,uint32_t descriptorSetCount,const VkDescriptorSet * pDescriptorSets) const279 void DeviceDriverSC::freeDescriptorSetsHandlerStat(VkDevice device, 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 (uint32_t i = 0; i < descriptorSetCount; ++i)
288         DDSTAT_HANDLE_DESTROY_IF(pDescriptorSets[i], descriptorSetRequestCount, 1);
289     for (uint32_t 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, VkDescriptorPool descriptorPool,
294                                                     VkDescriptorPoolResetFlags flags) const
295 {
296     DE_UNREF(device);
297     DE_UNREF(flags);
298 
299     DDSTAT_LOCK();
300     uint32_t removedCount = 0u;
301     for (auto it = begin(m_descriptorSetsInPool); it != end(m_descriptorSetsInPool);)
302     {
303         if (it->second.getInternal() == descriptorPool.getInternal())
304         {
305             m_descriptorSetsInPool.erase(it++);
306             removedCount++;
307         }
308         else
309             ++it;
310     }
311     DDSTAT_HANDLE_DESTROY(descriptorSetRequestCount, removedCount);
312 }
313 
createImageViewHandler(VkDevice device,const VkImageViewCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImageView * pView) const314 void DeviceDriverSC::createImageViewHandler(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
315                                             const VkAllocationCallbacks *pAllocator, VkImageView *pView) const
316 {
317     DE_UNREF(device);
318     DE_UNREF(pAllocator);
319 
320     DDSTAT_LOCK();
321     DDSTAT_HANDLE_CREATE(imageViewRequestCount, 1);
322     if (pCreateInfo->subresourceRange.layerCount > 1)
323         DDSTAT_HANDLE_CREATE(layeredImageViewRequestCount, 1);
324 
325     const auto &limits = m_physicalDeviceProperties.limits;
326 
327     uint32_t levelCount = pCreateInfo->subresourceRange.levelCount;
328     if (levelCount == VK_REMAINING_MIP_LEVELS)
329     {
330         uint32_t maxDimensions = limits.maxImageDimension1D;
331         maxDimensions          = de::max(maxDimensions, limits.maxImageDimension2D);
332         maxDimensions          = de::max(maxDimensions, limits.maxImageDimension3D);
333         maxDimensions          = de::max(maxDimensions, limits.maxImageDimensionCube);
334         levelCount             = deLog2Floor32(maxDimensions) + 1;
335     }
336 
337     uint32_t layerCount = pCreateInfo->subresourceRange.layerCount;
338     if (layerCount == VK_REMAINING_ARRAY_LAYERS)
339         layerCount = limits.maxImageArrayLayers;
340 
341     m_resourceInterface->getStatMax().maxImageViewMipLevels =
342         de::max(m_resourceInterface->getStatMax().maxImageViewMipLevels, levelCount);
343     m_resourceInterface->getStatMax().maxImageViewArrayLayers =
344         de::max(m_resourceInterface->getStatMax().maxImageViewArrayLayers, layerCount);
345     if (pCreateInfo->subresourceRange.layerCount > 1)
346         m_resourceInterface->getStatMax().maxLayeredImageViewMipLevels =
347             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, VkImageView imageView,
354                                              const VkAllocationCallbacks *pAllocator) const
355 {
356     DE_UNREF(device);
357     DE_UNREF(pAllocator);
358 
359     DDSTAT_LOCK();
360     auto it = m_imageViews.find(imageView);
361     if (it != end(m_imageViews))
362     {
363         DDSTAT_HANDLE_DESTROY(imageViewRequestCount, 1);
364         if (it->second.subresourceRange.layerCount > 1)
365             DDSTAT_HANDLE_DESTROY(layeredImageViewRequestCount, 1);
366         m_imageViews.erase(it);
367     }
368 }
369 
createQueryPoolHandler(VkDevice device,const VkQueryPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkQueryPool * pQueryPool) const370 void DeviceDriverSC::createQueryPoolHandler(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
371                                             const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) const
372 {
373     DE_UNREF(device);
374     DE_UNREF(pAllocator);
375 
376     DDSTAT_LOCK();
377     DDSTAT_HANDLE_CREATE(queryPoolRequestCount, 1);
378     switch (pCreateInfo->queryType)
379     {
380     case VK_QUERY_TYPE_OCCLUSION:
381         m_resourceInterface->getStatMax().maxOcclusionQueriesPerPool =
382             de::max(m_resourceInterface->getStatMax().maxOcclusionQueriesPerPool, pCreateInfo->queryCount);
383         break;
384     case VK_QUERY_TYPE_PIPELINE_STATISTICS:
385         m_resourceInterface->getStatMax().maxPipelineStatisticsQueriesPerPool =
386             de::max(m_resourceInterface->getStatMax().maxPipelineStatisticsQueriesPerPool, pCreateInfo->queryCount);
387         break;
388     case VK_QUERY_TYPE_TIMESTAMP:
389         m_resourceInterface->getStatMax().maxTimestampQueriesPerPool =
390             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, const VkPipelineLayoutCreateInfo *pCreateInfo,
400                                                          const VkAllocationCallbacks *pAllocator,
401                                                          VkPipelineLayout *pPipelineLayout) const
402 {
403     DDSTAT_LOCK();
404     VkResult result = m_vk.createPipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
405     m_resourceInterface->registerObjectHash(
406         pPipelineLayout->getInternal(),
407         calculatePipelineLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
408     return result;
409 }
410 
createPipelineLayoutHandlerStat(VkDevice device,const VkPipelineLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkPipelineLayout * pPipelineLayout) const411 void DeviceDriverSC::createPipelineLayoutHandlerStat(VkDevice device, 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(
419         pPipelineLayout->getInternal(),
420         calculatePipelineLayoutHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
421     m_resourceInterface->createPipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
422 }
423 
createGraphicsPipelinesHandlerNorm(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkGraphicsPipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const424 VkResult DeviceDriverSC::createGraphicsPipelinesHandlerNorm(VkDevice device, VkPipelineCache pipelineCache,
425                                                             uint32_t createInfoCount,
426                                                             const VkGraphicsPipelineCreateInfo *pCreateInfos,
427                                                             const VkAllocationCallbacks *pAllocator,
428                                                             VkPipeline *pPipelines) const
429 {
430     DDSTAT_LOCK();
431     return m_resourceInterface->createGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos,
432                                                         pAllocator, pPipelines, m_normalMode);
433 }
434 
createGraphicsPipelinesHandlerStat(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkGraphicsPipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const435 void DeviceDriverSC::createGraphicsPipelinesHandlerStat(VkDevice device, VkPipelineCache pipelineCache,
436                                                         uint32_t createInfoCount,
437                                                         const VkGraphicsPipelineCreateInfo *pCreateInfos,
438                                                         const VkAllocationCallbacks *pAllocator,
439                                                         VkPipeline *pPipelines) const
440 {
441     DE_UNREF(device);
442     DE_UNREF(pipelineCache);
443     DE_UNREF(pAllocator);
444 
445     DDSTAT_LOCK();
446     DDSTAT_HANDLE_CREATE(graphicsPipelineRequestCount, createInfoCount);
447     for (uint32_t i = 0; i < createInfoCount; ++i)
448     {
449         pPipelines[i] = VkPipeline(m_resourceInterface->incResourceCounter());
450         m_graphicsPipelines.insert({pPipelines[i], pCreateInfos[i]});
451     }
452 
453     m_resourceInterface->createGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator,
454                                                  pPipelines, m_normalMode);
455 }
456 
createComputePipelinesHandlerNorm(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkComputePipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const457 VkResult DeviceDriverSC::createComputePipelinesHandlerNorm(VkDevice device, VkPipelineCache pipelineCache,
458                                                            uint32_t createInfoCount,
459                                                            const VkComputePipelineCreateInfo *pCreateInfos,
460                                                            const VkAllocationCallbacks *pAllocator,
461                                                            VkPipeline *pPipelines) const
462 {
463     DDSTAT_LOCK();
464     return m_resourceInterface->createComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator,
465                                                        pPipelines, m_normalMode);
466 }
467 
createComputePipelinesHandlerStat(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkComputePipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const468 void DeviceDriverSC::createComputePipelinesHandlerStat(VkDevice device, VkPipelineCache pipelineCache,
469                                                        uint32_t createInfoCount,
470                                                        const VkComputePipelineCreateInfo *pCreateInfos,
471                                                        const VkAllocationCallbacks *pAllocator,
472                                                        VkPipeline *pPipelines) const
473 {
474     DE_UNREF(device);
475     DE_UNREF(pipelineCache);
476     DE_UNREF(pAllocator);
477 
478     DDSTAT_LOCK();
479     DDSTAT_HANDLE_CREATE(computePipelineRequestCount, createInfoCount);
480     for (uint32_t i = 0; i < createInfoCount; ++i)
481     {
482         pPipelines[i] = VkPipeline(m_resourceInterface->incResourceCounter());
483         m_computePipelines.insert({pPipelines[i], pCreateInfos[i]});
484     }
485 
486     m_resourceInterface->createComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator,
487                                                 pPipelines, m_normalMode);
488 }
489 
destroyPipelineHandler(VkDevice device,VkPipeline pipeline,const VkAllocationCallbacks * pAllocator) const490 void DeviceDriverSC::destroyPipelineHandler(VkDevice device, VkPipeline pipeline,
491                                             const VkAllocationCallbacks *pAllocator) const
492 {
493     DE_UNREF(device);
494     DE_UNREF(pAllocator);
495 
496     DDSTAT_LOCK();
497     auto it = m_graphicsPipelines.find(pipeline);
498     if (it != end(m_graphicsPipelines))
499     {
500         DDSTAT_HANDLE_DESTROY(graphicsPipelineRequestCount, 1);
501         m_graphicsPipelines.erase(it);
502         m_resourceInterface->destroyPipeline(device, pipeline, pAllocator);
503         return;
504     }
505 
506     auto it2 = m_computePipelines.find(pipeline);
507     if (it2 != end(m_computePipelines))
508     {
509         DDSTAT_HANDLE_DESTROY(computePipelineRequestCount, 1);
510         m_resourceInterface->destroyPipeline(device, pipeline, pAllocator);
511         m_computePipelines.erase(it2);
512     }
513 }
514 
createFramebufferHandlerNorm(VkDevice device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer) const515 VkResult DeviceDriverSC::createFramebufferHandlerNorm(VkDevice device, 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, const VkFramebufferCreateInfo *pCreateInfo,
526                                                   const VkAllocationCallbacks *pAllocator,
527                                                   VkFramebuffer *pFramebuffer) const
528 {
529     DE_UNREF(device);
530     DE_UNREF(pAllocator);
531 
532     DDSTAT_LOCK();
533     checkFramebufferSupport(pCreateInfo);
534     DDSTAT_HANDLE_CREATE(framebufferRequestCount, 1);
535 
536     *pFramebuffer = Handle<HANDLE_TYPE_FRAMEBUFFER>(m_resourceInterface->incResourceCounter());
537 }
538 
createRenderPassHandlerNorm(VkDevice device,const VkRenderPassCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const539 VkResult DeviceDriverSC::createRenderPassHandlerNorm(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
540                                                      const VkAllocationCallbacks *pAllocator,
541                                                      VkRenderPass *pRenderPass) const
542 {
543     DDSTAT_LOCK();
544 
545     checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
546     for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
547         checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount,
548                             pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
549 
550     VkResult result = m_vk.createRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
551     m_resourceInterface->registerObjectHash(
552         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, const VkRenderPassCreateInfo *pCreateInfo,
557                                                  const VkAllocationCallbacks *pAllocator,
558                                                  VkRenderPass *pRenderPass) const
559 {
560     DE_UNREF(device);
561     DE_UNREF(pAllocator);
562 
563     DDSTAT_LOCK();
564 
565     checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
566     for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
567         checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount,
568                             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(
577         pRenderPass->getInternal(), calculateRenderPassHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
578     m_resourceInterface->createRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
579 }
580 
createRenderPass2HandlerNorm(VkDevice device,const VkRenderPassCreateInfo2 * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const581 VkResult DeviceDriverSC::createRenderPass2HandlerNorm(VkDevice device, 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,
590                             pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
591 
592     VkResult result = m_vk.createRenderPass2(device, pCreateInfo, pAllocator, pRenderPass);
593     m_resourceInterface->registerObjectHash(
594         pRenderPass->getInternal(), calculateRenderPass2Hash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
595     return result;
596 }
597 
createRenderPass2HandlerStat(VkDevice device,const VkRenderPassCreateInfo2 * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const598 void DeviceDriverSC::createRenderPass2HandlerStat(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
599                                                   const VkAllocationCallbacks *pAllocator,
600                                                   VkRenderPass *pRenderPass) const
601 {
602     DE_UNREF(device);
603     DE_UNREF(pAllocator);
604 
605     DDSTAT_LOCK();
606 
607     checkRenderPassSupport(pCreateInfo->attachmentCount, pCreateInfo->subpassCount, pCreateInfo->dependencyCount);
608     for (uint32_t subpassNdx = 0; subpassNdx < pCreateInfo->subpassCount; ++subpassNdx)
609         checkSubpassSupport(pCreateInfo->pSubpasses[subpassNdx].inputAttachmentCount,
610                             pCreateInfo->pSubpasses[subpassNdx].preserveAttachmentCount);
611 
612     DDSTAT_HANDLE_CREATE(renderPassRequestCount, 1);
613     DDSTAT_HANDLE_CREATE(subpassDescriptionRequestCount, pCreateInfo->subpassCount);
614     DDSTAT_HANDLE_CREATE(attachmentDescriptionRequestCount, pCreateInfo->attachmentCount);
615 
616     *pRenderPass = VkRenderPass(m_resourceInterface->incResourceCounter());
617     m_renderPasses2.insert({*pRenderPass, *pCreateInfo});
618     m_resourceInterface->registerObjectHash(
619         pRenderPass->getInternal(), calculateRenderPass2Hash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
620     m_resourceInterface->createRenderPass2(device, pCreateInfo, pAllocator, pRenderPass);
621 }
622 
destroyRenderPassHandler(VkDevice device,VkRenderPass renderPass,const VkAllocationCallbacks * pAllocator) const623 void DeviceDriverSC::destroyRenderPassHandler(VkDevice device, VkRenderPass renderPass,
624                                               const VkAllocationCallbacks *pAllocator) const
625 {
626     DE_UNREF(device);
627     DE_UNREF(pAllocator);
628 
629     DDSTAT_LOCK();
630     auto it = m_renderPasses.find(renderPass);
631     if (it != end(m_renderPasses))
632     {
633         DDSTAT_HANDLE_DESTROY(renderPassRequestCount, 1);
634         DDSTAT_HANDLE_DESTROY(subpassDescriptionRequestCount, it->second.subpassCount);
635         DDSTAT_HANDLE_DESTROY(attachmentDescriptionRequestCount, it->second.attachmentCount);
636         m_renderPasses.erase(it);
637         return;
638     }
639 
640     auto it2 = m_renderPasses2.find(renderPass);
641     if (it2 != end(m_renderPasses2))
642     {
643         DDSTAT_HANDLE_DESTROY(renderPassRequestCount, 1);
644         DDSTAT_HANDLE_DESTROY(subpassDescriptionRequestCount, it2->second.subpassCount);
645         DDSTAT_HANDLE_DESTROY(attachmentDescriptionRequestCount, it2->second.attachmentCount);
646         m_renderPasses2.erase(it2);
647     }
648 }
649 
createSamplerHandlerNorm(VkDevice device,const VkSamplerCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSampler * pSampler) const650 VkResult DeviceDriverSC::createSamplerHandlerNorm(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
651                                                   const VkAllocationCallbacks *pAllocator, VkSampler *pSampler) const
652 {
653     DDSTAT_LOCK();
654     VkResult result = m_vk.createSampler(device, pCreateInfo, pAllocator, pSampler);
655     m_resourceInterface->registerObjectHash(pSampler->getInternal(),
656                                             calculateSamplerHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
657     return result;
658 }
659 
createSamplerHandlerStat(VkDevice device,const VkSamplerCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSampler * pSampler) const660 void DeviceDriverSC::createSamplerHandlerStat(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
661                                               const VkAllocationCallbacks *pAllocator, VkSampler *pSampler) const
662 {
663     DDSTAT_LOCK();
664     DDSTAT_HANDLE_CREATE(samplerRequestCount, 1);
665     *pSampler = VkSampler(m_resourceInterface->incResourceCounter());
666     m_resourceInterface->registerObjectHash(pSampler->getInternal(),
667                                             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(
679         pYcbcrConversion->getInternal(),
680         calculateSamplerYcbcrConversionHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
681     return result;
682 }
683 
createSamplerYcbcrConversionHandlerStat(VkDevice device,const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversion * pYcbcrConversion) const684 void DeviceDriverSC::createSamplerYcbcrConversionHandlerStat(VkDevice device,
685                                                              const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
686                                                              const VkAllocationCallbacks *pAllocator,
687                                                              VkSamplerYcbcrConversion *pYcbcrConversion) const
688 {
689     DDSTAT_LOCK();
690     DDSTAT_HANDLE_CREATE(samplerYcbcrConversionRequestCount, 1);
691     *pYcbcrConversion = VkSamplerYcbcrConversion(m_resourceInterface->incResourceCounter());
692     m_resourceInterface->registerObjectHash(
693         pYcbcrConversion->getInternal(),
694         calculateSamplerYcbcrConversionHash(*pCreateInfo, m_resourceInterface->getObjectHashes()));
695     m_resourceInterface->createSamplerYcbcrConversion(device, pCreateInfo, pAllocator, pYcbcrConversion);
696 }
697 
getDescriptorSetLayoutSupportHandler(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,VkDescriptorSetLayoutSupport * pSupport) const698 void DeviceDriverSC::getDescriptorSetLayoutSupportHandler(VkDevice device,
699                                                           const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
700                                                           VkDescriptorSetLayoutSupport *pSupport) const
701 {
702     DE_UNREF(device);
703 
704     DDSTAT_LOCK();
705     for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i)
706         m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit = de::max(
707             m_resourceInterface->getStatMax().descriptorSetLayoutBindingLimit, pCreateInfo->pBindings[i].binding + 1);
708     pSupport->supported = VK_TRUE;
709 }
710 
createShaderModule(VkDevice device,const VkShaderModuleCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkShaderModule * pShaderModule) const711 VkResult DeviceDriverSC::createShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
712                                             const VkAllocationCallbacks *pAllocator,
713                                             VkShaderModule *pShaderModule) const
714 {
715     DDSTAT_LOCK();
716     return m_resourceInterface->createShaderModule(device, pCreateInfo, pAllocator, pShaderModule, m_normalMode);
717 }
718 
createCommandPoolHandlerNorm(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool) const719 VkResult DeviceDriverSC::createCommandPoolHandlerNorm(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
720                                                       const VkAllocationCallbacks *pAllocator,
721                                                       VkCommandPool *pCommandPool) const
722 {
723     DDSTAT_LOCK();
724     VkCommandPoolMemoryReservationCreateInfo *chainedMemoryReservation =
725         (VkCommandPoolMemoryReservationCreateInfo *)findStructureInChain(
726             pCreateInfo->pNext, VK_STRUCTURE_TYPE_COMMAND_POOL_MEMORY_RESERVATION_CREATE_INFO);
727     // even if we deliver our own VkCommandPoolMemoryReservationCreateInfo - we have to call  ResourceInterface::getNextCommandPoolSize() and ignore its results
728     vksc_server::VulkanCommandMemoryConsumption memC = m_resourceInterface->getNextCommandPoolSize();
729 
730     VkCommandPoolCreateInfo pCreateInfoCopy = *pCreateInfo;
731     VkCommandPoolMemoryReservationCreateInfo cpMemReservationCI;
732     if (chainedMemoryReservation == DE_NULL)
733     {
734         VkDeviceSize cmdPoolSize = de::max(memC.maxCommandPoolReservedSize, m_commandPoolMinimumSize);
735         cmdPoolSize              = de::max(cmdPoolSize, memC.commandBufferCount * m_commandBufferMinimumSize);
736         if (m_physicalDeviceVulkanSC10Properties.maxCommandBufferSize < UINT64_MAX)
737             cmdPoolSize = de::min(cmdPoolSize,
738                                   m_physicalDeviceVulkanSC10Properties.maxCommandBufferSize * memC.commandBufferCount);
739         cpMemReservationCI = {
740             VK_STRUCTURE_TYPE_COMMAND_POOL_MEMORY_RESERVATION_CREATE_INFO, // VkStructureType        sType
741             DE_NULL,                                                       // const void*            pNext
742             de::max(cmdPoolSize, m_commandBufferMinimumSize), // VkDeviceSize            commandPoolReservedSize
743             de::max(memC.commandBufferCount, 1u)              // uint32_t                commandPoolMaxCommandBuffers
744         };
745         cpMemReservationCI.pNext = pCreateInfoCopy.pNext;
746         pCreateInfoCopy.pNext    = &cpMemReservationCI;
747     }
748 
749     return m_vk.createCommandPool(device, &pCreateInfoCopy, pAllocator, pCommandPool);
750 }
751 
resetCommandPoolHandlerNorm(VkDevice device,VkCommandPool commandPool,VkCommandPoolResetFlags flags) const752 VkResult DeviceDriverSC::resetCommandPoolHandlerNorm(VkDevice device, VkCommandPool commandPool,
753                                                      VkCommandPoolResetFlags flags) const
754 {
755     return m_vk.resetCommandPool(device, commandPool, flags);
756 }
757 
createCommandPoolHandlerStat(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool) const758 void DeviceDriverSC::createCommandPoolHandlerStat(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
759                                                   const VkAllocationCallbacks *pAllocator,
760                                                   VkCommandPool *pCommandPool) const
761 {
762     DDSTAT_LOCK();
763     DDSTAT_HANDLE_CREATE(commandPoolRequestCount, 1);
764     // Ensure that this VUID is satisfied: VUID-VkCommandPoolMemoryReservationCreateInfo-commandPoolMaxCommandBuffers-05074
765     m_resourceInterface->getStatMax().commandBufferRequestCount =
766         de::max(m_resourceInterface->getStatMax().commandBufferRequestCount,
767                 m_resourceInterface->getStatMax().commandPoolRequestCount);
768     // Increase maximum value of commandBufferRequestCount in case of VkCommandPoolMemoryReservationCreateInfo presence in pNext chain.
769     // ( some of the dEQP-VKSC.sc.command_pool_memory_reservation.memory_consumption.*.reserved_size tests use VkCommandPoolMemoryReservationCreateInfo without really creating command buffers and as
770     // a result - commandBufferRequestCount was too low )
771     VkCommandPoolMemoryReservationCreateInfo *chainedMemoryReservation =
772         (VkCommandPoolMemoryReservationCreateInfo *)findStructureInChain(
773             pCreateInfo->pNext, VK_STRUCTURE_TYPE_COMMAND_POOL_MEMORY_RESERVATION_CREATE_INFO);
774 
775     if (chainedMemoryReservation != DE_NULL)
776         DDSTAT_HANDLE_CREATE(commandBufferRequestCount, chainedMemoryReservation->commandPoolMaxCommandBuffers);
777     else
778         DDSTAT_HANDLE_CREATE(commandBufferRequestCount, 1);
779 
780     *pCommandPool = Handle<HANDLE_TYPE_COMMAND_POOL>(m_resourceInterface->incResourceCounter());
781     m_resourceInterface->createCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
782 }
783 
resetCommandPoolHandlerStat(VkDevice device,VkCommandPool commandPool,VkCommandPoolResetFlags flags) const784 void DeviceDriverSC::resetCommandPoolHandlerStat(VkDevice device, 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, const VkCommandBufferAllocateInfo *pAllocateInfo,
791                                                    VkCommandBuffer *pCommandBuffers) const
792 {
793     DDSTAT_LOCK();
794     DDSTAT_HANDLE_CREATE(commandBufferRequestCount, pAllocateInfo->commandBufferCount);
795     for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; ++i)
796         pCommandBuffers[i] = (VkCommandBuffer)m_resourceInterface->incResourceCounter();
797     m_resourceInterface->allocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
798 }
799 
freeCommandBuffersHandler(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers) const800 void DeviceDriverSC::freeCommandBuffersHandler(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
801                                                const VkCommandBuffer *pCommandBuffers) const
802 {
803     DE_UNREF(device);
804     DE_UNREF(commandPool);
805     DE_UNREF(commandBufferCount);
806     DE_UNREF(pCommandBuffers);
807 }
808 
increaseCommandBufferSize(VkCommandBuffer commandBuffer,VkDeviceSize commandSize) const809 void DeviceDriverSC::increaseCommandBufferSize(VkCommandBuffer commandBuffer, VkDeviceSize commandSize) const
810 {
811     DDSTAT_LOCK();
812     VkDeviceSize finalSize = de::max(commandSize, m_commandDefaultSize);
813     m_resourceInterface->increaseCommandBufferSize(commandBuffer, finalSize);
814 }
815 
checkFramebufferSupport(const VkFramebufferCreateInfo * pCreateInfo) const816 void DeviceDriverSC::checkFramebufferSupport(const VkFramebufferCreateInfo *pCreateInfo) const
817 {
818     if (m_resourceInterface->isVulkanSC())
819     {
820         if (pCreateInfo->attachmentCount > m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments)
821         {
822             const std::string msg = "Requested framebuffer attachment count (" +
823                                     de::toString(pCreateInfo->attachmentCount) +
824                                     ") is greater than VulkanSC limits allow (" +
825                                     de::toString(m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments) + ")";
826 
827             TCU_THROW(NotSupportedError, msg);
828         }
829         else if (pCreateInfo->layers > m_physicalDeviceProperties.limits.maxFramebufferLayers)
830         {
831             const std::string msg = "Requested framebuffer layers (" + de::toString(pCreateInfo->layers) +
832                                     ") is greater than VulkanSC limits allow (" +
833                                     de::toString(m_physicalDeviceProperties.limits.maxFramebufferLayers) + ")";
834 
835             TCU_THROW(NotSupportedError, msg);
836         }
837     }
838 }
839 
checkRenderPassSupport(uint32_t attachmentCount,uint32_t subpassCount,uint32_t dependencyCount) const840 void DeviceDriverSC::checkRenderPassSupport(uint32_t attachmentCount, uint32_t subpassCount,
841                                             uint32_t dependencyCount) const
842 {
843     if (m_resourceInterface->isVulkanSC())
844     {
845         if (attachmentCount > m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments)
846         {
847             const std::string msg = "Requested render pass attachment count (" + de::toString(attachmentCount) +
848                                     ") is greater than VulkanSC limits allow (" +
849                                     de::toString(m_physicalDeviceVulkanSC10Properties.maxFramebufferAttachments) + ")";
850 
851             TCU_THROW(NotSupportedError, msg);
852         }
853 
854         if (subpassCount > m_physicalDeviceVulkanSC10Properties.maxRenderPassSubpasses)
855         {
856             const std::string msg = "Requested subpassCount (" + de::toString(subpassCount) +
857                                     ") is greater than VulkanSC limits allow (" +
858                                     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 (" +
867                                     de::toString(m_physicalDeviceVulkanSC10Properties.maxRenderPassDependencies) + ")";
868 
869             TCU_THROW(NotSupportedError, msg);
870         }
871     }
872 }
873 
checkSubpassSupport(uint32_t inputAttachmentCount,uint32_t preserveAttachmentCount) const874 void DeviceDriverSC::checkSubpassSupport(uint32_t inputAttachmentCount, uint32_t preserveAttachmentCount) const
875 {
876     if (m_resourceInterface->isVulkanSC())
877     {
878         if (inputAttachmentCount > m_physicalDeviceVulkanSC10Properties.maxSubpassInputAttachments)
879         {
880             const std::string msg = "Requested inputAttachmentCount (" + de::toString(inputAttachmentCount) +
881                                     ") is greater than VulkanSC limits allow (" +
882                                     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 (" +
891                                     de::toString(m_physicalDeviceVulkanSC10Properties.maxSubpassPreserveAttachments) +
892                                     ")";
893 
894             TCU_THROW(NotSupportedError, msg);
895         }
896     }
897 }
898 
gerResourceInterface() const899 de::SharedPtr<ResourceInterface> DeviceDriverSC::gerResourceInterface() const
900 {
901     return m_resourceInterface;
902 }
903 
reset() const904 void DeviceDriverSC::reset() const
905 {
906     // these objects should be empty when function is invoked, but we will clear it anyway
907     m_imageViews.clear();
908     m_renderPasses.clear();
909     m_renderPasses2.clear();
910     m_graphicsPipelines.clear();
911     m_computePipelines.clear();
912 }
913 
914 #endif // CTS_USES_VULKANSC
915 
916 #include "vkPlatformDriverImpl.inl"
917 #include "vkInstanceDriverImpl.inl"
918 #include "vkDeviceDriverImpl.inl"
919 #ifdef CTS_USES_VULKANSC
920 #include "vkDeviceDriverSCImpl.inl"
921 #endif // CTS_USES_VULKANSC
922 
createWsiDisplay(wsi::Type) const923 wsi::Display *Platform::createWsiDisplay(wsi::Type) const
924 {
925     TCU_THROW(NotSupportedError, "WSI not supported");
926 }
927 
hasDisplay(wsi::Type) const928 bool Platform::hasDisplay(wsi::Type) const
929 {
930     return false;
931 }
932 
describePlatform(std::ostream & dst) const933 void Platform::describePlatform(std::ostream &dst) const
934 {
935     dst << "vk::Platform::describePlatform() not implemented";
936 }
937 
938 } // namespace vk
939