Skip to content

Commit

Permalink
Optimize Ubo
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS committed Oct 16, 2024
1 parent 1b90117 commit 428fa25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 36 deletions.
8 changes: 2 additions & 6 deletions cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,12 @@ function updateDefaultConstantBlock (blockId: number, sceneId: number, idxRD: nu
}

export function updatePerPassUBO (layout: string, sceneId: number, idxRD: number, user: RenderData): void {
const constantMap = user.constants;
const samplers = user.samplers;
const textures = user.textures;
const buffers = user.buffers;
const { constants, samplers, textures, buffers } = user;
const webPip = cclegacy.director.root.pipeline as WebPipeline;
const lg = webPip.layoutGraph;
const descriptorSetData = getDescriptorSetDataFromLayout(layout)!;
currBindBuffs.clear();
for (const [key, data] of constantMap) {
for (const [key, data] of constants) {
let constantBlock = constantBlockMap.get(key);
if (!constantBlock) {
const currMemKey = Array.from(lg.constantIndex).find(([_, v]) => v === key)![0];
Expand Down Expand Up @@ -683,7 +680,6 @@ export function updatePerPassUBO (layout: string, sceneId: number, idxRD: number
bindGlobalDesc(descriptorSet, bindId, value);
}
}
descriptorSet.update();
}

export function hashCombineKey (val): string {
Expand Down
39 changes: 9 additions & 30 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ class DeviceComputeQueue implements RecordingInterface {
private _renderPhase: RenderPhaseData | null = null;
private _descSetData: DescriptorSetData | null = null;
private _layoutID = -1;
private _isUpdateUBO = false;
private _isUploadInstance = false;
private _isUploadBatched = false;
private _queueId = -1;
Expand All @@ -551,15 +550,12 @@ class DeviceComputeQueue implements RecordingInterface {
get renderPhase (): RenderPhaseData | null { return this._renderPhase; }
set queueId (val) { this._queueId = val; }
get queueId (): number { return this._queueId; }
set isUpdateUBO (update: boolean) { this._isUpdateUBO = update; }
get isUpdateUBO (): boolean { return this._isUpdateUBO; }
set isUploadInstance (value: boolean) { this._isUploadInstance = value; }
get isUploadInstance (): boolean { return this._isUploadInstance; }
set isUploadBatched (value: boolean) { this._isUploadBatched = value; }
get isUploadBatched (): boolean { return this._isUploadBatched; }

reset (): void {
this._isUpdateUBO = false;
this._isUploadInstance = false;
this._isUploadBatched = false;
}
Expand All @@ -586,7 +582,6 @@ class DeviceRenderQueue implements RecordingInterface {
private _viewport: Viewport | null = null;
private _scissor: Rect | null = null;
private _layoutID = -1;
private _isUpdateUBO = false;
private _isUploadInstance = false;
private _isUploadBatched = false;
get phaseID (): number { return this._phaseID; }
Expand All @@ -608,8 +603,6 @@ class DeviceRenderQueue implements RecordingInterface {
private _queueId = -1;
set queueId (val) { this._queueId = val; }
get queueId (): number { return this._queueId; }
set isUpdateUBO (update: boolean) { this._isUpdateUBO = update; }
get isUpdateUBO (): boolean { return this._isUpdateUBO; }
set isUploadInstance (value: boolean) { this._isUploadInstance = value; }
get isUploadInstance (): boolean { return this._isUploadInstance; }
set isUploadBatched (value: boolean) { this._isUploadBatched = value; }
Expand Down Expand Up @@ -642,7 +635,6 @@ class DeviceRenderQueue implements RecordingInterface {
}
reset (): void {
this._renderScenes.length = 0;
this._isUpdateUBO = false;
this._isUploadInstance = false;
this._isUploadBatched = false;
this._blitDesc?.reset();
Expand Down Expand Up @@ -743,7 +735,7 @@ const renderPassArea = new Rect();
const resourceVisitor = new ResourceVisitor();
class DeviceRenderPass implements RecordingInterface {
protected _renderPass: RenderPass;
protected _framebuffer: Framebuffer;
protected _framebuffer!: Framebuffer;
protected _clearColor: Color[] = [];
protected _deviceQueues: Map<number, DeviceRenderQueue> = new Map();
protected _clearDepth = 1;
Expand Down Expand Up @@ -1227,18 +1219,6 @@ class DeviceRenderScene implements RecordingInterface {
}

protected _recordUI (): void {
const devicePass = this._currentQueue.devicePass;
const rasterId = devicePass.rasterID;
const passRenderData = context.renderGraph.getData(rasterId);
// RasterPass first
this._updateGlobal(passRenderData, this.sceneID);
// then Queue
const queueId = this._currentQueue.queueId;
const queueRenderData = context.renderGraph.getData(queueId)!;
this._updateGlobal(queueRenderData, this.sceneID);

this._currentQueue.isUpdateUBO = true;

const batches = this.camera!.scene!.batches;
for (let i = 0; i < batches.length; i++) {
const batch = batches[i];
Expand Down Expand Up @@ -1302,7 +1282,6 @@ class DeviceRenderScene implements RecordingInterface {
}

protected _updateRenderData (): void {
if (this._currentQueue.isUpdateUBO) return;
const devicePass = this._currentQueue.devicePass;
const rasterId = devicePass.rasterID;
const passRenderData = context.renderGraph.getData(rasterId);
Expand All @@ -1313,9 +1292,7 @@ class DeviceRenderScene implements RecordingInterface {
const queueId = this._currentQueue.queueId;
const queueRenderData = context.renderGraph.getData(queueId)!;
this._updateGlobal(queueRenderData, sceneId);
const sceneRenderData = context.renderGraph.getData(sceneId)!;
if (sceneRenderData) this._updateGlobal(sceneRenderData, sceneId);
this._currentQueue.isUpdateUBO = true;
context.passDescriptorSet?.update();
}

private _applyViewport (): void {
Expand All @@ -1341,7 +1318,7 @@ class DeviceRenderScene implements RecordingInterface {
public record (): void {
const devicePass = this._currentQueue.devicePass;
const sceneCulling = context.culling;
this._updateRenderData();
if (!devicePass.indexOfRD) this._updateRenderData();
this._applyViewport();
// Currently processing blit and camera first
if (this.blit) {
Expand All @@ -1351,9 +1328,10 @@ class DeviceRenderScene implements RecordingInterface {
const renderQueueQuery = sceneCulling.renderQueueQueryIndex.get(this.sceneID)!;
const renderQueue = sceneCulling.renderQueues[renderQueueQuery.renderQueueTarget];
const graphSceneData = this.sceneData!;
if (bool(graphSceneData.flags & SceneFlags.REFLECTION_PROBE)) renderQueue.probeQueue.applyMacro();
const isProbe = bool(graphSceneData.flags & SceneFlags.REFLECTION_PROBE);
if (isProbe) renderQueue.probeQueue.applyMacro();
renderQueue.recordCommands(context.commandBuffer, this._renderPass, graphSceneData.flags);
if (bool(graphSceneData.flags & SceneFlags.REFLECTION_PROBE)) renderQueue.probeQueue.removeMacro();
if (isProbe) renderQueue.probeQueue.removeMacro();
if (graphSceneData.flags & SceneFlags.GEOMETRY) {
this.camera!.geometryRenderer?.render(
devicePass.renderPass,
Expand Down Expand Up @@ -1442,11 +1420,12 @@ class BlitInfo {
const vb = this._genQuadVertexData(SurfaceTransform.IDENTITY, new Rect(0, 0, context.width, context.height));
this._pipelineIAData.quadVB!.update(vb);
this._createLightVolumes();
const size: number = UBOLocalEnum.SIZE;
this._localUBO = context.device.createBuffer(new BufferInfo(
BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.DEVICE,
UBOLocalEnum.SIZE,
UBOLocalEnum.SIZE,
size,
size,
));
}

Expand Down

0 comments on commit 428fa25

Please sign in to comment.