Skip to content

Commit a65b8f1

Browse files
Updated engine initialization
1 parent 7b6adaf commit a65b8f1

File tree

12 files changed

+34
-103
lines changed

12 files changed

+34
-103
lines changed

Samples/Asteroids/src/asteroids_DE.cpp

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,6 @@
4949

5050
using namespace Diligent;
5151

52-
namespace Diligent
53-
{
54-
#if ENGINE_DLL
55-
# if D3D11_SUPPORTED
56-
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = nullptr;
57-
# endif
58-
59-
# if D3D12_SUPPORTED
60-
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = nullptr;
61-
# endif
62-
63-
# if GL_SUPPORTED
64-
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = nullptr;
65-
# endif
66-
67-
# if VULKAN_SUPPORTED
68-
GetEngineFactoryVkType GetEngineFactoryVulkan = nullptr;
69-
# endif
70-
#endif
71-
} // namespace Diligent
72-
7352
namespace AsteroidsDE
7453
{
7554

@@ -118,11 +97,7 @@ void Asteroids::InitDevice(HWND hWnd, RENDER_DEVICE_TYPE DevType)
11897
EngineD3D11CreateInfo EngineCI;
11998
EngineCI.NumDeferredContexts = mNumSubsets - 1;
12099

121-
# if ENGINE_DLL
122-
if (GetEngineFactoryD3D11 == nullptr)
123-
GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
124-
# endif
125-
auto* pFactoryD3D11 = GetEngineFactoryD3D11();
100+
auto* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11();
126101
pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &mDevice, ppContexts.data());
127102
pFactoryD3D11->CreateSwapChainD3D11(mDevice, ppContexts[0], SwapChainDesc, FullScreenModeDesc{}, Win32NativeWindow{hWnd}, &mSwapChain);
128103
}
@@ -140,11 +115,8 @@ void Asteroids::InitDevice(HWND hWnd, RENDER_DEVICE_TYPE DevType)
140115
# ifndef DILIGENT_DEBUG
141116
EngineCI.DynamicDescriptorAllocationChunkSize[0] = 8192;
142117
# endif
143-
# if ENGINE_DLL
144-
if (GetEngineFactoryD3D12 == nullptr)
145-
GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
146-
# endif
147-
auto* pFactoryD3D12 = GetEngineFactoryD3D12();
118+
119+
auto* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12();
148120
pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &mDevice, ppContexts.data());
149121
pFactoryD3D12->CreateSwapChainD3D12(mDevice, ppContexts[0], SwapChainDesc, FullScreenModeDesc{}, Win32NativeWindow{hWnd}, &mSwapChain);
150122
}
@@ -169,11 +141,7 @@ void Asteroids::InitDevice(HWND hWnd, RENDER_DEVICE_TYPE DevType)
169141
EngineCI.ppIgnoreDebugMessageNames = ppIgnoreDebugMessages;
170142
EngineCI.IgnoreDebugMessageCount = _countof(ppIgnoreDebugMessages);
171143

