Skip to content

Commit cf8eb68

Browse files
Render state cache: reworked reload callback to handle graphics pipeline desc
1 parent 7ef614b commit cf8eb68

File tree

3 files changed

+45
-40
lines changed

3 files changed

+45
-40
lines changed

Graphics/GraphicsTools/interface/RenderStateCache.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ typedef struct RenderStateCacheCreateInfo RenderStateCacheCreateInfo;
7878
#endif
7979

8080
/// Type of the callback function called by the IRenderStateCache::Reload method.
81-
typedef void(DILIGENT_CALL_TYPE* ModifyPipelineReloadInfoCallbackType)(PipelineStateCreateInfo REF CreateInfo, void* pUserData);
81+
typedef void(DILIGENT_CALL_TYPE* ReloadGraphicsPipelineCallbackType)(const char* PipelineName, GraphicsPipelineDesc REF GraphicsDesc, void* pUserData);
8282

8383
#undef REF
8484

@@ -188,22 +188,18 @@ DILIGENT_BEGIN_INTERFACE(IRenderStateCache, IObject)
188188

189189
/// Reloads render states in the cache.
190190

191-
/// \param [in] ModifyReloadInfo - An optional callback function that will be called by the render state cache
192-
/// to let the application modify pipeline state create info before creating new
193-
/// pipeline.
194-
/// \param [in] pUserData - A pointer to user-specific data to pass to ModifyReloadInfo callback.
191+
/// \param [in] ReloadGraphicsPipeline - An optional callback function that will be called by the render state cache
192+
/// to let the application modify graphics pipeline state info before creating new
193+
/// pipeline.
194+
/// \param [in] pUserData - A pointer to the user-specific data to pass to ReloadGraphicsPipeline callback.
195195
///
196196
/// \return The total number of render states (shaders and pipelines) that were reloaded.
197197
///
198198
/// \remars Reloading is only enabled if the cache was created with the EnableHotReload member of
199199
/// RenderStateCacheCreateInfo member set to true.
200-
///
201-
/// ModifyReloadInfo callback is not allowed to modify shaders, resource layout or pipeline resource
202-
/// signatures. Its main use is to modify the graphics states of a graphics pipeline (blend state,
203-
/// rasterizer state, depth state, etc.).
204200
VIRTUAL Uint32 METHOD(Reload)(THIS_
205-
ModifyPipelineReloadInfoCallbackType ModifyReloadInfo DEFAULT_VALUE(nullptr),
206-
void* pUserData DEFAULT_VALUE(nullptr)) PURE;
201+
ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline DEFAULT_VALUE(nullptr),
202+
void* pUserData DEFAULT_VALUE(nullptr)) PURE;
207203
};
208204
DILIGENT_END_INTERFACE
209205

Graphics/GraphicsTools/src/RenderStateCache.cpp

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ class ReloadablePipelineState final : public ObjectBase<IPipelineState>
222222
}
223223
}
224224

225-
bool Reload(ModifyPipelineReloadInfoCallbackType ModifyReloadInfo, void* pUserData);
225+
bool Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData);
226226

227227
private:
228228
template <typename CreateInfoType>
229-
bool Reload(ModifyPipelineReloadInfoCallbackType ModifyReloadInfo, void* pUserData);
229+
bool Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData);
230230

231231
struct DynamicHeapObjectBase
232232
{
@@ -341,7 +341,7 @@ class RenderStateCacheImpl final : public ObjectBase<IRenderStateCache>
341341
m_Pipelines.clear();
342342
}
343343

344-
virtual Uint32 DILIGENT_CALL_TYPE Reload(ModifyPipelineReloadInfoCallbackType ModifyReloadInfo, void* pUserData) override final;
344+
virtual Uint32 DILIGENT_CALL_TYPE Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData) override final;
345345

346346
bool CreateShaderInternal(const ShaderCreateInfo& ShaderCI,
347347
IShader** ppShader);
@@ -1097,7 +1097,7 @@ bool RenderStateCacheImpl::CreatePipelineStateInternal(const CreateInfoType& PSO
10971097
return false;
10981098
}
10991099

