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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
GPUCompilationInfo
Experimental
messages
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

関連情報