From 956d71343efeb031d709731e20fa16f6d6767fcf Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Sun, 8 Oct 2023 11:12:50 +0800 Subject: [PATCH] [Fixed] web pipeline framebuffer resize issue. (#16321) --- cocos/gfx/base/framebuffer.ts | 10 ++++++++++ cocos/gfx/webgl/webgl-framebuffer.ts | 2 ++ cocos/gfx/webgl2/webgl2-framebuffer.ts | 2 ++ cocos/rendering/custom/executor.ts | 22 ++++++++++++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cocos/gfx/base/framebuffer.ts b/cocos/gfx/base/framebuffer.ts index 71c04e1f54b..d609db6bd67 100644 --- a/cocos/gfx/base/framebuffer.ts +++ b/cocos/gfx/base/framebuffer.ts @@ -55,9 +55,19 @@ export abstract class Framebuffer extends GFXObject { return this._depthStencilTexture; } + public get width (): number { + return this._width; + } + + public get height (): number { + return this._height; + } + protected _renderPass: RenderPass | null = null; protected _colorTextures: (Texture | null)[] = []; protected _depthStencilTexture: Texture | null = null; + protected _width: number = 0; + protected _height: number = 0; constructor () { super(ObjectType.FRAMEBUFFER); diff --git a/cocos/gfx/webgl/webgl-framebuffer.ts b/cocos/gfx/webgl/webgl-framebuffer.ts index aeab6338e91..448239c19c6 100644 --- a/cocos/gfx/webgl/webgl-framebuffer.ts +++ b/cocos/gfx/webgl/webgl-framebuffer.ts @@ -96,6 +96,8 @@ export class WebGLFramebuffer extends Framebuffer { }; WebGLCmdFuncCreateFramebuffer(WebGLDeviceManager.instance, this._gpuFramebuffer); + this._width = this._gpuFramebuffer.width; + this._height = this._gpuFramebuffer.height; } public destroy (): void { diff --git a/cocos/gfx/webgl2/webgl2-framebuffer.ts b/cocos/gfx/webgl2/webgl2-framebuffer.ts index 255c7a9a6b3..539857308ce 100644 --- a/cocos/gfx/webgl2/webgl2-framebuffer.ts +++ b/cocos/gfx/webgl2/webgl2-framebuffer.ts @@ -90,6 +90,8 @@ export class WebGL2Framebuffer extends Framebuffer { }; WebGL2CmdFuncCreateFramebuffer(WebGL2DeviceManager.instance, this._gpuFramebuffer); + this._width = this._gpuFramebuffer.width; + this._height = this._gpuFramebuffer.height; } public destroy (): void { diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index bc3f28ba261..e855f90ce53 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -950,6 +950,25 @@ class DeviceRenderPass { if (this.renderLayout && this.renderLayout.descriptorSet) { this.renderLayout.descriptorSet.update(); } + + const resGraph = context.resourceGraph; + const currentWidth = this._framebuffer ? this._framebuffer.width : 0; + const currentHeight = this._framebuffer ? this._framebuffer.height : 0; + + let width = 0; + let height = 0; + for (const [resName, rasterV] of this._rasterInfo.pass.rasterViews) { + if (rasterV.attachmentType === AttachmentType.SHADING_RATE) { + continue; + } + const resId = resGraph.vertex(resName); + const resDesc = resGraph.getDesc(resId); + width = resDesc.width; + height = resDesc.height; + break; + } + const needRebuild = (width !== currentWidth) || (height !== currentHeight); + for (const [resName, rasterV] of this._rasterInfo.pass.rasterViews) { let deviceTex = context.deviceTextures.get(resName)!; const currTex = deviceTex; @@ -963,8 +982,7 @@ class DeviceRenderPass { const resDesc = resGraph.getDesc(resId); if (deviceTex.framebuffer && resFbo instanceof Framebuffer && deviceTex.framebuffer !== resFbo) { framebuffer = this._framebuffer = deviceTex.framebuffer = resFbo; - } else if (!currTex || (deviceTex.texture - && (deviceTex.texture.width !== resDesc.width || deviceTex.texture.height !== resDesc.height))) { + } else if (!currTex || (deviceTex.texture && needRebuild)) { const gfxTex = deviceTex.texture!; if (currTex) gfxTex.resize(resDesc.width, resDesc.height); switch (rasterV.attachmentType) {