fix instanced buffers hashing (#7240)

This commit is contained in:
Yun Hsiao Wu
2020-08-28 11:47:28 +08:00
committed by GitHub
parent c99525cb7f
commit be21e64f15
4 changed files with 25 additions and 23 deletions
+7 -1
View File
@@ -1604,7 +1604,13 @@ export function WebGLCmdFuncBeginRenderPass (
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
cache.glFramebuffer = gpuFramebuffer.glFramebuffer;
// render targets are drawn with flipped-Y
gfxStateCache.reverseCW = !!gpuFramebuffer.glFramebuffer;
const reverseCW = !!gpuFramebuffer.glFramebuffer;
if (reverseCW !== gfxStateCache.reverseCW) {
gfxStateCache.reverseCW = reverseCW;
const isCCW = !device.stateCache.rs.isFrontFaceCCW;
gl.frontFace(isCCW ? gl.CCW : gl.CW);
device.stateCache.rs.isFrontFaceCCW = isCCW;
}
}
if (cache.viewport.left !== renderArea.x ||
+8 -2
View File
@@ -1830,7 +1830,13 @@ export function WebGL2CmdFuncBeginRenderPass (
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
cache.glFramebuffer = gpuFramebuffer.glFramebuffer;
// render targets are drawn with flipped-Y
gfxStateCache.reverseCW = !!gpuFramebuffer.glFramebuffer;
const reverseCW = !!gpuFramebuffer.glFramebuffer;
if (reverseCW !== gfxStateCache.reverseCW) {
gfxStateCache.reverseCW = reverseCW;
const isCCW = !device.stateCache.rs.isFrontFaceCCW;
gl.frontFace(isCCW ? gl.CCW : gl.CW);
device.stateCache.rs.isFrontFaceCCW = isCCW;
}
}
if (cache.viewport.left !== renderArea.x ||
@@ -2045,7 +2051,7 @@ export function WebGL2CmdFuncBindStates (
device.stateCache.rs.cullMode = rs.cullMode;
}
const isFrontFaceCCW = gfxStateCache.reverseCW ? !rs.isFrontFaceCCW : rs.isFrontFaceCCW;
const isFrontFaceCCW = rs.isFrontFaceCCW !== gfxStateCache.reverseCW; // boolean XOR
if (device.stateCache.rs.isFrontFaceCCW !== isFrontFaceCCW) {
gl.frontFace(isFrontFaceCCW ? gl.CCW : gl.CW);
device.stateCache.rs.isFrontFaceCCW = isFrontFaceCCW;
+5 -11
View File
@@ -26,21 +26,15 @@ export interface IBatchedItem {
hShader: ShaderHandle;
}
const _localBatched = new UBOLocalBatched();
export class BatchedBuffer {
private static _buffers = new Map<Pass | number, BatchedBuffer>();
private static _buffers = new Map<Pass, Record<number, BatchedBuffer>>();
public static get (pass: Pass, extraKey?: number) {
const hash = extraKey ? pass.hash ^ extraKey : pass.hash;
public static get (pass: Pass, extraKey = 0) {
const buffers = BatchedBuffer._buffers;
if (!buffers.has(hash)) {
const buffer = new BatchedBuffer(pass);
buffers.set(hash, buffer);
return buffer;
}
return buffers.get(hash)!;
if (!buffers.has(pass)) buffers.set(pass, {});
const record = buffers.get(pass)!;
return record[extraKey] || (record[extraKey] = new BatchedBuffer(pass));
}
public batches: IBatchedItem[] = [];
+5 -9
View File
@@ -27,17 +27,13 @@ const MAX_CAPACITY = 1024;
export class InstancedBuffer {
private static _buffers = new Map<Pass | number, InstancedBuffer>();
private static _buffers = new Map<Pass, Record<number, InstancedBuffer>>();
public static get (pass: Pass, extraKey?: number) {
const hash = extraKey ? pass.hash ^ extraKey : pass.hash;
public static get (pass: Pass, extraKey = 0) {
const buffers = InstancedBuffer._buffers;
if (!buffers.has(hash)) {
const buffer = new InstancedBuffer(pass);
buffers.set(hash, buffer);
return buffer;
}
return buffers.get(hash)!;
if (!buffers.has(pass)) buffers.set(pass, {});
const record = buffers.get(pass)!;
return record[extraKey] || (record[extraKey] = new InstancedBuffer(pass));
}
public instances: IInstancedItem[] = [];