1100-
Uint32 RenderStateCacheImpl::Reload(ModifyPipelineReloadInfoCallbackType ModifyReloadInfo, void* pUserData)
1100+
Uint32 RenderStateCacheImpl::Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData)
11011101
{
11021102
if (!m_CI.EnableHotReload)
11031103
{
@@ -1136,7 +1136,7 @@ Uint32 RenderStateCacheImpl::Reload(ModifyPipelineReloadInfoCallbackType ModifyR
11361136
RefCntAutoPtr<ReloadablePipelineState> pReloadablePSO{pPSO, ReloadablePipelineState::IID_InternalImpl};
11371137
if (pPSO)
11381138
{
1139-
if (pReloadablePSO->Reload(ModifyReloadInfo, pUserData))
1139+
if (pReloadablePSO->Reload(ReloadGraphicsPipeline, pUserData))
11401140
++NumStatesReloaded;
11411141
}
11421142
else
@@ -1193,7 +1193,12 @@ struct ReloadablePipelineState::CreateInfoWrapperBase : DynamicHeapObjectBase
11931193
return m_CI;
11941194
}
11951195

1196-
operator const CreateInfoType&()
1196+
operator const CreateInfoType&() const
1197+
{
1198+
return m_CI;
1199+
}
1200+
1201+
operator CreateInfoType&()
11971202
{
11981203
return m_CI;
11991204
}
@@ -1354,22 +1359,28 @@ ReloadablePipelineState::ReloadablePipelineState(IReferenceCounters*
13541359
}
13551360

13561361
template <typename CreateInfoType>
1357-
bool ReloadablePipelineState::Reload(ModifyPipelineReloadInfoCallbackType ModifyReloadInfo, void* pUserData)
1362+
void ModifyPsoCreateInfo(CreateInfoType& PsoCreateInfo, ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData)
13581363
{
1359-
const auto& CreateInfo = static_cast<const CreateInfoWrapper<CreateInfoType>&>(*m_pCreateInfo).Get();
1364+
}
13601365

1361-
RefCntAutoPtr<IPipelineState> pNewPSO;
1362-
bool FoundInCache = false;
1363-
if (ModifyReloadInfo != nullptr)
1364-
{
1365-
auto _CreateInfo = CreateInfo;
1366-
ModifyReloadInfo(_CreateInfo, pUserData);
1367-
FoundInCache = m_pStateCache->CreatePipelineStateInternal(_CreateInfo, &pNewPSO);
1368-
}
1369-
else
1366+
template <>
1367+
void ModifyPsoCreateInfo(GraphicsPipelineStateCreateInfo& PsoCreateInfo, ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData)
1368+
{
1369+
if (ReloadGraphicsPipeline != nullptr)
13701370
{
1371-
FoundInCache = m_pStateCache->CreatePipelineStateInternal(CreateInfo, &pNewPSO);
1371+
ReloadGraphicsPipeline(PsoCreateInfo.PSODesc.Name, PsoCreateInfo.GraphicsPipeline, pUserData);
13721372
}
1373+
}
1374+
1375+
template <typename CreateInfoType>
1376+
bool ReloadablePipelineState::Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData)
1377+
{
1378+
auto& CreateInfo = static_cast<CreateInfoWrapper<CreateInfoType>&>(*m_pCreateInfo);
1379+
ModifyPsoCreateInfo<CreateInfoType>(static_cast<CreateInfoType&>(CreateInfo), ReloadGraphicsPipeline, pUserData);
1380+
1381+
RefCntAutoPtr<IPipelineState> pNewPSO;
1382+
1383+
const auto FoundInCache = m_pStateCache->CreatePipelineStateInternal(static_cast<const CreateInfoType&>(CreateInfo), &pNewPSO);
13731384

13741385
if (pNewPSO)
13751386
{
@@ -1381,14 +1392,14 @@ bool ReloadablePipelineState::Reload(ModifyPipelineReloadInfoCallbackType Modify
13811392
}
13821393
else
13831394
{
1384-
const auto* Name = CreateInfo.PSODesc.Name;
1395+
const auto* Name = CreateInfo.Get().PSODesc.Name;
13851396
LOG_ERROR_MESSAGE("Failed to reload pipeline state '", (Name ? Name : "<unnamed>"), "'.");
13861397
}
13871398
return !FoundInCache;
13881399
}
13891400

13901401

1391-
bool ReloadablePipelineState::Reload(ModifyPipelineReloadInfoCallbackType ModifyReloadInfo, void* pUserData)
1402+
bool ReloadablePipelineState::Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData)
13921403
{
13931404
static_assert(PIPELINE_TYPE_COUNT == 5, "Did you add a new pipeline type? You may need to handle it here.");
13941405
// Note that all shaders in Create Info are reloadable shaders, so they will automatically redirect all calls
@@ -1397,16 +1408,16 @@ bool ReloadablePipelineState::Reload(ModifyPipelineReloadInfoCallbackType Modify
13971408
{
13981409
case PIPELINE_TYPE_GRAPHICS:
13991410
case PIPELINE_TYPE_MESH:
1400-
return Reload<GraphicsPipelineStateCreateInfo>(ModifyReloadInfo, pUserData);
1411+
return Reload<GraphicsPipelineStateCreateInfo>(ReloadGraphicsPipeline, pUserData);
14011412

14021413
case PIPELINE_TYPE_COMPUTE:
1403-
return Reload<ComputePipelineStateCreateInfo>(ModifyReloadInfo, pUserData);
1414+
return Reload<ComputePipelineStateCreateInfo>(ReloadGraphicsPipeline, pUserData);
14041415

14051416
case PIPELINE_TYPE_RAY_TRACING:
1406-
return Reload<RayTracingPipelineStateCreateInfo>(ModifyReloadInfo, pUserData);
1417+
return Reload<RayTracingPipelineStateCreateInfo>(ReloadGraphicsPipeline, pUserData);
14071418

14081419
case PIPELINE_TYPE_TILE:
1409-
return Reload<TilePipelineStateCreateInfo>(ModifyReloadInfo, pUserData);
1420+
return Reload<TilePipelineStateCreateInfo>(ReloadGraphicsPipeline, pUserData);
14101421

14111422
default:
14121423
UNEXPECTED("Unexpected pipeline type");

Tests/DiligentCoreAPITest/src/RenderStateCacheTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,9 @@ void TestPipelineReload(bool UseRenderPass, bool CreateSrbBeforeReload = false)
10621062
}
10631063

10641064
auto ModifyPSO = MakeCallback(
1065-
[&](PipelineStateCreateInfo& CreateInfo) {
1066-
ASSERT_STREQ(CreateInfo.PSODesc.Name, PSOName);
1067-
auto& GraphicsPsoCI = static_cast<GraphicsPipelineStateCreateInfo&>(CreateInfo);
1068-
1069-
GraphicsPsoCI.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
1065+
[&](const char* PipelineName, GraphicsPipelineDesc& GraphicsPipeline) {
1066+
ASSERT_STREQ(PipelineName, PSOName);
1067+
GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
10701068
});
10711069

10721070
EXPECT_EQ(pCache->Reload(ModifyPSO, ModifyPSO), pass == 0 ? 3u : 0u);

0 commit comments

Comments
 (0)