chromium/third_party/blink/web_tests/wpt_internal/webgpu/fast_api/GPUComputePassEncoder.dispatchWorkgroupsIndirect.https.html

<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
function optimizedMethodCall(computePassEncoder, indirectBuffer, indirectOffset) {
  computePassEncoder.dispatchWorkgroupsIndirect(indirectBuffer, indirectOffset);
}

promise_test(async t => {
  const adapter = await navigator.gpu.requestAdapter();
  assert_true(adapter instanceof GPUAdapter, 'Failed to request WebGPU adapter');
  const device = await adapter.requestDevice();
  assert_true(device instanceof GPUDevice, 'Failed to request WebGPU device');

  const encoder = device.createCommandEncoder();
  const computePassEncoder = encoder.beginComputePass();

  const indirectBuffer = device.createBuffer({
    size: 20,
    usage: GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_DST,
  });

  function hotLoop(count, computePassEncoder, indirectBuffer, indirectOffset) {
    for (let i = 0; i < count; ++i) {
      optimizedMethodCall(computePassEncoder, indirectBuffer, indirectOffset);
    }
  }
  hotLoop(100, computePassEncoder, indirectBuffer, 4);

  // Wait a bit for V8 to optimize. Then call again with an out-of-bounds value.
  // An exception should be thrown.
  await new Promise(resolve => t.step_timeout(resolve, 50));

  // kJSMaxInteger = 0x20000000000000 - 1;
  try {
    hotLoop(1, computePassEncoder, indirectBuffer, 0x20000000000000);
  } catch(e) {
    assert_true(e instanceof TypeError);
    return;
  }
  assert_unreached("A TypeError should be thrown.");
});
</script>
</body>
</html>