How yahya-azeem/shadps5 works
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: main.rs Main · kernel_hle.rs Kernel HLE · kernel.rs Kernel · loader.rs Loader
Components 22
Runtime
Process entrypoint and session orchestration
Loading
Executable loading and symbol binding
- Loader · Loads PS5 binaries and prepares execution
src/loader.rs - Symbols · Resolves guest imports to host implementations
src/hle_symbols.rs - Autogen · Generated symbol bindings and stubs
src/hle_autogen.rs - Decompress · Inflates or unpacks loaded content
src/decompression.rs
Kernel HLE
Guest kernel and OS service emulation
- Kernel · Translates guest kernel ABI and syscalls
src/kernel.rs - Kernel HLE · Higher-level kernel and OS behaviors
src/kernel_hle.rs - Memory · Tracks guest mappings and allocation lifetime
src/memory_tracker.rs - Sync · Guest-visible synchronization primitives
src/sync.rs
Graphics
GPU translation and presentation
- Graphics · Translates guest GPU commands
src/graphics.rs - GPU Queue · Queues and schedules GPU work
src/gpu_queue.rs - Shaders · Converts guest shaders to host form
src/shader_translation.rs - AMPR · Low-level packet or GPU format support
src/ampr.rs - Video Out · Presents frames to host display path
src/video_out.rs
I/O Services
Audio, input, and console services
- Audio · Host audio integration
src/audio.rs - Input · Host input integration
src/input.rs - User · User identity and session state
src/user_service.rs - Dialog · Console dialog and prompt handling
src/common_dialog.rs - Save Data · Save-state and storage behavior
src/save_data.rs - Network · Network service shims
src/network.rs - Profile · Network profile metadata
src/network_profile.rs
Connections 24
- 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