Expand description
GPU-accelerated force-directed graph layout using WebGPU.
This crate provides a high-performance Barnes-Hut force-directed layout algorithm that runs on the GPU via wgpu, supporting both native (Vulkan/Metal/DX12) and web (WebGPU) platforms.
§Architecture
┌─────────────────────────────────────────────────────────────┐
│ CPU Side │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Graph Data │───▶│ Quadtree │───▶│ GPU Buffers │ │
│ │ (positions) │ │ (Barnes-Hut)│ │ (upload) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ GPU Side │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Repulsive │───▶│ Attractive │───▶│ Integrate │ │
│ │ Forces │ │ Forces │ │ Positions │ │
│ │ (BH approx) │ │ (edges) │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Read Back │
│ Updated positions copied back to CPU for rendering │
└─────────────────────────────────────────────────────────────┘§Performance
- Traditional Fruchterman-Reingold: O(n²) per iteration
- Barnes-Hut approximation: O(n log n) per iteration
- GPU parallelization: ~100x speedup for large graphs
For a 10,000 node graph:
- CPU O(n²): ~100M operations → ~10 FPS
- GPU Barnes-Hut: ~100K operations, parallelized → 60+ FPS
Structs§
- Edge
- An edge between two nodes.
- GpuLayout
- GPU-accelerated force-directed graph layout.
- Layout
Config - Configuration for the GPU layout.
- Layout
Params - Layout parameters for the force-directed algorithm.
- Position
- A 2D position.
- Quad
Tree - A Barnes-Hut quadtree for 2D spatial partitioning.
- Quad
Tree Node - Barnes-Hut quadtree node for GPU upload. This is a flattened representation suitable for GPU processing.
- Velocity
- A 2D velocity.
Enums§
- Layout
Error - Errors that can occur during GPU layout operations.
- Layout
State - Current state of the layout.
Type Aliases§
- Result
- Result type for layout operations.