fix(web): stop the transfer-FBO leak and the canvas-freeze resize churn
- renderer: release_transfer_images() deletes the transfer framebuffer instead of only zeroing the name; the leak exhausted VRAM and killed the GPU process under Vulkan after ~3-7 minutes - canvas: status notices are absolute overlays, so they no longer resize the native surface (each show/hide freed and recreated region draw buffers and eventually froze the main regions) - compute: bounded shader/layout/pipeline caches, staging pool, device-lost error propagation, dev-only ?glStats / ?computeFault / ?compute hooks - headed tools: soak/probe/smoke assets and docs - evidence: 20-minute Vulkan soak STABLE (GPU-SOAK-20261205-161007), SwiftShader control STABLE (GPU-SOAK-20261205-162105), Clip 28/28 NOT_CLAIMED (CLIP-HEADED-20261205-162214) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head><meta charset="utf-8"><title>webgl2+webgpu control</title></head>
|
||||
<body style="margin:0;background:#111">
|
||||
<canvas id="gl" width="800" height="600"></canvas>
|
||||
<script id="compute" type="text/x-wgsl">
|
||||
@group(0) @binding(0) var<storage, read_write> data: array<f32>;
|
||||
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) id: vec3<u32>) {
|
||||
let i = id.x;
|
||||
if (i < arrayLength(&data)) { data[i] = sin(data[i] + 0.01); }
|
||||
}
|
||||
</script>
|
||||
<script type="module">
|
||||
/* Both stacks the engine uses at once: a WebGL2 raster context and a WebGPU
|
||||
* compute device in the same page/GPU process. */
|
||||
const glCanvas = document.getElementById("gl");
|
||||
const gl = glCanvas.getContext("webgl2");
|
||||
let glOk = false;
|
||||
if (gl) {
|
||||
glOk = true;
|
||||
gl.clearColor(0.1, 0.2, 0.5, 1);
|
||||
}
|
||||
const adapter = await navigator.gpu?.requestAdapter().catch(() => null);
|
||||
let computeOk = false;
|
||||
let device = null;
|
||||
if (adapter) {
|
||||
device = await adapter.requestDevice();
|
||||
const data = new Float32Array(100000).map((_, index) => Math.sin(index));
|
||||
const buffer = device.createBuffer({ size: data.byteLength, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC });
|
||||
device.queue.writeBuffer(buffer, 0, data);
|
||||
const module = device.createShaderModule({ code: document.getElementById("compute").textContent });
|
||||
const pipeline = device.createComputePipeline({ layout: "auto", compute: { module, entryPoint: "main" } });
|
||||
const bind = device.createBindGroup({ layout: pipeline.getBindGroupLayout(0), entries: [{ binding: 0, resource: { buffer } }] });
|
||||
const encoder = device.createCommandEncoder();
|
||||
const pass = encoder.beginComputePass();
|
||||
pass.setPipeline(pipeline);
|
||||
pass.setBindGroup(0, bind);
|
||||
pass.dispatchWorkgroups(Math.ceil(100000 / 64));
|
||||
pass.end();
|
||||
device.queue.submit([encoder.finish()]);
|
||||
computeOk = true;
|
||||
}
|
||||
document.title = `combined gl=${glOk} compute=${computeOk}`;
|
||||
let frame = 0;
|
||||
function tick() {
|
||||
if (gl) {
|
||||
gl.clearColor(0.1 + 0.05 * Math.sin(frame / 30), 0.2, 0.5, 1);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
}
|
||||
frame += 1;
|
||||
document.body.dataset.frames = String(frame);
|
||||
requestAnimationFrame(tick);
|
||||
}
|
||||
tick();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
8
tools/web/headed/fixtures/webgpu-control/index.html
Normal file
8
tools/web/headed/fixtures/webgpu-control/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head><meta charset="utf-8"><title>webgpu control</title></head>
|
||||
<body style="margin:0;background:#111">
|
||||
<canvas id="canvas" width="800" height="600"></canvas>
|
||||
<script type="module" src="./main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
49
tools/web/headed/fixtures/webgpu-control/main.js
Normal file
49
tools/web/headed/fixtures/webgpu-control/main.js
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Minimal WebGPU control page: one compute dispatch plus one render pass per
|
||||
* frame. Used by the headed tools as the "environment vs application" control
|
||||
* (see docs/web/HEADED-TOOLS.md). */
|
||||
const canvas = document.getElementById("canvas");
|
||||
const adapter = await navigator.gpu?.requestAdapter();
|
||||
if (!adapter) {
|
||||
document.title = "no-adapter";
|
||||
throw new Error("no webgpu adapter");
|
||||
}
|
||||
const device = await adapter.requestDevice();
|
||||
document.title = `webgpu ${adapter.info?.vendor ?? ""}/${adapter.info?.architecture ?? ""}`;
|
||||
const context = canvas.getContext("webgpu");
|
||||
const format = navigator.gpu.getPreferredCanvasFormat();
|
||||
context.configure({ device, format, alphaMode: "opaque" });
|
||||
|
||||
const N = 100000;
|
||||
const data = new Float32Array(N).map((_, index) => Math.sin(index));
|
||||
const buffer = device.createBuffer({ size: data.byteLength, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC });
|
||||
device.queue.writeBuffer(buffer, 0, data);
|
||||
const module = device.createShaderModule({
|
||||
code: `
|
||||
@group(0) @binding(0) var<storage, read_write> data: array<f32>;
|
||||
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) id: vec3<u32>) {
|
||||
let i = id.x;
|
||||
if (i < arrayLength(&data)) { data[i] = sin(data[i] + 0.01); }
|
||||
}`,
|
||||
});
|
||||
const pipeline = device.createComputePipeline({ layout: "auto", compute: { module, entryPoint: "main" } });
|
||||
const bind = device.createBindGroup({ layout: pipeline.getBindGroupLayout(0), entries: [{ binding: 0, resource: { buffer } }] });
|
||||
|
||||
let frame = 0;
|
||||
function tick() {
|
||||
const encoder = device.createCommandEncoder();
|
||||
const pass = encoder.beginComputePass();
|
||||
pass.setPipeline(pipeline);
|
||||
pass.setBindGroup(0, bind);
|
||||
pass.dispatchWorkgroups(Math.ceil(N / 64));
|
||||
pass.end();
|
||||
const view = context.getCurrentTexture().createView();
|
||||
const render = encoder.beginRenderPass({
|
||||
colorAttachments: [{ view, clearValue: { r: 0.06 + 0.02 * Math.sin(frame / 10), g: 0.2, b: 0.5, a: 1 }, loadOp: "clear", storeOp: "store" }],
|
||||
});
|
||||
render.end();
|
||||
device.queue.submit([encoder.finish()]);
|
||||
frame += 1;
|
||||
document.body.dataset.frames = String(frame);
|
||||
requestAnimationFrame(tick);
|
||||
}
|
||||
tick();
|
||||
Reference in New Issue
Block a user