# nikgeneburn/prim32 architecture

> Architecture diagram of the GitHub repository nikgeneburn/prim32, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nikgeneburn/prim32
- Repository: https://github.com/nikgeneburn/prim32

## Overview

Prim32 is an immediate-mode GUI and 2D renderer integrated into an application’s Direct3D 12 frame loop. The app builds widgets or issues draw-list commands; core text and resource handling emit compact primitives, which the D3D12 backend submits for GPU expansion and shading. The README also documents cached layers and a built-in CPU/GPU/system profiler. Arrows use only relationships shown in excerpts or README; unsampled subsystem details are represented by their existing directories, and links without direct evidence are omitted.

Main entry points: [`src/backends/prim32_dx12.cpp`](https://github.com/nikgeneburn/prim32/blob/main/src/backends/prim32_dx12.cpp) (D3D12 backend), [`include/prim32/prim32.h`](https://github.com/nikgeneburn/prim32/blob/main/include/prim32/prim32.h) (Draw-list primitives), [`src/prim32.cpp`](https://github.com/nikgeneburn/prim32/blob/main/src/prim32.cpp) (Context and widgets), [`src/profiler/p32prof.cpp`](https://github.com/nikgeneburn/prim32/blob/main/src/profiler/p32prof.cpp) (Metrics and history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI and drawing"]
  node_core["Context and widgets<br/>[prim32.cpp]"]
  node_drawlist["Draw-list primitives<br/>[prim32.h]"]
  node_state[("Persistent UI state<br/>[prim32_state.cpp]")]
  node_text["Text emission<br/>[prim32.cpp]"]
  node_internal["Shared runtime internals<br/>[prim32_internal.h]"]
end

subgraph group_resources["Fonts and images"]
  node_resource["Image and font handles"]
  node_raster["FreeType rasterizer"]
end

subgraph group_render["GPU rendering"]
  node_backend["D3D12 backend<br/>[prim32_dx12.cpp]"]
  node_cache["Cached primitive layers<br/>[prim32.h]"]
  node_gpu["GPU pipeline"]
end

subgraph group_profiler["Profiling"]
  node_profapi["Profiler API<br/>[p32prof.h]"]
  node_profcore["Metrics and history<br/>[p32prof.cpp]"]
  node_profui["Profiler window<br/>[p32prof_ui.cpp]"]
end

node_app(("D3D12 application"))
node_system["OS and GPU metrics"]

node_app -->|"builds UI"| node_core
node_app -->|"issues commands"| node_drawlist
node_core -->|"emits primitives"| node_drawlist
node_core -->|"draws text"| node_text
node_text -->|"uses glyph cache"| node_internal
node_resource -->|"resolves fonts"| node_internal
node_resource -->|"uploads textures"| node_backend
node_raster -->|"initializes atlas"| node_internal
node_drawlist -->|"submits primitives"| node_backend
node_backend -->|"draws and shades"| node_gpu
node_drawlist -->|"records layers"| node_cache
node_backend -->|"uploads cached layers"| node_cache
node_backend -->|"reports GPU zones"| node_profcore
node_profui -->|"reads metrics"| node_profcore
node_profui -->|"draws profiler UI"| node_drawlist
node_profcore -->|"samples process metrics"| node_system
node_core -.->|"maintains UI state"| node_state

click node_core "https://github.com/nikgeneburn/prim32/blob/main/src/prim32.cpp"
click node_drawlist "https://github.com/nikgeneburn/prim32/blob/main/include/prim32/prim32.h"
click node_state "https://github.com/nikgeneburn/prim32/blob/main/src/prim32_state.cpp"
click node_text "https://github.com/nikgeneburn/prim32/blob/main/src/prim32.cpp"
click node_resource "https://github.com/nikgeneburn/prim32/blob/main/src/prim32_resources.cpp"
click node_raster "https://github.com/nikgeneburn/prim32/blob/main/src/prim32_freetype.cpp"
click node_internal "https://github.com/nikgeneburn/prim32/blob/main/src/prim32_internal.h"
click node_backend "https://github.com/nikgeneburn/prim32/blob/main/src/backends/prim32_dx12.cpp"
click node_cache "https://github.com/nikgeneburn/prim32/blob/main/include/prim32/prim32.h"
click node_profapi "https://github.com/nikgeneburn/prim32/blob/main/include/prim32/p32prof.h"
click node_profcore "https://github.com/nikgeneburn/prim32/blob/main/src/profiler/p32prof.cpp"
click node_profui "https://github.com/nikgeneburn/prim32/blob/main/src/profiler/p32prof_ui.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core,node_drawlist,node_state,node_text,node_internal toneBlue
class node_resource,node_raster toneAmber
class node_backend,node_cache,node_gpu toneMint
class node_profapi,node_profcore,node_profui toneRose
class node_app,node_system toneIndigo
```

## Components

### UI and drawing

- [Context and widgets](https://github.com/nikgeneburn/prim32/blob/main/src/prim32.cpp): `src/prim32.cpp`
- [Draw-list primitives](https://github.com/nikgeneburn/prim32/blob/main/include/prim32/prim32.h): `include/prim32/prim32.h`
- [Persistent UI state](https://github.com/nikgeneburn/prim32/blob/main/src/prim32_state.cpp): `src/prim32_state.cpp`
- [Text emission](https://github.com/nikgeneburn/prim32/blob/main/src/prim32.cpp): `src/prim32.cpp`
- [Shared runtime internals](https://github.com/nikgeneburn/prim32/blob/main/src/prim32_internal.h): `src/prim32_internal.h`

### Fonts and images

- [Image and font handles](https://github.com/nikgeneburn/prim32/blob/main/src/prim32_resources.cpp): `src/prim32_resources.cpp`
- [FreeType rasterizer](https://github.com/nikgeneburn/prim32/blob/main/src/prim32_freetype.cpp): `src/prim32_freetype.cpp`

### GPU rendering

- [D3D12 backend](https://github.com/nikgeneburn/prim32/blob/main/src/backends/prim32_dx12.cpp): `src/backends/prim32_dx12.cpp`
- [Cached primitive layers](https://github.com/nikgeneburn/prim32/blob/main/include/prim32/prim32.h): `include/prim32/prim32.h`
- **GPU pipeline**

### Profiling

- [Profiler API](https://github.com/nikgeneburn/prim32/blob/main/include/prim32/p32prof.h): `include/prim32/p32prof.h`
- [Metrics and history](https://github.com/nikgeneburn/prim32/blob/main/src/profiler/p32prof.cpp): `src/profiler/p32prof.cpp`
- [Profiler window](https://github.com/nikgeneburn/prim32/blob/main/src/profiler/p32prof_ui.cpp): `src/profiler/p32prof_ui.cpp`

### Other components

- **D3D12 application**
- **OS and GPU metrics**

## Connections

- D3D12 application → Context and widgets: builds UI (evidence: `README.md`)
- D3D12 application → Draw-list primitives: issues commands (evidence: `README.md`)
- Context and widgets → Draw-list primitives: emits primitives (evidence: `README.md`)
- Context and widgets → Text emission: draws text (evidence: `src/prim32.cpp`)
- Text emission → Shared runtime internals: uses glyph cache (evidence: `src/prim32_internal.h`)
- Image and font handles → Shared runtime internals: resolves fonts (evidence: `src/prim32_internal.h`)
- Image and font handles → D3D12 backend: uploads textures
- FreeType rasterizer → Shared runtime internals: initializes atlas (evidence: `src/prim32_freetype.cpp`)
- Draw-list primitives → D3D12 backend: submits primitives (evidence: `README.md`)
- D3D12 backend → GPU pipeline: draws and shades (evidence: `src/backends/prim32_dx12.cpp`)
- Draw-list primitives → Cached primitive layers: records layers (evidence: `README.md`)
- D3D12 backend → Cached primitive layers: uploads cached layers (evidence: `src/backends/prim32_dx12.cpp`)
- D3D12 backend → Metrics and history: reports GPU zones
- Profiler window → Metrics and history: reads metrics (evidence: `src/profiler/p32prof_ui.cpp`)
- Profiler window → Draw-list primitives: draws profiler UI (evidence: `src/profiler/p32prof_ui.cpp`)
- Metrics and history → OS and GPU metrics: samples process metrics
- Context and widgets → Persistent UI state: maintains UI state
