Skip to main content

Crate vibe_graph_layout_gpu

Crate vibe_graph_layout_gpu 

Source
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.
LayoutConfig
Configuration for the GPU layout.
LayoutParams
Layout parameters for the force-directed algorithm.
Position
A 2D position.
QuadTree
A Barnes-Hut quadtree for 2D spatial partitioning.
QuadTreeNode
Barnes-Hut quadtree node for GPU upload. This is a flattened representation suitable for GPU processing.
Velocity
A 2D velocity.

Enums§

LayoutError
Errors that can occur during GPU layout operations.
LayoutState
Current state of the layout.

Type Aliases§

Result
Result type for layout operations.