* Return a MAP_READ staging buffer to the pool for reuse. * Evicts the smallest buffer if the pool is full.
(buf: GPUBuffer)
| 985 | * Evicts the smallest buffer if the pool is full. |
| 986 | */ |
| 987 | private recycleReadStagingBuffer(buf: GPUBuffer): void { |
| 988 | buf.unmap(); |
| 989 | if (this.readStagingBufferPool.length >= this.maxReadStagingBuffers) { |
| 990 | // Evict smallest buffer to make room |
| 991 | let minIdx = 0; |
| 992 | for (let i = 1; i < this.readStagingBufferPool.length; i++) { |
| 993 | if (this.readStagingBufferPool[i].size < this.readStagingBufferPool[minIdx].size) { |
| 994 | minIdx = i; |
| 995 | } |
| 996 | } |
| 997 | this.readStagingBufferPool.splice(minIdx, 1)[0].buffer.destroy(); |
| 998 | } |
| 999 | this.readStagingBufferPool.push({ buffer: buf, size: buf.size }); |
| 1000 | } |
| 1001 | |
| 1002 | private deviceCopyFromGPU( |
| 1003 | from: GPUPointer, |