Nugget
Loading...
Searching...
No Matches
texture-window-8-15.c
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27// Texture-window probes at 8-bit (CLUT8) and 15-bit (direct) depths.
28//
29// Same formula as the 4-bit path:
30// filtered_u = (u AND NOT (mask_u * 8)) OR ((offset_u * 8) AND (mask_u * 8))
31//
32// mask_u = 0x01 -> bit 3 of u forced from offset_u
33// mask_u = 0x03 -> bits 3 AND 4 of u forced from offset_u
34// mask_u = 0x07 -> bits 3, 4, 5 of u forced (24 high bits collapse window)
35//
36// The 8-bit fixture spans u=0..63 (64 texels) and 15-bit spans the
37// same range. Mask values up to 0x07 (collapse 24 high bits, leaving
38// 3-bit window) are meaningful at these widths.
39
41
42static void drawTexWindow8Tri(uint8_t mask_x, uint8_t off_x) {
43 rasterReset();
44 rasterClearTestRegion(0, 0, 64, 16);
45 setTexpage(TEX8_TX, TEX8_TY, 1);
46 setTextureWindow(mask_x, 0, off_x, 0);
47 /* Triangle (0,0)-(32,0)-(0,8). UV matches screen so pixel (x,y)
48 wants texel (x, y); window filtering rewrites the U bits. */
49 rasterTexTri(TEX_MOD_NEUTRAL,
50 0, 0, 0, 0,
51 32, 0, 32, 0,
52 0, 8, 0, 8,
54 rasterFlushPrimitive();
55}
56
57static void drawTexWindow15Tri(uint8_t mask_x, uint8_t off_x) {
58 rasterReset();
59 rasterClearTestRegion(0, 0, 32, 16);
60 setTexpage(TEX15_TX, TEX15_TY, 2);
61 setTextureWindow(mask_x, 0, off_x, 0);
62 rasterTexTri(TEX_MOD_NEUTRAL,
63 0, 0, 0, 0,
64 16, 0, 16, 0,
65 0, 8, 0, 8,
67 rasterFlushPrimitive();
68}
69
70// Vertical-window variant: mask_y forces high bits of v from offset_y.
71// Useful for confirming V-axis windowing isn't subtly different from U.
72static void drawTexWindow8TriV(uint8_t mask_y, uint8_t off_y) {
73 rasterReset();
74 rasterClearTestRegion(0, 0, 64, 16);
75 setTexpage(TEX8_TX, TEX8_TY, 1);
76 setTextureWindow(0, mask_y, 0, off_y);
77 rasterTexTri(TEX_MOD_NEUTRAL,
78 0, 0, 0, 0,
79 32, 0, 32, 0,
80 0, 8, 0, 8,
82 rasterFlushPrimitive();
83}
84
85) // CESTER_BODY
86
87// ==========================================================================
88// 8-bit: mask_u=0x01, offset_u=0 -> bit 3 of u cleared
89// u=0..7 -> texel 0..7
90// u=8..15 -> texel 0..7 (bit 3 cleared)
91// u=16..23 -> texel 16..23 (bit 3 of 16=0x10 unchanged; only bit 3
92// collapses 8-aligned 8-blocks)
93// ==========================================================================
94
95CESTER_TEST(texwin8_mask01_off00_u0, gpu_raster_phase9,
96 drawTexWindow8Tri(0x01, 0x00);
97 /* u=0, filtered=0, CLUT8[0]. */
98 ASSERT_PIXEL_EQ(expectedClut8Color(0), 0, 0);
99)
100CESTER_TEST(texwin8_mask01_off00_u7, gpu_raster_phase9,
101 drawTexWindow8Tri(0x01, 0x00);
102 ASSERT_PIXEL_EQ(expectedClut8Color(7), 7, 0);
103)
104CESTER_TEST(texwin8_mask01_off00_u8_wraps_to_0, gpu_raster_phase9,
105 drawTexWindow8Tri(0x01, 0x00);
106 /* u=8, bit 3 cleared -> texel 0. */
107 ASSERT_PIXEL_EQ(expectedClut8Color(0), 8, 0);
108)
109CESTER_TEST(texwin8_mask01_off00_u15_wraps_to_7, gpu_raster_phase9,
110 drawTexWindow8Tri(0x01, 0x00);
111 /* u=15=0x0F, bit 3 cleared -> texel 7. */
112 ASSERT_PIXEL_EQ(expectedClut8Color(7), 15, 0);
113)
114CESTER_TEST(texwin8_mask01_off00_u16, gpu_raster_phase9,
115 drawTexWindow8Tri(0x01, 0x00);
116 /* u=16=0x10, bit 3 already cleared -> texel 16. */
117 ASSERT_PIXEL_EQ(expectedClut8Color(16), 16, 0);
118)
119CESTER_TEST(texwin8_mask01_off00_u24_wraps_to_16, gpu_raster_phase9,
120 drawTexWindow8Tri(0x01, 0x00);
121 /* u=24=0x18, bit 3 cleared -> texel 16. */
122 ASSERT_PIXEL_EQ(expectedClut8Color(16), 24, 0);
123)
124
125// ==========================================================================
126// 8-bit: mask_u=0x01, offset_u=0x01 -> bit 3 of u SET from offset
127// u=0..7 -> texel 8..15
128// u=8..15 -> texel 8..15 (already set)
129// ==========================================================================
130
131CESTER_TEST(texwin8_mask01_off01_u0_forced_to_8, gpu_raster_phase9,
132 drawTexWindow8Tri(0x01, 0x01);
133 ASSERT_PIXEL_EQ(expectedClut8Color(8), 0, 0);
134)
135CESTER_TEST(texwin8_mask01_off01_u3_forced_to_b, gpu_raster_phase9,
136 drawTexWindow8Tri(0x01, 0x01);
137 /* u=3, bit 3 set -> texel 0xB. */
138 ASSERT_PIXEL_EQ(expectedClut8Color(0x0b), 3, 0);
139)
140
141// ==========================================================================
142// 8-bit: mask_u=0x03 (bits 3 and 4) -> collapse 16-texel window
143// offset_u=0: u with bits 3-4 cleared
144// u=0..7 -> 0..7
145// u=8..23 -> texels 0..7 then 0..7 (16-byte wrap)
146// ==========================================================================
147
148CESTER_TEST(texwin8_mask03_off00_u20_wraps_to_4, gpu_raster_phase9,
149 drawTexWindow8Tri(0x03, 0x00);
150 /* u=20=0x14, &~0x18=0x04 -> texel 4. */
151 ASSERT_PIXEL_EQ(expectedClut8Color(4), 20, 0);
152)
153CESTER_TEST(texwin8_mask03_off00_u31_wraps_to_7, gpu_raster_phase9,
154 drawTexWindow8Tri(0x03, 0x00);
155 /* u=31=0x1F, &~0x18=0x07 -> texel 7. */
156 ASSERT_PIXEL_EQ(expectedClut8Color(7), 31, 0);
157)
158
159// ==========================================================================
160// 8-bit: mask_u=0x07 -> collapse 24 high bits, 3-bit u window
161// offset_u=0x03 (set bit 4 and bit 3 from offset_u*8 = 0x18)
162// ==========================================================================
163
164CESTER_TEST(texwin8_mask07_off03_u0_forced_to_18, gpu_raster_phase9,
165 drawTexWindow8Tri(0x07, 0x03);
166 /* u=0, &~0x38 = 0, | 0x18 = 0x18 -> texel 24. */
167 ASSERT_PIXEL_EQ(expectedClut8Color(0x18), 0, 0);
168)
169CESTER_TEST(texwin8_mask07_off03_u5_forced_to_1d, gpu_raster_phase9,
170 drawTexWindow8Tri(0x07, 0x03);
171 /* u=5, &~0x38=5, | 0x18 = 0x1D -> texel 29. */
172 ASSERT_PIXEL_EQ(expectedClut8Color(0x1d), 5, 0);
173)
174
175// ==========================================================================
176// 8-bit V-axis windowing: mask_v=0x01, off_v=0 -> bit 3 of v cleared
177// At y=8, v=8 wraps to v=0. The texture's V dimension carries
178// the row, but our fixture is constant across rows (texel value
179// depends only on u). So V-window wrapping doesn't change the
180// pixel color - it should match the equivalent non-wrapped row.
181// This is a control test: confirms V-window is applied but
182// invisible for U-only fixtures.
183// ==========================================================================
184
185CESTER_TEST(texwin8_maskV01_off00_v0, gpu_raster_phase9,
186 drawTexWindow8TriV(0x01, 0x00);
187 /* y=0, v=0, no wrap. */
188 ASSERT_PIXEL_EQ(expectedClut8Color(0), 0, 0);
189)
190
191// ==========================================================================
192// 15-bit: mask_u=0x01, offset_u=0 -> bit 3 of u cleared
193// Texel value at (u, v) = vram555(u & 0x1f, v & 0x1f, (u+v) & 0x1f).
194// Window-rewritten u changes BOTH the R channel and the (u+v) blue
195// channel, so the read-back pixel is a direct function of filtered_u.
196// ==========================================================================
197
198CESTER_TEST(texwin15_mask01_off00_u0, gpu_raster_phase9,
199 drawTexWindow15Tri(0x01, 0x00);
200 /* (u=0, v=0): vram555(0, 0, 0) = 0. NOTE: this pixel might be
201 excluded by the top-left rule (apex of axis-aligned triangle).
202 If hardware draws it, value is 0x0000; if excluded, sentinel. */
204)
205CESTER_TEST(texwin15_mask01_off00_u7, gpu_raster_phase9,
206 drawTexWindow15Tri(0x01, 0x00);
207 /* (u=7, v=0): vram555(7, 0, 7) = 7 | (7<<10) = 0x1c07. */
209)
210CESTER_TEST(texwin15_mask01_off00_u8_wraps_to_0, gpu_raster_phase9,
211 drawTexWindow15Tri(0x01, 0x00);
212 /* (u=8, filtered=0, v=0): vram555(0, 0, 0) = 0x0000. */
214)
215CESTER_TEST(texwin15_mask01_off00_u15_wraps_to_7, gpu_raster_phase9,
216 drawTexWindow15Tri(0x01, 0x00);
217 /* (u=15, filtered=7, v=0): vram555(7, 0, 7) = 0x1c07. */
219)
220
221// ==========================================================================
222// 15-bit: mask_u=0x01, offset_u=0x01 -> bit 3 forced set
223// u=0..7 -> texel 8..15 -> vram555(8..15, 0, 8..15)
224// ==========================================================================
225
226CESTER_TEST(texwin15_mask01_off01_u0_forced_to_8, gpu_raster_phase9,
227 drawTexWindow15Tri(0x01, 0x01);
228 /* (filtered=8, v=0): vram555(8, 0, 8) = 8 | (8<<10) = 0x2008. */
230)
231CESTER_TEST(texwin15_mask01_off01_u3_forced_to_b, gpu_raster_phase9,
232 drawTexWindow15Tri(0x01, 0x01);
233 /* (filtered=0xB=11, v=0): vram555(11, 0, 11) = 11 | (11<<10) = 0x2c0b. */
235)
236CESTER_TEST(texwin15_mask01_off01_u8_already_set, gpu_raster_phase9,
237 drawTexWindow15Tri(0x01, 0x01);
238 /* (filtered=8, v=0). */
240)
241
242// ==========================================================================
243// 15-bit: mask_u=0x03 (bits 3-4 collapse, 16-texel window)
244// ==========================================================================
245
246CESTER_TEST(texwin15_mask03_off00_u13, gpu_raster_phase9,
247 drawTexWindow15Tri(0x03, 0x00);
248 /* u=13=0xD, &~0x18=0x05 -> texel 5 at v=0 -> vram555(5, 0, 5). */
250)
CESTER_BODY(static int s_got40;static int s_got80;static uint32_t s_cause;static uint32_t s_epc;static uint32_t s_from;static uint32_t *s_resume;static uint32_t *s_regs;static uint32_t(*s_customhandler)()=NULL;static uint32_t s_oldIMASK;static uint32_t s_oldDPCR;static uint32_t s_oldDICR;uint32_t handler(uint32_t *regs, uint32_t from) { if(from==0x40) s_got40=1;if(from==0x80) s_got80=1;uint32_t cause;uint32_t epc;s_from=from;asm("mfc0 %0, $13\nnop\nmfc0 %1, $14\nnop" :"=r"(cause), "=r"(epc));s_cause=cause;s_epc=epc;if(s_customhandler) { return s_customhandler();} else { return s_resume ?((uint32_t) s_resume) :(epc+4);} } void installExceptionHandlers(uint32_t(*handler)(uint32_t *regs, uint32_t from));void uninstallExceptionHandlers();uint32_t branchbranch1();uint32_t branchbranch2();uint32_t jumpjump1();uint32_t jumpjump2();uint32_t cpu_LWR_LWL_half(uint32_t buff[], uint32_t initial);uint32_t cpu_LWR_LWL_nodelay(uint32_t buff[], uint32_t initial);uint32_t cpu_LWR_LWL_delayed(uint32_t buff[], uint32_t initial);uint32_t cpu_LWR_LWL_load_different(uint32_t buff[], uint32_t initial);uint32_t cpu_LW_LWR(uint32_t buff[], uint32_t initial);uint32_t cpu_delayed_load(uint32_t buff[], uint32_t override);uint32_t cpu_delayed_load_cancelled(uint32_t buff[], uint32_t override);uint64_t cpu_delayed_load_load(uint32_t buff[], uint32_t override);uint32_t linkandload();uint32_t lwandlink();uint32_t nolink();static int s_interruptsWereEnabled;) CESTER_BEFORE_EACH(cpu_tests
CESTER_TEST(cpu_cop0_basic_write_bp, cpu_tests, uint32_t expectedEPC;uint32_t t;volatile uint32_t *ptr=(volatile uint32_t *) 0x58; *ptr=1;__asm__ volatile("" " lui %0, 0b1100101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0xfffffff0\n" " mtc0 %0, $9\n" :"=r"(t));cester_assert_uint_eq(1, *ptr);__asm__ volatile("la %0, 1f\n1:\nsw $0, 0x58($0)" :"=r"(expectedEPC));__asm__ volatile("mtc0 $0, $7\n");cester_assert_uint_eq(0, *ptr);cester_assert_uint_eq(1, s_got40);cester_assert_uint_eq(0, s_got80);cester_assert_uint_eq(0x40, s_from);cester_assert_uint_eq(expectedEPC, s_epc);) CESTER_TEST(cpu_cop0_kseg_write_bp
#define TW15_M01_O01_U0_Y0
Definition raster-expected-phase9.h:56
#define TW15_M01_O00_U15_Y0
Definition raster-expected-phase9.h:53
#define TW15_M01_O01_U3_Y0
Definition raster-expected-phase9.h:57
#define TW15_M01_O01_U8_Y0
Definition raster-expected-phase9.h:58
#define TW15_M01_O00_U0_Y0
Definition raster-expected-phase9.h:50
#define TW15_M03_O00_U13_Y0
Definition raster-expected-phase9.h:61
#define TW15_M01_O00_U8_Y0
Definition raster-expected-phase9.h:52
#define TW15_M01_O00_U7_Y0
Definition raster-expected-phase9.h:51
#define ASSERT_PIXEL_EQ(expected, x_, y_)
Definition raster-helpers.h:472
#define CLUT8_FIELD
Definition texture-fixtures.h:84
#define TEX15_TY
Definition texture-fixtures.h:66
#define TEX8_TY
Definition texture-fixtures.h:61
#define TEX15_TPAGE
Definition texture-fixtures.h:104
#define TEX8_TPAGE
Definition texture-fixtures.h:103
#define CLUT15_FIELD
Definition texture-fixtures.h:85
#define TEX15_TX
Definition texture-fixtures.h:65
#define TEX8_TX
Definition texture-fixtures.h:60
#define TEX_MOD_NEUTRAL
Definition texture-fixtures.h:328