Skip to content

Commit

Permalink
[Fixed] web pipeline framebuffer resize issue. (#16321)
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS authored Oct 8, 2023
1 parent 7a8bde3 commit 956d713
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cocos/gfx/base/framebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions cocos/gfx/webgl/webgl-framebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions cocos/gfx/webgl2/webgl2-framebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 20 additions & 2 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 956d713

Please sign in to comment.