Skip to content

Commit d57c606

Browse files
Added convenience functions to load the required engine dll and get the factory
1 parent f4c2460 commit d57c606

File tree

8 files changed

+110
-32
lines changed

8 files changed

+110
-32
lines changed

Graphics/Archiver/interface/ArchiverFactoryLoader.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444

4545
DILIGENT_BEGIN_NAMESPACE(Diligent)
4646

47-
#if EXPLICITLY_LOAD_ARCHIVER_FACTORY_DLL
48-
4947
typedef struct IArchiverFactory* (*GetArchiverFactoryType)();
5048

49+
#if EXPLICITLY_LOAD_ARCHIVER_FACTORY_DLL
50+
5151
inline GetArchiverFactoryType DILIGENT_GLOBAL_FUNCTION(LoadArchiverFactory)()
5252
{
5353
return (GetArchiverFactoryType)LoadEngineDll("Archiver", "GetArchiverFactory");
@@ -60,4 +60,20 @@ struct IArchiverFactory* DILIGENT_GLOBAL_FUNCTION(GetArchiverFactory)();
6060

6161
#endif
6262

63+
/// Loads the archiver implementation DLL if necessary and returns the archiver factory.
64+
inline struct IArchiverFactory* DILIGENT_GLOBAL_FUNCTION(LoadAndGetArchiverFactory)()
65+
{
66+
GetArchiverFactoryType GetFactoryFunc = NULL;
67+
#if EXPLICITLY_LOAD_ARCHIVER_FACTORY_DLL
68+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(LoadArchiverFactory)();
69+
if (GetFactoryFunc == NULL)
70+
{
71+
return NULL;
72+
}
73+
#else
74+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(GetArchiverFactory);
75+
#endif
76+
return GetFactoryFunc();
77+
}
78+
6379
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -151,11 +151,10 @@ DILIGENT_END_INTERFACE
151151

152152
#endif
153153

154+
typedef struct IEngineFactoryD3D11* (*GetEngineFactoryD3D11Type)();
154155

155156
#if ENGINE_DLL
156157

157-
typedef struct IEngineFactoryD3D11* (*GetEngineFactoryD3D11Type)();
158-
159158
inline GetEngineFactoryD3D11Type DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineD3D11)()
160159
{
161160
return (GetEngineFactoryD3D11Type)LoadEngineDll("GraphicsEngineD3D11", "GetEngineFactoryD3D11");
@@ -167,4 +166,20 @@ struct IEngineFactoryD3D11* DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryD3D11)();
167166

168167
#endif
169168

169+
/// Loads the graphics engine D3D11 implementation DLL if necessary and returns the engine factory.
170+
inline struct IEngineFactoryD3D11* DILIGENT_GLOBAL_FUNCTION(LoadAndGetEngineFactoryD3D11)()
171+
{
172+
GetEngineFactoryD3D11Type GetFactoryFunc = NULL;
173+
#if ENGINE_DLL
174+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineD3D11)();
175+
if (GetFactoryFunc == NULL)
176+
{
177+
return NULL;
178+
}
179+
#else
180+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryD3D11);
181+
#endif
182+
return GetFactoryFunc();
183+
}
184+
170185
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ DILIGENT_END_INTERFACE
187187
#endif
188188

189189

190-
#if ENGINE_DLL
191-
192190
typedef struct IEngineFactoryD3D12* (*GetEngineFactoryD3D12Type)();
193191

192+
#if ENGINE_DLL
193+
194194
inline GetEngineFactoryD3D12Type DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineD3D12)()
195195
{
196196
return (GetEngineFactoryD3D12Type)LoadEngineDll("GraphicsEngineD3D12", "GetEngineFactoryD3D12");
@@ -202,4 +202,21 @@ struct IEngineFactoryD3D12* DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryD3D12)();
202202

203203
#endif
204204

205+
/// Loads the graphics engine D3D12 implementation DLL if necessary and returns the engine factory.
206+
inline struct IEngineFactoryD3D12* DILIGENT_GLOBAL_FUNCTION(LoadAndGetEngineFactoryD3D12)()
207+
{
208+
GetEngineFactoryD3D12Type GetFactoryFunc = NULL;
209+
#if ENGINE_DLL
210+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineD3D12)();
211+
if (GetFactoryFunc == NULL)
212+
{
213+
return NULL;
214+
}
215+
#else
216+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryD3D12);
217+
#endif
218+
return GetFactoryFunc();
219+
}
220+
221+
205222
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ DILIGENT_END_INTERFACE
124124

125125
#endif
126126

127+
typedef struct IEngineFactoryOpenGL* (*GetEngineFactoryOpenGLType)();
127128

128129
#if EXPLICITLY_LOAD_ENGINE_GL_DLL
129130

130-
typedef struct IEngineFactoryOpenGL* (*GetEngineFactoryOpenGLType)();
131-
132131
inline GetEngineFactoryOpenGLType DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineOpenGL)()
133132
{
134133
return (GetEngineFactoryOpenGLType)LoadEngineDll("GraphicsEngineOpenGL", "GetEngineFactoryOpenGL");
@@ -142,4 +141,20 @@ struct IEngineFactoryOpenGL* DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryOpenGL)();
142141

143142
#endif
144143

