From 7313cc6879f26ca280edecdc5c4606335a6bc958 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 8 Jan 2025 22:29:10 -0800 Subject: [PATCH] ProxyPipelineState: keep a copy of PSO desc --- .../include/AsyncPipelineState.hpp | 3 +- .../include/ProxyPipelineState.hpp | 28 +++++++++++++------ .../include/ReloadablePipelineState.hpp | 3 +- .../GraphicsTools/src/AsyncPipelineState.cpp | 7 ++--- .../src/ReloadablePipelineState.cpp | 9 +++--- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Graphics/GraphicsTools/include/AsyncPipelineState.hpp b/Graphics/GraphicsTools/include/AsyncPipelineState.hpp index 48ee29b35..0693b4121 100644 --- a/Graphics/GraphicsTools/include/AsyncPipelineState.hpp +++ b/Graphics/GraphicsTools/include/AsyncPipelineState.hpp @@ -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. @@ -82,7 +82,6 @@ class AsyncPipelineState final : public ProxyPipelineState m_pStateCache; std::unique_ptr m_pCreateInfo; - const PIPELINE_TYPE m_Type; UniqueIdHelper m_UniqueID; }; diff --git a/Graphics/GraphicsTools/include/ProxyPipelineState.hpp b/Graphics/GraphicsTools/include/ProxyPipelineState.hpp index af11528dc..fbbdfc6f2 100644 --- a/Graphics/GraphicsTools/include/ProxyPipelineState.hpp +++ b/Graphics/GraphicsTools/include/ProxyPipelineState.hpp @@ -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. @@ -31,6 +31,7 @@ #include "PipelineState.h" #include "RefCntAutoPtr.hpp" +#include "PipelineStateBase.hpp" namespace Diligent { @@ -42,15 +43,15 @@ class ProxyPipelineState : public Base { public: template - ProxyPipelineState(Args&&... args) : - Base{std::forward(args)...} + ProxyPipelineState(const PipelineStateDesc& PSODesc, Args&&... args) : + Base{std::forward(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 @@ -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 @@ -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 @@ -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 @@ -168,6 +175,9 @@ class ProxyPipelineState : public Base } protected: + const std::string m_Name; + const PipelineStateDesc m_Desc; + RefCntAutoPtr m_pPipeline; }; diff --git a/Graphics/GraphicsTools/include/ReloadablePipelineState.hpp b/Graphics/GraphicsTools/include/ReloadablePipelineState.hpp index cfcf64512..8671b272a 100644 --- a/Graphics/GraphicsTools/include/ReloadablePipelineState.hpp +++ b/Graphics/GraphicsTools/include/ReloadablePipelineState.hpp @@ -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. @@ -84,7 +84,6 @@ class ReloadablePipelineState final : public ProxyPipelineState m_pStateCache; std::unique_ptr m_pCreateInfo; - const PIPELINE_TYPE m_Type; // Old pipeline state kept around to copy static resources from RefCntAutoPtr m_pOldPipeline; diff --git a/Graphics/GraphicsTools/src/AsyncPipelineState.cpp b/Graphics/GraphicsTools/src/AsyncPipelineState.cpp index 57f5a8a02..285e38f91 100644 --- a/Graphics/GraphicsTools/src/AsyncPipelineState.cpp +++ b/Graphics/GraphicsTools/src/AsyncPipelineState.cpp @@ -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. @@ -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."); @@ -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: diff --git a/Graphics/GraphicsTools/src/ReloadablePipelineState.cpp b/Graphics/GraphicsTools/src/ReloadablePipelineState.cpp index 44d516ec6..0cb64075f 100644 --- a/Graphics/GraphicsTools/src/ReloadablePipelineState.cpp +++ b/Graphics/GraphicsTools/src/ReloadablePipelineState.cpp @@ -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. @@ -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; @@ -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: