Nugget
Loading...
Searching...
No Matches
gte-depthcue.c
Go to the documentation of this file.
1// Depth cue instructions: DPCS, DPCT, DCPL, INTPL
2
3// DPCS: depth cue single - interpolates RGBC toward far color using IR0
5 gte_set_far_color(0x1000, 0x1000, 0x1000); // FC = (4096, 4096, 4096)
6 cop2_put(6, 0x00808080); // RGBC: R=0x80, G=0x80, B=0x80
7 cop2_put(8, 0x0800); // IR0 = 0.5
9 cop2_cmd(COP2_DPCS(1, 0));
10 int32_t mac1, mac2, mac3;
12 cop2_get(25, mac1);
13 cop2_get(26, mac2);
14 cop2_get(27, mac3);
15 cop2_get(22, rgb2);
16 ramsyscall_printf("DPCS: MAC=(%d,%d,%d) RGB2=0x%08x\n", mac1, mac2, mac3, rgb2);
20 cester_assert_uint_eq(0x00c0c0c0, rgb2);
21 // Formula: MAC = R<<16 + IR0*(FC<<12 - R<<16) >> shift
22 // R<<16 = 0x80<<16 = 0x800000
23 // FC<<12 = 0x1000<<12 = 0x1000000
24 // diff = 0x1000000 - 0x800000 = 0x800000
25 // IR0 * diff = 0x800 * 0x800000 ... this is large
26)
27
28// DPCS with IR0=0: no interpolation, output = input color
29CESTER_TEST(dpcs_ir0_zero, gte_tests,
30 gte_set_far_color(0xff00, 0xff00, 0xff00);
31 cop2_put(6, 0x00406080); // R=0x80, G=0x60, B=0x40
32 cop2_put(8, 0); // IR0 = 0
37 uint8_t r = rgb2 & 0xff;
38 uint8_t g = (rgb2 >> 8) & 0xff;
39 uint8_t b = (rgb2 >> 16) & 0xff;
40 // With IR0=0, interpolation weight is 0, so output = input
44)
45
46// DPCS with IR0=0x1000: full interpolation toward far color
47CESTER_TEST(dpcs_ir0_max, gte_tests,
48 gte_set_far_color(0x1000, 0x800, 0x400); // FC scaled
49 cop2_put(6, 0x00000000); // RGBC: all zero
50 cop2_put(8, 0x1000); // IR0 = 1.0
52 cop2_cmd(COP2_DPCS(1, 0));
53 int32_t mac1, mac2, mac3;
54 cop2_get(25, mac1);
55 cop2_get(26, mac2);
56 cop2_get(27, mac3);
57 ramsyscall_printf("DPCS max: MAC=(%d,%d,%d)\n", mac1, mac2, mac3);
61 // With R=0, MAC = 0 + IR0 * (FC<<12 - 0) = 1.0 * FC<<12 >> 12 = FC
62)
63
64// DPCS color FIFO push and CODE preservation
65CESTER_TEST(dpcs_code_preserved, gte_tests,
67 cop2_put(6, 0xab102030); // CODE=0xAB, R=0x30, G=0x20, B=0x10
68 cop2_put(8, 0);
70 cop2_cmd(COP2_DPCS(1, 0));
72 cop2_get(22, rgb2);
73 cester_assert_uint_eq(0xab, (rgb2 >> 24) & 0xff); // CODE preserved
74)
75
76// DPCT: depth cue triple - reads from color FIFO front (RGB0), not RGBC
77CESTER_TEST(dpct_reads_fifo, gte_tests,
78 gte_set_far_color(0, 0, 0);
79 // Set up color FIFO with known values
80 cop2_put(20, 0x00102030); // RGB0: R=0x30, G=0x20, B=0x10
81 cop2_put(21, 0x00405060); // RGB1
82 cop2_put(22, 0x00708090); // RGB2
83 cop2_put(6, 0xff000000); // RGBC: CODE=0xff, colors=0 (should NOT be used as input)
84 cop2_put(8, 0); // IR0=0: output = input
86 cop2_cmd(COP2_DPCT(1, 0));
87 // After 3 iterations, the FIFO has been processed
89 cop2_get(20, rgb0);
90 cop2_get(21, rgb1);
91 cop2_get(22, rgb2);
92 ramsyscall_printf("DPCT: RGB0=0x%08x RGB1=0x%08x RGB2=0x%08x\n", rgb0, rgb1, rgb2);
93 // Each iteration: reads R0/G0/B0 (front of FIFO), pushes result
94 // With IR0=0, each iteration's output = its input color
95 // Iteration 1: reads RGB0(0x102030), pushes -> FIFO shifts
96 // Iteration 2: reads new RGB0 (was RGB1: 0x405060), pushes
97 // Iteration 3: reads new RGB0 (was RGB2: 0x708090), pushes
98 // Result FIFO should contain the 3 processed colors
99 // CODE comes from RGBC (0xff)
100 cester_assert_uint_eq(0xff102030, rgb0);
101 cester_assert_uint_eq(0xff405060, rgb1);
102 cester_assert_uint_eq(0xff708090, rgb2);
103)
104
105// DCPL: depth cue with pre-computed light
106CESTER_TEST(dcpl_basic, gte_tests,
107 gte_set_far_color(0x1000, 0x1000, 0x1000);
108 cop2_put(6, 0x00808080); // RGBC
109 // Pre-computed light in IR1-3
110 cop2_put(9, 0x1000); // IR1 = 1.0
111 cop2_put(10, 0x0800); // IR2 = 0.5
112 cop2_put(11, 0x0400); // IR3 = 0.25
113 cop2_put(8, 0); // IR0 = 0 (no depth cue)
116 int32_t mac1, mac2, mac3;
121 cop2_get(22, rgb2);
122 ramsyscall_printf("DCPL: MAC=(%d,%d,%d) RGB2=0x%08x\n", mac1, mac2, mac3, rgb2);
127 // With IR0=0: MAC = (R<<4)*IR, no depth cue interpolation
128 // MAC1 = (0x80 << 4) * 0x1000 = 0x800 * 0x1000 = 0x800000
129 // After >>12: 0x800 = 2048 -> IR1, /16 = 128 -> R2
130)
131
132// DCPL with depth cue interpolation
133CESTER_TEST(dcpl_with_depth, gte_tests,
134 gte_set_far_color(0x1000, 0x1000, 0x1000);
135 cop2_put(6, 0x00808080);
136 cop2_put(9, 0x1000);
137 cop2_put(10, 0x1000);
138 cop2_put(11, 0x1000);
139 cop2_put(8, 0x0800); // IR0 = 0.5
141 cop2_cmd(COP2_DCPL(1, 0));
142 int32_t mac1, mac2, mac3;
144 cop2_get(25, mac1);
145 cop2_get(26, mac2);
146 cop2_get(27, mac3);
147 flag = gte_read_flag();
148 ramsyscall_printf("DCPL depth: MAC=(%d,%d,%d) FLAG=0x%08x\n", mac1, mac2, mac3, flag);
152 cester_assert_uint_eq(0x00000000, flag);
153)
154
155// INTPL: interpolation (depth cue on IR vector directly)
156CESTER_TEST(intpl_basic, gte_tests,
157 gte_set_far_color(0x1000, 0x2000, 0x3000);
158 cop2_put(9, 0x100); // IR1
159 cop2_put(10, 0x200); // IR2
160 cop2_put(11, 0x300); // IR3
161 cop2_put(8, 0); // IR0 = 0: no interpolation
164 int32_t mac1, mac2, mac3;
165 cop2_get(25, mac1);
166 cop2_get(26, mac2);
167 cop2_get(27, mac3);
168 // With IR0=0: MAC = IR << 12 >> shift = IR (with sf=1)
172)
173
175 gte_set_far_color(0x1000, 0x1000, 0x1000);
176 cop2_put(9, 0);
177 cop2_put(10, 0);
178 cop2_put(11, 0);
179 cop2_put(8, 0x0800); // IR0 = 0.5
181 cop2_cmd(COP2_INTPL(1, 0));
182 int32_t mac1, mac2, mac3;
183 cop2_get(25, mac1);
184 cop2_get(26, mac2);
185 cop2_get(27, mac3);
186 ramsyscall_printf("INTPL half: MAC=(%d,%d,%d)\n", mac1, mac2, mac3);
190 // IR=0, FC=0x1000, IR0=0.5
191 // MAC = 0 + 0.5*(FC - 0) = 0.5 * 0x1000 = 0x800
192)
193
194// INTPL pushes color FIFO
195CESTER_TEST(intpl_color_push, gte_tests,
196 gte_set_far_color(0, 0, 0);
197 cop2_put(9, 0x0ff0); // MAC1=0x0ff0, /16 = 255
198 cop2_put(10, 0x0800); // MAC2=0x0800, /16 = 128
199 cop2_put(11, 0x0010); // MAC3=0x0010, /16 = 1
200 cop2_put(8, 0);
201 cop2_put(6, 0xcc000000); // CODE=0xCC
203 cop2_cmd(COP2_INTPL(1, 0));
205 cop2_get(22, rgb2);
206 uint8_t cd = (rgb2 >> 24) & 0xff;
207 uint8_t r = rgb2 & 0xff;
208 uint8_t g = (rgb2 >> 8) & 0xff;
209 uint8_t b = (rgb2 >> 16) & 0xff;
210 ramsyscall_printf("INTPL color: R=%u G=%u B=%u CD=0x%02x raw=0x%08x\n", r, g, b, cd, rgb2);
215)
#define COP2_INTPL(sf, lm)
Definition cop2.h:142
#define cop2_cmd(op)
Definition cop2.h:175
#define COP2_DPCT(sf, lm)
Definition cop2.h:140
#define cop2_put(reg, val)
Definition cop2.h:182
#define COP2_DPCS(sf, lm)
Definition cop2.h:139
#define cop2_get(reg, dest)
Definition cop2.h:189
#define COP2_DCPL(sf, lm)
Definition cop2.h:141
int32_t mac1
Definition gte-depthcue.c:116
uint8_t g
Definition gte-depthcue.c:38
uint8_t r
Definition gte-depthcue.c:37
gte_set_far_color(0xff00, 0xff00, 0xff00)
gte_tests
Definition gte-depthcue.c:29
cester_assert_uint_eq(0x80, r)
uint8_t cd
Definition gte-depthcue.c:206
uint8_t b
Definition gte-depthcue.c:39
int32_t mac2
Definition gte-depthcue.c:116
gte_clear_flag()
CESTER_TEST(dpcs_basic, gte_tests, gte_set_far_color(0x1000, 0x1000, 0x1000);cop2_put(6, 0x00808080);cop2_put(8, 0x0800);gte_clear_flag();cop2_cmd(COP2_DPCS(1, 0));int32_t mac1, mac2, mac3;uint32_t rgb2;cop2_get(25, mac1);cop2_get(26, mac2);cop2_get(27, mac3);cop2_get(22, rgb2);ramsyscall_printf("DPCS: MAC=(%d,%d,%d) RGB2=0x%08x\n", mac1, mac2, mac3, rgb2);cester_assert_int_eq(3072, mac1);cester_assert_int_eq(3072, mac2);cester_assert_int_eq(3072, mac3);cester_assert_uint_eq(0x00c0c0c0, rgb2);) CESTER_TEST(dpcs_ir0_zero
int32_t mac3
Definition gte-depthcue.c:116
cester_assert_int_eq(2048, mac1)
uint32_t rgb2
Definition gte-depthcue.c:35
ramsyscall_printf("DCPL: MAC=(%d,%d,%d) RGB2=0x%08x\n", mac1, mac2, mac3, rgb2)
uint32_t flag
Definition gte-edgecase.c:36
uint32_t rgb1
Definition gte-lighting.c:205
uint32_t rgb0
Definition gte-lighting.c:205
void uint32_t(classId, spec)