From 742989cce91c1fcc95caecdea4ae8b4a5a17ff92 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Mon, 17 Aug 2020 17:33:26 +0800 Subject: [PATCH] keep pipeline layouts for effect overrides (#7152) --- cocos/core/gfx/webgl/webgl-gpu-objects.ts | 2 +- cocos/core/gfx/webgl/webgl-pipeline-layout.ts | 7 ++++--- cocos/core/gfx/webgl2/webgl2-gpu-objects.ts | 2 +- cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts | 7 ++++--- cocos/core/renderer/core/pass.ts | 1 - cocos/core/renderer/core/program-lib.ts | 6 +++++- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cocos/core/gfx/webgl/webgl-gpu-objects.ts b/cocos/core/gfx/webgl/webgl-gpu-objects.ts index 92c6fb8e1d..7c80c949ff 100644 --- a/cocos/core/gfx/webgl/webgl-gpu-objects.ts +++ b/cocos/core/gfx/webgl/webgl-gpu-objects.ts @@ -166,7 +166,7 @@ export interface IWebGLGPUDescriptorSetLayout { } export interface IWebGLGPUPipelineLayout { - setLayouts: GFXDescriptorSetLayout[]; + gpuSetLayouts: IWebGLGPUDescriptorSetLayout[]; dynamicOffsetIndices: number[][]; } diff --git a/cocos/core/gfx/webgl/webgl-pipeline-layout.ts b/cocos/core/gfx/webgl/webgl-pipeline-layout.ts index 4b29190759..ede04328fd 100644 --- a/cocos/core/gfx/webgl/webgl-pipeline-layout.ts +++ b/cocos/core/gfx/webgl/webgl-pipeline-layout.ts @@ -1,5 +1,5 @@ import { GFXPipelineLayout, IGFXPipelineLayoutInfo } from '../pipeline-layout'; -import { IWebGLGPUPipelineLayout } from './webgl-gpu-objects'; +import { IWebGLGPUPipelineLayout, IWebGLGPUDescriptorSetLayout } from './webgl-gpu-objects'; import { WebGLDescriptorSetLayout } from './webgl-descriptor-set-layout'; export class WebGLPipelineLayout extends GFXPipelineLayout { @@ -13,12 +13,13 @@ export class WebGLPipelineLayout extends GFXPipelineLayout { const dynamicOffsetIndices: number[][] = []; - let idx = 0; + const gpuSetLayouts: IWebGLGPUDescriptorSetLayout[] = []; let idx = 0; for (let i = 0; i < this._setLayouts.length; i++) { const setLayout = this._setLayouts[i] as WebGLDescriptorSetLayout; const dynamicBindings = setLayout.gpuDescriptorSetLayout.dynamicBindings; const bindings = setLayout.bindings; const indices: number[] = []; + gpuSetLayouts.push(setLayout.gpuDescriptorSetLayout); for (let j = 0, k = 0; j < bindings.length; j++) { if (dynamicBindings[k] === j) { indices.push(idx); @@ -32,7 +33,7 @@ export class WebGLPipelineLayout extends GFXPipelineLayout { } this._gpuPipelineLayout = { - setLayouts: this._setLayouts, + gpuSetLayouts, dynamicOffsetIndices, }; diff --git a/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts b/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts index 826c37cb20..e589d627e4 100644 --- a/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts +++ b/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts @@ -176,7 +176,7 @@ export interface IWebGL2GPUDescriptorSetLayout { } export interface IWebGL2GPUPipelineLayout { - setLayouts: GFXDescriptorSetLayout[]; + gpuSetLayouts: IWebGL2GPUDescriptorSetLayout[]; dynamicOffsetIndices: number[][]; } diff --git a/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts b/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts index dac59bc628..7d1b4086fc 100644 --- a/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts +++ b/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts @@ -1,5 +1,5 @@ import { GFXPipelineLayout, IGFXPipelineLayoutInfo } from '../pipeline-layout'; -import { IWebGL2GPUPipelineLayout } from './webgl2-gpu-objects'; +import { IWebGL2GPUPipelineLayout, IWebGL2GPUDescriptorSetLayout } from './webgl2-gpu-objects'; import { WebGL2DescriptorSetLayout } from './webgl2-descriptor-set-layout'; export class WebGL2PipelineLayout extends GFXPipelineLayout { @@ -13,12 +13,13 @@ export class WebGL2PipelineLayout extends GFXPipelineLayout { const dynamicOffsetIndices: number[][] = []; - let idx = 0; + const gpuSetLayouts: IWebGL2GPUDescriptorSetLayout[] = []; let idx = 0; for (let i = 0; i < this._setLayouts.length; i++) { const setLayout = this._setLayouts[i] as WebGL2DescriptorSetLayout; const dynamicBindings = setLayout.gpuDescriptorSetLayout.dynamicBindings; const bindings = setLayout.bindings; const indices: number[] = []; + gpuSetLayouts.push(setLayout.gpuDescriptorSetLayout); for (let j = 0, k = 0; j < bindings.length; j++) { if (dynamicBindings[k] === j) { indices.push(idx); @@ -32,7 +33,7 @@ export class WebGL2PipelineLayout extends GFXPipelineLayout { } this._gpuPipelineLayout = { - setLayouts: this._setLayouts, + gpuSetLayouts, dynamicOffsetIndices, }; diff --git a/cocos/core/renderer/core/pass.ts b/cocos/core/renderer/core/pass.ts index f2cfb9fd93..4384fad577 100644 --- a/cocos/core/renderer/core/pass.ts +++ b/cocos/core/renderer/core/pass.ts @@ -473,7 +473,6 @@ export class Pass { const pipeline = this._root.pipeline; if (!pipeline) { return null; } this._syncBatchingScheme(); - Object.assign(this._defines, pipeline.macros); const key = programLib.getKey(this._programName, this._defines); this._hShaderDefault = programLib.getGFXShader(this._device, this._programName, this._defines, pipeline, key); if (!this._hShaderDefault) { console.warn(`create shader ${this._programName} failed`); return false; } diff --git a/cocos/core/renderer/core/program-lib.ts b/cocos/core/renderer/core/program-lib.ts index f715ce2df0..5ddf198024 100644 --- a/cocos/core/renderer/core/program-lib.ts +++ b/cocos/core/renderer/core/program-lib.ts @@ -227,7 +227,10 @@ class ProgramLib { // store it this._templates[prog.name] = tmpl; - this._pipelineLayouts[prog.name] = { hPipelineLayout: NULL_HANDLE, setLayouts: [] }; + + if (!this._pipelineLayouts[prog.name]) { + this._pipelineLayouts[prog.name] = { hPipelineLayout: NULL_HANDLE, setLayouts: [] }; + } } public getTemplate (name: string) { @@ -318,6 +321,7 @@ class ProgramLib { * @param pipeline 实际渲染命令执行时所属的 [[RenderPipeline]] */ public getGFXShader (device: GFXDevice, name: string, defines: MacroRecord, pipeline: RenderPipeline, key?: string) { + Object.assign(defines, pipeline.macros); if (!key) key = this.getKey(name, defines); const res = this._cache[key]; if (res) { return res; }