Skip to content

Commit eb7bd97

Browse files
Refactored render state cache implementation
1 parent d9d0fe6 commit eb7bd97

File tree

8 files changed

+1920
-1605
lines changed

8 files changed

+1920
-1605
lines changed

Graphics/GraphicsTools/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ set(SOURCE
4646
src/VertexPool.cpp
4747
)
4848

49+
set(INCLUDE)
50+
4951
if(ARCHIVER_SUPPORTED)
5052
list(APPEND INTERFACE
5153
interface/RenderStateCache.h
5254
interface/RenderStateCache.hpp
5355
)
56+
list(APPEND INCLUDE
57+
include/RenderStateCacheImpl.hpp
58+
include/ReloadableShader.hpp
59+
include/ReloadablePipelineState.hpp
60+
)
5461
list(APPEND SOURCE
55-
src/RenderStateCache.cpp
62+
src/RenderStateCacheImpl.cpp
63+
src/ReloadableShader.cpp
64+
src/ReloadablePipelineState.cpp
5665
)
5766
set(RENDER_STATE_CACHE_SUPPORTED TRUE CACHE INTERNAL "Render state cache is supported")
5867
else()
@@ -102,13 +111,14 @@ if(METAL_SUPPORTED)
102111
list(APPEND DEPENDENCIES Diligent-GraphicsEngineMetalInterface)
103112
endif()
104113

105-
add_library(Diligent-GraphicsTools STATIC ${SOURCE} ${INTERFACE})
114+
add_library(Diligent-GraphicsTools STATIC ${SOURCE} ${INCLUDE} ${INTERFACE})
106115

107116
target_include_directories(Diligent-GraphicsTools
108117
PUBLIC
109118
interface
110119
PRIVATE
111120
../GraphicsEngineD3DBase/include
121+
include
112122
)
113123

