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

Conversation

dumganhar
Copy link
Contributor

@dumganhar dumganhar commented Aug 12, 2024

Add WebGLConstants.ts for inlining enums. Depends on: cocos/cocos-ccbuild#65

After this changes, the package size could reduce 100KB.

gfx WebGL2 backend:187KB -> 103KB

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Greptile Summary

The pull request focuses on reducing JavaScript size by mangling property names and removing unused code in the gfx/base and gfx/webgl modules.

  • Property Renaming: Private properties across multiple files have been renamed by appending a $ symbol to their names (e.g., _layout to _layout$). This affects files like cocos/gfx/base/buffer.ts, cocos/gfx/base/command-buffer.ts, and others.
  • Import Path Updates: Import paths for functions like murmurhash2_32_gc have been updated to be more specific in files such as cocos/gfx/base/render-pass.ts.
  • New Utility Functions: Introduced a new ceil function in cocos/gfx/base/define.ts to replace multiple instances of Math.ceil.
  • Consistency Across Codebase: Ensured that all references to renamed properties are updated accordingly to prevent runtime errors.
  • No Functional Changes: The changes are syntactical and should not affect the runtime behavior or introduce new functionality.

@dumganhar dumganhar marked this pull request as draft August 12, 2024 09:22
Copy link

github-actions bot commented Aug 12, 2024

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -7969,10 +7969,10 @@
          */
         export class Sampler extends GFXObject {
             get info(): Readonly<SamplerInfo>;
             get hash(): number;
-            protected _info: SamplerInfo;
-            protected _hash: number;
+            protected _info$: SamplerInfo;
+            protected _hash$: number;
             constructor(info: Readonly<SamplerInfo>, hash: number);
             static computeHash(info: Readonly<SamplerInfo>): Filter;
             static unpackFromHash(hash: number): SamplerInfo;
         }
