Files
cocos4/cocos/core/pipeline/render-batched-queue.ts
T
Yun Hsiao Wu dfc3d141f2 GFX Descriptor Set (#7101)
* gfx: descriptor sets

* gfx: descriptor set, singular

* better structure

* adapt upper layers: first pass

finally all compiler errors cleared.

OKAY IT'S HAPPENING EVERYBODY STAY THE ****ING CALM

* adapt upper layers: second pass

THERE AND BACK AGAIN

* unified light pass & shadow shader

* gfx: descriptor set & pipeline layout

* light pass: better structure

* light pass: dynamic uniform

* even more type checking for memory pools

* Fix particleSystem and lineComponent.

* delete comment

* guard pool init param

* Fix trail module error.

* delete space

* light pass: instancing & batching support

* don't polyfill gfx stuff inside EffectAsset

* better light pass structure

* fix spot light culling

Co-authored-by: caryliu <caryliu1999@gmail.com>
2020-08-13 18:21:15 +08:00

67 lines
2.4 KiB
TypeScript

/**
* @category pipeline
*/
import { GFXCommandBuffer } from '../gfx/command-buffer';
import { BatchedBuffer } from './batched-buffer';
import { PipelineStateManager } from './pipeline-state-manager';
import { GFXDevice } from '../gfx/device';
import { GFXRenderPass } from '../gfx';
import { DSPool, ShaderPool, PassPool, PassView } from '../renderer/core/memory-pools';
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<BatchedBuffer>();
/**
* @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();
}
/**
* @en Record command buffer for the current queue
* @zh 记录命令缓冲。
* @param cmdBuff The command buffer to store the result
*/
public recordCommandBuffer (device: GFXDevice, renderPass: GFXRenderPass, cmdBuff: GFXCommandBuffer) {
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; }
for (let v = 0; v < batch.vbs.length; ++v) {
batch.vbs[v].update(batch.vbDatas[v]);
}
batch.vbIdx.update(batch.vbIdxData.buffer);
batch.ubo.update(batch.uboData.view);
const shader = ShaderPool.get(batch.hShader);
const pso = PipelineStateManager.getOrCreatePipelineState(device, batch.hPass, shader, renderPass, batch.ia);
if (!boundPSO) { cmdBuff.bindPipelineState(pso); boundPSO = true; }
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, DSPool.get(PassPool.get(batch.hPass, PassView.DESCRIPTOR_SET)));
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, batch.descriptorSet, res.value.dynamicOffsets);
cmdBuff.bindInputAssembler(batch.ia);
cmdBuff.draw(batch.ia);
}
res = it.next();
}
}
}