Skip to content

Commit 6276a6e

Browse files
Vulkan: avoid loading Vulkan library multiple times
1 parent 03b7ad5 commit 6276a6e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Graphics/GraphicsEngineVulkan/include/VulkanUtilities/Instance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class Instance : public std::enable_shared_from_this<Instance>
102102
private:
103103
explicit Instance(const CreateInfo& CI);
104104

105+
private:
105106
enum DebugMode
106107
{
107108
Disabled,

Graphics/GraphicsEngineVulkan/src/VulkanUtilities/Instance.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,27 @@ std::shared_ptr<Instance> Instance::Create(const CreateInfo& CI)
250250
return std::shared_ptr<Instance>{new Instance{CI}};
251251
}
252252

253+
#if DILIGENT_USE_VOLK
254+
static bool LoadVulkan()
255+
{
256+
static bool VulkanLoaded = false;
257+
if (VulkanLoaded)
258+
return true;
259+
260+
if (volkInitialize() == VK_SUCCESS)
261+
{
262+
VulkanLoaded = true;
263+
}
264+
265+
return VulkanLoaded;
266+
}
267+
#endif
268+
253269
Instance::Instance(const CreateInfo& CI) :
254270
m_pvkAllocator{CI.pVkAllocator}
255271
{
256272
#if DILIGENT_USE_VOLK
257-
if (volkInitialize() != VK_SUCCESS)
273+
if (!LoadVulkan())
258274
{
259275
LOG_ERROR_AND_THROW("Failed to load Vulkan.");
260276
}

0 commit comments

Comments
 (0)