Skip to content

Commit

Permalink
Some changes to make new inline enum & mangle properties work as expect.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Dec 27, 2024
1 parent a25fafa commit 2172937
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cocos/2d/renderer/batcher-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ class LocalDescriptorSet {
this._samplerHash = batch.samplerHash;
_dsInfo.layout = batch.passes[0].localSetLayout;
this._descriptorSet = device.createDescriptorSet(_dsInfo);
this._descriptorSet.bindBuffer(UBOLocal.BINDING, this._localBuffer!);
this._descriptorSet.bindBuffer(UBOLocalEnum.BINDING, this._localBuffer!);
const binding = ModelLocalBindings.SAMPLER_SPRITE;
this._descriptorSet.bindTexture(binding, batch.texture!);
this._descriptorSet.bindSampler(binding, batch.sampler!);
Expand Down
1 change: 0 additions & 1 deletion cocos/2d/renderer/native-2d-empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
THE SOFTWARE.
*/


export const NativeRenderDrawInfo = undefined;
export const NativeBatcher2d = undefined;
export const NativeUIMeshBuffer = undefined;
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/event/eventify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export interface IEventified {
*/
export function Eventify<TBase> (base: Constructor<TBase>): Constructor<TBase & IEventified> {
class Eventified extends (base as unknown as any) {
private _callbackTable = createMap(true);
protected _callbackTable = createMap(true);

public once<Callback extends (...any) => void> (type: EventType, callback: Callback, target?: any): Callback {
return this.on(type, callback, target, true) as Callback;
Expand Down
16 changes: 8 additions & 8 deletions cocos/gfx/webgl/webgl-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,12 +1194,12 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
binding: glLoc,
name: varName,
type: gfxType,
stride: stride,
stride,
count: attribSize,
size: stride * attribSize,

glType: attribType,
glLoc: glLoc,
glLoc,
};
}
}
Expand Down Expand Up @@ -1231,12 +1231,12 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
binding: -1,
name: uniform.name,
type: uniform.type,
stride: stride,
stride,
count: uniform.count,
size: size,
size,
offset: 0,

glType: glType,
glType,
glLoc: null!,
array: null!,
};
Expand Down Expand Up @@ -1479,8 +1479,8 @@ export function WebGLCmdFuncCreateInputAssember (device: WebGLDevice, gpuInputAs
gpuInputAssembler.glAttribs[i] = {
name: attrib.name,
glBuffer: gpuBuffer.glBuffer,
glType: glType,
size: size,
glType,
size,
count: FormatInfos[attribFormat].count,
stride: gpuBuffer.stride,
componentCount: WebGLGetComponentCount(glType, gl),
Expand Down Expand Up @@ -2450,7 +2450,7 @@ export function WebGLCmdFuncBindStates (
export function WebGLCmdFuncDraw (device: WebGLDevice, drawInfo: Readonly<DrawInfo>): void {
const { gl } = device;
const { ANGLE_instanced_arrays: ia, WEBGL_multi_draw: md } = device.extensions;
const { gpuInputAssembler: gpuInputAssembler, glPrimitive: glPrimitive } = gfxStateCache;
const { gpuInputAssembler, glPrimitive } = gfxStateCache;

if (gpuInputAssembler) {
const indexBuffer = gpuInputAssembler.gpuIndexBuffer;
Expand Down
5 changes: 3 additions & 2 deletions cocos/gfx/webgl/webgl-descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ export class WebGLDescriptorSet extends DescriptorSet {
for (let i = 0; i < bindings.length; ++i) {
const binding = bindings[i];
for (let j = 0; j < binding.count; j++) {
gpuDescriptors.push({
const gpuDescriptor: IWebGLGPUDescriptor = {
type: binding.descriptorType,
gpuBuffer: null,
gpuTexture: null,
gpuSampler: null,
});
};
gpuDescriptors.push(gpuDescriptor);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/gfx/webgl/webgl-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export class WebGLDevice extends Device {
samplerTextureOffsets[curSet] -= mapping.maxBlockCounts[curSet];
}
this._bindingMappings = {
blockOffsets: blockOffsets,
samplerTextureOffsets: samplerTextureOffsets,
blockOffsets,
samplerTextureOffsets,
flexibleSet: mapping.setIndices[mapping.setIndices.length - 1],
};

Expand Down
6 changes: 5 additions & 1 deletion cocos/gfx/webgl/webgl-state-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IWebGLTexUnit {
glTexture: WebGLTexture | null;
}

/** @mangle */
export class WebGLStateCache {
public glArrayBuffer: WebGLBuffer | null = null;
public glElementArrayBuffer: WebGLBuffer | null = null;
Expand All @@ -48,7 +49,10 @@ export class WebGLStateCache {
public texUnitCacheMap: Record<string, number> = {};

initialize (texUnit: number, vertexAttributes: number): void {
for (let i = 0; i < texUnit; ++i) this.glTexUnits.push({ glTexture: null });
for (let i = 0; i < texUnit; ++i) {
const glTexUnit: IWebGLTexUnit = { glTexture: null };
this.glTexUnits.push(glTexUnit);
}

this.glEnabledAttribLocs.length = vertexAttributes;
this.glEnabledAttribLocs.fill(false);
Expand Down
14 changes: 7 additions & 7 deletions cocos/gfx/webgl2/webgl2-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ export function WebGL2CmdFuncDestroyTexture (device: WebGL2Device, gpuTexture: I
}

if (gpuTexture.glRenderbuffer) {
let glRenderbuffer = cache.glRenderbuffer;
const glRenderbuffer = cache.glRenderbuffer;
gl.deleteRenderbuffer(gpuTexture.glRenderbuffer);
if (glRenderbuffer === gpuTexture.glRenderbuffer) {
gl.bindRenderbuffer(WebGLConstants.RENDERBUFFER, null);
Expand Down Expand Up @@ -1551,13 +1551,13 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb

gpuShader.glInputs[i] = {
name: varName,
type: type,
stride: stride,
type,
stride,
count: attribInfo.size,
size: stride * attribInfo.size,

glType: attribInfo.type,
glLoc: glLoc,
glLoc,
};
}
}
Expand Down Expand Up @@ -1607,7 +1607,7 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb
idx: blockIdx,
name: blockName,
size: blockSize,
glBinding: glBinding,
glBinding,
};
}
}
Expand Down Expand Up @@ -1776,8 +1776,8 @@ export function WebGL2CmdFuncCreateInputAssember (device: WebGL2Device, gpuInput
gpuInputAssembler.glAttribs[i] = {
name: attrib.name,
glBuffer: gpuBuffer.glBuffer,
glType: glType,
size: size,
glType,
size,
count: FormatInfos[attrib.format].count,
stride: gpuBuffer.stride,
componentCount: WebGLGetComponentCount(glType, gl),
Expand Down
4 changes: 2 additions & 2 deletions cocos/render-scene/scene/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1278,11 +1278,11 @@ export class Model {
}

protected _updateLocalDescriptors (subModelIndex: number, descriptorSet: DescriptorSet): void {
if (this._localBuffer) descriptorSet.bindBuffer(UBOLocal.BINDING, this._localBuffer);
if (this._localBuffer) descriptorSet.bindBuffer(UBOLocalEnum.BINDING, this._localBuffer);
}

protected _updateLocalSHDescriptors (subModelIndex: number, descriptorSet: DescriptorSet): void {
if (this._localSHBuffer) descriptorSet.bindBuffer(UBOSH.BINDING, this._localSHBuffer);
if (this._localSHBuffer) descriptorSet.bindBuffer(UBOSHEnum.BINDING, this._localSHBuffer);
}

protected _updateWorldBoundDescriptors (subModelIndex: number, descriptorSet: DescriptorSet): void {
Expand Down
2 changes: 1 addition & 1 deletion cocos/rendering/deferred/lighting-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class LightingStage extends RenderStage {
UBOLocalEnum.SIZE,
UBOLocalEnum.SIZE,
));
this._descriptorSet.bindBuffer(UBOLocal.BINDING, _localUBO);
this._descriptorSet.bindBuffer(UBOLocalEnum.BINDING, _localUBO);
}

public activate (pipeline: DeferredPipeline, flow: MainFlow): void {
Expand Down
10 changes: 5 additions & 5 deletions cocos/rendering/deferred/postprocess-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/
import { ccclass, displayOrder, type, serializable } from 'cc.decorator';
import { Camera } from '../../render-scene/scene';
import { SetIndex, UBOLocal, UBOLocalEnum } from '../define';
import { Color, Rect, PipelineState, ClearFlagBit, DescriptorSetInfo, BufferInfo, BufferUsageBit, MemoryUsageBit } from '../../gfx';
import { SetIndex, UBOLocalEnum } from '../define';
import { Color, Rect, PipelineState, ClearFlagBit, DescriptorSetInfo, BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet, Buffer } from '../../gfx';

Check warning on line 32 in cocos/rendering/deferred/postprocess-stage.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 155. Maximum allowed is 150
import { IRenderStageInfo, RenderStage } from '../render-stage';
import { CommonStagePriority } from '../enum';
import { Material } from '../../asset/assets/material';
Expand Down Expand Up @@ -67,8 +67,8 @@ export class PostProcessStage extends RenderStage {

private _renderArea = new Rect();
private declare _uiPhase: UIPhase;
private _stageDesc;
private _localUBO;
private _stageDesc: DescriptorSet | null = null;
private _localUBO: Buffer | null = null;
constructor () {
super();
this._uiPhase = new UIPhase();
Expand Down Expand Up @@ -149,7 +149,7 @@ export class PostProcessStage extends RenderStage {
UBOLocalEnum.SIZE,
UBOLocalEnum.SIZE,
));
this._stageDesc.bindBuffer(UBOLocal.BINDING, this._localUBO);
this._stageDesc.bindBuffer(UBOLocalEnum.BINDING, this._localUBO);
}
this._stageDesc.update();
cmdBuff.bindPipelineState(pso);
Expand Down
16 changes: 9 additions & 7 deletions cocos/rendering/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export enum UBOLocalEnum {
REFLECTION_PROBE_BLEND_DATA2 = REFLECTION_PROBE_BLEND_DATA1 + 4,
COUNT = REFLECTION_PROBE_BLEND_DATA2 + 4,
SIZE = COUNT * 4,
BINDING = ModelLocalBindings.UBO_LOCAL,
}

/**
Expand All @@ -468,9 +469,9 @@ export class UBOLocal {
public static readonly SIZE = UBOLocalEnum.SIZE;

public static readonly NAME = 'CCLocal';
public static readonly BINDING = ModelLocalBindings.UBO_LOCAL;
public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOLocal.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.VERTEX | ShaderStageFlagBit.FRAGMENT | ShaderStageFlagBit.COMPUTE);
public static readonly LAYOUT = new UniformBlock(SetIndex.LOCAL, UBOLocal.BINDING, UBOLocal.NAME, [
public static readonly BINDING = UBOLocalEnum.BINDING;
public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOLocalEnum.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.VERTEX | ShaderStageFlagBit.FRAGMENT | ShaderStageFlagBit.COMPUTE);
public static readonly LAYOUT = new UniformBlock(SetIndex.LOCAL, UBOLocalEnum.BINDING, UBOLocal.NAME, [
new Uniform('cc_matWorld', Type.MAT4, 1),
new Uniform('cc_matWorldIT', Type.MAT4, 1),
new Uniform('cc_lightingMapUVParam', Type.FLOAT4, 1),
Expand All @@ -482,7 +483,7 @@ export class UBOLocal {
], 1);
}
localDescriptorSetLayout.layouts[UBOLocal.NAME] = UBOLocal.LAYOUT;
localDescriptorSetLayout.bindings[UBOLocal.BINDING] = UBOLocal.DESCRIPTOR;
localDescriptorSetLayout.bindings[UBOLocalEnum.BINDING] = UBOLocal.DESCRIPTOR;

/**
* @en The world bound uniform buffer object
Expand Down Expand Up @@ -696,6 +697,7 @@ export enum UBOSHEnum {
SH_QUADRATIC_A_OFFSET = SH_QUADRATIC_B_OFFSET + 4,
COUNT = SH_QUADRATIC_A_OFFSET + 4,
SIZE = COUNT * 4,
BINDING = ModelLocalBindings.UBO_SH,
}

/**
Expand All @@ -715,8 +717,8 @@ export class UBOSH {

public static readonly NAME = 'CCSH';
public static readonly BINDING = ModelLocalBindings.UBO_SH;
public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOSH.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.FRAGMENT);
public static readonly LAYOUT = new UniformBlock(SetIndex.LOCAL, UBOSH.BINDING, UBOSH.NAME, [
public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOSHEnum.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.FRAGMENT);
public static readonly LAYOUT = new UniformBlock(SetIndex.LOCAL, UBOSHEnum.BINDING, UBOSH.NAME, [
new Uniform('cc_sh_linear_const_r', Type.FLOAT4, 1),
new Uniform('cc_sh_linear_const_g', Type.FLOAT4, 1),
new Uniform('cc_sh_linear_const_b', Type.FLOAT4, 1),
Expand All @@ -727,7 +729,7 @@ export class UBOSH {
], 1);
}
localDescriptorSetLayout.layouts[UBOSH.NAME] = UBOSH.LAYOUT;
localDescriptorSetLayout.bindings[UBOSH.BINDING] = UBOSH.DESCRIPTOR;
localDescriptorSetLayout.bindings[UBOSHEnum.BINDING] = UBOSH.DESCRIPTOR;

/**
* @en The sampler for joint texture
Expand Down
2 changes: 1 addition & 1 deletion cocos/scene-graph/prefab/prefab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class Prefab extends Asset {
return this._createFunction!(rootToRedirect); // this.data._instantiate();
}

private _instantiate (): Node {
protected _instantiate (): Node {
let node: Node;
let useJit = false;
if (SUPPORT_JIT) {
Expand Down
24 changes: 14 additions & 10 deletions cocos/serialization/instantiate-jit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,23 @@ function writeAssignment (codeArray, statement, expression): void {
// -> 't.foo1 = bar1;'
// -> 't.foo2 = bar2;'
class Assignments {
public static pool: js.Pool<{}>;
public static pool: js.Pool<Assignments> = new js.Pool((obj: Assignments) => {
obj._exps.length = 0;
obj._targetExp = null;
}, 1);

private declare _exps: any[];
private declare _targetExp: any;

constructor (targetExpression?) {
constructor (targetExpression?: any) {
this._exps = [];
this._targetExp = targetExpression;
}

setTargetExp (value: any): void {
this._targetExp = value;
}

public append (key, expression): void {
this._exps.push([key, expression]);
}
Expand All @@ -130,15 +138,11 @@ class Assignments {
}
}

Assignments.pool = new js.Pool((obj: any) => {
obj._exps.length = 0;
obj._targetExp = null;
}, 1);
// HACK: here we've changed the signature of get method
(Assignments.pool.get as any) = function (this: any, targetExpression): Assignments {
const cache: any = this._get() || new Assignments();
cache._targetExp = targetExpression;
return cache as Assignments;
(Assignments.pool.get as any) = function get (this: js.Pool<Assignments>, targetExpression: any): Assignments {
const cache: Assignments = this._get() || new Assignments();
cache.setTargetExp(targetExpression);
return cache;
};

// HELPER FUNCTIONS
Expand Down

0 comments on commit 2172937

Please sign in to comment.