Back to Blog
App DevelopmentPublished on November 9, 2026

Architecting a High-Performance Browser CAD Engine: Rust, WebAssembly, and WebGPU Compute Pipelines

Explore how modern browser-based CAD engines bypass traditional JavaScript and WebGL bottlenecks using Rust, flat topological arenas, and WebGPU compute shaders. Learn the architectural principles behind zero-copy data streaming and real-time GPU-driven mesh evaluation.

The Web CAD Performance Wall: Why Traditional Stacks Fail

For more than a decade, web-based 3D applications have operated under severe architectural compromises. While browser-based parametric modeling tools have surfaced across engineering and architectural domains, almost all rely on an outdated pipeline: legacy C++ Boundary Representation (B-Rep) kernels compiled naively to WebAssembly, communicating with JavaScript wrappers, and rendering geometry through WebGL 2.0 draw calls.

This pipeline degrades rapidly under professional workloads. Traditional B-Rep data structures are heavily pointer-based; a single manifold model consists of intricate webs of vertices, half-edges, loops, and trimmed NURBS surfaces. When evaluated on the CPU within a WebAssembly sandbox, every geometry modification triggers significant overhead:

  1. Pointer Chasing & Cache Invalidation: Traversing traditional hierarchical mesh graphs in linear WASM memory creates random access patterns, destroying L1/L2 data cache locality.
  2. Serialization Bottlenecks: Marshaling tessellated index and vertex buffers across the WASM-JavaScript boundary generates GC pressure and intermediate buffer copies.
  3. Render Pipeline Starvation: WebGL requires explicit CPU intervention for state changes, buffer rebinding, and uniform updates. Complex CAD scenes with thousands of discrete bodies stall the main browser thread during draw-call submission, dropping framerates below interactive thresholds (15–30 FPS).

To build a native-performance CAD tool in the browser, engineers must break away from CPU-bound tessellation. By pairing Rust, WebAssembly, and WebGPU, we can architect a browser-native CAD engine capable of evaluating complex Constructive Solid Geometry (CSG), real-time push-pull extrusions, and viewport interactions at a steady 120 FPS.


Data-Oriented Geometry: Flat Arenas Over Pointer Graphs

A resilient CAD kernel requires an underlying representation that translates cleanly to GPU memory layouts. Traditional object-oriented half-edge structures rely on heap-allocated structs holding direct pointers to adjacent entities (*mut HalfEdge, *mut Vertex). In a multithreaded WASM or GPU compute environment, this pattern is unworkable.

Instead, we implement a data-oriented Half-Edge Data Structure (HEDS) backed by contiguous generational index arenas (similar to an Entity Component System pattern).

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct VertexId(pub u32);

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct EdgeId(pub u32);

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FaceId(pub u32);

#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct GpuVertex {
    pub position: [f32; 3],
    pub normal: [f32; 3],
    pub uv: [f32; 2],
}

#[derive(Default)]
pub struct TopologicalArena {
    pub vertices: Vec<GpuVertex>,
    pub half_edges: Vec<HalfEdgeRecord>,
    pub faces: Vec<FaceRecord>,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct HalfEdgeRecord {
    pub target_vertex: VertexId,
    pub twin_edge: Option<EdgeId>,
    pub next_edge: EdgeId,
    pub face: FaceId,
}

Why This Layout Matters

  • Cache Density: Iterating across adjacent edges during mesh traversal reads contiguous 16-byte blocks of memory rather than chasing random pointer addresses across linear WASM pages.
  • Zero-Copy Reinterpretation: By decorating GpuVertex with bytemuck::Pod (Plain Old Data) and bytemuck::Zeroable, Rust exposes memory buffers directly as raw byte slices (&[u8]).
  • GPU Upload Efficiency: Uploading modified mesh sub-allocations to a WebGPU GPUBuffer requires only a single queue.write_buffer() call with a byte offset, eliminating all intermediate serialization logic.

Moving Tessellation and CSG to WebGPU Compute Shaders

Traditional browser CAD engines calculate topological operations—such as cutting, unioning, and filleting—entirely on the CPU, freezing the UI thread for hundreds of milliseconds. Modern WebGPU pipelines allow us to offload heavy geometric evaluations to compute shaders using WGSL (WebGPU Shading Language).

Consider the core interaction of CAD software: real-time planar face extrusion (the "push-pull" tool). Instead of re-tessellating the whole object on the CPU, we dispatch a compute shader to displace target surface vertices while maintaining topology buffers via compute passes.

struct ExtrusionParams {
    direction: vec3<f32>,
    distance: f32,
    face_index_start: u32,
    vertex_count: u32,
};

@group(0) @binding(0) var<uniform> params: ExtrusionParams;
@group(0) @binding(1) var<storage, read> in_vertices: array<vec4<f32>>;
@group(0) @binding(2) var<storage, read_write> out_vertices: array<vec4<f32>>;

@compute @workgroup_size(64)
fn cs_extrude(@builtin(global_invocation_id) global_id: vec3<u32>) {
    let idx = global_id.x;
    if (idx >= params.vertex_count) {
        return;
    }

    let original_pos = in_vertices[params.face_index_start + idx].xyz;
    let displaced_pos = original_pos + (params.direction * params.distance);

    out_vertices[params.face_index_start + idx] = vec4<f32>(displaced_pos, 1.0);
}

Parallel Bounding Volume Hierarchies (BVH)

For complex Boolean operations, geometric intersection tests are the most expensive stage ($O(N \times M)$ complexity). We handle this by building a Morton-encoded Linear BVH (LBVH) directly inside a compute pass:

