diff --git a/cocos/game/director.ts b/cocos/game/director.ts index efa8f7163f6..aa3b79d7467 100644 --- a/cocos/game/director.ts +++ b/cocos/game/director.ts @@ -806,10 +806,11 @@ export class Director extends EventTarget { } /** + * @engineInternal * @en Build custom render pipeline * @zh 构建自定义渲染管线 */ - private buildRenderPipeline (): void { + public buildRenderPipeline (): void { if (!this._root) { return; } @@ -831,11 +832,6 @@ export class Director extends EventTarget { // 2. cclegacy.rendering is available // 3. The root node is created and uses custom pipeline if (macro.CUSTOM_PIPELINE_NAME !== '' && cclegacy.rendering && this._root && this._root.usesCustomPipeline) { - this.on( - DirectorEvent.BEFORE_RENDER, - this.buildRenderPipeline, - this, - ); this.on( DirectorEvent.BEFORE_SCENE_LAUNCH, cclegacy.rendering.forceResizeAllWindows, diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 8f0472aea82..338491cb96d 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -1516,7 +1516,8 @@ export class WebPipeline implements BasicPipeline { ); } beginFrame (): void { - // noop + const director: Director = cclegacy.director; + director.buildRenderPipeline(); } update (camera: Camera): void { // noop diff --git a/cocos/root.jsb.ts b/cocos/root.jsb.ts index 182af483fac..f95fc5cdc68 100644 --- a/cocos/root.jsb.ts +++ b/cocos/root.jsb.ts @@ -118,6 +118,11 @@ rootProto.createModel = function (ModelCtor) { return model; }; +jsb.buildRenderPipeline = function () { + const director = cclegacy.director; + director.buildRenderPipeline(); +} + rootProto.destroyModel = function (m) { const p = this._modelPools.get(m.constructor); if (p) { diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index 94af3b5659e..f0814b7715e 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -39,6 +39,7 @@ #include "cocos/scene/ReflectionProbeManager.h" #include "cocos/scene/RenderScene.h" #include "cocos/scene/RenderWindow.h" +#include "bindings/jswrapper/SeApi.h" #if CC_USE_DEBUG_RENDERER #include "profiler/DebugRenderer.h" @@ -1310,6 +1311,22 @@ void buildLayoutGraphNodeBuffer( } } +se::Value buildRPVal; +void buildRenderPipeline() { + if (buildRPVal.isUndefined()) { + auto *global = se::ScriptEngine::getInstance()->getGlobalObject(); + se::Value jsbVal; + if(global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) { + jsbVal.toObject()->getProperty("buildRenderPipeline", &buildRPVal); + } + se::ScriptEngine::getInstance()->addBeforeCleanupHook([]() { + buildRPVal.setUndefined(); + }); + } + se::ValueArray args; + buildRPVal.toObject()->call(args, nullptr); +} + } // namespace // NOLINTNEXTLINE @@ -1491,7 +1508,7 @@ void NativePipeline::render(const ccstd::vector &cameras) { std::ignore = cameras; const auto *sceneData = pipelineSceneData.get(); auto *commandBuffer = device->getCommandBuffer(); - + buildRenderPipeline(); executeRenderGraph(renderGraph); }