# yahya-azeem/shadps5 architecture

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

- Interactive diagram: https://gitdiagram.com/yahya-azeem/shadps5
- Repository: https://github.com/yahya-azeem/shadps5

## Overview

1. **Top-level shape**
   - This repo is a Rust-based PS5 compatibility layer, not a full instruction-set CPU emulator.
   - The architecture centers on translating guest OS/GPU-facing calls into host-side services on Windows/Linux, with Vulkan used for rendering and SDL2 used for windowing/input integration.

2. **Entrypoint and orchestration**
   - `src/main.rs` is the runtime entrypoint that wires the subsystems together for a single emulation session.
   - `src/bin/scratch.rs` looks like an auxiliary/debug executable for experimentation rather than the primary product path.

3. **Program loading and symbol resolution**
   - `src/loader.rs` is the first major boundary: it loads PS5 executables and prepares them for execution.
   - `src/hle_symbols.rs` and `src/hle_autogen.rs` provide the symbol/NID resolution layer needed to map guest imports to host-side implementations.
   - `src/decompression.rs` likely supports unpacking or inflating guest assets/content used during load-time or service emulation.

4. **Guest kernel and syscall virtualization**
   - `src/kernel.rs` is the core syscall/ABI translation layer, mapping PS5/FreeBSD-style kernel interactions to host equivalents.
   - `src/kernel_hle.rs` appears to host higher-level kernel services that are too semantic to treat as raw syscalls alone.
   - `src/memory_tracker.rs` supports memory mapping, guest address-space bookkeeping, and lifetime tracking for emulated allocations.
   - `src/sync.rs` provides synchronization primitives used to coordinate guest-visible concurrency with host execution.

5. **System service shims**
   - The repo splits several PS5 OS services into dedicated modules rather than one monolith:
     - `src/user_service.rs`
     - `src/common_dialog.rs`
     - `src/save_data.rs`
     - `src/network.rs`
     - `src/network_profile.rs`
   - These modules represent the HLE boundary for common console services: user identity/session state, dialogs, save-state/storage behavior, and network/profile metadata.

6. **Graphics command path**
   - `src/graphics.rs` is the main graphics translation layer.
   - It likely receives guest GPU command streams and turns them into host rendering operations.
   - `src/gpu_queue.rs` suggests a queueing/dispatch model for GPU work, separating command submission from execution/presentation.

7. **Shader and pipeline translation**
   - `src/shader_translation.rs` is a distinct graphics subsystem, likely responsible for converting guest shader representations into host-compatible shaders or intermediate forms.
   - This is an important architectural boundary because shader translation is usually separate from command-buffer translation and presentation.

8. **Presentation and video output**
   - `src/video_out.rs` is the display-facing output layer, bridging rendered frames to the host window/swapchain path.
   - This is where the emulator’s graphics stack meets SDL2/windowing and the user-visible framebuffer.

9. **Audio and input**
   - `src/audio.rs` and `src/input.rs` are the main real-time I/O interfaces.
   - They separate low-latency host device integration from the kernel/service emulation path, which helps keep interactive subsystems isolated from load-time and graphics logic.

10. **GPU/runtime support and AMPR**
   - `src/ampr.rs` appears to be a low-level GPU or packet-format support module, likely adjacent to the graphics command translator.
   - Taken together with `gpu_queue.rs` and `graphics.rs`, this suggests a pipeline that decodes guest GPU submission formats, queues work, and emits Vulkan calls.

11. **External/runtime dependencies that matter architecturally**
   - Vulkan is the primary rendering backend; this drives the design of the graphics and shader subsystems.
   - SDL2 provides cross-platform window creation, event handling, and input capture.
   - The codebase is pure Rust, with host-specific OS behavior abstracted behind modules instead of platform-specific application tiers.

12. **How the data flows**
   - A PS5 executable enters through the loader.
   - Imports/NIDs are resolved into HLE services and kernel shims.
   - Guest syscalls are intercepted by the kernel layer.
   - Guest GPU command traffic is routed through the graphics/queue/shader stack to Vulkan.
   - Frame output is presented through `video_out`, while audio, input, save data, dialog, and network requests are handled by dedicated service modules.

