forked from 1b-agent/opencadstudio-upstream
Each pipeline slot owned its own gpu_wires: every paper viewport and every Model tile rebuilt an identical resident wire set into its own GPU vertex buffers and its own handle index. With N content viewports drawing one shared tessellation that is N copies of the (potentially huge) wire buffers in VRAM plus N batch+index builds on every content change — the issue-131 memory exposure multiplied by the viewport count. A wgpu::Buffer is internally ref-counted, so sharing a WireGpu by Arc shares its GPU allocation. Make Pipeline.gpu_wires an Arc<Vec<WireGpu>> (and wire_handle_index an Arc<map>), turn upload_wires into build_wire_buffers(&self) that returns those Arcs, and add MultiPipeline.wire_buffer_cache keyed by wire_content_id. prepare() builds an entry once on a cache miss and hands Arc clones to every slot with that id — so N viewports (and, since one MultiPipeline backs all panes, N panes) upload the wire vertices exactly once between them. Camera uniforms and scissor stay per-slot, so the draw still issues one call per viewport with the right view; only the geometry is deduplicated. The shared Vec is never mutated in place — only reassigned on a content change — so the sharing is sound. The cache drops entries no slot still references (Arc::strong_count == 1) once it passes a small bound, so a live buffer (held by any pane) is never evicted. Model multi-tile gets the same dedup for free, and two panes showing the same model now share buffers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>