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