114124
target_link_libraries(Diligent-GraphicsTools
@@ -147,6 +157,7 @@ set_common_target_properties(Diligent-GraphicsTools)
147157

148158
source_group("src" FILES ${SOURCE})
149159
source_group("interface" FILES ${INTERFACE})
160+
source_group("include" FILES ${INCLUDE})
150161

151162
set_target_properties(Diligent-GraphicsTools PROPERTIES
152163
FOLDER DiligentCore/Graphics
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Copyright 2024 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#pragma once
28+
29+
/// \file
30+
/// Definition of the Diligent::ReloadablePipelineState class
31+
32+
#include <memory>
33+
34+
#include "PipelineState.h"
35+
#include "RenderStateCache.h"
36+
#include "ObjectBase.hpp"
37+
#include "RefCntAutoPtr.hpp"
38+
39+
namespace Diligent
40+
{
41+
42+
class RenderStateCacheImpl;
43+
44+
/// Reloadable pipeline state implements the IPipelineState interface and delegates all
45+
/// calls to the internal pipeline object, which can be replaced at run-time.
46+
class ReloadablePipelineState final : public ObjectBase<IPipelineState>
47+
{
48+
public:
49+
using TBase = ObjectBase<IPipelineState>;
50+
51+
// {1F325E25-496B-41B4-A1F9-242302ABCDD4}
52+
static constexpr INTERFACE_ID IID_InternalImpl =
53+
{0x1f325e25, 0x496b, 0x41b4, {0xa1, 0xf9, 0x24, 0x23, 0x2, 0xab, 0xcd, 0xd4}};
54+
55+
ReloadablePipelineState(IReferenceCounters* pRefCounters,
56+
RenderStateCacheImpl* pStateCache,
57+
IPipelineState* pPipeline,
58+
const PipelineStateCreateInfo& CreateInfo);
59+
~ReloadablePipelineState();
60+
61+
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
62+
63+
// Delegate all calls to the internal pipeline object
64+
65+
virtual const PipelineStateDesc& DILIGENT_CALL_TYPE GetDesc() const override final
66+
{
67+
return m_pPipeline->GetDesc();
68+
}
69+
70+
virtual Int32 DILIGENT_CALL_TYPE GetUniqueID() const override final
71+
{
72+
return m_pPipeline->GetUniqueID();
73+
}
74+
75+
virtual void DILIGENT_CALL_TYPE SetUserData(IObject* pUserData) override final
76+
{
77+
m_pPipeline->SetUserData(pUserData);
78+
}
79+
80+
virtual IObject* DILIGENT_CALL_TYPE GetUserData() const override final
81+
{
82+
return m_pPipeline->GetUserData();
83+
}
84+
85+
virtual const GraphicsPipelineDesc& DILIGENT_CALL_TYPE GetGraphicsPipelineDesc() const override final
86+
{
87+
return m_pPipeline->GetGraphicsPipelineDesc();
88+
}
89+
90+
virtual const RayTracingPipelineDesc& DILIGENT_CALL_TYPE GetRayTracingPipelineDesc() const override final
91+
{
92+
return m_pPipeline->GetRayTracingPipelineDesc();
93+
}
94+
95+
virtual const TilePipelineDesc& DILIGENT_CALL_TYPE GetTilePipelineDesc() const override final
96+
{
97+
return m_pPipeline->GetTilePipelineDesc();
98+
}
99+
100+
virtual void DILIGENT_CALL_TYPE BindStaticResources(SHADER_TYPE ShaderStages, IResourceMapping* pResourceMapping, BIND_SHADER_RESOURCES_FLAGS Flags) override final
101+
{
102+
m_pPipeline->BindStaticResources(ShaderStages, pResourceMapping, Flags);
103+
}
104+
105+
virtual Uint32 DILIGENT_CALL_TYPE GetStaticVariableCount(SHADER_TYPE ShaderType) const override final
106+
{
107+
return m_pPipeline->GetStaticVariableCount(ShaderType);
108+
}
109+
110+
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) override final
111+
{
112+
return m_pPipeline->GetStaticVariableByName(ShaderType, Name);
113+
}
114+
115+
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final
116+
{
117+
return m_pPipeline->GetStaticVariableByIndex(ShaderType, Index);
118+
}
119+
120+
virtual void DILIGENT_CALL_TYPE CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) override final
121+
{
122+
m_pPipeline->CreateShaderResourceBinding(ppShaderResourceBinding, InitStaticResources);
123+
}
124+
125+
virtual void DILIGENT_CALL_TYPE InitializeStaticSRBResources(IShaderResourceBinding* pShaderResourceBinding) const override final
126+
{
127+
m_pPipeline->InitializeStaticSRBResources(pShaderResourceBinding);
128+
}
129+
130+
virtual void DILIGENT_CALL_TYPE CopyStaticResources(IPipelineState* pPSO) const override final
131+
{
132+
m_pPipeline->CopyStaticResources(pPSO);
133+
}
134+
135+
virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineState* pPSO) const override final
136+
{
137+
return m_pPipeline->IsCompatibleWith(pPSO);
138+
}
139+
140+
virtual Uint32 DILIGENT_CALL_TYPE GetResourceSignatureCount() const override final
141+
{
142+
return m_pPipeline->GetResourceSignatureCount();
143+
}
144+
145+
virtual IPipelineResourceSignature* DILIGENT_CALL_TYPE GetResourceSignature(Uint32 Index) const override final
146+
{
147+
return m_pPipeline->GetResourceSignature(Index);
148+
}
149+
150+
virtual PIPELINE_STATE_STATUS DILIGENT_CALL_TYPE GetStatus(bool WaitForCompletion) override final
151+
{
152+
return m_pPipeline->GetStatus(WaitForCompletion);
153+
}
154+
155+
static void Create(RenderStateCacheImpl* pStateCache,
156+
IPipelineState* pPipeline,
157+
const PipelineStateCreateInfo& CreateInfo,
158+
IPipelineState** ppReloadablePipeline);
159+
160+
bool Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData);
161+
162+
private:
163+
template <typename CreateInfoType>
164+
bool Reload(ReloadGraphicsPipelineCallbackType ReloadGraphicsPipeline, void* pUserData);
165+
166+
struct DynamicHeapObjectBase
167+
{
168+
virtual ~DynamicHeapObjectBase() {}
169+
};
170+
171+
template <typename CreateInfoType>
172+
struct CreateInfoWrapperBase;
173+
174+
template <typename CreateInfoType>
175+
struct CreateInfoWrapper;
176+
177+
RefCntAutoPtr<RenderStateCacheImpl> m_pStateCache;
178+
RefCntAutoPtr<IPipelineState> m_pPipeline;
179+
std::unique_ptr<DynamicHeapObjectBase> m_pCreateInfo;
180+
const PIPELINE_TYPE m_Type;
181+
};
182+
183+
} // namespace Diligent
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2024 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#pragma once
28+
29+
/// \file
30+
/// Definition of the Diligent::ReloadableShader class
31+
32+
#include "Shader.h"
33+
#include "ShaderBase.hpp"
34+
35+
namespace Diligent
36+
{
37+
38+
class RenderStateCacheImpl;
39+
40+
/// Reloadable shader implements the IShader interface and delegates all
41+
/// calls to the internal shader object, which can be replaced at run-time.
42+
class ReloadableShader final : public ObjectBase<IShader>
43+
{
44+
public:
45+
using TBase = ObjectBase<IShader>;
46+
47+
// {6BFAAABD-FE55-4420-B0C8-5C4B4F5F8D65}
48+
static constexpr INTERFACE_ID IID_InternalImpl =
49+
{0x6bfaaabd, 0xfe55, 0x4420, {0xb0, 0xc8, 0x5c, 0x4b, 0x4f, 0x5f, 0x8d, 0x65}};
50+
51+
ReloadableShader(IReferenceCounters* pRefCounters,
52+
RenderStateCacheImpl* pStateCache,
53+
IShader* pShader,
54+
const ShaderCreateInfo& CreateInfo);
55+
56+
~ReloadableShader();
57+
58+
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
59+
60+
// Delegate all calls to the internal shader object
61+
62+
virtual const ShaderDesc& DILIGENT_CALL_TYPE GetDesc() const override final
63+
{
64+
return m_pShader->GetDesc();
65+
}
66+
67+
virtual Int32 DILIGENT_CALL_TYPE GetUniqueID() const override final
68+
{
69+
return m_pShader->GetUniqueID();
70+
}
71+
72+
virtual void DILIGENT_CALL_TYPE SetUserData(IObject* pUserData) override final
73+
{
74+
m_pShader->SetUserData(pUserData);
75+
}
76+
77+
virtual IObject* DILIGENT_CALL_TYPE GetUserData() const override final
78+
{
79+
return m_pShader->GetUserData();
80+
}
81+
82+
virtual Uint32 DILIGENT_CALL_TYPE GetResourceCount() const override final
83+
{
84+
return m_pShader->GetResourceCount();
85+
}
86+
87+
virtual void DILIGENT_CALL_TYPE GetResourceDesc(Uint32 Index, ShaderResourceDesc& ResourceDesc) const override final
88+
{
89+
m_pShader->GetResourceDesc(Index, ResourceDesc);
90+
}
91+
92+
virtual const ShaderCodeBufferDesc* DILIGENT_CALL_TYPE GetConstantBufferDesc(Uint32 Index) const override final
93+
{
94+
return m_pShader->GetConstantBufferDesc(Index);
95+
}
96+
97+
virtual void DILIGENT_CALL_TYPE GetBytecode(const void** ppBytecode, Uint64& Size) const override final
98+
{
99+
m_pShader->GetBytecode(ppBytecode, Size);
100+
}
101+
102+
virtual SHADER_STATUS DILIGENT_CALL_TYPE GetStatus(bool WaitForCompletion) override final
103+
{
104+
return m_pShader->GetStatus(WaitForCompletion);
105+
}
106+
107+
static void Create(RenderStateCacheImpl* pStateCache,
108+
IShader* pShader,
109+
const ShaderCreateInfo& CreateInfo,
110+
IShader** ppReloadableShader);
111+
112+
bool Reload();
113+
114+
private:
115+
RefCntAutoPtr<RenderStateCacheImpl> m_pStateCache;
116+
RefCntAutoPtr<IShader> m_pShader;
117+
ShaderCreateInfoWrapper m_CreateInfo;
118+
};
119+
120+
} // namespace Diligent

0 commit comments

Comments
 (0)