mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 19:42:39 +08:00
dfc3d141f2
* 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>
67 lines
2.4 KiB
TypeScript
67 lines
2.4 KiB
TypeScript
/**
|
|
* @category pipeline
|
|
*/
|
|
|
|
import { GFXCommandBuffer } from '../gfx/command-buffer';
|
|
import { InstancedBuffer } from './instanced-buffer';
|
|
import { GFXDevice, GFXRenderPass, GFXPipelineState } from '../gfx';
|
|
import { PipelineStateManager } from './pipeline-state-manager';
|
|
import { DSPool, ShaderPool, PassPool, PassView } from '../renderer/core/memory-pools';
|
|
import { SetIndex } from './define';
|
|
|
|
/**
|
|
* @en Render queue for instanced batching
|
|
* @zh 渲染合批队列。
|
|
*/
|
|
export class RenderInstancedQueue {
|
|
|
|
/**
|
|
* @en A set of instanced buffer
|
|
* @zh Instance 合批缓存集合。
|
|
*/
|
|
public queue = new Set<InstancedBuffer>();
|
|
|
|
/**
|
|
* @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) {
|
|
const { instances, hPass, hasPendingModels } = res.value;
|
|
if (!hasPendingModels) { continue; }
|
|
res.value.uploadBuffers();
|
|
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, DSPool.get(PassPool.get(hPass, PassView.DESCRIPTOR_SET)));
|
|
let lastPSO: GFXPipelineState | null = null;
|
|
for (let b = 0; b < instances.length; ++b) {
|
|
const instance = instances[b];
|
|
if (!instance.count) { continue; }
|
|
const shader = ShaderPool.get(instance.hShader);
|
|
const pso = PipelineStateManager.getOrCreatePipelineState(device, hPass, shader, renderPass, instance.ia);
|
|
if (lastPSO !== pso) {
|
|
cmdBuff.bindPipelineState(pso);
|
|
lastPSO = pso;
|
|
}
|
|
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, DSPool.get(instance.hDescriptorSet), res.value.dynamicOffsets);
|
|
cmdBuff.bindInputAssembler(instance.ia);
|
|
cmdBuff.draw(instance.ia);
|
|
}
|
|
res = it.next();
|
|
}
|
|
}
|
|
}
|