libdragon
Loading...
Searching...
No Matches
rdpq.h
Go to the documentation of this file.
1
144#ifndef __LIBDRAGON_RDPQ_H
145#define __LIBDRAGON_RDPQ_H
146
147#include <stdint.h>
148#include <stdbool.h>
149#include <string.h>
150#include "graphics.h"
151#include "n64sys.h"
152#include "rdpq_macros.h"
153#include "surface.h"
154#include "debug.h"
155
161#define RDPQ_OVL_ID (0xC << 28)
162
163enum {
164 RDPQ_CMD_NOOP = 0x00,
165 RDPQ_CMD_SET_LOOKUP_ADDRESS = 0x01,
166 RDPQ_CMD_FILL_RECTANGLE_EX = 0x02,
167 RDPQ_CMD_RESET_RENDER_MODE = 0x04,
168 RDPQ_CMD_SET_COMBINE_MODE_2PASS = 0x05,
169 RDPQ_CMD_PUSH_RENDER_MODE = 0x06,
170 RDPQ_CMD_POP_RENDER_MODE = 0x07,
171 RDPQ_CMD_TRI = 0x08,
172 RDPQ_CMD_TRI_ZBUF = 0x09,
173 RDPQ_CMD_TRI_TEX = 0x0A,
174 RDPQ_CMD_TRI_TEX_ZBUF = 0x0B,
175 RDPQ_CMD_TRI_SHADE = 0x0C,
176 RDPQ_CMD_TRI_SHADE_ZBUF = 0x0D,
177 RDPQ_CMD_TRI_SHADE_TEX = 0x0E,
178 RDPQ_CMD_TRI_SHADE_TEX_ZBUF = 0x0F,
179
180 RDPQ_CMD_TEXTURE_RECTANGLE_EX = 0x10,
181 RDPQ_CMD_SET_DEBUG_MODE = 0x11,
182 RDPQ_CMD_SET_SCISSOR_EX = 0x12,
183 RDPQ_CMD_SET_PRIM_COLOR_COMPONENT = 0x13,
184 RDPQ_CMD_MODIFY_OTHER_MODES = 0x14,
185 RDPQ_CMD_SET_FILL_COLOR_32 = 0x16,
186 RDPQ_CMD_SET_BLENDING_MODE = 0x18,
187 RDPQ_CMD_SET_FOG_MODE = 0x19,
188 RDPQ_CMD_SET_COMBINE_MODE_1PASS = 0x1B,
189 RDPQ_CMD_AUTOTMEM_SET_ADDR = 0x1C,
190 RDPQ_CMD_AUTOTMEM_SET_TILE = 0x1D,
191 RDPQ_CMD_TRIANGLE = 0x1E,
192 RDPQ_CMD_TRIANGLE_DATA = 0x1F,
193
194 RDPQ_CMD_TEXTURE_RECTANGLE = 0x24,
195 RDPQ_CMD_TEXTURE_RECTANGLE_FLIP = 0x25,
196 RDPQ_CMD_SYNC_LOAD = 0x26,
197 RDPQ_CMD_SYNC_PIPE = 0x27,
198 RDPQ_CMD_SYNC_TILE = 0x28,
199 RDPQ_CMD_SYNC_FULL = 0x29,
200 RDPQ_CMD_SET_KEY_GB = 0x2A,
201 RDPQ_CMD_SET_KEY_R = 0x2B,
202 RDPQ_CMD_SET_CONVERT = 0x2C,
203 RDPQ_CMD_SET_SCISSOR = 0x2D,
204 RDPQ_CMD_SET_PRIM_DEPTH = 0x2E,
205 RDPQ_CMD_SET_OTHER_MODES = 0x2F,
206
207 RDPQ_CMD_LOAD_TLUT = 0x30,
208 RDPQ_CMD_DEBUG = 0x31,
209 RDPQ_CMD_SET_TILE_SIZE = 0x32,
210 RDPQ_CMD_LOAD_BLOCK = 0x33,
211 RDPQ_CMD_LOAD_TILE = 0x34,
212 RDPQ_CMD_SET_TILE = 0x35,
213 RDPQ_CMD_FILL_RECTANGLE = 0x36,
214 RDPQ_CMD_SET_FILL_COLOR = 0x37,
215 RDPQ_CMD_SET_FOG_COLOR = 0x38,
216 RDPQ_CMD_SET_BLEND_COLOR = 0x39,
217 RDPQ_CMD_SET_PRIM_COLOR = 0x3A,
218 RDPQ_CMD_SET_ENV_COLOR = 0x3B,
219 RDPQ_CMD_SET_COMBINE_MODE_RAW = 0x3C,
220 RDPQ_CMD_SET_TEXTURE_IMAGE = 0x3D,
221 RDPQ_CMD_SET_Z_IMAGE = 0x3E,
222 RDPQ_CMD_SET_COLOR_IMAGE = 0x3F,
223};
224
225#define RDPQ_CFG_AUTOSYNCPIPE (1 << 0)
226#define RDPQ_CFG_AUTOSYNCLOAD (1 << 1)
227#define RDPQ_CFG_AUTOSYNCTILE (1 << 2)
228#define RDPQ_CFG_AUTOSCISSOR (1 << 3)
229#define RDPQ_CFG_DEFAULT (0xFFFF)
230
232// Used in inline functions as part of the autosync engine. Not part of public API.
233#define AUTOSYNC_TILE(n) (1 << (0+(n))) // Autosync state: Bit used for tile N
234#define AUTOSYNC_TILES (0xFF << 0) // Autosync state: Mask for all bits regarding tile
235#define AUTOSYNC_TMEM(n) (1 << (8+(n))) // Autosync state: Bit used for tmem portion N
236#define AUTOSYNC_TMEMS (0xFF << 8) // Autosync state: Mask for all bits regarding TMEM
237#define AUTOSYNC_PIPE (1 << 16) // Autosync state: Bit used for pipe
239
241/* Used internally for bit-packing RDP commands. Not part of public API. */
242#define _carg(value, mask, shift) (((uint32_t)((value) & (mask))) << (shift))
244
250typedef enum {
251 TILE0 = 0,
252 TILE1 = 1,
253 TILE2 = 2,
254 TILE3 = 3,
255 TILE4 = 4,
256 TILE5 = 5,
257 TILE6 = 6,
258 TILE7 = 7,
260
261
272typedef struct {
273 uint8_t palette;
274
275 // Additional mapping parameters; Leave them as 0 if not required;
276
277 struct{
278 bool clamp;
279 bool mirror;
280 uint8_t mask;
281 int8_t shift;
282 } s,t; // S/T directions of the tile descriptor
283
285
287#define RDPQ_TILE_INTERNAL TILE7
288
289#ifdef __cplusplus
290extern "C" {
291#endif
292
294extern void __rdpq_set_scissor(uint32_t, uint32_t);
295
307void rdpq_init(void);
308
314void rdpq_close(void);
315
316
335uint32_t rdpq_config_set(uint32_t cfg);
336
350uint32_t rdpq_config_enable(uint32_t cfg_enable_bits);
351
352
381uint32_t rdpq_config_disable(uint32_t cfg_disable_bits);
382
386inline void rdpq_set_yuv_parms(uint16_t k0, uint16_t k1, uint16_t k2, uint16_t k3, uint16_t k4, uint16_t k5)
387{
388 extern void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync);
389 __rdpq_write8_syncchange(RDPQ_CMD_SET_CONVERT,
390 _carg(k0, 0x1FF, 13) | _carg(k1, 0x1FF, 4) | (((uint32_t)(k2 & 0x1FF)) >> 5),
391 _carg(k2, 0x1F, 27) | _carg(k3, 0x1FF, 18) | _carg(k4, 0x1FF, 9) | _carg(k5, 0x1FF, 0),
392 AUTOSYNC_PIPE);
393}
394
424#define rdpq_set_scissor(x0, y0, x1, y1) ({ \
425 int32_t x0fx = (x0)*4; \
426 int32_t y0fx = (y0)*4; \
427 int32_t x1fx = (x1)*4; \
428 int32_t y1fx = (y1)*4; \
429 assertf(x0fx <= x1fx, "x1 must be greater or equal to x0"); \
430 assertf(y0fx <= y1fx, "y1 must be greater or equal to y0"); \
431 assertf(x0fx >= 0, "x0 must be positive"); \
432 assertf(y0fx >= 0, "y0 must be positive"); \
433 assertf(x1fx <= 0xFFF, "x1 must be less than 1024"); \
434 assertf(y1fx <= 0xFFF, "y1 must be less than 1024"); \
435 __rdpq_set_scissor( \
436 _carg(x0fx, 0xFFF, 12) | _carg(y0fx, 0xFFF, 0), \
437 _carg(x1fx, 0xFFF, 12) | _carg(y1fx, 0xFFF, 0)); \
438})
439
465 inline void rdpq_set_prim_depth_raw(uint16_t prim_z, int16_t prim_dz)
466{
467 // NOTE: this does not require a pipe sync
468 extern void __rdpq_write8(uint32_t, uint32_t, uint32_t);
469 assertf(prim_z <= 0x7FFF, "prim_z must be in [0..0x7FFF]");
470 assertf((prim_dz & -prim_dz) == (prim_dz >= 0 ? prim_dz : -prim_dz),
471 "prim_dz must be a power of 2");
472 __rdpq_write8(RDPQ_CMD_SET_PRIM_DEPTH, 0, _carg(prim_z, 0xFFFF, 16) | _carg(prim_dz, 0xFFFF, 0));
473}
474
520#define rdpq_load_tile(tile, s0, t0, s1, t1) ({ \
521 assertf((s0) >= 0 && (t0) >= 0 && (s1) >= 0 && (t1) >= 0, "texture coordinates must be positive"); \
522 assertf((s0) < 1024 && (t0) < 1024 && (s1) < 1024 && (t1) < 1024, "texture coordinates must be smaller than 1024"); \
523 rdpq_load_tile_fx((tile), (s0)*4, (t0)*4, (s1)*4, (t1)*4); \
524})
525
549inline void rdpq_load_tile_fx(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t s1, uint16_t t1)
550{
551 extern void __rdpq_write8_syncchangeuse(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
552 __rdpq_write8_syncchangeuse(RDPQ_CMD_LOAD_TILE,
553 _carg(s0, 0xFFF, 12) | _carg(t0, 0xFFF, 0),
554 _carg(tile, 0x7, 24) | _carg(s1-4, 0xFFF, 12) | _carg(t1-4, 0xFFF, 0),
555 AUTOSYNC_TMEM(0) | AUTOSYNC_TILE(tile),
556 AUTOSYNC_TILE(tile));
557}
558
559
590inline void rdpq_load_tlut_raw(rdpq_tile_t tile, int color_idx, int num_colors)
591{
592 extern void __rdpq_write8_syncchangeuse(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
593 __rdpq_write8_syncchangeuse(RDPQ_CMD_LOAD_TLUT,
594 _carg(color_idx, 0xFF, 14),
595 _carg(tile, 0x7, 24) | _carg(color_idx+num_colors-1, 0xFF, 14),
596 AUTOSYNC_TMEM(0),
597 AUTOSYNC_TILE(tile));
598}
599
626#define rdpq_set_tile_size(tile, s0, t0, s1, t1) ({ \
627 rdpq_set_tile_size_fx((tile), (s0)*4, (t0)*4, (s1)*4, (t1)*4); \
628})
629
645inline void rdpq_set_tile_size_fx(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t s1, uint16_t t1)
646{
647 assertf((s0) >= 0 && (t0) >= 0 && (s1) >= 0 && (t1) >= 0, "texture coordinates must be positive");
648 assertf((s0) <= 1024*4 && (t0) <= 1024*4 && (s1) <= 1024*4 && (t1) <= 1024*4, "texture coordinates must be smaller than 1024");
649
650 extern void __rdpq_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
651 __rdpq_write8_syncchange(RDPQ_CMD_SET_TILE_SIZE,
652 _carg(s0, 0xFFF, 12) | _carg(t0, 0xFFF, 0),
653 _carg(tile, 0x7, 24) | _carg(s1-4, 0xFFF, 12) | _carg(t1-4, 0xFFF, 0),
654 AUTOSYNC_TILE(tile));
655}
656
657
661inline void rdpq_load_block_fx(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t num_texels, uint16_t dxt)
662{
663 extern void __rdpq_write8_syncchangeuse(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
664 __rdpq_write8_syncchangeuse(RDPQ_CMD_LOAD_BLOCK,
665 _carg(s0, 0xFFF, 12) | _carg(t0, 0xFFF, 0),
666 _carg(tile, 0x7, 24) | _carg(num_texels-1, 0xFFF, 12) | _carg(dxt, 0xFFF, 0),
667 AUTOSYNC_TMEM(0),
668 AUTOSYNC_TILE(tile));
669}
670
718inline void rdpq_load_block(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t num_texels, uint16_t tmem_pitch)
719{
720 assertf(num_texels <= 2048, "invalid num_texels %d: must be smaller than 2048", num_texels);
721 assertf((tmem_pitch % 8) == 0, "invalid tmem_pitch %d: must be multiple of 8", tmem_pitch);
722 // Dxt is the reciprocal of the number of 64 bit words in a line in 1.11 format, rounded up
723 uint32_t words = tmem_pitch / 8;
724 rdpq_load_block_fx(tile, s0, t0, num_texels, (2048 + words - 1) / words);
725}
726
727
729#define RDPQ_AUTOTMEM (0x8000)
731#define RDPQ_AUTOTMEM_REUSE(offset) (0x4000 | ((offset)/8))
732
733
740inline void rdpq_set_tile(rdpq_tile_t tile,
741 tex_format_t format,
742 int32_t tmem_addr,
743 uint16_t tmem_pitch,
744 const rdpq_tileparms_t *parms)
745{
746 static const rdpq_tileparms_t default_parms = {0};
747 if (!parms) parms = &default_parms;
748 else {
749 assertf(parms->s.shift >= -5 && parms->s.shift <= 10, "invalid s shift %d: must be in [-5..10]", parms->s.shift);
750 assertf(parms->t.shift >= -5 && parms->t.shift <= 10, "invalid t shift %d: must be in [-5..10]", parms->t.shift);
751 }
752 bool fixup = false;
753 bool reuse = false;
754 uint32_t cmd_id = RDPQ_CMD_SET_TILE;
755 if (tmem_addr & (RDPQ_AUTOTMEM | RDPQ_AUTOTMEM_REUSE(0))) {
756 cmd_id = RDPQ_CMD_AUTOTMEM_SET_TILE;
757 reuse = (tmem_addr & RDPQ_AUTOTMEM_REUSE(0)) != 0;
758 fixup = true;
759 tmem_addr &= ~(RDPQ_AUTOTMEM | RDPQ_AUTOTMEM_REUSE(0));
760 } else {
761 assertf((tmem_addr % 8) == 0, "invalid tmem_addr %ld: must be multiple of 8", tmem_addr);
762 tmem_addr /= 8;
763 }
764 assertf((tmem_pitch % 8) == 0, "invalid tmem_pitch %d: must be multiple of 8", tmem_pitch);
765 extern void __rdpq_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
766 extern void __rdpq_fixup_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
768 _carg(format, 0x1F, 19) | _carg(reuse, 0x1, 18) | _carg(tmem_pitch/8, 0x1FF, 9) | _carg(tmem_addr, 0x1FF, 0),
769 _carg(tile, 0x7, 24) | _carg(parms->palette, 0xF, 20) |
770 _carg(parms->t.clamp | (parms->t.mask == 0), 0x1, 19) | _carg(parms->t.mirror, 0x1, 18) | _carg(parms->t.mask, 0xF, 14) | _carg(parms->t.shift, 0xF, 10) |
771 _carg(parms->s.clamp | (parms->s.mask == 0), 0x1, 9) | _carg(parms->s.mirror, 0x1, 8) | _carg(parms->s.mask, 0xF, 4) | _carg(parms->s.shift, 0xF, 0),
772 AUTOSYNC_TILE(tile));
773}
774
811void rdpq_set_tile_autotmem(int16_t tmem_bytes);
812
838inline void rdpq_set_fill_color(color_t color) {
839 extern void __rdpq_set_fill_color(uint32_t);
840 __rdpq_set_fill_color((color.r << 24) | (color.g << 16) | (color.b << 8) | (color.a << 0));
841}
842
861inline void rdpq_set_fill_color_stripes(color_t color1, color_t color2) {
862 extern void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync);
863 uint32_t c1 = (((int)color1.r >> 3) << 11) | (((int)color1.g >> 3) << 6) | (((int)color1.b >> 3) << 1) | (color1.a >> 7);
864 uint32_t c2 = (((int)color2.r >> 3) << 11) | (((int)color2.g >> 3) << 6) | (((int)color2.b >> 3) << 1) | (color2.a >> 7);
865 __rdpq_write8_syncchange(RDPQ_CMD_SET_FILL_COLOR, 0, (c1 << 16) | c2,
866 AUTOSYNC_PIPE);
867}
868
890inline void rdpq_set_fog_color(color_t color)
891{
892 extern void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync);
893 __rdpq_write8_syncchange(RDPQ_CMD_SET_FOG_COLOR, 0, color_to_packed32(color),
894 AUTOSYNC_PIPE);
895}
896
919{
920 extern void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync);
921 __rdpq_write8_syncchange(RDPQ_CMD_SET_BLEND_COLOR, 0, color_to_packed32(color),
922 AUTOSYNC_PIPE);
923}
924
952inline void rdpq_set_prim_color(color_t color)
953{
954 // NOTE: this does not require a pipe sync
955 extern void __rdpq_fixup_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
956 __rdpq_fixup_write8_syncchange(RDPQ_CMD_SET_PRIM_COLOR_COMPONENT, (0<<16), color_to_packed32(color), 0);
957}
958
976inline void rdpq_set_detail_factor(float value)
977{
978 // NOTE: this does not require a pipe sync
979 int8_t conv = (1.0 - value) * 31;
980 extern void __rdpq_fixup_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
981 __rdpq_fixup_write8_syncchange(RDPQ_CMD_SET_PRIM_COLOR_COMPONENT, ((conv & 0x1F) << 8) | (2<<16), 0, 0);
982}
983
1003inline void rdpq_set_prim_lod_frac(uint8_t value)
1004{
1005 // NOTE: this does not require a pipe sync
1006 extern void __rdpq_fixup_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
1007 __rdpq_fixup_write8_syncchange(RDPQ_CMD_SET_PRIM_COLOR_COMPONENT, value | (1<<16), 0, 0);
1008}
1009
1041inline void rdpq_set_prim_register_raw(color_t color, uint8_t minlod, uint8_t primlod)
1042{
1043 extern void __rdpq_write8(uint32_t cmd_id, uint32_t arg0, uint32_t arg1);
1044 __rdpq_write8(RDPQ_CMD_SET_PRIM_COLOR, ((minlod & 0x1F) << 8) | primlod, color_to_packed32(color));
1045}
1046
1068inline void rdpq_set_env_color(color_t color)
1069{
1070 extern void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync);
1071 __rdpq_write8_syncchange(RDPQ_CMD_SET_ENV_COLOR, 0, color_to_packed32(color),
1072 AUTOSYNC_PIPE);
1073}
1074
1099void rdpq_set_color_image(const surface_t *surface);
1100
1119void rdpq_set_z_image(const surface_t* surface);
1120
1135void rdpq_set_texture_image(const surface_t* surface);
1136
1161inline void rdpq_set_color_image_raw(uint8_t index, uint32_t offset, tex_format_t format, uint32_t width, uint32_t height, uint32_t stride)
1162{
1163 assertf(format == FMT_RGBA32 || format == FMT_RGBA16 ||
1164 format == FMT_I8 || format == FMT_CI8,
1165 "Image format is not supported as color image: %s\nIt must be FMT_RGBA32, FMT_RGBA16, FMT_I8 or FMT_CI8", tex_format_name(format));
1166 assertf(index <= 15, "Lookup address index out of range [0,15]: %d", index);
1167
1168 extern void __rdpq_set_color_image(uint32_t, uint32_t, uint32_t, uint32_t);
1170 _carg(format, 0x1F, 19) | _carg(TEX_FORMAT_BYTES2PIX(format, stride)-1, 0x3FF, 0) | _carg(height-1, 0x1FF, 10),
1171 _carg(index, 0xF, 28) | (offset & 0xFFFFFF) | _carg((height-1)>>9, 0x1, 31),
1172 _carg(0, 0xFFF, 12) | _carg(0, 0xFFF, 0), // for set_scissor
1173 _carg(width*4, 0xFFF, 12) | _carg(height*4, 0xFFF, 0)); // for set_scissor
1174}
1175
1195inline void rdpq_set_z_image_raw(uint8_t index, uint32_t offset)
1196{
1197 assertf(index <= 15, "Lookup address index out of range [0,15]: %d", index);
1198 extern void __rdpq_fixup_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
1199 __rdpq_fixup_write8_syncchange(RDPQ_CMD_SET_Z_IMAGE,
1200 0,
1201 _carg(index, 0xF, 28) | (offset & 0xFFFFFF),
1202 AUTOSYNC_PIPE);
1203}
1204
1227inline void rdpq_set_texture_image_raw(uint8_t index, uint32_t offset, tex_format_t format, uint16_t width, uint16_t height)
1228{
1229 assertf(width <= 1024, "Texture width out of range [1,1024]: %d", width);
1230 assertf(height <= 1024, "Texture height out of range [1,1024]: %d", height);
1231 assertf(index <= 15, "Lookup address index out of range [0,15]: %d", index);
1232 extern void __rdpq_fixup_write8_syncchange(uint32_t, uint32_t, uint32_t, uint32_t);
1233 // NOTE: we also encode the texture height in the command (split in two halves...)
1234 // to help the validator to a better job. The RDP hardware ignores those bits.
1235 __rdpq_fixup_write8_syncchange(RDPQ_CMD_SET_TEXTURE_IMAGE,
1236 _carg(format, 0x1F, 19) | _carg(width-1, 0x3FF, 0) | _carg(height-1, 0x1FF, 10),
1237 _carg(index, 0xF, 28) | (offset & 0xFFFFFF) | _carg((height-1)>>9, 0x1, 31),
1238 AUTOSYNC_PIPE);
1239}
1240
1297inline void rdpq_set_lookup_address(uint8_t index, void* rdram_addr)
1298{
1299 assertf(index > 0 && index <= 15, "Lookup address index out of range [1,15]: %d", index);
1300 extern void __rdpq_write8(uint32_t, uint32_t, uint32_t);
1301 __rdpq_write8(RDPQ_CMD_SET_LOOKUP_ADDRESS, index << 2, PhysicalAddr(rdram_addr));
1302}
1303
1317void rdpq_sync_pipe(void);
1318
1332void rdpq_sync_tile(void);
1333
1347void rdpq_sync_load(void);
1348
1372void rdpq_sync_full(void (*callback)(void*), void* arg);
1373
1374
1391inline void rdpq_set_other_modes_raw(uint64_t mode)
1392{
1393 extern void __rdpq_set_other_modes(uint32_t, uint32_t);
1395 (mode >> 32) & 0x00FFFFFF,
1396 mode & 0xFFFFFFFF);
1397}
1398
1417inline void rdpq_change_other_modes_raw(uint64_t mask, uint64_t val)
1418{
1419 extern void __rdpq_change_other_modes(uint32_t, uint32_t, uint32_t);
1420
1421 if (mask >> 32)
1422 __rdpq_change_other_modes(0, ~(mask >> 32), val >> 32);
1423 if ((uint32_t)mask)
1424 __rdpq_change_other_modes(4, ~(uint32_t)mask, (uint32_t)val);
1425}
1426
1436uint64_t rdpq_get_other_modes_raw(void);
1437
1456inline void rdpq_set_combiner_raw(uint64_t comb) {
1457 extern void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync);
1458 __rdpq_write8_syncchange(RDPQ_CMD_SET_COMBINE_MODE_RAW,
1459 (comb >> 32) & 0x00FFFFFF,
1460 comb & 0xFFFFFFFF,
1461 AUTOSYNC_PIPE);
1462}
1463
1484void rdpq_fence(void);
1485
1504void rdpq_exec(void *buffer, int size);
1505
1542#define rdpq_write(num_rdp_commands, ovl_id, cmd_id, ...) ({ \
1543 int __num_rdp_commands = (num_rdp_commands); \
1544 if (!__builtin_constant_p(__num_rdp_commands) || __num_rdp_commands != 0) { \
1545 extern rspq_block_t *rspq_block; \
1546 if (__builtin_expect(rspq_block != NULL, 0)) { \
1547 extern void __rdpq_block_reserve(int); \
1548 __rdpq_block_reserve(__num_rdp_commands); \
1549 } \
1550 } \
1551 rspq_write(ovl_id, cmd_id, ##__VA_ARGS__); \
1552})
1553
1554
1555#ifdef __cplusplus
1556}
1557#endif
1558
1559#endif
Debugging Support.
#define assertf(expr, msg,...)
assertf() is like assert() with an attached printf().
Definition debug.h:196
2D Graphics
uint8_t a
Alpha component.
Definition graphics.h:62
uint8_t g
Green component.
Definition graphics.h:58
uint8_t b
Blue component.
Definition graphics.h:60
uint8_t r
Red component.
Definition graphics.h:56
uint32_t color_to_packed32(color_t c)
Convert a color_t to the 32-bit packed format used by a FMT_RGBA32 surface (RGBA 8888)
Definition graphics.h:86
Generic color structure.
Definition graphics.h:54
#define PhysicalAddr(_addr)
Return the physical memory address for a given address.
Definition n64sys.h:124
N64 System Interface.
void __rdpq_set_scissor(uint32_t w0, uint32_t w1)
Out-of-line implementation of rdpq_set_scissor.
Definition rdpq.c:972
void __rdpq_set_fill_color(uint32_t w1)
Out-of-line implementation of rdpq_set_fill_color.
Definition rdpq.c:983
void __rdpq_change_other_modes(uint32_t w0, uint32_t w1, uint32_t w2)
Out-of-line implementation of rdpq_change_other_modes_raw.
Definition rdpq.c:1071
void __rdpq_write8_syncchangeuse(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync_c, uint32_t autosync_u)
Write a standard 8-byte RDP command, which changes some autosync resources and uses others.
Definition rdpq.c:928
void __rdpq_set_other_modes(uint32_t w0, uint32_t w1)
Out-of-line implementation of rdpq_set_other_modes_raw.
Definition rdpq.c:1056
void __rdpq_set_color_image(uint32_t w0, uint32_t w1, uint32_t sw0, uint32_t sw1)
Out-of-line implementation of rdpq_set_color_image.
Definition rdpq.c:991
void __rdpq_fixup_write8_syncchange(uint32_t cmd_id, uint32_t w0, uint32_t w1, uint32_t autosync)
Write a 8-byte RDP command fixup.
Definition rdpq.c:952
void __rdpq_write8_syncchange(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t autosync)
Write a standard 8-byte RDP command, which changes some autosync resources
Definition rdpq.c:912
void __rdpq_write8(uint32_t cmd_id, uint32_t arg0, uint32_t arg1)
Write a standard 8-byte RDP command.
Definition rdpq.c:905
void rdpq_load_block_fx(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t num_texels, uint16_t dxt)
Low level function to load a texture image into TMEM in a single memory transfer.
Definition rdpq.h:661
void rdpq_set_color_image_raw(uint8_t index, uint32_t offset, tex_format_t format, uint32_t width, uint32_t height, uint32_t stride)
Low-level version of rdpq_set_color_image, with address lookup capability.
Definition rdpq.h:1161
void rdpq_set_texture_image(const surface_t *surface)
Configure the texture to use (RDP command: SET_TEX_IMAGE)
Definition rdpq.c:1041
void rdpq_set_env_color(color_t color)
Set the RDP ENV combiner register (RDP command: SET_ENV_COLOR)
Definition rdpq.h:1068
void rdpq_close(void)
Shutdown the RDPQ library.
Definition rdpq.c:488
void rdpq_set_prim_lod_frac(uint8_t value)
Set the RDP PRIM LOD FRAC combiner register (RDP command: SET_PRIM_COLOR (partial))
Definition rdpq.h:1003
void rdpq_set_tile(rdpq_tile_t tile, tex_format_t format, int32_t tmem_addr, uint16_t tmem_pitch, const rdpq_tileparms_t *parms)
Enqueue a RDP SET_TILE command (full version)
Definition rdpq.h:740
void rdpq_set_combiner_raw(uint64_t comb)
Low-level function to change the RDP combiner.
Definition rdpq.h:1456
void rdpq_set_yuv_parms(uint16_t k0, uint16_t k1, uint16_t k2, uint16_t k3, uint16_t k4, uint16_t k5)
Low level functions to set the matrix coefficients for texture format conversion.
Definition rdpq.h:386
void rdpq_exec(void *buffer, int size)
Send to the RDP a buffer of RDP commands from RDRAM.
Definition rdpq.c:528
void rdpq_init(void)
Initialize the RDPQ library.
Definition rdpq.c:446
void rdpq_change_other_modes_raw(uint64_t mask, uint64_t val)
Low-level function to partly change the rendering mode register.
Definition rdpq.h:1417
void rdpq_set_fill_color(color_t color)
Enqueue a SET_FILL_COLOR RDP command.
Definition rdpq.h:838
void rdpq_sync_load(void)
Schedule a RDP SYNC_LOAD command.
Definition rdpq.c:1126
void rdpq_set_prim_register_raw(color_t color, uint8_t minlod, uint8_t primlod)
Set the RDP PRIM combiner register (raw version) (RDP command: SET_PRIM_COLOR)
Definition rdpq.h:1041
uint8_t palette
Optional palette associated to the texture. For textures in FMT_CI4 format, specify the palette index...
Definition rdpq.h:273
void rdpq_set_fog_color(color_t color)
Set the RDP FOG blender register.
Definition rdpq.h:890
void rdpq_set_z_image(const surface_t *surface)
Configure the Z-buffer to use (RDP command: SET_Z_IMAGE)
Definition rdpq.c:1028
rdpq_tile_t
Tile descriptors.
Definition rdpq.h:250
@ TILE5
Tile #5 (for code readability)
Definition rdpq.h:256
@ TILE3
Tile #3 (for code readability)
Definition rdpq.h:254
@ TILE4
Tile #4 (for code readability)
Definition rdpq.h:255
@ TILE7
Tile #7 (for code readability)
Definition rdpq.h:258
@ TILE0
Tile #0 (for code readability)
Definition rdpq.h:251
@ TILE1
Tile #1 (for code readability)
Definition rdpq.h:252
@ TILE6
Tile #6 (for code readability)
Definition rdpq.h:257
@ TILE2
Tile #2 (for code readability)
Definition rdpq.h:253
void rdpq_set_color_image(const surface_t *surface)
Configure the framebuffer to render to (RDP command: SET_COLOR_IMAGE)
Definition rdpq.c:1002
void rdpq_set_detail_factor(float value)
Set the detail/sharpen blending factor (RDP command: SET_PRIM_COLOR (partial))
Definition rdpq.h:976
void rdpq_load_block(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t num_texels, uint16_t tmem_pitch)
Load a texture image into TMEM with a single contiguous memory transfer (RDP command: LOAD_BLOCK)
Definition rdpq.h:718
void rdpq_set_tile_size_fx(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t s1, uint16_t t1)
Configure the extents of a tile descriptor – fixed point version (RDP command: SET_TILE_SIZE)
Definition rdpq.h:645
void rdpq_sync_full(void(*callback)(void *), void *arg)
Schedule a RDP SYNC_FULL command and register a callback when it is done.
Definition rdpq.c:1101
void rdpq_sync_tile(void)
Schedule a RDP SYNC_TILE command.
Definition rdpq.c:1120
void rdpq_set_texture_image_raw(uint8_t index, uint32_t offset, tex_format_t format, uint16_t width, uint16_t height)
Low-level version of rdpq_set_texture_image, with address lookup capability.
Definition rdpq.h:1227
void rdpq_set_fill_color_stripes(color_t color1, color_t color2)
Enqueue a SET_FILL_COLOR RDP command to draw a striped pattern.
Definition rdpq.h:861
void rdpq_set_prim_depth_raw(uint16_t prim_z, int16_t prim_dz)
Set a fixed Z value to be used instead of a per-pixel value (RDP command; SET_PRIM_DEPTH)
Definition rdpq.h:465
void rdpq_set_lookup_address(uint8_t index, void *rdram_addr)
Store an address into the rdpq lookup table.
Definition rdpq.h:1297
void rdpq_load_tlut_raw(rdpq_tile_t tile, int color_idx, int num_colors)
Load a palette of colors into TMEM (RDP command: LOAD_TLUT)
Definition rdpq.h:590
void rdpq_sync_pipe(void)
Schedule a RDP SYNC_PIPE command.
Definition rdpq.c:1114
uint64_t rdpq_get_other_modes_raw(void)
Read the current render mode register.
Definition rdpq.c:1086
void rdpq_set_prim_color(color_t color)
Set the RDP PRIM combiner register (color only) (RDP command: SET_PRIM_COLOR)
Definition rdpq.h:952
void rdpq_load_tile_fx(rdpq_tile_t tile, uint16_t s0, uint16_t t0, uint16_t s1, uint16_t t1)
Load a portion of a texture into TMEM – fixed point version (RDP command: LOAD_TILE)
Definition rdpq.h:549
#define RDPQ_AUTOTMEM
Special TMEM address to pass to rdpq_set_tile to use automatic TMEM allocation.
Definition rdpq.h:729
void rdpq_set_blend_color(color_t color)
Set the RDP BLEND blender register.
Definition rdpq.h:918
void rdpq_set_z_image_raw(uint8_t index, uint32_t offset)
Low-level version of rdpq_set_z_image, with address lookup capability.
Definition rdpq.h:1195
void rdpq_fence(void)
Add a fence to synchronize RSP with RDP commands.
Definition rdpq.c:518
uint32_t rdpq_config_disable(uint32_t cfg_disable_bits)
Disable a specific set of configuration flags.
Definition rdpq.c:513
uint32_t rdpq_config_enable(uint32_t cfg_enable_bits)
Enable a specific set of configuration flags.
Definition rdpq.c:508
uint32_t rdpq_config_set(uint32_t cfg)
Set the configuration of the RDPQ module.
Definition rdpq.c:501
void rdpq_set_tile_autotmem(int16_t tmem_bytes)
Configure the auto-TMEM feature of rdpq_set_tile.
Definition rdpq.c:1092
void rdpq_set_other_modes_raw(uint64_t mode)
Low-level function to set the rendering mode register.
Definition rdpq.h:1391
#define RDPQ_AUTOTMEM_REUSE(offset)
Special TMEM address to pass to rdpq_set_tile to configure a tile with the same address of previous t...
Definition rdpq.h:731
Tile parameters for rdpq_set_tile.
Definition rdpq.h:272
RDP command macros.
const char * tex_format_name(tex_format_t fmt)
Return the name of the texture format as a string (for debugging purposes)
Definition surface.c:15
Surface buffers used to draw images.
tex_format_t
Pixel format enum.
Definition surface.h:105
@ FMT_RGBA32
Format RGBA 8888 (32-bit)
Definition surface.h:109
@ FMT_CI8
Format CI8: color index 8-bit (paletted, 1 index per byte)
Definition surface.h:112
@ FMT_I8
Format I8: 8-bit intensity (8-bit per pixel)
Definition surface.h:117
@ FMT_RGBA16
Format RGBA 5551 (16-bit)
Definition surface.h:108
#define TEX_FORMAT_BYTES2PIX(fmt, bytes)
Convert the specified number of bytes to pixels.
Definition surface.h:91
A surface buffer for graphics.
Definition surface.h:140