144+
/// Loads the graphics engine OpenGL implementation DLL if necessary and returns the engine factory.
145+
inline struct IEngineFactoryOpenGL* DILIGENT_GLOBAL_FUNCTION(LoadAndGetEngineFactoryOpenGL)()
146+
{
147+
GetEngineFactoryOpenGLType GetFactoryFunc = NULL;
148+
#if EXPLICITLY_LOAD_ENGINE_GL_DLL
149+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineOpenGL)();
150+
if (GetFactoryFunc == NULL)
151+
{
152+
return NULL;
153+
}
154+
#else
155+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryOpenGL);
156+
#endif
157+
return GetFactoryFunc();
158+
}
159+
145160
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ DILIGENT_END_INTERFACE
130130

131131
#endif
132132

133-
#if EXPLICITLY_LOAD_ENGINE_VK_DLL
134-
135133
typedef struct IEngineFactoryVk* (*GetEngineFactoryVkType)();
136134

135+
#if EXPLICITLY_LOAD_ENGINE_VK_DLL
136+
137137
inline GetEngineFactoryVkType DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineVk)()
138138
{
139139
return (GetEngineFactoryVkType)LoadEngineDll("GraphicsEngineVk", "GetEngineFactoryVk");
@@ -146,4 +146,20 @@ struct IEngineFactoryVk* DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryVk)();
146146

147147
#endif
148148

149+
/// Loads the graphics engine Vulkan implementation DLL if necessary and returns the engine factory.
150+
inline struct IEngineFactoryVk* DILIGENT_GLOBAL_FUNCTION(LoadAndGetEngineFactoryVk)()
151+
{
152+
GetEngineFactoryVkType GetFactoryFunc = NULL;
153+
#if EXPLICITLY_LOAD_ENGINE_VK_DLL
154+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineVk)();
155+
if (GetFactoryFunc == NULL)
156+
{
157+
return NULL;
158+
}
159+
#else
160+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryVk);
161+
#endif
162+
return GetFactoryFunc();
163+
}
164+
149165
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsEngineWebGPU/interface/EngineFactoryWebGPU.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ DILIGENT_END_INTERFACE
139139
#endif
140140

141141

142-
#if EXPLICITLY_LOAD_ENGINE_WEBGPU_DLL
143-
144142
typedef struct IEngineFactoryWebGPU* (*GetEngineFactoryWebGPUType)();
145143

144+
#if EXPLICITLY_LOAD_ENGINE_WEBGPU_DLL
145+
146146
inline GetEngineFactoryWebGPUType DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineWebGPU)()
147147
{
148148
return (GetEngineFactoryWebGPUType)LoadEngineDll("GraphicsEngineWebGPU", "GetEngineFactoryWebGPU");
@@ -155,4 +155,20 @@ struct IEngineFactoryWebGPU* DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryWebGPU)();
155155

156156
#endif
157157

158+
/// Loads the graphics engine WebGPU implementation DLL if necessary and returns the engine factory.
159+
inline struct IEngineFactoryWebGPU* DILIGENT_GLOBAL_FUNCTION(LoadAndGetEngineFactoryWebGPU)()
160+
{
161+
GetEngineFactoryWebGPUType GetFactoryFunc = NULL;
162+
#if EXPLICITLY_LOAD_ENGINE_WEBGPU_DLL
163+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineWebGPU)();
164+
if (GetFactoryFunc == NULL)
165+
{
166+
return NULL;
167+
}
168+
#else
169+
GetFactoryFunc = DILIGENT_GLOBAL_FUNCTION(GetEngineFactoryWebGPU);
170+
#endif
171+
return GetFactoryFunc();
172+
}
173+
158174
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,7 @@ RenderStateCacheImpl::RenderStateCacheImpl(IReferenceCounters* pRe
179179
if (CreateInfo.pDevice == nullptr)
180180
LOG_ERROR_AND_THROW("CreateInfo.pDevice must not be null");
181181

182-
IArchiverFactory* pArchiverFactory = nullptr;
183-
#if EXPLICITLY_LOAD_ARCHIVER_FACTORY_DLL
184-
auto GetArchiverFactory = LoadArchiverFactory();
185-
if (GetArchiverFactory != nullptr)
186-
{
187-
pArchiverFactory = GetArchiverFactory();
188-
}
189-
#else
190-
pArchiverFactory = GetArchiverFactory();
191-
#endif
182+
IArchiverFactory* pArchiverFactory = LoadAndGetArchiverFactory();
192183
VERIFY_EXPR(pArchiverFactory != nullptr);
193184

194185
SerializationDeviceCreateInfo SerializationDeviceCI;

Tests/GPUTestFramework/src/GPUTestingEnvironment.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,7 @@ GPUTestingEnvironment::GPUTestingEnvironment(const CreateInfo& EnvCI, const Swap
607607
#if ARCHIVER_SUPPORTED
608608
// Create archiver factory
609609
{
610-
# if EXPLICITLY_LOAD_ARCHIVER_FACTORY_DLL
611-
GetArchiverFactoryType GetArchiverFactory = LoadArchiverFactory();
612-
if (GetArchiverFactory != nullptr)
613-
{
614-
m_ArchiverFactory = GetArchiverFactory();
615-
}
616-
# else
617-
m_ArchiverFactory = Diligent::GetArchiverFactory();
618-
# endif
610+
m_ArchiverFactory = LoadAndGetArchiverFactory();
619611
m_ArchiverFactory->SetMessageCallback(EnvCI.MessageCallback);
620612
m_ArchiverFactory->SetBreakOnError(false);
621613
}

0 commit comments

Comments
 (0)