From fa366ee6fef17f1afdb215917f767a5b5381f33d Mon Sep 17 00:00:00 2001 From: Weiliang Wang Date: Thu, 29 Aug 2019 06:08:36 -0500 Subject: [PATCH] enable pooling of command allocator (#5280) * add transformAffine() * remove duplicate code * enable pooling of command allocator --- cocos/gfx/webgl/webgl-command-allocator.ts | 16 ++++++++-------- cocos/gfx/webgl2/webgl2-command-allocator.ts | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cocos/gfx/webgl/webgl-command-allocator.ts b/cocos/gfx/webgl/webgl-command-allocator.ts index 12bdee0502..ca92cfaaec 100644 --- a/cocos/gfx/webgl/webgl-command-allocator.ts +++ b/cocos/gfx/webgl/webgl-command-allocator.ts @@ -27,11 +27,12 @@ export class WebGLGFXCommandPool { this._freeIdx = count - 1; } + /* public alloc (clazz: new() => T): T { return new clazz(); } + */ - /* public alloc (clazz: new() => T): T { if (this._freeIdx < 0) { const size = this._frees.length * 2; @@ -55,7 +56,6 @@ export class WebGLGFXCommandPool { ++cmd.refCount; return cmd; } - */ public free (cmd: T) { if (--cmd.refCount === 0) { @@ -64,7 +64,7 @@ export class WebGLGFXCommandPool { } public freeCmds (cmds: CachedArray) { - return ; + // return ; for (let i = 0; i < cmds.length; ++i) { if (--cmds.array[i].refCount === 0) { this._freeCmds.push(cmds.array[i]); @@ -92,11 +92,11 @@ export class WebGLGFXCommandAllocator extends GFXCommandAllocator { constructor (device: GFXDevice) { super(device); - this.beginRenderPassCmdPool = new WebGLGFXCommandPool(WebGLCmdBeginRenderPass, 16); - this.bindStatesCmdPool = new WebGLGFXCommandPool(WebGLCmdBindStates, 16); - this.drawCmdPool = new WebGLGFXCommandPool(WebGLCmdDraw, 16); - this.updateBufferCmdPool = new WebGLGFXCommandPool(WebGLCmdUpdateBuffer, 16); - this.copyBufferToTextureCmdPool = new WebGLGFXCommandPool(WebGLCmdCopyBufferToTexture, 16); + this.beginRenderPassCmdPool = new WebGLGFXCommandPool(WebGLCmdBeginRenderPass, 1); + this.bindStatesCmdPool = new WebGLGFXCommandPool(WebGLCmdBindStates, 1); + this.drawCmdPool = new WebGLGFXCommandPool(WebGLCmdDraw, 1); + this.updateBufferCmdPool = new WebGLGFXCommandPool(WebGLCmdUpdateBuffer, 1); + this.copyBufferToTextureCmdPool = new WebGLGFXCommandPool(WebGLCmdCopyBufferToTexture, 1); } public initialize (info: IGFXCommandAllocatorInfo): boolean { diff --git a/cocos/gfx/webgl2/webgl2-command-allocator.ts b/cocos/gfx/webgl2/webgl2-command-allocator.ts index f0a6582324..736683cd18 100644 --- a/cocos/gfx/webgl2/webgl2-command-allocator.ts +++ b/cocos/gfx/webgl2/webgl2-command-allocator.ts @@ -27,11 +27,12 @@ export class WebGL2GFXCommandPool { this._freeIdx = count - 1; } + /* public alloc (clazz: new() => T): T { return new clazz(); } + */ - /* public alloc (clazz: new() => T): T { if (this._freeIdx < 0) { const size = this._frees.length * 2; @@ -55,7 +56,6 @@ export class WebGL2GFXCommandPool { ++cmd.refCount; return cmd; } - */ public free (cmd: T) { if (--cmd.refCount === 0) { @@ -64,7 +64,7 @@ export class WebGL2GFXCommandPool { } public freeCmds (cmds: CachedArray) { - return ; + // return ; for (let i = 0; i < cmds.length; ++i) { if (--cmds.array[i].refCount === 0) { this._freeCmds.push(cmds.array[i]); @@ -92,11 +92,11 @@ export class WebGL2GFXCommandAllocator extends GFXCommandAllocator { constructor (device: GFXDevice) { super(device); - this.beginRenderPassCmdPool = new WebGL2GFXCommandPool(WebGL2CmdBeginRenderPass, 16); - this.bindStatesCmdPool = new WebGL2GFXCommandPool(WebGL2CmdBindStates, 16); - this.drawCmdPool = new WebGL2GFXCommandPool(WebGL2CmdDraw, 16); - this.updateBufferCmdPool = new WebGL2GFXCommandPool(WebGL2CmdUpdateBuffer, 16); - this.copyBufferToTextureCmdPool = new WebGL2GFXCommandPool(WebGL2CmdCopyBufferToTexture, 16); + this.beginRenderPassCmdPool = new WebGL2GFXCommandPool(WebGL2CmdBeginRenderPass, 1); + this.bindStatesCmdPool = new WebGL2GFXCommandPool(WebGL2CmdBindStates, 1); + this.drawCmdPool = new WebGL2GFXCommandPool(WebGL2CmdDraw, 1); + this.updateBufferCmdPool = new WebGL2GFXCommandPool(WebGL2CmdUpdateBuffer, 1); + this.copyBufferToTextureCmdPool = new WebGL2GFXCommandPool(WebGL2CmdCopyBufferToTexture, 1); } public initialize (info: IGFXCommandAllocatorInfo): boolean {