$ show shadps4-emu/shadPS4
shadPS4 is a PlayStation 4 emulator for Windows, Linux, and macOS, written in C++20. It emulates the PS4's AMD GCN GPU via a custom shader recompiler that translates GCN instructions to SPIR-V, and implements high-level emulation (HLE) of PS4 system libraries (kernel, libc, networking, audio, video, input, etc.). The architecture is monolithic with modular subsystems: a Vulkan renderer with texture/buffer caches, a shader recompiler with IR optimization passes, a file system abstraction supporting host files and ZArchive, and an ImGui-based debug UI. While many library functions are stubbed or partially implemented, the core GPU and CPU emulation is functional enough to run several commercial games. The codebase demonstrates strong engineering practices with reusable common utilities (bitfields, slot containers, thread-safe queues) and a well-structured shader compilation pipeline. It is a hybrid project, combining software application development with significant reverse-engineering and data analysis of PS4 firmware and GPU architecture.
The LLM identified 5 files worth highlighting for reuse:
A template-based bitfield abstraction that allows type-safe, endianness-independent access to hardware register fields. It supports arbitrary bit positions and widths, and can be used to model GPU or CPU register layouts. The implementation is self-contained, header-only, and can be extracted for any project that needs to manipulate bit-packed hardware registers.
A slot-based container that provides O(1) insertion, removal, and lookup with stable indices (handles). It uses a free list to recycle slots and supports iteration. This is a common pattern for resource handles in emulators and game engines, and the implementation is clean, generic, and reusable.
An IR optimization pass that performs constant propagation and folding on the shader intermediate representation. It demonstrates non-obvious compiler techniques such as tracking constant values through phi nodes and simplifying arithmetic operations. The pass is self-contained and follows a visitor pattern that could be adapted for other IR-based compilers.
Uses Boost ICL interval containers to manage GPU buffer regions for efficient tracking of dirty ranges and invalidation. The implementation handles overlapping intervals, coalescing, and range queries with logarithmic complexity. This pattern is reusable for any system that needs to manage sparse, overlapping address ranges (e.g., memory caches, page tables).
A portable file I/O wrapper that supports both standard read/write and memory-mapped file access. It abstracts platform-specific APIs (Windows CreateFileMapping2, POSIX mmap) behind a clean C++ interface. The implementation is self-contained and can be reused in any project requiring efficient file I/O with optional memory mapping.