GPUCompilationInfo
注意:此功能在 Web Workers 中可用。
GPUCompilationInfo 介面是 WebGPU API 的一部分,它表示一個由 GPU 著色器模組編譯器生成的 GPUCompilationMessage 物件陣列,用於幫助診斷著色器程式碼中的問題。
透過 GPUShaderModule.getCompilationInfo() 來訪問 GPUCompilationInfo。
例項屬性
messages只讀-
一個
GPUCompilationMessage物件陣列,每個物件都包含單個著色器編譯訊息的詳細資訊。訊息可以是資訊性的、警告或錯誤。
示例
在下面的示例中,我們故意在著色器程式碼的函式宣告中遺漏了一個括號
js
const shaders = `
struct VertexOut {
@builtin(position) position : vec4f,
@location(0) color : vec4f
}
@vertex
fn vertex_main(@location(0) position: vec4f,
@location(1) color: vec4f -> VertexOut
{
var output : VertexOut;
output.position = position;
output.color = color;
return output;
}
@fragment
fn fragment_main(fragData: VertexOut) -> @location(0) vec4f
{
return fragData.color;
}
`;
當我們編譯著色器模組時,我們使用 getCompilationInfo() 來獲取一些關於由此產生的錯誤的附加資訊
js
async function init() {
// …
const shaderModule = device.createShaderModule({
code: shaders,
});
const shaderInfo = await shaderModule.getCompilationInfo();
const firstMessage = shaderInfo.messages[0];
console.log(firstMessage.lineNum); // 9
console.log(firstMessage.message); // "expected ')' for function declaration"
console.log(firstMessage.type); // "error"
// …
}
規範
| 規範 |
|---|
| WebGPU # gpucompilationinfo |
瀏覽器相容性
載入中…