@@ -7999,13 +7999,13 @@
          * @zh GFX 描述符集组。
          */
         export abstract class DescriptorSet extends GFXObject {
             get layout(): DescriptorSetLayout;
-            protected _layout: DescriptorSetLayout | null;
-            protected _buffers: Buffer[];
-            protected _textures: Texture[];
-            protected _samplers: Sampler[];
-            protected _isDirty: boolean;
+            protected _layout$: DescriptorSetLayout | null;
+            protected _buffers$: Buffer[];
+            protected _textures$: Texture[];
+            protected _samplers$: Sampler[];
+            protected _isDirty$: boolean;
             constructor();
             abstract initialize(info: Readonly<DescriptorSetInfo>): void;
             abstract destroy(): void;
             abstract update(): void;
@@ -8079,15 +8079,15 @@
              * @zh 缓冲条目数量。
              */
             get count(): number;
             get flags(): BufferFlags;
-            protected _usage: BufferUsage;
-            protected _memUsage: MemoryUsage;
-            protected _size: number;
-            protected _stride: number;
-            protected _count: number;
-            protected _flags: BufferFlags;
-            protected _isBufferView: boolean;
+            protected _usage$: BufferUsage;
+            protected _memUsage$: MemoryUsage;
+            protected _size$: number;
+            protected _stride$: number;
+            protected _count$: number;
+            protected _flags$: BufferFlags;
+            protected _isBufferView$: boolean;
             constructor();
             abstract initialize(info: Readonly<BufferInfo> | Readonly<BufferViewInfo>): void;
             abstract destroy(): void;
             /**
@@ -8133,13 +8133,13 @@
              * @en Number of triangles currently recorded.
              * @zh 绘制三角形数量。
              */
             get numTris(): number;
-            protected _queue: Queue | null;
-            protected _type: CommandBufferType;
-            protected _numDrawCalls: number;
-            protected _numInstances: number;
-            protected _numTris: number;
+            protected _queue$: Queue | null;
+            protected _type$: CommandBufferType;
+            protected _numDrawCalls$: number;
+            protected _numInstances$: number;
+            protected _numTris$: number;
             constructor();
             abstract initialize(info: Readonly<CommandBufferInfo>): void;
             abstract destroy(): void;
             /**
@@ -9392,11 +9392,11 @@
         export class GFXObject extends __private._cocos_core_data_gc_object__GCObject {
             get objectType(): ObjectType;
             get objectID(): number;
             get typedID(): number;
-            protected _objectType: ObjectType;
-            protected _objectID: number;
-            protected _typedID: number;
+            protected _objectType$: ObjectType;
+            protected _objectID$: number;
+            protected _typedID$: number;
             constructor(objectType: ObjectType);
         }
         export interface ISwapchainTextureInfo {
             swapchain: Swapchain;
@@ -9501,26 +9501,26 @@
              * @en Current device binding mappings.
              * @zh 当前设备的绑定槽位映射关系。
              */
             get bindingMappingInfo(): BindingMappingInfo;
-            protected _gfxAPI: API;
-            protected _renderer: string;
-            protected _vendor: string;
-            protected _features: boolean[];
-            protected _formatFeatures: FormatFeatureBit[];
-            protected _queue: Queue | null;
-            protected _cmdBuff: CommandBuffer | null;
-            protected _numDrawCalls: number;
-            protected _numInstances: number;
-            protected _numTris: number;
-            protected _memoryStatus: MemoryStatus;
-            protected _caps: DeviceCaps;
-            protected _bindingMappingInfo: BindingMappingInfo;
-            protected _samplers: Map<number, Sampler>;
-            protected _generalBarrierss: Map<number, GeneralBarrier>;
-            protected _textureBarriers: Map<number, TextureBarrier>;
-            protected _bufferBarriers: Map<number, __private._cocos_gfx_base_states_buffer_barrier__BufferBarrier>;
-            protected _swapchainFormat: Format;
+            protected _gfxAPI$: API;
+            protected _renderer$: string;
+            protected _vendor$: string;
+            protected _features$: boolean[];
+            protected _formatFeatures$: FormatFeatureBit[];
+            protected _queue$: Queue | null;
+            protected _cmdBuff$: CommandBuffer | null;
+            protected _numDrawCalls$: number;
+            protected _numInstances$: number;
+            protected _numTris$: number;
+            protected _memoryStatus$: MemoryStatus;
+            protected _caps$: DeviceCaps;
+            protected _bindingMappingInfo$: BindingMappingInfo;
+            protected _samplers$: Map<number, Sampler>;
+            protected _generalBarrierss$: Map<number, GeneralBarrier>;
+            protected _textureBarriers$: Map<number, TextureBarrier>;
+            protected _bufferBarriers$: Map<number, __private._cocos_gfx_base_states_buffer_barrier__BufferBarrier>;
+            protected _swapchainFormat$: Format;
             static canvas: HTMLCanvasElement;
             abstract initialize(info: Readonly<DeviceInfo>): boolean | Promise<boolean>;
             abstract destroy(): void;
             /**
@@ -9721,11 +9721,11 @@
              */
             get surfaceTransform(): SurfaceTransform;
             get width(): number;
             get height(): number;
-            protected _transform: SurfaceTransform;
-            protected _colorTexture: Texture;
-            protected _depthStencilTexture: Texture;
+            protected _transform$: SurfaceTransform;
+            protected _colorTexture$: Texture;
+            protected _depthStencilTexture$: Texture;
             constructor();
             abstract initialize(info: Readonly<SwapchainInfo>): void;
             abstract resize(width: number, height: number, surfaceTransform: SurfaceTransform): void;
             abstract destroy(): void;
@@ -9752,13 +9752,13 @@
             get depthStencilTexture(): Texture | null;
             get width(): number;
             get height(): number;
             get needRebuild(): boolean;
-            protected _renderPass: RenderPass | null;
-            protected _colorTextures: (Texture | null)[];
-            protected _depthStencilTexture: Texture | null;
-            protected _width: number;
-            protected _height: number;
+            protected _renderPass$: RenderPass | null;
+            protected _colorTextures$: (Texture | null)[];
+            protected _depthStencilTexture$: Texture | null;
+            protected _width$: number;
+            protected _height$: number;
             constructor();
             abstract initialize(info: Readonly<FramebufferInfo>): void;
             abstract destroy(): void;
         }
@@ -9843,22 +9843,22 @@
              * @en get the draw range
              * @zh 获取渲染范围
              */
             get drawInfo(): DrawInfo;
-            protected _attributes: Attribute[];
-            protected _attributesHash: number;
-            protected _vertexBuffers: Buffer[];
-            protected _indexBuffer: Buffer | null;
-            protected _indirectBuffer: Buffer | null;
-            protected _drawInfo: DrawInfo;
+            protected _attributes$: Attribute[];
+            protected _attributesHash$: number;
+            protected _vertexBuffers$: Buffer[];
+            protected _indexBuffer$: Buffer | null;
+            protected _indirectBuffer$: Buffer | null;
+            protected _drawInfo$: DrawInfo;
             constructor();
             /**
              * @en Get the specified vertex buffer.
              * @zh 获取顶点缓冲。
              * @param stream The stream index of the vertex buffer.
              */
             getVertexBuffer(stream?: number): Buffer | null;
