libctru  v2.3.1
gx.h
Go to the documentation of this file.
1 /**
2  * @file gx.h
3  * @brief GX commands.
4  */
5 #pragma once
6 
7 /**
8  * @brief Creates a buffer dimension parameter from width and height values.
9  * @param w buffer width for GX_DisplayTransfer, linesize for GX_TextureCopy
10  * @param h buffer height for GX_DisplayTransfer, gap for GX_TextureCopy
11  */
12 #define GX_BUFFER_DIM(w, h) (((h)<<16)|((w)&0xFFFF))
13 
14 /**
15  * @brief Supported transfer pixel formats.
16  * @sa GSPGPU_FramebufferFormat
17  */
18 typedef enum
19 {
20  GX_TRANSFER_FMT_RGBA8 = 0, ///< 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha
21  GX_TRANSFER_FMT_RGB8 = 1, ///< 8-bit Red + 8-bit Green + 8-bit Blue
22  GX_TRANSFER_FMT_RGB565 = 2, ///< 5-bit Red + 6-bit Green + 5-bit Blue
23  GX_TRANSFER_FMT_RGB5A1 = 3, ///< 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha
24  GX_TRANSFER_FMT_RGBA4 = 4 ///< 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha
26 
27 /**
28  * @brief Anti-aliasing modes
29  *
30  * Please remember that the framebuffer is sideways.
31  * Hence if you activate 2x1 anti-aliasing the destination dimensions are w = 240*2 and h = 400
32  */
33 typedef enum
34 {
35  GX_TRANSFER_SCALE_NO = 0, ///< No anti-aliasing
36  GX_TRANSFER_SCALE_X = 1, ///< 2x1 anti-aliasing
37  GX_TRANSFER_SCALE_XY = 2, ///< 2x2 anti-aliasing
39 
40 /// GX transfer control flags
41 typedef enum
42 {
43  GX_FILL_TRIGGER = 0x001, ///< Trigger the PPF event
44  GX_FILL_FINISHED = 0x002, ///< Indicates if the memory fill is complete. You should not use it when requesting a transfer.
45  GX_FILL_16BIT_DEPTH = 0x000, ///< The buffer has a 16 bit per pixel depth
46  GX_FILL_24BIT_DEPTH = 0x100, ///< The buffer has a 24 bit per pixel depth
47  GX_FILL_32BIT_DEPTH = 0x200, ///< The buffer has a 32 bit per pixel depth
49 
50 /// Creates a transfer vertical flip flag.
51 #define GX_TRANSFER_FLIP_VERT(x) ((x)<<0)
52 /// Creates a transfer tiled output flag.
53 #define GX_TRANSFER_OUT_TILED(x) ((x)<<1)
54 /// Creates a transfer raw copy flag.
55 #define GX_TRANSFER_RAW_COPY(x) ((x)<<3)
56 /// Creates a transfer input format flag.
57 #define GX_TRANSFER_IN_FORMAT(x) ((x)<<8)
58 /// Creates a transfer output format flag.
59 #define GX_TRANSFER_OUT_FORMAT(x) ((x)<<12)
60 /// Creates a transfer scaling flag.
61 #define GX_TRANSFER_SCALING(x) ((x)<<24)
62 
63 /// Updates gas additive blend results.
64 #define GX_CMDLIST_UPDATE_GAS_ACC BIT(0)
65 /// Flushes the command list.
66 #define GX_CMDLIST_FLUSH BIT(1)
67 
68 /// GX command entry
69 typedef union
70 {
71  u32 data[8]; ///< Raw command data
72  struct
73  {
74  u8 type; ///< Command type
75  u8 unk1;
76  u8 unk2;
77  u8 unk3;
78  u32 args[7]; ///< Command arguments
79  };
80 } gxCmdEntry_s;
81 
82 /// GX command queue structure
83 typedef struct tag_gxCmdQueue_s
84 {
85  gxCmdEntry_s* entries; ///< Pointer to array of GX command entries
86  u16 maxEntries; ///< Capacity of the command array
87  u16 numEntries; ///< Number of commands in the queue
88  u16 curEntry; ///< Index of the first pending command to be submitted to GX
89  u16 lastEntry; ///< Number of commands completed by GX
90  void (* callback)(struct tag_gxCmdQueue_s*); ///< User callback
91  void* user; ///< Data for user callback
92 } gxCmdQueue_s;
93 
94 /**
95  * @brief Clears a GX command queue.
96  * @param queue The GX command queue.
97  */
99 
100 /**
101  * @brief Adds a command to a GX command queue.
102  * @param queue The GX command queue.
103  * @param entry The GX command to add.
104  */
105 void gxCmdQueueAdd(gxCmdQueue_s* queue, const gxCmdEntry_s* entry);
106 
107 /**
108  * @brief Runs a GX command queue, causing it to begin processing incoming commands as they arrive.
109  * @param queue The GX command queue.
110  */
112 
113 /**
114  * @brief Stops a GX command queue from processing incoming commands.
115  * @param queue The GX command queue.
116  */
118 
119 /**
120  * @brief Waits for a GX command queue to finish executing pending commands.
121  * @param queue The GX command queue.
122  * @param timeout Optional timeout (in nanoseconds) to wait (specify -1 for no timeout).
123  * @return false if timeout expired, true otherwise.
124  */
125 bool gxCmdQueueWait(gxCmdQueue_s* queue, s64 timeout);
126 
127 /**
128  * @brief Sets the completion callback for a GX command queue.
129  * @param queue The GX command queue.
130  * @param callback The completion callback.
131  * @param user User data.
132  */
133 static inline void gxCmdQueueSetCallback(gxCmdQueue_s* queue, void (* callback)(gxCmdQueue_s*), void* user)
134 {
135  queue->callback = callback;
136  queue->user = user;
137 }
138 
139 /**
140  * @brief Selects a command queue to which GX_* functions will add commands instead of immediately submitting them to GX.
141  * @param queue The GX command queue. (Pass NULL to remove the bound command queue)
142  */
144 
145 /**
146  * @brief Requests a DMA.
147  * @param src Source to DMA from.
148  * @param dst Destination to DMA to.
149  * @param length Length of data to transfer.
150  */
151 Result GX_RequestDma(u32* src, u32* dst, u32 length);
152 
153 /**
154  * @brief Processes a GPU command list.
155  * @param buf0a Command list address.
156  * @param buf0s Command list size.
157  * @param flags Flags to process with.
158  */
159 Result GX_ProcessCommandList(u32* buf0a, u32 buf0s, u8 flags);
160 
161 /**
162  * @brief Fills the memory of two buffers with the given values.
163  * @param buf0a Start address of the first buffer.
164  * @param buf0v Dimensions of the first buffer.
165  * @param buf0e End address of the first buffer.
166  * @param control0 Value to fill the first buffer with.
167  * @param buf1a Start address of the second buffer.
168  * @param buf1v Dimensions of the second buffer.
169  * @param buf1e End address of the second buffer.
170  * @param control1 Value to fill the second buffer with.
171  */
172 Result GX_MemoryFill(u32* buf0a, u32 buf0v, u32* buf0e, u16 control0, u32* buf1a, u32 buf1v, u32* buf1e, u16 control1);
173 
174 /**
175  * @brief Initiates a display transfer.
176  * @note The PPF event will be signaled on completion.
177  * @param inadr Address of the input.
178  * @param indim Dimensions of the input.
179  * @param outadr Address of the output.
180  * @param outdim Dimensions of the output.
181  * @param flags Flags to transfer with.
182  */
183 Result GX_DisplayTransfer(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 flags);
184 
185 /**
186  * @brief Initiates a texture copy.
187  * @note The PPF event will be signaled on completion.
188  * @param inadr Address of the input.
189  * @param indim Dimensions of the input.
190  * @param outadr Address of the output.
191  * @param outdim Dimensions of the output.
192  * @param size Size of the data to transfer.
193  * @param flags Flags to transfer with.
194  */
195 Result GX_TextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags);
196 
197 /**
198  * @brief Flushes the cache regions of three buffers. (This command cannot be queued in a GX command queue)
199  * @param buf0a Address of the first buffer.
200  * @param buf0s Size of the first buffer.
201  * @param buf1a Address of the second buffer.
202  * @param buf1s Size of the second buffer.
203  * @param buf2a Address of the third buffer.
204  * @param buf2s Size of the third buffer.
205  */
206 Result GX_FlushCacheRegions(u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s);
void GX_BindQueue(gxCmdQueue_s *queue)
Selects a command queue to which GX_* functions will add commands instead of immediately submitting t...
Result GX_ProcessCommandList(u32 *buf0a, u32 buf0s, u8 flags)
Processes a GPU command list.
GX_TRANSFER_SCALE
Anti-aliasing modes.
Definition: gx.h:34
@ GX_TRANSFER_SCALE_XY
2x2 anti-aliasing
Definition: gx.h:37
@ GX_TRANSFER_SCALE_NO
No anti-aliasing.
Definition: gx.h:35
@ GX_TRANSFER_SCALE_X
2x1 anti-aliasing
Definition: gx.h:36
Result GX_TextureCopy(u32 *inadr, u32 indim, u32 *outadr, u32 outdim, u32 size, u32 flags)
Initiates a texture copy.
void gxCmdQueueAdd(gxCmdQueue_s *queue, const gxCmdEntry_s *entry)
Adds a command to a GX command queue.
Result GX_DisplayTransfer(u32 *inadr, u32 indim, u32 *outadr, u32 outdim, u32 flags)
Initiates a display transfer.
Result GX_RequestDma(u32 *src, u32 *dst, u32 length)
Requests a DMA.
static void gxCmdQueueSetCallback(gxCmdQueue_s *queue, void(*callback)(gxCmdQueue_s *), void *user)
Sets the completion callback for a GX command queue.
Definition: gx.h:133
void gxCmdQueueClear(gxCmdQueue_s *queue)
Clears a GX command queue.
Result GX_MemoryFill(u32 *buf0a, u32 buf0v, u32 *buf0e, u16 control0, u32 *buf1a, u32 buf1v, u32 *buf1e, u16 control1)
Fills the memory of two buffers with the given values.
void gxCmdQueueRun(gxCmdQueue_s *queue)
Runs a GX command queue, causing it to begin processing incoming commands as they arrive.
bool gxCmdQueueWait(gxCmdQueue_s *queue, s64 timeout)
Waits for a GX command queue to finish executing pending commands.
GX_TRANSFER_FORMAT
Supported transfer pixel formats.
Definition: gx.h:19
@ GX_TRANSFER_FMT_RGB565
5-bit Red + 6-bit Green + 5-bit Blue
Definition: gx.h:22
@ GX_TRANSFER_FMT_RGB5A1
5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha
Definition: gx.h:23
@ GX_TRANSFER_FMT_RGB8
8-bit Red + 8-bit Green + 8-bit Blue
Definition: gx.h:21
@ GX_TRANSFER_FMT_RGBA4
4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha
Definition: gx.h:24
@ GX_TRANSFER_FMT_RGBA8
8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha
Definition: gx.h:20
Result GX_FlushCacheRegions(u32 *buf0a, u32 buf0s, u32 *buf1a, u32 buf1s, u32 *buf2a, u32 buf2s)
Flushes the cache regions of three buffers.
void gxCmdQueueStop(gxCmdQueue_s *queue)
Stops a GX command queue from processing incoming commands.
GX_FILL_CONTROL
GX transfer control flags.
Definition: gx.h:42
@ GX_FILL_32BIT_DEPTH
The buffer has a 32 bit per pixel depth.
Definition: gx.h:47
@ GX_FILL_TRIGGER
Trigger the PPF event.
Definition: gx.h:43
@ GX_FILL_16BIT_DEPTH
The buffer has a 16 bit per pixel depth.
Definition: gx.h:45
@ GX_FILL_FINISHED
Indicates if the memory fill is complete. You should not use it when requesting a transfer.
Definition: gx.h:44
@ GX_FILL_24BIT_DEPTH
The buffer has a 24 bit per pixel depth.
Definition: gx.h:46
GX command queue structure.
Definition: gx.h:84
void(* callback)(struct tag_gxCmdQueue_s *)
User callback.
Definition: gx.h:90
u16 numEntries
Number of commands in the queue.
Definition: gx.h:87
void * user
Data for user callback.
Definition: gx.h:91
u16 curEntry
Index of the first pending command to be submitted to GX.
Definition: gx.h:88
u16 lastEntry
Number of commands completed by GX.
Definition: gx.h:89
u16 maxEntries
Capacity of the command array.
Definition: gx.h:86
gxCmdEntry_s * entries
Pointer to array of GX command entries.
Definition: gx.h:85
int64_t s64
64-bit signed integer
Definition: types.h:29
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
s32 Result
Function result.
Definition: types.h:42
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
GX command entry.
Definition: gx.h:70
u8 type
Command type.
Definition: gx.h:74