GPUPipelineError
注意:此功能在 Web Workers 中可用。
GPUPipelineError 接口是 WebGPU API 的一部分,用于描述管道(pipeline)的失败。当 Promise 被 GPUDevice.createComputePipelineAsync() 或 GPUDevice.createRenderPipelineAsync() 调用拒绝时,就会接收到这个值。
构造函数
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 |
浏览器兼容性
加载中…