Nugget
Loading...
Searching...
No Matches
slanted-gouraud.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// Slanted gouraud color suite. Every triangle here has BOTH the long
28// left edge and the top edge off-axis, so the per-row left-edge color
29// seed lands at a fractional x and the horizontal span delta both carry
30// truncated accumulators. That compounding is precisely what the
31// axis-aligned phase-7 gouraud suite cannot reach, and where a soft
32// renderer can drift by a single LSB on slanted gouraud fills.
33//
34// All probes target interior pixels or a covered (left) vertex; none
35// hit a top-left-excluded bottom/right vertex (those read sentinel).
36// SG_AB reproduces the exact triangle the 24 carried-over silicon
37// pixels were captured from, using full 8-bit 0xFF command colors (see
38// raster-expected-phase22.h).
39
41
42// SG_AB: the libgouraud cross-check triangle. Raw 0xFF command colors to
43// match the captured silicon. v0=(20,20)R v1=(200,60)G v2=(90,230)B.
44static void drawSGAB(void) {
45 rasterReset();
46 rasterClearTestRegion(0, 0, 64, 32);
47 rasterGouraudTri(0x0000ffu, 20, 20,
48 0x00ff00u, 200, 60,
49 0xff0000u, 90, 230);
50 rasterFlushPrimitive();
51}
52
53// SG1: medium slanted RGB triangle, suite idiom (5-bit colors).
54static void drawSG1(void) {
55 rasterReset();
56 rasterClearTestRegion(0, 0, 64, 56);
57 rasterGouraudTri(RASTER_CMD_RED, 8, 4,
58 RASTER_CMD_GREEN, 58, 22,
59 RASTER_CMD_BLUE, 22, 52);
60 rasterFlushPrimitive();
61}
62
63// SG2: flatter slanted RGB triangle, apex-low orientation.
64static void drawSG2(void) {
65 rasterReset();
66 rasterClearTestRegion(0, 0, 72, 56);
67 rasterGouraudTri(RASTER_CMD_RED, 40, 6,
68 RASTER_CMD_GREEN, 70, 48,
69 RASTER_CMD_BLUE, 6, 40);
70 rasterFlushPrimitive();
71}
72
73// SG_R: R-only slanted gradient. Apex R=31, base verts R=0. Isolates a
74// single channel's accumulator on a slanted shape.
75static void drawSGR(void) {
76 rasterReset();
77 rasterClearTestRegion(0, 0, 56, 56);
78 rasterGouraudTri(RASTER_CMD_RED, 6, 6,
79 0u, 54, 18,
80 0u, 18, 50);
81 rasterFlushPrimitive();
82}
83
84// SG3: narrow / steep slanted triangle.
85static void drawSG3(void) {
86 rasterReset();
87 rasterClearTestRegion(0, 0, 48, 56);
88 rasterGouraudTri(RASTER_CMD_RED, 30, 4,
89 RASTER_CMD_GREEN, 40, 50,
90 RASTER_CMD_BLUE, 20, 46);
91 rasterFlushPrimitive();
92}
93
94) // CESTER_BODY
95
96// --------------------------------------------------------------------------
97// SG_AB: 24 silicon cross-check probes
98// --------------------------------------------------------------------------
99
100CESTER_TEST(sg_ab_26_22, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_26_22, 26, 22); )
101CESTER_TEST(sg_ab_24_23, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_24_23, 24, 23); )
102CESTER_TEST(sg_ab_26_23, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_26_23, 26, 23); )
103CESTER_TEST(sg_ab_27_24, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_27_24, 27, 24); )
104CESTER_TEST(sg_ab_30_24, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_30_24, 30, 24); )
105CESTER_TEST(sg_ab_32_24, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_32_24, 32, 24); )
106CESTER_TEST(sg_ab_37_24, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_37_24, 37, 24); )
107CESTER_TEST(sg_ab_27_25, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_27_25, 27, 25); )
108CESTER_TEST(sg_ab_32_25, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_32_25, 32, 25); )
109CESTER_TEST(sg_ab_22_26, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_22_26, 22, 26); )
110CESTER_TEST(sg_ab_27_26, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_27_26, 27, 26); )
111CESTER_TEST(sg_ab_35_26, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_35_26, 35, 26); )
112CESTER_TEST(sg_ab_25_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_25_27, 25, 27); )
113CESTER_TEST(sg_ab_28_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_28_27, 28, 27); )
114CESTER_TEST(sg_ab_33_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_33_27, 33, 27); )
115CESTER_TEST(sg_ab_38_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_38_27, 38, 27); )
116CESTER_TEST(sg_ab_41_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_41_27, 41, 27); )
117CESTER_TEST(sg_ab_43_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_43_27, 43, 27); )
118CESTER_TEST(sg_ab_49_27, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_49_27, 49, 27); )
119CESTER_TEST(sg_ab_28_28, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_28_28, 28, 28); )
120CESTER_TEST(sg_ab_29_28, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_29_28, 29, 28); )
121CESTER_TEST(sg_ab_30_28, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_30_28, 30, 28); )
122CESTER_TEST(sg_ab_33_28, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_33_28, 33, 28); )
123CESTER_TEST(sg_ab_49_28, gpu_raster_phase22, drawSGAB(); ASSERT_PIXEL_EQ(SG_AB_49_28, 49, 28); )
124
125// --------------------------------------------------------------------------
126// SG1: medium slanted RGB triangle (interior probes)
127// --------------------------------------------------------------------------
128
129CESTER_TEST(sg1_29_26, gpu_raster_phase22, drawSG1(); ASSERT_PIXEL_EQ(SG1_29_26, 29, 26); )
130CESTER_TEST(sg1_24_24, gpu_raster_phase22, drawSG1(); ASSERT_PIXEL_EQ(SG1_24_24, 24, 24); )
131CESTER_TEST(sg1_36_28, gpu_raster_phase22, drawSG1(); ASSERT_PIXEL_EQ(SG1_36_28, 36, 28); )
132CESTER_TEST(sg1_20_20, gpu_raster_phase22, drawSG1(); ASSERT_PIXEL_EQ(SG1_20_20, 20, 20); )
133CESTER_TEST(sg1_30_32, gpu_raster_phase22, drawSG1(); ASSERT_PIXEL_EQ(SG1_30_32, 30, 32); )
134CESTER_TEST(sg1_40_24, gpu_raster_phase22, drawSG1(); ASSERT_PIXEL_EQ(SG1_40_24, 40, 24); )
135
136// --------------------------------------------------------------------------
137// SG2: flatter slanted RGB triangle (v2 covered vertex + interior)
138// --------------------------------------------------------------------------
139
140CESTER_TEST(sg2_v2_6_40, gpu_raster_phase22, drawSG2(); ASSERT_PIXEL_EQ(SG2_V2_6_40, 6, 40); )
141CESTER_TEST(sg2_39_31, gpu_raster_phase22, drawSG2(); ASSERT_PIXEL_EQ(SG2_39_31, 39, 31); )
142CESTER_TEST(sg2_30_30, gpu_raster_phase22, drawSG2(); ASSERT_PIXEL_EQ(SG2_30_30, 30, 30); )
143CESTER_TEST(sg2_48_32, gpu_raster_phase22, drawSG2(); ASSERT_PIXEL_EQ(SG2_48_32, 48, 32); )
144CESTER_TEST(sg2_40_20, gpu_raster_phase22, drawSG2(); ASSERT_PIXEL_EQ(SG2_40_20, 40, 20); )
145CESTER_TEST(sg2_20_34, gpu_raster_phase22, drawSG2(); ASSERT_PIXEL_EQ(SG2_20_34, 20, 34); )
146
147// --------------------------------------------------------------------------
148// SG_R: R-only slanted gradient (interior probes)
149// --------------------------------------------------------------------------
150
151CESTER_TEST(sgr_8_8, gpu_raster_phase22, drawSGR(); ASSERT_PIXEL_EQ(SGR_8_8, 8, 8); )
152CESTER_TEST(sgr_26_25, gpu_raster_phase22, drawSGR(); ASSERT_PIXEL_EQ(SGR_26_25, 26, 25); )
153CESTER_TEST(sgr_16_16, gpu_raster_phase22, drawSGR(); ASSERT_PIXEL_EQ(SGR_16_16, 16, 16); )
154CESTER_TEST(sgr_22_28, gpu_raster_phase22, drawSGR(); ASSERT_PIXEL_EQ(SGR_22_28, 22, 28); )
155CESTER_TEST(sgr_31_20, gpu_raster_phase22, drawSGR(); ASSERT_PIXEL_EQ(SGR_31_20, 31, 20); )
156CESTER_TEST(sgr_13_22, gpu_raster_phase22, drawSGR(); ASSERT_PIXEL_EQ(SGR_13_22, 13, 22); )
157
158// --------------------------------------------------------------------------
159// SG3: narrow / steep slanted triangle (v2 covered vertex + interior)
160// --------------------------------------------------------------------------
161
162CESTER_TEST(sg3_v2_20_46, gpu_raster_phase22, drawSG3(); ASSERT_PIXEL_EQ(SG3_V2_20_46, 20, 46); )
163CESTER_TEST(sg3_30_33, gpu_raster_phase22, drawSG3(); ASSERT_PIXEL_EQ(SG3_30_33, 30, 33); )
164CESTER_TEST(sg3_30_22, gpu_raster_phase22, drawSG3(); ASSERT_PIXEL_EQ(SG3_30_22, 30, 22); )
165CESTER_TEST(sg3_31_40, gpu_raster_phase22, drawSG3(); ASSERT_PIXEL_EQ(SG3_31_40, 31, 40); )
166CESTER_TEST(sg3_28_30, gpu_raster_phase22, drawSG3(); ASSERT_PIXEL_EQ(SG3_28_30, 28, 30); )
167CESTER_TEST(sg3_33_38, gpu_raster_phase22, drawSG3(); ASSERT_PIXEL_EQ(SG3_33_38, 33, 38); )
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 SG3_31_40
Definition raster-expected-phase22.h:136
#define SG_AB_33_28
Definition raster-expected-phase22.h:90
#define SG_AB_24_23
Definition raster-expected-phase22.h:69
#define SG_AB_43_27
Definition raster-expected-phase22.h:85
#define SG_AB_28_27
Definition raster-expected-phase22.h:81
#define SG_AB_30_28
Definition raster-expected-phase22.h:89
#define SG1_29_26
Definition raster-expected-phase22.h:97
#define SG2_39_31
Definition raster-expected-phase22.h:110
#define SG2_30_30
Definition raster-expected-phase22.h:111
#define SG_AB_27_25
Definition raster-expected-phase22.h:75
#define SGR_31_20
Definition raster-expected-phase22.h:125
#define SG_AB_28_28
Definition raster-expected-phase22.h:87
#define SGR_13_22
Definition raster-expected-phase22.h:126
#define SG_AB_29_28
Definition raster-expected-phase22.h:88
#define SG2_48_32
Definition raster-expected-phase22.h:112
#define SG_AB_30_24
Definition raster-expected-phase22.h:72
#define SG1_20_20
Definition raster-expected-phase22.h:100
#define SG_AB_38_27
Definition raster-expected-phase22.h:83
#define SG_AB_26_23
Definition raster-expected-phase22.h:70
#define SG_AB_25_27
Definition raster-expected-phase22.h:80
#define SG3_33_38
Definition raster-expected-phase22.h:138
#define SG_AB_27_26
Definition raster-expected-phase22.h:78
#define SG_AB_32_24
Definition raster-expected-phase22.h:73
#define SG_AB_27_24
Definition raster-expected-phase22.h:71
#define SG2_40_20
Definition raster-expected-phase22.h:113
#define SG_AB_32_25
Definition raster-expected-phase22.h:76
#define SG3_30_33
Definition raster-expected-phase22.h:134
#define SG1_24_24
Definition raster-expected-phase22.h:98
#define SG2_20_34
Definition raster-expected-phase22.h:114
#define SG_AB_26_22
Definition raster-expected-phase22.h:68
#define SG1_36_28
Definition raster-expected-phase22.h:99
#define SG_AB_37_24
Definition raster-expected-phase22.h:74
#define SG3_30_22
Definition raster-expected-phase22.h:135
#define SG_AB_49_28
Definition raster-expected-phase22.h:91
#define SG3_V2_20_46
Definition raster-expected-phase22.h:133
#define SG_AB_35_26
Definition raster-expected-phase22.h:79
#define SG_AB_49_27
Definition raster-expected-phase22.h:86
#define SG_AB_22_26
Definition raster-expected-phase22.h:77
#define SGR_8_8
Definition raster-expected-phase22.h:121
#define SG2_V2_6_40
Definition raster-expected-phase22.h:109
#define SGR_16_16
Definition raster-expected-phase22.h:123
#define SG1_40_24
Definition raster-expected-phase22.h:102
#define SG_AB_33_27
Definition raster-expected-phase22.h:82
#define SG3_28_30
Definition raster-expected-phase22.h:137
#define SGR_22_28
Definition raster-expected-phase22.h:124
#define SG1_30_32
Definition raster-expected-phase22.h:101
#define SG_AB_41_27
Definition raster-expected-phase22.h:84
#define SGR_26_25
Definition raster-expected-phase22.h:122
#define RASTER_CMD_BLUE
Definition raster-helpers.h:127
#define RASTER_CMD_RED
Definition raster-helpers.h:123
#define RASTER_CMD_GREEN
Definition raster-helpers.h:125
#define ASSERT_PIXEL_EQ(expected, x_, y_)
Definition raster-helpers.h:472