Skip to content

Commit 634dd4b

Browse files
Render State Cache: use archiver factory from create info to initialize the cache (close #701)
This makes the cache initialization more flexible, and removes dependency of GraphicsTools on Archiver
1 parent d57c606 commit 634dd4b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

Graphics/GraphicsTools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ PUBLIC
157157
if(ARCHIVER_SUPPORTED)
158158
target_link_libraries(Diligent-GraphicsTools
159159
PRIVATE
160-
Diligent-Archiver-static
160+
Diligent-ArchiverInterface
161161
)
162162
endif()
163163

Graphics/GraphicsTools/interface/RenderStateCache.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ struct RenderStateCacheCreateInfo
5656
/// A pointer to the render device, must not be null.
5757
IRenderDevice* pDevice DEFAULT_INITIALIZER(nullptr);
5858

59+
/// Archiver factory, must not be null.
60+
61+
/// Use `LoadAndGetArchiverFactory()` from `ArchiverFactoryLoader.h` to create the factory.
62+
struct IArchiverFactory* pArchiverFactory DEFAULT_INITIALIZER(nullptr);
63+
5964
/// Logging level, see Diligent::RENDER_STATE_CACHE_LOG_LEVEL.
6065
RENDER_STATE_CACHE_LOG_LEVEL LogLevel DEFAULT_INITIALIZER(RENDER_STATE_CACHE_LOG_LEVEL_NORMAL);
6166

@@ -82,11 +87,13 @@ struct RenderStateCacheCreateInfo
8287

8388
constexpr explicit RenderStateCacheCreateInfo(
8489
IRenderDevice* _pDevice,
90+
struct IArchiverFactory* _pArchiverFactory,
8591
RENDER_STATE_CACHE_LOG_LEVEL _LogLevel = RenderStateCacheCreateInfo{}.LogLevel,
8692
bool _EnableHotReload = RenderStateCacheCreateInfo{}.EnableHotReload,
8793
bool _OptimizeGLShaders = RenderStateCacheCreateInfo{}.OptimizeGLShaders,
8894
IShaderSourceInputStreamFactory* _pReloadSource = RenderStateCacheCreateInfo{}.pReloadSource) noexcept :
8995
pDevice{_pDevice},
96+
pArchiverFactory{_pArchiverFactory},
9097
LogLevel{_LogLevel},
9198
EnableHotReload{_EnableHotReload},
9299
OptimizeGLShaders{_OptimizeGLShaders},

Graphics/GraphicsTools/src/RenderStateCacheImpl.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "Archiver.h"
4040
#include "Dearchiver.h"
4141
#include "ArchiverFactory.h"
42-
#include "ArchiverFactoryLoader.h"
4342

4443
#include "PipelineStateBase.hpp"
4544
#include "RefCntAutoPtr.hpp"
@@ -177,10 +176,14 @@ RenderStateCacheImpl::RenderStateCacheImpl(IReferenceCounters* pRe
177176
// clang-format on
178177
{
179178
if (CreateInfo.pDevice == nullptr)
179+
{
180180
LOG_ERROR_AND_THROW("CreateInfo.pDevice must not be null");
181+
}
181182

182-
IArchiverFactory* pArchiverFactory = LoadAndGetArchiverFactory();
183-
VERIFY_EXPR(pArchiverFactory != nullptr);
183+
if (CreateInfo.pArchiverFactory == nullptr)
184+
{
185+
LOG_ERROR_AND_THROW("CreateInfo.pArchiverFactory must not be null. Use LoadAndGetArchiverFactory() from ArchiverFactoryLoader.h to create the factory.");
186+
}
184187

185188
SerializationDeviceCreateInfo SerializationDeviceCI;
186189
SerializationDeviceCI.DeviceInfo = m_pDevice->GetDeviceInfo();
@@ -219,13 +222,13 @@ RenderStateCacheImpl::RenderStateCacheImpl(IReferenceCounters* pRe
219222
UNEXPECTED("Unknown device type");
220223
}
221224

222-
pArchiverFactory->CreateSerializationDevice(SerializationDeviceCI, &m_pSerializationDevice);
225+
CreateInfo.pArchiverFactory->CreateSerializationDevice(SerializationDeviceCI, &m_pSerializationDevice);
223226
if (!m_pSerializationDevice)
224227
LOG_ERROR_AND_THROW("Failed to create serialization device");
225228

226229
m_pSerializationDevice->AddRenderDevice(m_pDevice);
227230

228-
pArchiverFactory->CreateArchiver(m_pSerializationDevice, &m_pArchiver);
231+
CreateInfo.pArchiverFactory->CreateArchiver(m_pSerializationDevice, &m_pArchiver);
229232
if (!m_pArchiver)
230233
LOG_ERROR_AND_THROW("Failed to create archiver");
231234

Tests/DiligentCoreAPITest/src/RenderStateCacheTest.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,14 @@ RefCntAutoPtr<IRenderStateCache> CreateCache(IRenderDevice* pD
249249
IDataBlob* pCacheData = nullptr,
250250
IShaderSourceInputStreamFactory* pShaderReloadFactory = nullptr)
251251
{
252-
RenderStateCacheCreateInfo CacheCI{pDevice, RENDER_STATE_CACHE_LOG_LEVEL_VERBOSE, HotReload, OptimizeGLShaders, pShaderReloadFactory};
252+
RenderStateCacheCreateInfo CacheCI{
253+
pDevice,
254+
GPUTestingEnvironment::GetInstance()->GetArchiverFactory(),
255+
RENDER_STATE_CACHE_LOG_LEVEL_VERBOSE,
256+
HotReload,
257+
OptimizeGLShaders,
258+
pShaderReloadFactory,
259+
};
253260

254261
RefCntAutoPtr<IRenderStateCache> pCache;
255262
CreateRenderStateCache(CacheCI, &pCache);

0 commit comments

Comments
 (0)