GPU Error Types

Reading GPUValidationError, GPUOutOfMemoryError and GPUInternalError

Every error is a GPUError with one property, message, and the subclass says what to do. A GPUValidationError means your call broke a rule; given the same features and limits it fails identically on every device, so it is a bug to fix. A GPUOutOfMemoryError means free something or retry smaller, and a GPUInternalError means the implementation could not do it, so try a simpler variant. This page asks for a 16384 x 16384 rgba32float texture (4 GiB), valid once the device requests the adapter's larger texture limit, but too big for this 4 GB GPU:

Catching a real out-of-memory errorHTMLLive
<script type="module">
  const adapter = await navigator.gpu.requestAdapter();
  const device = await adapter.requestDevice({
    requiredLimits: { maxTextureDimension2D: 16384 } });
  device.pushErrorScope('out-of-memory');
  const texture = device.createTexture({ label: 'poster', size: [16384, 16384],
    format: 'rgba32float', usage: GPUTextureUsage.TEXTURE_BINDING });   // 4 GiB
  const error = await device.popErrorScope();
  console.log(`${error instanceof GPUOutOfMemoryError}: ${error.message.split('\n')[0]}`);
  texture.destroy();
</script>

The full message ends "Device removed reason: S_OK": the device survived, only the texture is invalid, and the failure took 18 ms. Messages are localizable text for developers, so branch with instanceof, never by parsing. This machine never produced a GPUInternalError, the sign of a shader or pipeline beyond some undocumented limit.