add legacy-pipeline culling (#17260)

This commit is contained in:
hyde zhou
2024-07-29 16:45:31 +08:00
committed by GitHub
parent 67233882cf
commit 8106f8677d
10 changed files with 380 additions and 335 deletions
+8
View File
@@ -267,6 +267,14 @@ Failed to set shading scale, pipelineSceneData is invalid.
Setting orientation is not supported yet.
### 1222
Failed to initialize render pipeline.
### 1223
Custom pipeline and legacy pipeline are all culled.
### 1300
%s is not in the model pool and cannot be destroyed by destroyModel.
+16 -8
View File
@@ -1126,27 +1126,35 @@ export class Game extends EventTarget {
}
private _setupRenderPipeline (): void | Promise<void> {
const usesCustomPipeline = settings.querySettings(
Settings.Category.RENDERING,
'customPipeline',
);
const renderPipeline = settings.querySettings(Settings.Category.RENDERING, 'renderPipeline') as string;
if (!renderPipeline || renderPipeline === 'ca127c79-69d6-4afd-8183-d712d7b80e14') {
// editor or 'builtin-pipeline', do not load asset
return this._setRenderPipeline();
if (usesCustomPipeline || !renderPipeline) {
return this._setRenderPipeline(!!usesCustomPipeline);
}
return new Promise<RenderPipeline>((resolve, reject): void => {
assetManager.loadAny(renderPipeline, (err, asset): void => ((err || !(asset instanceof RenderPipeline))
? reject(err)
: resolve(asset)));
}).then((asset): void => {
this._setRenderPipeline(asset);
this._setRenderPipeline(!!usesCustomPipeline, asset);
}).catch((reason): void => {
warn(reason);
warn(`Failed load render pipeline: ${renderPipeline}, engine failed to initialize, will fallback to default pipeline`);
this._setRenderPipeline();
this._setRenderPipeline(!!usesCustomPipeline);
});
}
private _setRenderPipeline (rppl?: RenderPipeline): void {
if (!director.root!.setRenderPipeline(rppl)) {
this._setRenderPipeline();
private _setRenderPipeline (customPipeline: boolean, rppl?: RenderPipeline): void {
if (!director.root!.setRenderPipeline(rppl, customPipeline)) {
if (!director.root!.setRenderPipeline(undefined, customPipeline)) {
errorID(1222);
return;
}
}
this._rendererInitialized = true;
+3 -277
View File
@@ -26,30 +26,17 @@ declare const nr: any;
declare const jsb: any;
import { OPEN_HARMONY } from 'internal:constants'
import { ccenum, CCString, js } from '../core';
import { ccenum, CCString } from '../core';
import * as pipeline from './define';
import { ccclass, serializable, editable, type } from '../core/data/class-decorator';
import { serializable, editable, type } from '../core/data/class-decorator';
import { legacyCC } from '../core/global-exports';
import * as decors from '../native-binding/decorators';
import { RenderTexture } from '../asset/assets/render-texture';
import { Skin } from '../render-scene/scene/skin';
import {
RenderPipeline as NrRenderPipeline,
RenderFlow as NrRenderFlow,
RenderStage as NrRenderStage,
InstancedBuffer as NrInstancedBuffer,
PipelineStateManager as NrPipelineStateManager,
ForwardPipeline as NrForwardPipeline,
ForwardFlow as NrForwardFlow,
ShadowFlow as NrShadowFlow,
ForwardStage as NrForwardStage,
ShadowStage as NrShadowStage,
DeferredPipeline as NrDeferredPipeline,
MainFlow as NrMainFlow,
LightingStage as NrLightingStage,
PostProcessStage as NrPostProcessStage,
GbufferStage as NrGbufferStage,
BloomStage as NrBloomStage,
ReflectionProbeFlow as NrReflectionProbeFlow,
ReflectionProbeStage as NrReflectionProbeStage,
} from './index';
@@ -66,28 +53,7 @@ export const InstancedBuffer: typeof NrInstancedBuffer = nr.InstancedBuffer;
export type InstancedBuffer = NrInstancedBuffer;
export const PipelineStateManager: typeof NrPipelineStateManager = nr.PipelineStateManager;
export type PipelineStateManager = NrPipelineStateManager;
export const ForwardPipeline: typeof NrForwardPipeline = nr.ForwardPipeline;
export type ForwardPipeline = NrForwardPipeline;
export const ForwardFlow: typeof NrForwardFlow = nr.ForwardFlow;
export type ForwardFlow = NrForwardFlow;
export const ShadowFlow: typeof NrShadowFlow = nr.ShadowFlow;
export type ShadowFlow = NrShadowFlow;
export const ForwardStage: typeof NrForwardStage = nr.ForwardStage;
export type ForwardStage = NrForwardStage;
export const ShadowStage: typeof NrShadowStage = nr.ShadowStage;
export type ShadowStage = NrShadowStage;
export const DeferredPipeline: typeof NrDeferredPipeline = nr.DeferredPipeline;
export type DeferredPipeline = NrDeferredPipeline;
export const MainFlow: typeof NrMainFlow = nr.MainFlow;
export type MainFlow = NrMainFlow;
export const LightingStage: typeof NrLightingStage = nr.LightingStage;
export type LightingStage = NrLightingStage;
export const PostProcessStage: typeof NrPostProcessStage = nr.PostProcessStage;
export type PostProcessStage = NrPostProcessStage;
export const GbufferStage: typeof NrGbufferStage = nr.GbufferStage;
export type GbufferStage = NrGbufferStage;
export const BloomStage: typeof NrBloomStage = nr.BloomStage;
export type BloomStage = NrBloomStage;
export const ReflectionProbeFlow: typeof NrReflectionProbeFlow = nr.ReflectionProbeFlow;
export type ReflectionProbeFlow = NrReflectionProbeFlow;
export const ReflectionProbeStage: typeof NrReflectionProbeStage = nr.ReflectionProbeStage;
@@ -101,10 +67,6 @@ interface IRenderFlowInfo {
tag: number;
}
interface IRenderPipelineInfo {
flows: any[];
tag: number;
}
interface IRenderStageInfo {
name: string;
priority: number;
@@ -118,65 +80,6 @@ nr.PipelineStateManager.getOrCreatePipelineState = function (device, pass, shade
};
// ForwardPipeline
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const forwardPipelineProto: any = ForwardPipeline.prototype;
forwardPipelineProto._ctor = function () {
this._tag = 0;
this._flows = [];
};
forwardPipelineProto.init = function () {
for (let i = 0; i < this._flows.length; i++) {
this._flows[i].init(this);
}
const info: IRenderPipelineInfo = { tag: this._tag, flows: this._flows };
this.initialize(info);
};
const oldForwardOnLoaded = forwardPipelineProto.onLoaded;
// hook to invoke init after deserialization
forwardPipelineProto.onLoaded = function () {
if (oldForwardOnLoaded) oldForwardOnLoaded.call(this);
for (let i = 0; i < this._flows.length; i++) {
this._flows[i].init(this);
}
const info: IRenderPipelineInfo = { tag: this._tag, flows: this._flows };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const forwardFlowProto: any = ForwardFlow.prototype;
forwardFlowProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this._stages = [];
}
forwardFlowProto.init = function (pipeline) {
for (let i = 0; i < this._stages.length; i++) {
this._stages[i].init(pipeline);
}
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const shadowFlowProto: any = ShadowFlow.prototype;
shadowFlowProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this._stages = [];
}
shadowFlowProto.init = function (pipeline) {
for (let i = 0; i < this._stages.length; i++) {
this._stages[i].init(pipeline);
}
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const reflectionProbeFlowProto: any = ReflectionProbeFlow.prototype;
@@ -194,34 +97,6 @@ reflectionProbeFlowProto.init = function (pipeline) {
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const forwardStageProto: any = ForwardStage.prototype;
forwardStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
}
forwardStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const shadowStageProto: any = ShadowStage.prototype;
shadowStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const reflectionProbeStage: any = ReflectionProbeStage.prototype;
reflectionProbeStage._ctor = function () {
@@ -247,11 +122,6 @@ export enum RenderQueueSortMode {
}
ccenum(RenderQueueSortMode);
shadowStageProto.init = function (pipeline) {
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: [] };
this.initialize(info);
}
export class RenderQueueDesc {
/**
@@ -285,138 +155,10 @@ export class RenderQueueDesc {
}
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const deferredPipelineProto: any = DeferredPipeline.prototype;
deferredPipelineProto._ctor = function () {
this._tag = 0;
this._flows = [];
this.renderTextures = [];
this.materials = [];
}
const oldDeferredOnLoaded = deferredPipelineProto.onLoaded;
// hook to invoke init after deserialization
deferredPipelineProto.onLoaded = function () {
if (oldDeferredOnLoaded) oldDeferredOnLoaded.call(this);
for (let i = 0; i < this._flows.length; i++) {
this._flows[i].init(this);
}
let info = { tag: this._tag, flows: this._flows };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const mainFlowProto: any = MainFlow.prototype;
mainFlowProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this._stages = [];
}
mainFlowProto.init = function (pipeline) {
for (let i = 0; i < this._stages.length; i++) {
this._stages[i].init(pipeline);
}
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const gbufferStageProto: any = GbufferStage.prototype;
gbufferStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
}
gbufferStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const lightingStageProto: any = LightingStage.prototype;
lightingStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
this._deferredMaterial = null;
}
lightingStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
pipeline.pipelineSceneData.deferredLightingMaterial = this._deferredMaterial;
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const bloomStageProto: any = BloomStage.prototype;
bloomStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
this._bloomMaterial = null;
}
bloomStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
pipeline.pipelineSceneData.bloomMaterial = this._bloomMaterial;
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const postProcessStageProto: any = PostProcessStage.prototype;
postProcessStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
this._postProcessMaterial = null;
}
postProcessStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
pipeline.pipelineSceneData.postProcessMaterial = this._postProcessMaterial;
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
legacyCC.RenderFlow = RenderFlow;
legacyCC.RenderStage = RenderStage;
legacyCC.RenderPipeline = RenderPipeline;
@ccclass('RenderTextureConfig')
class RenderTextureConfig {
@serializable
@editable
public name = '';
@type(RenderTexture)
public texture: RenderTexture | null = null;
}
function proxyArrayAttributeImpl(proto: any, attr: string): void {
const proxyTarget = `_${attr}_target`;
let arrayProxy = (self, targetArrayAttr: string): any => {
@@ -456,27 +198,11 @@ if (!OPEN_HARMONY) {
//-------------------- register types --------------------
const Material = jsb.Material;
decors.patch_RenderQueueDesc({RenderQueueDesc, RenderQueueSortMode, CCString});
decors.patch_RenderStage({RenderStage});
decors.patch_ReflectionProbeStage({ReflectionProbeStage});
decors.patch_GbufferStage({GbufferStage, RenderQueueDesc});
decors.patch_LightingStage({LightingStage, RenderQueueDesc, Material});
decors.patch_BloomStage({BloomStage, Material});
decors.patch_PostProcessStage({PostProcessStage, Material, RenderQueueDesc});
decors.patch_ForwardStage({ForwardStage, RenderQueueDesc});
decors.patch_ShadowStage({ShadowStage});
decors.patch_RenderFlow({RenderFlow, RenderStage});
decors.patch_MainFlow({MainFlow});
decors.patch_ForwardFlow({ForwardFlow});
decors.patch_ShadowFlow({ShadowFlow});
decors.patch_ReflectionProbeFlow({ReflectionProbeFlow});
decors.patch_cc_RenderPipeline({RenderPipeline, RenderFlow});
decors.patch_ForwardPipeline({ForwardPipeline, RenderTextureConfig});
decors.patch_DeferredPipeline({DeferredPipeline, RenderTextureConfig});
-12
View File
@@ -34,18 +34,6 @@ export { RenderFlow } from './render-flow';
export { RenderStage } from './render-stage';
export { PipelineSceneData } from './pipeline-scene-data';
export { ForwardPipeline, createDefaultPipeline } from './forward/forward-pipeline';
export { ForwardFlow } from './forward/forward-flow';
export { ForwardStage } from './forward/forward-stage';
export { DeferredPipeline } from './deferred/deferred-pipeline';
export { MainFlow } from './deferred/main-flow';
export { GbufferStage } from './deferred/gbuffer-stage';
export { LightingStage } from './deferred/lighting-stage';
export { BloomStage } from './deferred/bloom-stage';
export { PostProcessStage } from './deferred/postprocess-stage';
export { ShadowFlow } from './shadow/shadow-flow';
export { ShadowStage } from './shadow/shadow-stage';
export { InstancedBuffer } from './instanced-buffer';
export { PipelineStateManager } from './pipeline-state-manager';
+303 -2
View File
@@ -22,5 +22,306 @@
THE SOFTWARE.
*/
// Dummy, will be removed in the future
export class LegacyPipeline {}
declare const nr: any;
declare const jsb: any;
import {
ForwardPipeline as NrForwardPipeline,
ForwardFlow as NrForwardFlow,
ShadowFlow as NrShadowFlow,
ForwardStage as NrForwardStage,
ShadowStage as NrShadowStage,
DeferredPipeline as NrDeferredPipeline,
MainFlow as NrMainFlow,
LightingStage as NrLightingStage,
PostProcessStage as NrPostProcessStage,
GbufferStage as NrGbufferStage,
BloomStage as NrBloomStage,
} from './index';
import {
RenderQueueDesc
} from '../index.jsb';
import * as decors from '../../native-binding/decorators';
import { ccclass, serializable, editable, type } from '../../core/data/class-decorator';
import { RenderTexture } from '../../asset/assets/render-texture';
export function createDefaultPipeline (): ForwardPipeline {
const rppl = new ForwardPipeline();
rppl.initialize({ flows: [] });
return rppl;
}
export const ForwardPipeline: typeof NrForwardPipeline = nr.ForwardPipeline;
export type ForwardPipeline = NrForwardPipeline;
export const ForwardFlow: typeof NrForwardFlow = nr.ForwardFlow;
export type ForwardFlow = NrForwardFlow;
export const ShadowFlow: typeof NrShadowFlow = nr.ShadowFlow;
export type ShadowFlow = NrShadowFlow;
export const ForwardStage: typeof NrForwardStage = nr.ForwardStage;
export type ForwardStage = NrForwardStage;
export const ShadowStage: typeof NrShadowStage = nr.ShadowStage;
export type ShadowStage = NrShadowStage;
export const DeferredPipeline: typeof NrDeferredPipeline = nr.DeferredPipeline;
export type DeferredPipeline = NrDeferredPipeline;
export const MainFlow: typeof NrMainFlow = nr.MainFlow;
export type MainFlow = NrMainFlow;
export const LightingStage: typeof NrLightingStage = nr.LightingStage;
export type LightingStage = NrLightingStage;
export const PostProcessStage: typeof NrPostProcessStage = nr.PostProcessStage;
export type PostProcessStage = NrPostProcessStage;
export const GbufferStage: typeof NrGbufferStage = nr.GbufferStage;
export type GbufferStage = NrGbufferStage;
export const BloomStage: typeof NrBloomStage = nr.BloomStage;
export type BloomStage = NrBloomStage;
interface IRenderPipelineInfo {
flows: any[];
tag: number;
}
interface IRenderFlowInfo {
name: string;
priority: number;
stages: any[];
tag: number;
}
interface IRenderStageInfo {
name: string;
priority: number;
tag: number;
renderQueues: RenderQueueDesc[];
}
// ForwardPipeline
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const forwardPipelineProto: any = ForwardPipeline.prototype;
forwardPipelineProto._ctor = function () {
this._tag = 0;
this._flows = [];
};
forwardPipelineProto.init = function () {
for (let i = 0; i < this._flows.length; i++) {
this._flows[i].init(this);
}
const info: IRenderPipelineInfo = { tag: this._tag, flows: this._flows };
this.initialize(info);
};
const oldForwardOnLoaded = forwardPipelineProto.onLoaded;
// hook to invoke init after deserialization
forwardPipelineProto.onLoaded = function () {
if (oldForwardOnLoaded) oldForwardOnLoaded.call(this);
for (let i = 0; i < this._flows.length; i++) {
this._flows[i].init(this);
}
const info: IRenderPipelineInfo = { tag: this._tag, flows: this._flows };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const forwardFlowProto: any = ForwardFlow.prototype;
forwardFlowProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this._stages = [];
}
forwardFlowProto.init = function (pipeline) {
for (let i = 0; i < this._stages.length; i++) {
this._stages[i].init(pipeline);
}
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const shadowFlowProto: any = ShadowFlow.prototype;
shadowFlowProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this._stages = [];
}
shadowFlowProto.init = function (pipeline) {
for (let i = 0; i < this._stages.length; i++) {
this._stages[i].init(pipeline);
}
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const forwardStageProto: any = ForwardStage.prototype;
forwardStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
}
forwardStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const shadowStageProto: any = ShadowStage.prototype;
shadowStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
}
shadowStageProto.init = function (pipeline) {
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: [] };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const deferredPipelineProto: any = DeferredPipeline.prototype;
deferredPipelineProto._ctor = function () {
this._tag = 0;
this._flows = [];
this.renderTextures = [];
this.materials = [];
}
const oldDeferredOnLoaded = deferredPipelineProto.onLoaded;
// hook to invoke init after deserialization
deferredPipelineProto.onLoaded = function () {
if (oldDeferredOnLoaded) oldDeferredOnLoaded.call(this);
for (let i = 0; i < this._flows.length; i++) {
this._flows[i].init(this);
}
let info = { tag: this._tag, flows: this._flows };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const mainFlowProto: any = MainFlow.prototype;
mainFlowProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this._stages = [];
}
mainFlowProto.init = function (pipeline) {
for (let i = 0; i < this._stages.length; i++) {
this._stages[i].init(pipeline);
}
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const gbufferStageProto: any = GbufferStage.prototype;
gbufferStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
}
gbufferStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const lightingStageProto: any = LightingStage.prototype;
lightingStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
this._deferredMaterial = null;
}
lightingStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
pipeline.pipelineSceneData.deferredLightingMaterial = this._deferredMaterial;
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const bloomStageProto: any = BloomStage.prototype;
bloomStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
this._bloomMaterial = null;
}
bloomStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
pipeline.pipelineSceneData.bloomMaterial = this._bloomMaterial;
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
// TODO: we mark it as type of any, because here we have many dynamic injected property @dumganhar
const postProcessStageProto: any = PostProcessStage.prototype;
postProcessStageProto._ctor = function () {
this._name = 0;
this._priority = 0;
this._tag = 0;
this.renderQueues = [];
this._postProcessMaterial = null;
}
postProcessStageProto.init = function (pipeline) {
const queues = [];
for (let i = 0; i < this.renderQueues.length; i++) {
// @ts-ignore
queues.push(this.renderQueues[i].init());
}
pipeline.pipelineSceneData.postProcessMaterial = this._postProcessMaterial;
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
this.initialize(info);
}
@ccclass('RenderTextureConfig')
class RenderTextureConfig {
@serializable
@editable
public name = '';
@type(RenderTexture)
public texture: RenderTexture | null = null;
}
//-------------------- register types --------------------
const Material = jsb.Material;
decors.patch_GbufferStage({GbufferStage, RenderQueueDesc});
decors.patch_LightingStage({LightingStage, RenderQueueDesc, Material});
decors.patch_BloomStage({BloomStage, Material});
decors.patch_PostProcessStage({PostProcessStage, Material, RenderQueueDesc});
decors.patch_ForwardStage({ForwardStage, RenderQueueDesc});
decors.patch_ShadowStage({ShadowStage});
decors.patch_MainFlow({MainFlow});
decors.patch_ForwardFlow({ForwardFlow});
decors.patch_ShadowFlow({ShadowFlow});
decors.patch_ForwardPipeline({ForwardPipeline, RenderTextureConfig});
decors.patch_DeferredPipeline({DeferredPipeline, RenderTextureConfig});
+11 -2
View File
@@ -22,5 +22,14 @@
THE SOFTWARE.
*/
// Dummy, will be removed in the future
export class LegacyPipeline {}
export { ForwardPipeline, createDefaultPipeline } from '../forward/forward-pipeline';
export { ForwardFlow } from '../forward/forward-flow';
export { ForwardStage } from '../forward/forward-stage';
export { DeferredPipeline } from '../deferred/deferred-pipeline';
export { MainFlow } from '../deferred/main-flow';
export { GbufferStage } from '../deferred/gbuffer-stage';
export { LightingStage } from '../deferred/lighting-stage';
export { BloomStage } from '../deferred/bloom-stage';
export { PostProcessStage } from '../deferred/postprocess-stage';
export { ShadowFlow } from '../shadow/shadow-flow';
export { ShadowStage } from '../shadow/shadow-stage';
+9 -6
View File
@@ -25,8 +25,7 @@
import { legacyCC } from './core/global-exports';
import { DataPoolManager } from './3d/skeletal-animation/data-pool-manager';
import { Device, deviceManager } from './gfx';
import { settings, Settings, warnID, Pool, macro, log } from './core';
import { ForwardPipeline } from './rendering';
import { settings, Settings, warnID, Pool, macro, log, cclegacy } from './core';
import { PipelineEventProcessor } from './rendering/pipeline-event';
import type { Root as JsbRoot } from './root';
@@ -233,17 +232,21 @@ rootProto.frameMove = function (deltaTime: number) {
};
const oldSetPipeline = rootProto.setRenderPipeline;
rootProto.setRenderPipeline = function (pipeline) {
rootProto.setRenderPipeline = function (pipeline, customPipeline: boolean) {
let ppl;
if (macro.CUSTOM_PIPELINE_NAME !== '' && legacyCC.rendering && this.usesCustomPipeline) {
if (customPipeline) {
legacyCC.rendering.createCustomPipeline();
ppl = oldSetPipeline.call(this, null);
log(`Using custom pipeline: ${macro.CUSTOM_PIPELINE_NAME}`);
} else {
if (!pipeline) {
// pipeline should not be created in C++, ._ctor need to be triggered
pipeline = new ForwardPipeline();
pipeline.init();
if (cclegacy.legacy_rendering) {
pipeline = cclegacy.legacy_rendering.createDefaultPipeline();
pipeline.init();
} else {
log(`No render pipeline: legacy-pipeline is not available`);
}
}
ppl = oldSetPipeline.call(this, pipeline);
}
+26 -28
View File
@@ -22,10 +22,8 @@
THE SOFTWARE.
*/
import { Pool, cclegacy, warnID, settings, Settings, macro, log } from './core';
import { Pool, cclegacy, warnID, settings, Settings, macro, log, errorID } from './core';
import type { RenderPipeline } from './rendering/render-pipeline';
import { DeferredPipeline } from './rendering/deferred/deferred-pipeline';
import { createDefaultPipeline } from './rendering/forward/forward-pipeline';
import { DebugView } from './rendering/debug-view';
import { Camera, CameraType, Light, Model, TrackingType } from './render-scene/scene';
import type { DataPoolManager } from './3d/skeletal-animation/data-pool-manager';
@@ -370,39 +368,39 @@ export class Root {
* @param rppl The render pipeline
* @returns The setup is successful or not
*/
public setRenderPipeline (rppl?: RenderPipeline): boolean {
const { internal, director, rendering } = cclegacy;
public setRenderPipeline (rppl?: RenderPipeline, useCustomPipeline?: boolean): boolean {
const { internal, director, rendering, legacy_rendering } = cclegacy;
if (rendering === undefined && legacy_rendering === undefined) {
errorID(1223);
return false;
}
//-----------------------------------------------
// prepare classic pipeline
//-----------------------------------------------
if (rppl instanceof DeferredPipeline) {
this._useDeferredPipeline = true;
}
let isCreateDefaultPipeline = false;
if (!rppl) {
rppl = createDefaultPipeline();
isCreateDefaultPipeline = true;
}
// now cluster just enabled in deferred pipeline
if (!this._useDeferredPipeline || !this.device.hasFeature(Feature.COMPUTE_SHADER)) {
// disable cluster
rppl.clusterEnabled = false;
}
rppl.bloomEnabled = false;
//-----------------------------------------------
// choose pipeline
//-----------------------------------------------
if (macro.CUSTOM_PIPELINE_NAME !== '' && rendering && this.usesCustomPipeline) {
if (useCustomPipeline) {
this._customPipeline = rendering.createCustomPipeline();
isCreateDefaultPipeline = true;
this._pipeline = this._customPipeline!;
// Use default _pipelineEvent
log(`Using custom pipeline: ${macro.CUSTOM_PIPELINE_NAME}`);
} else {
this._classicPipeline = rppl;
if (rppl && (rppl as any).renderTextures !== undefined) {
this._useDeferredPipeline = true;
}
if (!rppl) {
rppl = legacy_rendering.createDefaultPipeline();
isCreateDefaultPipeline = true;
}
if (!this._useDeferredPipeline || !this.device.hasFeature(Feature.COMPUTE_SHADER)) {
// disable cluster
(rppl as any).clusterEnabled = false;
}
(rppl as any).bloomEnabled = false;
log(`Using legacy pipeline`);
this._classicPipeline = rppl!;
this._pipeline = this._classicPipeline;
this._pipelineEvent = this._classicPipeline; // Use forward pipeline's pipeline event
this._usesCustomPipeline = false;
@@ -741,7 +739,7 @@ export class Root {
for (let i = 0; i < webxrHmdPoseInfos.length; i++) {
const info = webxrHmdPoseInfos[i];
if ((info.code === XRPoseType.VIEW_LEFT && xrEye === XREye.LEFT)
|| (info.code === XRPoseType.VIEW_RIGHT && xrEye === XREye.RIGHT)) {
|| (info.code === XRPoseType.VIEW_RIGHT && xrEye === XREye.RIGHT)) {
cameraPosition[0] = info.position.x;
cameraPosition[1] = info.position.y;
cameraPosition[2] = info.position.z;
@@ -768,7 +766,7 @@ export class Root {
for (let i = cameraList.length - 1; i >= 0; i--) {
const camera = cameraList[i];
const isMismatchedCam = (xrEye === XREye.LEFT && camera.cameraType === CameraType.RIGHT_EYE)
|| (xrEye === XREye.RIGHT && camera.cameraType === CameraType.LEFT_EYE);
|| (xrEye === XREye.RIGHT && camera.cameraType === CameraType.LEFT_EYE);
if (isMismatchedCam) {
// currently is left eye loop, so right camera do not need active
cameraList.splice(i, 1);
+3
View File
@@ -23,5 +23,8 @@
*/
import { legacyCC } from '../cocos/core/global-exports';
import * as legacy_rendering from '../cocos/rendering/legacy';
export * from '../cocos/rendering/legacy';
legacyCC.legacy_rendering = legacy_rendering;
+1
View File
@@ -138,6 +138,7 @@ import { glsl4 } from './fixtures/builtin-glsl4';
import { initBuiltinMaterial } from './fixtures/builtin-material';
import { initBuiltinPhysicsMaterial } from './fixtures/builtin-physics-material';
import '../cocos/2d/utils/dynamic-atlas/atlas-manager';
import '../exports/legacy-pipeline';
const canvas = document.createElement('canvas');
const div = document.createElement('div');