# gfx-rs/wgpu architecture

> Architecture diagram of the GitHub repository gfx-rs/wgpu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gfx-rs/wgpu
- Repository: https://github.com/gfx-rs/wgpu

## Overview

##### Main Components (Top Level)

- wgpu       |     |   wgpu-core   |     |   wgpu-hal    |
- (Public API)   | --> | (Safe Core)   | --> | (HAL Layer)   |

##### Backend Implementations (Second Level)
- Under the HAL layer, connected with lines:

- Vulkan  |  | Metal  |  |  DX12  |  | OpenGL  |  | WebGPU  |

##### Supporting Components (Side Components)

- Naga   | --> | wgpu-types  |
- (Shader)|     | (Shared    |
- Types)     |

##### Key Features to Highlight
- Blue: Core API components
- Green: Backend implementations
- Yellow: Supporting libraries
- Red: Critical paths/dependencies

- Shader compilation flow through Naga
- Command submission flow from API to backends
- Resource management paths

##### Integration Points
- WebAssembly integration path
- Platform-specific bridges
- Conformance test integration points

##### Detailed Component Breakdown
- Resource management
- Command encoding
- Pipeline state
- Memory management

##### Cross-Cutting Concerns
Horizontal layers showing:
- Safety boundaries
- Platform abstraction
- API compatibility

##### Implementation Notes
Callouts for:
- WGSL support
- Platform-specific considerations
- Safety guarantees
- Performance characteristics

##### The WebGPU compliance path

Use consistent visual language:
- Double lines for safety boundaries

Keep the abstraction level appropriate by:
- Focusing on architectural components rather than implementation details
- Highlighting key integration points
- Showing major data flows
- Indicating critical dependencies

- How the components interact
- Where their code fits in the stack
- How data flows through the system
- Where platform-specific code lives
- How safety is maintained

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        L1[API Component]:::api
        L2[Core Component]:::core
        L3[Backend Component]:::backend
        L4[Support Component]:::support
        L5[Cross-cutting Component]:::crosscut
    end

    subgraph "Public API Layer"
        API["wgpu Public API"]:::api
    end

    subgraph "Safe Core Layer"
        CORE["wgpu-core"]:::core
        PIPE["Pipeline Management"]:::crosscut
        RES["Resource Management"]:::crosscut
        CMD["Command Encoding"]:::crosscut
        MEM["Memory Management"]:::crosscut
    end

    subgraph "HAL Layer"
        HAL["wgpu-hal"]:::core
    end

    subgraph "Backend Implementations"
        VULKAN["Vulkan Backend"]:::backend
        METAL["Metal Backend"]:::backend
        DX12["DirectX 12 Backend"]:::backend
        OPENGL["OpenGL Backend"]:::backend
        WEBGPU["WebGPU Backend"]:::backend
    end

    subgraph "Supporting Components"
        NAGA["Naga Shader System"]:::support
        TYPES["wgpu-types"]:::support
    end

    subgraph "Platform Integration"
        WASM["WebAssembly Support"]:::crosscut
        BRIDGES["Platform Bridges"]:::crosscut
    end

    API --> CORE
    CORE --> HAL
    CORE --> PIPE
    CORE --> RES
    CORE --> CMD
    CORE --> MEM
    
    HAL --> VULKAN
    HAL --> METAL
    HAL --> DX12
    HAL --> OPENGL
    HAL --> WEBGPU
    
    NAGA --> CORE
    TYPES --> CORE
    
    HAL --> BRIDGES
    WEBGPU --> WASM

    %% Click events for component mapping
    click API "https://github.com/gfx-rs/wgpu/blob/trunk/wgpu/src/lib.rs"
    click CORE "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-core/src/"
    click HAL "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/"
    click VULKAN "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/vulkan/"
    click METAL "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/metal/"
    click DX12 "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/dx12/"
    click OPENGL "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/gles/"
    click WEBGPU "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/backend/webgpu/"
    click NAGA "https://github.com/gfx-rs/wgpu/tree/trunk/naga/src/"
    click TYPES "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-types/src/"
    click PIPE "https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-core/src/pipeline.rs"
    click RES "https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-core/src/resource.rs"
    click CMD "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-core/src/command/"
    click MEM "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-core/src/track/"
    click WASM "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu/src/backend/webgpu/"
    click BRIDGES "https://github.com/gfx-rs/wgpu/tree/trunk/wgpu-hal/src/auxil/"

    classDef api fill:#2374ab
    classDef core fill:#048ba8
    classDef backend fill:#0db39e
    classDef support fill:#16db93
    classDef crosscut fill:#83e377
```
