Files
workinf_Blender_Wasm/tools/web/headed/fixtures/webgpu-control/main.js
mes123456 5976c3dd7c 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>
2026-12-05 16:29:26 +08:00

50 lines
2.1 KiB
JavaScript

/* 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();