RustLayout Architecture¶
RustLayout is a clean-room, 100% pure-Rust (edition = "2024", rust-version = "1.100", unsafe_code = "deny" at workspace root) IC layout viewing and verification engine designed for gigabyte-scale GDSII, .gds.gz, and SEMI P39 OASIS databases.
1. Crate Dependency Graph¶
rustlayout-cli
├── rustlayout-app (winit 0.30 + wgpu 30 + egui 0.37 + egui_dock 0.22 desktop workbench)
│ └── rustlayout-render
├── rustlayout-render (GUI-agnostic wgpu engine: headless PNG, embeddable surface, XOR diff)
│ ├── rustlayout-style (KLayout .lyp XML codec, 32x32 GPU stipples, PDK presets)
│ └── rustlayout-db
├── rustlayout-db (SoA arenas, Hilbert sort, 128B BvhNode4 HLOD, picker, .rlay mmap cache)
│ └── rustlayout-gds
├── rustlayout-gds (Two-phase parallel GDSII, .gds.gz, SEMI P39 OASIS + CBLOCK inflate)
│ └── rustlayout-core
└── rustlayout-core (DBU i32/i64 geometry, D4/affine transforms, CameraState, ResourceLimits)
rustlayout-benchgen (Deterministic canonical, hostile-fuzz, and multi-GB stress GDS writer)
rustlayout-render has zero dependency on winit or egui and accepts externally owned wgpu handles via GpuContext::from_external(instance, adapter, device, queue) so RustEDA Studio or headless CI tools can embed it directly.
2. Two-Phase Parallel Ingestion (rustlayout-gds)¶
- GDSII:
- Phase 0 (Streaming Scan & Intra-Cell Chunking): Files
< 32 MiBuse zero-copy read-onlymmap; files>= 32 MiBon Unix stream sequentially through a 4 MiB buffer to locate cell boundaries and split giant flat cells (> 16 MiB, e.g., 2 GB dummy metal fill) into~8 MiBENDEL-aligned chunks so all CPU cores stay saturated. - Phase 1 (Rayon Parallel Decode): Worker threads read chunks via Unix
pread(FileExt::read_exact_at, preventing the raw multi-GB GDS file from inflating process RSS), run a 64-byte canonical rectangle fast-path directly into compactRectI32(16 B/rect), preserveAREFs strictly unexpanded, and merge one layer at a time to keep peak RAM at 0.49×–0.61× file size on multi-GB layouts. - Hierarchy & Safety: Iterative 3-color DFS rejects cyclic
SREF/AREFgraphs cleanly, enforcesResourceLimits(max_file_bytes,max_cells,max_hierarchy_depth,max_vertices_per_shape), and propagates exactRectI64bounding boxes bottom-up in O(1) perAREF. .gds.gz: Detected automatically by gzip magic0x1F 0x8Band decompressed with pure-Rustflate2(rust_backend/miniz_oxide) bounded byResourceLimits::max_file_bytes.- SEMI P39 OASIS (
.oas): Detected automatically by%SEMI-OASIS\r\n. Top-levelCBLOCK(record 34) compressed spans are extracted and inflated in parallel withrayon+ pure-Rust RFC1951 raw deflate. Regular placement repetitions (types 1, 2, 3, 8, 9) map directly into native unexpandedArefRecords.
3. Spatial Database, Hilbert 4-Wide BVH & .rlay Cache (rustlayout-db)¶
- Hilbert Spatial Locality: Every rectangle bucket is sorted along a 32-bit Hilbert curve using a low-scratch parallel 12-bit MSB radix sort, grouping spatially adjacent metal tracks into contiguous 1 MiB (
65,536rect) GPU chunks. - 128-Byte Cache-Aligned
BvhNode4: - Cache line 0 (
0..64 B): SoA child bounding boxes (min_x[4], min_y[4], max_x[4], max_y[4]). - Cache line 1 (
64..128 B):child_start[4],child_len[4](MSB leaf tag),max_extent[4](largest individual shape dimension in subtree so sub-pixel dummy fill collapses to HLOD while long power rails stay sharp), and non-inflatingdensity[4](u8computed from an 8×8u64coverage bitmask + exact area summation). - O(1)
AREFClamping:clamp_aref_indicesinverts the 2×2 world-space lattice matrix across all four frustum corners with conservative±1padding, achieving 100% recall on arbitrary rotated/mirrored/skewed32767×32767arrays without ever expanding them. - Zero-Copy
.rlaySnapshot (RLAY0001): Serializes metadata plus 64-byte-aligned flat arenas (rects,bvh_nodes,points) protected by xxHash3-64 checksums. Reopening via read-onlymmapmaps arenas directly as&[RectI32]/&[BvhNode4]/&[PointI32]in< 0.5 ms.
4. GPU Rendering Pipeline (rustlayout-render)¶
- Exact DBU Coordinate Precision (
±1e9DBU): - Each draw batch computes a camera-centered integer
local_pivot: [i32; 2]and residualf32world offset on the CPU inf64/i64. - In WGSL, local
i32coordinates are subtracted fromlocal_pivotin integer arithmetic and split into(hi16, lo16)signed 16-bit pairs before multiplying by the 2×2 transform matrix — eliminatingf32mantissa loss even at 100 nm zoom on a 100 mm wafer. - Vertex-Pulled & Instanced Draw Paths:
RECT_MASK_WGSL: pullsRectI32directly from16 B/rectstorage slabs, supports multi-SREFinstance batches and native unexpandedAREF(col, row)stride evaluation directly on GPU, and renders crisp analytical 1px borders.POLY_MASK_WGSL&EDGE_MASK_WGSL: renders lazily triangulated1,024-polygon chunks (clean-room earcut with convex fast-path and keyhole-safe fallback) plus 1px outline edge quads.HLOD_MASK_WGSL: draws coverage-calibrated density quads for sub-pixel BVH nodes, collapsed leaf cells, sub-pixelAREFs, and zero-fault deferred chunks while streaming.CULL_COMPUTE_WGSL: runnable WGSL compute frustum + size culler producing indirect draw arguments.- Bounded VRAM & Mask Caching:
VramPool: frame-stamped LRU pool capped at--max-vram-mibwith a per-frame staging budget (4 MiB/frameduring interactive motion) and zero-fault HLOD fallback when streaming new chunks.LayerMaskCache: per-layerRG8Unorm(R = fill,G = border) offscreen masks paired with a pre-allocated dynamic uniform ring forCOMPOSITE_WGSL, yielding< 1.7 mslayer visibility/color/stipple/Z-order toggles at Retina3024×1964plus GPUcopy_texture_to_texturepan tile-shift for smooth border-strip-only panning.XOR_DIFF_WGSL: composites dual-layout masks in real time (A \ BCopper#F08A4B,B \ AMint#4ADBC0,A ∩ Bdim Slate).
5. Desktop Workbench & RustEDA Integration (rustlayout-app)¶
- Zero Idle Power: Direct
winit 0.30ApplicationHandlerswitches toControlFlow::Waitas soon as damped camera motion and background loaders settle (0% idle CPU/GPU). - Desktop Menu Bar & Native Dialogs: Complete 8-menu CAD bar (
File,Edit,View,Layers,Tools,Diff,Window,Help) with native OS open/save dialogs (rfd), persistentOpen Recentlist, background.rlaycache export, GPU PNG viewport export,.lypload/save, dynamic window titles, and dockable/toggleable side panels. - Zero-Copy Viewport & Minimap:
LayoutRendererrenders directly intoRgba8Unormwgpu::Textures registered withegui_wgpu::Renderer::register_native_texture— zero CPU pixel readback. - RustEDA Cross-Probing: Passing
--watch-focus <path.json>watches a lightweight JSON payload (bbox_dbu,layers,highlights,message) soRustEDA,RustROADDRC/antenna checks, orRustSTAcritical paths can pan/highlight exact layout regions inside an open viewer window.
6. Audited unsafe Inventory¶
Workspace lint unsafe_code = "deny" is enforced across all 8 crates. Narrow #[expect(unsafe_code, reason = "...")] blocks exist solely in two audited categories:
1. Read-only memmap2::MmapOptions::map on opened files (rustlayout-gds/src/mmap.rs, rustlayout-db/src/cache.rs).
2. bytemuck::{Pod, Zeroable} implementations on compile-time-size-checked, plain integer/float #[repr(C)] structs (RectI32, RectI64, BvhNode4, and WGSL uniform/storage structs in rustlayout-render).