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

visgl / luma.gl / 27877205100

20 Jun 2026 04:32PM UTC coverage: 70.733% (+0.08%) from 70.652%
27877205100

push

github

web-flow
feat(engine) add portable video textures (#2677)

9660 of 15389 branches covered (62.77%)

Branch coverage included in aggregate %.

99 of 116 new or added lines in 2 files covered. (85.34%)

379 existing lines in 28 files now uncovered.

19717 of 26143 relevant lines covered (75.42%)

4107.12 hits per line

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

77.24
/modules/webgpu/src/adapter/webgpu-device.ts
1
// luma.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
// biome-ignore format: preserve layout
6
// / <reference types="@webgpu/types" />
7

8
import type {
9
  Bindings,
10
  ComputePipeline,
11
  ComputeShaderLayout,
12
  DeviceInfo,
13
  DeviceLimits,
14
  DeviceFeature,
15
  DeviceTextureFormatCapabilities,
16
  VertexFormat,
17
  CanvasContextProps,
18
  PresentationContextProps,
19
  PresentationContext,
20
  BufferProps,
21
  SamplerProps,
22
  ShaderProps,
23
  TextureProps,
24
  Texture,
25
  ExternalTextureProps,
26
  FramebufferProps,
27
  RenderPipelineProps,
28
  ComputePipelineProps,
29
  VertexArrayProps,
30
  TransformFeedback,
31
  TransformFeedbackProps,
32
  QuerySet,
33
  QuerySetProps,
34
  DeviceProps,
35
  CommandEncoderProps,
36
  CommandEncoder,
37
  PipelineLayoutProps,
38
  RenderPipeline,
39
  RenderBundleEncoderProps,
40
  ShaderLayout
41
} from '@luma.gl/core';
42
import {Buffer, Device, DeviceFeatures} from '@luma.gl/core';
43
import {WebGPUBuffer} from './resources/webgpu-buffer';
44
import {WebGPUTexture} from './resources/webgpu-texture';
45
import {WebGPUExternalTexture} from './resources/webgpu-external-texture';
46
import {WebGPUSampler, type WebGPUSamplerProps} from './resources/webgpu-sampler';
47
import {WebGPUShader} from './resources/webgpu-shader';
48
import {WebGPURenderPipeline} from './resources/webgpu-render-pipeline';
49
import {WebGPURenderBundleEncoder} from './resources/webgpu-render-bundle';
50
import {WebGPUFramebuffer} from './resources/webgpu-framebuffer';
51
import {WebGPUComputePipeline} from './resources/webgpu-compute-pipeline';
52
import {WebGPUVertexArray} from './resources/webgpu-vertex-array';
53

54
import {WebGPUCanvasContext} from './webgpu-canvas-context';
55
import {WebGPUPresentationContext} from './webgpu-presentation-context';
56
import {WebGPUCommandEncoder} from './resources/webgpu-command-encoder';
57
import {WebGPUCommandBuffer} from './resources/webgpu-command-buffer';
58
import {WebGPUQuerySet} from './resources/webgpu-query-set';
59
import {WebGPUPipelineLayout} from './resources/webgpu-pipeline-layout';
60
import {WebGPUFence} from './resources/webgpu-fence';
61

62
import {getShaderLayoutFromWGSL} from '../wgsl/get-shader-layout-wgsl';
63
import {generateMipmapsWebGPU} from './helpers/generate-mipmaps-webgpu';
64
import {getBindGroup} from './helpers/get-bind-group';
65
import {
66
  getCpuHotspotProfiler as getWebGPUCpuHotspotProfiler,
67
  getCpuHotspotSubmitReason as getWebGPUCpuHotspotSubmitReason,
68
  getTimestamp
69
} from './helpers/cpu-hotspot-profiler';
70

71
/** WebGPU Device implementation */
72
export class WebGPUDevice extends Device {
73
  /** The underlying WebGPU device */
74
  readonly handle: GPUDevice;
75
  /* The underlying WebGPU adapter */
76
  readonly adapter: GPUAdapter;
77
  /* The underlying WebGPU adapter's info */
78
  readonly adapterInfo: GPUAdapterInfo;
79

80
  /** type of this device */
81
  readonly type = 'webgpu';
55✔
82

83
  readonly preferredColorFormat = navigator.gpu.getPreferredCanvasFormat() as
55✔
84
    | 'rgba8unorm'
85
    | 'bgra8unorm';
86
  readonly preferredDepthFormat = 'depth24plus';
55✔
87

88
  readonly features: DeviceFeatures;
89
  readonly info: DeviceInfo;
90
  readonly limits: DeviceLimits;
91

92
  readonly lost: Promise<{reason: 'destroyed'; message: string}>;
93

94
  override canvasContext: WebGPUCanvasContext | null = null;
55✔
95

96
  private _isLost: boolean = false;
55✔
97
  private _defaultSampler: WebGPUSampler | null = null;
55✔
98
  commandEncoder: WebGPUCommandEncoder;
99

100
  override get [Symbol.toStringTag](): string {
UNCOV
101
    return 'WebGPUDevice';
×
102
  }
103

104
  override toString(): string {
UNCOV
105
    return `WebGPUDevice(${this.id})`;
×
106
  }
107

108
  constructor(
109
    props: DeviceProps,
110
    device: GPUDevice,
111
    adapter: GPUAdapter,
112
    adapterInfo: GPUAdapterInfo
113
  ) {
114
    super({...props, id: props.id || 'webgpu-device'});
55!
115
    this.handle = device;
55✔
116
    this.adapter = adapter;
55✔
117
    this.adapterInfo = adapterInfo;
55✔
118

119
    this.info = this._getInfo();
55✔
120
    this.features = this._getFeatures();
55✔
121
    this.limits = getWebGPUDeviceLimits(this.handle.limits);
55✔
122

123
    // Listen for uncaptured WebGPU errors
124
    device.addEventListener('uncapturederror', (event: Event) => {
55✔
UNCOV
125
      event.preventDefault();
×
126
      // TODO is this the right way to make sure the error is an Error instance?
127
      const errorMessage =
128
        event instanceof GPUUncapturedErrorEvent ? event.error.message : 'Unknown WebGPU error';
×
UNCOV
129
      this.reportError(new Error(errorMessage), this)();
×
UNCOV
130
      this.debug();
×
131
    });
132

133
    // "Context" loss handling
134
    this.lost = this.handle.lost.then(lostInfo => {
55✔
135
      this._isLost = true;
7✔
136
      return {reason: 'destroyed', message: lostInfo.message};
7✔
137
    });
138

139
    // Note: WebGPU devices can be created without a canvas, for compute shader purposes
140
    const canvasContextProps = Device._getCanvasContextProps(props);
55✔
141
    if (canvasContextProps) {
55!
142
      this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
55✔
143
    }
144

145
    this.commandEncoder = this.createCommandEncoder({});
55✔
146
  }
147

148
  // TODO
149
  // Load the glslang module now so that it is available synchronously when compiling shaders
150
  // const {glsl = true} = props;
151
  // this.glslang = glsl && await loadGlslangModule();
152

153
  destroy(): void {
154
    this.commandEncoder?.destroy();
×
155
    this._defaultSampler?.destroy();
×
UNCOV
156
    this._defaultSampler = null;
×
UNCOV
157
    this.handle.destroy();
×
158
  }
159

160
  get isLost(): boolean {
161
    return this._isLost;
227✔
162
  }
163

164
  getShaderLayout(source: string) {
165
    return getShaderLayoutFromWGSL(source);
154✔
166
  }
167

168
  override isVertexFormatSupported(format: VertexFormat): boolean {
UNCOV
169
    const info = this.getVertexFormatInfo(format);
×
UNCOV
170
    return !info.webglOnly;
×
171
  }
172

173
  createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WebGPUBuffer {
174
    const newProps = this._normalizeBufferProps(props);
756✔
175
    return new WebGPUBuffer(this, newProps);
756✔
176
  }
177

178
  createTexture(props: TextureProps): WebGPUTexture {
179
    return new WebGPUTexture(this, props);
161✔
180
  }
181

182
  createExternalTexture(props: ExternalTextureProps): WebGPUExternalTexture {
UNCOV
183
    return new WebGPUExternalTexture(this, props);
×
184
  }
185

186
  createShader(props: ShaderProps): WebGPUShader {
187
    return new WebGPUShader(this, props);
146✔
188
  }
189

190
  createSampler(props: SamplerProps): WebGPUSampler {
191
    return new WebGPUSampler(this, props as WebGPUSamplerProps);
7✔
192
  }
193

194
  getDefaultSampler(): WebGPUSampler {
195
    this._defaultSampler ||= new WebGPUSampler(this, {
129✔
196
      id: `${this.id}-default-sampler`
197
    });
198
    return this._defaultSampler;
129✔
199
  }
200

201
  createRenderPipeline(props: RenderPipelineProps): WebGPURenderPipeline {
202
    return new WebGPURenderPipeline(this, props);
32✔
203
  }
204

205
  createFramebuffer(props: FramebufferProps): WebGPUFramebuffer {
206
    return new WebGPUFramebuffer(this, props);
39✔
207
  }
208

209
  createComputePipeline(props: ComputePipelineProps): WebGPUComputePipeline {
210
    return new WebGPUComputePipeline(this, props);
88✔
211
  }
212

213
  /** Creates an encoder for reusable WebGPU draw commands. */
214
  createRenderBundleEncoder(props: RenderBundleEncoderProps = {}): WebGPURenderBundleEncoder {
4✔
215
    return new WebGPURenderBundleEncoder(this, props);
4✔
216
  }
217

218
  createVertexArray(props: VertexArrayProps): WebGPUVertexArray {
219
    return new WebGPUVertexArray(this, props);
39✔
220
  }
221

222
  override createCommandEncoder(props?: CommandEncoderProps): WebGPUCommandEncoder {
223
    return new WebGPUCommandEncoder(this, props);
258✔
224
  }
225

226
  override writeBufferViaCommandEncoder(
227
    commandEncoder: CommandEncoder,
228
    destinationBuffer: Buffer,
229
    data: ArrayBufferLike | ArrayBufferView | SharedArrayBuffer,
230
    byteOffset: number = 0
1✔
231
  ): void {
232
    const webgpuCommandEncoder = commandEncoder as WebGPUCommandEncoder;
1✔
233
    const uploadData = ArrayBuffer.isView(data)
1!
234
      ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
235
      : new Uint8Array(data);
236
    // WebGPU cannot encode CPU writes directly on a command encoder. Record the
237
    // upload as a staging-buffer copy so it stays ordered with the draw/dispatch
238
    // commands that will consume the destination buffer.
239
    const uploadBuffer = this.createBuffer({
1✔
240
      usage: Buffer.COPY_SRC,
241
      data: uploadData
242
    });
243

244
    webgpuCommandEncoder.trackTransientUploadBuffer(uploadBuffer);
1✔
245
    webgpuCommandEncoder.copyBufferToBuffer({
1✔
246
      sourceBuffer: uploadBuffer,
247
      destinationBuffer,
248
      destinationOffset: byteOffset,
249
      size: uploadData.byteLength
250
    });
251
  }
252

253
  // WebGPU specifics
254

255
  createTransformFeedback(props: TransformFeedbackProps): TransformFeedback {
UNCOV
256
    throw new Error('Transform feedback not supported in WebGPU');
×
257
  }
258

259
  override createQuerySet(props: QuerySetProps): QuerySet {
260
    return new WebGPUQuerySet(this, props);
6✔
261
  }
262

263
  override createFence(): WebGPUFence {
264
    return new WebGPUFence(this);
1✔
265
  }
266

267
  createCanvasContext(props: CanvasContextProps): WebGPUCanvasContext {
UNCOV
268
    return new WebGPUCanvasContext(this, this.adapter, props);
×
269
  }
270

271
  createPresentationContext(props?: PresentationContextProps): PresentationContext {
272
    return new WebGPUPresentationContext(this, props);
2✔
273
  }
274

275
  createPipelineLayout(props: PipelineLayoutProps): WebGPUPipelineLayout {
276
    return new WebGPUPipelineLayout(this, props);
32✔
277
  }
278

279
  override generateMipmapsWebGPU(texture: Texture): void {
280
    generateMipmapsWebGPU(this, texture);
12✔
281
  }
282

283
  override _createBindGroupLayoutWebGPU(
284
    pipeline: RenderPipeline | ComputePipeline,
285
    group: number
286
  ): GPUBindGroupLayout {
287
    return (pipeline as WebGPURenderPipeline | WebGPUComputePipeline).handle.getBindGroupLayout(
101✔
288
      group
289
    );
290
  }
291

292
  override _createBindGroupWebGPU(
293
    bindGroupLayout: unknown,
294
    shaderLayout: ShaderLayout | ComputeShaderLayout,
295
    bindings: Bindings,
296
    group: number,
297
    label?: string
298
  ): GPUBindGroup | null {
299
    if (Object.keys(bindings).length === 0) {
157✔
300
      return this.handle.createBindGroup({
9✔
301
        label,
302
        layout: bindGroupLayout as GPUBindGroupLayout,
303
        entries: []
304
      });
305
    }
306

307
    return getBindGroup(
148✔
308
      this,
309
      bindGroupLayout as GPUBindGroupLayout,
310
      shaderLayout,
311
      bindings,
312
      group,
313
      label
314
    );
315
  }
316

317
  submit(commandBuffer?: WebGPUCommandBuffer): void {
318
    let submittedCommandEncoder: WebGPUCommandEncoder | null = null;
198✔
319
    if (!commandBuffer) {
198✔
320
      ({submittedCommandEncoder, commandBuffer} = this._finalizeDefaultCommandEncoderForSubmit());
193✔
321
    }
322

323
    const profiler = getWebGPUCpuHotspotProfiler(this);
198✔
324
    const startTime = profiler ? getTimestamp() : 0;
198✔
325
    const submitReason = getWebGPUCpuHotspotSubmitReason(this);
198✔
326
    const transientUploadBuffers = commandBuffer.transientUploadBuffers;
198✔
327
    let didSubmit = false;
198✔
328
    try {
198✔
329
      this.pushErrorScope('validation');
198✔
330
      const queueSubmitStartTime = profiler ? getTimestamp() : 0;
198✔
331
      this.handle.queue.submit([commandBuffer.handle]);
198✔
332
      didSubmit = true;
198✔
333
      if (profiler) {
198✔
334
        profiler.queueSubmitCount = (profiler.queueSubmitCount || 0) + 1;
42✔
335
        profiler.queueSubmitTimeMs =
42✔
336
          (profiler.queueSubmitTimeMs || 0) + (getTimestamp() - queueSubmitStartTime);
51✔
337
      }
338
      this.popErrorScope((error: GPUError) => {
198✔
UNCOV
339
        this.reportError(new Error(`${this} command submission: ${error.message}`), this)();
×
UNCOV
340
        this.debug();
×
341
      });
342

343
      if (submittedCommandEncoder) {
198✔
344
        const submitResolveKickoffStartTime = profiler ? getTimestamp() : 0;
193✔
345
        scheduleMicrotask(() => {
193✔
346
          submittedCommandEncoder
193✔
347
            .resolveTimeProfilingQuerySet()
348
            .then(() => {
349
              this.commandEncoder._gpuTimeMs = submittedCommandEncoder._gpuTimeMs;
193✔
350
            })
351
            .catch(() => {});
352
        });
353
        if (profiler) {
193✔
354
          profiler.submitResolveKickoffCount = (profiler.submitResolveKickoffCount || 0) + 1;
42✔
355
          profiler.submitResolveKickoffTimeMs =
42✔
356
            (profiler.submitResolveKickoffTimeMs || 0) +
59✔
357
            (getTimestamp() - submitResolveKickoffStartTime);
358
        }
359
      }
360
    } finally {
361
      if (transientUploadBuffers.length) {
198!
362
        if (didSubmit) {
×
363
          // The GPU may still be reading from the staging buffers after
364
          // queue.submit() returns, so defer destruction until the submitted
365
          // work has fully completed.
UNCOV
366
          this.handle.queue
×
367
            .onSubmittedWorkDone()
368
            .then(() => {
UNCOV
369
              for (const uploadBuffer of transientUploadBuffers) {
×
UNCOV
370
                uploadBuffer.destroy();
×
371
              }
372
            })
373
            .catch(() => {
UNCOV
374
              for (const uploadBuffer of transientUploadBuffers) {
×
UNCOV
375
                uploadBuffer.destroy();
×
376
              }
377
            });
378
        } else {
UNCOV
379
          for (const uploadBuffer of transientUploadBuffers) {
×
UNCOV
380
            uploadBuffer.destroy();
×
381
          }
382
        }
383
      }
384
      if (profiler) {
198✔
385
        profiler.submitCount = (profiler.submitCount || 0) + 1;
42✔
386
        profiler.submitTimeMs = (profiler.submitTimeMs || 0) + (getTimestamp() - startTime);
42✔
387
        const reasonCountKey =
388
          submitReason === 'query-readback' ? 'queryReadbackSubmitCount' : 'defaultSubmitCount';
42!
389
        const reasonTimeKey =
390
          submitReason === 'query-readback' ? 'queryReadbackSubmitTimeMs' : 'defaultSubmitTimeMs';
42!
391
        profiler[reasonCountKey] = (profiler[reasonCountKey] || 0) + 1;
42✔
392
        profiler[reasonTimeKey] = (profiler[reasonTimeKey] || 0) + (getTimestamp() - startTime);
42✔
393
      }
394
      const commandBufferDestroyStartTime = profiler ? getTimestamp() : 0;
198✔
395
      commandBuffer.destroy();
198✔
396
      if (profiler) {
198✔
397
        profiler.commandBufferDestroyCount = (profiler.commandBufferDestroyCount || 0) + 1;
42✔
398
        profiler.commandBufferDestroyTimeMs =
42✔
399
          (profiler.commandBufferDestroyTimeMs || 0) +
52✔
400
          (getTimestamp() - commandBufferDestroyStartTime);
401
      }
402
    }
403
  }
404

405
  private _finalizeDefaultCommandEncoderForSubmit(): {
406
    submittedCommandEncoder: WebGPUCommandEncoder;
407
    commandBuffer: WebGPUCommandBuffer;
408
  } {
409
    const submittedCommandEncoder = this.commandEncoder;
193✔
410
    if (
193!
411
      submittedCommandEncoder.getTimeProfilingSlotCount() > 0 &&
193!
412
      submittedCommandEncoder.getTimeProfilingQuerySet() instanceof WebGPUQuerySet
413
    ) {
UNCOV
414
      const querySet = submittedCommandEncoder.getTimeProfilingQuerySet() as WebGPUQuerySet;
×
UNCOV
415
      querySet._encodeResolveToReadBuffer(submittedCommandEncoder, {
×
416
        firstQuery: 0,
417
        queryCount: submittedCommandEncoder.getTimeProfilingSlotCount()
418
      });
419
    }
420

421
    const commandBuffer = submittedCommandEncoder.finish();
193✔
422
    this.commandEncoder.destroy();
193✔
423
    this.commandEncoder = this.createCommandEncoder({
193✔
424
      id: submittedCommandEncoder.props.id,
425
      timeProfilingQuerySet: submittedCommandEncoder.getTimeProfilingQuerySet()
426
    });
427

428
    return {submittedCommandEncoder, commandBuffer};
193✔
429
  }
430

431
  // WebGPU specific
432

433
  pushErrorScope(scope: 'validation' | 'out-of-memory'): void {
434
    if (!this.props.debug) {
4,570!
UNCOV
435
      return;
×
436
    }
437
    const profiler = getWebGPUCpuHotspotProfiler(this);
4,570✔
438
    const startTime = profiler ? getTimestamp() : 0;
4,570✔
439
    this.handle.pushErrorScope(scope);
4,570✔
440
    if (profiler) {
4,570✔
441
      profiler.errorScopePushCount = (profiler.errorScopePushCount || 0) + 1;
149✔
442
      profiler.errorScopeTimeMs = (profiler.errorScopeTimeMs || 0) + (getTimestamp() - startTime);
149✔
443
    }
444
  }
445

446
  popErrorScope(handler: (error: GPUError) => void): void {
447
    if (!this.props.debug) {
4,570!
UNCOV
448
      return;
×
449
    }
450
    const profiler = getWebGPUCpuHotspotProfiler(this);
4,570✔
451
    const startTime = profiler ? getTimestamp() : 0;
4,570✔
452
    this.handle
4,570✔
453
      .popErrorScope()
454
      .then((error: GPUError | null) => {
455
        if (error) {
4,177✔
456
          handler(error);
11✔
457
        }
458
      })
459
      .catch((error: unknown) => {
460
        if (this.shouldIgnoreDroppedInstanceError(error, 'popErrorScope')) {
392!
461
          return;
392✔
462
        }
463

UNCOV
464
        const errorMessage = error instanceof Error ? error.message : String(error);
×
465
        this.reportError(new Error(`${this} popErrorScope failed: ${errorMessage}`), this)();
392✔
466
        this.debug();
392✔
467
      });
468
    if (profiler) {
4,570✔
469
      profiler.errorScopePopCount = (profiler.errorScopePopCount || 0) + 1;
149✔
470
      profiler.errorScopeTimeMs = (profiler.errorScopeTimeMs || 0) + (getTimestamp() - startTime);
149✔
471
    }
472
  }
473

474
  // PRIVATE METHODS
475

476
  protected _getInfo(): DeviceInfo {
477
    const [driver, driverVersion] = ((this.adapterInfo as any).driver || '').split(' Version ');
55✔
478

479
    // See https://developer.chrome.com/blog/new-in-webgpu-120#adapter_information_updates
480
    const vendor = this.adapterInfo.vendor || this.adapter.__brand || 'unknown';
55!
481
    const renderer = driver || '';
55✔
482
    const version = driverVersion || '';
55✔
483
    const fallback = Boolean(
55✔
484
      (this.adapterInfo as any).isFallbackAdapter ??
55!
485
        (this.adapter as any).isFallbackAdapter ??
486
        false
487
    );
488
    const softwareRenderer = /SwiftShader/i.test(
55✔
489
      `${vendor} ${renderer} ${this.adapterInfo.architecture || ''}`
55!
490
    );
491

492
    const gpuArchitecture = this.adapterInfo.architecture || 'unknown';
55!
493
    const gpu =
494
      identifyGPUVendor(vendor, renderer) ??
55✔
495
      (softwareRenderer || fallback ? 'software' : 'unknown');
110!
496
    const gpuBackend = (this.adapterInfo as any).backend || 'unknown';
55✔
497
    const gpuType =
55✔
498
      ((this.adapterInfo as any).type || '').split(' ')[0].toLowerCase() ||
110✔
499
      (softwareRenderer || fallback ? 'cpu' : 'unknown');
110!
500

501
    return {
55✔
502
      type: 'webgpu',
503
      vendor,
504
      renderer,
505
      version,
506
      gpu,
507
      gpuType,
508
      gpuBackend,
509
      gpuArchitecture,
510
      fallback,
511
      featureLevel: getWebGPUDeviceFeatureLevel(this.props.featureLevel),
512
      shadingLanguage: 'wgsl',
513
      shadingLanguageVersion: 100
514
    };
515
  }
516

517
  shouldIgnoreDroppedInstanceError(error: unknown, operation?: string): boolean {
518
    const errorMessage = error instanceof Error ? error.message : String(error);
397!
519
    return (
397✔
520
      errorMessage.includes('Instance dropped') &&
1,588!
521
      (!operation || errorMessage.includes(operation)) &&
522
      (this._isLost ||
523
        this.info.gpu === 'software' ||
524
        this.info.gpuType === 'cpu' ||
525
        Boolean(this.info.fallback))
526
    );
527
  }
528

529
  protected _getFeatures(): DeviceFeatures {
530
    // Initialize with actual WebGPU Features (note that unknown features may not be in DeviceFeature type)
531
    const features = new Set<DeviceFeature>(this.handle.features as Set<DeviceFeature>);
55✔
532
    // Fixups for pre-standard names: https://github.com/webgpu-native/webgpu-headers/issues/133
533
    // @ts-expect-error Chrome Canary v99
534
    if (features.has('depth-clamping')) {
55!
535
      // @ts-expect-error Chrome Canary v99
UNCOV
536
      features.delete('depth-clamping');
×
UNCOV
537
      features.add('depth-clip-control');
×
538
    }
539

540
    // Some subsets of WebGPU extensions correspond to WebGL extensions
541
    if (features.has('texture-compression-bc')) {
55✔
542
      features.add('texture-compression-bc5-webgl');
54✔
543
    }
544

545
    if (this.handle.features.has('chromium-experimental-norm16-texture-formats')) {
55!
UNCOV
546
      features.add('norm16-renderable-webgl');
×
547
    }
548

549
    if (this.handle.features.has('chromium-experimental-snorm16-texture-formats')) {
55!
UNCOV
550
      features.add('snorm16-renderable-webgl');
×
551
    }
552

553
    const WEBGPU_ALWAYS_FEATURES: DeviceFeature[] = [
55✔
554
      'compilation-status-async-webgl',
555
      'float32-renderable-webgl',
556
      'float16-renderable-webgl',
557
      'norm16-renderable-webgl',
558
      'texture-filterable-anisotropic-webgl',
559
      'shader-noperspective-interpolation-webgl'
560
    ];
561

562
    for (const feature of WEBGPU_ALWAYS_FEATURES) {
55✔
563
      features.add(feature);
330✔
564
    }
565

566
    return new DeviceFeatures(Array.from(features), this.props._disabledFeatures);
55✔
567
  }
568

569
  override _getDeviceSpecificTextureFormatCapabilities(
570
    capabilities: DeviceTextureFormatCapabilities
571
  ): DeviceTextureFormatCapabilities {
572
    const {format} = capabilities;
72✔
573
    if (format.includes('webgl')) {
72✔
574
      return {format, create: false, render: false, filter: false, blend: false, store: false};
11✔
575
    }
576
    return capabilities;
61✔
577
  }
578
}
579

580
function getWebGPUDeviceLimits(limits: GPUSupportedLimits): DeviceLimits {
581
  const stageSpecificLimits: Partial<Record<keyof DeviceLimits, number>> = {
55✔
582
    maxStorageBuffersInVertexStage:
583
      limits.maxStorageBuffersInVertexStage ?? limits.maxStorageBuffersPerShaderStage,
55!
584
    maxStorageBuffersInFragmentStage:
585
      limits.maxStorageBuffersInFragmentStage ?? limits.maxStorageBuffersPerShaderStage,
55!
586
    maxStorageTexturesInVertexStage:
587
      limits.maxStorageTexturesInVertexStage ?? limits.maxStorageTexturesPerShaderStage,
55!
588
    maxStorageTexturesInFragmentStage:
589
      limits.maxStorageTexturesInFragmentStage ?? limits.maxStorageTexturesPerShaderStage
55!
590
  };
591

592
  return new Proxy(limits, {
55✔
593
    get(target, property) {
594
      return typeof property === 'string' && property in stageSpecificLimits
398✔
595
        ? stageSpecificLimits[property as keyof DeviceLimits]
596
        : Reflect.get(target, property, target);
597
    }
598
  }) as DeviceLimits;
599
}
600

601
function getWebGPUDeviceFeatureLevel(
602
  featureLevel: DeviceProps['featureLevel']
603
): NonNullable<DeviceInfo['featureLevel']> {
604
  return featureLevel === 'best-available' ? 'core' : featureLevel || 'core';
55!
605
}
606

607
function identifyGPUVendor(
608
  vendor: string,
609
  renderer: string
610
): 'nvidia' | 'intel' | 'apple' | 'amd' | null {
611
  if (/NVIDIA/i.exec(vendor) || /NVIDIA/i.exec(renderer)) {
55!
UNCOV
612
    return 'nvidia';
×
613
  }
614
  if (/INTEL/i.exec(vendor) || /INTEL/i.exec(renderer)) {
55!
UNCOV
615
    return 'intel';
×
616
  }
617
  if (/Apple/i.exec(vendor) || /Apple/i.exec(renderer)) {
55!
UNCOV
618
    return 'apple';
×
619
  }
620
  if (
55!
621
    /AMD/i.exec(vendor) ||
220✔
622
    /AMD/i.exec(renderer) ||
623
    /ATI/i.exec(vendor) ||
624
    /ATI/i.exec(renderer)
625
  ) {
UNCOV
626
    return 'amd';
×
627
  }
628
  return null;
55✔
629
}
630

631
function scheduleMicrotask(callback: () => void): void {
632
  if (globalThis.queueMicrotask) {
193!
633
    globalThis.queueMicrotask(callback);
193✔
634
    return;
193✔
635
  }
UNCOV
636
  Promise.resolve()
×
637
    .then(callback)
638
    .catch(() => {});
639
}
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