Nugget
Loading...
Searching...
No Matches
affine-quads.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// Phase-17 affine UV-mapping quad suite. Five 4-vertex flat-textured
28// quads spanning the parameter space:
29//
30// Q1 axis-aligned 1:1 baseline
31// Q2 90 degree UV rotation
32// Q3 trapezoid (non-parallelogram, top-width != bottom-width)
33// Q4 skewed non-parallelogram (every edge non-axis-aligned)
34// Q5 compressed UV on large quad
35//
36// These tests primarily validate that the 4-vert path produces
37// hardware-matching output across non-trivial geometries. Hardware
38// decomposes a quad into two triangles natively; if the 4-vert sweep
39// diverges from a (1,3,2)+(0,1,2) decomposition output in ways
40// hardware doesn't, that's evidence to retire the 4-vert sweep
41// entirely. Q4 in particular probes the diagonal-seam class where
42// phase-8's QFD finding showed a single seam-gap pixel.
43
45
46// ---- Q1 AQ_AXIS_BASE -----------------------------------------------------
47// v0=(5,5)/(0,0) v1=(20,5)/(15,0) v2=(5,15)/(0,10) v3=(20,15)/(15,10)
48// Axis-aligned 1:1. Baseline correctness.
49
50static void drawAQ_AXIS_BASE(void) {
51 rasterReset();
52 rasterClearTestRegion(0, 0, 24, 16);
53 setTexpage(TEX17_TX, TEX17_TY, 2);
54 setTextureWindow(0, 0, 0, 0);
55 rasterFlatTexQuad(TEX_MOD_NEUTRAL,
56 5, 5, 0, 0,
57 20, 5, 15, 0,
58 5, 15, 0, 10,
59 20, 15, 15, 10,
61 rasterFlushPrimitive();
62}
63
64// ---- Q2 AQ_TWIST_90 ------------------------------------------------------
65// v0=(5,5)/(0,0) v1=(20,5)/(0,15) v2=(5,18)/(13,0) v3=(20,18)/(13,15)
66// 90 degree UV rotation. dU/dX = 0 along v0-v1, dU/dY = 1 along v0-v2.
67// Decomposition's per-triangle UV interpolation has to match at the
68// (v1, v2) diagonal seam.
69
70static void drawAQ_TWIST_90(void) {
71 rasterReset();
72 rasterClearTestRegion(0, 0, 24, 20);
73 setTexpage(TEX17_TX, TEX17_TY, 2);
74 setTextureWindow(0, 0, 0, 0);
75 rasterFlatTexQuad(TEX_MOD_NEUTRAL,
76 5, 5, 0, 0,
77 20, 5, 0, 15,
78 5, 18, 13, 0,
79 20, 18, 13, 15,
81 rasterFlushPrimitive();
82}
83
84// ---- Q3 AQ_TRAPEZOID -----------------------------------------------------
85// v0=(8,5)/(0,0) v1=(20,5)/(15,0) v2=(5,18)/(0,13) v3=(23,18)/(15,13)
86// Top edge 12 wide, bottom 18 wide. Per-row pixel-count varies linearly.
87// Stresses both decomposed triangles having different X spans per row.
88
89static void drawAQ_TRAPEZOID(void) {
90 rasterReset();
91 rasterClearTestRegion(0, 0, 32, 20);
92 setTexpage(TEX17_TX, TEX17_TY, 2);
93 setTextureWindow(0, 0, 0, 0);
94 rasterFlatTexQuad(TEX_MOD_NEUTRAL,
95 8, 5, 0, 0,
96 20, 5, 15, 0,
97 5, 18, 0, 13,
98 23, 18, 15, 13,
100 rasterFlushPrimitive();
101}
102
103// ---- Q4 AQ_SKEW_NP -------------------------------------------------------
104// v0=(5,5)/(0,0) v1=(20,8)/(12,0) v2=(8,22)/(0,12) v3=(25,18)/(12,12)
105// Every edge non-axis-aligned. Diagonal seam between (v1, v2) bisects
106// interior. Phase-8 QFD found one seam-gap pixel on a parallelogram;
107// arbitrary skew may surface more.
108
109static void drawAQ_SKEW_NP(void) {
110 rasterReset();
111 rasterClearTestRegion(0, 0, 32, 24);
112 setTexpage(TEX17_TX, TEX17_TY, 2);
113 setTextureWindow(0, 0, 0, 0);
114 rasterFlatTexQuad(TEX_MOD_NEUTRAL,
115 5, 5, 0, 0,
116 20, 8, 12, 0,
117 8, 22, 0, 12,
118 25, 18, 12, 12,
120 rasterFlushPrimitive();
121}
122
123// ---- Q5 AQ_COMPRESS_UV ---------------------------------------------------
124// v0=(5,5)/(0,0) v1=(30,5)/(8,0) v2=(5,22)/(0,5) v3=(30,22)/(8,5)
125// 25x17 screen -> 8x5 UV. Texture stretched. Fractional UV step
126// across decomposition seam.
127
128static void drawAQ_COMPRESS_UV(void) {
129 rasterReset();
130 rasterClearTestRegion(0, 0, 32, 24);
131 setTexpage(TEX17_TX, TEX17_TY, 2);
132 setTextureWindow(0, 0, 0, 0);
133 rasterFlatTexQuad(TEX_MOD_NEUTRAL,
134 5, 5, 0, 0,
135 30, 5, 8, 0,
136 5, 22, 0, 5,
137 30, 22, 8, 5,
139 rasterFlushPrimitive();
140}
141
142) // CESTER_BODY
143
144// --------------------------------------------------------------------------
145// Q1 AQ_AXIS_BASE assertions
146// --------------------------------------------------------------------------
147
148CESTER_TEST(aq_axis_base_8_8, gpu_raster_phase17,
149 drawAQ_AXIS_BASE();
151)
152
153CESTER_TEST(aq_axis_base_15_10, gpu_raster_phase17,
154 drawAQ_AXIS_BASE();
156)
157
158CESTER_TEST(aq_axis_base_5_14, gpu_raster_phase17,
159 drawAQ_AXIS_BASE();
161)
162
163CESTER_TEST(aq_axis_base_20_5_v1_excluded, gpu_raster_phase17,
164 drawAQ_AXIS_BASE();
166)
167
168// --------------------------------------------------------------------------
169// Q2 AQ_TWIST_90 assertions
170// --------------------------------------------------------------------------
171
172CESTER_TEST(aq_twist_90_8_10, gpu_raster_phase17,
173 drawAQ_TWIST_90();
175)
176
177CESTER_TEST(aq_twist_90_15_13, gpu_raster_phase17,
178 drawAQ_TWIST_90();
180)
181
182CESTER_TEST(aq_twist_90_12_8_near_seam, gpu_raster_phase17,
183 drawAQ_TWIST_90();
185)
186
187CESTER_TEST(aq_twist_90_12_11_near_seam, gpu_raster_phase17,
188 drawAQ_TWIST_90();
190)
191
192// --------------------------------------------------------------------------
193// Q3 AQ_TRAPEZOID assertions
194// --------------------------------------------------------------------------
195
196CESTER_TEST(aq_trapezoid_12_8, gpu_raster_phase17,
197 drawAQ_TRAPEZOID();
199)
200
201CESTER_TEST(aq_trapezoid_14_13, gpu_raster_phase17,
202 drawAQ_TRAPEZOID();
204)
205
206CESTER_TEST(aq_trapezoid_8_15, gpu_raster_phase17,
207 drawAQ_TRAPEZOID();
209)
210
211CESTER_TEST(aq_trapezoid_20_15, gpu_raster_phase17,
212 drawAQ_TRAPEZOID();
214)
215
216// --------------------------------------------------------------------------
217// Q4 AQ_SKEW_NP assertions
218// --------------------------------------------------------------------------
219
220CESTER_TEST(aq_skew_np_12_10, gpu_raster_phase17,
221 drawAQ_SKEW_NP();
223)
224
225CESTER_TEST(aq_skew_np_15_14, gpu_raster_phase17,
226 drawAQ_SKEW_NP();
228)
229
230CESTER_TEST(aq_skew_np_10_15, gpu_raster_phase17,
231 drawAQ_SKEW_NP();
233)
234
235CESTER_TEST(aq_skew_np_18_12_seam, gpu_raster_phase17,
236 drawAQ_SKEW_NP();
238)
239
240// --------------------------------------------------------------------------
241// Q5 AQ_COMPRESS_UV assertions
242// --------------------------------------------------------------------------
243
244CESTER_TEST(aq_compress_uv_10_8, gpu_raster_phase17,
245 drawAQ_COMPRESS_UV();
247)
248
249CESTER_TEST(aq_compress_uv_20_15, gpu_raster_phase17,
250 drawAQ_COMPRESS_UV();
252)
253
254CESTER_TEST(aq_compress_uv_15_10, gpu_raster_phase17,
255 drawAQ_COMPRESS_UV();
257)
258
259CESTER_TEST(aq_compress_uv_29_21, gpu_raster_phase17,
260 drawAQ_COMPRESS_UV();
262)
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 EXPECT_AQ_SKEW_NP_10_15
Definition raster-expected-phase17.h:211
#define EXPECT_AQ_COMPRESS_UV_20_15
Definition raster-expected-phase17.h:220
#define EXPECT_AQ_AXIS_BASE_20_5
Definition raster-expected-phase17.h:182
#define EXPECT_AQ_TWIST_90_15_13
Definition raster-expected-phase17.h:190
#define EXPECT_AQ_TWIST_90_8_10
Definition raster-expected-phase17.h:189
#define EXPECT_AQ_TRAPEZOID_14_13
Definition raster-expected-phase17.h:200
#define EXPECT_AQ_SKEW_NP_15_14
Definition raster-expected-phase17.h:210
#define EXPECT_AQ_TRAPEZOID_12_8
Definition raster-expected-phase17.h:199
#define EXPECT_AQ_TRAPEZOID_8_15
Definition raster-expected-phase17.h:201
#define EXPECT_AQ_TWIST_90_12_11
Definition raster-expected-phase17.h:192
#define EXPECT_AQ_AXIS_BASE_15_10
Definition raster-expected-phase17.h:180
#define EXPECT_AQ_COMPRESS_UV_10_8
Definition raster-expected-phase17.h:219
#define EXPECT_AQ_TWIST_90_12_8
Definition raster-expected-phase17.h:191
#define EXPECT_AQ_COMPRESS_UV_29_21
Definition raster-expected-phase17.h:222
#define EXPECT_AQ_COMPRESS_UV_15_10
Definition raster-expected-phase17.h:221
#define EXPECT_AQ_AXIS_BASE_5_14
Definition raster-expected-phase17.h:181
#define EXPECT_AQ_SKEW_NP_18_12
Definition raster-expected-phase17.h:212
#define EXPECT_AQ_TRAPEZOID_20_15
Definition raster-expected-phase17.h:202
#define EXPECT_AQ_AXIS_BASE_8_8
Definition raster-expected-phase17.h:179
#define EXPECT_AQ_SKEW_NP_12_10
Definition raster-expected-phase17.h:209
#define TEX17_TY
Definition texture-fixture-phase17.h:58
#define TEX17_TPAGE
Definition texture-fixture-phase17.h:65
#define TEX17_TX
Definition texture-fixture-phase17.h:57
#define PHASE17_ASSERT_PIXEL_EQ(expected, x_, y_)
Definition texture-fixture-phase17.h:102
#define TEX17_CLUT_FIELD
Definition texture-fixture-phase17.h:66
#define TEX_MOD_NEUTRAL
Definition texture-fixtures.h:328