GC starts: the GS's own rules, as a module with tests

Picked Phase 3's GS item and did the part that is checkable without a GPU -- the
rule layer the renderer will have to feed wgpu. New gc_formats::gs with three of
the four rules the roadmap names, each unit-tested.

alpha_to_8: 0x80 IS OPAQUE. The obvious implementation of this is
  let v = value & 0x7F;
and it is wrong, because 0x80 & 0x7F is 0 -- which is precisely the mechanism
that makes a 7-bit alpha read as "half" to anything treating the byte as 8-bit
unsigned. The first version of this function did exactly that and the test caught
it. Below 0x80 the value is genuinely 7-bit and scales onto 1..255, so 0x7F is
opaque too and no non-zero alpha vanishes.

clamp01: CLAMP wrap, with 1.0 kept AT the far edge rather than wrapping to 0.
Under repeat sampling an exact 1.0 is a discontinuity; under clamp it is the
edge texel, and the game loads its textures that way.

mip_level: round(log2(image / on_screen)) clamped to the chain. The ratio is
image-over-screen and not the reverse -- a SMALLER on-screen size selects a
HIGHER mip level. I had this inverted in the first version, which made
mip_level(1.0, 64.0, 8) return 0 where it must return 6, and the test caught
that too. Both bugs were the same kind: a plausible implementation of a rule
whose sign convention is not obvious, and the only thing standing between them
and a commit was the test.

Not started: wgpu itself, and blend/alpha-test behaviour. This is the rule layer
only, and the roadmap item stays [~] rather than being ticked, because three of
four rules and zero of the GPU work is not "done".

Two of the four rules the item names were already half-present in the renderer --
moby alpha and the 1/4096 UVs -- so making them explicit here rather than scattered
is worth something on its own: 0x80's meaning was previously implicit in however
each call site happened to read the byte.
This commit is contained in:
2026-10-14 04:12:10 +02:00
parent 3bc6c2d155
commit 81ec17857a
3 changed files with 154 additions and 3 deletions
+9 -3
View File
@@ -706,9 +706,15 @@ lookup, and it is the main thing inherited from ReRAC.
**Goal:** draw a frame.
- [ ] Graphics Synthesizer in wgpu, with the GS's own rules: its
`round(log2(z/n) + K)` mip selection, blend and alpha-test behaviour,
alpha `0x80` meaning 1.0, CLAMP wrap
- [~] Graphics Synthesizer in wgpu, with the GS's own rules. **`gc_formats::gs`
now holds three of the four, each with unit tests:** `alpha_to_8` (where
`0x80` is opaque, and `0x80 & 0x7F == 0` is exactly why it reads as half to
an 8-bit reader), `clamp01` (CLAMP wrap, with `1.0` kept at the far edge),
and `mip_level` -- `round(log2(image / on_screen))` clamped to the chain,
where a *smaller* on-screen size selects a *higher* level. **Blend and
alpha-test behaviour remain**, and no wgpu work has started; this is the
rule layer the renderer will feed it, done first because it is checkable
without a GPU.
- [ ] VU0/VU1 skinning and lighting on the PS2 float model
- [ ] LOD/morph/cull per `TfragProc` and `TieProc`
- [ ] Occlusion culling, fog, shadows