• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / luma.gl / 28601425812

02 Jul 2026 03:21PM UTC coverage: 71.25% (-0.002%) from 71.252%
28601425812

Pull #2706

github

web-flow
Merge 43f44858b into ee8298f81
Pull Request #2706: fix(gpgpu) buffer size limits

10131 of 16110 branches covered (62.89%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 1 file covered. (50.0%)

20257 of 26540 relevant lines covered (76.33%)

4348.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/modules/gpgpu/src/utils/buffer-pool.ts
1
// luma.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import {Device, Buffer} from '@luma.gl/core';
6

7
class BufferPool {
8
  poolSize: number = 100;
21✔
9

10
  private bufferPools: Map<Device, Buffer[]>;
11

12
  constructor() {
13
    this.bufferPools = new Map();
21✔
14
  }
15

16
  createOrReuse(device: Device, byteLength: number): Buffer {
17
    if (byteLength > device.limits.maxBufferSize) {
497!
NEW
18
      throw new Error(
×
19
        `Buffer pool cannot allocate ${byteLength} bytes: device.limits.maxBufferSize is ${device.limits.maxBufferSize}`
20
      );
21
    }
22

23
    const pool = this.bufferPools.get(device);
497✔
24
    const i = pool ? pool.findIndex(b => b.byteLength >= byteLength) : -1;
497✔
25
    if (i < 0) {
497✔
26
      return device.createBuffer({
179✔
27
        usage: Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_DST | Buffer.COPY_SRC,
28
        byteLength
29
      });
30
    }
31
    const [result] = pool!.splice(i, 1);
318✔
32
    return result;
318✔
33
  }
34

35
  recycle(buffer: Buffer) {
36
    const device = buffer.device;
492✔
37
    if (!this.bufferPools.has(device)) {
492✔
38
      this.bufferPools.set(device, []);
51✔
39
    }
40
    const pool = this.bufferPools.get(device)!;
492✔
41
    // Sort buffers by increasing size
42
    const i = pool.findIndex(b => b.byteLength > buffer.byteLength);
608✔
43
    if (i < 0) {
492✔
44
      pool.push(buffer);
394✔
45
    } else {
46
      pool.splice(i, 0, buffer);
98✔
47
    }
48
    while (this.poolSize && pool.length > this.poolSize) {
492✔
49
      // Drop the smallest one
50
      pool.shift()!.destroy();
×
51
    }
52
  }
53
}
54

55
export const bufferPool = new BufferPool();
21✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc