Skip to main content
The RSX library provides the core interface to the PlayStation 3’s graphics accelerator. This library handles initialization, context management, command buffers, and memory management for hardware-accelerated rendering.

Initialization

rsxInit

Initialize the RSX context and memory manager.
s32 rsxInit(gcmContextData **context, u32 cmdSize, u32 ioSize, const void *ioAddress);
context
gcmContextData**
required
Pointer to receive the address of the default command buffer context
cmdSize
u32
required
Command buffer size in bytes
ioSize
u32
required
Size of the IO buffer allocated in main memory (must be multiple of 1 MB)
ioAddress
const void*
required
Pointer to a 1 MB-aligned buffer in main memory of ioSize bytes
return
s32
Returns 0 on success, nonzero on error
This function initializes a heap structure in RSX memory space, allowing dynamic memory allocation using rsxMalloc(), rsxMemalign(), and rsxFree().
Example
// Allocate 1MB IO buffer
void *host_addr = memalign(1024*1024, 1024*1024);
gcmContextData *context;

// Initialize RSX with 256KB command buffer
rsxInit(&context, 256*1024, 1024*1024, host_addr);

Context Management

rsxSetupContextData

Manually setup a command buffer context.
void rsxSetupContextData(gcmContextData *context, const u32 *addr, u32 size, gcmContextCallback cb);
context
gcmContextData*
required
Pointer to the context structure to initialize
addr
const u32*
required
Start address of the command buffer
size
u32
required
Size of the command buffer in bytes
cb
gcmContextCallback
required
Callback function to be called when buffer is full

rsxSetCurrentBuffer

Set the current command buffer.
void rsxSetCurrentBuffer(gcmContextData **context, const u32 *addr, u32 size);
context
gcmContextData**
required
Pointer to pointer of context structure
addr
const u32*
required
Start address of the command buffer
size
u32
required
Size of the command buffer in bytes

rsxSetDefaultCommandBuffer

Restore the default command buffer context.
void rsxSetDefaultCommandBuffer(gcmContextData **context);
context
gcmContextData**
required
Pointer to pointer to receive the default context

rsxGetCurrentBuffer

Get the current position in the command buffer.
u32* rsxGetCurrentBuffer();
return
u32*
Pointer to the current position in the command buffer

rsxSetUserCallback

Set a user-defined callback for the command buffer.
void rsxSetUserCallback(gcmContextCallback cb);
cb
gcmContextCallback
required
Callback function to be invoked when buffer is full

Memory Management

rsxAddressToOffset

Convert a pointer in RSX memory to an offset value.
static inline s32 rsxAddressToOffset(const void *ptr, u32 *offset);
ptr
const void*
required
Pointer to convert
offset
u32*
required
Pointer to receive the offset value
return
s32
Returns 0 on success, nonzero on error
Example
void *buffer = rsxMemalign(64, 1920*1080*4);
u32 offset;
rsxAddressToOffset(buffer, &offset);

rsxHeapInit

Initialize the RSX memory heap.
s32 rsxHeapInit();
return
s32
Returns 0 on success, nonzero on error

rsxMalloc

Dynamically allocate RSX video memory.
void* rsxMalloc(u32 size);
size
u32
required
Size in bytes to allocate
return
void*
Pointer to allocated buffer, or NULL on error
Example
// Allocate a color buffer
void *color_buffer = rsxMalloc(1920 * 1080 * 4);
if (!color_buffer) {
    // Handle allocation error
}

rsxMemalign

Dynamically allocate aligned RSX video memory.
void* rsxMemalign(u32 alignment, u32 size);
alignment
u32
required
Required alignment in bytes (typically 64 or higher)
size
u32
required
Size in bytes to allocate
return
void*
Pointer to allocated aligned buffer, or NULL on error
Most RSX operations require 64-byte alignment. Use this function instead of rsxMalloc() when alignment is critical.
Example
// Allocate 64-byte aligned display buffer
void *display_buffer = rsxMemalign(64, 1920 * 1080 * 4);

rsxFree

Free previously allocated RSX memory.
void rsxFree(void *ptr);
ptr
void*
required
Pointer to buffer allocated with rsxMalloc() or rsxMemalign()

Utility Functions

rsxGetFixedSint32

Convert floating point coordinate to 32-bit signed fixed point.
static inline s32 rsxGetFixedSint32(f32 f);
f
f32
required
Floating point value to convert
return
s32
32-bit signed fixed point representation (multiplied by 1048576.0)
Example
f32 scale_x = 1.5f;
s32 fixed_scale = rsxGetFixedSint32(scale_x);

rsxGetFixedUint16

Convert floating point coordinate to 16-bit unsigned fixed point.
static inline u16 rsxGetFixedUint16(f32 f);
f
f32
required
Floating point value to convert
return
u16
16-bit unsigned fixed point representation (multiplied by 16.0)

rsxAlign

Align a value to the specified alignment.
static inline u32 rsxAlign(u32 alignment, u32 value);
alignment
u32
required
Alignment value (power of 2)
value
u32
required
Value to align
return
u32
Aligned value
Example
// Align pitch to 64 bytes
u32 pitch = rsxAlign(64, width * 4);

Global Context

gGcmContext

Pointer to the default command buffer context.
extern gcmContextData *gGcmContext;
This global variable provides access to the default RSX context initialized by rsxInit(). Most RSX command functions use this context automatically.

Typical Usage Pattern

Complete Example
#include <rsx/rsx.h>

// 1. Allocate IO buffer
void *host_addr = memalign(1024*1024, 1024*1024);
gcmContextData *context;

// 2. Initialize RSX
if (rsxInit(&context, 256*1024, 1024*1024, host_addr) != 0) {
    // Handle error
}

// 3. Configure video mode
videoConfiguration vconfig;
videGetState(0, 0, &vconfig);
videoConfigure(0, &vconfig, NULL, 0);

// 4. Set flip mode
gcmSetFlipMode(GCM_FLIP_VSYNC);

// 5. Allocate display buffers
for (int i = 0; i < 2; i++) {
    void *buffer = rsxMemalign(64, 1920 * 1080 * 4);
    u32 offset;
    rsxAddressToOffset(buffer, &offset);
    gcmSetDisplayBuffer(i, offset, 1920 * 4, 1920, 1080);
}

// 6. Allocate depth buffer
void *depth_buffer = rsxMemalign(64, 1920 * 1080 * 4);
u32 depth_offset;
rsxAddressToOffset(depth_buffer, &depth_offset);

// 7. Reset flip status
gcmResetFlipStatus();

// Now ready for rendering

See Also

  • GCM System - Low-level command buffer and display management
  • RESC - Resolution scaling and conversion
  • Video Configuration - Display output configuration

Build docs developers (and LLMs) love