1 #ifndef _VKPLATFORM_HPP
2 #define _VKPLATFORM_HPP
3 /*-------------------------------------------------------------------------
7 * Copyright (c) 2015 Google Inc.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Vulkan platform abstraction.
24 *//*--------------------------------------------------------------------*/
27 #include "deUniquePtr.hpp"
30 #include <deSharedPtr.hpp>
31 #ifdef CTS_USES_VULKANSC
35 #include "vkResourceInterface.hpp"
36 #include "tcuCommandLine.hpp"
37 #endif // CTS_USES_VULKANSC
41 class FunctionLibrary;
51 virtual ~Library (void) {}
53 virtual const PlatformInterface& getPlatformInterface (void) const = 0;
54 virtual const tcu::FunctionLibrary& getFunctionLibrary (void) const = 0;
57 class PlatformDriver : public PlatformInterface
60 PlatformDriver (const tcu::FunctionLibrary& library);
61 ~PlatformDriver (void);
63 #include "vkConcretePlatformInterface.inl"
65 virtual GetInstanceProcAddrFunc getGetInstanceProcAddr () const {
66 return m_vk.getInstanceProcAddr;
72 #include "vkPlatformFunctionPointers.inl"
78 class InstanceDriver : public InstanceInterface
81 InstanceDriver (const PlatformInterface& platformInterface,
83 virtual ~InstanceDriver (void);
85 #include "vkConcreteInstanceInterface.inl"
88 void loadFunctions (const PlatformInterface& platformInterface,
93 #include "vkInstanceFunctionPointers.inl"
99 #ifdef CTS_USES_VULKANSC
101 class InstanceDriverSC : public InstanceDriver
104 InstanceDriverSC (const PlatformInterface& platformInterface,
106 const tcu::CommandLine& cmdLine,
107 de::SharedPtr<vk::ResourceInterface> resourceInterface);
109 virtual VkResult createDevice (VkPhysicalDevice physicalDevice,
110 const VkDeviceCreateInfo* pCreateInfo,
111 const VkAllocationCallbacks* pAllocator,
112 VkDevice* pDevice) const;
114 mutable std::mutex functionMutex;
116 de::SharedPtr<vk::ResourceInterface> m_resourceInterface;
119 #endif // CTS_USES_VULKANSC
121 class DeviceDriver : public DeviceInterface
124 DeviceDriver (const PlatformInterface& platformInterface,
127 virtual ~DeviceDriver (void);
129 #include "vkConcreteDeviceInterface.inl"
131 #ifdef CTS_USES_VULKANSC
132 virtual VkResult createShaderModule (VkDevice device,
133 const VkShaderModuleCreateInfo* pCreateInfo,
134 const VkAllocationCallbacks* pAllocator,
135 VkShaderModule* pShaderModule) const;
136 #endif // CTS_USES_VULKANSC
141 #include "vkDeviceFunctionPointers.inl"
147 #ifdef CTS_USES_VULKANSC
149 #define DDSTAT_LOCK() std::lock_guard<std::mutex> statLock(m_resourceInterface->getStatMutex())
150 #define DDSTAT_HANDLE_CREATE(VAR_NAME,VAR_VALUE) do { m_resourceInterface->getStatCurrent().VAR_NAME += (VAR_VALUE); m_resourceInterface->getStatMax().VAR_NAME = de::max(m_resourceInterface->getStatMax().VAR_NAME, m_resourceInterface->getStatCurrent().VAR_NAME); } while(0)
151 #define DDSTAT_HANDLE_DESTROY_IF(VAR_VARIABLE,VAR_NAME,VAR_VALUE) if(VAR_VARIABLE.getInternal()!=DE_NULL && m_resourceInterface->isEnabledHandleDestroy()) m_resourceInterface->getStatCurrent().VAR_NAME -= (VAR_VALUE)
152 #define DDSTAT_HANDLE_DESTROY(VAR_NAME,VAR_VALUE) if( m_resourceInterface->isEnabledHandleDestroy() ) m_resourceInterface->getStatCurrent().VAR_NAME -= (VAR_VALUE)
154 class DeviceDriverSC : public DeviceDriver
157 DeviceDriverSC (const PlatformInterface& platformInterface,
160 const tcu::CommandLine& cmdLine,
161 de::SharedPtr<vk::ResourceInterface> resourceInterface,
162 const VkPhysicalDeviceVulkanSC10Properties& physicalDeviceVulkanSC10Properties,
163 const VkPhysicalDeviceProperties& physicalDeviceProperties);
164 virtual ~DeviceDriverSC (void);
166 #include "vkConcreteDeviceInterface.inl"
168 // Functions ending with Handler() and HandlerStat() work only when we gather statistics ( in a main process ).
169 // Functions ending with HandlerNorm() work in normal mode ( in subprocess, when real test is performed )
170 // Method createShaderModule() works in both modes, and ResourceInterface is responsible for distinguishing modes
171 void destroyDeviceHandler (VkDevice device,
172 const VkAllocationCallbacks* pAllocator) const;
173 VkResult createDescriptorSetLayoutHandlerNorm (VkDevice device,
174 const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
175 const VkAllocationCallbacks* pAllocator,
176 VkDescriptorSetLayout* pSetLayout) const;
177 void createDescriptorSetLayoutHandlerStat (VkDevice device,
178 const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
179 const VkAllocationCallbacks* pAllocator,
180 VkDescriptorSetLayout* pSetLayout) const;
181 void destroyDescriptorSetLayoutHandler (VkDevice device,
182 VkDescriptorSetLayout descriptorSetLayout,
183 const VkAllocationCallbacks* pAllocator) const;
184 void allocateDescriptorSetsHandlerStat (VkDevice device,
185 const VkDescriptorSetAllocateInfo* pAllocateInfo,
186 VkDescriptorSet* pDescriptorSets) const;
187 void freeDescriptorSetsHandlerStat (VkDevice device,
188 VkDescriptorPool descriptorPool,
189 uint32_t descriptorSetCount,
190 const VkDescriptorSet* pDescriptorSets) const;
191 void resetDescriptorPoolHandlerStat (VkDevice device,
192 VkDescriptorPool descriptorPool,
193 VkDescriptorPoolResetFlags flags) const;
194 void createImageViewHandler (VkDevice device,
195 const VkImageViewCreateInfo* pCreateInfo,
196 const VkAllocationCallbacks* pAllocator,
197 VkImageView* pView) const;
198 void destroyImageViewHandler (VkDevice device,
199 VkImageView imageView,
200 const VkAllocationCallbacks* pAllocator) const;
201 void createQueryPoolHandler (VkDevice device,
202 const VkQueryPoolCreateInfo* pCreateInfo,
203 const VkAllocationCallbacks* pAllocator,
204 VkQueryPool* pQueryPool) const ;
205 VkResult createPipelineLayoutHandlerNorm (VkDevice device,
206 const VkPipelineLayoutCreateInfo* pCreateInfo,
207 const VkAllocationCallbacks* pAllocator,
208 VkPipelineLayout* pPipelineLayout) const;
209 void createPipelineLayoutHandlerStat (VkDevice device,
210 const VkPipelineLayoutCreateInfo* pCreateInfo,
211 const VkAllocationCallbacks* pAllocator,
212 VkPipelineLayout* pPipelineLayout) const;
213 VkResult createGraphicsPipelinesHandlerNorm (VkDevice device,
214 VkPipelineCache pipelineCache,
215 deUint32 createInfoCount,
216 const VkGraphicsPipelineCreateInfo* pCreateInfos,
217 const VkAllocationCallbacks* pAllocator,
218 VkPipeline* pPipelines) const;
219 void createGraphicsPipelinesHandlerStat (VkDevice device,
220 VkPipelineCache pipelineCache,
221 deUint32 createInfoCount,
222 const VkGraphicsPipelineCreateInfo* pCreateInfos,
223 const VkAllocationCallbacks* pAllocator,
224 VkPipeline* pPipelines) const;
225 VkResult createComputePipelinesHandlerNorm (VkDevice device,
226 VkPipelineCache pipelineCache,
227 deUint32 createInfoCount,
228 const VkComputePipelineCreateInfo* pCreateInfos,
229 const VkAllocationCallbacks* pAllocator,
230 VkPipeline* pPipelines) const;
231 void createComputePipelinesHandlerStat (VkDevice device,
232 VkPipelineCache pipelineCache,
233 deUint32 createInfoCount,
234 const VkComputePipelineCreateInfo* pCreateInfos,
235 const VkAllocationCallbacks* pAllocator,
236 VkPipeline* pPipelines) const;
237 void destroyPipelineHandler (VkDevice device,
239 const VkAllocationCallbacks* pAllocator) const;
240 VkResult createFramebufferHandlerNorm (VkDevice device,
241 const VkFramebufferCreateInfo* pCreateInfo,
242 const VkAllocationCallbacks* pAllocator,
243 VkFramebuffer* pFramebuffer) const;
244 void createFramebufferHandlerStat (VkDevice device,
245 const VkFramebufferCreateInfo* pCreateInfo,
246 const VkAllocationCallbacks* pAllocator,
247 VkFramebuffer* pFramebuffer) const;
248 VkResult createRenderPassHandlerNorm (VkDevice device,
249 const VkRenderPassCreateInfo* pCreateInfo,
250 const VkAllocationCallbacks* pAllocator,
251 VkRenderPass* pRenderPass) const;
252 void createRenderPassHandlerStat (VkDevice device,
253 const VkRenderPassCreateInfo* pCreateInfo,
254 const VkAllocationCallbacks* pAllocator,
255 VkRenderPass* pRenderPass) const;
256 VkResult createRenderPass2HandlerNorm (VkDevice device,
257 const VkRenderPassCreateInfo2* pCreateInfo,
258 const VkAllocationCallbacks* pAllocator,
259 VkRenderPass* pRenderPass) const;
260 void createRenderPass2HandlerStat (VkDevice device,
261 const VkRenderPassCreateInfo2* pCreateInfo,
262 const VkAllocationCallbacks* pAllocator,
263 VkRenderPass* pRenderPass) const;
264 void destroyRenderPassHandler (VkDevice device,
265 VkRenderPass renderPass,
266 const VkAllocationCallbacks* pAllocator) const;
267 VkResult createSamplerHandlerNorm (VkDevice device,
268 const VkSamplerCreateInfo* pCreateInfo,
269 const VkAllocationCallbacks* pAllocator,
270 VkSampler* pSampler) const;
271 void createSamplerHandlerStat (VkDevice device,
272 const VkSamplerCreateInfo* pCreateInfo,
273 const VkAllocationCallbacks* pAllocator,
274 VkSampler* pSampler) const;
275 VkResult createSamplerYcbcrConversionHandlerNorm (VkDevice device,
276 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
277 const VkAllocationCallbacks* pAllocator,
278 VkSamplerYcbcrConversion* pYcbcrConversion) const;
279 void createSamplerYcbcrConversionHandlerStat (VkDevice device,
280 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
281 const VkAllocationCallbacks* pAllocator,
282 VkSamplerYcbcrConversion* pYcbcrConversion) const;
283 void getDescriptorSetLayoutSupportHandler (VkDevice device,
284 const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
285 VkDescriptorSetLayoutSupport* pSupport) const;
286 virtual VkResult createShaderModule (VkDevice device,
287 const VkShaderModuleCreateInfo* pCreateInfo,
288 const VkAllocationCallbacks* pAllocator,
289 VkShaderModule* pShaderModule) const;
291 VkResult createCommandPoolHandlerNorm (VkDevice device,
292 const VkCommandPoolCreateInfo* pCreateInfo,
293 const VkAllocationCallbacks* pAllocator,
294 VkCommandPool* pCommandPool) const;
295 VkResult resetCommandPoolHandlerNorm (VkDevice device,
296 VkCommandPool commandPool,
297 VkCommandPoolResetFlags flags) const;
298 void createCommandPoolHandlerStat (VkDevice device,
299 const VkCommandPoolCreateInfo* pCreateInfo,
300 const VkAllocationCallbacks* pAllocator,
301 VkCommandPool* pCommandPool) const;
302 void resetCommandPoolHandlerStat (VkDevice device,
303 VkCommandPool commandPool,
304 VkCommandPoolResetFlags flags) const;
305 void allocateCommandBuffersHandler (VkDevice device,
306 const VkCommandBufferAllocateInfo* pAllocateInfo,
307 VkCommandBuffer* pCommandBuffers) const;
308 void freeCommandBuffersHandler (VkDevice device,
309 VkCommandPool commandPool,
310 deUint32 commandBufferCount,
311 const VkCommandBuffer* pCommandBuffers) const;
312 void increaseCommandBufferSize (VkCommandBuffer commandBuffer,
313 VkDeviceSize commandSize) const;
314 void checkFramebufferSupport (const VkFramebufferCreateInfo* pCreateInfo) const;
315 void checkRenderPassSupport (deUint32 attachmentCount,
316 deUint32 subpassCount,
317 deUint32 dependencyCount) const;
318 void checkSubpassSupport (deUint32 inputAttachmentCount,
319 deUint32 preserveAttachmentCount) const;
322 de::SharedPtr<ResourceInterface> gerResourceInterface () const;
326 mutable std::mutex functionMutex;
329 de::SharedPtr<vk::ResourceInterface> m_resourceInterface;
331 mutable std::vector<deUint8> m_falseMemory;
332 mutable std::map<VkImageView, VkImageViewCreateInfo> m_imageViews;
333 mutable std::map<VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo> m_descriptorSetLayouts;
334 mutable std::map<VkRenderPass, VkRenderPassCreateInfo> m_renderPasses;
335 mutable std::map<VkRenderPass, VkRenderPassCreateInfo2> m_renderPasses2;
336 mutable std::map<VkPipeline, VkGraphicsPipelineCreateInfo> m_graphicsPipelines;
337 mutable std::map<VkPipeline, VkComputePipelineCreateInfo> m_computePipelines;
338 mutable std::map<VkDescriptorSet, VkDescriptorPool> m_descriptorSetsInPool;
339 VkPhysicalDeviceVulkanSC10Properties m_physicalDeviceVulkanSC10Properties;
340 VkPhysicalDeviceProperties m_physicalDeviceProperties;
342 VkDeviceSize m_commandDefaultSize;
343 VkDeviceSize m_commandBufferMinimumSize;
344 VkDeviceSize m_commandPoolMinimumSize;
347 class DeinitDeviceDeleter : public Deleter<DeviceDriverSC>
350 DeinitDeviceDeleter (ResourceInterface* resourceInterface, const VkDevice& device)
351 : m_resourceInterface(resourceInterface)
355 DeinitDeviceDeleter (void)
356 : m_resourceInterface(DE_NULL)
360 void operator() (DeviceDriverSC* obj) const
362 if (m_resourceInterface != DE_NULL)
363 m_resourceInterface->deinitDevice(m_device);
367 ResourceInterface* m_resourceInterface;
371 #endif // CTS_USES_VULKANSC
373 // Single device driver pointer type which will differ in SC and non-SC mode helping clearing the code
374 #ifndef CTS_USES_VULKANSC
375 typedef de::MovePtr<DeviceDriver> DeviceDriverPtr;
377 typedef de::MovePtr<DeviceDriverSC, vk::DeinitDeviceDeleter> DeviceDriverPtr;
378 #endif // CTS_USES_VULKANSC
380 // Defined in vkWsiPlatform.hpp
386 /*--------------------------------------------------------------------*//*!
387 * \brief Vulkan platform interface
388 *//*--------------------------------------------------------------------*/
395 virtual Library* createLibrary (const char* libraryPath) const = 0;
396 virtual wsi::Display* createWsiDisplay (wsi::Type wsiType) const;
397 virtual bool hasDisplay (wsi::Type wsiType) const;
398 virtual void describePlatform (std::ostream& dst) const;
403 #endif // _VKPLATFORM_HPP