Skip to content

Commit

Permalink
revert invalid optimizations for global patches (#16241)
Browse files Browse the repository at this point in the history
  • Loading branch information
troublemaker52025 authored Sep 15, 2023
1 parent 59c6afd commit 5aecd91
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions cocos/render-scene/scene/submodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture, Text
import { errorID, Mat4, cclegacy } from '../../core';
import { getPhaseID } from '../../rendering/pass-phase';
import { Root } from '../../root';
import { MacroRecord } from '../core/pass-utils';

const _dsInfo = new DescriptorSetInfo(null!);
const MAX_PASS_COUNT = 8;
Expand All @@ -55,7 +54,6 @@ export class SubModel {
protected _shaders: Shader[] | null = null;
protected _subMesh: RenderingSubMesh | null = null;
protected _patches: IMacroPatch[] | null = null;
protected _globalPatches: MacroRecord | null = null;
protected _priority: RenderPriority = RenderPriority.DEFAULT;
protected _inputAssembler: InputAssembler | null = null;
protected _descriptorSet: DescriptorSet | null = null;
Expand Down Expand Up @@ -296,7 +294,6 @@ export class SubModel {
this.priority = RenderPriority.DEFAULT;

this._patches = null;
this._globalPatches = null;
this._subMesh = null;

this._passes = null;
Expand Down Expand Up @@ -327,22 +324,6 @@ export class SubModel {
* @zh 管线更新回调
*/
public onPipelineStateChanged (): void {
const root = cclegacy.director.root as Root;
const pipeline = root.pipeline;
const pipelinePatches = Object.entries(pipeline.macros);
if (!this._globalPatches && pipelinePatches.length === 0) {
return;
} else if (pipelinePatches.length) {
if (this._globalPatches) {
const globalPatches = Object.entries(this._globalPatches);
if (pipelinePatches.length === globalPatches.length) {
const patchesStateUnchanged = JSON.stringify(pipelinePatches.sort()) === JSON.stringify(globalPatches.sort());
if (patchesStateUnchanged) return;
}
}
}
this._globalPatches = pipeline.macros;

const passes = this._passes;
if (!passes) { return; }

Expand All @@ -365,6 +346,7 @@ export class SubModel {
return;
} else if (patches) {
patches = patches.sort();
// Sorting on shorter patches outperforms hashing, with negative optimization on longer global patches.
if (this._patches && patches.length === this._patches.length) {
const patchesStateUnchanged = JSON.stringify(patches) === JSON.stringify(this._patches);
if (patchesStateUnchanged) return;
Expand Down

0 comments on commit 5aecd91

Please sign in to comment.