このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

GPUCompilationInfo

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

WebGPU APIGPUCompilationInfo インターフェイスは、シェーダーコードの問題を診断する助けになるように GPU シェーダーモジュールコンパイラーが生成した GPUCompilationMessage オブジェクトの配列を表します。

GPUCompilationInfo には、GPUShaderModule.getCompilationInfo() からアクセスできます。

インスタンスプロパティ

messages Experimental 読取専用

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" // ... } 

仕様書

Specification
WebGPU
# gpucompilationinfo

ブラウザーの互換性

関連情報