From a0d4480f55d7967410cc01434ecb71c8fd7ec95b Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Fri, 17 Jul 2020 13:55:58 +0800 Subject: [PATCH] command buffer interface update (#6991) --- cocos/core/assets/deprecation.ts | 11 ++++++++++ cocos/core/assets/simple-texture.ts | 2 +- cocos/core/gfx/command-buffer.ts | 2 +- cocos/core/gfx/queue.ts | 1 - cocos/core/gfx/texture.ts | 12 +++++------ cocos/core/gfx/webgl/webgl-command-buffer.ts | 14 ++++--------- cocos/core/gfx/webgl/webgl-commands.ts | 8 +++---- .../gfx/webgl/webgl-primary-command-buffer.ts | 16 ++++---------- cocos/core/gfx/webgl/webgl-texture.ts | 12 +++++------ .../core/gfx/webgl2/webgl2-command-buffer.ts | 14 ++++--------- cocos/core/gfx/webgl2/webgl2-commands.ts | 8 +++---- .../webgl2/webgl2-primary-command-buffer.ts | 17 ++++----------- cocos/core/gfx/webgl2/webgl2-texture.ts | 12 +++++------ cocos/core/pipeline/forward/forward-stage.ts | 10 ++------- cocos/core/pipeline/ppfx/tonemap-stage.ts | 13 +----------- cocos/core/pipeline/render-flow.ts | 11 +++++++--- cocos/core/pipeline/render-pipeline.ts | 19 ++++++++++++++++- cocos/core/pipeline/render-stage.ts | 21 ++----------------- cocos/core/pipeline/ui/ui-stage.ts | 10 ++------- cocos/core/root.ts | 18 +++++++++------- cocos/core/utils/profiler/profiler.ts | 6 +++--- 21 files changed, 99 insertions(+), 138 deletions(-) diff --git a/cocos/core/assets/deprecation.ts b/cocos/core/assets/deprecation.ts index 6ca99ab6c0..c56d244534 100644 --- a/cocos/core/assets/deprecation.ts +++ b/cocos/core/assets/deprecation.ts @@ -5,6 +5,7 @@ import { removeProperty, replaceProperty } from '../utils'; import { Mesh } from './mesh'; import { TextureBase } from './texture-base'; +import { RenderTexture } from './render-texture'; replaceProperty(Mesh.prototype, 'Mesh.prototype', [ { @@ -33,3 +34,13 @@ removeProperty(TextureBase.prototype, 'TextureBase.prototype', [ name: 'setFlipY', }, ]); + +replaceProperty(RenderTexture.prototype, 'RenderTexture.prototype', [ + { + name: 'getGFXWindow', + customFunction () { + // @ts-ignore + return this._window; + }, + }, +]); diff --git a/cocos/core/assets/simple-texture.ts b/cocos/core/assets/simple-texture.ts index 7390bdda99..807f9ef524 100644 --- a/cocos/core/assets/simple-texture.ts +++ b/cocos/core/assets/simple-texture.ts @@ -105,7 +105,7 @@ export class SimpleTexture extends TextureBase { * @param arrayIndex 数组索引。 */ public uploadData (source: HTMLCanvasElement | HTMLImageElement | ArrayBufferView, level: number = 0, arrayIndex: number = 0) { - if (!this._gfxTexture || this._gfxTexture.mipLevel <= level) { + if (!this._gfxTexture || this._gfxTexture.levelCount <= level) { return; } diff --git a/cocos/core/gfx/command-buffer.ts b/cocos/core/gfx/command-buffer.ts index 48f1dff613..9abcbc4f22 100644 --- a/cocos/core/gfx/command-buffer.ts +++ b/cocos/core/gfx/command-buffer.ts @@ -259,7 +259,7 @@ export abstract class GFXCommandBuffer extends GFXObject { * @param dstLayout The target texture layout. * @param regions The region descriptions. */ - public abstract copyBufferToTexture (srcBuff: GFXBuffer, dstTex: GFXTexture, dstLayout: GFXTextureLayout, regions: GFXBufferTextureCopy[]): void; + public abstract copyBuffersToTexture (buffers: ArrayBufferView[], texture: GFXTexture, regions: GFXBufferTextureCopy[]): void; /** * @en Execute specified command buffers. diff --git a/cocos/core/gfx/queue.ts b/cocos/core/gfx/queue.ts index 822323617c..cdf734a4f1 100644 --- a/cocos/core/gfx/queue.ts +++ b/cocos/core/gfx/queue.ts @@ -9,7 +9,6 @@ import { GFXFence } from './fence'; export interface IGFXQueueInfo { type: GFXQueueType; - forceSync?: boolean; } /** diff --git a/cocos/core/gfx/texture.ts b/cocos/core/gfx/texture.ts index febe1153fa..ecc669aa07 100644 --- a/cocos/core/gfx/texture.ts +++ b/cocos/core/gfx/texture.ts @@ -100,16 +100,16 @@ export abstract class GFXTexture extends GFXObject { * @en Get texture array layer. * @zh 纹理数组层数。 */ - get arrayLayer (): number { - return this._arrayLayer; + get layerCount (): number { + return this._layerCount; } /** * @en Get texture mip level. * @zh 纹理 mip 层级数。 */ - get mipLevel (): number { - return this._mipLevel; + get levelCount (): number { + return this._levelCount; } /** @@ -158,9 +158,9 @@ export abstract class GFXTexture extends GFXObject { protected _depth: number = 1; - protected _arrayLayer: number = 1; + protected _layerCount: number = 1; - protected _mipLevel: number = 1; + protected _levelCount: number = 1; protected _samples: GFXSampleCount = GFXSampleCount.X1; diff --git a/cocos/core/gfx/webgl/webgl-command-buffer.ts b/cocos/core/gfx/webgl/webgl-command-buffer.ts index 6663ab5fb5..70f4554555 100644 --- a/cocos/core/gfx/webgl/webgl-command-buffer.ts +++ b/cocos/core/gfx/webgl/webgl-command-buffer.ts @@ -401,23 +401,17 @@ export class WebGLGFXCommandBuffer extends GFXCommandBuffer { } } - public copyBufferToTexture ( - srcBuff: GFXBuffer, - dstTex: GFXTexture, - dstLayout: GFXTextureLayout, - regions: GFXBufferTextureCopy[]) { + public copyBuffersToTexture (buffers: ArrayBufferView[], texture: GFXTexture, regions: GFXBufferTextureCopy[]) { if (this._type === GFXCommandBufferType.PRIMARY && !this._isInRenderPass || this._type === GFXCommandBufferType.SECONDARY) { - const gpuBuffer = ( srcBuff as WebGLGFXBuffer).gpuBuffer; - const gpuTexture = ( dstTex as WebGLGFXTexture).gpuTexture; - if (gpuBuffer && gpuTexture) { + const gpuTexture = (texture as WebGLGFXTexture).gpuTexture; + if (gpuTexture) { const cmd = this._webGLAllocator!.copyBufferToTextureCmdPool.alloc(WebGLCmdCopyBufferToTexture); if (cmd) { - cmd.gpuBuffer = gpuBuffer; cmd.gpuTexture = gpuTexture; - cmd.dstLayout = dstLayout; cmd.regions = regions; + cmd.buffers = buffers; this.cmdPackage.copyBufferToTextureCmds.push(cmd); this.cmdPackage.cmds.push(WebGLCmd.COPY_BUFFER_TO_TEXTURE); diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index e767492886..ef95b12cea 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -618,9 +618,8 @@ export class WebGLGFXBufferTextureCopy { export class WebGLCmdCopyBufferToTexture extends WebGLCmdObject { - public gpuBuffer: WebGLGPUBuffer | null = null; public gpuTexture: WebGLGPUTexture | null = null; - public dstLayout: GFXTextureLayout | null = null; + public buffers: ArrayBufferView[] = []; public regions: GFXBufferTextureCopy[] = []; constructor () { @@ -628,9 +627,8 @@ export class WebGLCmdCopyBufferToTexture extends WebGLCmdObject { } public clear () { - this.gpuBuffer = null; this.gpuTexture = null; - this.dstLayout = null; + this.buffers.length = 0; this.regions.length = 0; } } @@ -2704,7 +2702,7 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web } case WebGLCmd.COPY_BUFFER_TO_TEXTURE: { const cmd5 = cmdPackage.copyBufferToTextureCmds.array[cmdId]; - WebGLCmdFuncCopyBuffersToTexture(device, [(cmd5.gpuBuffer as WebGLGPUBuffer).buffer!], cmd5.gpuTexture as WebGLGPUTexture, cmd5.regions); + WebGLCmdFuncCopyBuffersToTexture(device, cmd5.buffers, cmd5.gpuTexture as WebGLGPUTexture, cmd5.regions); break; } } // switch diff --git a/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts b/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts index 820df1dd5f..4e0d937537 100644 --- a/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts +++ b/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts @@ -15,8 +15,6 @@ import { WebGLGFXTexture } from './webgl-texture'; import { GFXRenderPass } from '../render-pass'; import { WebGLGFXRenderPass } from './webgl-render-pass'; -const _buffers: ArrayBufferView[] = []; - export class WebGLGFXPrimaryCommandBuffer extends WebGLGFXCommandBuffer { public beginRenderPass ( @@ -87,18 +85,12 @@ export class WebGLGFXPrimaryCommandBuffer extends WebGLGFXCommandBuffer { } } - public copyBufferToTexture ( - srcBuff: GFXBuffer, - dstTex: GFXTexture, - dstLayout: GFXTextureLayout, - regions: GFXBufferTextureCopy[]) { + public copyBuffersToTexture (buffers: ArrayBufferView[], texture: GFXTexture, regions: GFXBufferTextureCopy[]) { if (!this._isInRenderPass) { - const gpuBuffer = (srcBuff as WebGLGFXBuffer).gpuBuffer; - const gpuTexture = (dstTex as WebGLGFXTexture).gpuTexture; - if (gpuBuffer && gpuTexture) { - _buffers[0] = gpuBuffer.buffer!; - WebGLCmdFuncCopyBuffersToTexture(this._device as WebGLGFXDevice, _buffers, gpuTexture, regions); + const gpuTexture = (texture as WebGLGFXTexture).gpuTexture; + if (gpuTexture) { + WebGLCmdFuncCopyBuffersToTexture(this._device as WebGLGFXDevice, buffers, gpuTexture, regions); } } else { console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.'); diff --git a/cocos/core/gfx/webgl/webgl-texture.ts b/cocos/core/gfx/webgl/webgl-texture.ts index 1086e1aaf8..39747ddcae 100644 --- a/cocos/core/gfx/webgl/webgl-texture.ts +++ b/cocos/core/gfx/webgl/webgl-texture.ts @@ -30,11 +30,11 @@ export class WebGLGFXTexture extends GFXTexture { } if (info.arrayLayer !== undefined) { - this._arrayLayer = info.arrayLayer; + this._layerCount = info.arrayLayer; } if (info.mipLevel !== undefined) { - this._mipLevel = info.mipLevel; + this._levelCount = info.mipLevel; } if (info.samples !== undefined) { @@ -48,7 +48,7 @@ export class WebGLGFXTexture extends GFXTexture { this._isPowerOf2 = IsPowerOf2(this._width) && IsPowerOf2(this._height); this._size = GFXFormatSurfaceSize(this._format, this.width, this.height, - this.depth, this.mipLevel) * this._arrayLayer; + this.depth, this._levelCount) * this._layerCount; if (this._flags & GFXTextureFlagBit.BAKUP_BUFFER) { this._buffer = new ArrayBuffer(this._size); @@ -62,8 +62,8 @@ export class WebGLGFXTexture extends GFXTexture { height: this._height, depth: this._depth, size: this._size, - arrayLayer: this._arrayLayer, - mipLevel: this._mipLevel, + arrayLayer: this._layerCount, + mipLevel: this._levelCount, samples: this._samples, flags: this._flags, isPowerOf2: this._isPowerOf2, @@ -105,7 +105,7 @@ export class WebGLGFXTexture extends GFXTexture { this._width = width; this._height = height; this._size = GFXFormatSurfaceSize(this._format, this.width, this.height, - this.depth, this.mipLevel) * this._arrayLayer; + this.depth, this._levelCount) * this._layerCount; if (this._gpuTexture) { this._gpuTexture.width = width; diff --git a/cocos/core/gfx/webgl2/webgl2-command-buffer.ts b/cocos/core/gfx/webgl2/webgl2-command-buffer.ts index d6f13c7ccf..b7c427c217 100644 --- a/cocos/core/gfx/webgl2/webgl2-command-buffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-command-buffer.ts @@ -397,21 +397,15 @@ export class WebGL2GFXCommandBuffer extends GFXCommandBuffer { } } - public copyBufferToTexture ( - srcBuff: GFXBuffer, - dstTex: GFXTexture, - dstLayout: GFXTextureLayout, - regions: GFXBufferTextureCopy[]) { + public copyBuffersToTexture (buffers: ArrayBufferView[], texture: GFXTexture, regions: GFXBufferTextureCopy[]) { if (this._type === GFXCommandBufferType.PRIMARY && !this._isInRenderPass || this._type === GFXCommandBufferType.SECONDARY) { - const gpuBuffer = ( srcBuff as WebGL2GFXBuffer).gpuBuffer; - const gpuTexture = ( dstTex as WebGL2GFXTexture).gpuTexture; - if (gpuBuffer && gpuTexture) { + const gpuTexture = (texture as WebGL2GFXTexture).gpuTexture; + if (gpuTexture) { const cmd = this._webGLAllocator!.copyBufferToTextureCmdPool.alloc(WebGL2CmdCopyBufferToTexture); - cmd.gpuBuffer = gpuBuffer; cmd.gpuTexture = gpuTexture; - cmd.dstLayout = dstLayout; + cmd.buffers = buffers; cmd.regions = regions; this.cmdPackage.copyBufferToTextureCmds.push(cmd); diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index bae40cbfde..8c10daf824 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -769,9 +769,8 @@ export class WebGL2GFXBufferTextureCopy { export class WebGL2CmdCopyBufferToTexture extends WebGL2CmdObject { - public gpuBuffer: WebGL2GPUBuffer | null = null; public gpuTexture: WebGL2GPUTexture | null = null; - public dstLayout: GFXTextureLayout | null = null; + public buffers: ArrayBufferView[] = []; public regions: GFXBufferTextureCopy[] = []; constructor () { @@ -779,9 +778,8 @@ export class WebGL2CmdCopyBufferToTexture extends WebGL2CmdObject { } public clear () { - this.gpuBuffer = null; this.gpuTexture = null; - this.dstLayout = null; + this.buffers.length = 0; this.regions.length = 0; } } @@ -2741,7 +2739,7 @@ export function WebGL2CmdFuncExecuteCmds (device: WebGL2GFXDevice, cmdPackage: W } case WebGL2Cmd.COPY_BUFFER_TO_TEXTURE: { const cmd5 = cmdPackage.copyBufferToTextureCmds.array[cmdId]; - WebGL2CmdFuncCopyBuffersToTexture(device, [(cmd5.gpuBuffer as WebGL2GPUBuffer).buffer!], cmd5.gpuTexture as WebGL2GPUTexture, cmd5.regions); + WebGL2CmdFuncCopyBuffersToTexture(device, cmd5.buffers, cmd5.gpuTexture as WebGL2GPUTexture, cmd5.regions); break; } } // switch diff --git a/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts b/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts index 1faba736fe..ebe5e76ef8 100644 --- a/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts @@ -15,8 +15,6 @@ import { WebGL2GFXTexture } from './webgl2-texture'; import { GFXRenderPass } from '../render-pass'; import { WebGL2GFXRenderPass } from './webgl2-render-pass'; -const _buffers: ArrayBufferView[] = []; - export class WebGL2GFXPrimaryCommandBuffer extends WebGL2GFXCommandBuffer { public beginRenderPass ( @@ -87,18 +85,11 @@ export class WebGL2GFXPrimaryCommandBuffer extends WebGL2GFXCommandBuffer { } } - public copyBufferToTexture ( - srcBuff: GFXBuffer, - dstTex: GFXTexture, - dstLayout: GFXTextureLayout, - regions: GFXBufferTextureCopy[]) { - + public copyBuffersToTexture (buffers: ArrayBufferView[], texture: GFXTexture, regions: GFXBufferTextureCopy[]) { if (!this._isInRenderPass) { - const gpuBuffer = (srcBuff as WebGL2GFXBuffer).gpuBuffer; - const gpuTexture = (dstTex as WebGL2GFXTexture).gpuTexture; - if (gpuBuffer && gpuTexture) { - _buffers[0] = gpuBuffer.buffer!; - WebGL2CmdFuncCopyBuffersToTexture(this._device as WebGL2GFXDevice, _buffers, gpuTexture, regions); + const gpuTexture = (texture as WebGL2GFXTexture).gpuTexture; + if (gpuTexture) { + WebGL2CmdFuncCopyBuffersToTexture(this._device as WebGL2GFXDevice, buffers, gpuTexture, regions); } } else { console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.'); diff --git a/cocos/core/gfx/webgl2/webgl2-texture.ts b/cocos/core/gfx/webgl2/webgl2-texture.ts index 2c5f9cca41..a2f75c6ad0 100644 --- a/cocos/core/gfx/webgl2/webgl2-texture.ts +++ b/cocos/core/gfx/webgl2/webgl2-texture.ts @@ -30,11 +30,11 @@ export class WebGL2GFXTexture extends GFXTexture { } if (info.arrayLayer !== undefined) { - this._arrayLayer = info.arrayLayer; + this._layerCount = info.arrayLayer; } if (info.mipLevel !== undefined) { - this._mipLevel = info.mipLevel; + this._levelCount = info.mipLevel; } if (info.samples !== undefined) { @@ -48,7 +48,7 @@ export class WebGL2GFXTexture extends GFXTexture { this._isPowerOf2 = IsPowerOf2(this._width) && IsPowerOf2(this._height); this._size = GFXFormatSurfaceSize(this._format, this.width, this.height, - this.depth, this.mipLevel) * this._arrayLayer; + this.depth, this._levelCount) * this._layerCount; if (this._flags & GFXTextureFlagBit.BAKUP_BUFFER) { this._buffer = new ArrayBuffer(this._size); @@ -62,8 +62,8 @@ export class WebGL2GFXTexture extends GFXTexture { height: this._height, depth: this._depth, size: this._size, - arrayLayer: this._arrayLayer, - mipLevel: this._mipLevel, + arrayLayer: this._layerCount, + mipLevel: this._levelCount, samples: this._samples, flags: this._flags, isPowerOf2: this._isPowerOf2, @@ -105,7 +105,7 @@ export class WebGL2GFXTexture extends GFXTexture { this._width = width; this._height = height; this._size = GFXFormatSurfaceSize(this._format, this.width, this.height, - this.depth, this.mipLevel) * this._arrayLayer; + this.depth, this._levelCount) * this._layerCount; if (this._gpuTexture) { this._gpuTexture.width = width; diff --git a/cocos/core/pipeline/forward/forward-stage.ts b/cocos/core/pipeline/forward/forward-stage.ts index a712eae7d8..1465f5bc3c 100644 --- a/cocos/core/pipeline/forward/forward-stage.ts +++ b/cocos/core/pipeline/forward/forward-stage.ts @@ -55,14 +55,9 @@ export class ForwardStage extends RenderStage { public activate (flow: RenderFlow) { super.activate(flow); - this.createCmdBuffer(); } public destroy () { - if (this._cmdBuff) { - this._cmdBuff.destroy(); - this._cmdBuff = null; - } } public resize (width: number, height: number) { @@ -124,7 +119,7 @@ export class ForwardStage extends RenderStage { const camera = view.camera; - const cmdBuff = this._cmdBuff!; + const cmdBuff = this._pipeline.commandBuffers[0]; const vp = camera.viewport; this._renderArea!.x = vp.x * camera.width; @@ -174,8 +169,7 @@ export class ForwardStage extends RenderStage { cmdBuff.endRenderPass(); cmdBuff.end(); - bufs[0] = cmdBuff; - device.queue.submit(bufs); + device.queue.submit(this._pipeline.commandBuffers); if (this._pipeline.useMSAA) { device.blitFramebuffer( diff --git a/cocos/core/pipeline/ppfx/tonemap-stage.ts b/cocos/core/pipeline/ppfx/tonemap-stage.ts index f0411a91d7..308f63d461 100644 --- a/cocos/core/pipeline/ppfx/tonemap-stage.ts +++ b/cocos/core/pipeline/ppfx/tonemap-stage.ts @@ -35,16 +35,10 @@ export class ToneMapStage extends RenderStage { super.activate(flow); - this.createCmdBuffer(); - this.rebuild(); } public destroy () { - if (this._cmdBuff) { - this._cmdBuff.destroy(); - this._cmdBuff = null; - } } public resize (width: number, height: number) { @@ -74,7 +68,7 @@ export class ToneMapStage extends RenderStage { public render (view: RenderView) { const camera = view.camera!; - const cmdBuff = this._cmdBuff!; + const cmdBuff = this._pipeline.commandBuffers[0]; this._renderArea!.width = camera.width; this._renderArea!.height = camera.height; @@ -82,7 +76,6 @@ export class ToneMapStage extends RenderStage { const framebuffer = view.window.framebuffer; const renderPass = framebuffer.renderPass; - cmdBuff.begin(); cmdBuff.beginRenderPass(renderPass, framebuffer, this._renderArea!, [{ r: 0.0, g: 0.0, b: 0.0, a: 1.0 }], 1.0, 0); const pso = PipelineStateManager.getOrCreatePipelineState(PipelineGlobal.device, this._psoCreateInfo!, framebuffer.renderPass!, this._pipeline!.quadIA); @@ -91,10 +84,6 @@ export class ToneMapStage extends RenderStage { cmdBuff.bindInputAssembler(this._pipeline!.quadIA); cmdBuff.draw(this._pipeline!.quadIA); cmdBuff.endRenderPass(); - cmdBuff.end(); - - bufs[0] = cmdBuff; - PipelineGlobal.device.queue.submit(bufs); // this._pipeline.swapFBOs(); } diff --git a/cocos/core/pipeline/render-flow.ts b/cocos/core/pipeline/render-flow.ts index 9ea7bc1d70..f9ecc4f2d4 100644 --- a/cocos/core/pipeline/render-flow.ts +++ b/cocos/core/pipeline/render-flow.ts @@ -11,6 +11,7 @@ import { RenderView } from './render-view'; import { legacyCC } from '../global-exports'; import { GFXClearFlag, GFXRenderPass, GFXColorAttachment, GFXDepthStencilAttachment, GFXLoadOp, GFXTextureLayout } from '../gfx'; import { PipelineGlobal } from './global'; +import { SKYBOX_FLAG } from '../renderer'; /** * @en Render flow information descriptor @@ -97,7 +98,7 @@ export abstract class RenderFlow { protected _priority: number = 0; @property({ - type: legacyCC.Material, + type: Material, displayOrder: 2, visible: true, }) @@ -207,8 +208,12 @@ export abstract class RenderFlow { depthStencilAttachment.format = device.depthStencilFormat; if (!(clearFlags & GFXClearFlag.COLOR)) { - colorAttachment.loadOp = GFXLoadOp.LOAD; - colorAttachment.beginLayout = GFXTextureLayout.PRESENT_SRC; + if (clearFlags & SKYBOX_FLAG) { + colorAttachment.loadOp = GFXLoadOp.DISCARD; + } else { + colorAttachment.loadOp = GFXLoadOp.LOAD; + colorAttachment.beginLayout = GFXTextureLayout.PRESENT_SRC; + } } if ((clearFlags & GFXClearFlag.DEPTH_STENCIL) !== GFXClearFlag.DEPTH_STENCIL) { diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index 489f228850..9edc8ffe9b 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -14,7 +14,8 @@ import { GFXTextureLayout, GFXTextureUsageBit, GFXLoadOp, - GFXStoreOp} from '../gfx/define'; + GFXStoreOp, + GFXCommandBufferType} from '../gfx/define'; import { GFXFeature } from '../gfx/device'; import { GFXFramebuffer } from '../gfx/framebuffer'; import { GFXInputAssembler, IGFXAttribute } from '../gfx/input-assembler'; @@ -33,6 +34,7 @@ import { RenderFlow } from './render-flow'; import { RenderView } from './render-view'; import { legacyCC } from '../global-exports'; import { PipelineGlobal } from './global'; +import { GFXCommandBuffer } from '../gfx'; const v3_1 = new Vec3(); @@ -245,6 +247,15 @@ export abstract class RenderPipeline { return this._prevIdx; } + /** + * @en The primary command buffer this pipeline uses + * @zh 当前管线使用的一级命令缓冲 + * @readonly + */ + get commandBuffers () { + return this._commandBuffers; + } + /** * @en Whether use dynamic batching in this pipeline * @zh 是否启用动态合批。 @@ -312,6 +323,7 @@ export abstract class RenderPipeline { protected _fpScaleInv: number = 1024.0; protected _macros: IDefineMap = {}; protected _useDynamicBatching = false; + protected _commandBuffers: GFXCommandBuffer[] = []; @property({ type: [RenderTextureDesc], @@ -831,6 +843,11 @@ export abstract class RenderPipeline { }); this.addRenderPass(RenderPassStage.UI, uiPass); + this._commandBuffers[0] = PipelineGlobal.device.createCommandBuffer({ + type: GFXCommandBufferType.PRIMARY, + queue: PipelineGlobal.device.queue, + }); + // update global defines when all states initialized. this._macros.CC_USE_HDR = (this._isHDR); this._macros.CC_SUPPORT_FLOAT_TEXTURE =PipelineGlobal.device.hasFeature(GFXFeature.TEXTURE_FLOAT); diff --git a/cocos/core/pipeline/render-stage.ts b/cocos/core/pipeline/render-stage.ts index 6b5ec8ec39..65dba77773 100644 --- a/cocos/core/pipeline/render-stage.ts +++ b/cocos/core/pipeline/render-stage.ts @@ -148,12 +148,6 @@ export abstract class RenderStage { protected _framebuffer: GFXFramebuffer | null = null; - /** - * @en The command buffer - * @zh 命令缓冲。 - */ - protected _cmdBuff: GFXCommandBuffer | null = null; - /** * @en The list of clear colors * @zh 清空颜色数组。 @@ -363,7 +357,7 @@ export abstract class RenderStage { public executeCommandBuffer (view: RenderView) { const camera = view.camera; - const cmdBuff = this._cmdBuff!; + const cmdBuff = this._pipeline.commandBuffers[0]; const vp = camera.viewport; this._renderArea!.x = vp.x * camera.width; @@ -391,19 +385,8 @@ export abstract class RenderStage { cmdBuff.endRenderPass(); cmdBuff.end(); - bufs[0] = cmdBuff; - PipelineGlobal.device.queue.submit(bufs); - } - /** - * @en Create the main command buffer of this stage - * @zh 创建该阶段的主命令缓冲 - */ - public createCmdBuffer () { - this._cmdBuff = PipelineGlobal.device.createCommandBuffer({ - queue: PipelineGlobal.device.queue, - type: GFXCommandBufferType.PRIMARY, - }); + PipelineGlobal.device.queue.submit(this._pipeline.commandBuffers); } /** diff --git a/cocos/core/pipeline/ui/ui-stage.ts b/cocos/core/pipeline/ui/ui-stage.ts index 146346d2f9..8750fd22c6 100644 --- a/cocos/core/pipeline/ui/ui-stage.ts +++ b/cocos/core/pipeline/ui/ui-stage.ts @@ -31,14 +31,9 @@ export class UIStage extends RenderStage { public activate (flow: RenderFlow) { super.activate(flow); - this.createCmdBuffer(); } public destroy () { - if (this._cmdBuff) { - this._cmdBuff.destroy(); - this._cmdBuff = null; - } } public resize (width: number, height: number) { @@ -69,7 +64,7 @@ export class UIStage extends RenderStage { colors[0] = camera.clearColor; - const cmdBuff = this._cmdBuff!; + const cmdBuff = this._pipeline.commandBuffers[0]; const framebuffer = view.window.framebuffer; const renderPass = framebuffer.colorTextures[0] ? framebuffer.renderPass : this._flow.getRenderPass(camera.clearFlag); @@ -83,7 +78,6 @@ export class UIStage extends RenderStage { cmdBuff.endRenderPass(); cmdBuff.end(); - bufs[0] = cmdBuff; - PipelineGlobal.device.queue.submit(bufs); + PipelineGlobal.device.queue.submit(this._pipeline.commandBuffers); } } diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 270e980604..271fd9b008 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -359,17 +359,19 @@ export class Root { this._fpsTime = 0.0; } - this._device.acquire(); + if (this._pipeline) { + this._device.acquire(); - const views = this._views; - for (let i = 0; i < views.length; i++) { - const view = views[i]; - if (view.isEnable && view.window && this._pipeline) { - this._pipeline.render(view); + const views = this._views; + for (let i = 0; i < views.length; i++) { + const view = views[i]; + if (view.isEnable && view.window) { + this._pipeline.render(view); + } } - } - this._device.present(); + this._device.present(); + } } /** diff --git a/cocos/core/utils/profiler/profiler.ts b/cocos/core/utils/profiler/profiler.ts index 9ae2ace351..450429c86d 100644 --- a/cocos/core/utils/profiler/profiler.ts +++ b/cocos/core/utils/profiler/profiler.ts @@ -245,12 +245,12 @@ export class Profiler { legacyCC.game.addPersistRootNode(this._rootNode); const cameraNode = new Node('Profiler_Camera'); - cameraNode.setPosition(0, 0, 1); + cameraNode.setPosition(0, 0, 1.5); cameraNode.parent = this._rootNode; const camera = cameraNode.addComponent('cc.CameraComponent') as CameraComponent; camera.projection = CameraComponent.ProjectionType.ORTHO; - camera.near = 0; - camera.far = 0; + camera.near = 1; + camera.far = 2; camera.orthoHeight = this._device!.height; camera.visibility = Layers.BitMask.PROFILER; camera.clearFlags = GFXClearFlag.NONE;