13. **What to draw in an architecture diagram**
   - The main boundary is between **guest PS5 executable + guest OS expectations** and **host-native Rust services**.
   - Inside the host side, show four major clusters: **loading/linking**, **kernel/service emulation**, **graphics/GPU translation**, and **interactive I/O/services**.
   - Treat `memory_tracker`, `sync`, and `gpu_queue` as shared runtime infrastructure connecting those clusters rather than standalone features.

Main entry points: [`src/main.rs`](https://github.com/yahya-azeem/shadps5/blob/main/src/main.rs) (Main), [`src/kernel_hle.rs`](https://github.com/yahya-azeem/shadps5/blob/main/src/kernel_hle.rs) (Kernel HLE), [`src/kernel.rs`](https://github.com/yahya-azeem/shadps5/blob/main/src/kernel.rs) (Kernel), [`src/loader.rs`](https://github.com/yahya-azeem/shadps5/blob/main/src/loader.rs) (Loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Main<br/>entrypoint<br/>[main.rs]"]
  node_scratch["Scratch<br/>debug bin<br/>[scratch.rs]"]
end

subgraph group_load["Loading"]
  node_loader["Loader<br/>[loader.rs]"]
  node_symbols["Symbols<br/>NID map<br/>[hle_symbols.rs]"]
  node_autogen["Autogen<br/>generated HLE<br/>[hle_autogen.rs]"]
  node_decompress["Decompress<br/>asset unpack<br/>[decompression.rs]"]
end

subgraph group_kernel["Kernel HLE"]
  node_kernel_core["Kernel<br/>syscall shim<br/>[kernel.rs]"]
  node_kernel_hle["Kernel HLE<br/>OS services<br/>[kernel_hle.rs]"]
  node_memtrack["Memory<br/>address space<br/>[memory_tracker.rs]"]
  node_sync["Sync<br/>concurrency<br/>[sync.rs]"]
end

subgraph group_gfx["Graphics"]
  node_graphics["Graphics<br/>GPU translate<br/>[graphics.rs]"]
  node_gpu_queue["GPU Queue<br/>dispatch queue<br/>[gpu_queue.rs]"]
  node_shader["Shaders<br/>shader translate"]
  node_ampr["AMPR<br/>GPU support<br/>[ampr.rs]"]
  node_video_out["Video Out<br/>present<br/>[video_out.rs]"]
end

subgraph group_io["I/O Services"]
  node_audio["Audio<br/>device I/O<br/>[audio.rs]"]
  node_input["Input<br/>device I/O<br/>[input.rs]"]
  node_user_service["User<br/>HLE service<br/>[user_service.rs]"]
  node_dialog["Dialog<br/>HLE service<br/>[common_dialog.rs]"]
  node_save_data["Save Data<br/>HLE service<br/>[save_data.rs]"]
  node_network["Network<br/>HLE service<br/>[network.rs]"]
  node_profile["Profile<br/>HLE service<br/>[network_profile.rs]"]
end

node_main -->|"boot"| node_loader
node_main -->|"run"| node_kernel_core
node_main -->|"init gfx"| node_graphics
node_main -->|"init io"| node_audio
node_main -->|"init io"| node_input
node_loader -->|"unpack"| node_decompress
node_loader -->|"resolve"| node_symbols
node_symbols -->|"bind"| node_autogen
node_loader -->|"handoff"| node_kernel_core
node_kernel_core -->|"service"| node_kernel_hle
node_kernel_core -->|"map"| node_memtrack
node_kernel_core -->|"sync"| node_sync
node_kernel_hle -->|"user"| node_user_service
node_kernel_hle -->|"dialog"| node_dialog
node_kernel_hle -->|"save"| node_save_data
node_kernel_hle -->|"net"| node_network
node_network -->|"profile"| node_profile
node_graphics -->|"queue"| node_gpu_queue
node_gpu_queue -->|"decode"| node_ampr
node_graphics -->|"translate"| node_shader
node_graphics -->|"present"| node_video_out
node_video_out -.->|"events"| node_input
node_audio -.->|"callbacks"| node_main
node_input -.->|"events"| node_main

click node_main "https://github.com/yahya-azeem/shadps5/blob/main/src/main.rs"
click node_scratch "https://github.com/yahya-azeem/shadps5/blob/main/src/bin/scratch.rs"
click node_loader "https://github.com/yahya-azeem/shadps5/blob/main/src/loader.rs"
click node_symbols "https://github.com/yahya-azeem/shadps5/blob/main/src/hle_symbols.rs"
click node_autogen "https://github.com/yahya-azeem/shadps5/blob/main/src/hle_autogen.rs"
click node_decompress "https://github.com/yahya-azeem/shadps5/blob/main/src/decompression.rs"
click node_kernel_core "https://github.com/yahya-azeem/shadps5/blob/main/src/kernel.rs"
click node_kernel_hle "https://github.com/yahya-azeem/shadps5/blob/main/src/kernel_hle.rs"
click node_memtrack "https://github.com/yahya-azeem/shadps5/blob/main/src/memory_tracker.rs"
click node_sync "https://github.com/yahya-azeem/shadps5/blob/main/src/sync.rs"
click node_graphics "https://github.com/yahya-azeem/shadps5/blob/main/src/graphics.rs"
click node_gpu_queue "https://github.com/yahya-azeem/shadps5/blob/main/src/gpu_queue.rs"
click node_shader "https://github.com/yahya-azeem/shadps5/blob/main/src/shader_translation.rs"
click node_ampr "https://github.com/yahya-azeem/shadps5/blob/main/src/ampr.rs"
click node_video_out "https://github.com/yahya-azeem/shadps5/blob/main/src/video_out.rs"
click node_audio "https://github.com/yahya-azeem/shadps5/blob/main/src/audio.rs"
click node_input "https://github.com/yahya-azeem/shadps5/blob/main/src/input.rs"
click node_user_service "https://github.com/yahya-azeem/shadps5/blob/main/src/user_service.rs"
click node_dialog "https://github.com/yahya-azeem/shadps5/blob/main/src/common_dialog.rs"
click node_save_data "https://github.com/yahya-azeem/shadps5/blob/main/src/save_data.rs"
click node_network "https://github.com/yahya-azeem/shadps5/blob/main/src/network.rs"
click node_profile "https://github.com/yahya-azeem/shadps5/blob/main/src/network_profile.rs"

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_main,node_scratch toneBlue
class node_loader,node_symbols,node_autogen,node_decompress toneAmber
class node_kernel_core,node_kernel_hle,node_memtrack,node_sync toneMint
class node_graphics,node_gpu_queue,node_shader,node_ampr,node_video_out toneRose
class node_audio,node_input,node_user_service,node_dialog,node_save_data,node_network,node_profile toneIndigo
```

## Components

### Runtime

Process entrypoint and session orchestration

- [Main](https://github.com/yahya-azeem/shadps5/blob/main/src/main.rs): entrypoint · Wires subsystems for a single emulation run · `src/main.rs`
- [Scratch](https://github.com/yahya-azeem/shadps5/blob/main/src/bin/scratch.rs): debug bin · Auxiliary experimentation executable · `src/bin/scratch.rs`

### Loading

Executable loading and symbol binding

- [Loader](https://github.com/yahya-azeem/shadps5/blob/main/src/loader.rs): exe loader · Loads PS5 binaries and prepares execution · `src/loader.rs`
- [Symbols](https://github.com/yahya-azeem/shadps5/blob/main/src/hle_symbols.rs): NID map · Resolves guest imports to host implementations · `src/hle_symbols.rs`
- [Autogen](https://github.com/yahya-azeem/shadps5/blob/main/src/hle_autogen.rs): generated HLE · Generated symbol bindings and stubs · `src/hle_autogen.rs`
- [Decompress](https://github.com/yahya-azeem/shadps5/blob/main/src/decompression.rs): asset unpack · Inflates or unpacks loaded content · `src/decompression.rs`

### Kernel HLE

Guest kernel and OS service emulation

- [Kernel](https://github.com/yahya-azeem/shadps5/blob/main/src/kernel.rs): syscall shim · Translates guest kernel ABI and syscalls · `src/kernel.rs`
- [Kernel HLE](https://github.com/yahya-azeem/shadps5/blob/main/src/kernel_hle.rs): OS services · Higher-level kernel and OS behaviors · `src/kernel_hle.rs`
- [Memory](https://github.com/yahya-azeem/shadps5/blob/main/src/memory_tracker.rs): address space · Tracks guest mappings and allocation lifetime · `src/memory_tracker.rs`
- [Sync](https://github.com/yahya-azeem/shadps5/blob/main/src/sync.rs): concurrency · Guest-visible synchronization primitives · `src/sync.rs`

### Graphics

GPU translation and presentation

- [Graphics](https://github.com/yahya-azeem/shadps5/blob/main/src/graphics.rs): GPU translate · Translates guest GPU commands · `src/graphics.rs`
- [GPU Queue](https://github.com/yahya-azeem/shadps5/blob/main/src/gpu_queue.rs): dispatch queue · Queues and schedules GPU work · `src/gpu_queue.rs`
- [Shaders](https://github.com/yahya-azeem/shadps5/blob/main/src/shader_translation.rs): shader translate · Converts guest shaders to host form · `src/shader_translation.rs`
- [AMPR](https://github.com/yahya-azeem/shadps5/blob/main/src/ampr.rs): GPU support · Low-level packet or GPU format support · `src/ampr.rs`
- [Video Out](https://github.com/yahya-azeem/shadps5/blob/main/src/video_out.rs): present · Presents frames to host display path · `src/video_out.rs`

### I/O Services

Audio, input, and console services

- [Audio](https://github.com/yahya-azeem/shadps5/blob/main/src/audio.rs): device I/O · Host audio integration · `src/audio.rs`
- [Input](https://github.com/yahya-azeem/shadps5/blob/main/src/input.rs): device I/O · Host input integration · `src/input.rs`
- [User](https://github.com/yahya-azeem/shadps5/blob/main/src/user_service.rs): HLE service · User identity and session state · `src/user_service.rs`
- [Dialog](https://github.com/yahya-azeem/shadps5/blob/main/src/common_dialog.rs): HLE service · Console dialog and prompt handling · `src/common_dialog.rs`
- [Save Data](https://github.com/yahya-azeem/shadps5/blob/main/src/save_data.rs): HLE service · Save-state and storage behavior · `src/save_data.rs`
- [Network](https://github.com/yahya-azeem/shadps5/blob/main/src/network.rs): HLE service · Network service shims · `src/network.rs`
- [Profile](https://github.com/yahya-azeem/shadps5/blob/main/src/network_profile.rs): HLE service · Network profile metadata · `src/network_profile.rs`

## Connections

- Main → Loader: boot · Starts executable loading and session setup
- Main → Kernel: run · Enters guest syscall and ABI handling
- Main → Graphics: init gfx · Initializes the rendering path
- Main → Audio: init io · Initializes interactive host devices
- Main → Input: init io · Initializes interactive host devices
- Loader → Decompress: unpack · Expands compressed assets or payloads
- Loader → Symbols: resolve · Maps guest imports to HLE implementations
- Symbols → Autogen: bind · Uses generated symbol tables and stubs
- Loader → Kernel: handoff · Transfers loaded program into execution
- Kernel → Kernel HLE: service · Delegates higher-level OS behaviors
- Kernel → Memory: map · Maintains guest address-space state
- Kernel → Sync: sync · Coordinates guest-visible synchronization
- Kernel HLE → User: user · Provides user/session state
- Kernel HLE → Dialog: dialog · Handles system dialog flows
- Kernel HLE → Save Data: save · Routes save-data requests
- Kernel HLE → Network: net · Handles network service calls
- Network → Profile: profile · Resolves network profile metadata
- Graphics → GPU Queue: queue · Submits GPU work for scheduling
- GPU Queue → AMPR: decode · Decodes low-level GPU packet formats
- Graphics → Shaders: translate · Builds host-compatible shader forms
- Graphics → Video Out: present · Sends rendered frames to display output
- Video Out → Input: events · Shares window and presentation event loop
- Audio → Main: callbacks · Feeds runtime audio callbacks
- Input → Main: events · Feeds runtime input events
