69 using StorageType = plUInt32;
73 UsesExternalMemory = PL_BIT(0),
74 IsFileDescriptor = PL_BIT(1),
80 StorageType UsesExternalMemory : 1;
81 StorageType IsFileDescriptor : 1;
87 PL_DECLARE_POD_TYPE();
88 vk::ObjectType m_type;
93 plVulkanAllocation m_allocation;
100 PL_DECLARE_POD_TYPE();
101 vk::ObjectType m_type;
103 void* m_pContext =
nullptr;
108 bool m_bSurface =
false;
109#if defined(VK_USE_PLATFORM_WIN32_KHR)
110 bool m_bWin32Surface =
false;
111#elif PL_ENABLED(PL_SUPPORTS_GLFW)
112#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
113 bool m_bAndroidSurface =
false;
115# error "Vulkan Platform not supported"
118 bool m_bDebugUtils =
false;
119 bool m_bDebugUtilsMarkers =
false;
120 PFN_vkCreateDebugUtilsMessengerEXT pfn_vkCreateDebugUtilsMessengerEXT =
nullptr;
121 PFN_vkDestroyDebugUtilsMessengerEXT pfn_vkDestroyDebugUtilsMessengerEXT =
nullptr;
122 PFN_vkSetDebugUtilsObjectNameEXT pfn_vkSetDebugUtilsObjectNameEXT =
nullptr;
124 bool m_bDeviceSwapChain =
false;
125 bool m_bShaderViewportIndexLayer =
false;
127 vk::PhysicalDeviceCustomBorderColorFeaturesEXT m_borderColorEXT;
128 bool m_bBorderColorFloat =
false;
130 bool m_bImageFormatList =
false;
131 vk::PhysicalDeviceTimelineSemaphoreFeatures m_timelineSemaphoresEXT;
132 bool m_bTimelineSemaphore =
false;
134 bool m_bExternalMemoryCapabilities =
false;
135 bool m_bExternalSemaphoreCapabilities =
false;
137 bool m_bExternalMemory =
false;
138 bool m_bExternalSemaphore =
false;
140 bool m_bExternalMemoryFd =
false;
141 bool m_bExternalSemaphoreFd =
false;
143 bool m_bExternalMemoryWin32 =
false;
144 bool m_bExternalSemaphoreWin32 =
false;
150 plUInt32 m_uiQueueFamily = -1;
151 plUInt32 m_uiQueueIndex = 0;
154 vk::Instance GetVulkanInstance()
const;
155 vk::Device GetVulkanDevice()
const;
156 const Queue& GetGraphicsQueue()
const;
157 const Queue& GetTransferQueue()
const;
159 vk::PhysicalDevice GetVulkanPhysicalDevice()
const;
160 const vk::PhysicalDeviceProperties& GetPhysicalDeviceProperties()
const {
return m_properties; }
161 const Extensions& GetExtensions()
const {
return m_extensions; }
163 vk::PipelineStageFlags GetSupportedStages()
const;
165 vk::CommandBuffer& GetCurrentCommandBuffer();
177 plInt32 GetMemoryIndex(vk::MemoryPropertyFlags properties,
const vk::MemoryRequirements& requirements)
const;
179 vk::Fence Submit(
bool bAddSignalSemaphore =
true);
181 void DeleteLaterImpl(
const PendingDeletion& deletion);
183 void DeleteLater(vk::Image& image, vk::DeviceMemory& externalMemory)
187 PendingDeletion del = {vk::ObjectType::eImage, {PendingDeletionFlags::UsesExternalMemory}, (
void*)image,
nullptr};
188 del.m_pContext = (
void*)externalMemory;
189 DeleteLaterImpl(del);
192 externalMemory =
nullptr;
195 template <
typename T>
196 void DeleteLater(T&
object, plVulkanAllocation& allocation)
200 DeleteLaterImpl({
object.objectType, {}, (
void*)
object, allocation});
203 allocation =
nullptr;
206 template <
typename T>
207 void DeleteLater(T&
object,
void* pContext)
211 PendingDeletion del = {
object.objectType, {}, (
void*)
object,
nullptr};
212 del.m_pContext = pContext;
213 DeleteLaterImpl(
static_cast<const PendingDeletion&
>(del));
218 template <
typename T>
219 void DeleteLater(T&
object)
223 DeleteLaterImpl({
object.objectType, {}, (
void*)
object,
nullptr});
228 void ReclaimLater(
const ReclaimResource& reclaim);
230 template <
typename T>
231 void ReclaimLater(T&
object,
void* pContext =
nullptr)
233 ReclaimLater({
object.objectType, (
void*)
object, pContext});
237 void SetDebugName(
const vk::DebugUtilsObjectNameInfoEXT& info, plVulkanAllocation allocation =
nullptr);
239 template <
typename T>
240 void SetDebugName(
const char* szName, T&
object, plVulkanAllocation allocation =
nullptr)
242#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT)
245 vk::DebugUtilsObjectNameInfoEXT nameInfo;
246 nameInfo.objectType =
object.objectType;
247 nameInfo.objectHandle = (uint64_t)
static_cast<typename T::NativeType
>(
object);
248 nameInfo.pObjectName = szName;
250 SetDebugName(nameInfo, allocation);
255 void ReportLiveGpuObjects();
271 static SemaphoreInfo MakeWaitSemaphore(vk::Semaphore semaphore, vk::PipelineStageFlagBits waitStage = vk::PipelineStageFlagBits::eAllCommands, vk::SemaphoreType type = vk::SemaphoreType::eBinary, plUInt64 uiValue = 0)
276 static SemaphoreInfo MakeSignalSemaphore(vk::Semaphore semaphore, vk::SemaphoreType type = vk::SemaphoreType::eBinary, plUInt64 uiValue = 0)
278 return SemaphoreInfo{semaphore, type, vk::PipelineStageFlagBits::eNone, uiValue};
281 vk::Semaphore m_semaphore;
282 vk::SemaphoreType m_type = vk::SemaphoreType::eBinary;
283 vk::PipelineStageFlagBits m_waitStage = vk::PipelineStageFlagBits::eAllCommands;
284 plUInt64 m_uiValue = 0;
287 void AddSignalSemaphore(
const SemaphoreInfo& signalSemaphore);
297 virtual plResult InitPlatform()
override;
298 virtual plResult ShutdownPlatform()
override;
305 virtual void FlushPlatform()
override;
311 virtual void DestroyBlendStatePlatform(
plGALBlendState* pBlendState)
override;
320 virtual void DestroySamplerStatePlatform(
plGALSamplerState* pSamplerState)
override;
326 virtual void DestroyShaderPlatform(
plGALShader* pShader)
override;
329 virtual void DestroyBufferPlatform(
plGALBuffer* pBuffer)
override;
332 virtual void DestroyTexturePlatform(
plGALTexture* pTexture)
override;
335 virtual void DestroySharedTexturePlatform(
plGALTexture* pTexture)
override;
365 virtual plUInt64 GetCurrentFramePlatform()
const override;
366 virtual plUInt64 GetSafeFramePlatform()
const override;
368 virtual void FillCapabilitiesPlatform()
override;
370 virtual void WaitIdlePlatform()
override;
380 vk::CommandBuffer m_currentCommandBuffer;
381 plUInt64 m_uiFrame = -1;
383 plMutex m_pendingDeletionsMutex;
387 plMutex m_reclaimResourcesMutex;
395 void FillFormatLookupTable();
397 static constexpr plUInt32 FRAMES = 4;
399 plUInt64 m_uiFrameCounter = 1;
400 plUInt64 m_uiSafeFrame = 0;
401 plUInt8 m_uiCurrentPerFrameData = m_uiFrameCounter % FRAMES;
403 vk::Instance m_instance;
404 vk::PhysicalDevice m_physicalDevice;
405 vk::PhysicalDeviceProperties m_properties;
407 Queue m_graphicsQueue;
408 Queue m_transferQueue;
411 vk::PipelineStageFlags m_supportedStages;
412 vk::PhysicalDeviceMemoryProperties m_memoryProperties;
425 vk::Semaphore m_lastCommandBufferFinished;
427 PerFrameData m_PerFrameData[FRAMES];
429#if PL_ENABLED(PL_USE_PROFILING)
430 struct GPUTimingScope* m_pFrameTimingScope =
nullptr;
431 struct GPUTimingScope* m_pPipelineTimingScope =
nullptr;
432 struct GPUTimingScope* m_pPassTimingScope =
nullptr;
435 Extensions m_extensions;
437#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT)
438 VkDebugUtilsMessengerEXT m_debugMessenger = VK_NULL_HANDLE;
Optional interface for plGALTexture if it was created via plGALDevice::CreateSharedTexture....
Definition Texture.h:33
Definition RendererFoundationDLL.h:411
Definition ResourceView.h:11
Definition UnorderedAccesView.h:11
Definition TextureVulkan.h:11
Thread-safe context for initializing resources. Records a command buffer that transitions all newly c...
Definition InitContext.h:13
Definition DispatchContext.h:15