Skip to main content

Overview

Ryujinx’s graphics subsystem emulates the NVIDIA Tegra X1 GPU, translating Switch graphics commands to host APIs (Vulkan, OpenGL). The architecture is layered:
GAL (Graphics Abstraction Layer) provides a unified API for multiple rendering backends

GPU Context

The central GPU emulation context from src/Ryujinx.Graphics.Gpu/GpuContext.cs:
Key responsibilities:
  • Command buffer submission and processing
  • Memory management (texture, buffer, shader storage)
  • Synchronization with CPU
  • Multi-process GPU sharing

Command Processing

GPFifo (General Purpose FIFO)

The command submission interface:

Command Buffer Format

Switch uses pushbuffer-style command submission:
Handles 2D blits and surface operations:

Graphics Engine (3D)

The main rendering engine processes graphics state and draw commands:

Render State Management

Graphics state is cached and synchronized:
State groups:
  • Rasterizer: Primitive topology, polygon mode, cull mode, front face
  • Depth/Stencil: Depth test, stencil test, depth bounds
  • Blend: Blend equations, blend factors, color mask
  • Viewport: Viewport transforms, depth range
  • Scissor: Scissor rectangles

Shader Translation

Shaders are translated from Switch binary format to host GLSL/SPIR-V:

Shader Cache

From src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs:

Translation Pipeline

1

Binary Decode

Decode Maxwell/Pascal GPU binary instructions:
2

Control Flow Analysis

Build control flow graph:
3

Translation to IR

Convert to intermediate representation:
4

Optimization

Optimize shader IR:
5

Code Generation

Generate target shader language:

Guest-to-Host Feature Mapping

Shader Specialization

Shaders are specialized based on render state:
Specialization allows aggressive optimization by baking constants into shader code

Texture Management

Texture Pool

Textures are managed in pools:

Texture Descriptor

Switch uses descriptors to define texture properties:

Texture Formats

Ryujinx supports extensive format conversions:

Block Linear Swizzling

Switch uses block-linear texture layout for cache efficiency:
Block-linear benefits:
  • Improved texture cache hit rate
  • Better memory access patterns
  • Efficient mipmap storage

Buffer Management

Buffer Cache

Buffer Types

Vertex Buffers

Index Buffers

Uniform Buffers

Storage Buffers

Synchronization

GPU-CPU Sync

Handling synchronization between CPU and GPU:

Sync Actions

Actions triggered at synchronization points:

Graphics Abstraction Layer (GAL)

Unified interface for rendering backends:

Backend Implementations

Advantages:
  • Lower CPU overhead
  • Better multi-threading
  • Advanced features (descriptor indexing, dynamic rendering)
  • Preferred on Windows/Linux
Key features:

Presentation & Display

Window management and frame presentation:

Performance Optimizations

  • Disk cache for compiled shaders
  • Reduces stuttering on repeated execution
  • Per-game cache with version tracking
  • Merge small buffers into larger allocations
  • Reduces bind overhead
  • Improves memory locality
  • Only update changed state
  • Batch state changes
  • Shadow state comparison
  • Compile shaders on background threads
  • Display loading indicator
  • Minimal impact on frame time

Debugging Tools

Shader Dumps

Export guest and translated shaders:

Frame Capture

RenderDoc integration:
  • Capture frame commands
  • Inspect state
  • Debug shaders

Command Logging

Log GPU commands:
Outputs method calls and arguments

Resource Tracking

Monitor GPU memory:
  • Texture usage
  • Buffer allocations
  • Cache statistics

HLE Services

NVDRV service and ioctl interface

Memory Management

GPU memory mapping and MMU

Performance Tuning

Graphics optimization settings

Troubleshooting

Resolving graphics issues

Source Code Reference

  • src/Ryujinx.Graphics.Gpu/GpuContext.cs:19 - GPU context
  • src/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs - Command processor
  • src/Ryujinx.Graphics.Gpu/Engine/Threed/ - 3D engine
  • src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs:22 - Shader cache
  • src/Ryujinx.Graphics.GAL/ - Graphics abstraction layer
  • src/Ryujinx.Graphics.Vulkan/ - Vulkan backend
  • src/Ryujinx.Graphics.OpenGL/ - OpenGL backend