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

visgl / luma.gl / 29646907050

18 Jul 2026 01:50PM UTC coverage: 71.874% (-0.4%) from 72.255%
29646907050

Pull #2746

github

web-flow
Merge 136cf5204 into 5d8d46193
Pull Request #2746: feat: add WebGL extension and WebGPU feature support

11338 of 17802 branches covered (63.69%)

Branch coverage included in aggregate %.

76 of 194 new or added lines in 20 files covered. (39.18%)

5 existing lines in 1 file now uncovered.

21918 of 28468 relevant lines covered (76.99%)

5571.34 hits per line

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

78.13
/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, isHTMLInCanvasSupported} 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';
71✔
82

83
  readonly preferredColorFormat = navigator.gpu.getPreferredCanvasFormat() as
71✔
84
    | 'rgba8unorm'
85
    | 'bgra8unorm';
86
  readonly preferredDepthFormat = 'depth24plus';
71✔
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;
71✔
95

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

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

104
  override toString(): string {
105
    return `WebGPUDevice(${this.id})`;
2✔
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'});
71!
115
    this.handle = device;
71✔
116
    this.adapter = adapter;
71✔
117
    this.adapterInfo = adapterInfo;
71✔
118

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

123
    // Listen for uncaptured WebGPU errors
124
    device.addEventListener('uncapturederror', (event: Event) => {
71✔
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';
×
129
      this.reportError(new Error(errorMessage), this)();
×
130
      this.debug();
×
131
    });
132

133
    // "Context" loss handling
134
    this.lost = this.handle.lost.then(lostInfo => {
71✔
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);
71✔
141
    if (canvasContextProps) {
71!
142
      this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
71✔
143
    }
144

145
    this.commandEncoder = this.createCommandEncoder({});
71✔
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();
×
156
    this._defaultSampler = null;
×
157
    this.handle.destroy();
×
158
  }
159

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

226
  override writeBufferViaCommandEncoder(
227
    commandEncoder: CommandEncoder,
228
    destinationBuffer: Buffer,
229
    data: ArrayBufferLike | ArrayBufferView | SharedArrayBuffer,
230
    byteOffset: number = 0
52✔
231
  ): void {
232
    const webgpuCommandEncoder = commandEncoder as WebGPUCommandEncoder;
52✔
233
    const uploadData = ArrayBuffer.isView(data)
52!
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({
52✔
240
      usage: Buffer.COPY_SRC,
241
      data: uploadData
242
    });
243

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

253
  // WebGPU specifics
254

255
  createTransformFeedback(props: TransformFeedbackProps): TransformFeedback {
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 {
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);
84✔
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(
337✔
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) {
712✔
300
      return this.handle.createBindGroup({
18✔
301
        label,
302
        layout: bindGroupLayout as GPUBindGroupLayout,
303
        entries: []
304
      });
305
    }
306

307
    return getBindGroup(
694✔
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;
284✔
319
    if (!commandBuffer) {
284✔
320
      ({submittedCommandEncoder, commandBuffer} = this._finalizeDefaultCommandEncoderForSubmit());
213✔
321
    }
322

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

343
      if (submittedCommandEncoder) {
284✔
344
        const submitResolveKickoffStartTime = profiler ? getTimestamp() : 0;
213✔
345
        scheduleMicrotask(() => {
213✔
346
          submittedCommandEncoder
213✔
347
            .resolveTimeProfilingQuerySet()
348
            .then(() => {
349
              this.commandEncoder._gpuTimeMs = submittedCommandEncoder._gpuTimeMs;
213✔
350
            })
351
            .catch(() => {});
352
        });
353
        if (profiler) {
213✔
354
          profiler.submitResolveKickoffCount = (profiler.submitResolveKickoffCount || 0) + 1;
42✔
355
          profiler.submitResolveKickoffTimeMs =
42✔
356
            (profiler.submitResolveKickoffTimeMs || 0) +
58✔
357
            (getTimestamp() - submitResolveKickoffStartTime);
358
        }
359
      }
360
    } finally {
361
      if (transientUploadBuffers.length) {
284✔
362
        if (didSubmit) {
5!
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.
366
          this.handle.queue
5✔
367
            .onSubmittedWorkDone()
368
            .then(() => {
369
              for (const uploadBuffer of transientUploadBuffers) {
4✔
370
                uploadBuffer.destroy();
10✔
371
              }
372
            })
373
            .catch(() => {
374
              for (const uploadBuffer of transientUploadBuffers) {
×
375
                uploadBuffer.destroy();
×
376
              }
377
            });
378
        } else {
379
          for (const uploadBuffer of transientUploadBuffers) {
×
380
            uploadBuffer.destroy();
×
381
          }
382
        }
383
      }
384
      if (profiler) {
284✔
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;
284✔
395
      commandBuffer.destroy();
284✔
396
      if (profiler) {
284✔
397
        profiler.commandBufferDestroyCount = (profiler.commandBufferDestroyCount || 0) + 1;
42✔
398
        profiler.commandBufferDestroyTimeMs =
42✔
399
          (profiler.commandBufferDestroyTimeMs || 0) +
50✔
400
          (getTimestamp() - commandBufferDestroyStartTime);
401
      }
402
    }
403
  }
404

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

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

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

431
  // WebGPU specific
432

433
  pushErrorScope(scope: 'validation' | 'out-of-memory'): void {
434
    if (!this.props.debug) {
8,118!
435
      return;
×
436
    }
437
    const profiler = getWebGPUCpuHotspotProfiler(this);
8,118✔
438
    const startTime = profiler ? getTimestamp() : 0;
8,118✔
439
    this.handle.pushErrorScope(scope);
8,118✔
440
    if (profiler) {
8,118✔
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): Promise<void> {
447
    if (!this.props.debug) {
8,118!
448
      return Promise.resolve();
×
449
    }
450
    const profiler = getWebGPUCpuHotspotProfiler(this);
8,118✔
451
    const startTime = profiler ? getTimestamp() : 0;
8,118✔
452
    const errorScopePromise = this.handle
8,118✔
453
      .popErrorScope()
454
      .then((error: GPUError | null) => {
455
        if (error) {
7,118✔
456
          handler(error);
11✔
457
        }
458
      })
459
      .catch((error: unknown) => {
460
        if (this.shouldIgnoreDroppedInstanceError(error, 'popErrorScope')) {
209!
461
          return;
209✔
462
        }
463

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

475
  // PRIVATE METHODS
476

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

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

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

502
    return {
71✔
503
      type: 'webgpu',
504
      vendor,
505
      renderer,
506
      version,
507
      gpu,
508
      gpuType,
509
      gpuBackend,
510
      gpuArchitecture,
511
      fallback,
512
      featureLevel: getWebGPUDeviceFeatureLevel(this.props.featureLevel),
513
      subgroupMinSize: (this.adapterInfo as GPUAdapterInfo & {subgroupMinSize?: number})
514
        .subgroupMinSize,
515
      subgroupMaxSize: (this.adapterInfo as GPUAdapterInfo & {subgroupMaxSize?: number})
516
        .subgroupMaxSize,
517
      shadingLanguage: 'wgsl',
518
      shadingLanguageVersion: 100
519
    };
520
  }
521

522
  shouldIgnoreDroppedInstanceError(error: unknown, operation?: string): boolean {
523
    const errorMessage = error instanceof Error ? error.message : String(error);
213!
524
    return (
213✔
525
      errorMessage.includes('Instance dropped') &&
852!
526
      (!operation || errorMessage.includes(operation)) &&
527
      (this._isLost ||
528
        this.info.gpu === 'software' ||
529
        this.info.gpuType === 'cpu' ||
530
        Boolean(this.info.fallback))
531
    );
532
  }
533

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

545
    // Some subsets of WebGPU extensions correspond to WebGL extensions
546
    if (features.has('texture-compression-bc')) {
71✔
547
      features.add('texture-compression-bc5-webgl');
69✔
548
    }
549

550
    if (features.has('texture-formats-tier2')) {
71!
NEW
551
      features.add('texture-formats-tier1');
×
552
    }
553

554
    if (features.has('subgroup-size-control')) {
71!
NEW
555
      features.add('subgroups');
×
556
    }
557

558
    if (this.handle.features.has('chromium-experimental-norm16-texture-formats')) {
71!
559
      features.add('norm16-renderable-webgl');
×
560
    }
561

562
    if (this.handle.features.has('chromium-experimental-snorm16-texture-formats')) {
71!
563
      features.add('snorm16-renderable-webgl');
×
564
    }
565

566
    const WEBGPU_ALWAYS_FEATURES: DeviceFeature[] = [
71✔
567
      'compilation-status-async-webgl',
568
      'float32-renderable-webgl',
569
      'float16-renderable-webgl',
570
      'norm16-renderable-webgl',
571
      'texture-filterable-anisotropic-webgl',
572
      'shader-noperspective-interpolation-webgl'
573
    ];
574

575
    for (const feature of WEBGPU_ALWAYS_FEATURES) {
71✔
576
      features.add(feature);
426✔
577
    }
578

579
    if (
71!
580
      isHTMLInCanvasSupported() &&
71!
581
      typeof (
582
        this.handle.queue as GPUQueue & {
583
          copyElementImageToTexture?: unknown;
584
        }
585
      ).copyElementImageToTexture === 'function'
586
    ) {
587
      features.add('html-in-canvas');
×
588
    }
589

590
    return new DeviceFeatures(Array.from(features), this.props._disabledFeatures);
71✔
591
  }
592

593
  override _getDeviceSpecificTextureFormatCapabilities(
594
    capabilities: DeviceTextureFormatCapabilities
595
  ): DeviceTextureFormatCapabilities {
596
    const {format} = capabilities;
76✔
597
    if (format.includes('webgl')) {
76✔
598
      return {
11✔
599
        format,
600
        create: false,
601
        render: false,
602
        filter: false,
603
        blend: false,
604
        store: false,
605
        storageRead: false,
606
        storageWrite: false,
607
        storageReadWrite: false
608
      };
609
    }
610
    return capabilities;
65✔
611
  }
612
}
613

614
function getWebGPUDeviceLimits(limits: GPUSupportedLimits): DeviceLimits {
615
  const stageSpecificLimits: Partial<Record<keyof DeviceLimits, number>> = {
71✔
616
    maxStorageBuffersInVertexStage:
617
      limits.maxStorageBuffersInVertexStage ?? limits.maxStorageBuffersPerShaderStage,
71!
618
    maxStorageBuffersInFragmentStage:
619
      limits.maxStorageBuffersInFragmentStage ?? limits.maxStorageBuffersPerShaderStage,
71!
620
    maxStorageTexturesInVertexStage:
621
      limits.maxStorageTexturesInVertexStage ?? limits.maxStorageTexturesPerShaderStage,
71!
622
    maxStorageTexturesInFragmentStage:
623
      limits.maxStorageTexturesInFragmentStage ?? limits.maxStorageTexturesPerShaderStage
71!
624
  };
625

626
  return new Proxy(limits, {
71✔
627
    get(target, property) {
628
      return typeof property === 'string' && property in stageSpecificLimits
1,203✔
629
        ? stageSpecificLimits[property as keyof DeviceLimits]
630
        : Reflect.get(target, property, target);
631
    }
632
  }) as DeviceLimits;
633
}
634

635
function getWebGPUDeviceFeatureLevel(
636
  featureLevel: DeviceProps['featureLevel']
637
): NonNullable<DeviceInfo['featureLevel']> {
638
  return featureLevel === 'best-available' ? 'core' : featureLevel || 'core';
71!
639
}
640

641
function identifyGPUVendor(
642
  vendor: string,
643
  renderer: string
644
): 'nvidia' | 'intel' | 'apple' | 'amd' | null {
645
  if (/NVIDIA/i.exec(vendor) || /NVIDIA/i.exec(renderer)) {
71!
646
    return 'nvidia';
×
647
  }
648
  if (/INTEL/i.exec(vendor) || /INTEL/i.exec(renderer)) {
71!
649
    return 'intel';
×
650
  }
651
  if (/Apple/i.exec(vendor) || /Apple/i.exec(renderer)) {
71!
652
    return 'apple';
×
653
  }
654
  if (
71!
655
    /AMD/i.exec(vendor) ||
284✔
656
    /AMD/i.exec(renderer) ||
657
    /ATI/i.exec(vendor) ||
658
    /ATI/i.exec(renderer)
659
  ) {
660
    return 'amd';
×
661
  }
662
  return null;
71✔
663
}
664

665
function scheduleMicrotask(callback: () => void): void {
666
  if (globalThis.queueMicrotask) {
213!
667
    globalThis.queueMicrotask(callback);
213✔
668
    return;
213✔
669
  }
670
  Promise.resolve()
×
671
    .then(callback)
672
    .catch(() => {});
673
}
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