libctru  v1.6.0
gspgpu.h
Go to the documentation of this file.
1 /**
2  * @file gspgpu.h
3  * @brief GSPGPU service.
4  */
5 #pragma once
6 
7 #define GSPGPU_REBASE_REG(r) ((r)-0x1EB00000)
8 
9 /// Framebuffer information.
10 typedef struct
11 {
12  u32 active_framebuf; ///< Active framebuffer. (0 = first, 1 = second)
13  u32 *framebuf0_vaddr; ///< Framebuffer virtual address, for the main screen this is the 3D left framebuffer.
14  u32 *framebuf1_vaddr; ///< For the main screen: 3D right framebuffer address.
15  u32 framebuf_widthbytesize; ///< Value for 0x1EF00X90, controls framebuffer width.
16  u32 format; ///< Framebuffer format, this u16 is written to the low u16 for LCD register 0x1EF00X70.
17  u32 framebuf_dispselect; ///< Value for 0x1EF00X78, controls which framebuffer is displayed.
18  u32 unk; ///< Unknown.
20 
21 /// Framebuffer format.
22 typedef enum
23 {
24  GSP_RGBA8_OES=0, ///< RGBA8. (4 bytes)
25  GSP_BGR8_OES=1, ///< BGR8. (3 bytes)
26  GSP_RGB565_OES=2, ///< RGB565. (2 bytes)
27  GSP_RGB5_A1_OES=3, ///< RGB5A1. (2 bytes)
28  GSP_RGBA4_OES=4 ///< RGBA4. (2 bytes)
30 
31 /// Capture info entry.
32 typedef struct
33 {
34  u32 *framebuf0_vaddr; ///< Left framebuffer.
35  u32 *framebuf1_vaddr; ///< Right framebuffer.
36  u32 format; ///< Framebuffer format.
37  u32 framebuf_widthbytesize; ///< Framebuffer pitch.
39 
40 /// Capture info.
41 typedef struct
42 {
43  GSPGPU_CaptureInfoEntry screencapture[2]; ///< Capture info entries, one for each screen.
45 
46 /// GSPGPU events.
47 typedef enum
48 {
49  GSPGPU_EVENT_PSC0 = 0, ///< Memory fill completed.
50  GSPGPU_EVENT_PSC1, ///< TODO
53  GSPGPU_EVENT_PPF, ///< Display transfer finished.
54  GSPGPU_EVENT_P3D, ///< Command list processing finished.
55  GSPGPU_EVENT_DMA, ///< TODO
56 
57  GSPGPU_EVENT_MAX, ///< Used to know how many events there are.
58 } GSPGPU_Event;
59 
60 /// Initializes GSPGPU.
61 Result gspInit(void);
62 
63 /// Exits GSPGPU.
64 void gspExit(void);
65 
66 /**
67  * @brief Configures a callback to run when a GSPGPU event occurs.
68  * @param id ID of the event.
69  * @param cb Callback to run.
70  * @param data Data to be passed to the callback.
71  * @param oneShot When true, the callback is only executed once. When false, the callback is executed every time the event occurs.
72  */
73 void gspSetEventCallback(GSPGPU_Event id, ThreadFunc cb, void* data, bool oneShot);
74 
75 /**
76  * @brief Initializes the GSPGPU event handler.
77  * @param gspEvent Event handle to use.
78  * @param gspSharedMem GSP shared memory.
79  * @param gspThreadId ID of the GSP thread.
80  */
81 Result gspInitEventHandler(Handle gspEvent, vu8* gspSharedMem, u8 gspThreadId);
82 
83 /// Exits the GSPGPU event handler.
84 void gspExitEventHandler(void);
85 
86 /**
87  * @brief Waits for a GSPGPU event to occur.
88  * @param id ID of the event.
89  * @param nextEvent Whether to discard the current event and wait for the next event.
90  */
91 void gspWaitForEvent(GSPGPU_Event id, bool nextEvent);
92 
93 /**
94  * @brief Waits for any GSPGPU event to occur.
95  * @return The ID of the event that occurred.
96  *
97  * The function returns immediately if there are unprocessed events at the time of call.
98  */
100 
101 /// Waits for PSC0
102 #define gspWaitForPSC0() gspWaitForEvent(GSPGPU_EVENT_PSC0, false)
103 
104 /// Waits for PSC1
105 #define gspWaitForPSC1() gspWaitForEvent(GSPGPU_EVENT_PSC1, false)
106 
107 /// Waits for VBlank.
108 #define gspWaitForVBlank() gspWaitForVBlank0()
109 
110 /// Waits for VBlank0.
111 #define gspWaitForVBlank0() gspWaitForEvent(GSPGPU_EVENT_VBlank0, true)
112 
113 /// Waits for VBlank1.
114 #define gspWaitForVBlank1() gspWaitForEvent(GSPGPU_EVENT_VBlank1, true)
115 
116 /// Waits for PPF.
117 #define gspWaitForPPF() gspWaitForEvent(GSPGPU_EVENT_PPF, false)
118 
119 /// Waits for P3D.
120 #define gspWaitForP3D() gspWaitForEvent(GSPGPU_EVENT_P3D, false)
121 
122 /// Waits for DMA.
123 #define gspWaitForDMA() gspWaitForEvent(GSPGPU_EVENT_DMA, false)
124 
125 /**
126  * @brief Submits a GX command.
127  * @param sharedGspCmdBuf Command buffer to use.
128  * @param gxCommand GX command to execute.
129  */
130 Result gspSubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8]);
131 
132 /**
133  * @brief Acquires GPU rights.
134  * @param flags Flags to acquire with.
135  */
137 
138 /// Releases GPU rights.
140 
141 /**
142  * @brief Retrieves display capture info.
143  * @param captureinfo Pointer to output capture info to.
144  */
146 
147 /// Sames the VRAM sys area.
149 
150 /// Restores the VRAM sys area.
152 
153 /**
154  * @brief Sets whether to force the LCD to black.
155  * @param flags Whether to force the LCD to black. (0 = no, non-zero = yes)
156  */
158 
159 /**
160  * @brief Updates a screen's framebuffer state.
161  * @param screenid ID of the screen to update.
162  * @param framebufinfo Framebuffer information to update with.
163  */
164 Result GSPGPU_SetBufferSwap(u32 screenid, GSPGPU_FramebufferInfo*framebufinfo);
165 
166 /**
167  * @brief Flushes memory from the data cache.
168  * @param adr Address to flush.
169  * @param size Size of the memory to flush.
170  */
171 Result GSPGPU_FlushDataCache(const void* adr, u32 size);
172 
173 /**
174  * @brief Invalidates memory in the data cache.
175  * @param adr Address to invalidate.
176  * @param size Size of the memory to invalidate.
177  */
178 Result GSPGPU_InvalidateDataCache(const void* adr, u32 size);
179 
180 /**
181  * @brief Writes to GPU hardware registers.
182  * @param regAddr Register address to write to.
183  * @param data Data to write.
184  * @param size Size of the data to write.
185  */
186 Result GSPGPU_WriteHWRegs(u32 regAddr, u32* data, u8 size);
187 
188 /**
189  * @brief Writes to GPU hardware registers with a mask.
190  * @param regAddr Register address to write to.
191  * @param data Data to write.
192  * @param datasize Size of the data to write.
193  * @param maskdata Data of the mask.
194  * @param masksize Size of the mask.
195  */
196 Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize);
197 
198 /**
199  * @brief Reads from GPU hardware registers.
200  * @param regAddr Register address to read from.
201  * @param data Buffer to read data to.
202  * @param size Size of the buffer.
203  */
204 Result GSPGPU_ReadHWRegs(u32 regAddr, u32* data, u8 size);
205 
206 /**
207  * @brief Registers the interrupt relay queue.
208  * @param eventHandle Handle of the GX command event.
209  * @param flags Flags to register with.
210  * @param outMemHandle Pointer to output the shared memory handle to.
211  * @param threadID Pointer to output the GSP thread ID to.
212  */
213 Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID);
214 
215 /// Unregisters the interrupt relay queue.
217 
218 /// Triggers a handling of commands written to shared memory.
220 
221 /**
222  * @brief Sets 3D_LEDSTATE to the input state value.
223  * @param disable False = 3D LED enable, true = 3D LED disable.
224  */
225 Result GSPGPU_SetLedForceOff(bool disable);
u32 * framebuf1_vaddr
Right framebuffer.
Definition: gspgpu.h:35
GSPGPU_Event
GSPGPU events.
Definition: gspgpu.h:47
Used to know how many events there are.
Definition: gspgpu.h:57
Result GSPGPU_AcquireRight(u8 flags)
Acquires GPU rights.
void gspWaitForEvent(GSPGPU_Event id, bool nextEvent)
Waits for a GSPGPU event to occur.
s32 Result
Function result.
Definition: types.h:42
u32 format
Framebuffer format.
Definition: gspgpu.h:36
RGBA4. (2 bytes)
Definition: gspgpu.h:28
u32 format
Framebuffer format, this u16 is written to the low u16 for LCD register 0x1EF00X70.
Definition: gspgpu.h:16
void(* ThreadFunc)(void *)
Thread entrypoint function.
Definition: types.h:43
void gspSetEventCallback(GSPGPU_Event id, ThreadFunc cb, void *data, bool oneShot)
Configures a callback to run when a GSPGPU event occurs.
Display transfer finished.
Definition: gspgpu.h:53
Result GSPGPU_UnregisterInterruptRelayQueue(void)
Unregisters the interrupt relay queue.
Result GSPGPU_SetLcdForceBlack(u8 flags)
Sets whether to force the LCD to black.
u32 * framebuf0_vaddr
Framebuffer virtual address, for the main screen this is the 3D left framebuffer.
Definition: gspgpu.h:13
void gspExitEventHandler(void)
Exits the GSPGPU event handler.
u32 Handle
Resource handle.
Definition: types.h:41
volatile u8 vu8
8-bit volatile unsigned integer.
Definition: types.h:31
Result GSPGPU_InvalidateDataCache(const void *adr, u32 size)
Invalidates memory in the data cache.
Result gspSubmitGxCommand(u32 *sharedGspCmdBuf, u32 gxCommand[0x8])
Submits a GX command.
GSPGPU_FramebufferFormats
Framebuffer format.
Definition: gspgpu.h:22
u32 * framebuf1_vaddr
For the main screen: 3D right framebuffer address.
Definition: gspgpu.h:14
Result GSPGPU_ImportDisplayCaptureInfo(GSPGPU_CaptureInfo *captureinfo)
Retrieves display capture info.
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
Memory fill completed.
Definition: gspgpu.h:49
Result GSPGPU_SetLedForceOff(bool disable)
Sets 3D_LEDSTATE to the input state value.
void gspExit(void)
Exits GSPGPU.
Result GSPGPU_SetBufferSwap(u32 screenid, GSPGPU_FramebufferInfo *framebufinfo)
Updates a screen's framebuffer state.
u32 framebuf_dispselect
Value for 0x1EF00X78, controls which framebuffer is displayed.
Definition: gspgpu.h:17
TODO.
Definition: gspgpu.h:55
RGB565. (2 bytes)
Definition: gspgpu.h:26
GSPGPU_Event gspWaitForAnyEvent(void)
Waits for any GSPGPU event to occur.
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
Capture info entry.
Definition: gspgpu.h:32
Result gspInitEventHandler(Handle gspEvent, vu8 *gspSharedMem, u8 gspThreadId)
Initializes the GSPGPU event handler.
u32 framebuf_widthbytesize
Framebuffer pitch.
Definition: gspgpu.h:37
Result GSPGPU_SaveVramSysArea(void)
Sames the VRAM sys area.
RGB5A1. (2 bytes)
Definition: gspgpu.h:27
Result GSPGPU_TriggerCmdReqQueue(void)
Triggers a handling of commands written to shared memory.
u32 framebuf_widthbytesize
Value for 0x1EF00X90, controls framebuffer width.
Definition: gspgpu.h:15
Framebuffer information.
Definition: gspgpu.h:10
RGBA8. (4 bytes)
Definition: gspgpu.h:24
TODO.
Definition: gspgpu.h:50
Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, u32 *data, u8 datasize, u32 *maskdata, u8 masksize)
Writes to GPU hardware registers with a mask.
u32 active_framebuf
Active framebuffer. (0 = first, 1 = second)
Definition: gspgpu.h:12
Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle *outMemHandle, u8 *threadID)
Registers the interrupt relay queue.
Result GSPGPU_WriteHWRegs(u32 regAddr, u32 *data, u8 size)
Writes to GPU hardware registers.
Result GSPGPU_RestoreVramSysArea(void)
Restores the VRAM sys area.
TODO.
Definition: gspgpu.h:51
Capture info.
Definition: gspgpu.h:41
BGR8. (3 bytes)
Definition: gspgpu.h:25
Result GSPGPU_ReleaseRight(void)
Releases GPU rights.
Result GSPGPU_ReadHWRegs(u32 regAddr, u32 *data, u8 size)
Reads from GPU hardware registers.
Result gspInit(void)
Initializes GSPGPU.
TODO.
Definition: gspgpu.h:52
u32 unk
Unknown.
Definition: gspgpu.h:18
u32 * framebuf0_vaddr
Left framebuffer.
Definition: gspgpu.h:34
Result GSPGPU_FlushDataCache(const void *adr, u32 size)
Flushes memory from the data cache.
Command list processing finished.
Definition: gspgpu.h:54