Skip to content

Commit

Permalink
Remove unused code in gfx/base, gfx/webgl module and mangle propertie…
Browse files Browse the repository at this point in the history
…s to reduce js size.

Add WebGLConstants.ts for inlining enums. Depends on: cocos/cocos-ccbuild#65
  • Loading branch information
dumganhar committed Aug 12, 2024
1 parent 3b8a65e commit 8306c3a
Show file tree
Hide file tree
Showing 89 changed files with 4,835 additions and 4,824 deletions.
26 changes: 13 additions & 13 deletions cocos/gfx/base/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,52 +46,52 @@ export abstract class Buffer extends GFXObject {
* @zh 缓冲使用方式。
*/
get usage (): BufferUsage {
return this._usage;
return this._usage$;
}

/**
* @en Memory usage of the buffer.
* @zh 缓冲的内存使用方式。
*/
get memUsage (): MemoryUsage {
return this._memUsage;
return this._memUsage$;
}

/**
* @en Size of the buffer.
* @zh 缓冲大小。
*/
get size (): number {
return this._size;
return this._size$;
}

/**
* @en Stride of the buffer.
* @zh 缓冲步长。
*/
get stride (): number {
return this._stride;
return this._stride$;
}

/**
* @en Count of the buffer wrt. stride.
* @zh 缓冲条目数量。
*/
get count (): number {
return this._count;
return this._count$;
}

get flags (): BufferFlags {
return this._flags;
return this._flags$;
}

protected _usage: BufferUsage = BufferUsageBit.NONE;
protected _memUsage: MemoryUsage = MemoryUsageBit.NONE;
protected _size = 0;
protected _stride = 1;
protected _count = 0;
protected _flags: BufferFlags = BufferFlagBit.NONE;
protected _isBufferView = false;
protected _usage$: BufferUsage = BufferUsageBit.NONE;
protected _memUsage$: MemoryUsage = MemoryUsageBit.NONE;
protected _size$ = 0;
protected _stride$ = 1;
protected _count$ = 0;
protected _flags$: BufferFlags = BufferFlagBit.NONE;
protected _isBufferView$ = false;

constructor () {
super(ObjectType.BUFFER);
Expand Down
20 changes: 10 additions & 10 deletions cocos/gfx/base/command-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,46 @@ export abstract class CommandBuffer extends GFXObject {
* @zh 命令缓冲类型。
*/
get type (): CommandBufferType {
return this._type;
return this._type$;
}

/**
* @en Type of the command buffer.
* @zh 命令缓冲类型。
*/
get queue (): Queue {
return this._queue!;
return this._queue$!;
}

/**
* @en Number of draw calls currently recorded.
* @zh 绘制调用次数。
*/
get numDrawCalls (): number {
return this._numDrawCalls;
return this._numDrawCalls$;
}

/**
* @en Number of instances currently recorded.
* @zh 绘制 Instance 数量。
*/
get numInstances (): number {
return this._numInstances;
return this._numInstances$;
}

/**
* @en Number of triangles currently recorded.
* @zh 绘制三角形数量。
*/
get numTris (): number {
return this._numTris;
return this._numTris$;
}

protected _queue: Queue | null = null;
protected _type: CommandBufferType = CommandBufferType.PRIMARY;
protected _numDrawCalls = 0;
protected _numInstances = 0;
protected _numTris = 0;
protected _queue$: Queue | null = null;
protected _type$: CommandBufferType = CommandBufferType.PRIMARY;
protected _numDrawCalls$ = 0;
protected _numInstances$ = 0;
protected _numTris$ = 0;

constructor () {
super(ObjectType.COMMAND_BUFFER);
Expand Down
70 changes: 36 additions & 34 deletions cocos/gfx/base/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import { DescriptorSetLayout } from './descriptor-set-layout';

import { Sampler } from './states/sampler';
import { GeneralBarrier } from './states/general-barrier';
import { TextureBarrier } from './states/texture-barrier';
import { BufferBarrier } from './states/buffer-barrier';
import { GCObject } from '../../core';
import { GCObject } from '../../core/data/gc-object';

interface ICopyable { copy (info: ICopyable): ICopyable; }

Expand Down Expand Up @@ -1959,28 +1957,28 @@ export class DynamicStates {
*/
export class GFXObject extends GCObject {
public get objectType (): ObjectType {
return this._objectType;
return this._objectType$;
}

public get objectID (): number {
return this._objectID;
return this._objectID$;
}

public get typedID (): number {
return this._typedID;
return this._typedID$;
}

protected _objectType = ObjectType.UNKNOWN;
protected _objectID = 0;
protected _typedID = 0;
protected _objectType$ = ObjectType.UNKNOWN;
protected _objectID$ = 0;
protected _typedID$ = 0;

private static _idTable = Array(ObjectType.COUNT).fill(1 << 16);

constructor (objectType: ObjectType) {
super();
this._objectType = objectType;
this._objectID = GFXObject._idTable[ObjectType.UNKNOWN]++;
this._typedID = GFXObject._idTable[objectType]++;
this._objectType$ = objectType;
this._objectID$ = GFXObject._idTable[ObjectType.UNKNOWN]++;
this._typedID$ = GFXObject._idTable[objectType]++;
}
}

Expand Down Expand Up @@ -2163,6 +2161,10 @@ export function IsPowerOf2 (x: number): boolean {
return x > 0 && (x & (x - 1)) === 0;
}

function ceil (x: number): number {
return Math.ceil(x);
}

/**
* @en Get memory size of the specified fomat.
* @zh 获取指定格式对应的内存大小。
Expand All @@ -2180,7 +2182,7 @@ export function FormatSize (format: Format, width: number, height: number, depth
case Format.BC1_ALPHA:
case Format.BC1_SRGB:
case Format.BC1_SRGB_ALPHA:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
return ceil(width / 4) * ceil(height / 4) * 8 * depth;
case Format.BC2:
case Format.BC2_SRGB:
case Format.BC3:
Expand All @@ -2191,76 +2193,76 @@ export function FormatSize (format: Format, width: number, height: number, depth
case Format.BC6H_UF16:
case Format.BC7:
case Format.BC7_SRGB:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
return ceil(width / 4) * ceil(height / 4) * 16 * depth;
case Format.BC5:
case Format.BC5_SNORM:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 32 * depth;
return ceil(width / 4) * ceil(height / 4) * 32 * depth;

case Format.ETC_RGB8:
case Format.ETC2_RGB8:
case Format.ETC2_SRGB8:
case Format.ETC2_RGB8_A1:
case Format.EAC_R11:
case Format.EAC_R11SN:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
return ceil(width / 4) * ceil(height / 4) * 8 * depth;
case Format.ETC2_RGBA8:
case Format.ETC2_SRGB8_A1:
case Format.EAC_RG11:
case Format.EAC_RG11SN:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
return ceil(width / 4) * ceil(height / 4) * 16 * depth;

case Format.PVRTC_RGB2:
case Format.PVRTC_RGBA2:
case Format.PVRTC2_2BPP:
return Math.ceil(width / 8) * Math.ceil(height / 4) * 8 * depth;
return ceil(width / 8) * ceil(height / 4) * 8 * depth;

case Format.PVRTC_RGB4:
case Format.PVRTC_RGBA4:
case Format.PVRTC2_4BPP:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
return ceil(width / 4) * ceil(height / 4) * 8 * depth;

case Format.ASTC_RGBA_4X4:
case Format.ASTC_SRGBA_4X4:
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
return ceil(width / 4) * ceil(height / 4) * 16 * depth;
case Format.ASTC_RGBA_5X4:
case Format.ASTC_SRGBA_5X4:
return Math.ceil(width / 5) * Math.ceil(height / 4) * 16 * depth;
return ceil(width / 5) * ceil(height / 4) * 16 * depth;
case Format.ASTC_RGBA_5X5:
case Format.ASTC_SRGBA_5X5:
return Math.ceil(width / 5) * Math.ceil(height / 5) * 16 * depth;
return ceil(width / 5) * ceil(height / 5) * 16 * depth;
case Format.ASTC_RGBA_6X5:
case Format.ASTC_SRGBA_6X5:
return Math.ceil(width / 6) * Math.ceil(height / 5) * 16 * depth;
return ceil(width / 6) * ceil(height / 5) * 16 * depth;
case Format.ASTC_RGBA_6X6:
case Format.ASTC_SRGBA_6X6:
return Math.ceil(width / 6) * Math.ceil(height / 6) * 16 * depth;
return ceil(width / 6) * ceil(height / 6) * 16 * depth;
case Format.ASTC_RGBA_8X5:
case Format.ASTC_SRGBA_8X5:
return Math.ceil(width / 8) * Math.ceil(height / 5) * 16 * depth;
return ceil(width / 8) * ceil(height / 5) * 16 * depth;
case Format.ASTC_RGBA_8X6:
case Format.ASTC_SRGBA_8X6:
return Math.ceil(width / 8) * Math.ceil(height / 6) * 16 * depth;
return ceil(width / 8) * ceil(height / 6) * 16 * depth;
case Format.ASTC_RGBA_8X8:
case Format.ASTC_SRGBA_8X8:
return Math.ceil(width / 8) * Math.ceil(height / 8) * 16 * depth;
return ceil(width / 8) * ceil(height / 8) * 16 * depth;
case Format.ASTC_RGBA_10X5:
case Format.ASTC_SRGBA_10X5:
return Math.ceil(width / 10) * Math.ceil(height / 5) * 16 * depth;
return ceil(width / 10) * ceil(height / 5) * 16 * depth;
case Format.ASTC_RGBA_10X6:
case Format.ASTC_SRGBA_10X6:
return Math.ceil(width / 10) * Math.ceil(height / 6) * 16 * depth;
return ceil(width / 10) * ceil(height / 6) * 16 * depth;
case Format.ASTC_RGBA_10X8:
case Format.ASTC_SRGBA_10X8:
return Math.ceil(width / 10) * Math.ceil(height / 8) * 16 * depth;
return ceil(width / 10) * ceil(height / 8) * 16 * depth;
case Format.ASTC_RGBA_10X10:
case Format.ASTC_SRGBA_10X10:
return Math.ceil(width / 10) * Math.ceil(height / 10) * 16 * depth;
return ceil(width / 10) * ceil(height / 10) * 16 * depth;
case Format.ASTC_RGBA_12X10:
case Format.ASTC_SRGBA_12X10:
return Math.ceil(width / 12) * Math.ceil(height / 10) * 16 * depth;
return ceil(width / 12) * ceil(height / 10) * 16 * depth;
case Format.ASTC_RGBA_12X12:
case Format.ASTC_SRGBA_12X12:
return Math.ceil(width / 12) * Math.ceil(height / 12) * 16 * depth;
return ceil(width / 12) * ceil(height / 12) * 16 * depth;

default: {
return 0;
Expand Down Expand Up @@ -2471,7 +2473,7 @@ export function formatAlignment (format: Format): FormatAlignment {
}

export function alignTo (size: number, alignment: number): number {
return Math.ceil(size / alignment) * alignment;
return ceil(size / alignment) * alignment;
}

declare interface GPUTexture {}
Expand Down
12 changes: 6 additions & 6 deletions cocos/gfx/base/descriptor-set-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ import { GFXObject, ObjectType, DescriptorSetLayoutBinding, DescriptorSetLayoutI
*/
export abstract class DescriptorSetLayout extends GFXObject {
get bindings (): DescriptorSetLayoutBinding[] {
return this._bindings;
return this._bindings$;
}

get bindingIndices (): number[] {
return this._bindingIndices;
return this._bindingIndices$;
}

get descriptorIndices (): number[] {
return this._descriptorIndices;
return this._descriptorIndices$;
}

protected _bindings: DescriptorSetLayoutBinding[] = [];
protected _bindingIndices: number[] = [];
protected _descriptorIndices: number[] = [];
protected _bindings$: DescriptorSetLayoutBinding[] = [];
protected _bindingIndices$: number[] = [];
protected _descriptorIndices$: number[] = [];

constructor () {
super(ObjectType.DESCRIPTOR_SET_LAYOUT);
Expand Down
Loading

0 comments on commit 8306c3a

Please sign in to comment.