GPUShaderModule

class

class GPUShaderModule implements GPUObjectBase

Represents a compiled shader module that can be used to create graphics or compute pipelines.

Example

// Create a shader module using WGSL (WebGPU Shading Language)
const shaderModule = device.createShaderModule({
  label: "My Shader",
  code: `
    @vertex
    fn vertexMain(@location(0) pos: vec2f) -> @builtin(position) vec4f {
      return vec4f(pos, 0.0, 1.0);
    }

    @fragment
    fn fragmentMain() -> @location(0) vec4f {
      return vec4f(1.0, 0.0, 0.0, 1.0); // red color
    }
  `
});

// Can optionally check for compilation errors/warnings
const compilationInfo = await shaderModule.getCompilationInfo();
for (const message of compilationInfo.messages) {
  console.log(`${message.type}: ${message.message} at ${message.lineNum}:${message.linePos}`);
}

Properties

label

label: string

Methods

getCompilationInfo

getCompilationInfo(): Promise<GPUCompilationInfo>

Returns compilation messages for this shader module, which can include errors, warnings and info messages.