-            protected computeAttributesHash(): number;
+            protected computeAttributesHash$(): number;
             abstract initialize(info: Readonly<InputAssemblerInfo>): void;
             abstract destroy(): void;
         }
         /**
@@ -9868,11 +9868,11 @@
         export abstract class DescriptorSetLayout extends GFXObject {
             get bindings(): DescriptorSetLayoutBinding[];
             get bindingIndices(): number[];
             get descriptorIndices(): number[];
-            protected _bindings: DescriptorSetLayoutBinding[];
-            protected _bindingIndices: number[];
-            protected _descriptorIndices: number[];
+            protected _bindings$: DescriptorSetLayoutBinding[];
+            protected _bindingIndices$: number[];
+            protected _descriptorIndices$: number[];
             constructor();
             abstract initialize(info: Readonly<DescriptorSetLayoutInfo>): void;
             abstract destroy(): void;
         }
@@ -9881,9 +9881,9 @@
          * @zh GFX 管线布局。
          */
         export abstract class PipelineLayout extends GFXObject {
             get setLayouts(): DescriptorSetLayout[];
-            protected _setLayouts: DescriptorSetLayout[];
+            protected _setLayouts$: DescriptorSetLayout[];
             constructor();
             abstract initialize(info: Readonly<PipelineLayoutInfo>): void;
             abstract destroy(): void;
         }
@@ -10043,17 +10043,17 @@
              * @en Get current render pass.
              * @zh GFX 渲染过程。
              */
             get renderPass(): RenderPass;
-            protected _shader: Shader | null;
-            protected _pipelineLayout: PipelineLayout | null;
-            protected _primitive: PrimitiveMode;
-            protected _is: InputState | null;
-            protected _rs: RasterizerState;
-            protected _dss: DepthStencilState;
-            protected _bs: BlendState;
-            protected _dynamicStates: DynamicStateFlags;
-            protected _renderPass: RenderPass | null;
+            protected _shader$: Shader | null;
+            protected _pipelineLayout$: PipelineLayout | null;
+            protected _primitive$: PrimitiveMode;
+            protected _is$: InputState | null;
+            protected _rs$: RasterizerState;
+            protected _dss$: DepthStencilState;
+            protected _bs$: BlendState;
+            protected _dynamicStates$: DynamicStateFlags;
+            protected _renderPass$: RenderPass | null;
             constructor();
             abstract initialize(info: Readonly<PipelineStateInfo>): void;
             abstract destroy(): void;
         }
@@ -10066,9 +10066,9 @@
              * @en Get current type.
              * @zh 队列类型。
              */
             get type(): number;
-            protected _type: QueueType;
+            protected _type$: QueueType;
             constructor();
             abstract initialize(info: Readonly<QueueInfo>): void;
             abstract destroy(): void;
             /**
@@ -10083,12 +10083,12 @@
          * @en GFX render pass.
          * @zh GFX 渲染过程。
          */
         export abstract class RenderPass extends GFXObject {
-            protected _colorInfos: ColorAttachment[];
-            protected _depthStencilInfo: DepthStencilAttachment | null;
-            protected _subpasses: SubpassInfo[];
-            protected _hash: number;
+            protected _colorInfos$: ColorAttachment[];
+            protected _depthStencilInfo$: DepthStencilAttachment | null;
+            protected _subpasses$: SubpassInfo[];
+            protected _hash$: number;
             get colorAttachments(): Readonly<ColorAttachment[]>;
             get depthStencilAttachment(): Readonly<DepthStencilAttachment> | null;
             get subPasses(): Readonly<SubpassInfo[]>;
             get hash(): number;
@@ -10106,13 +10106,13 @@
             get attributes(): Attribute[];
             get blocks(): UniformBlock[];
             get samplers(): UniformSampler[];
             get stages(): ShaderStage[];
-            protected _name: string;
-            protected _stages: ShaderStage[];
-            protected _attributes: Attribute[];
-            protected _blocks: UniformBlock[];
-            protected _samplers: UniformSampler[];
+            protected _name$: string;
+            protected _stages$: ShaderStage[];
+            protected _attributes$: Attribute[];
+            protected _blocks$: UniformBlock[];
+            protected _samplers$: UniformSampler[];
             constructor();
             abstract initialize(info: Readonly<ShaderInfo>): void;
             abstract destroy(): void;
         }
@@ -10190,13 +10190,13 @@
              * @en Get texture type.
              * @zh 是否为纹理视图。
              */
             get isTextureView(): boolean;
-            protected _info: TextureInfo;
-            protected _viewInfo: TextureViewInfo;
-            protected _isPowerOf2: boolean;
-            protected _isTextureView: boolean;
-            protected _size: number;
+            protected _info$: TextureInfo;
+            protected _viewInfo$: TextureViewInfo;
+            protected _isPowerOf2$: boolean;
+            protected _isTextureView$: boolean;
+            protected _size$: number;
             constructor();
             abstract initialize(info: Readonly<TextureInfo> | Readonly<TextureViewInfo>): void;
             abstract destroy(): void;
             abstract getTextureHandle(): TextureHandle;
