<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
function optimizedMethodCall(computePassEncoder, workgroupCountX, workgroupCountY, workgroupCountZ) {
computePassEncoder.dispatchWorkgroups(workgroupCountX, workgroupCountY, workgroupCountZ);
}
function test(t, hotLoop, computePassEncoder, workgroupCountX, workgroupCountY, workgroupCountZ) {
try {
hotLoop(1, computePassEncoder, workgroupCountX, workgroupCountY, workgroupCountZ);
} catch(e) {
assert_true(e instanceof TypeError);
return;
}
assert_unreached("A TypeError should be thrown.");
}
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();
function hotLoop(count, computePassEncoder, workgroupCountX, workgroupCountY, workgroupCountZ) {
for (let i = 0; i < count; ++i) {
optimizedMethodCall(computePassEncoder, workgroupCountX, workgroupCountY, workgroupCountZ);
}
}
hotLoop(100, computePassEncoder, 8, 8, 8);
// 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));
test(t, hotLoop, computePassEncoder, 0xFFFFFFFF + 1, 1, 1);
test(t, hotLoop, computePassEncoder, 1, 0xFFFFFFFF + 1, 1);
test(t, hotLoop, computePassEncoder, 1, 1, 0xFFFFFFFF + 1);
});
</script>
</body>
</html>