Skip to content

Commit

Permalink
ProxyPipelineState: keep a copy of PSO desc
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jan 9, 2025
1 parent 41e6218 commit 7313cc6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
3 changes: 1 addition & 2 deletions Graphics/GraphicsTools/include/AsyncPipelineState.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diligent Graphics LLC
* Copyright 2024-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -82,7 +82,6 @@ class AsyncPipelineState final : public ProxyPipelineState<ObjectBase<IPipelineS

RefCntAutoPtr<RenderStateCacheImpl> m_pStateCache;
std::unique_ptr<CreateInfoWrapperBase> m_pCreateInfo;
const PIPELINE_TYPE m_Type;
UniqueIdHelper<AsyncPipelineState> m_UniqueID;
};

Expand Down
28 changes: 19 additions & 9 deletions Graphics/GraphicsTools/include/ProxyPipelineState.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diligent Graphics LLC
* Copyright 2024-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@

#include "PipelineState.h"
#include "RefCntAutoPtr.hpp"
#include "PipelineStateBase.hpp"

namespace Diligent
{
Expand All @@ -42,15 +43,15 @@ class ProxyPipelineState : public Base
{
public:
template <typename... Args>
ProxyPipelineState(Args&&... args) :
Base{std::forward<Args>(args)...}
ProxyPipelineState(const PipelineStateDesc& PSODesc, Args&&... args) :
Base{std::forward<Args>(args)...},
m_Name{PSODesc.Name != nullptr ? PSODesc.Name : ""},
m_Desc{m_Name.c_str(), PSODesc.PipelineType}
{}

virtual const PipelineStateDesc& DILIGENT_CALL_TYPE GetDesc() const override
{
DEV_CHECK_ERR(m_pPipeline, "Internal pipeline is null");
static constexpr PipelineStateDesc NullDesc;
return m_pPipeline ? m_pPipeline->GetDesc() : NullDesc;
return m_pPipeline ? m_pPipeline->GetDesc() : m_Desc;
}

virtual Int32 DILIGENT_CALL_TYPE GetUniqueID() const override
Expand All @@ -62,7 +63,10 @@ class ProxyPipelineState : public Base
virtual void DILIGENT_CALL_TYPE SetUserData(IObject* pUserData) override
{
DEV_CHECK_ERR(m_pPipeline, "Internal pipeline is null");
m_pPipeline->SetUserData(pUserData);
if (m_pPipeline)
{
m_pPipeline->SetUserData(pUserData);
}
}

virtual IObject* DILIGENT_CALL_TYPE GetUserData() const override
Expand Down Expand Up @@ -104,7 +108,7 @@ class ProxyPipelineState : public Base
virtual Uint32 DILIGENT_CALL_TYPE GetStaticVariableCount(SHADER_TYPE ShaderType) const override
{
DEV_CHECK_ERR(m_pPipeline, "Internal pipeline is null");
return m_pPipeline->GetStaticVariableCount(ShaderType);
return m_pPipeline ? m_pPipeline->GetStaticVariableCount(ShaderType) : 0;
}

virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) override
Expand All @@ -122,7 +126,10 @@ class ProxyPipelineState : public Base
virtual void DILIGENT_CALL_TYPE CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) override
{
DEV_CHECK_ERR(m_pPipeline, "Internal pipeline is null");
m_pPipeline->CreateShaderResourceBinding(ppShaderResourceBinding, InitStaticResources);
if (m_pPipeline)
{
m_pPipeline->CreateShaderResourceBinding(ppShaderResourceBinding, InitStaticResources);
}
}

virtual void DILIGENT_CALL_TYPE InitializeStaticSRBResources(IShaderResourceBinding* pShaderResourceBinding) const override
Expand Down Expand Up @@ -168,6 +175,9 @@ class ProxyPipelineState : public Base
}

protected:
const std::string m_Name;
const PipelineStateDesc m_Desc;

RefCntAutoPtr<IPipelineState> m_pPipeline;
};

Expand Down
3 changes: 1 addition & 2 deletions Graphics/GraphicsTools/include/ReloadablePipelineState.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diligent Graphics LLC
* Copyright 2024-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -84,7 +84,6 @@ class ReloadablePipelineState final : public ProxyPipelineState<ObjectBase<IPipe

RefCntAutoPtr<RenderStateCacheImpl> m_pStateCache;
std::unique_ptr<CreateInfoWrapperBase> m_pCreateInfo;
const PIPELINE_TYPE m_Type;

// Old pipeline state kept around to copy static resources from
RefCntAutoPtr<IPipelineState> m_pOldPipeline;
Expand Down
7 changes: 3 additions & 4 deletions Graphics/GraphicsTools/src/AsyncPipelineState.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diligent Graphics LLC
* Copyright 2024-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -73,9 +73,8 @@ struct AsyncPipelineState::CreateInfoWrapper : CreateInfoWrapperBase
AsyncPipelineState::AsyncPipelineState(IReferenceCounters* pRefCounters,
RenderStateCacheImpl* pStateCache,
const PipelineStateCreateInfo& CreateInfo) :
TBase{pRefCounters},
TBase{CreateInfo.PSODesc, pRefCounters},
m_pStateCache{pStateCache},
m_Type{CreateInfo.PSODesc.PipelineType},
m_UniqueID{}
{
static_assert(PIPELINE_TYPE_COUNT == 5, "Did you add a new pipeline type? You may need to handle it here.");
Expand Down Expand Up @@ -132,7 +131,7 @@ void AsyncPipelineState::QueryInterface(const INTERFACE_ID& IID, IObject** ppInt
void AsyncPipelineState::InitInternalPipeline()
{
static_assert(PIPELINE_TYPE_COUNT == 5, "Did you add a new pipeline type? You may need to handle it here.");
switch (m_Type)
switch (m_Desc.PipelineType)
{
case PIPELINE_TYPE_GRAPHICS:
case PIPELINE_TYPE_MESH:
Expand Down
9 changes: 4 additions & 5 deletions Graphics/GraphicsTools/src/ReloadablePipelineState.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diligent Graphics LLC
* Copyright 2024-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -82,9 +82,8 @@ ReloadablePipelineState::ReloadablePipelineState(IReferenceCounters*
RenderStateCacheImpl* pStateCache,
IPipelineState* pPipeline,
const PipelineStateCreateInfo& CreateInfo) :
TBase{pRefCounters},
m_pStateCache{pStateCache},
m_Type{CreateInfo.PSODesc.PipelineType}
TBase{CreateInfo.PSODesc, pRefCounters},
m_pStateCache{pStateCache}
{
m_pPipeline = pPipeline;

Expand Down Expand Up @@ -249,7 +248,7 @@ bool ReloadablePipelineState::Reload(ReloadGraphicsPipelineCallbackType ReloadGr
static_assert(PIPELINE_TYPE_COUNT == 5, "Did you add a new pipeline type? You may need to handle it here.");
// Note that all shaders in Create Info are reloadable shaders, so they will automatically redirect all calls
// to the updated internal shader
switch (m_Type)
switch (m_Desc.PipelineType)
{
case PIPELINE_TYPE_GRAPHICS:
case PIPELINE_TYPE_MESH:
Expand Down

0 comments on commit 7313cc6

Please sign in to comment.