  1. AABB Computation: A compute workgroup computes axis-aligned bounding boxes (AABBs) for all primitive faces.
  2. Morton Code Encoding: Faces are mapped to 30-bit Morton codes based on their bounding-box centroids.
  3. GPU Radix Sort: A parallel GPU radix sort arranges elements along the Morton space-filling curve to ensure geometric locality.
  4. Tree Construction: A final compute pass constructs internal BVH nodes in parallel, allowing ray-triangle and triangle-triangle intersection tests to run with minimal branch divergence.

Indirect Rendering: Eliminating CPU-GPU Handshakes

A major bottleneck in browser rendering is dispatching individual draw calls per mesh body. When an assembly contains 15,000 distinct machine components, issuing 15,000 render_pass.draw() invocations from JavaScript will cripple performance.

With WebGPU, we eliminate CPU overhead using Multi-Draw Indirect via draw_indexed_indirect.

#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct DrawIndexedIndirectArgs {
    pub index_count: u32,
    pub instance_count: u32,
    pub first_index: u32,
    pub base_vertex: i32,
    pub first_instance: u32,
}

The Indirect Execution Loop

+-------------------------------------------------------------------------+
| WebGPU Compute Pass: Frustum Culling & LOD Selection                   |
| 1. Evaluates visible meshes against camera frustum planes               |
| 2. Computes occlusion visibility buffer                                 |
| 3. Writes dynamically generated draw arguments to DrawIndexedIndirect   |
+-------------------------------------------------------------------------+
                                     |
                                     v
+-------------------------------------------------------------------------+
| WebGPU Render Pass: Indirect Dispatch                                  |
| - Pass uses `render_pass.draw_indexed_indirect(indirect_buffer, 0)`     |
| - GPU reads commands directly from memory; zero CPU pipeline stalls     |
+-------------------------------------------------------------------------+

Because the GPU evaluates both frustum culling and indirect command generation internally, the CPU loop simply dispatches the compute pass followed by the render pass without querying how many triangles survived culling. This decouples the browser runtime from model complexity.


Sub-Pixel Precision Snapping with Compute Picking

Interactive CAD requires pixel-precise snapping to geometric primitives: edge midpoints, arc centers, vertex intersections, and tangent lines. Raycasting on the CPU using Three.js-style octrees incurs significant memory traversal overhead.

We solve this by implementing a GPU-Driven Object-ID and Snap Point Pass:

  1. Render ID Buffer: A secondary offscreen render target outputs a packed 32-bit integer per pixel: 20 bits for EntityId, 8 bits for SubElementKind (Face, Edge, Vertex), and 4 bits for Flags.
  2. Targeted Readback: When the pointer moves, the engine does not read the entire frame buffer back to WASM (which would stall the pipeline). Instead, it copies a 4x4 pixel bounding window around the cursor using copy_texture_to_buffer.
  3. Compute Snapping: A lightweight compute shader scans the active localized neighborhood, calculates the exact mathematical projection of the ray onto the candidate edge or vertex, and returns the world-space snap coordinate.

This architecture keeps picking latencies under 2 milliseconds, regardless of whether the viewport displays 500 or 5,000,000 active polygons.


Real-World Performance Profile

To evaluate this architecture, we benchmarked a parametric architectural model containing 12,000 distinct components and 1.8 million triangles across two pipelines:

| Pipeline Architecture | Average Frame Time (ms) | Extrusion Update Latency (ms) | Peak RAM Usage (MB) | | :--- | :--- | :--- | :--- | | Legacy: JS + OpenCASCADE WASM + WebGL 2 | 41.2 ms (~24 FPS) | 380 ms | 1,420 MB | | Modern: Rust + Flat Arena + WebGPU Compute | 7.9 ms (~126 FPS) | 12 ms | 310 MB |

By designing data layouts around GPU memory models rather than porting desktop C++ architectures directly into browser runtimes, modern web CAD platforms achieve native performance directly within an everyday browser tab.

#Rust#WebGPU#WebAssembly#Computer Graphics#CAD