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

visgl / luma.gl / 5111325440

pending completion
5111325440

push

github

web-flow
docs: Reorganize v9 docs (#1753)

2483 of 3226 branches covered (76.97%)

Branch coverage included in aggregate %.

11 of 11 new or added lines in 7 files covered. (100.0%)

37548 of 49789 relevant lines covered (75.41%)

17.68 hits per line

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

37.84
/modules/webgpu/src/adapter/resources/webgpu-shader.ts
1
// luma.gl, MIT license
1✔
2

1✔
3
import type {ShaderProps, CompilerMessage} from '@luma.gl/api';
1✔
4
import {Shader, log} from '@luma.gl/api';
1✔
5
import type {WebGPUDevice} from '../webgpu-device';
1✔
6

1✔
7
export type WebGPUShaderProps = ShaderProps & {
1✔
8
  handle?: GPUShaderModule;
1✔
9
};
1✔
10

1✔
11
/**
1✔
12
 * Immutable shader
1✔
13
 */
1✔
14
export class WebGPUShader extends Shader {
1✔
15
  readonly device: WebGPUDevice;
1✔
16
  readonly handle: GPUShaderModule;
1✔
17

1✔
18
  constructor(device: WebGPUDevice, props: WebGPUShaderProps) {
1✔
19
    super(device, props);
×
20
    this.device = device;
×
21

×
22
    this.device.handle.pushErrorScope('validation');
×
23

×
24
    this.handle = this.props.handle || this.createHandle();
×
25
    this.handle.label = this.props.id;
×
26

×
27
    this._checkCompilationError(this.device.handle.popErrorScope());
×
28
  }
×
29

1✔
30
  async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {
1✔
31
    const error = await errorScope as GPUValidationError;
×
32
    if (error) {
×
33
      const shaderLog = await this.compilationInfo();
×
34
      log.error(`Shader compilation error: ${error.message}`, shaderLog)();
×
35
      // Note: Even though this error is asynchronous and thrown after the constructor completes,
×
36
      // it will result in a useful stack trace leading back to the constructor
×
37
      throw new Error(`Shader compilation error: ${error.message}`);
×
38
    }
×
39
  }
×
40

1✔
41
  override destroy(): void {
1✔
42
    // this.handle.destroy();
×
43
  }
×
44

1✔
45
  protected createHandle(): GPUShaderModule {
1✔
46
    const {source, stage} = this.props;
×
47

×
48
    let language = this.props.language;
×
49
    // Compile from src
×
50
    if (!language) {
×
51
      // wgsl uses C++ "auto" style arrow notation
×
52
      language = source.includes('->') ? 'wgsl' : 'glsl';
×
53
    }
×
54

×
55
    switch(language) {
×
56
      case 'wgsl':
×
57
        return this.device.handle.createShaderModule({code: source});
×
58
      case 'glsl':
×
59
        return this.device.handle.createShaderModule({
×
60
          code: source,
×
61
          // @ts-expect-error
×
62
          transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)
×
63
        });
×
64
      default:
×
65
        throw new Error(language);
×
66
    }
×
67
  }
×
68

1✔
69
  /** Returns compilation info for this shader */
1✔
70
  async compilationInfo(): Promise<readonly CompilerMessage[]> {
1✔
71
    const compilationInfo = await this.handle.getCompilationInfo();
×
72
    return compilationInfo.messages;
×
73
  }
×
74
}
1✔
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

© 2025 Coveralls, Inc