diff --git a/web/src/webgpu.ts b/web/src/webgpu.ts index 199fa14235ee..43fb7a3ed6e7 100644 --- a/web/src/webgpu.ts +++ b/web/src/webgpu.ts @@ -423,6 +423,7 @@ export class WebGPUContext { private uniformBufferPool: Array = []; private uniformBufferPoolSizes: Array = []; private pendingDispatchCount = 0; + maxDispatchesPerFlush = 32; // flags for debugging // stats of the runtime. // peak allocation @@ -799,6 +800,11 @@ export class WebGPUContext { compute.dispatchWorkgroups(workDim[0], workDim[1], workDim[2]); compute.end(); + if (this.maxDispatchesPerFlush <= 0 || + this.pendingDispatchCount >= this.maxDispatchesPerFlush) { + this.flushCommands(); + } + // In debug mode, flush immediately so we can observe each submission. if (this.debugLogFinish) { this.flushCommands();