Skip to content

Commit

Permalink
Adjust the timing for building the rendergraph in the pipeline. (#18049)
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS authored Dec 18, 2024
1 parent 32bf693 commit 1ab9ec5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
8 changes: 2 additions & 6 deletions cocos/game/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,8 @@ export class WebPipeline implements BasicPipeline {
);
}
beginFrame (): void {
// noop
const director: Director = cclegacy.director;
director.buildRenderPipeline();
}
update (camera: Camera): void {
// noop
Expand Down
5 changes: 5 additions & 0 deletions cocos/root.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 18 additions & 1 deletion native/cocos/renderer/pipeline/custom/NativePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1491,7 +1508,7 @@ void NativePipeline::render(const ccstd::vector<scene::Camera *> &cameras) {
std::ignore = cameras;
const auto *sceneData = pipelineSceneData.get();
auto *commandBuffer = device->getCommandBuffer();

buildRenderPipeline();
executeRenderGraph(renderGraph);
}

Expand Down

0 comments on commit 1ab9ec5

Please sign in to comment.