@@ -10215,10 +10215,10 @@
          */
         export class GeneralBarrier extends GFXObject {
             get info(): Readonly<GeneralBarrierInfo>;
             get hash(): number;
-            protected _info: GeneralBarrierInfo;
-            protected _hash: number;
+            protected _info$: GeneralBarrierInfo;
+            protected _hash$: number;
             constructor(info: Readonly<GeneralBarrierInfo>, hash: number);
             static computeHash(info: Readonly<GeneralBarrierInfo>): number;
         }
         /**
@@ -10227,10 +10227,10 @@
          */
         export class TextureBarrier extends GFXObject {
             get info(): Readonly<TextureBarrierInfo>;
             get hash(): number;
-            protected _info: TextureBarrierInfo;
-            protected _hash: number;
+            protected _info$: TextureBarrierInfo;
+            protected _hash$: number;
             constructor(info: Readonly<TextureBarrierInfo>, hash: number);
             static computeHash(info: Readonly<TextureBarrierInfo>): number;
         }
         /**
@@ -44511,9 +44511,9 @@
         get nullTexCube(): __private._cocos_gfx_webgl_webgl_texture__WebGLTexture;
         get textureExclusive(): boolean[];
         get bindingMappings(): __private._cocos_gfx_webgl_webgl_gpu_objects__IWebGLBindingMapping;
         get blitManager(): __private._cocos_gfx_webgl_webgl_gpu_objects__IWebGLBlitManager;
-        protected _textureExclusive: boolean[];
+        protected _textureExclusive$: boolean[];
         initialize(info: Readonly<gfx.DeviceInfo>): boolean;
         destroy(): void;
         flushCommands(cmdBuffs: gfx.CommandBuffer[]): void;
         acquire(swapchains: gfx.Swapchain[]): void;
@@ -44541,17 +44541,18 @@
         copyTextureToBuffers(texture: Readonly<gfx.Texture>, buffers: ArrayBufferView[], regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTexImagesToTexture(texImages: Readonly<TexImageSource[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
     }
     export class WebGL2Device extends gfx.Device {
+        constructor();
         get gl(): WebGL2RenderingContext;
         get extensions(): __private._cocos_gfx_webgl2_webgl2_define__IWebGL2Extensions;
-        get stateCache(): __private._cocos_gfx_webgl2_webgl2_state_cache__WebGL2StateCache;
+        getStateCache$(): __private._cocos_gfx_webgl2_webgl2_state_cache__WebGL2StateCache;
         get nullTex2D(): __private._cocos_gfx_webgl2_webgl2_texture__WebGL2Texture;
         get nullTexCube(): __private._cocos_gfx_webgl2_webgl2_texture__WebGL2Texture;
         get textureExclusive(): boolean[];
         get bindingMappings(): __private._cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2BindingMapping;
         get blitManager(): __private._cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2BlitManager | null;
-        protected _textureExclusive: boolean[];
+        protected _textureExclusive$: boolean[];
         initialize(info: Readonly<gfx.DeviceInfo>): boolean;
         destroy(): void;
         flushCommands(cmdBuffs: Readonly<gfx.CommandBuffer[]>): void;
         acquire(swapchains: Readonly<gfx.Swapchain[]>): void;
@@ -62388,10 +62389,10 @@
          */
         export class _cocos_gfx_base_states_buffer_barrier__BufferBarrier extends gfx.GFXObject {
             get info(): Readonly<gfx.BufferBarrierInfo>;
             get hash(): number;
-            protected _info: gfx.BufferBarrierInfo;
-            protected _hash: number;
+            protected _info$: gfx.BufferBarrierInfo;
+            protected _hash$: number;
             constructor(info: Readonly<gfx.BufferBarrierInfo>, hash: number);
             static computeHash(info: Readonly<gfx.BufferBarrierInfo>): number;
         }
         export type __types_globals__TypedArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor | Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
