Overview
Ryujinx emulates the NVIDIA Tegra X1’s Maxwell GPU architecture, providing a complete software implementation of the graphics processing unit used in the Nintendo Switch. The GPU emulation layer sits between the guest application and the host graphics API (OpenGL or Vulkan).GpuContext
Central GPU emulation context managing all GPU resources and state
GpuChannel
Individual GPU command submission channels with isolated state
GPFifo
General Purpose FIFO for command buffer submission and processing
Engine Classes
Specialized engines for 3D, 2D, compute, and DMA operations
GpuContext
TheGpuContext class is the central hub of GPU emulation, coordinating all GPU operations and managing shared resources.
Architecture
The GPU context uses a Maxwell timer frequency of 614.4 MHz (384/625 of nanoseconds) to accurately emulate GPU timing behavior.
Key Responsibilities
Memory Management
Memory Management
- Manages physical memory registries per process (keyed by process ID)
- Supports multiple
PhysicalMemoryinstances for multi-process emulation - Handles CPU virtual memory tracking and GPU memory mapping
- Provides
MemoryManagercreation for GPU virtual address spaces
Channel Management
Channel Management
- Creates and manages
GpuChannelinstances - Each channel represents an independent command submission context
- Channels can be bound to different memory managers
Synchronization
Synchronization
- Tracks sequence numbers for resource modification ordering
- Manages sync actions triggered by CPU-GPU synchronization points
- Handles buffer migrations between memory regions
- Creates host sync objects for GPU-CPU coordination
Shader Cache
Shader Cache
- Coordinates shader cache initialization across all processes
- Propagates shader cache state changes to the host application
- Manages disk cache for persistent shader storage
GPU Timer
The emulated GPU provides accurate timing using Maxwell’s timer frequency:The
FastGpuTime configuration option can divide the reported time by 256 to prevent games from reducing resolution due to perceived slow performance.GpuChannel
EachGpuChannel represents an independent command submission context with its own state and resource bindings.
Channel Architecture
Components
GPFifo Command Processing
The General Purpose FIFO (GPFifo) is the primary mechanism for submitting commands to the GPU. It processes command buffers containing method calls to various engine classes.Command Buffer Format
Commands use a compressed format with multiple encoding schemes:Processing Pipeline
Command Decode
Commands are decoded from the GPFIFO stream, extracting method address, subchannel, and arguments.
Fast Path Optimization
Common operations are optimized with fast paths:
- Inline-to-Memory uploads: Batch copy data directly to GPU memory
- Uniform buffer updates: Bulk constant buffer data transfers
Engine Dispatch
Methods are routed to the appropriate engine class based on subchannel:
- Subchannel 0: 3D Engine (ThreedClass)
- Subchannel 1: Compute Engine (ComputeClass)
- Subchannel 2: Inline-to-Memory (I2M)
- Subchannel 3: 2D Engine (TwodClass)
- Subchannel 4: DMA Engine (DmaClass)
Engine Classes
Ryujinx implements multiple GPU engine classes that handle different types of operations.ThreedClass (3D Engine)
The primary graphics engine handling 3D rendering operations.- Overview
- State Management
- Draw Operations
Located in
src/Ryujinx.Graphics.Gpu/Engine/Threed/, the 3D engine manages:- Vertex and index buffer bindings
- Render target configuration
- Pipeline state (blend, depth, stencil, rasterizer)
- Shader program binding
- Draw calls (arrays, indexed, instanced, indirect)
- Transform feedback
- Conditional rendering
ComputeClass
Handles compute shader dispatch operations:DmaClass
Performs memory-to-memory copy operations:- Linear-to-linear copies
- Tiled-to-linear and linear-to-tiled conversions
- Pitch linear memory layout handling
TwodClass
2D blit and fill operations for surfaces:- Surface copies with format conversion
- Texture blitting
- Solid color fills
Memory Management
The GPU memory subsystem provides virtual addressing and resource tracking.MemoryManager
Buffer Cache
TheBufferCache (in PhysicalMemory) tracks all buffer objects:
- Handles overlapping buffer ranges
- Manages CPU modification tracking
- Performs buffer migrations when needed
- Implements copy-on-write semantics
Command Buffer Flow
Performance Optimizations
State Redundancy Check
Only propagate state changes to host API using shadow RAM comparison
Fast Path Uploads
Batch inline-to-memory and uniform buffer updates
Deferred Actions
Queue resource operations to run on the render thread
Sequence Numbers
Track resource modifications efficiently for cache coherency
References
Source Files
src/Ryujinx.Graphics.Gpu/GpuContext.cssrc/Ryujinx.Graphics.Gpu/GpuChannel.cssrc/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoProcessor.cssrc/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClass.cs