feat(rendering): expose builtin forward scene steps to srp context

This commit is contained in:
2026-04-17 22:26:51 +08:00
parent 69319b4a7b
commit 6f6c8877fa
14 changed files with 551 additions and 170 deletions

View File

@@ -11,6 +11,7 @@
#include "Input/InputManager.h"
#include "Physics/PhysicsWorld.h"
#include "Rendering/Pipelines/BuiltinForwardPipeline.h"
#include "Rendering/Pipelines/BuiltinForwardSceneRecorder.h"
#include "Rendering/Pipelines/ManagedScriptableRenderPipelineAsset.h"
#include "Scene/Scene.h"
#include "Scripting/ScriptComponent.h"
@@ -88,7 +89,8 @@ struct ManagedScriptableRenderContextState {
uint64_t handle = 0;
Rendering::CameraFrameStage stage = Rendering::CameraFrameStage::MainScene;
const Rendering::RenderPipelineStageRenderGraphContext* graphContext = nullptr;
Rendering::Pipelines::BuiltinForwardPipeline builtinForwardPipeline;
Rendering::Pipelines::BuiltinForwardSceneRecorder* builtinForwardSceneRecorder =
nullptr;
};
uint64_t& GetManagedScriptableRenderContextNextHandle() {
@@ -233,6 +235,7 @@ public:
}
void Shutdown() override {
m_builtinForwardPipeline.Shutdown();
ReleaseManagedObjects();
m_supportsStageMethod = nullptr;
m_recordStageMethod = nullptr;
@@ -283,6 +286,11 @@ public:
ManagedScriptableRenderContextState managedContextState = {};
managedContextState.stage = context.stage;
managedContextState.graphContext = &context;
Rendering::Pipelines::BuiltinForwardSceneRecorder builtinForwardSceneRecorder(
m_builtinForwardPipeline,
context);
managedContextState.builtinForwardSceneRecorder =
&builtinForwardSceneRecorder;
const uint64_t managedContextHandle =
RegisterManagedScriptableRenderContextState(managedContextState);
MonoObject* const managedContextObject =
@@ -441,6 +449,7 @@ private:
mutable MonoMethod* m_supportsStageMethod = nullptr;
mutable MonoMethod* m_recordStageMethod = nullptr;
mutable bool m_pipelineCreationAttempted = false;
Rendering::Pipelines::BuiltinForwardPipeline m_builtinForwardPipeline;
};
class MonoManagedRenderPipelineBridge final
@@ -2169,18 +2178,56 @@ int32_t InternalCall_Rendering_ScriptableRenderContext_GetStage(
: static_cast<int32_t>(Rendering::CameraFrameStage::MainScene);
}
mono_bool InternalCall_Rendering_ScriptableRenderContext_RenderBuiltinForwardMainScene(
mono_bool InternalCall_Rendering_ScriptableRenderContext_RecordBuiltinForwardMainScene(
uint64_t nativeHandle) {
ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
if (state == nullptr ||
state->graphContext == nullptr ||
state->builtinForwardSceneRecorder == nullptr ||
state->stage != Rendering::CameraFrameStage::MainScene) {
return 0;
}
return state->builtinForwardPipeline.RecordStageRenderGraph(
*state->graphContext)
return state->builtinForwardSceneRecorder->RecordDefaultScene()
? 1
: 0;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_RecordBuiltinForwardScenePhase(
uint64_t nativeHandle,
int32_t scenePhase) {
ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
if (state == nullptr ||
state->graphContext == nullptr ||
state->builtinForwardSceneRecorder == nullptr ||
state->stage != Rendering::CameraFrameStage::MainScene) {
return 0;
}
return state->builtinForwardSceneRecorder->RecordScenePhase(
static_cast<Rendering::ScenePhase>(scenePhase))
? 1
: 0;
}
mono_bool
InternalCall_Rendering_ScriptableRenderContext_RecordBuiltinForwardInjectionPoint(
uint64_t nativeHandle,
int32_t injectionPoint) {
ManagedScriptableRenderContextState* const state =
FindManagedScriptableRenderContextState(nativeHandle);
if (state == nullptr ||
state->graphContext == nullptr ||
state->builtinForwardSceneRecorder == nullptr ||
state->stage != Rendering::CameraFrameStage::MainScene) {
return 0;
}
return state->builtinForwardSceneRecorder->RecordInjectionPoint(
static_cast<Rendering::SceneRenderInjectionPoint>(injectionPoint))
? 1
: 0;
}
@@ -2314,7 +2361,9 @@ void RegisterInternalCalls() {
mono_add_internal_call("XCEngine.InternalCalls::Rendering_SetRenderPipelineAssetType", reinterpret_cast<const void*>(&InternalCall_Rendering_SetRenderPipelineAssetType));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_GetRenderPipelineAssetTypeName", reinterpret_cast<const void*>(&InternalCall_Rendering_GetRenderPipelineAssetTypeName));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_GetStage", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_GetStage));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RenderBuiltinForwardMainScene", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RenderBuiltinForwardMainScene));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RecordBuiltinForwardMainScene", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RecordBuiltinForwardMainScene));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RecordBuiltinForwardScenePhase", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RecordBuiltinForwardScenePhase));
mono_add_internal_call("XCEngine.InternalCalls::Rendering_ScriptableRenderContext_RecordBuiltinForwardInjectionPoint", reinterpret_cast<const void*>(&InternalCall_Rendering_ScriptableRenderContext_RecordBuiltinForwardInjectionPoint));
GetInternalCallRegistrationState() = true;
}