* Get a MAP_READ staging buffer from the pool, or create one if none fits. * Uses first-fit-by-size: returns the first pooled buffer >= nbytes.
(nbytes: number)
| 968 | * Uses first-fit-by-size: returns the first pooled buffer >= nbytes. |
| 969 | */ |
| 970 | private getOrCreateReadStagingBuffer(nbytes: number): GPUBuffer { |
| 971 | for (let i = 0; i < this.readStagingBufferPool.length; i++) { |
| 972 | if (this.readStagingBufferPool[i].size >= nbytes) { |
| 973 | const entry = this.readStagingBufferPool.splice(i, 1)[0]; |
| 974 | return entry.buffer; |
| 975 | } |
| 976 | } |
| 977 | return tryCreateBuffer(this.device, { |
| 978 | size: nbytes, |
| 979 | usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST, |
| 980 | }); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Return a MAP_READ staging buffer to the pool for reuse. |
no test coverage detected