8#ifndef LIBDRAGON_RDPQ_RECT_H
9#define LIBDRAGON_RDPQ_RECT_H
20#define __UNLIKELY(x) __builtin_expect(!!(x), 0)
22__attribute__((always_inline))
23inline void __rdpq_fill_rectangle_inline(int32_t x0, int32_t y0, int32_t x1, int32_t y1) {
24 if (__UNLIKELY(x0 < 0)) x0 = 0;
25 if (__UNLIKELY(y0 < 0)) y0 = 0;
26 if (__UNLIKELY(x1 > 0xFFF)) x1 = 0xFFF;
27 if (__UNLIKELY(y1 > 0xFFF)) y1 = 0xFFF;
28 if (__UNLIKELY(x0+3 >= x1 || y0+3 >= y1))
return;
32 _carg(x1, 0xFFF, 12) | _carg(y1, 0xFFF, 0),
33 _carg(x0, 0xFFF, 12) | _carg(y0, 0xFFF, 0));
36__attribute__((always_inline))
37inline void __rdpq_texture_rectangle_inline(
rdpq_tile_t tile,
38 int32_t x0, int32_t y0, int32_t x1, int32_t y1,
39 int32_t s0, int32_t t0)
41 if (__UNLIKELY(x1 == x0 || y1 == y0))
return;
42 int32_t dsdx = 1<<10, dtdy = 1<<10;
44 if (__UNLIKELY(x0 > x1)) {
45 int32_t tmp = x0; x0 = x1; x1 = tmp;
47 s0 += (x1 - x0 - 4) << 3;
50 if (__UNLIKELY(y0 > y1)) {
51 int32_t tmp = y0; y0 = y1; y1 = tmp;
53 t0 += (y1 - y0 - 4) << 3;
56 if (__UNLIKELY(x0 < 0)) {
57 s0 -= (x0 * dsdx) >> 7;
59 if (__UNLIKELY(x0 >= x1))
return;
61 if (__UNLIKELY(y0 < 0)) {
62 t0 -= (y0 * dtdy) >> 7;
64 if (__UNLIKELY(y0 >= y1))
return;
66 if (__UNLIKELY(x1 > 1024*4-1)) {
68 if (__UNLIKELY(x0 >= x1))
return;
70 if (__UNLIKELY(y1 > 1024*4-1)) {
72 if (__UNLIKELY(y0 >= y1))
return;
77 _carg(x1, 0xFFF, 12) | _carg(y1, 0xFFF, 0),
78 _carg(tile, 0x7, 24) | _carg(x0, 0xFFF, 12) | _carg(y0, 0xFFF, 0),
79 _carg(s0, 0xFFFF, 16) | _carg(t0, 0xFFFF, 0),
80 _carg(dsdx, 0xFFFF, 16) | _carg(dtdy, 0xFFFF, 0));
83__attribute__((always_inline))
84inline void __rdpq_texture_rectangle_scaled_inline(
rdpq_tile_t tile,
85 int32_t x0, int32_t y0, int32_t x1, int32_t y1,
86 int32_t s0, int32_t t0, int32_t s1, int32_t t1)
88 if (__UNLIKELY(x1 == x0 || y1 == y0))
return;
89 int32_t dsdx = ((s1 - s0) << 7) / (x1 - x0), dtdy = ((t1 - t0) << 7) / (y1 - y0);
91 if (__UNLIKELY(x0 > x1)) {
92 int32_t tmp = x0; x0 = x1; x1 = tmp;
93 s0 += ((x0 - x1 - 4) * dsdx) >> 7;
95 if (__UNLIKELY(y0 > y1)) {
96 int32_t tmp = y0; y0 = y1; y1 = tmp;
97 t0 += ((y0 - y1 - 4) * dtdy) >> 7;
99 if (__UNLIKELY(x0 < 0)) {
100 s0 -= (x0 * dsdx) >> 7;
102 if (__UNLIKELY(x0 >= x1))
return;
104 if (__UNLIKELY(y0 < 0)) {
105 t0 -= (y0 * dtdy) >> 7;
107 if (__UNLIKELY(y0 >= y1))
return;
109 if (__UNLIKELY(x1 > 1024*4-1)) {
110 s1 -= ((x1 - 1024*4-1) * dsdx) >> 7;
112 if (__UNLIKELY(x0 >= x1))
return;
114 if (__UNLIKELY(y1 > 1024*4-1)) {
115 t1 -= ((y1 - 1024*4-1) * dtdy) >> 7;
117 if (__UNLIKELY(y0 >= y1))
return;
122 _carg(x1, 0xFFF, 12) | _carg(y1, 0xFFF, 0),
123 _carg(tile, 0x7, 24) | _carg(x0, 0xFFF, 12) | _carg(y0, 0xFFF, 0),
124 _carg(s0, 0xFFFF, 16) | _carg(t0, 0xFFFF, 0),
125 _carg(dsdx, 0xFFFF, 16) | _carg(dtdy, 0xFFFF, 0));
128inline void __rdpq_fill_rectangle_fx(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
130 if (__builtin_constant_p(x0) && __builtin_constant_p(y0) && __builtin_constant_p(x1) && __builtin_constant_p(y1)) {
131 __rdpq_fill_rectangle_inline(x0, y0, x1, y1);
138inline void __rdpq_texture_rectangle_fx(
rdpq_tile_t tile, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t s, int32_t t)
140 if (__builtin_constant_p(x0) && __builtin_constant_p(y0) && __builtin_constant_p(x1) && __builtin_constant_p(y1)) {
141 __rdpq_texture_rectangle_inline(tile, x0, y0, x1, y1, s, t);
148inline void __rdpq_texture_rectangle_scaled_fx(
rdpq_tile_t tile, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t s0, int32_t t0, int32_t s1, int32_t t1)
150 if (__builtin_constant_p(x0) && __builtin_constant_p(y0) && __builtin_constant_p(x1) && __builtin_constant_p(y1)) {
151 __rdpq_texture_rectangle_scaled_inline(tile, x0, y0, x1, y1, s0, t0, s1, t1);
158inline void __rdpq_texture_rectangle_raw_fx(
rdpq_tile_t tile, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t s0, uint16_t t0, int16_t dsdx, int16_t dtdy)
162 _carg(x1, 0xFFF, 12) | _carg(y1, 0xFFF, 0),
163 _carg(tile, 0x7, 24) | _carg(x0, 0xFFF, 12) | _carg(y0, 0xFFF, 0),
164 _carg(s0, 0xFFFF, 16) | _carg(t0, 0xFFFF, 0),
165 _carg(dsdx, 0xFFFF, 16) | _carg(dtdy, 0xFFFF, 0));
168inline void __rdpq_texture_rectangle_flip_raw_fx(
rdpq_tile_t tile, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t s, int16_t t, int16_t dsdy, int16_t dtdx)
176 _carg(x1, 0xFFF, 12) | _carg(y1, 0xFFF, 0),
177 _carg(tile, 0x7, 24) | _carg(x0, 0xFFF, 12) | _carg(y0, 0xFFF, 0),
178 _carg(s, 0xFFFF, 16) | _carg(t, 0xFFFF, 0),
179 _carg(dsdy, 0xFFFF, 16) | _carg(dtdx, 0xFFFF, 0),
180 AUTOSYNC_PIPE | AUTOSYNC_TILE(tile) | AUTOSYNC_TMEM(0));
250#define rdpq_fill_rectangle(x0, y0, x1, y1) ({ \
251 __rdpq_fill_rectangle_fx((x0)*4, (y0)*4, (x1)*4, (y1)*4); \
309#define rdpq_texture_rectangle(tile, x0, y0, x1, y1, s, t) \
310 __rdpq_texture_rectangle_fx((tile), (x0)*4, (y0)*4, (x1)*4, (y1)*4, (s)*32, (t)*32)
333#define rdpq_texture_rectangle_scaled(tile, x0, y0, x1, y1, s0, t0, s1, t1) \
334 __rdpq_texture_rectangle_scaled_fx((tile), (x0)*4, (y0)*4, (x1)*4, (y1)*4, (s0)*32, (t0)*32, (s1)*32, (t1)*32)
377#define rdpq_texture_rectangle_raw(tile, x0, y0, x1, y1, s0, t0, dsdx, dtdy) \
378 __rdpq_texture_rectangle_raw_fx(tile, (x0)*4, (y0)*4, (x1)*4, (y1)*4, (s0)*32, (t0)*32, (dsdx)*1024, (dtdy)*1024)
406#define rdpq_texture_rectangle_flip_raw(tile, x0, y0, x1, y1, s, t, dsdy, dtdx) ({ \
407 __rdpq_texture_rectangle_flip_raw_fx((tile), (x0)*4, (y0)*4, (x1)*4, (y1)*4, (s)*32, (t)*32, (dsdy)*1024, (dtdx)*1024); \
void __rdpq_write16_syncuse(uint32_t cmd_id, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t autosync)
Write a standard 16-byte RDP command, which uses some autosync resources
Definition rdpq.c:944
rdpq_tile_t
Tile descriptors.
Definition rdpq.h:250
void __rdpq_fill_rectangle(uint32_t w0, uint32_t w1)
Out-of-line implementation of rdpq_texture_rectangle.
Definition rdpq_rect.c:23
void __rdpq_texture_rectangle_offline(rdpq_tile_t tile, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t s0, int32_t t0)
Out of line implementation of rdpq_texture_rectangle.
Definition rdpq_rect.c:62
void __rdpq_texture_rectangle_scaled_offline(rdpq_tile_t tile, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t s0, int32_t t0, int32_t s1, int32_t t1)
Out of line implementation of rdpq_texture_rectangle_scaled.
Definition rdpq_rect.c:67
void __rdpq_texture_rectangle(uint32_t w0, uint32_t w1, uint32_t w2, uint32_t w3)
Out-of-line implementation of rdpq_texture_rectangle.
Definition rdpq_rect.c:43
void __rdpq_fill_rectangle_offline(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
Out of line implementation of rdpq_fill_rectangle.
Definition rdpq_rect.c:37