refactor(rendering): auto-initialize scriptable render pipeline host
This commit is contained in:
@@ -93,19 +93,7 @@ void ScriptableRenderPipelineHost::SetPipelineRendererAsset(
|
||||
}
|
||||
|
||||
bool ScriptableRenderPipelineHost::Initialize(const RenderContext& context) {
|
||||
if (m_pipelineRenderer == nullptr ||
|
||||
!m_pipelineRenderer->Initialize(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_stageRecorder != nullptr &&
|
||||
!m_stageRecorder->Initialize(context)) {
|
||||
m_stageRecorder->Shutdown();
|
||||
m_pipelineRenderer->Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return EnsureInitialized(context);
|
||||
}
|
||||
|
||||
void ScriptableRenderPipelineHost::Shutdown() {
|
||||
@@ -116,6 +104,7 @@ void ScriptableRenderPipelineHost::Shutdown() {
|
||||
m_pipelineRenderer->Shutdown();
|
||||
}
|
||||
ShutdownCameraFrameStandalonePasses();
|
||||
ResetInitializationState();
|
||||
}
|
||||
|
||||
bool ScriptableRenderPipelineHost::SupportsStageRenderGraph(
|
||||
@@ -128,6 +117,10 @@ bool ScriptableRenderPipelineHost::SupportsStageRenderGraph(
|
||||
|
||||
bool ScriptableRenderPipelineHost::RecordStageRenderGraph(
|
||||
const RenderPipelineStageRenderGraphContext& context) {
|
||||
if (!EnsureInitialized(context.renderContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_stageRecorder != nullptr &&
|
||||
m_stageRecorder->SupportsStageRenderGraph(context.stage)) {
|
||||
return m_stageRecorder->RecordStageRenderGraph(context);
|
||||
@@ -139,6 +132,10 @@ bool ScriptableRenderPipelineHost::RecordStageRenderGraph(
|
||||
|
||||
bool ScriptableRenderPipelineHost::Render(
|
||||
const FrameExecutionContext& executionContext) {
|
||||
if (!EnsureInitialized(executionContext.renderContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_pipelineRenderer != nullptr &&
|
||||
m_pipelineRenderer->Render(executionContext);
|
||||
}
|
||||
@@ -147,10 +144,86 @@ bool ScriptableRenderPipelineHost::Render(
|
||||
const RenderContext& context,
|
||||
const RenderSurface& surface,
|
||||
const RenderSceneData& sceneData) {
|
||||
if (!EnsureInitialized(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_pipelineRenderer != nullptr &&
|
||||
m_pipelineRenderer->Render(context, surface, sceneData);
|
||||
}
|
||||
|
||||
bool ScriptableRenderPipelineHost::EnsureInitialized(const RenderContext& context) {
|
||||
if (!context.IsValid() || m_pipelineRenderer == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool hasInitializationContext =
|
||||
m_initializedDevice != nullptr ||
|
||||
m_pipelineRendererInitialized ||
|
||||
m_stageRecorderInitialized;
|
||||
if (hasInitializationContext &&
|
||||
(m_initializedDevice != context.device ||
|
||||
m_initializedBackendType != context.backendType)) {
|
||||
ShutdownInitializedComponents();
|
||||
}
|
||||
|
||||
if (!m_pipelineRendererInitialized) {
|
||||
if (!m_pipelineRenderer->Initialize(context)) {
|
||||
m_pipelineRenderer->Shutdown();
|
||||
ClearInitializationContextIfNoComponentsAreInitialized();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pipelineRendererInitialized = true;
|
||||
m_initializedDevice = context.device;
|
||||
m_initializedBackendType = context.backendType;
|
||||
}
|
||||
|
||||
if (m_stageRecorder != nullptr &&
|
||||
!m_stageRecorderInitialized) {
|
||||
if (!m_stageRecorder->Initialize(context)) {
|
||||
m_stageRecorder->Shutdown();
|
||||
ShutdownInitializedComponents();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_stageRecorderInitialized = true;
|
||||
m_initializedDevice = context.device;
|
||||
m_initializedBackendType = context.backendType;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptableRenderPipelineHost::ShutdownInitializedComponents() {
|
||||
if (m_stageRecorderInitialized &&
|
||||
m_stageRecorder != nullptr) {
|
||||
m_stageRecorder->Shutdown();
|
||||
}
|
||||
|
||||
if (m_pipelineRendererInitialized &&
|
||||
m_pipelineRenderer != nullptr) {
|
||||
m_pipelineRenderer->Shutdown();
|
||||
}
|
||||
|
||||
ResetInitializationState();
|
||||
}
|
||||
|
||||
void ScriptableRenderPipelineHost::ResetInitializationState() {
|
||||
m_initializedDevice = nullptr;
|
||||
m_initializedBackendType = RHI::RHIType::D3D12;
|
||||
m_pipelineRendererInitialized = false;
|
||||
m_stageRecorderInitialized = false;
|
||||
}
|
||||
|
||||
void ScriptableRenderPipelineHost::ClearInitializationContextIfNoComponentsAreInitialized() {
|
||||
if (!m_pipelineRendererInitialized &&
|
||||
!m_stageRecorderInitialized) {
|
||||
m_initializedDevice = nullptr;
|
||||
m_initializedBackendType = RHI::RHIType::D3D12;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptableRenderPipelineHost::ResetStageRecorder(
|
||||
std::unique_ptr<RenderPipelineStageRecorder> stageRecorder) {
|
||||
if (m_stageRecorder != nullptr) {
|
||||
@@ -158,6 +231,8 @@ void ScriptableRenderPipelineHost::ResetStageRecorder(
|
||||
}
|
||||
|
||||
m_stageRecorder = std::move(stageRecorder);
|
||||
m_stageRecorderInitialized = false;
|
||||
ClearInitializationContextIfNoComponentsAreInitialized();
|
||||
}
|
||||
|
||||
void ScriptableRenderPipelineHost::ResetPipelineRenderer(
|
||||
@@ -174,6 +249,9 @@ void ScriptableRenderPipelineHost::ResetPipelineRenderer(
|
||||
m_pipelineRenderer =
|
||||
CreatePipelineRendererFromAsset(m_pipelineRendererAsset);
|
||||
}
|
||||
|
||||
m_pipelineRendererInitialized = false;
|
||||
ClearInitializationContextIfNoComponentsAreInitialized();
|
||||
}
|
||||
|
||||
ScriptableRenderPipelineHostAsset::ScriptableRenderPipelineHostAsset()
|
||||
|
||||
Reference in New Issue
Block a user