GPUPipelineError

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

注意:此功能在 Web Workers 中可用。

GPUPipelineError 接口是 WebGPU API 的一部分,用于描述管道(pipeline)的失败。当 PromiseGPUDevice.createComputePipelineAsync()GPUDevice.createRenderPipelineAsync() 调用拒绝时,就会接收到这个值。

DOMException GPUPipelineError

构造函数

GPUPipelineError()

创建一个新的 GPUPipelineError 对象实例。

实例属性

继承其父级 DOMException 的属性。

reason 只读

一个枚举值,以机器可读的方式定义了管道创建失败的原因。

示例

在下面的代码片段中,我们尝试使用 GPUDevice.createComputePipelineAsync() 创建一个 GPUComputePipeline。但是,我们错误地拼写了计算管道的 entryPoint,将其写成了 "maijn"(而它应该是 "main"),因此管道创建失败,我们的 catch 块将由此产生的 reason 和错误消息打印到控制台。

js
// …

let computePipeline;

try {
  computePipeline = await device.createComputePipelineAsync({
    layout: device.createPipelineLayout({
      bindGroupLayouts: [bindGroupLayout],
    }),
    compute: {
      module: shaderModule,
      entryPoint: "maijn",
    },
  });
} catch (error) {
  // error is a GPUPipelineError object instance
  console.error(error.reason);
  console.error(`Pipeline creation failed: ${error.message}`);
}

// …

在这种情况下,给定的 reason"Validation",而 message"Entry point "maijn" doesn't exist in the shader module [ShaderModule]."(入口点 "maijn" 在着色器模块 [ShaderModule] 中不存在。)

规范

规范
WebGPU
# gpupipelineerror

浏览器兼容性

另见