Every pixel the NV2A writes goes through its register combiners; D3D's
fixed-function stages compile to them too. The executor stood in with
"stage 0 texel * diffuse", which is right for a menu quad and wrong for
any lit or multi-textured surface: Burnout 3's race came out unlit, with
a black sky, and its composite passes lost what their other stages carry.
- nv2a_combiner.c: up to eight general stages and the final combiner --
input mappings, dot products, mux (LSB/MSB), output scale/bias, blue to
alpha, per-stage or shared factors, V1+R0 sum and E*F product -- per
xemu's psh.c. tests/nv2a_combiner checks MODULATE, a final-combiner
lerp and an expand-normal dot product.
- Four texture stages, each with its own offset/format/size/address/
palette; the 0x1B00-0x1BFF block is decoded per stage.
- Texture shader modes per SET_SHADER_STAGE_PROGRAM: 2D/3D projective,
cube maps (face select, 128-byte-aligned face stride), pass-through,
clip plane (per-component discard). Bump/dot-product modes read zero.
- The fog unit (linear/exp/exp2, abs variants, FOG_PARAMS) and fog colour
feed the combiners' fog register; alpha test runs on the combiner
output, before the depth write.
- Unwritten program texture coordinates default to (0,0,0,1).
The combiner path takes over once a title writes COMBINER_CONTROL;
RECOMP_NO_COMBINERS restores the old path for comparison. The frame
trace prints each batch's stage textures and combiner words.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With both a MAC and an ILU op in one instruction the ILU's temp write goes
to R1 whatever the temp field says. The interpreter only did that when the
MAC half also wrote a temp. The Xbox D3D screen-space epilogue is
`mul o[0].xyz` beside `rcc R1.x`, where the MAC writes no temp at all, so
the reciprocal went to R7, R1.x stayed 0, and every vertex of every 3D
batch landed on c[59].
Also adds nv2a_vsh_constant (read, for traces) and
nv2a_vsh_constant_component (the viewport methods write c[58]/c[59] a word
at a time). tests/nv2a_vsh runs the epilogue and fails on the old rule
with exactly the collapsed position (320, 240, 0).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RECOMP_FP_PC rounded with a plain (float) cast. The x87 under PC=24
narrows only the significand; the exponent keeps the register's range.
Outside float's range the cast turned a large intermediate into inf (and
inf*0 into NaN) and flushed a tiny one to zero, where the hardware carries
on. Values in float range still take the cast; the rest go through
frexp/ldexp.
tests/fp_precision checks the Burnout 3 compare case and both range ends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The APU now delivers its interrupt and resolves physical addresses through
the kernel (591dcb9), so xbox_apu on its own no longer links. Link the
xboxrecomp interface library, as the kernel tests do, and give the test
the recomp_lookup stubs a title would supply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adpcm_decode_block refused any block whose fourth header byte was non-zero
or whose step index was outside 0..88, returning 0 frames -- after it had
already written the first sample of each channel. The MCPX does neither:
the byte is reserved in the format, not checked by the decoder. Titles ship
such blocks. Jet Set Radio Future ends every ADPCM buffer in a 0x08 pad, and
3.5-4.4% of its blocks were silenced, measured in play.
The index is now clamped, as the per-nibble update already clamps it. It has
to be clamped rather than trusted, because step_table has 89 entries; the
byte is read as int8_t, so values above 127 arrive negative.
tests/adpcm_decode checks a block with the reserved byte set decodes
identically to the same block with it clear, the all-0x08 pad block, and
out-of-range indices (100, and 200 which is negative as int8_t). Five of its
checks fail against the previous decoder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017QvivF8psGzR3Ws8tv21Ut
A codec is a long chain of MMX operations. One wrong lane in one helper does
not crash and does not warn: it comes out as a picture that is subtly wrong,
days later, with nothing to point at. Reading the helpers proves nothing
either -- they all look right, which is the problem. The processor is the
only authority on what they should do, and on any host that can run this
toolkit it is sitting right there.
tests/mmx_integer runs all 41 integer helpers plus the shifts, the shuffle
and the lane insert/extract against the host's own intrinsics on the same
inputs. 4784128 checks. They all agree.
Nothing here is a fix. It is a control: when a decoded frame is wrong, this
says in one run whether MMX semantics are a candidate. That answer was worth
having -- it is how I ruled MMX out of a video frame that decodes to DC
coefficients and no AC.
Points that shaped it:
- Inputs mix edge patterns (all ones, 0x8000..., 0x7FFF...) with random
bits. The saturating and packing helpers only differ from a wrong answer
at the limits, which uniform noise reaches rarely.
- Shift counts run past the lane width, where the answer is not "shift by
the low bits" -- the mistake the C operator invites.
- _mm_shuffle_pi16, _mm_extract_pi16 and _mm_insert_pi16 take their selector
as a literal, so those cases are written out rather than looped.
- x86 hosts only. Elsewhere it reports that it did not run rather than
passing vacuously.
Standalone CMake project like the rest of tests/, so nothing needs wiring up.
MmAllocateContiguousMemory always allocates via VirtualAlloc, which on POSIX is mmap. MmFreeContiguousMemory picks its deallocator by asking VirtualQuery whether mbi.AllocationBase == BaseAddress. The POSIX VirtualQuery hardcodes AllocationBase = NULL. The comment says so outright: /* != address -> freed via _aligned_free */.
`_aligned_free(ptr) { free(ptr); }`
So the branch is unreachable in the VirtualFree direction, and every contiguous-memory alloc/free pair hands an mmap'd pointer to free().
mcpx_apu_dsp_frame read mixbins[0] and mixbins[1] and discarded the other
thirty. On hardware the GP and EP mix the submixes down; here they are stubs,
so thirty of thirty-two bins were computed correctly and thrown away every
frame, with no counter anywhere to say so.
Titles route their 3D positional voices -- their sound effects -- to bins above
1. Measured on Jet Set Radio Future over one 200 s gameplay run, with a
positive control moving beside it:
[APU-BIN] 2D heard=557466 lost=0
3D heard=0 lost=377768
lost by bin: 6,7,8,9,10
557,466 music voice-frames heard and none lost; 377,768 effect voice-frames
produced correctly and thrown away. Music is on 2D voices and lands in bins 0
and 1, which is why the music was always audible and no effect ever was. Every
instrument upstream of this line read healthy, which is why several
investigations looked everywhere but here. A player confirmed the fix by ear.
Gating the HRTF submix override was tried first and did not fix it -- the
guest's own V0BIN..V3BIN also point above bin 1 -- so the defect is the width
of this mixdown and nothing else.
Even bins go left and odd bins right, which preserves the stereo pairing the
guest set up: bins 6/7 and 8/9 arrive with matched counts. This is not what a
real EP does. It is the cheapest mixdown that stops discarding audio, and it
is behind RECOMP_APU_MIXDOWN_ALL (default on) because it changes audible
output for every title and an escape hatch costs one branch.
tests/apu_mixdown puts a signal only in bins 6..10 -- bins 0 and 1 stay silent
-- and requires it to reach the frame buffer on both channels. It is
registered twice because the accessor caches its getenv in a static, and the
off arm is a real negative control: it requires the same signal to be LOST
with the switch off, so a mixdown that ignored its own switch cannot pass.
VirtualFree(ptr, 0, MEM_RELEASE) was a silent no-op. Win32 passes size 0 and frees the whole allocation; the shim returned TRUE without unmapping because it couldn't know the length. There was already a s_views[] registry doing exactly this for UnmapViewOfFile, so VirtualAlloc now registers its length and VirtualFree recovers it. That fixes every caller, not just this one.
Shutdown never released five regions — contiguous window, MCPX, flash, tiled view, and the span reservation. Added.
The fixed-function vertex shader took D3DFVF_XYZRHW input, threw RHW away and
emitted clip W = 1. Screen-space geometry still landed where it should, so the
symptom is not a misplaced quad -- it is texture coordinates interpolated
affinely across it, which looks like a subtly wrong texture rather than a
broken transform.
Dividing the reconstructed clip position by RHW restores clip W = 1/RHW and
leaves post-divide screen XYZ exactly as it was. Confined to the pretransformed
branch; programmable shaders and untransformed vertices are untouched. Four
draws at RHW ratios 1:1, 1:3, 3:1 and 2:2 over a black/white texture -- the
nonuniform cases must sample white and black, not the same grey midpoint.
Co-Authored-By: NoRain211 <NoRain211@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uoundkw2h1Z9uiD1sc2oFJ
update_blend_state copied the RGB factors straight into SrcBlendAlpha and
DestBlendAlpha. D3D11 rejects colour factors there, so guest SRCCOLOR,
INVSRCCOLOR, DESTCOLOR and INVDESTCOLOR made CreateBlendState fail with
E_INVALIDARG and left whatever was previously bound still active -- a wrong
blend rather than a missing one, which is much harder to spot.
Each maps to its alpha component for the alpha channel only; the requested RGB
factors, blend ops, write mask and the state cache are untouched. The smoke
test now reads back the bound descriptor, so a stale non-null state cannot
pass.
Co-Authored-By: NoRain211 <NoRain211@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uoundkw2h1Z9uiD1sc2oFJ
A title's XAPI is linked into its own image and reads the USB host controller
registers directly, so a gamepad only exists if those registers do. This
runtime backs the whole MCPX aperture with zeroed RAM, which describes a
controller reporting revision 0 and no root hub ports -- correctly enumerating
nothing.
src/usb/ohci.c is the register half: two controllers at 0xFED00000 and
0xFED08000, four downstream ports between them, one device on HC0 port 1. The
registers modelled are the ones with behaviour rather than storage, which are
exactly the ones a driver gets stuck on. HcCommandStatus.HCR is self-clearing
and is the first thing a driver writes, so a reset bit left set is a hang
before anything else runs. HcInterruptStatus is write-1-to-clear. HcRhPortStatus
writes are set/clear requests by bit position rather than a value to store, and
treating them as a value looks precisely like a port that will not enable.
HcFmNumber and HcFmRemaining advance on their own, because a stopped frame
counter is how a driver recognises a controller that is not running.
It is behind RECOMP_USB and off by default. A port with no descriptor walker
behind it is not yet a controller, and a title that worked without one has to
keep behaving exactly as it did.
Reaching the registers means faulting on them rather than reading RAM, and the
decoder for that already existed twice -- once in nv2a_mmio_hook.c, once in
apu_mmio_hook.c -- as one opcode table written out against two different pairs
of accessors. src/platform/mmio_decode.h is that logic with the accessors
passed in, so this device did not add a third. The originals still carry their
own and can move onto it whenever they are next touched; rewriting two working
decoders to prove a point is how you spend an evening finding out which of them
had the bug you just inherited.
tests/mmio_decode covers it, and the cases are the ones where being wrong is
silent: an instruction length that leaves the instruction pointer mid-opcode, a
32-bit read that does not clear the high half of its destination, flags that
send a poll loop the wrong way, and an unrecognised opcode reported as handled
-- which steps over an instruction nobody decoded and corrupts the guest with
no message at all. It refuses that case rather than guessing.
Written from the OHCI 1.0a specification and the title's own code.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PvNxGv5fth3NiNe3ZLCKZo
Half of Half-Life 2's menu batches carried texture coordinates and drew flat
anyway. Counting why said it in one run -- 3,353 textured against 3,354 with
texcoords and no usable stage, alternating almost one for one -- and the stage
they bound was format 0x0F with no pitch. That is DXT5.
Block-compressed formats are neither linear nor swizzled, so they fell between
the two rules the sampler had. They have no pitch, which failed the validity
check; their dimensions come from the format word's BASE_SIZE_U/V rather than
SET_TEXTURE_IMAGE_RECT, which this title never sends for them, so width and
height stayed at whatever the previous texture left behind; and their
coordinates arrive normalised rather than in texels.
Those are three symptoms of one thing -- a format whose size and addressing
come from the format word rather than from a pitch -- so they are one predicate
now (tex_size_from_format) used in all three places, instead of three separate
tests for "is it swizzled" that each needed the same second case adding.
Then the decode itself, for DXT1, DXT3 and DXT5: 4x4 blocks, two RGB565
endpoints and two-bit indices, with DXT1's three-colour mode and its one bit of
alpha, DXT3's explicit nibbles and DXT5's interpolated eight. It lives beside
the other pure format helpers rather than in the executor, because that is
where the existing test harness can reach it, and it is exactly the kind of
table-driven code that rots silently without one. DXN, DXT3A, DXT5A and CTX1
are different block layouts with no decoder; they return 0 block bytes and stay
unsampled rather than being decoded as something they are not.
The tests pin the things a plausible bug moves: which endpoint is c0, that a
5-bit channel widens to 0xFF and not 0xF8, that the 1/3 and 2/3 interpolants
are not swapped, that c0 <= c1 means three colours and a transparent index 3
for DXT1 and does not for DXT3 and DXT5, and that texel (4,0) is the second
block along rather than texel 4 of the first. One of them caught an arithmetic
error in this commit's own test expectations before it caught anything else.
HL2's menu now reports 8,403 textured batches and none rejected, and its
selection arrows draw as arrows.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PvNxGv5fth3NiNe3ZLCKZo