Skip to content

Commit

Permalink
Fix surface-shader
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS committed Nov 11, 2024
1 parent e4bf2e1 commit 1c9d11e
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions cocos/rendering/custom/web-pipeline-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,37 +901,48 @@ export class RenderDrawQueue {
}

export class RenderInstancingQueue {
/**
* @en A set of instanced buffer
* @zh Instance 合批缓存集合。
*/
public queue = new Set<InstancedBuffer>();
passInstances: Map<Pass, number> = new Map<Pass, number>();
instanceBuffers: Array<InstancedBuffer> = new Array<InstancedBuffer>();

empty (): boolean {
return this.queue.size === 0;
return this.passInstances.size === 0;
}

add (pass: Pass, subModel: SubModel, passID: number): void {
const instancedBuffer = pass.getInstancedBuffer();
const iter = this.passInstances.get(pass);
if (iter === undefined) {
const instanceBufferID = this.passInstances.size;
if (instanceBufferID >= this.instanceBuffers.length) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.instanceBuffers.push(new InstancedBuffer(pass));
}
this.passInstances.set(pass, instanceBufferID);

const instanceBuffer = this.instanceBuffers[instanceBufferID];
instanceBuffer.pass = pass;
const instances = instanceBuffer.instances;
}

const instancedBuffer = this.instanceBuffers[this.passInstances.get(pass)!];
instancedBuffer.merge(subModel, passID);
this.queue.add(instancedBuffer);
}

clear (): void {
const it = this.queue.values(); let res = it.next();
while (!res.done) {
res.value.clear();
res = it.next();
}
this.queue.clear();
this.passInstances.clear();
const instanceBuffers = this.instanceBuffers;
instanceBuffers.forEach((instance) => {
instance.clear();
});
}

sort (): void {}

uploadBuffers (cmdBuffer: CommandBuffer): void {
const it = this.queue.values(); let res = it.next();
while (!res.done) {
if (res.value.hasPendingModels) res.value.uploadBuffers(cmdBuffer);
res = it.next();
for (const [pass, bufferID] of this.passInstances.entries()) {
const instanceBuffer = this.instanceBuffers[bufferID];
if (instanceBuffer.hasPendingModels) {
instanceBuffer.uploadBuffers(cmdBuffer);
}
}
}

Expand All @@ -942,7 +953,7 @@ export class RenderInstancingQueue {
offset = 0,
dynamicOffsets: number[] | null = null,
): void {
const renderQueue = this.queue;
const renderQueue = this.instanceBuffers;
for (const instanceBuffer of renderQueue) {
if (!instanceBuffer.hasPendingModels) {
continue;
Expand Down

0 comments on commit 1c9d11e

Please sign in to comment.