mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
add memory usage status to gfx (#4814)
This commit is contained in:
@@ -779,6 +779,11 @@ export interface IGFXFormatInfo {
|
||||
readonly isCompressed: boolean;
|
||||
}
|
||||
|
||||
export interface IGFXMemoryStatus {
|
||||
bufferSize: number;
|
||||
textureSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* GFX格式信息数组。
|
||||
*/
|
||||
|
||||
+13
-42
@@ -7,7 +7,7 @@ import { GFXBindingLayout, IGFXBindingLayoutInfo } from './binding-layout';
|
||||
import { GFXBuffer, IGFXBufferInfo } from './buffer';
|
||||
import { GFXCommandAllocator, IGFXCommandAllocatorInfo } from './command-allocator';
|
||||
import { GFXCommandBuffer, IGFXCommandBufferInfo } from './command-buffer';
|
||||
import { GFX_MAX_BUFFER_BINDINGS, GFXBufferTextureCopy, GFXFilter, GFXFormat, IGFXRect } from './define';
|
||||
import { GFX_MAX_BUFFER_BINDINGS, GFXBufferTextureCopy, GFXFilter, GFXFormat, IGFXRect, IGFXMemoryStatus } from './define';
|
||||
import { GFXFramebuffer, IGFXFramebufferInfo } from './framebuffer';
|
||||
import { GFXInputAssembler, IGFXInputAssemblerInfo } from './input-assembler';
|
||||
import { GFXPipelineLayout, IGFXPipelineLayoutInfo } from './pipeline-layout';
|
||||
@@ -290,78 +290,49 @@ export abstract class GFXDevice {
|
||||
return this._numTris;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 内存状态。
|
||||
*/
|
||||
public get memoryStatus (): IGFXMemoryStatus {
|
||||
return this._memoryStatus;
|
||||
}
|
||||
|
||||
protected _canvas: HTMLCanvasElement | null = null;
|
||||
|
||||
protected _canvas2D: HTMLCanvasElement | null = null;
|
||||
|
||||
protected _gfxAPI: GFXAPI = GFXAPI.UNKNOWN;
|
||||
protected _deviceName: string = '';
|
||||
|
||||
protected _renderer: string = '';
|
||||
|
||||
protected _vendor: string = '';
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 驱动版本。
|
||||
*/
|
||||
protected _version: string = '';
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 特性数组。
|
||||
*/
|
||||
protected _features: boolean[] = new Array<boolean>(GFXFeature.COUNT);
|
||||
|
||||
protected _queue: GFXQueue | null = null;
|
||||
|
||||
protected _devicePixelRatio: number = 1.0;
|
||||
|
||||
protected _width: number = 0;
|
||||
|
||||
protected _height: number = 0;
|
||||
|
||||
protected _nativeWidth: number = 0;
|
||||
|
||||
protected _nativeHeight: number = 0;
|
||||
|
||||
protected _mainWindow: GFXWindow | null = null;
|
||||
|
||||
protected _cmdAllocator: GFXCommandAllocator | null = null;
|
||||
|
||||
protected _maxVertexAttributes: number = 0;
|
||||
|
||||
protected _maxVertexUniformVectors: number = 0;
|
||||
|
||||
protected _maxFragmentUniformVectors: number = 0;
|
||||
|
||||
protected _maxTextureUnits: number = 0;
|
||||
|
||||
protected _maxVertexTextureUnits: number = 0;
|
||||
|
||||
protected _maxUniformBufferBindings: number = GFX_MAX_BUFFER_BINDINGS;
|
||||
|
||||
protected _maxUniformBlockSize: number = 0;
|
||||
|
||||
protected _depthBits: number = 0;
|
||||
|
||||
protected _stencilBits: number = 0;
|
||||
|
||||
protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN;
|
||||
|
||||
protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* Shader ID 生成标识。
|
||||
*/
|
||||
protected _shaderIdGen: number = 0;
|
||||
|
||||
protected _macros: Map<string, string> = new Map();
|
||||
|
||||
protected _numDrawCalls: number = 0;
|
||||
|
||||
protected _numTris: number = 0;
|
||||
protected _memoryStatus: IGFXMemoryStatus = {
|
||||
bufferSize: 0,
|
||||
textureSize: 0,
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh
|
||||
|
||||
@@ -58,6 +58,7 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
|
||||
WebGLCmdFuncCreateBuffer(this._device as WebGLGFXDevice, this._gpuBuffer);
|
||||
|
||||
this._device.memoryStatus.bufferSize += this._size;
|
||||
this._status = GFXStatus.SUCCESS;
|
||||
|
||||
return true;
|
||||
@@ -66,6 +67,7 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
public destroy () {
|
||||
if (this._gpuBuffer) {
|
||||
WebGLCmdFuncDestroyBuffer(this._device as WebGLGFXDevice, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= this._size;
|
||||
this._gpuBuffer = null;
|
||||
}
|
||||
|
||||
@@ -73,6 +75,7 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
}
|
||||
|
||||
public resize (size: number) {
|
||||
const oldSize = this._size;
|
||||
this._size = size;
|
||||
this._count = this._size / this._stride;
|
||||
|
||||
@@ -84,9 +87,12 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
if (this._uniformBuffer) {
|
||||
this._gpuBuffer.buffer = this._uniformBuffer;
|
||||
}
|
||||
|
||||
this._gpuBuffer.size = this._size;
|
||||
if (this._size > 0) {
|
||||
WebGLCmdFuncResizeBuffer(this._device as WebGLGFXDevice, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= oldSize;
|
||||
this._device.memoryStatus.bufferSize += this._size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
public blitFramebuffer (src: GFXFramebuffer, dst: GFXFramebuffer, srcRect: IGFXRect, dstRect: IGFXRect, filter: GFXFilter) {
|
||||
}
|
||||
|
||||
private initStates (gl: gl) {
|
||||
private initStates (gl: WebGLRenderingContext) {
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.pixelStorei(gl.PACK_ALIGNMENT, 1);
|
||||
|
||||
@@ -130,6 +130,7 @@ export class WebGLGFXTexture extends GFXTexture {
|
||||
|
||||
WebGLCmdFuncCreateTexture(this._device as WebGLGFXDevice, this._gpuTexture);
|
||||
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
this._status = GFXStatus.SUCCESS;
|
||||
|
||||
return true;
|
||||
@@ -138,12 +139,14 @@ export class WebGLGFXTexture extends GFXTexture {
|
||||
public destroy () {
|
||||
if (this._gpuTexture) {
|
||||
WebGLCmdFuncDestroyTexture(this._device as WebGLGFXDevice, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= this._size;
|
||||
this._gpuTexture = null;
|
||||
}
|
||||
this._status = GFXStatus.UNREADY;
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
const oldSize = this._size;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
this._size = GFXFormatSurfaceSize(this._format, this.width, this.height,
|
||||
@@ -154,6 +157,8 @@ export class WebGLGFXTexture extends GFXTexture {
|
||||
this._gpuTexture.height = this._height;
|
||||
this._gpuTexture.size = this._size;
|
||||
WebGLCmdFuncResizeTexture(this._device as WebGLGFXDevice, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= oldSize;
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
}
|
||||
this._status = GFXStatus.UNREADY;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export class WebGL2GFXBuffer extends GFXBuffer {
|
||||
|
||||
WebGL2CmdFuncCreateBuffer(this._device as WebGL2GFXDevice, this._gpuBuffer);
|
||||
|
||||
this._device.memoryStatus.bufferSize += this._size;
|
||||
this._status = GFXStatus.SUCCESS;
|
||||
|
||||
return true;
|
||||
@@ -61,6 +62,7 @@ export class WebGL2GFXBuffer extends GFXBuffer {
|
||||
public destroy () {
|
||||
if (this._gpuBuffer) {
|
||||
WebGL2CmdFuncDestroyBuffer(this._device as WebGL2GFXDevice, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= this._size;
|
||||
this._gpuBuffer = null;
|
||||
}
|
||||
|
||||
@@ -68,6 +70,7 @@ export class WebGL2GFXBuffer extends GFXBuffer {
|
||||
}
|
||||
|
||||
public resize (size: number) {
|
||||
const oldSize = this._size;
|
||||
this._size = size;
|
||||
this._count = this._size / this._stride;
|
||||
|
||||
@@ -75,6 +78,8 @@ export class WebGL2GFXBuffer extends GFXBuffer {
|
||||
this._gpuBuffer.size = this._size;
|
||||
if (this._size > 0) {
|
||||
WebGL2CmdFuncResizeBuffer(this._device as WebGL2GFXDevice, this._gpuBuffer);
|
||||
this._device.memoryStatus.bufferSize -= oldSize;
|
||||
this._device.memoryStatus.bufferSize += this._size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +129,7 @@ export class WebGL2GFXTexture extends GFXTexture {
|
||||
|
||||
WebGL2CmdFuncCreateTexture(this._device as WebGL2GFXDevice, this._gpuTexture);
|
||||
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
this._status = GFXStatus.SUCCESS;
|
||||
|
||||
return true;
|
||||
@@ -137,12 +138,14 @@ export class WebGL2GFXTexture extends GFXTexture {
|
||||
public destroy () {
|
||||
if (this._gpuTexture) {
|
||||
WebGL2CmdFuncDestroyTexture(this._device as WebGL2GFXDevice, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= this._size;
|
||||
this._gpuTexture = null;
|
||||
}
|
||||
this._status = GFXStatus.UNREADY;
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
const oldSize = this._size;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
this._size = GFXFormatSurfaceSize(this._format, this.width, this.height,
|
||||
@@ -153,6 +156,8 @@ export class WebGL2GFXTexture extends GFXTexture {
|
||||
this._gpuTexture.height = this._height;
|
||||
this._gpuTexture.size = this._size;
|
||||
WebGL2CmdFuncResizeTexture(this._device as WebGL2GFXDevice, this._gpuTexture);
|
||||
this._device.memoryStatus.textureSize -= oldSize;
|
||||
this._device.memoryStatus.textureSize += this._size;
|
||||
}
|
||||
this._status = GFXStatus.UNREADY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user