blob: 5bd2aa72d54c9b4a8861ff65a55eff01e060f724 [file] [edit]
<!DOCTYPE html><!-- webkit-test-runner [ runSingly=true ] -->
<meta charset="utf-8">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
// https://github.com/microsoft/playwright-webkit/issues/84
promise_test(async () => {
const adapter = await navigator.gpu.requestAdapter();
assert_not_equals(adapter, null, "A WebGPU adapter is available");
const device = await adapter.requestDevice();
let deviceLost = false;
device.lost.then(() => deviceLost = true);
device.pushErrorScope("validation");
const module = device.createShaderModule({ code: `
@vertex fn vertex(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {
let positions = array(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
return vec4f(positions[index], 0, 1);
}
@fragment fn fragment(@builtin(position) position: vec4f) -> @location(0) vec4f {
var value = position.x * 0.001 + position.y * 0.002;
for (var index = 0u; index < 4000u; index++) {
value = fract(sin(value * 12.9898 + f32(index)) * 43758.5453);
}
return vec4f(value, value, value, 1);
}
` });
const pipeline = device.createRenderPipeline({
layout: "auto",
vertex: { module, entryPoint: "vertex" },
fragment: { module, entryPoint: "fragment", targets: [{ format: "rgba8unorm" }] },
});
const view = device.createTexture({
size: [1920, 1080],
format: "rgba8unorm",
usage: GPUTextureUsage.RENDER_ATTACHMENT,
}).createView();
const submitPass = () => {
const encoder = device.createCommandEncoder();
const pass = encoder.beginRenderPass({
colorAttachments: [{ view, loadOp: "clear", storeOp: "store" }],
});
pass.setPipeline(pipeline);
pass.draw(3);
pass.end();
device.queue.submit([encoder.finish()]);
};
// Warm up pipeline state, then measure pass duration so the queued batch
// reliably exceeds the 3s watchdog window (~4s target) without timing out on slower GPUs.
submitPass();
await device.queue.onSubmittedWorkDone();
const calibrationStart = performance.now();
submitPass();
submitPass();
await device.queue.onSubmittedWorkDone();
const msPerPass = Math.max((performance.now() - calibrationStart) / 2, 1);
const passCount = Math.min(Math.max(Math.ceil(4000 / msPerPass), 8), 2000);
for (let index = 0; index < passCount; index++)
submitPass();
await device.queue.onSubmittedWorkDone();
assert_equals(await device.popErrorScope(), null, "No validation error");
assert_false(deviceLost, "Queued render work must not lose the device");
}, "A backlog of individually short render passes does not trigger the command-buffer watchdog");
</script>