Nugget
Loading...
Searching...
No Matches
texture-fixture-phase17.h
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#pragma once
28
29// Phase-17 dedicated 15-bit signature texture for affine UV characterization.
30//
31// Lives in its own texpage cell at (tx=11, ty=0) -> VRAM base (704, 0),
32// disjoint from the phase-4 TEX4/TEX8/TEX15 fixtures. The 32x32 texture
33// encodes texel(u, v) = vram555(u & 31, v & 31, ((u + v) & 31) | 1) so:
34//
35// - Red channel = u (5-bit, unique for u in [0, 32)).
36// - Green channel = v (5-bit, unique for v in [0, 32)).
37// - Blue channel = ((u+v)&31) | 1, always odd, in {1, 3, ..., 31}.
38//
39// Two properties that matter:
40// (a) Every (u, v) in [0, 32)^2 has a unique signature - if you read
41// back a VRAM pixel, you can decode which UV the rasterizer
42// sampled by masking the red and green channels.
43// (b) No texel is 0x0000. Bit 0 of the blue channel is forced set so
44// even (u=0, v=0) renders. PSX hardware treats texel 0x0000 as
45// transparent (canonical rule, verified in phase-4 - see
46// tex15_pixel_0_0_transparent). Forcing bit 0 of blue prevents
47// any probe from accidentally landing on the transparent cell.
48//
49// Why a new cell instead of extending TEX15: keeps phase-4/phase-8
50// fixtures untouched. The TEX15 fixture (phase-4) is 64-wide x 16-tall
51// at (tx=10, ty=0); phase-17 probes need up to v=31 so a fresh cell with
52// the right footprint was simpler than trying to merge.
53
54#include "raster-helpers.h"
55#include "texture-fixtures.h"
56
57#define TEX17_TX 11u
58#define TEX17_TY 0u
59#define TEX17_VRAM_BASE_X (TEX17_TX * 64) /* 704 */
60#define TEX17_VRAM_BASE_Y (TEX17_TY * 256) /* 0 */
61
62#define TEX17_WIDTH 32 /* texels per row */
63#define TEX17_HEIGHT 32 /* rows */
64
65#define TEX17_TPAGE texpageField(TEX17_TX, TEX17_TY, 0, 2)
66#define TEX17_CLUT_FIELD 0u /* 15-bit direct ignores CLUT */
67
68// Encode a texel value for position (u, v). Mirrors uploadTex17's
69// encoding so tests can predict expected sampled-texel values for any
70// (u, v) in [0, 32)^2.
71static inline uint16_t expectedTex17Color(uint8_t u, uint8_t v) {
72 return rasterVram555((uint8_t)(u & 0x1f),
73 (uint8_t)(v & 0x1f),
74 (uint8_t)(((u + v) & 0x1f) | 1));
75}
76
77// Upload the 32x32 signature texture to (TEX17_VRAM_BASE_X,
78// TEX17_VRAM_BASE_Y). 32 pixels per row * 32 rows = 1024 pixels = 512
79// words. Each VRAM pixel IS a 15-bit texel.
80static inline void uploadTex17(void) {
81 waitGPU();
82 GPU_DATA = 0xa0000000u;
83 GPU_DATA = ((uint32_t)(uint16_t)TEX17_VRAM_BASE_Y << 16) |
84 (uint32_t)(uint16_t)TEX17_VRAM_BASE_X;
85 GPU_DATA = ((uint32_t)(uint16_t)TEX17_HEIGHT << 16) |
86 (uint32_t)(uint16_t)TEX17_WIDTH;
87 int wordIdx = 0;
88 for (int v = 0; v < TEX17_HEIGHT; v++) {
89 for (int u = 0; u < TEX17_WIDTH; u += 2) {
90 uint16_t t0 = expectedTex17Color((uint8_t)u, (uint8_t)v);
91 uint16_t t1 = expectedTex17Color((uint8_t)(u + 1), (uint8_t)v);
92 rasterStreamPace(wordIdx++);
93 GPU_DATA = (uint32_t)t0 | ((uint32_t)t1 << 16);
94 }
95 }
96}
97
98// Quiet pixel-equality assertion. Mirrors ASSERT_PIXEL_EQ from
99// raster-helpers.h but does NOT emit the OBS log line - phase-17
100// onward relies on cester's existing FAIL output for hardware-truth
101// capture instead of a parallel printf channel.
102#define PHASE17_ASSERT_PIXEL_EQ(expected, x_, y_) \
103 do { \
104 uint16_t _aval = rasterReadPixel((int16_t)(x_), (int16_t)(y_)); \
105 cester_assert_uint_eq((unsigned)(expected), (unsigned)_aval); \
106 } while (0)
107
108#define PHASE17_ASSERT_PIXEL_UNTOUCHED(x_, y_) \
109 PHASE17_ASSERT_PIXEL_EQ(RASTER_SENTINEL, (x_), (y_))
#define GPU_DATA
Definition hwregs.h:52
void uint32_t(classId, spec)
#define TEX17_VRAM_BASE_X
Definition texture-fixture-phase17.h:59
#define TEX17_WIDTH
Definition texture-fixture-phase17.h:62
#define TEX17_VRAM_BASE_Y
Definition texture-fixture-phase17.h:60
#define TEX17_HEIGHT
Definition texture-fixture-phase17.h:63