gspgpu.h
Go to the documentation of this file.
/**
* @file gspgpu.h
* @brief GSPGPU service.
*/
#pragma once
#define GSP_SCREEN_TOP 0 ///< ID of the top screen.
#define GSP_SCREEN_BOTTOM 1 ///< ID of the bottom screen.
#define GSP_SCREEN_WIDTH 240 ///< Width of the top/bottom screens.
#define GSP_SCREEN_HEIGHT_TOP 400 ///< Height of the top screen.
#define GSP_SCREEN_HEIGHT_TOP_2X 800 ///< Height of the top screen (2x).
#define GSP_SCREEN_HEIGHT_BOTTOM 320 ///< Height of the bottom screen.
/// Framebuffer information.
typedef struct
{
u32 active_framebuf; ///< Active framebuffer. (0 = first, 1 = second)
u32 *framebuf0_vaddr; ///< Framebuffer virtual address, for the main screen this is the 3D left framebuffer.
u32 *framebuf1_vaddr; ///< For the main screen: 3D right framebuffer address.
u32 framebuf_widthbytesize; ///< Value for 0x1EF00X90, controls framebuffer width.
u32 format; ///< Framebuffer format, this u16 is written to the low u16 for LCD register 0x1EF00X70.
u32 framebuf_dispselect; ///< Value for 0x1EF00X78, controls which framebuffer is displayed.
u32 unk; ///< Unknown.
} GSPGPU_FramebufferInfo;
/// Framebuffer format.
typedef enum
{
GSP_RGBA8_OES=0, ///< RGBA8. (4 bytes)
GSP_BGR8_OES=1, ///< BGR8. (3 bytes)
GSP_RGB565_OES=2, ///< RGB565. (2 bytes)
GSP_RGB5_A1_OES=3, ///< RGB5A1. (2 bytes)
GSP_RGBA4_OES=4 ///< RGBA4. (2 bytes)
} GSPGPU_FramebufferFormat;
/// Capture info entry.
typedef struct
{
u32 *framebuf0_vaddr; ///< Left framebuffer.
u32 *framebuf1_vaddr; ///< Right framebuffer.
u32 format; ///< Framebuffer format.
u32 framebuf_widthbytesize; ///< Framebuffer pitch.
} GSPGPU_CaptureInfoEntry;
/// Capture info.
typedef struct
{
GSPGPU_CaptureInfoEntry screencapture[2]; ///< Capture info entries, one for each screen.
} GSPGPU_CaptureInfo;
/// GSPGPU events.
typedef enum
{
GSPGPU_EVENT_PSC0 = 0, ///< Memory fill completed.
GSPGPU_EVENT_PSC1, ///< TODO
GSPGPU_EVENT_VBlank0, ///< TODO
GSPGPU_EVENT_VBlank1, ///< TODO
GSPGPU_EVENT_PPF, ///< Display transfer finished.
GSPGPU_EVENT_P3D, ///< Command list processing finished.
GSPGPU_EVENT_DMA, ///< TODO
GSPGPU_EVENT_MAX, ///< Used to know how many events there are.
} GSPGPU_Event;
/**
* @brief Gets the number of bytes per pixel for the specified format.
* @param format See \ref GSPGPU_FramebufferFormat.
* @return Bytes per pixel.
*/
static inline unsigned gspGetBytesPerPixel(GSPGPU_FramebufferFormat format)
{
switch (format)
{
case GSP_RGBA8_OES:
return 4;
default:
case GSP_BGR8_OES:
return 3;
case GSP_RGB565_OES:
case GSP_RGB5_A1_OES:
case GSP_RGBA4_OES:
return 2;
}
}
/// Initializes GSPGPU.
Result gspInit(void);
/// Exits GSPGPU.
void gspExit(void);
/**
* @brief Gets a pointer to the current gsp::Gpu session handle.
* @return A pointer to the current gsp::Gpu session handle.
*/
Handle *gspGetSessionHandle(void);
/// Returns true if the application currently has GPU rights.
bool gspHasGpuRight(void);
/**
* @brief Presents a buffer to the specified screen.
* @param screen Screen ID (see \ref GSP_SCREEN_TOP and \ref GSP_SCREEN_BOTTOM)
* @param swap Specifies which set of framebuffer registers to configure and activate (0 or 1)
* @param fb_a Pointer to the framebuffer (in stereo mode: left eye)
* @param fb_b Pointer to the secondary framebuffer (only used in stereo mode for the right eye, otherwise pass the same as fb_a)
* @param stride Stride in bytes between scanlines
* @param mode Mode configuration to be written to LCD register
* @return true if a buffer had already been presented to the screen but not processed yet by GSP, false otherwise.
* @note The most recently presented buffer is processed and configured during the specified screen's next VBlank event.
*/
bool gspPresentBuffer(unsigned screen, unsigned swap, const void* fb_a, const void* fb_b, u32 stride, u32 mode);
/**
* @brief Returns true if a prior \ref gspPresentBuffer command is still pending to be processed by GSP.
* @param screen Screen ID (see \ref GSP_SCREEN_TOP and \ref GSP_SCREEN_BOTTOM)
*/
bool gspIsPresentPending(unsigned screen);
/**
* @brief Configures a callback to run when a GSPGPU event occurs.
* @param id ID of the event.
* @param cb Callback to run.
* @param data Data to be passed to the callback.
* @param oneShot When true, the callback is only executed once. When false, the callback is executed every time the event occurs.
*/
void gspSetEventCallback(GSPGPU_Event id, ThreadFunc cb, void* data, bool oneShot);
/**
* @brief Waits for a GSPGPU event to occur.
* @param id ID of the event.
* @param nextEvent Whether to discard the current event and wait for the next event.
*/
void gspWaitForEvent(GSPGPU_Event id, bool nextEvent);
/**
* @brief Waits for any GSPGPU event to occur.
* @return The ID of the event that occurred.
*
* The function returns immediately if there are unprocessed events at the time of call.
*/
GSPGPU_Event gspWaitForAnyEvent(void);
/// Waits for PSC0
#define gspWaitForPSC0() gspWaitForEvent(GSPGPU_EVENT_PSC0, false)
/// Waits for PSC1
#define gspWaitForPSC1() gspWaitForEvent(GSPGPU_EVENT_PSC1, false)
/// Waits for VBlank.
#define gspWaitForVBlank() gspWaitForVBlank0()
/// Waits for VBlank0.
#define gspWaitForVBlank0() gspWaitForEvent(GSPGPU_EVENT_VBlank0, true)
/// Waits for VBlank1.
#define gspWaitForVBlank1() gspWaitForEvent(GSPGPU_EVENT_VBlank1, true)
/// Waits for PPF.
#define gspWaitForPPF() gspWaitForEvent(GSPGPU_EVENT_PPF, false)
/// Waits for P3D.
#define gspWaitForP3D() gspWaitForEvent(GSPGPU_EVENT_P3D, false)
/// Waits for DMA.
#define gspWaitForDMA() gspWaitForEvent(GSPGPU_EVENT_DMA, false)
/**
* @brief Submits a GX command.
* @param gxCommand GX command to execute.
*/
Result gspSubmitGxCommand(const u32 gxCommand[0x8]);
/**
* @brief Acquires GPU rights.
* @param flags Flags to acquire with.
*/
Result GSPGPU_AcquireRight(u8 flags);
/// Releases GPU rights.
Result GSPGPU_ReleaseRight(void);
/**
* @brief Retrieves display capture info.
* @param captureinfo Pointer to output capture info to.
*/
Result GSPGPU_ImportDisplayCaptureInfo(GSPGPU_CaptureInfo* captureinfo);
/// Saves the VRAM sys area.
Result GSPGPU_SaveVramSysArea(void);
/// Resets the GPU
Result GSPGPU_ResetGpuCore(void);
/// Restores the VRAM sys area.
Result GSPGPU_RestoreVramSysArea(void);
/**
* @brief Sets whether to force the LCD to black.
* @param flags Whether to force the LCD to black. (0 = no, non-zero = yes)
*/
Result GSPGPU_SetLcdForceBlack(u8 flags);
/**
* @brief Updates a screen's framebuffer state.
* @param screenid ID of the screen to update.
* @param framebufinfo Framebuffer information to update with.
*/
Result GSPGPU_SetBufferSwap(u32 screenid, const GSPGPU_FramebufferInfo* framebufinfo);
/**
* @brief Flushes memory from the data cache.
* @param adr Address to flush.
* @param size Size of the memory to flush.
*/
Result GSPGPU_FlushDataCache(const void* adr, u32 size);
/**
* @brief Invalidates memory in the data cache.
* @param adr Address to invalidate.
* @param size Size of the memory to invalidate.
*/
Result GSPGPU_InvalidateDataCache(const void* adr, u32 size);
/**
* @brief Writes to GPU hardware registers.
* @param regAddr Register address to write to.
* @param data Data to write.
* @param size Size of the data to write.
*/
Result GSPGPU_WriteHWRegs(u32 regAddr, const u32* data, u8 size);
/**
* @brief Writes to GPU hardware registers with a mask.
* @param regAddr Register address to write to.
* @param data Data to write.
* @param datasize Size of the data to write.
* @param maskdata Data of the mask.
* @param masksize Size of the mask.
*/
Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, const u32* data, u8 datasize, const u32* maskdata, u8 masksize);
/**
* @brief Reads from GPU hardware registers.
* @param regAddr Register address to read from.
* @param data Buffer to read data to.
* @param size Size of the buffer.
*/
Result GSPGPU_ReadHWRegs(u32 regAddr, u32* data, u8 size);
/**
* @brief Registers the interrupt relay queue.
* @param eventHandle Handle of the GX command event.
* @param flags Flags to register with.
* @param outMemHandle Pointer to output the shared memory handle to.
* @param threadID Pointer to output the GSP thread ID to.
*/
Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID);
/// Unregisters the interrupt relay queue.
Result GSPGPU_UnregisterInterruptRelayQueue(void);
/// Triggers a handling of commands written to shared memory.
Result GSPGPU_TriggerCmdReqQueue(void);
/**
* @brief Sets 3D_LEDSTATE to the input state value.
* @param disable False = 3D LED enable, true = 3D LED disable.
*/
Result GSPGPU_SetLedForceOff(bool disable);
gspIsPresentPending
bool gspIsPresentPending(unsigned screen)
Returns true if a prior gspPresentBuffer command is still pending to be processed by GSP.
gspInit
Result gspInit(void)
Initializes GSPGPU.
GSPGPU_Event
GSPGPU_Event
GSPGPU events.
Definition: gspgpu.h:53
GSPGPU_EVENT_MAX
@ GSPGPU_EVENT_MAX
Used to know how many events there are.
Definition: gspgpu.h:62
GSPGPU_EVENT_PPF
@ GSPGPU_EVENT_PPF
Display transfer finished.
Definition: gspgpu.h:58
GSPGPU_EVENT_VBlank0
@ GSPGPU_EVENT_VBlank0
TODO.
Definition: gspgpu.h:56
GSPGPU_EVENT_DMA
@ GSPGPU_EVENT_DMA
TODO.
Definition: gspgpu.h:60
GSPGPU_EVENT_PSC0
@ GSPGPU_EVENT_PSC0
Memory fill completed.
Definition: gspgpu.h:54
GSPGPU_EVENT_PSC1
@ GSPGPU_EVENT_PSC1
TODO.
Definition: gspgpu.h:55
GSPGPU_EVENT_VBlank1
@ GSPGPU_EVENT_VBlank1
TODO.
Definition: gspgpu.h:57
GSPGPU_EVENT_P3D
@ GSPGPU_EVENT_P3D
Command list processing finished.
Definition: gspgpu.h:59
GSPGPU_SetLcdForceBlack
Result GSPGPU_SetLcdForceBlack(u8 flags)
Sets whether to force the LCD to black.
gspExit
void gspExit(void)
Exits GSPGPU.
GSPGPU_FlushDataCache
Result GSPGPU_FlushDataCache(const void *adr, u32 size)
Flushes memory from the data cache.
GSPGPU_AcquireRight
Result GSPGPU_AcquireRight(u8 flags)
Acquires GPU rights.
gspSetEventCallback
void gspSetEventCallback(GSPGPU_Event id, ThreadFunc cb, void *data, bool oneShot)
Configures a callback to run when a GSPGPU event occurs.
gspSubmitGxCommand
Result gspSubmitGxCommand(const u32 gxCommand[0x8])
Submits a GX command.
gspGetSessionHandle
Handle * gspGetSessionHandle(void)
Gets a pointer to the current gsp::Gpu session handle.
GSPGPU_SetLedForceOff
Result GSPGPU_SetLedForceOff(bool disable)
Sets 3D_LEDSTATE to the input state value.
GSPGPU_RegisterInterruptRelayQueue
Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle *outMemHandle, u8 *threadID)
Registers the interrupt relay queue.
GSPGPU_SaveVramSysArea
Result GSPGPU_SaveVramSysArea(void)
Saves the VRAM sys area.
GSPGPU_RestoreVramSysArea
Result GSPGPU_RestoreVramSysArea(void)
Restores the VRAM sys area.
GSPGPU_ImportDisplayCaptureInfo
Result GSPGPU_ImportDisplayCaptureInfo(GSPGPU_CaptureInfo *captureinfo)
Retrieves display capture info.
GSPGPU_WriteHWRegs
Result GSPGPU_WriteHWRegs(u32 regAddr, const u32 *data, u8 size)
Writes to GPU hardware registers.
GSPGPU_UnregisterInterruptRelayQueue
Result GSPGPU_UnregisterInterruptRelayQueue(void)
Unregisters the interrupt relay queue.
gspWaitForAnyEvent
GSPGPU_Event gspWaitForAnyEvent(void)
Waits for any GSPGPU event to occur.
gspGetBytesPerPixel
static unsigned gspGetBytesPerPixel(GSPGPU_FramebufferFormat format)
Gets the number of bytes per pixel for the specified format.
Definition: gspgpu.h:70
gspWaitForEvent
void gspWaitForEvent(GSPGPU_Event id, bool nextEvent)
Waits for a GSPGPU event to occur.
GSPGPU_ReleaseRight
Result GSPGPU_ReleaseRight(void)
Releases GPU rights.
GSPGPU_TriggerCmdReqQueue
Result GSPGPU_TriggerCmdReqQueue(void)
Triggers a handling of commands written to shared memory.
gspHasGpuRight
bool gspHasGpuRight(void)
Returns true if the application currently has GPU rights.
GSPGPU_InvalidateDataCache
Result GSPGPU_InvalidateDataCache(const void *adr, u32 size)
Invalidates memory in the data cache.
gspPresentBuffer
bool gspPresentBuffer(unsigned screen, unsigned swap, const void *fb_a, const void *fb_b, u32 stride, u32 mode)
Presents a buffer to the specified screen.
GSPGPU_WriteHWRegsWithMask
Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, const u32 *data, u8 datasize, const u32 *maskdata, u8 masksize)
Writes to GPU hardware registers with a mask.
GSPGPU_FramebufferFormat
GSPGPU_FramebufferFormat
Framebuffer format.
Definition: gspgpu.h:28
GSP_RGB5_A1_OES
@ GSP_RGB5_A1_OES
RGB5A1. (2 bytes)
Definition: gspgpu.h:32
GSP_RGBA4_OES
@ GSP_RGBA4_OES
RGBA4. (2 bytes)
Definition: gspgpu.h:33
GSP_BGR8_OES
@ GSP_BGR8_OES
BGR8. (3 bytes)
Definition: gspgpu.h:30
GSP_RGBA8_OES
@ GSP_RGBA8_OES
RGBA8. (4 bytes)
Definition: gspgpu.h:29
GSP_RGB565_OES
@ GSP_RGB565_OES
RGB565. (2 bytes)
Definition: gspgpu.h:31
GSPGPU_ResetGpuCore
Result GSPGPU_ResetGpuCore(void)
Resets the GPU.
GSPGPU_ReadHWRegs
Result GSPGPU_ReadHWRegs(u32 regAddr, u32 *data, u8 size)
Reads from GPU hardware registers.
GSPGPU_SetBufferSwap
Result GSPGPU_SetBufferSwap(u32 screenid, const GSPGPU_FramebufferInfo *framebufinfo)
Updates a screen's framebuffer state.
GSPGPU_CaptureInfoEntry
Capture info entry.
Definition: gspgpu.h:38
GSPGPU_CaptureInfoEntry::format
u32 format
Framebuffer format.
Definition: gspgpu.h:41
GSPGPU_CaptureInfoEntry::framebuf1_vaddr
u32 * framebuf1_vaddr
Right framebuffer.
Definition: gspgpu.h:40
GSPGPU_CaptureInfoEntry::framebuf0_vaddr
u32 * framebuf0_vaddr
Left framebuffer.
Definition: gspgpu.h:39
GSPGPU_CaptureInfoEntry::framebuf_widthbytesize
u32 framebuf_widthbytesize
Framebuffer pitch.
Definition: gspgpu.h:42
GSPGPU_CaptureInfo
Capture info.
Definition: gspgpu.h:47
GSPGPU_FramebufferInfo
Framebuffer information.
Definition: gspgpu.h:16
GSPGPU_FramebufferInfo::unk
u32 unk
Unknown.
Definition: gspgpu.h:23
GSPGPU_FramebufferInfo::framebuf_widthbytesize
u32 framebuf_widthbytesize
Value for 0x1EF00X90, controls framebuffer width.
Definition: gspgpu.h:20
GSPGPU_FramebufferInfo::format
u32 format
Framebuffer format, this u16 is written to the low u16 for LCD register 0x1EF00X70.
Definition: gspgpu.h:21
GSPGPU_FramebufferInfo::framebuf0_vaddr
u32 * framebuf0_vaddr
Framebuffer virtual address, for the main screen this is the 3D left framebuffer.
Definition: gspgpu.h:18
GSPGPU_FramebufferInfo::active_framebuf
u32 active_framebuf
Active framebuffer. (0 = first, 1 = second)
Definition: gspgpu.h:17
GSPGPU_FramebufferInfo::framebuf1_vaddr
u32 * framebuf1_vaddr
For the main screen: 3D right framebuffer address.
Definition: gspgpu.h:19
GSPGPU_FramebufferInfo::framebuf_dispselect
u32 framebuf_dispselect
Value for 0x1EF00X78, controls which framebuffer is displayed.
Definition: gspgpu.h:22
ThreadFunc
void(* ThreadFunc)(void *)
Thread entrypoint function.
Definition: types.h:43
u8
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
Handle
u32 Handle
Resource handle.
Definition: types.h:41
Result
s32 Result
Function result.
Definition: types.h:42
u32
uint32_t u32
32-bit unsigned integer
Definition: types.h:23