@@ -65969,87 +65970,87 @@
             readonly COMPRESSED_RGB_PVRTC_2BPPV1_IMG: GLenum;
             readonly COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: GLenum;
         }
         export interface _cocos_gfx_webgl_webgl_define__IWebGLExtensions {
-            EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null;
-            EXT_blend_minmax: EXT_blend_minmax | null;
-            EXT_frag_depth: EXT_frag_depth | null;
-            EXT_shader_texture_lod: EXT_shader_texture_lod | null;
-            EXT_sRGB: EXT_sRGB | null;
-            OES_vertex_array_object: OES_vertex_array_object | null;
-            EXT_color_buffer_half_float: __node_modules_typescript_lib_libdom__EXT_color_buffer_half_float | null;
-            WEBGL_multi_draw: __node_modules_typescript_lib_libdom__WEBGL_multi_draw | null;
-            WEBGL_color_buffer_float: WEBGL_color_buffer_float | null;
-            WEBGL_compressed_texture_etc1: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc1 | null;
-            WEBGL_compressed_texture_etc: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc | null;
-            WEBGL_compressed_texture_pvrtc: __types_webGLextras__WEBGL_compressed_texture_pvrtc | null;
-            WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null;
-            WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null;
-            WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null;
-            WEBGL_debug_shaders: WEBGL_debug_shaders | null;
-            WEBGL_draw_buffers: WEBGL_draw_buffers | null;
-            WEBGL_lose_context: WEBGL_lose_context | null;
-            WEBGL_depth_texture: WEBGL_depth_texture | null;
-            WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null;
-            OES_texture_half_float: OES_texture_half_float | null;
-            OES_texture_half_float_linear: OES_texture_half_float_linear | null;
-            OES_texture_float: OES_texture_float | null;
-            OES_texture_float_linear: OES_texture_float_linear | null;
-            OES_standard_derivatives: OES_standard_derivatives | null;
-            OES_element_index_uint: OES_element_index_uint | null;
-            ANGLE_instanced_arrays: ANGLE_instanced_arrays | null;
-            destroyShadersImmediately: boolean;
-            noCompressedTexSubImage2D: boolean;
-            isLocationActive: (glLoc: unknown) => glLoc is WebGLUniformLocation;
-            useVAO: boolean;
+            EXT_texture_filter_anisotropic$: EXT_texture_filter_anisotropic | null;
+            EXT_blend_minmax$: EXT_blend_minmax | null;
+            EXT_frag_depth$: EXT_frag_depth | null;
+            EXT_shader_texture_lod$: EXT_shader_texture_lod | null;
+            EXT_sRGB$: EXT_sRGB | null;
+            OES_vertex_array_object$: OES_vertex_array_object | null;
+            EXT_color_buffer_half_float$: __node_modules_typescript_lib_libdom__EXT_color_buffer_half_float | null;
+            WEBGL_multi_draw$: __node_modules_typescript_lib_libdom__WEBGL_multi_draw | null;
+            WEBGL_color_buffer_float$: WEBGL_color_buffer_float | null;
+            WEBGL_compressed_texture_etc1$: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc1 | null;
+            WEBGL_compressed_texture_etc$: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc | null;
+            WEBGL_compressed_texture_pvrtc$: __types_webGLextras__WEBGL_compressed_texture_pvrtc | null;
+            WEBGL_compressed_texture_astc$: WEBGL_compressed_texture_astc | null;
+            WEBGL_compressed_texture_s3tc$: WEBGL_compressed_texture_s3tc | null;
+            WEBGL_compressed_texture_s3tc_srgb$: WEBGL_compressed_texture_s3tc_srgb | null;
+            WEBGL_debug_shaders$: WEBGL_debug_shaders | null;
+            WEBGL_draw_buffers$: WEBGL_draw_buffers | null;
+            WEBGL_lose_context$: WEBGL_lose_context | null;
+            WEBGL_depth_texture$: WEBGL_depth_texture | null;
+            WEBGL_debug_renderer_info$: WEBGL_debug_renderer_info | null;
+            OES_texture_half_float$: OES_texture_half_float | null;
+            OES_texture_half_float_linear$: OES_texture_half_float_linear | null;
+            OES_texture_float$: OES_texture_float | null;
+            OES_texture_float_linear$: OES_texture_float_linear | null;
+            OES_standard_derivatives$: OES_standard_derivatives | null;
+            OES_element_index_uint$: OES_element_index_uint | null;
+            ANGLE_instanced_arrays$: ANGLE_instanced_arrays | null;
+            destroyShadersImmediately$: boolean;
+            noCompressedTexSubImage2D$: boolean;
+            isLocationActive$: (glLoc: unknown) => glLoc is WebGLUniformLocation;
+            useVAO$: boolean;
         }
         export interface _cocos_gfx_webgl_webgl_state_cache__IWebGLTexUnit {
-            glTexture: WebGLTexture | null;
+            glTexture$: WebGLTexture | null;
         }
         export class _cocos_gfx_webgl_webgl_state_cache__WebGLStateCache {
-            glArrayBuffer: WebGLBuffer | null;
-            glElementArrayBuffer: WebGLBuffer | null;
-            glVAO: WebGLVertexArrayObjectOES | null;
-            texUnit: number;
-            glTexUnits: _cocos_gfx_webgl_webgl_state_cache__IWebGLTexUnit[];
-            glRenderbuffer: WebGLRenderbuffer | null;
-            glFramebuffer: WebGLFramebuffer | null;
-            viewport: gfx.Viewport;
-            scissorRect: gfx.Rect;
-            rs: gfx.RasterizerState;
-            dss: gfx.DepthStencilState;
-            bs: gfx.BlendState;
-            glProgram: WebGLProgram | null;
-            glEnabledAttribLocs: boolean[];
-            glCurrentAttribLocs: boolean[];
-            texUnitCacheMap: Record<string, number>;
+            glArrayBuffer$: WebGLBuffer | null;
+            glElementArrayBuffer$: WebGLBuffer | null;
+            glVAO$: WebGLVertexArrayObjectOES | null;
+            texUnit$: number;
+            glTexUnits$: _cocos_gfx_webgl_webgl_state_cache__IWebGLTexUnit[];
+            glRenderbuffer$: WebGLRenderbuffer | null;
+            glFramebuffer$: WebGLFramebuffer | null;
+            viewport$: gfx.Viewport;
+            scissorRect$: gfx.Rect;
+            rs$: gfx.RasterizerState;
+            dss$: gfx.DepthStencilState;
+            bs$: gfx.BlendState;
+            glProgram$: WebGLProgram | null;
+            glEnabledAttribLocs$: boolean[];
+            glCurrentAttribLocs$: boolean[];
+            texUnitCacheMap$: Record<string, number>;
             initialize(texUnit: number, vertexAttributes: number): void;
         }
         export interface _cocos_gfx_webgl_webgl_gpu_objects__IWebGLGPUTexture {
-            type: gfx.TextureType;
-            format: gfx.Format;
-            usage: gfx.TextureUsage;
-            width: number;
-            height: number;
-            depth: number;
-            size: number;
-            arrayLayer: number;
-            mipLevel: number;
-            samples: gfx.SampleCount;
-            flags: gfx.TextureFlags;
-            isPowerOf2: boolean;
-            glTarget: GLenum;
-            glInternalFmt: GLenum;
-            glFormat: GLenum;
-            glType: GLenum;
-            glUsage: GLenum;
-            glTexture: WebGLTexture | null;
-            glRenderbuffer: WebGLRenderbuffer | null;
-            glWrapS: GLenum;
-            glWrapT: GLenum;
-            glMinFilter: GLenum;
-            glMagFilter: GLenum;
-            isSwapchainTexture: boolean;
+            type$: gfx.TextureType;
+            format$: gfx.Format;
+            usage$: gfx.TextureUsage;
+            width$: number;
+            height$: number;
+            depth$: number;
+            size$: number;
+            arrayLayer$: number;
+            mipLevel$: number;
+            samples$: gfx.SampleCount;
+            flags$: gfx.TextureFlags;
+            isPowerOf2$: boolean;
+            glTarget$: GLenum;
+            glInternalFmt$: GLenum;
+            glFormat$: GLenum;
+            glType$: GLenum;
+            glUsage$: GLenum;
+            glTexture$: WebGLTexture | null;
+            glRenderbuffer$: WebGLRenderbuffer | null;
+            glWrapS$: GLenum;
+            glWrapT$: GLenum;
+            glMinFilter$: GLenum;
+            glMagFilter$: GLenum;
+            isSwapchainTexture$: boolean;
         }
         export class _cocos_gfx_webgl_webgl_texture__WebGLTexture extends gfx.Texture {
             get gpuTexture(): _cocos_gfx_webgl_webgl_gpu_objects__IWebGLGPUTexture;
             get lodLevel(): number;
@@ -66059,11 +66060,11 @@
             getTextureHandle(): number;
             resize(width: number, height: number): void;
         }
         export interface _cocos_gfx_webgl_webgl_gpu_objects__IWebGLBindingMapping {
-            blockOffsets: number[];
-            samplerTextureOffsets: number[];
-            flexibleSet: number;
+            blockOffsets$: number[];
+            samplerTextureOffsets$: number[];
+            flexibleSet$: number;
         }
         export class _cocos_gfx_webgl_webgl_gpu_objects__IWebGLBlitManager {
             constructor();
             destroy(): void;
@@ -66073,103 +66074,105 @@
         }
         export interface __node_modules_typescript_lib_libdom__EXT_color_buffer_float {
         }
         export interface _cocos_gfx_webgl2_webgl2_define__IWebGL2Extensions {
-            EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null;
-            EXT_color_buffer_half_float: __node_modules_typescript_lib_libdom__EXT_color_buffer_half_float | null;
-            EXT_color_buffer_float: __node_modules_typescript_lib_libdom__EXT_color_buffer_float | null;
-            WEBGL_multi_draw: __node_modules_typescript_lib_libdom__WEBGL_multi_draw | null;
-            WEBGL_compressed_texture_etc1: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc1 | null;
-            WEBGL_compressed_texture_etc: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc | null;
-            WEBGL_compressed_texture_pvrtc: __types_webGLextras__WEBGL_compressed_texture_pvrtc | null;
-            WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null;
-            WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null;
-            WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null;
-            WEBGL_debug_shaders: WEBGL_debug_shaders | null;
-            WEBGL_lose_context: WEBGL_lose_context | null;
-            WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null;
-            OES_texture_half_float_linear: OES_texture_half_float_linear | null;
-            OES_texture_float_linear: OES_texture_float_linear | null;
-            useVAO: boolean;
+            EXT_texture_filter_anisotropic$: EXT_texture_filter_anisotropic | null;
+            EXT_color_buffer_half_float$: __node_modules_typescript_lib_libdom__EXT_color_buffer_half_float | null;
+            EXT_color_buffer_float$: __node_modules_typescript_lib_libdom__EXT_color_buffer_float | null;
+            WEBGL_multi_draw$: __node_modules_typescript_lib_libdom__WEBGL_multi_draw | null;
+            WEBGL_compressed_texture_etc1$: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc1 | null;
+            WEBGL_compressed_texture_etc$: __node_modules_typescript_lib_libdom__WEBGL_compressed_texture_etc | null;
+            WEBGL_compressed_texture_pvrtc$: __types_webGLextras__WEBGL_compressed_texture_pvrtc | null;
+            WEBGL_compressed_texture_astc$: WEBGL_compressed_texture_astc | null;
+            WEBGL_compressed_texture_s3tc$: WEBGL_compressed_texture_s3tc | null;
+            WEBGL_compressed_texture_s3tc_srgb$: WEBGL_compressed_texture_s3tc_srgb | null;
+            WEBGL_debug_shaders$: WEBGL_debug_shaders | null;
+            WEBGL_lose_context$: WEBGL_lose_context | null;
+            WEBGL_debug_renderer_info$: WEBGL_debug_renderer_info | null;
+            OES_texture_half_float_linear$: OES_texture_half_float_linear | null;
+            OES_texture_float_linear$: OES_texture_float_linear | null;
+            useVAO$: boolean;
         }
         export interface _cocos_gfx_webgl2_webgl2_state_cache__IWebGL2TexUnit {
-            glTexture: WebGLTexture | null;
+            glTexture$: WebGLTexture | null;
         }
         export class _cocos_gfx_webgl2_webgl2_state_cache__WebGL2StateCache {
-            glArrayBuffer: WebGLBuffer | null;
-            glElementArrayBuffer: WebGLBuffer | null;
-            glUniformBuffer: WebGLBuffer | null;
-            glBindUBOs: (WebGLBuffer | null)[];
-            glBindUBOOffsets: number[];
-            glVAO: WebGLVertexArrayObject | null;
-            texUnit: number;
-            glTexUnits: _cocos_gfx_webgl2_webgl2_state_cache__IWebGL2TexUnit[];
-            glSamplerUnits: (WebGLSampler | null)[];
-            glRenderbuffer: WebGLRenderbuffer | null;
-            glFramebuffer: WebGLFramebuffer | null;
-            glReadFramebuffer: WebGLFramebuffer | null;
-            viewport: gfx.Viewport;
-            scissorRect: gfx.Rect;
-            rs: gfx.RasterizerState;
-            dss: gfx.DepthStencilState;
-            bs: gfx.BlendState;
-            glProgram: WebGLProgram | null;
-            glEnabledAttribLocs: boolean[];
-            glCurrentAttribLocs: boolean[];
-            texUnitCacheMap: Record<string, number>;
+            glArrayBuffer$: WebGLBuffer | null;
+            glElementArrayBuffer$: WebGLBuffer | null;
+            glUniformBuffer$: WebGLBuffer | null;
+            glBindUBOs$: (WebGLBuffer | null)[];
+            glBindUBOOffsets$: number[];
+            glVAO$: WebGLVertexArrayObject | null;
+            texUnit$: number;
+            glTexUnits$: _cocos_gfx_webgl2_webgl2_state_cache__IWebGL2TexUnit[];
+            glSamplerUnits$: (WebGLSampler | null)[];
+            glRenderbuffer$: WebGLRenderbuffer | null;
+            glFramebuffer$: WebGLFramebuffer | null;
+            glReadFramebuffer$: WebGLFramebuffer | null;
+            viewport$: gfx.Viewport;
+            scissorRect$: gfx.Rect;
+            rs$: gfx.RasterizerState;
+            dss$: gfx.DepthStencilState;
+            bs$: gfx.BlendState;
+            glProgram$: WebGLProgram | null;
+            glEnabledAttribLocs$: boolean[];
+            glCurrentAttribLocs$: boolean[];
+            texUnitCacheMap$: Record<string, number>;
+            constructor();
             initialize(texUnit: number, bufferBindings: number, vertexAttributes: number): void;
         }
         export interface _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2GPUTexture {
-            type: gfx.TextureType;
-            format: gfx.Format;
-            usage: gfx.TextureUsage;
-            width: number;
-            height: number;
-            depth: number;
-            size: number;
-            arrayLayer: number;
-            mipLevel: number;
-            samples: gfx.SampleCount;
-            flags: gfx.TextureFlags;
-            isPowerOf2: boolean;
-            glTarget: GLenum;
-            glInternalFmt: GLenum;
-            glFormat: GLenum;
-            glType: GLenum;
-            glUsage: GLenum;
-            glTexture: WebGLTexture | null;
-            glRenderbuffer: WebGLRenderbuffer | null;
-            glWrapS: GLenum;
-            glWrapT: GLenum;
-            glMinFilter: GLenum;
-            glMagFilter: GLenum;
-            isSwapchainTexture: boolean;
+            type$: gfx.TextureType;
+            format$: gfx.Format;
+            usage$: gfx.TextureUsage;
+            width$: number;
+            height$: number;
+            depth$: number;
+            size$: number;
+            arrayLayer$: number;
+            mipLevel$: number;
+            samples$: gfx.SampleCount;
+            flags$: gfx.TextureFlags;
+            isPowerOf2$: boolean;
+            glTarget$: GLenum;
+            glInternalFmt$: GLenum;
+            glFormat$: GLenum;
+            glType$: GLenum;
+            glUsage$: GLenum;
+            glTexture$: WebGLTexture | null;
+            glRenderbuffer$: WebGLRenderbuffer | null;
+            glWrapS$: GLenum;
+            glWrapT$: GLenum;
+            glMinFilter$: GLenum;
+            glMagFilter$: GLenum;
+            isSwapchainTexture$: boolean;
         }
         export interface _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2GPUTextureView {
-            gpuTexture: _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2GPUTexture;
-            type: gfx.TextureType;
-            format: gfx.Format;
-            baseLevel: number;
-            levelCount: number;
+            gpuTexture$: _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2GPUTexture;
+            type$: gfx.TextureType;
+            format$: gfx.Format;
+            baseLevel$: number;
+            levelCount$: number;
         }
         export class _cocos_gfx_webgl2_webgl2_texture__WebGL2Texture extends gfx.Texture {
+            constructor();
             get gpuTexture(): _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2GPUTexture;
             get gpuTextureView(): _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2GPUTextureView;
             initialize(info: Readonly<gfx.TextureInfo> | Readonly<gfx.TextureViewInfo>, isSwapchainTexture?: boolean): void;
             destroy(): void;
             getTextureHandle(): number;
             resize(width: number, height: number): void;
         }
         export interface _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2BindingMapping {
-            blockOffsets: number[];
-            samplerTextureOffsets: number[];
-            flexibleSet: number;
+            blockOffsets$: number[];
+            samplerTextureOffsets$: number[];
+            flexibleSet$: number;
         }
         export class _cocos_gfx_webgl2_webgl2_gpu_objects__IWebGL2BlitManager {
             get srcFramebuffer(): WebGLFramebuffer | null;
             get dstFramebuffer(): WebGLFramebuffer | null;
             constructor();
-            destroy(): void;
+            destroy$(): void;
         }
         export interface _cocos_gfx_webgpu_webgpu_gpu_objects__IWebGPUBindingMapping {
             blockOffsets: number[];
             samplerTextureOffsets: number[];

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

30 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

cocos/gfx/base/define.ts Outdated Show resolved Hide resolved
@dumganhar dumganhar changed the base branch from v3.8.4 to v3.8.5 September 6, 2024 07:32
@dumganhar
Copy link
Contributor Author

dumganhar commented Sep 6, 2024

TODO:

  • gfx-webgl2 is also needed to optimized.
  • Need to check whether source map works.

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

Copy link

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL Hexa,puzzle,shield-node,graphics-draw-before-init
ios PASS PASS FAIL Hexa,puzzle,shield-node
mac PASS PASS FAIL Hexa,puzzle,shield-node

Copy link

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS FAIL Hexa,puzzle,shield-node
android PASS PASS FAIL Hexa,puzzle,shield-node
wechatgame PASS PASS FAIL Hexa,puzzle,shield-node

@dumganhar dumganhar marked this pull request as ready for review September 24, 2024 02:10
…85-reduce-gfx-code

# Conflicts:
#	cocos/gfx/webgl/webgl-commands.ts
#	cocos/gfx/webgl2/webgl2-commands.ts
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@@ -0,0 +1,562 @@
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
export enum WebGLConstants {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this gl-constants.ts file for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use const enum, since these values will never be changed.

Copy link
Contributor Author

@dumganhar dumganhar Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, both enum and const enum will be inlined since I wrote a custom babel plugin in ccbuild.
I remember that I got same errors when using const enum.
It seems that we could use const enum here, but could not use const enum for the exported type since that will break compatibility.

What is this gl-constants.ts file for?
The default WebGL constants is not enum which will not be inlined. So I add this file to inline the enums.
For example:

//libdom.d.ts
interface WEBGL_color_buffer_float {
    readonly RGBA32F_EXT: 0x8814;
    readonly FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: 0x8211;
    readonly UNSIGNED_NORMALIZED_EXT: 0x8C17;
}

Copy link

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL SpineMesh,Hexa,puzzle,shield-node
ios PASS PASS FAIL SpineMesh,Hexa,puzzle,shield-node
mac PASS PASS FAIL SpineMesh,Hexa,puzzle,shield-node

Copy link

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
windows PASS PASS FAIL SpineMesh,Hexa,puzzle,shield-node
android PASS PASS FAIL Hexa,puzzle,shield-node
wechatgame PASS PASS FAIL SpineMesh,Hexa,puzzle,shield-node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants