diff --git a/cocos/render-scene/core/pass-instance.ts b/cocos/render-scene/core/pass-instance.ts index 85932419a9..d353e27f29 100644 --- a/cocos/render-scene/core/pass-instance.ts +++ b/cocos/render-scene/core/pass-instance.ts @@ -114,7 +114,7 @@ export class PassInstance extends Pass { } protected _syncBatchingScheme () { - this._defines.USE_BATCHING = this._defines.USE_INSTANCING = false; + this._defines.USE_INSTANCING = false; this._batchingScheme = BatchingSchemes.NONE; } diff --git a/cocos/render-scene/core/pass.jsb.ts b/cocos/render-scene/core/pass.jsb.ts index 85ca632d54..82a249cad7 100644 --- a/cocos/render-scene/core/pass.jsb.ts +++ b/cocos/render-scene/core/pass.jsb.ts @@ -43,7 +43,6 @@ export interface IMacroPatch { export enum BatchingSchemes { NONE = 0, INSTANCING = 1, - VB_MERGING = 2, } export const Pass: typeof JsbPass = jsb.Pass; diff --git a/cocos/render-scene/core/pass.ts b/cocos/render-scene/core/pass.ts index 7553254f55..06cde220a4 100644 --- a/cocos/render-scene/core/pass.ts +++ b/cocos/render-scene/core/pass.ts @@ -39,7 +39,6 @@ import { MacroRecord, MaterialProperty, customizeType, getBindingFromHandle, get } from './pass-utils'; import { RenderPassStage, RenderPriority } from '../../rendering/define'; import { InstancedBuffer } from '../../rendering/instanced-buffer'; -import { BatchedBuffer } from '../../rendering/batched-buffer'; import { ProgramLibrary } from '../../rendering/custom/private'; export interface IPassInfoFull extends EffectAsset.IPassInfo { @@ -76,7 +75,6 @@ const _materialSet = 1; export enum BatchingSchemes { NONE = 0, INSTANCING = 1, - VB_MERGING = 2, } export declare namespace Pass { @@ -197,7 +195,6 @@ export class Pass { protected _batchingScheme: BatchingSchemes = BatchingSchemes.NONE; protected _dynamicStates: DynamicStateFlagBit = DynamicStateFlagBit.NONE; protected _instancedBuffers: Record = {}; - protected _batchedBuffers: Record = {}; protected _hash = 0; // external references protected _root: Root; @@ -374,10 +371,6 @@ export class Pass { return this._instancedBuffers[extraKey] || (this._instancedBuffers[extraKey] = new InstancedBuffer(this)); } - public getBatchedBuffer (extraKey = 0) { - return this._batchedBuffers[extraKey] || (this._batchedBuffers[extraKey] = new BatchedBuffer(this)); - } - /** * @en Destroy the current pass. * @zh 销毁当前 pass。 @@ -398,10 +391,6 @@ export class Pass { this._instancedBuffers[ib].destroy(); } - for (const bb in this._batchedBuffers) { - this._batchedBuffers[bb].destroy(); - } - this._descriptorSet.destroy(); this._rs.destroy(); this._dss.destroy(); @@ -754,8 +743,6 @@ export class Pass { this._defines.USE_INSTANCING = false; this._batchingScheme = BatchingSchemes.NONE; } - } else if (this._defines.USE_BATCHING) { - this._batchingScheme = BatchingSchemes.VB_MERGING; } else { this._batchingScheme = BatchingSchemes.NONE; } diff --git a/cocos/render-scene/scene/submodel.ts b/cocos/render-scene/scene/submodel.ts index 2df562def3..669f4ff402 100644 --- a/cocos/render-scene/scene/submodel.ts +++ b/cocos/render-scene/scene/submodel.ts @@ -86,9 +86,6 @@ export class SubModel { } this._passes = passes; this._flushPassInfo(); - if (this._passes[0].batchingScheme === BatchingSchemes.VB_MERGING) { - this.subMesh.genFlatBuffers(); - } // DS layout might change too if (this._descriptorSet) { @@ -117,7 +114,6 @@ export class SubModel { set subMesh (subMesh) { this._inputAssembler!.destroy(); this._inputAssembler = this._device!.createInputAssembler(subMesh.iaInfo); - if (this._passes![0].batchingScheme === BatchingSchemes.VB_MERGING) { this.subMesh.genFlatBuffers(); } this._subMesh = subMesh; } @@ -256,9 +252,6 @@ export class SubModel { this._passes = passes; this._flushPassInfo(); - if (passes[0].batchingScheme === BatchingSchemes.VB_MERGING) { - this.subMesh.genFlatBuffers(); - } this.priority = RenderPriority.DEFAULT; const r = cclegacy.rendering; diff --git a/cocos/rendering/batched-buffer.ts b/cocos/rendering/batched-buffer.ts deleted file mode 100644 index 99188d6cb4..0000000000 --- a/cocos/rendering/batched-buffer.ts +++ /dev/null @@ -1,219 +0,0 @@ -/* - Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd. - - https://www.cocos.com/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ - -import { BufferUsageBit, Format, MemoryUsageBit, Device, DescriptorSet, InputAssembler, - InputAssemblerInfo, Attribute, Buffer, BufferInfo, Shader } from '../gfx'; -import { Mat4 } from '../core'; -import { SubModel } from '../render-scene/scene/submodel'; -import { UBOLocalBatched } from './define'; -import { Pass } from '../render-scene'; -import { Model } from '../render-scene/scene'; - -export interface IBatchedItem { - vbs: Buffer[]; - vbDatas: Uint8Array[]; - vbIdx: Buffer; - vbIdxData: Float32Array; - vbCount: number; - mergeCount: number; - ia: InputAssembler; - ubo: Buffer; - uboData: Float32Array; - descriptorSet: DescriptorSet; - pass: Pass; - shader: Shader | null; -} - -export class BatchedBuffer { - public batches: IBatchedItem[] = []; - public dynamicOffsets: number[] = []; - private _device: Device; - - constructor (pass: Pass) { - this._device = pass.device; - } - - public destroy () { - for (let i = 0; i < this.batches.length; ++i) { - const batch = this.batches[i]; - for (let j = 0; j < batch.vbs.length; ++j) { - batch.vbs[j].destroy(); - } - batch.vbIdx.destroy(); - batch.ia.destroy(); - batch.ubo.destroy(); - } - this.batches.length = 0; - } - - public merge (subModel: SubModel, passIdx: number, model: Model) { - const flatBuffers = subModel.subMesh.flatBuffers; - if (flatBuffers.length === 0) { return; } - let vbSize = 0; - let vbIdxSize = 0; - const vbCount = flatBuffers[0].count; - const pass = subModel.passes[passIdx]; - const shader = subModel.shaders[passIdx]; - const descriptorSet = subModel.descriptorSet; - let isBatchExist = false; - for (let i = 0; i < this.batches.length; ++i) { - const batch = this.batches[i]; - if (batch.vbs.length === flatBuffers.length && batch.mergeCount < UBOLocalBatched.BATCHING_COUNT) { - isBatchExist = true; - for (let j = 0; j < batch.vbs.length; ++j) { - const vb = batch.vbs[j]; - if (vb.stride !== flatBuffers[j].stride) { - isBatchExist = false; - break; - } - } - - if (isBatchExist) { - for (let j = 0; j < batch.vbs.length; ++j) { - const flatBuff = flatBuffers[j]; - const batchVB = batch.vbs[j]; - const vbBuf = batch.vbDatas[j]; - vbSize = (vbCount + batch.vbCount) * flatBuff.stride; - if (vbSize > batchVB.size) { - batchVB.resize(vbSize); - batch.vbDatas[j] = new Uint8Array(vbSize); - batch.vbDatas[j].set(vbBuf); - } - batch.vbDatas[j].set(flatBuff.buffer, batch.vbCount * flatBuff.stride); - } - - let vbIdxBuf = batch.vbIdxData; - vbIdxSize = (vbCount + batch.vbCount) * 4; - if (vbIdxSize > batch.vbIdx.size) { - batch.vbIdx.resize(vbIdxSize); - batch.vbIdxData = new Float32Array(vbIdxSize / Float32Array.BYTES_PER_ELEMENT); - batch.vbIdxData.set(vbIdxBuf); - vbIdxBuf = batch.vbIdxData; - } - - const start = batch.vbCount; - const end = start + vbCount; - const mergeCount = batch.mergeCount; - if (vbIdxBuf[start] !== mergeCount || vbIdxBuf[end - 1] !== mergeCount) { - for (let j = start; j < end; j++) { - vbIdxBuf[j] = mergeCount + 0.1; // guard against underflow - } - } - - // update world matrix - Mat4.toArray(batch.uboData, model.transform.worldMatrix, UBOLocalBatched.MAT_WORLDS_OFFSET + batch.mergeCount * 16); - if (!batch.mergeCount) { - descriptorSet.bindBuffer(UBOLocalBatched.BINDING, batch.ubo); - descriptorSet.update(); - batch.pass = pass; - batch.shader = shader; - batch.descriptorSet = descriptorSet; - } - - ++batch.mergeCount; - batch.vbCount += vbCount; - batch.ia.vertexCount += vbCount; - - return; - } - } - } - - // Create a new batch - const vbs: Buffer[] = []; - const vbDatas: Uint8Array[] = []; - const totalVBs: Buffer[] = []; - for (let i = 0; i < flatBuffers.length; ++i) { - const flatBuff = flatBuffers[i]; - const newVB = this._device.createBuffer(new BufferInfo( - BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST, - MemoryUsageBit.HOST | MemoryUsageBit.DEVICE, - flatBuff.count * flatBuff.stride, - flatBuff.stride, - )); - newVB.update(flatBuff.buffer.buffer); - vbs.push(newVB); - vbDatas.push(new Uint8Array(newVB.size)); - totalVBs.push(newVB); - } - - const vbIdx = this._device.createBuffer(new BufferInfo( - BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST, - MemoryUsageBit.HOST | MemoryUsageBit.DEVICE, - vbCount * 4, - 4, - )); - const vbIdxData = new Float32Array(vbCount); - vbIdxData.fill(0); - vbIdx.update(vbIdxData); - totalVBs.push(vbIdx); - - const attributes = subModel.inputAssembler.attributes; - const attrs = new Array(attributes.length + 1); - for (let a = 0; a < attributes.length; ++a) { - attrs[a] = attributes[a]; - } - attrs[attributes.length] = new Attribute('a_dyn_batch_id', Format.R32F, false, flatBuffers.length); - - const iaInfo = new InputAssemblerInfo(attrs, totalVBs); - const ia = this._device.createInputAssembler(iaInfo); - - const ubo = this._device.createBuffer(new BufferInfo( - BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST, - MemoryUsageBit.HOST | MemoryUsageBit.DEVICE, - UBOLocalBatched.SIZE, - UBOLocalBatched.SIZE, - )); - - descriptorSet.bindBuffer(UBOLocalBatched.BINDING, ubo); - descriptorSet.update(); - - const uboData = new Float32Array(UBOLocalBatched.COUNT); - Mat4.toArray(uboData, model.transform.worldMatrix, UBOLocalBatched.MAT_WORLDS_OFFSET); - - this.batches.push({ - mergeCount: 1, - vbs, - vbDatas, - vbIdx, - vbIdxData, - vbCount, - ia, - ubo, - uboData, - pass, - shader, - descriptorSet, - }); - } - - public clear () { - for (let i = 0; i < this.batches.length; ++i) { - const batch = this.batches[i]; - batch.vbCount = 0; - batch.mergeCount = 0; - batch.ia.vertexCount = 0; - } - } -} diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index d1cf26be1d..0b6d33771e 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -42,7 +42,6 @@ import { BatchingSchemes, Pass } from '../../render-scene'; import { Camera } from '../../render-scene/scene/camera'; import { ShadowType } from '../../render-scene/scene/shadows'; import { Root } from '../../root'; -import { BatchedBuffer } from '../batched-buffer'; import { IRenderPass, isEnableEffect, SetIndex, UBODeferredLight, UBOForwardLight, UBOLocal } from '../define'; import { PipelineSceneData } from '../pipeline-scene-data'; import { PipelineInputAssemblerData } from '../render-pipeline'; @@ -427,7 +426,6 @@ class DeviceRenderQueue { private _layoutID = -1; private _isUpdateUBO = false; private _isUploadInstance = false; - private _isUploadBatched = false; protected _transversal: DeviceSceneTransversal | null = null; get phaseID (): number { return this._phaseID; } set layoutID (value: number) { @@ -449,8 +447,6 @@ class DeviceRenderQueue { get isUpdateUBO () { return this._isUpdateUBO; } set isUploadInstance (value: boolean) { this._isUploadInstance = value; } get isUploadInstance () { return this._isUploadInstance; } - set isUploadBatched (value: boolean) { this._isUploadBatched = value; } - get isUploadBatched () { return this._isUploadBatched; } init (devicePass: DeviceRenderPass, queueHint: QueueHint, id: number) { this.reset(); this.queueHint = queueHint; @@ -481,7 +477,6 @@ class DeviceRenderQueue { this._postSceneTasks.length = this._preSceneTasks.length = this._sceneTasks.length = 0; this._isUpdateUBO = false; this._isUploadInstance = false; - this._isUploadBatched = false; this._blitDesc?.reset(); } get blitDesc () { return this._blitDesc; } @@ -522,7 +517,6 @@ class DeviceRenderQueue { class SubmitInfo { public instances = new Set(); public renderInstanceQueue: InstancedBuffer[] = []; - public batches = new Set(); public opaqueList: RenderInfo[] = []; public transparentList: RenderInfo[] = []; public planarQueue: PlanarShadowQueue | null = null; @@ -532,7 +526,6 @@ class SubmitInfo { reset () { this.instances.clear(); this.renderInstanceQueue.length = 0; - this.batches.clear(); this.opaqueList.length = 0; this.transparentList.length = 0; this.planarQueue = null; @@ -1099,8 +1092,7 @@ class DevicePreSceneTask extends WebSceneTask { // If it is not empty, it means that it has been added and will not be traversed. const isEmpty = !this._submitInfo.opaqueList.length && !this._submitInfo.transparentList.length - && !this._submitInfo.instances.size - && !this._submitInfo.batches.size; + && !this._submitInfo.instances.size; if (isEmpty) { for (const ro of this.sceneData.renderObjects) { const subModels = ro.model.subModels; @@ -1113,10 +1105,6 @@ class DevicePreSceneTask extends WebSceneTask { const instancedBuffer = p.getInstancedBuffer(); instancedBuffer.merge(subModel, passes.indexOf(p)); this._submitInfo.instances.add(instancedBuffer); - } else if (batchingScheme === BatchingSchemes.VB_MERGING) { - const batchedBuffer = p.getBatchedBuffer(); - batchedBuffer.merge(subModel, passes.indexOf(p), ro.model); - this._submitInfo.batches.add(batchedBuffer); } else { this._insertRenderList(ro, subModels.indexOf(subModel), passes.indexOf(p)); this._insertRenderList(ro, subModels.indexOf(subModel), passes.indexOf(p), true); @@ -1206,24 +1194,6 @@ class DevicePreSceneTask extends WebSceneTask { this._currentQueue.isUploadInstance = true; } - private _uploadBatchedBuffers () { - if (this._currentQueue.isUploadBatched) return; - const it = this._submitInfo!.batches.values(); let res = it.next(); - while (!res.done) { - for (let b = 0; b < res.value.batches.length; ++b) { - const batch = res.value.batches[b]; - if (!batch.mergeCount) { continue; } - for (let v = 0; v < batch.vbs.length; ++v) { - batch.vbs[v].update(batch.vbDatas[v]); - } - this._cmdBuff.updateBuffer(batch.vbIdx, batch.vbIdxData.buffer); - this._cmdBuff.updateBuffer(batch.ubo, batch.uboData); - } - res = it.next(); - } - this._currentQueue.isUploadBatched = true; - } - private _isShadowMap () { return this.sceneData.shadows.enabled && this.sceneData.shadows.type === ShadowType.ShadowMap @@ -1287,7 +1257,6 @@ class DevicePreSceneTask extends WebSceneTask { return; } this._uploadInstanceBuffers(); - this._uploadBatchedBuffers(); } } @@ -1368,31 +1337,7 @@ class DeviceSceneTask extends WebSceneTask { res = it.next(); } } - protected _recordBatches () { - const submitMap = context.submitMap; - const currSubmitInfo = submitMap.get(this.camera!)!.get(this._currentQueue.phaseID)!; - const it = currSubmitInfo.batches.values(); let res = it.next(); - while (!res.done) { - let boundPSO = false; - for (let b = 0; b < res.value.batches.length; ++b) { - const batch = res.value.batches[b]; - if (!batch.mergeCount) { continue; } - if (!boundPSO) { - const shader = batch.shader!; - const pso = PipelineStateManager.getOrCreatePipelineState(deviceManager.gfxDevice, batch.pass, - shader, this._renderPass, batch.ia); - this.visitor.bindPipelineState(pso); - this.visitor.bindDescriptorSet(SetIndex.MATERIAL, batch.pass.descriptorSet); - boundPSO = true; - } - const ia: any = batch.ia; - this.visitor.bindDescriptorSet(SetIndex.LOCAL, batch.descriptorSet, res.value.dynamicOffsets); - this.visitor.bindInputAssembler(ia); - this.visitor.draw(ia); - } - res = it.next(); - } - } + protected _recordUI () { const batches = this.camera!.scene!.batches; for (let i = 0; i < batches.length; i++) { @@ -1539,7 +1484,6 @@ class DeviceSceneTask extends WebSceneTask { if (graphSceneData.flags & SceneFlags.DRAW_INSTANCING) { this._recordInstences(); } - // this._recordBatches(); if (graphSceneData.flags & SceneFlags.DEFAULT_LIGHTING) { this._recordAdditiveLights(); } diff --git a/cocos/rendering/deferred/gbuffer-stage.ts b/cocos/rendering/deferred/gbuffer-stage.ts index c846d652f2..16bb54ad0b 100644 --- a/cocos/rendering/deferred/gbuffer-stage.ts +++ b/cocos/rendering/deferred/gbuffer-stage.ts @@ -34,7 +34,6 @@ import { getPhaseID } from '../pass-phase'; import { renderQueueClearFunc, RenderQueue, convertRenderQueue, renderQueueSortFunc } from '../render-queue'; import { ClearFlagBit, Color, Rect } from '../../gfx'; import { SRGBToLinear } from '../pipeline-funcs'; -import { RenderBatchedQueue } from '../render-batched-queue'; import { RenderInstancedQueue } from '../render-instanced-queue'; import { IRenderStageInfo, RenderStage } from '../render-stage'; import { DeferredStagePriority } from '../enum'; @@ -76,13 +75,11 @@ export class GbufferStage extends RenderStage { protected _renderQueues: RenderQueue[] = []; private _renderArea = new Rect(); - private _batchedQueue: RenderBatchedQueue; private _instancedQueue: RenderInstancedQueue; private _phaseID = getPhaseID('default'); constructor () { super(); - this._batchedQueue = new RenderBatchedQueue(); this._instancedQueue = new RenderInstancedQueue(); } @@ -106,7 +103,6 @@ export class GbufferStage extends RenderStage { public render (camera: Camera) { this._instancedQueue.clear(); - this._batchedQueue.clear(); const pipeline = this._pipeline as DeferredPipeline; const device = pipeline.device; this._renderQueues.forEach(renderQueueClearFunc); @@ -131,10 +127,6 @@ export class GbufferStage extends RenderStage { const instancedBuffer = pass.getInstancedBuffer(); instancedBuffer.merge(subModel, p); this._instancedQueue.queue.add(instancedBuffer); - } else if (batchingScheme === BatchingSchemes.VB_MERGING) { - const batchedBuffer = pass.getBatchedBuffer(); - batchedBuffer.merge(subModel, p, ro.model); - this._batchedQueue.queue.add(batchedBuffer); } else { for (k = 0; k < this._renderQueues.length; k++) { this._renderQueues[k].insertRenderPass(ro, m, p); @@ -148,7 +140,6 @@ export class GbufferStage extends RenderStage { const cmdBuff = pipeline.commandBuffers[0]; this._instancedQueue.uploadBuffers(cmdBuff); - this._batchedQueue.uploadBuffers(cmdBuff); if (camera.clearFlag & ClearFlagBit.COLOR) { if (pipeline.pipelineSceneData.isHDR) { @@ -175,7 +166,6 @@ export class GbufferStage extends RenderStage { this._renderQueues[i].recordCommandBuffer(device, renderPass, cmdBuff); } this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff); - this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff); cmdBuff.endRenderPass(); } diff --git a/cocos/rendering/forward/forward-stage.ts b/cocos/rendering/forward/forward-stage.ts index 00da442cc3..f7470ab5cc 100644 --- a/cocos/rendering/forward/forward-stage.ts +++ b/cocos/rendering/forward/forward-stage.ts @@ -27,7 +27,6 @@ import { SetIndex } from '../define'; import { getPhaseID } from '../pass-phase'; import { renderQueueClearFunc, RenderQueue, convertRenderQueue, renderQueueSortFunc } from '../render-queue'; import { ClearFlagBit, Color, Rect } from '../../gfx'; -import { RenderBatchedQueue } from '../render-batched-queue'; import { RenderInstancedQueue } from '../render-instanced-queue'; import { IRenderStageInfo, RenderStage } from '../render-stage'; import { ForwardStagePriority } from '../enum'; @@ -74,7 +73,6 @@ export class ForwardStage extends RenderStage { protected _renderQueues: RenderQueue[] = []; private _renderArea = new Rect(); - private _batchedQueue: RenderBatchedQueue; private _instancedQueue: RenderInstancedQueue; private _phaseID = getPhaseID('default'); private _clearFlag = 0xffffffff; @@ -86,7 +84,6 @@ export class ForwardStage extends RenderStage { constructor () { super(); - this._batchedQueue = new RenderBatchedQueue(); this._instancedQueue = new RenderInstancedQueue(); this._uiPhase = new UIPhase(); } @@ -129,7 +126,6 @@ export class ForwardStage extends RenderStage { public render (camera: Camera) { this._instancedQueue.clear(); - this._batchedQueue.clear(); const pipeline = this._pipeline as ForwardPipeline; const device = pipeline.device; this._renderQueues.forEach(renderQueueClearFunc); @@ -150,10 +146,6 @@ export class ForwardStage extends RenderStage { const instancedBuffer = pass.getInstancedBuffer(); instancedBuffer.merge(subModel, p); this._instancedQueue.queue.add(instancedBuffer); - } else if (batchingScheme === BatchingSchemes.VB_MERGING) { - const batchedBuffer = pass.getBatchedBuffer(); - batchedBuffer.merge(subModel, p, ro.model); - this._batchedQueue.queue.add(batchedBuffer); } else { for (k = 0; k < this._renderQueues.length; k++) { this._renderQueues[k].insertRenderPass(ro, m, p); @@ -174,7 +166,6 @@ export class ForwardStage extends RenderStage { } this._instancedQueue.uploadBuffers(cmdBuff); - this._batchedQueue.uploadBuffers(cmdBuff); this._additiveLightQueue.gatherLightPasses(camera, cmdBuff); this._planarQueue.gatherShadowPasses(camera, cmdBuff); @@ -198,7 +189,6 @@ export class ForwardStage extends RenderStage { } this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff); - this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff); this._additiveLightQueue.recordCommandBuffer(device, renderPass, cmdBuff); diff --git a/cocos/rendering/render-additive-light-queue.ts b/cocos/rendering/render-additive-light-queue.ts index 3b2bb64695..777210b494 100644 --- a/cocos/rendering/render-additive-light-queue.ts +++ b/cocos/rendering/render-additive-light-queue.ts @@ -28,7 +28,6 @@ import { PipelineStateManager } from './pipeline-state-manager'; import { Vec3, nextPow2, Mat4, Color, Pool, geometry, cclegacy } from '../core'; import { Device, RenderPass, Buffer, BufferUsageBit, MemoryUsageBit, BufferInfo, BufferViewInfo, CommandBuffer } from '../gfx'; -import { RenderBatchedQueue } from './render-batched-queue'; import { RenderInstancedQueue } from './render-instanced-queue'; import { SphereLight } from '../render-scene/scene/sphere-light'; import { SpotLight } from '../render-scene/scene/spot-light'; @@ -117,7 +116,6 @@ export class RenderAdditiveLightQueue { private _device: Device; private _lightPasses: IAdditiveLightPass[] = []; private _instancedLightPassPool = _lightPassPool.alloc(); - private _batchedLightPassPool = _lightPassPool.alloc(); private _shadowUBO = new Float32Array(UBOShadow.COUNT); private _lightBufferCount = 16; private _lightBufferStride: number; @@ -126,7 +124,6 @@ export class RenderAdditiveLightQueue { private _firstLightBufferView: Buffer; private _lightBufferData: Float32Array; private _instancedQueues: RenderInstancedQueue[] = []; - private _batchedQueues: RenderBatchedQueue[] = []; private _lightMeterScale = 10000.0; constructor (pipeline: PipelineRuntime) { @@ -154,10 +151,6 @@ export class RenderAdditiveLightQueue { instancedQueue.clear(); }); this._instancedQueues.length = 0; - this._batchedQueues.forEach((batchedQueue) => { - batchedQueue.clear(); - }); - this._batchedQueues.length = 0; for (let i = 0; i < this._lightPasses.length; i++) { const lp = this._lightPasses[i]; @@ -169,8 +162,6 @@ export class RenderAdditiveLightQueue { this._instancedLightPassPool.dynamicOffsets.length = 0; this._instancedLightPassPool.lights.length = 0; - this._batchedLightPassPool.dynamicOffsets.length = 0; - this._batchedLightPassPool.lights.length = 0; } public destroy () { @@ -241,16 +232,11 @@ export class RenderAdditiveLightQueue { const light = validPunctualLights[l]; this._instancedLightPassPool.lights.push(light); this._instancedLightPassPool.dynamicOffsets.push(this._lightBufferStride * l); - this._batchedLightPassPool.lights.push(light); - this._batchedLightPassPool.dynamicOffsets.push(this._lightBufferStride * l); } this._instancedQueues.forEach((instancedQueue) => { instancedQueue.uploadBuffers(cmdBuff); }); - this._batchedQueues.forEach((batchedQueue) => { - batchedQueue.uploadBuffers(cmdBuff); - }); } public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer) { @@ -262,13 +248,6 @@ export class RenderAdditiveLightQueue { this._instancedQueues[j].recordCommandBuffer(device, renderPass, cmdBuff, descriptorSet, _dynamicOffsets); } - for (let j = 0; j < this._batchedQueues.length; ++j) { - const light = this._batchedLightPassPool.lights[j]; - _dynamicOffsets[0] = this._batchedLightPassPool.dynamicOffsets[j]; - const descriptorSet = globalDSManager.getOrCreateDescriptorSet(light); - this._batchedQueues[j].recordCommandBuffer(device, renderPass, cmdBuff, descriptorSet, _dynamicOffsets); - } - for (let i = 0; i < this._lightPasses.length; i++) { const { subModel, passIdx, dynamicOffsets, lights } = this._lightPasses[i]; const pass = subModel.passes[passIdx]; @@ -344,13 +323,6 @@ export class RenderAdditiveLightQueue { if (!this._instancedQueues[l]) { this._instancedQueues[l] = new RenderInstancedQueue(); } this._instancedQueues[l].queue.add(buffer); } break; - case BatchingSchemes.VB_MERGING: { - const buffer = pass.getBatchedBuffer(l); - buffer.merge(subModel, lightPassIdx, model); - buffer.dynamicOffsets[0] = this._lightBufferStride; - if (!this._batchedQueues[l]) { this._batchedQueues[l] = new RenderBatchedQueue(); } - this._batchedQueues[l].queue.add(buffer); - } break; default: lp!.lights.push(light); lp!.dynamicOffsets.push(this._lightBufferStride * lightIdx); diff --git a/cocos/rendering/render-batched-queue.ts b/cocos/rendering/render-batched-queue.ts deleted file mode 100644 index 96aa9e671b..0000000000 --- a/cocos/rendering/render-batched-queue.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd. - - https://www.cocos.com/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ - -import { BatchedBuffer } from './batched-buffer'; -import { PipelineStateManager } from './pipeline-state-manager'; -import { RenderPass, Device, CommandBuffer, DescriptorSet } from '../gfx'; -import { SetIndex } from './define'; - -/** - * @en The render queue for dynamic batching - * @zh 渲染合批队列。 - */ -export class RenderBatchedQueue { - /** - * @en A set of dynamic batched buffer - * @zh 动态合批缓存集合。 - */ - public queue = new Set(); - - /** - * @en Clear the render queue - * @zh 清空渲染队列。 - */ - public clear () { - const it = this.queue.values(); let res = it.next(); - while (!res.done) { - res.value.clear(); - res = it.next(); - } - this.queue.clear(); - } - - public uploadBuffers (cmdBuff: CommandBuffer) { - const it = this.queue.values(); let res = it.next(); - while (!res.done) { - for (let b = 0; b < res.value.batches.length; ++b) { - const batch = res.value.batches[b]; - if (!batch.mergeCount) { continue; } - for (let v = 0; v < batch.vbs.length; ++v) { - batch.vbs[v].update(batch.vbDatas[v]); - } - cmdBuff.updateBuffer(batch.vbIdx, batch.vbIdxData.buffer); - cmdBuff.updateBuffer(batch.ubo, batch.uboData); - } - res = it.next(); - } - } - - /** - * @en Record command buffer for the current queue - * @zh 记录命令缓冲。 - * @param cmdBuff The command buffer to store the result - */ - public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer, - descriptorSet: DescriptorSet | null = null, dynamicOffsets?: Readonly) { - const it = this.queue.values(); let res = it.next(); - while (!res.done) { - let boundPSO = false; - for (let b = 0; b < res.value.batches.length; ++b) { - const batch = res.value.batches[b]; - if (!batch.mergeCount) { continue; } - if (!boundPSO) { - const shader = batch.shader; - const pso = PipelineStateManager.getOrCreatePipelineState(device, batch.pass, shader!, renderPass, batch.ia); - cmdBuff.bindPipelineState(pso); - cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, batch.pass.descriptorSet); - boundPSO = true; - } - if (descriptorSet) cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, descriptorSet); - if (dynamicOffsets) { - cmdBuff.bindDescriptorSet(SetIndex.LOCAL, batch.descriptorSet, dynamicOffsets); - } else { - cmdBuff.bindDescriptorSet(SetIndex.LOCAL, batch.descriptorSet, res.value.dynamicOffsets); - } - cmdBuff.bindInputAssembler(batch.ia); - cmdBuff.draw(batch.ia); - } - res = it.next(); - } - } -} diff --git a/cocos/rendering/render-reflection-probe-queue.ts b/cocos/rendering/render-reflection-probe-queue.ts index 46853433a2..a76133ba3f 100644 --- a/cocos/rendering/render-reflection-probe-queue.ts +++ b/cocos/rendering/render-reflection-probe-queue.ts @@ -33,7 +33,6 @@ import { Camera, ProbeType, ReflectionProbe, SKYBOX_FLAG } from '../render-scene import { PipelineRuntime } from './custom/pipeline'; import { IMacroPatch, RenderScene } from '../render-scene'; import { RenderInstancedQueue } from './render-instanced-queue'; -import { RenderBatchedQueue } from './render-batched-queue'; import { cclegacy, geometry } from '../core'; import { Layers } from '../scene-graph/layers'; @@ -80,12 +79,10 @@ export class RenderReflectionProbeQueue { private _shaderArray: Shader[] = []; private _rgbeSubModelsArray: SubModel[]=[] private _instancedQueue: RenderInstancedQueue; - private _batchedQueue: RenderBatchedQueue; public constructor (pipeline: PipelineRuntime) { this._pipeline = pipeline; this._instancedQueue = new RenderInstancedQueue(); - this._batchedQueue = new RenderBatchedQueue(); } public gatherRenderObjects (probe: ReflectionProbe, camera: Camera, cmdBuff: CommandBuffer) { this.clear(); @@ -121,7 +118,6 @@ export class RenderReflectionProbeQueue { } } this._instancedQueue.uploadBuffers(cmdBuff); - this._batchedQueue.uploadBuffers(cmdBuff); } public clear () { @@ -129,7 +125,6 @@ export class RenderReflectionProbeQueue { this._shaderArray.length = 0; this._passArray.length = 0; this._instancedQueue.clear(); - this._batchedQueue.clear(); this._rgbeSubModelsArray.length = 0; } @@ -169,10 +164,6 @@ export class RenderReflectionProbeQueue { const buffer = pass.getInstancedBuffer(); buffer.merge(subModel, passIdx); this._instancedQueue.queue.add(buffer); - } else if (pass.batchingScheme === BatchingSchemes.VB_MERGING) { // vb-merging - const buffer = pass.getBatchedBuffer(); - buffer.merge(subModel, passIdx, model); - this._batchedQueue.queue.add(buffer); } else { const shader = subModel.shaders[passIdx]; this._subModelsArray.push(subModel); @@ -188,7 +179,6 @@ export class RenderReflectionProbeQueue { */ public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer) { this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff); - this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff); for (let i = 0; i < this._subModelsArray.length; ++i) { const subModel = this._subModelsArray[i]; @@ -206,7 +196,6 @@ export class RenderReflectionProbeQueue { } this.resetRGBEMacro(); this._instancedQueue.clear(); - this._batchedQueue.clear(); } public resetRGBEMacro () { for (let i = 0; i < this._rgbeSubModelsArray.length; i++) { diff --git a/cocos/rendering/render-shadow-map-batched-queue.ts b/cocos/rendering/render-shadow-map-batched-queue.ts index 36f2eb25a9..79dddbfaf7 100644 --- a/cocos/rendering/render-shadow-map-batched-queue.ts +++ b/cocos/rendering/render-shadow-map-batched-queue.ts @@ -29,7 +29,6 @@ import { getPhaseID } from './pass-phase'; import { PipelineStateManager } from './pipeline-state-manager'; import { Pass, BatchingSchemes } from '../render-scene/core/pass'; import { RenderInstancedQueue } from './render-instanced-queue'; -import { RenderBatchedQueue } from './render-batched-queue'; import { ShadowType } from '../render-scene/scene/shadows'; import { Light, LightType } from '../render-scene/scene/light'; import { cclegacy, geometry } from '../core'; @@ -62,12 +61,10 @@ export class RenderShadowMapBatchedQueue { private _passArray: Pass[] = []; private _shaderArray: Shader[] = []; private _instancedQueue: RenderInstancedQueue; - private _batchedQueue: RenderBatchedQueue; public constructor (pipeline: PipelineRuntime) { this._pipeline = pipeline; this._instancedQueue = new RenderInstancedQueue(); - this._batchedQueue = new RenderBatchedQueue(); } public gatherLightPasses (camera: Camera, light: Light, cmdBuff: CommandBuffer, level = 0) { @@ -120,7 +117,6 @@ export class RenderShadowMapBatchedQueue { } this._instancedQueue.uploadBuffers(cmdBuff); - this._batchedQueue.uploadBuffers(cmdBuff); } } @@ -133,7 +129,6 @@ export class RenderShadowMapBatchedQueue { this._shaderArray.length = 0; this._passArray.length = 0; this._instancedQueue.clear(); - this._batchedQueue.clear(); } public add (model: Model) { @@ -149,10 +144,6 @@ export class RenderShadowMapBatchedQueue { const buffer = pass.getInstancedBuffer(); buffer.merge(subModel, shadowPassIdx); this._instancedQueue.queue.add(buffer); - } else if (pass.batchingScheme === BatchingSchemes.VB_MERGING) { // vb-merging - const buffer = pass.getBatchedBuffer(); - buffer.merge(subModel, shadowPassIdx, model); - this._batchedQueue.queue.add(buffer); } else { const shader = subModel.shaders[shadowPassIdx]; this._subModelsArray.push(subModel); @@ -168,7 +159,6 @@ export class RenderShadowMapBatchedQueue { */ public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer) { this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff); - this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff); for (let i = 0; i < this._subModelsArray.length; ++i) { const subModel = this._subModelsArray[i]; diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index b9f945ad9d..826d119d10 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -1316,8 +1316,6 @@ cocos_source_files( cocos/renderer/gfx-empty/EmptyTexture.h cocos/renderer/gfx-empty/EmptyTexture.cpp - cocos/renderer/pipeline/BatchedBuffer.cpp - cocos/renderer/pipeline/BatchedBuffer.h cocos/renderer/pipeline/ClusterLightCulling.cpp cocos/renderer/pipeline/ClusterLightCulling.h cocos/renderer/pipeline/Define.h @@ -1330,8 +1328,6 @@ cocos_source_files( cocos/renderer/pipeline/PipelineStateManager.h cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp cocos/renderer/pipeline/RenderAdditiveLightQueue.h - cocos/renderer/pipeline/RenderBatchedQueue.cpp - cocos/renderer/pipeline/RenderBatchedQueue.h cocos/renderer/pipeline/RenderFlow.cpp cocos/renderer/pipeline/RenderFlow.h cocos/renderer/pipeline/RenderInstancedQueue.cpp diff --git a/native/cocos/renderer/core/PassInstance.cpp b/native/cocos/renderer/core/PassInstance.cpp index 8c4e157e8e..024d2cd0c7 100644 --- a/native/cocos/renderer/core/PassInstance.cpp +++ b/native/cocos/renderer/core/PassInstance.cpp @@ -25,7 +25,6 @@ #include "cocos/renderer/core/PassInstance.h" #include "cocos/renderer/core/MaterialInstance.h" #include "cocos/renderer/core/ProgramLib.h" -#include "cocos/renderer/pipeline/BatchedBuffer.h" #include "cocos/renderer/pipeline/InstancedBuffer.h" #include "cocos/renderer/pipeline/custom/RenderingModule.h" @@ -105,7 +104,6 @@ void PassInstance::endChangeStatesSilently() { void PassInstance::syncBatchingScheme() { _defines["USE_INSTANCING"] = false; - _defines["USE_BATCHING"] = false; _batchingScheme = scene::BatchingSchemes::NONE; } diff --git a/native/cocos/renderer/pipeline/BatchedBuffer.cpp b/native/cocos/renderer/pipeline/BatchedBuffer.cpp deleted file mode 100644 index c94fdbaa9d..0000000000 --- a/native/cocos/renderer/pipeline/BatchedBuffer.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************** - Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#include "BatchedBuffer.h" -#include "gfx-base/GFXBuffer.h" -#include "gfx-base/GFXDescriptorSet.h" -#include "gfx-base/GFXDevice.h" -#include "gfx-base/GFXInputAssembler.h" -#include "scene/Model.h" -#include "scene/Pass.h" -#include "scene/SubModel.h" - -namespace cc { -namespace pipeline { - -BatchedBuffer::BatchedBuffer(const scene::Pass *pass) -: _pass(pass), - _device(gfx::Device::getInstance()) { -} - -BatchedBuffer::~BatchedBuffer() = default; - -void BatchedBuffer::destroy() { - for (auto &batch : _batches) { - for (auto *vb : batch.vbs) { - CC_SAFE_DESTROY_AND_DELETE(vb); - } - - for (auto *data : batch.vbDatas) { - CC_FREE(data); - } - - CC_SAFE_DESTROY_AND_DELETE(batch.indexBuffer); - CC_SAFE_DESTROY_AND_DELETE(batch.ia); - CC_SAFE_DESTROY_AND_DELETE(batch.ubo); - - CC_FREE(batch.indexData); - } - _batches.clear(); -} - -void BatchedBuffer::merge(const scene::SubModel *subModel, uint32_t passIdx, const scene::Model *model) { - const auto *subMesh = subModel->getSubMesh(); - const auto &flatBuffers = subMesh->getFlatBuffers(); - auto flatBuffersCount = static_cast(flatBuffers.size()); - if (0 == flatBuffersCount) { - return; - } - - const auto &flatBuffer = flatBuffers[0]; - uint32_t vbSize = 0; - uint32_t indexSize = 0; - const auto vbCount = flatBuffer.count; - const auto *const pass = subModel->getPass(passIdx); - auto *const shader = subModel->getShader(passIdx); - auto *const descriptorSet = subModel->getDescriptorSet(); - bool isBatchExist = false; - - for (auto &batch : _batches) { - if (batch.vbs.size() == flatBuffersCount && batch.mergeCount < UBOLocalBatched::BATCHING_COUNT) { - isBatchExist = true; - for (uint32_t j = 0; j < flatBuffersCount; ++j) { - auto *const vb = batch.vbs[j]; - if (vb->getStride() != flatBuffers[j].stride) { - isBatchExist = false; - break; - } - } - - if (isBatchExist) { - for (uint32_t j = 0; j < flatBuffersCount; ++j) { - const auto &flatBuffer = flatBuffers[j]; - auto *batchVB = batch.vbs[j]; - auto *vbData = batch.vbDatas[j]; - const uint32_t vbBufSizeOld = batchVB->getSize(); - vbSize = (vbCount + batch.vbCount) * flatBuffer.stride; - if (vbSize > vbBufSizeOld) { - auto *vbDataNew = static_cast(CC_MALLOC(vbSize)); - memcpy(vbDataNew, vbData, vbBufSizeOld); - batchVB->resize(vbSize); - CC_FREE(vbData); - batch.vbDatas[j] = vbDataNew; - vbData = vbDataNew; - } - - auto offset = batch.vbCount * flatBuffer.stride; - memcpy(vbData + offset, flatBuffer.buffer.buffer()->getData(), flatBuffer.buffer.buffer()->byteLength()); - } - - auto *indexData = batch.indexData; - indexSize = (vbCount + batch.vbCount) * sizeof(float); - if (indexSize > batch.indexBuffer->getSize()) { - auto *newIndexData = static_cast(CC_MALLOC(indexSize)); - memcpy(newIndexData, indexData, batch.indexBuffer->getSize()); - CC_FREE(indexData); - batch.indexData = newIndexData; - indexData = batch.indexData; - batch.indexBuffer->resize(indexSize); - } - - const auto start = batch.vbCount; - const auto end = start + vbCount; - const auto mergeCount = batch.mergeCount; - if (indexData[start] != static_cast(mergeCount) || indexData[end - 1] != static_cast(mergeCount)) { - for (auto j = start; j < end; j++) { - indexData[j] = static_cast(mergeCount) + 0.1F; // guard against underflow - } - } - - // update world matrix - const auto offset = UBOLocalBatched::MAT_WORLDS_OFFSET + batch.mergeCount * 16; - const auto &worldMatrix = model->getTransform()->getWorldMatrix(); - memcpy(batch.uboData.data() + offset, worldMatrix.m, sizeof(worldMatrix)); - - if (!batch.mergeCount) { - descriptorSet->bindBuffer(UBOLocalBatched::BINDING, batch.ubo); - descriptorSet->update(); - batch.pass = pass; - batch.shader = shader; - batch.descriptorSet = descriptorSet; - } - - ++batch.mergeCount; - batch.vbCount += vbCount; - auto prevCount = batch.ia->getDrawInfo().vertexCount; - batch.ia->setVertexCount(prevCount + vbCount); - return; - } - } - } - - // Create a new batch - ccstd::vector vbs(flatBuffersCount, nullptr); - ccstd::vector vbDatas(flatBuffersCount, nullptr); - ccstd::vector totalVBs(flatBuffersCount + 1, nullptr); - - for (uint32_t i = 0; i < flatBuffersCount; ++i) { - const auto &flatBuffer = flatBuffers[i]; - auto *newVB = _device->createBuffer({ - gfx::BufferUsageBit::VERTEX | gfx::BufferUsageBit::TRANSFER_DST, - gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, - flatBuffer.count * flatBuffer.stride, - flatBuffer.stride, - }); - auto size = 0U; - newVB->update(flatBuffer.buffer.buffer()->getData(), flatBuffer.buffer.buffer()->byteLength()); - - vbs[i] = newVB; - vbDatas[i] = static_cast(CC_MALLOC(newVB->getSize())); - memset(vbDatas[i], 0, newVB->getSize()); - totalVBs[i] = newVB; - } - - const auto indexBufferSize = vbCount * sizeof(float); - auto *indexBuffer = _device->createBuffer({ - gfx::BufferUsageBit::VERTEX | gfx::BufferUsageBit::TRANSFER_DST, - gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, - static_cast(indexBufferSize), - sizeof(float), - }); - auto *indexData = static_cast(CC_MALLOC(indexBufferSize)); - memset(indexData, 0, indexBufferSize); - indexBuffer->update(indexData, static_cast(indexBufferSize)); - totalVBs[flatBuffersCount] = indexBuffer; - - ccstd::vector attributes = subModel->getInputAssembler()->getAttributes(); - gfx::Attribute attrib = { - "a_dyn_batch_id", - gfx::Format::R32F, - false, - flatBuffersCount, - }; - attributes.emplace_back(std::move(attrib)); - - auto *ia = _device->createInputAssembler({std::move(attributes), std::move(totalVBs)}); - - auto *ubo = _device->createBuffer({ - gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, - gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, - UBOLocalBatched::SIZE, - UBOLocalBatched::SIZE, - }); - - descriptorSet->bindBuffer(UBOLocalBatched::BINDING, ubo); - descriptorSet->update(); - - ccstd::array uboData; - const auto &worldMatrix = model->getTransform()->getWorldMatrix(); - memcpy(uboData.data() + UBOLocalBatched::MAT_WORLDS_OFFSET, worldMatrix.m, sizeof(worldMatrix)); - BatchedItem item = { - std::move(vbs), //vbs - std::move(vbDatas), //vbDatas - indexBuffer, //indexBuffer - static_cast(indexData), //indexData - vbCount, //vbCount - 1, //mergeCount - ia, //ia - ubo, //ubo - uboData, //uboData - descriptorSet, //descriptorSet - pass, //pass - shader, //shader - }; - _batches.emplace_back(std::move(item)); -} - -void BatchedBuffer::clear() { - for (auto &batch : _batches) { - batch.vbCount = 0; - batch.mergeCount = 0; - batch.ia->setVertexCount(0); - } -} - -void BatchedBuffer::setDynamicOffset(uint32_t idx, uint32_t value) { - _dynamicOffsets[idx] = value; -} - -} // namespace pipeline -} // namespace cc diff --git a/native/cocos/renderer/pipeline/BatchedBuffer.h b/native/cocos/renderer/pipeline/BatchedBuffer.h deleted file mode 100644 index d3dbce8ed6..0000000000 --- a/native/cocos/renderer/pipeline/BatchedBuffer.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#pragma once - -#include "Define.h" -#include "base/RefCounted.h" -#include "base/std/container/array.h" -#include "base/std/container/unordered_map.h" - -namespace cc { -namespace scene { -class Pass; -class Model; -class SubModel; -} // namespace scene -namespace pipeline { - -struct CC_DLL BatchedItem { - gfx::BufferList vbs; - ccstd::vector vbDatas; - gfx::Buffer *indexBuffer = nullptr; - float *indexData = nullptr; - uint32_t vbCount = 0; - uint32_t mergeCount = 0; - gfx::InputAssembler *ia = nullptr; - gfx::Buffer *ubo = nullptr; - ccstd::array uboData; - gfx::DescriptorSet *descriptorSet = nullptr; - const scene::Pass *pass = nullptr; - gfx::Shader *shader = nullptr; -}; -using BatchedItemList = ccstd::vector; -using DynamicOffsetList = ccstd::vector; - -class CC_DLL BatchedBuffer : public RefCounted { -public: - explicit BatchedBuffer(const scene::Pass *pass); - ~BatchedBuffer() override; - - void destroy(); - void merge(const scene::SubModel *, uint32_t passIdx, const scene::Model *); - void clear(); - void setDynamicOffset(uint32_t idx, uint32_t value); - - inline const BatchedItemList &getBatches() const { return _batches; } - inline const scene::Pass *getPass() const { return _pass; } - inline const DynamicOffsetList &getDynamicOffset() const { return _dynamicOffsets; } - -private: - DynamicOffsetList _dynamicOffsets; - BatchedItemList _batches; - // weak reference - const scene::Pass *_pass{nullptr}; - // weak reference - gfx::Device *_device{nullptr}; -}; - -} // namespace pipeline -} // namespace cc diff --git a/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp b/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp index 992a878d3a..11c7d8ed97 100644 --- a/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp @@ -23,12 +23,10 @@ ****************************************************************************/ #include "ReflectionProbeBatchedQueue.h" -#include "BatchedBuffer.h" #include "Define.h" #include "InstancedBuffer.h" #include "PipelineSceneData.h" #include "PipelineStateManager.h" -#include "RenderBatchedQueue.h" #include "RenderInstancedQueue.h" #include "core/geometry/AABB.h" #include "core/geometry/Intersect.h" @@ -50,7 +48,6 @@ ReflectionProbeBatchedQueue::ReflectionProbeBatchedQueue(RenderPipeline *pipelin : _phaseID(getPhaseID("default")), _phaseReflectMapID(getPhaseID("reflect-map")) { _pipeline = pipeline; _instancedQueue = ccnew RenderInstancedQueue; - _batchedQueue = ccnew RenderBatchedQueue; } ReflectionProbeBatchedQueue::~ReflectionProbeBatchedQueue() { @@ -58,7 +55,6 @@ ReflectionProbeBatchedQueue::~ReflectionProbeBatchedQueue() { } void ReflectionProbeBatchedQueue::destroy() { - CC_SAFE_DELETE(_batchedQueue) CC_SAFE_DELETE(_instancedQueue) } @@ -102,7 +98,6 @@ void ReflectionProbeBatchedQueue::gatherRenderObjects(const scene::Camera *camer } _instancedQueue->uploadBuffers(cmdBuffer); - _batchedQueue->uploadBuffers(cmdBuffer); } void ReflectionProbeBatchedQueue::clear() { @@ -111,7 +106,6 @@ void ReflectionProbeBatchedQueue::clear() { _passes.clear(); _rgbeSubModels.clear(); if (_instancedQueue) _instancedQueue->clear(); - if (_batchedQueue) _batchedQueue->clear(); } void ReflectionProbeBatchedQueue::add(const scene::Model *model) { @@ -146,10 +140,6 @@ void ReflectionProbeBatchedQueue::add(const scene::Model *model) { auto *instancedBuffer = subModel->getPass(passIdx)->getInstancedBuffer(); instancedBuffer->merge(subModel, passIdx); _instancedQueue->add(instancedBuffer); - } else if (batchingScheme == scene::BatchingSchemes::VB_MERGING) { - auto *batchedBuffer = subModel->getPass(passIdx)->getBatchedBuffer(); - batchedBuffer->merge(subModel, passIdx, model); - _batchedQueue->add(batchedBuffer); } else { // standard draw _subModels.emplace_back(subModel); _shaders.emplace_back(subModel->getShader(passIdx)); @@ -160,7 +150,6 @@ void ReflectionProbeBatchedQueue::add(const scene::Model *model) { void ReflectionProbeBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) const { _instancedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); - _batchedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); for (size_t i = 0; i < _subModels.size(); i++) { const auto *const subModel = _subModels[i]; @@ -177,7 +166,6 @@ void ReflectionProbeBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx:: } resetMacro(); if (_instancedQueue) _instancedQueue->clear(); - if (_batchedQueue) _batchedQueue->clear(); } void ReflectionProbeBatchedQueue::resetMacro() const { for (const auto &subModel : _rgbeSubModels) { diff --git a/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.h b/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.h index 08dac4ff3a..7631a8736e 100644 --- a/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.h +++ b/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.h @@ -35,7 +35,6 @@ class ReflectionProbe; namespace pipeline { struct RenderObject; class RenderInstancedQueue; -class RenderBatchedQueue; class RenderPipeline; //const uint32_t phaseID(PassPhase::getPhaseID("shadow-caster")); @@ -69,8 +68,6 @@ private: ccstd::vector _shaders; // manage memory manually RenderInstancedQueue *_instancedQueue{nullptr}; - // manage memory manually - RenderBatchedQueue *_batchedQueue{nullptr}; uint32_t _phaseID{0}; uint32_t _phaseReflectMapID{0}; ccstd::vector _rgbeSubModels; diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index 4542530ca9..94b51c5d12 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -23,14 +23,12 @@ ****************************************************************************/ #include "RenderAdditiveLightQueue.h" -#include "BatchedBuffer.h" #include "Define.h" #include "GlobalDescriptorSetManager.h" #include "InstancedBuffer.h" #include "PipelineSceneData.h" #include "PipelineStateManager.h" #include "PipelineUBO.h" -#include "RenderBatchedQueue.h" #include "RenderInstancedQueue.h" #include "base/Utils.h" #include "forward/ForwardPipeline.h" @@ -76,13 +74,6 @@ void RenderAdditiveLightQueue::recordCommandBuffer(gfx::Device *device, scene::C _instancedQueues[i]->recordCommandBuffer(device, renderPass, cmdBuffer, globalDescriptorSet, offset, &_dynamicOffsets); } - for (size_t i = 0; i < _batchedQueues.size(); ++i) { - const auto *light = _batchedLightPass.lights[i]; - _dynamicOffsets[0] = _batchedLightPass.dynamicOffsets[i]; - auto *globalDescriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(light); - _batchedQueues[i]->recordCommandBuffer(device, renderPass, cmdBuffer, globalDescriptorSet, offset, &_dynamicOffsets); - } - const bool enableOcclusionQuery = _pipeline->isOcclusionQueryEnabled(); for (const auto &lightPass : _lightPasses) { const auto *const subModel = lightPass.subModel; @@ -160,15 +151,10 @@ void RenderAdditiveLightQueue::gatherLightPasses(const scene::Camera *camera, gf const auto *light = _validPunctualLights[l]; _instancedLightPass.lights.emplace_back(light); _instancedLightPass.dynamicOffsets.emplace_back(_lightBufferStride * l); - _batchedLightPass.lights.emplace_back(light); - _batchedLightPass.dynamicOffsets.emplace_back(_lightBufferStride * l); } for (const auto &instancedQueue : _instancedQueues) { instancedQueue->uploadBuffers(cmdBuffer); } - for (const auto &batchedQueue : _batchedQueues) { - batchedQueue->uploadBuffers(cmdBuffer); - } } void RenderAdditiveLightQueue::clear() { @@ -176,10 +162,6 @@ void RenderAdditiveLightQueue::clear() { instancedQueue->clear(); } _instancedQueues.clear(); - for (const auto &batchedQueue : _batchedQueues) { - batchedQueue->clear(); - } - _batchedQueues.clear(); for (auto lightPass : _lightPasses) { lightPass.dynamicOffsets.clear(); @@ -189,9 +171,6 @@ void RenderAdditiveLightQueue::clear() { _instancedLightPass.dynamicOffsets.clear(); _instancedLightPass.lights.clear(); - - _batchedLightPass.dynamicOffsets.clear(); - _batchedLightPass.lights.clear(); } bool RenderAdditiveLightQueue::cullSphereLight(const scene::SphereLight *light, const scene::Model *model) { @@ -240,15 +219,6 @@ void RenderAdditiveLightQueue::addRenderQueue(scene::SubModel *subModel, const s } _instancedQueues[i]->add(buffer); } break; - case scene::BatchingSchemes::VB_MERGING: { - auto *buffer = pass->getBatchedBuffer(i); - buffer->merge(subModel, lightPassIdx, model); - buffer->setDynamicOffset(0, _lightBufferStride); - if (i >= _batchedQueues.size()) { - _batchedQueues.emplace_back(ccnew RenderBatchedQueue()); - } - _batchedQueues[i]->add(buffer); - } break; case scene::BatchingSchemes::NONE: { lightPass.lights.emplace_back(light); lightPass.dynamicOffsets[i] = _lightBufferStride * lightIdx; diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h index f2fe14d90d..4b209caa08 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h @@ -42,7 +42,6 @@ namespace pipeline { struct RenderObject; class RenderPipeline; class RenderInstancedQueue; -class RenderBatchedQueue; class ForwardPipeline; struct AdditiveLightPass { @@ -88,7 +87,6 @@ private: float _lightMeterScale{10000.0F}; AdditiveLightPass _instancedLightPass; - AdditiveLightPass _batchedLightPass; ccstd::vector _dynamicOffsets; ccstd::vector _lightIndices; @@ -101,8 +99,6 @@ private: ccstd::vector> _instancedQueues; - ccstd::vector> _batchedQueues; - ccstd::vector _lightPasses; ccstd::vector> _sortedPSOCIArray; diff --git a/native/cocos/renderer/pipeline/RenderBatchedQueue.cpp b/native/cocos/renderer/pipeline/RenderBatchedQueue.cpp deleted file mode 100644 index 8351f878db..0000000000 --- a/native/cocos/renderer/pipeline/RenderBatchedQueue.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#include "RenderBatchedQueue.h" -#include "BatchedBuffer.h" -#include "PipelineStateManager.h" -#include "gfx-base/GFXCommandBuffer.h" -#include "gfx-base/GFXDevice.h" -#include "gfx-base/GFXRenderPass.h" -#include "scene/Pass.h" - -namespace cc { -namespace pipeline { - -void RenderBatchedQueue::clear() { - for (auto *it : _queues) { - it->clear(); - } - _queues.clear(); -} - -void RenderBatchedQueue::uploadBuffers(gfx::CommandBuffer *cmdBuffer) { - for (const auto *batchedBuffer : _queues) { - const auto &batches = batchedBuffer->getBatches(); - for (const auto &batch : batches) { - if (!batch.mergeCount) continue; - - auto i = 0U; - for (auto *vb : batch.vbs) { - cmdBuffer->updateBuffer(vb, batch.vbDatas[i++], vb->getSize()); - } - cmdBuffer->updateBuffer(batch.indexBuffer, batch.indexData, batch.indexBuffer->getSize()); - cmdBuffer->updateBuffer(batch.ubo, batch.uboData.data(), batch.ubo->getSize()); - } - } -} - -void RenderBatchedQueue::recordCommandBuffer(gfx::Device * /*device*/, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer, - gfx::DescriptorSet *ds, uint32_t offset, const ccstd::vector *dynamicOffsets) { - for (const auto *batchedBuffer : _queues) { - bool boundPSO = false; - const auto &batches = batchedBuffer->getBatches(); - for (const auto &batch : batches) { - if (!batch.mergeCount) continue; - if (!boundPSO) { - auto *pso = PipelineStateManager::getOrCreatePipelineState(batch.pass, batch.shader, batch.ia, renderPass); - cmdBuffer->bindPipelineState(pso); - cmdBuffer->bindDescriptorSet(materialSet, batch.pass->getDescriptorSet()); - boundPSO = true; - } - if (ds) cmdBuffer->bindDescriptorSet(globalSet, ds, 1, &offset); - if (dynamicOffsets) { - cmdBuffer->bindDescriptorSet(localSet, batch.descriptorSet, *dynamicOffsets); - } else { - cmdBuffer->bindDescriptorSet(localSet, batch.descriptorSet, batchedBuffer->getDynamicOffset()); - } - - cmdBuffer->bindInputAssembler(batch.ia); - cmdBuffer->draw(batch.ia); - } - } -} - -void RenderBatchedQueue::add(BatchedBuffer *batchedBuffer) { - _queues.emplace(batchedBuffer); -} - -} // namespace pipeline -} // namespace cc diff --git a/native/cocos/renderer/pipeline/RenderBatchedQueue.h b/native/cocos/renderer/pipeline/RenderBatchedQueue.h deleted file mode 100644 index 3a5747c0a3..0000000000 --- a/native/cocos/renderer/pipeline/RenderBatchedQueue.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -#pragma once - -#include "base/RefCounted.h" -#include "base/std/container/unordered_set.h" -#include "gfx-base/GFXDef.h" - -namespace cc { -namespace gfx { -class Device; -class RenderPass; -class CommandBuffer; -class DescriptorSet; -} // namespace gfx - -namespace pipeline { - -class BatchedBuffer; - -class CC_DLL RenderBatchedQueue final : public RefCounted { -public: - RenderBatchedQueue() = default; - ~RenderBatchedQueue() override = default; - - void clear(); - void uploadBuffers(gfx::CommandBuffer *cmdBuff); - void recordCommandBuffer(gfx::Device *device, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer, - gfx::DescriptorSet *ds = nullptr, uint32_t offset = 0, const ccstd::vector *dynamicOffsets = nullptr); - void add(BatchedBuffer *batchedBuffer); - bool empty() const { return _queues.empty(); } - -private: - // weak reference - ccstd::unordered_set _queues; -}; - -} // namespace pipeline -} // namespace cc diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index e3189d1f75..7cbecfdf11 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -23,7 +23,6 @@ ****************************************************************************/ #include "RenderPipeline.h" -#include "BatchedBuffer.h" #if CC_USE_GEOMETRY_RENDERER #include "GeometryRenderer.h" #endif diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp index 2937efdd9d..7801f3cffd 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp @@ -23,12 +23,10 @@ ****************************************************************************/ #include "ShadowMapBatchedQueue.h" -#include "BatchedBuffer.h" #include "Define.h" #include "InstancedBuffer.h" #include "PipelineSceneData.h" #include "PipelineStateManager.h" -#include "RenderBatchedQueue.h" #include "RenderInstancedQueue.h" #include "SceneCulling.h" #include "forward/ForwardPipeline.h" @@ -47,7 +45,6 @@ ShadowMapBatchedQueue::ShadowMapBatchedQueue(RenderPipeline *pipeline) : _phaseID(getPhaseID("shadow-caster")) { _pipeline = pipeline; _instancedQueue = ccnew RenderInstancedQueue; - _batchedQueue = ccnew RenderBatchedQueue; } ShadowMapBatchedQueue::~ShadowMapBatchedQueue() = default; @@ -105,7 +102,6 @@ void ShadowMapBatchedQueue::gatherLightPasses(const scene::Camera *camera, const } _instancedQueue->uploadBuffers(cmdBuffer); - _batchedQueue->uploadBuffers(cmdBuffer); } } @@ -114,7 +110,6 @@ void ShadowMapBatchedQueue::clear() { _shaders.clear(); _passes.clear(); if (_instancedQueue) _instancedQueue->clear(); - if (_batchedQueue) _batchedQueue->clear(); } void ShadowMapBatchedQueue::add(const scene::Model *model) { @@ -131,10 +126,6 @@ void ShadowMapBatchedQueue::add(const scene::Model *model) { auto *instancedBuffer = subModel->getPass(shadowPassIdx)->getInstancedBuffer(); instancedBuffer->merge(subModel, shadowPassIdx); _instancedQueue->add(instancedBuffer); - } else if (batchingScheme == scene::BatchingSchemes::VB_MERGING) { - auto *batchedBuffer = subModel->getPass(shadowPassIdx)->getBatchedBuffer(); - batchedBuffer->merge(subModel, shadowPassIdx, model); - _batchedQueue->add(batchedBuffer); } else { // standard draw _subModels.emplace_back(subModel); _shaders.emplace_back(subModel->getShader(shadowPassIdx)); @@ -145,7 +136,6 @@ void ShadowMapBatchedQueue::add(const scene::Model *model) { void ShadowMapBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) const { _instancedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); - _batchedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); for (size_t i = 0; i < _subModels.size(); i++) { const auto *const subModel = _subModels[i]; @@ -163,8 +153,6 @@ void ShadowMapBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::Render } void ShadowMapBatchedQueue::destroy() { - CC_SAFE_DELETE(_batchedQueue) - CC_SAFE_DELETE(_instancedQueue) } diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h index 40adf9203d..825ffa2b38 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h @@ -34,7 +34,6 @@ class Pass; namespace pipeline { struct RenderObject; class RenderInstancedQueue; -class RenderBatchedQueue; class RenderPipeline; //const uint32_t phaseID(PassPhase::getPhaseID("shadow-caster")); @@ -63,8 +62,6 @@ private: ccstd::vector _shaders; // manage memory manually RenderInstancedQueue *_instancedQueue{nullptr}; - // manage memory manually - RenderBatchedQueue *_batchedQueue{nullptr}; uint32_t _phaseID = 0; }; diff --git a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp index 54edbf3664..8d7db93077 100644 --- a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp @@ -24,12 +24,10 @@ ****************************************************************************/ #include "GbufferStage.h" -#include "../BatchedBuffer.h" #include "../InstancedBuffer.h" #include "../PipelineSceneData.h" #include "../PipelineUBO.h" #include "../PlanarShadowQueue.h" -#include "../RenderBatchedQueue.h" #include "../RenderInstancedQueue.h" #include "../RenderQueue.h" #include "DeferredPipeline.h" @@ -53,7 +51,6 @@ RenderStageInfo GbufferStage::initInfo = { const RenderStageInfo &GbufferStage::getInitializeInfo() { return GbufferStage::initInfo; } GbufferStage::GbufferStage() { - _batchedQueue = ccnew RenderBatchedQueue; _instancedQueue = ccnew RenderInstancedQueue; } @@ -79,7 +76,6 @@ void GbufferStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { } void GbufferStage::destroy() { - CC_SAFE_DELETE(_batchedQueue); CC_SAFE_DELETE(_instancedQueue); CC_SAFE_DESTROY_AND_DELETE(_planarShadowQueue); RenderStage::destroy(); @@ -87,7 +83,6 @@ void GbufferStage::destroy() { void GbufferStage::dispenseRenderObject2Queues() { _instancedQueue->clear(); - _batchedQueue->clear(); const auto &renderObjects = _pipeline->getPipelineSceneData()->getRenderObjects(); for (auto *queue : _renderQueues) { @@ -112,10 +107,6 @@ void GbufferStage::dispenseRenderObject2Queues() { auto *instancedBuffer = pass->getInstancedBuffer(); instancedBuffer->merge(subModel, passIdx); _instancedQueue->add(instancedBuffer); - } else if (pass->getBatchingScheme() == scene::BatchingSchemes::VB_MERGING) { - auto *batchedBuffer = pass->getBatchedBuffer(); - batchedBuffer->merge(subModel, passIdx, model); - _batchedQueue->add(batchedBuffer); } else { for (k = 0; k < _renderQueues.size(); k++) { _renderQueues[k]->insertRenderPass(ro, subModelIdx, passIdx); @@ -139,7 +130,6 @@ void GbufferStage::recordCommands(DeferredPipeline *pipeline, scene::Camera *cam // record commands _renderQueues[0]->recordCommandBuffer(_device, camera, renderPass, cmdBuff); _instancedQueue->recordCommandBuffer(_device, renderPass, cmdBuff); - _batchedQueue->recordCommandBuffer(_device, renderPass, cmdBuff); } void GbufferStage::render(scene::Camera *camera) { @@ -234,10 +224,9 @@ void GbufferStage::render(scene::Camera *camera) { dispenseRenderObject2Queues(); auto *cmdBuff = pipeline->getCommandBuffers()[0]; _instancedQueue->uploadBuffers(cmdBuff); - _batchedQueue->uploadBuffers(cmdBuff); // if empty == true, gbuffer and lightig passes will be ignored - bool empty = _renderQueues[0]->empty() && _instancedQueue->empty() && _batchedQueue->empty(); + bool empty = _renderQueues[0]->empty() && _instancedQueue->empty(); if (!empty) { pipeline->getFrameGraph().addPass(static_cast(DeferredInsertPoint::DIP_GBUFFER), DeferredPipeline::fgStrHandleGbufferPass, gbufferSetup, gbufferExec); } diff --git a/native/cocos/renderer/pipeline/deferred/GbufferStage.h b/native/cocos/renderer/pipeline/deferred/GbufferStage.h index d0540251fa..28c1d0e442 100644 --- a/native/cocos/renderer/pipeline/deferred/GbufferStage.h +++ b/native/cocos/renderer/pipeline/deferred/GbufferStage.h @@ -34,7 +34,6 @@ class Camera; namespace pipeline { class RenderFlow; -class RenderBatchedQueue; class RenderInstancedQueue; class RenderAdditiveLightQueue; class PlanarShadowQueue; @@ -60,7 +59,6 @@ private: static RenderStageInfo initInfo; PlanarShadowQueue *_planarShadowQueue = nullptr; - RenderBatchedQueue *_batchedQueue = nullptr; RenderInstancedQueue *_instancedQueue = nullptr; uint32_t _phaseID = 0; }; diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index c052f5cc4c..5c1aace21e 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -24,7 +24,6 @@ ****************************************************************************/ #include "LightingStage.h" -#include "../BatchedBuffer.h" #include "../Define.h" #if CC_USE_GEOMETRY_RENDERER #include "../GeometryRenderer.h" @@ -34,7 +33,6 @@ #include "../PipelineStateManager.h" #include "../PipelineUBO.h" #include "../PlanarShadowQueue.h" -#include "../RenderBatchedQueue.h" #include "../RenderInstancedQueue.h" #include "../RenderQueue.h" #include "DeferredPipeline.h" diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.h b/native/cocos/renderer/pipeline/deferred/LightingStage.h index 3752ee887a..82ab4830be 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.h +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.h @@ -33,7 +33,6 @@ namespace cc { namespace pipeline { class RenderFlow; -class RenderBatchedQueue; class RenderInstancedQueue; class RenderAdditiveLightQueue; class PlanarShadowQueue; diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index 1a5a47ecda..9837c1448a 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -23,7 +23,6 @@ ****************************************************************************/ #include "ForwardStage.h" -#include "../BatchedBuffer.h" #if CC_USE_GEOMETRY_RENDERER #include "../GeometryRenderer.h" #endif @@ -32,7 +31,6 @@ #include "../PipelineUBO.h" #include "../PlanarShadowQueue.h" #include "../RenderAdditiveLightQueue.h" -#include "../RenderBatchedQueue.h" #include "../RenderInstancedQueue.h" #include "../RenderQueue.h" #include "../helper/Utils.h" @@ -56,7 +54,6 @@ RenderStageInfo ForwardStage::initInfo = { const RenderStageInfo &ForwardStage::getInitializeInfo() { return ForwardStage::initInfo; } ForwardStage::ForwardStage() { - _batchedQueue = ccnew RenderBatchedQueue; _instancedQueue = ccnew RenderInstancedQueue; _uiPhase = ccnew UIPhase; } @@ -86,7 +83,6 @@ void ForwardStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { } void ForwardStage::destroy() { - CC_SAFE_DELETE(_batchedQueue); CC_SAFE_DELETE(_instancedQueue); CC_SAFE_DELETE(_additiveLightQueue); CC_SAFE_DESTROY_AND_DELETE(_planarShadowQueue); @@ -98,7 +94,6 @@ void ForwardStage::dispenseRenderObject2Queues() { if (!_pipeline->isRenderQueueReset()) return; _instancedQueue->clear(); - _batchedQueue->clear(); const auto *sceneData = _pipeline->getPipelineSceneData(); const auto &renderObjects = sceneData->getRenderObjects(); @@ -122,10 +117,6 @@ void ForwardStage::dispenseRenderObject2Queues() { auto *instancedBuffer = pass->getInstancedBuffer(); instancedBuffer->merge(subModel, passIdx); _instancedQueue->add(instancedBuffer); - } else if (pass->getBatchingScheme() == scene::BatchingSchemes::VB_MERGING) { - auto *batchedBuffer = pass->getBatchedBuffer(); - batchedBuffer->merge(subModel, passIdx, model); - _batchedQueue->add(batchedBuffer); } else { for (auto *renderQueue : _renderQueues) { renderQueue->insertRenderPass(ro, subModelIdx, passIdx); @@ -159,7 +150,6 @@ void ForwardStage::render(scene::Camera *camera) { pipeline->getPipelineUBO()->updateShadowUBO(camera); _instancedQueue->uploadBuffers(cmdBuff); - _batchedQueue->uploadBuffers(cmdBuff); _additiveLightQueue->gatherLightPasses(camera, cmdBuff); _planarShadowQueue->gatherShadowPasses(camera, cmdBuff); auto forwardSetup = [&](framegraph::PassNodeBuilder &builder, RenderData &data) { @@ -263,8 +253,6 @@ void ForwardStage::render(scene::Camera *camera) { if (!_pipeline->getPipelineSceneData()->getRenderObjects().empty()) { _renderQueues[0]->recordCommandBuffer(_device, camera, renderPass, cmdBuff); _instancedQueue->recordCommandBuffer(_device, renderPass, cmdBuff); - _batchedQueue->recordCommandBuffer(_device, renderPass, cmdBuff); - _additiveLightQueue->recordCommandBuffer(_device, camera, renderPass, cmdBuff); cmdBuff->bindDescriptorSet(globalSet, _pipeline->getDescriptorSet(), 1, &offset); diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.h b/native/cocos/renderer/pipeline/forward/ForwardStage.h index d3730fc5b2..50bdc7002e 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.h +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.h @@ -30,7 +30,6 @@ namespace cc { namespace pipeline { class RenderFlow; -class RenderBatchedQueue; class RenderInstancedQueue; class RenderAdditiveLightQueue; class PlanarShadowQueue; @@ -55,8 +54,6 @@ private: // manage memory manually PlanarShadowQueue *_planarShadowQueue{nullptr}; // manage memory manually - RenderBatchedQueue *_batchedQueue{nullptr}; - // manage memory manually RenderInstancedQueue *_instancedQueue{nullptr}; // manage memory manually RenderAdditiveLightQueue *_additiveLightQueue{nullptr}; diff --git a/native/cocos/scene/Pass.cpp b/native/cocos/scene/Pass.cpp index 33a3442f4e..21a291ae52 100644 --- a/native/cocos/scene/Pass.cpp +++ b/native/cocos/scene/Pass.cpp @@ -37,7 +37,6 @@ #include "renderer/core/ProgramLib.h" #include "renderer/gfx-base/GFXDef.h" #include "renderer/gfx-base/states/GFXSampler.h" -#include "renderer/pipeline/BatchedBuffer.h" #include "renderer/pipeline/Define.h" #include "renderer/pipeline/InstancedBuffer.h" #include "scene/Define.h" @@ -296,16 +295,6 @@ pipeline::InstancedBuffer *Pass::getInstancedBuffer(int32_t extraKey) { return instancedBuffer; } -pipeline::BatchedBuffer *Pass::getBatchedBuffer(int32_t extraKey) { - auto iter = _batchedBuffers.find(extraKey); - if (iter != _batchedBuffers.end()) { - return iter->second.get(); - } - auto *batchedBuffers = ccnew pipeline::BatchedBuffer(this); - _batchedBuffers[extraKey] = batchedBuffers; - return batchedBuffers; -} - void Pass::destroy() { if (!_buffers.empty()) { for (const auto &u : _shaderInfo->blocks) { @@ -325,11 +314,6 @@ void Pass::destroy() { } _instancedBuffers.clear(); - for (auto &bb : _batchedBuffers) { - bb.second->destroy(); - } - _batchedBuffers.clear(); - // NOTE: There may be many passes reference the same descriptor set, // so here we can't use _descriptorSet->destroy() to release it. // Its type is IntrusivePtr, so just set it to nullptr, @@ -823,12 +807,7 @@ void Pass::syncBatchingScheme() { _batchingScheme = BatchingSchemes::NONE; } } else { - auto iter = _defines.find("USE_BATCHING"); - if (iter != _defines.end() && macroRecordAsBool(iter->second)) { - _batchingScheme = BatchingSchemes::VB_MERGING; - } else { - _batchingScheme = BatchingSchemes::NONE; - } + _batchingScheme = BatchingSchemes::NONE; } } diff --git a/native/cocos/scene/Pass.h b/native/cocos/scene/Pass.h index 6e264f11a9..a00b5f231c 100644 --- a/native/cocos/scene/Pass.h +++ b/native/cocos/scene/Pass.h @@ -44,7 +44,6 @@ class Root; struct IProgramInfo; namespace pipeline { class InstancedBuffer; -class BatchedBuffer; } // namespace pipeline namespace scene { struct IMacroPatch; @@ -58,7 +57,6 @@ using IPassDynamics = ccstd::unordered_map; enum class BatchingSchemes { NONE = 0, INSTANCING = 1, - VB_MERGING = 2, }; struct IBlockRef { @@ -208,7 +206,6 @@ public: void update(); pipeline::InstancedBuffer *getInstancedBuffer(int32_t extraKey = 0); - pipeline::BatchedBuffer *getBatchedBuffer(int32_t extraKey = 0); /** * @en Destroy the current pass. @@ -355,7 +352,6 @@ protected: BatchingSchemes _batchingScheme{BatchingSchemes::NONE}; gfx::DynamicStateFlagBit _dynamicStates{gfx::DynamicStateFlagBit::NONE}; ccstd::unordered_map> _instancedBuffers; - ccstd::unordered_map> _batchedBuffers; ccstd::hash_t _hash{0U}; // external references diff --git a/native/cocos/scene/SubModel.cpp b/native/cocos/scene/SubModel.cpp index 88e07cf864..f26da93178 100644 --- a/native/cocos/scene/SubModel.cpp +++ b/native/cocos/scene/SubModel.cpp @@ -102,9 +102,6 @@ void SubModel::setPasses(const std::shared_ptr> flushPassInfo(); const auto &passes = *_passes; - if (passes[0]->getBatchingScheme() == BatchingSchemes::VB_MERGING) { - _subMesh->genFlatBuffers(); - } // DS layout might change too if (_descriptorSet) { _descriptorSet->destroy(); @@ -154,9 +151,6 @@ void SubModel::initialize(RenderingSubMesh *subMesh, const std::shared_ptrgetBatchingScheme() == BatchingSchemes::VB_MERGING) { - subMesh->genFlatBuffers(); - } _priority = pipeline::RenderPriority::DEFAULT; // initialize resources for reflection material @@ -365,9 +359,6 @@ void SubModel::setSubMesh(RenderingSubMesh *subMesh) { const auto &passes = *_passes; _inputAssembler->destroy(); _inputAssembler->initialize(subMesh->getIaInfo()); - if (passes[0]->getBatchingScheme() == BatchingSchemes::VB_MERGING) { - subMesh->genFlatBuffers(); - } _subMesh = subMesh; } diff --git a/native/tools/swig-config/pipeline.i b/native/tools/swig-config/pipeline.i index fca830d950..64e34412ac 100644 --- a/native/tools/swig-config/pipeline.i +++ b/native/tools/swig-config/pipeline.i @@ -24,7 +24,6 @@ #include "renderer/pipeline/deferred/BloomStage.h" #include "renderer/pipeline/deferred/PostProcessStage.h" #include "renderer/pipeline/PipelineSceneData.h" -#include "renderer/pipeline/BatchedBuffer.h" #include "renderer/pipeline/GeometryRenderer.h" #include "renderer/pipeline/DebugView.h" #include "renderer/pipeline/reflection-probe/ReflectionProbeFlow.h" @@ -245,7 +244,6 @@ using namespace cc; %include "renderer/pipeline/deferred/BloomStage.h" %include "renderer/pipeline/deferred/PostProcessStage.h" %include "renderer/pipeline/PipelineSceneData.h" -%include "renderer/pipeline/BatchedBuffer.h" %include "renderer/pipeline/GeometryRenderer.h" %include "renderer/pipeline/reflection-probe/ReflectionProbeFlow.h"