172-
# if ENGINE_DLL
173-
if (GetEngineFactoryVulkan == nullptr)
174-
GetEngineFactoryVulkan = LoadGraphicsEngineVk();
175-
# endif
176-
auto* pFactoryVk = GetEngineFactoryVulkan();
144+
auto* pFactoryVk = LoadAndGetEngineFactoryVk();
177145
pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &mDevice, ppContexts.data());
178146
pFactoryVk->CreateSwapChainVk(mDevice, ppContexts[0], SwapChainDesc, Win32NativeWindow{hWnd}, &mSwapChain);
179147
}
@@ -184,13 +152,11 @@ void Asteroids::InitDevice(HWND hWnd, RENDER_DEVICE_TYPE DevType)
184152
#if GL_SUPPORTED
185153
case RENDER_DEVICE_TYPE_GL:
186154
{
187-
# if ENGINE_DLL
188-
if (GetEngineFactoryOpenGL == nullptr)
189-
GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
190-
# endif
191155
EngineGLCreateInfo CreationAttribs;
192156
CreationAttribs.Window.hWnd = hWnd;
193-
GetEngineFactoryOpenGL()->CreateDeviceAndSwapChainGL(
157+
158+
auto* pFactoryGL = LoadAndGetEngineFactoryOpenGL();
159+
pFactoryGL->CreateDeviceAndSwapChainGL(
194160
CreationAttribs, &mDevice, &mDeviceCtxt, SwapChainDesc, &mSwapChain);
195161
}
196162
break;

Samples/GLFWDemo/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ set_target_properties(GLFWDemo PROPERTIES
4949
FOLDER DiligentSamples/Samples
5050
)
5151

52-
target_compile_definitions(GLFWDemo PRIVATE ENGINE_DLL=1)
5352
target_link_libraries(GLFWDemo
5453
PRIVATE
5554
Diligent-Common

Samples/GLFWDemo/src/GLFWDemo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
* of the possibility of such damages.
2626
*/
2727

28-
#ifndef ENGINE_DLL
29-
# define ENGINE_DLL 1
30-
#endif
31-
3228
#ifndef D3D11_SUPPORTED
3329
# define D3D11_SUPPORTED 0
3430
#endif

Samples/USDViewer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ target_link_libraries(USDViewer
8787
PRIVATE
8888
Diligent-Hydrogent
8989
DiligentFX
90+
Diligent-Archiver-static
9091
)
9192
set_target_properties(USDViewer PROPERTIES CXX_STANDARD 17)
9293
target_compile_definitions(USDViewer PRIVATE DILIGENT_FX_SHADERS_DIR="${DILIGENT_FX_SOURCE_DIR}/Shaders" HYDROGENT_SHADERS_DIR="${HYDROGENT_SOURCE_DIR}/shaders")

Samples/USDViewer/src/USDViewer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "FileSystem.hpp"
3939
#include "Timer.hpp"
4040
#include "RenderStateCache.h"
41+
#include "ArchiverFactoryLoader.h"
4142
#include "ThreadPool.hpp"
4243

4344
#include "Tasks/HnReadRprimIdTask.hpp"
@@ -186,7 +187,8 @@ void USDViewer::Initialize(const SampleInitInfo& InitInfo)
186187
{
187188
// Create render state cache
188189
RenderStateCacheCreateInfo StateCacheCI;
189-
StateCacheCI.LogLevel = RENDER_STATE_CACHE_LOG_LEVEL_NORMAL;
190+
StateCacheCI.pArchiverFactory = LoadAndGetArchiverFactory();
191+
StateCacheCI.LogLevel = RENDER_STATE_CACHE_LOG_LEVEL_NORMAL;
190192

191193
RefCntAutoPtr<IShaderSourceInputStreamFactory> pReloadFactory;
192194
if (m_EnableHotShaderReload)

Tutorials/Tutorial00_HelloWin32/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ set_target_properties(Tutorial00_HelloWin32 PROPERTIES
1515
FOLDER DiligentSamples/Tutorials
1616
)
1717

18-
target_compile_definitions(Tutorial00_HelloWin32 PRIVATE ENGINE_DLL=1)
1918
target_link_libraries(Tutorial00_HelloWin32 PRIVATE Diligent-BuildSettings)
2019

2120
if(D3D11_SUPPORTED)

Tutorials/Tutorial00_HelloWin32/src/Tutorial00_HelloWin32.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
# define PLATFORM_WIN32 1
4040
#endif
4141

42-
#ifndef ENGINE_DLL
43-
# define ENGINE_DLL 1
44-
#endif
45-
4642
#ifndef D3D11_SUPPORTED
4743
# define D3D11_SUPPORTED 1
4844
#endif
@@ -145,11 +141,8 @@ class Tutorial00App
145141
case RENDER_DEVICE_TYPE_D3D11:
146142
{
147143
EngineD3D11CreateInfo EngineCI;
148-
# if ENGINE_DLL
149-
// Load the dll and import GetEngineFactoryD3D11() function
150-
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
151-
# endif
152-
IEngineFactoryD3D11* pFactoryD3D11 = GetEngineFactoryD3D11();
144+
// Load the Direct3D11 engine library and get the factory interface
145+
IEngineFactoryD3D11* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11();
153146
pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &m_pDevice, &m_pImmediateContext);
154147
Win32NativeWindow Window{hWnd};
155148
pFactoryD3D11->CreateSwapChainD3D11(m_pDevice, m_pImmediateContext, SCDesc, FullScreenModeDesc{}, Window, &m_pSwapChain);
@@ -161,13 +154,9 @@ class Tutorial00App
161154
#if D3D12_SUPPORTED
162155
case RENDER_DEVICE_TYPE_D3D12:
163156
{
164-
# if ENGINE_DLL
165-
// Load the dll and import GetEngineFactoryD3D12() function
166-
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
167-
# endif
168157
EngineD3D12CreateInfo EngineCI;
169-
170-
IEngineFactoryD3D12* pFactoryD3D12 = GetEngineFactoryD3D12();
158+
// Load the Direct3D12 engine library and get the factory interface
159+
IEngineFactoryD3D12* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12();
171160
pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &m_pDevice, &m_pImmediateContext);
172161
Win32NativeWindow Window{hWnd};
173162
pFactoryD3D12->CreateSwapChainD3D12(m_pDevice, m_pImmediateContext, SCDesc, FullScreenModeDesc{}, Window, &m_pSwapChain);
@@ -179,11 +168,8 @@ class Tutorial00App
179168
#if GL_SUPPORTED
180169
case RENDER_DEVICE_TYPE_GL:
181170
{
182-
# if EXPLICITLY_LOAD_ENGINE_GL_DLL
183-
// Load the dll and import GetEngineFactoryOpenGL() function
184-
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
185-
# endif
186-
IEngineFactoryOpenGL* pFactoryOpenGL = GetEngineFactoryOpenGL();
171+
// Load the OpenGL engine library and get the factory interface
172+
IEngineFactoryOpenGL* pFactoryOpenGL = LoadAndGetEngineFactoryOpenGL();
187173

188174
EngineGLCreateInfo EngineCI;
189175
EngineCI.Window.hWnd = hWnd;
@@ -197,13 +183,10 @@ class Tutorial00App
197183
#if VULKAN_SUPPORTED
198184
case RENDER_DEVICE_TYPE_VULKAN:
199185
{
200-
# if EXPLICITLY_LOAD_ENGINE_VK_DLL
201-
// Load the dll and import GetEngineFactoryVk() function
202-
GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
203-
# endif
204186
EngineVkCreateInfo EngineCI;
205187

206-
IEngineFactoryVk* pFactoryVk = GetEngineFactoryVk();
188+
// Load the Vulkan engine library and get the factory interface
189+
IEngineFactoryVk* pFactoryVk = LoadAndGetEngineFactoryVk();
207190
pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &m_pDevice, &m_pImmediateContext);
208191

209192
if (!m_pSwapChain && hWnd != nullptr)

Tutorials/Tutorial15_MultipleWindows/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ set_target_properties(Tutorial15_MultipleWindows PROPERTIES
1515
FOLDER DiligentSamples/Tutorials
1616
)
1717

18-
target_compile_definitions(Tutorial15_MultipleWindows PRIVATE ENGINE_DLL=1)
1918
target_link_libraries(Tutorial15_MultipleWindows PRIVATE Diligent-BuildSettings)
2019

2120
if(D3D11_SUPPORTED)

Tutorials/Tutorial15_MultipleWindows/src/Tutorial15_MultipleWindows.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
# define PLATFORM_WIN32 1
4343
#endif
4444

45-
#ifndef ENGINE_DLL
46-
# define ENGINE_DLL 1
47-
#endif
48-
4945
#ifndef D3D11_SUPPORTED
5046
# define D3D11_SUPPORTED 1
5147
#endif
@@ -154,11 +150,7 @@ class Tutorial00App
154150
{
155151
EngineD3D11CreateInfo EngineCI;
156152

157-
# if ENGINE_DLL
158-
// Load the dll and import GetEngineFactoryD3D11() function
159-
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
160-
# endif
161-
IEngineFactoryD3D11* pFactoryD3D11 = GetEngineFactoryD3D11();
153+
IEngineFactoryD3D11* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11();
162154
pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &m_pDevice, &m_pImmediateContext);
163155
for (WindowInfo& WndInfo : m_Windows)
164156
{
@@ -174,13 +166,9 @@ class Tutorial00App
174166
#if D3D12_SUPPORTED
175167
case RENDER_DEVICE_TYPE_D3D12:
176168
{
177-
# if ENGINE_DLL
178-
// Load the dll and import GetEngineFactoryD3D12() function
179-
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
180-
# endif
181169
EngineD3D12CreateInfo EngineCI;
182170

183-
IEngineFactoryD3D12* pFactoryD3D12 = GetEngineFactoryD3D12();
171+
IEngineFactoryD3D12* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12();
184172
pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &m_pDevice, &m_pImmediateContext);
185173
for (WindowInfo& WndInfo : m_Windows)
186174
{
@@ -196,13 +184,8 @@ class Tutorial00App
196184
#if GL_SUPPORTED
197185
case RENDER_DEVICE_TYPE_GL:
198186
{
199-
200-
# if EXPLICITLY_LOAD_ENGINE_GL_DLL
201-
// Load the dll and import GetEngineFactoryOpenGL() function
202-
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
203-
# endif
204187
MessageBox(NULL, L"OpenGL backend does not currently support multiple swap chains", L"Error", MB_OK | MB_ICONWARNING);
205-
IEngineFactoryOpenGL* pFactoryOpenGL = GetEngineFactoryOpenGL();
188+
IEngineFactoryOpenGL* pFactoryOpenGL = LoadAndGetEngineFactoryOpenGL();
206189

207190
EngineGLCreateInfo EngineCI;
208191

@@ -218,13 +201,9 @@ class Tutorial00App
218201
#if VULKAN_SUPPORTED
219202
case RENDER_DEVICE_TYPE_VULKAN:
220203
{
221-
# if EXPLICITLY_LOAD_ENGINE_VK_DLL
222-
// Load the dll and import GetEngineFactoryVk() function
223-
GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
224-
# endif
225204
EngineVkCreateInfo EngineCI;
226205

227-
IEngineFactoryVk* pFactoryVk = GetEngineFactoryVk();
206+
IEngineFactoryVk* pFactoryVk = LoadAndGetEngineFactoryVk();
228207
pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &m_pDevice, &m_pImmediateContext);
229208
for (WindowInfo& WndInfo : m_Windows)
230209
{

Tutorials/Tutorial26_StateCache/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ add_sample_app(Tutorial26_StateCache
2121
assets/PBR_Common.fxh
2222
)
2323

24-
target_link_libraries(Tutorial26_StateCache PRIVATE Diligent-RenderStateNotation)
24+
target_link_libraries(Tutorial26_StateCache
25+
PRIVATE
26+
Diligent-RenderStateNotation
27+
Diligent-Archiver-static
28+
)
2529

2630
add_custom_command(TARGET Tutorial26_StateCache PRE_BUILD
2731
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../../../DiligentFX/Shaders/Common/public/PBR_Common.fxh" "${CMAKE_CURRENT_SOURCE_DIR}/assets"

0 commit comments

Comments
 (0)