Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code in gfx/base, gfx/webgl module and mangle properties to reduce js size. #17529

Open
wants to merge 10 commits into
base: v3.8.5
Choose a base branch
from
24 changes: 24 additions & 0 deletions EngineErrorMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -3832,3 +3832,27 @@ ProgressBar FILLED mode only works when barSprite's Type is FILLED!
### 16398

ProgressBar non-FILLED mode only works when barSprite's Type is non-FILLED!

### 16399

CopyTextureToBuffers: not supported texture target.

### 16401

beginRenderPass: Only primary command buffer is supported.

### 16402

execute is not supported.

### 16403

GPU memory alias is not supported

### 16404

Block '%s' does not bound

### 16405

This device does not support WebGL2
15 changes: 12 additions & 3 deletions cocos/core/global-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,26 @@ const _global = typeof window === 'undefined' ? global : window;
* Cocos引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。
* @deprecated
*/
export const legacyCC: Record<string, any> & {
export const cclegacy: Record<string, any> & {
_global: typeof globalThis;
} = {
_global,
};

/**
* @en
* The main namespace of Cocos engine, all engine core classes, functions, properties and constants are defined in this namespace.
* @zh
* Cocos引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。
* @deprecated
*/
export const legacyCC = cclegacy;

// For internal usage
legacyCC.internal = {};
cclegacy.internal = {};

if (DEV) {
legacyCC._Test = {};
cclegacy._Test = {};
}

const engineVersion = '3.8.5';
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export * from './curves';
export * from './settings';
export * from './system';
export * from './algorithm';
export { legacyCC as cclegacy } from './global-exports';
export { cclegacy } from './global-exports';
export * from './curves/bezier';

// TODO: should not include engine internal exports when module mechanism is implemented.
Expand Down
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
68 changes: 34 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,8 @@ export function IsPowerOf2 (x: number): boolean {
return x > 0 && (x & (x - 1)) === 0;
}

const ceil = Math.ceil;

/**
* @en Get memory size of the specified fomat.
* @zh 获取指定格式对应的内存大小。
Expand All @@ -2180,7 +2180,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 +2191,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 +2471,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