The game calibrates seconds per cycle at boot (sub_00068010) by counting rdtsc cycles while KeTickCount moves 200 ms. The runtime wrote KeTickCount from GetTickCount(), which moves in ~15.6 ms steps, so the calibration came out 0.996-1.002x the emulated 733 MHz clock and the level clock and match timer ran that far off real time, differently every boot. With KeTickCount counted from the performance counter the calibration is exact (1.00000x in 8 of 8 runs) and the level clock matches host time at every frame rate. Refs #20
13 KiB
Fixed so far, and how
Read this when a symptom looks familiar, or before changing the code a fix touched. GitHub Issues have what is still open.
-
Freeze after the first flip. The dump's registers fit the spin at
loc_00386C60insub_00386B30(eax=2,ecx=3,esi=0xD,edi=0xA), which waits for the semaphore to reach the fence. It is not the0x400B10loop insub_00386AC0.RECOMP_WATCHshowed the semaphore at0x80267000written only once, to 3, by D3D at init. The executor dropped releases because it had no target.sub_00386840_enterinrecomp_manual.cnow supplies the target fromdevice+0x30. -
"Dirty disc" fatal screen.
sub_0001A110draws a message and callsSleep(0xFFFFFED8), so it looks like a hang. It was reached throughReadFile beyond EOFinsub_00015D20, becauseNtReadFilerejected a buffer at0x74000008.bridge_va_mappeddid not know aboutRECOMP_EXT_VMAmemory. This is fixed inpatches/xboxrecomp-extvma-buffers.patch. -
Movies stuck or crawling. XMV (
sub_002C5E0A) times frames with the vblank count atdevice+0x1DE8, read bysub_00382610, and adds a skew at+0xC8that tracks real time. With no vblanks the count never moved. Tying it to flips (21 Hz) made the two clocks disagree, so the skew kept jumping and frames were scheduled further away.RECOMP_VBLANK=paceddelivers real 60 Hz vblanks to D3D's own ISR. Do not register the count withxbox_Nv2aFrameCounteras well. -
Freeze on pressing Start. The original fence wait's "GPU far behind" path spins on PGRAPH
0x400B10and sleeps on the event atdevice+0x1DCC(miniport+0x1A4) that a GPU interrupt sets.src/recomp_manual.creplacessub_00386B30: it kicks the fence if newest, then waits on the semaphore, giving up after 250 ms with GET not moving. It logs[D3D] fence ...: no GPU progressthen, and the original's callback atdevice+0x19FCis not called. -
Pad not seen.
main.cnever calledxbox_OhciInit, soRECOMP_USBdid nothing. -
Untranslated CRT x87 targets. The table at
0x0040AAB8has targets0x002B7B7Cand0x002B7C1Ethat were never translated, because neighbouring functions started two bytes further in. Skipped calls left values on the FPU stack.recomp_lookup_manualnow supplies both. This did not fix the fatal screen, whatever the commit "Supply missing CRT x87 entries to reach map loading" says. -
Fatal screen on Begin Match.
RtlRaiseExceptiononly logs and returns, so code ran on after everythrow. Loading a match throws "Can't resolve package name" in normal use, and running past it ended in a garbage file name andsub_00016784's dirty disc call.src/recomp_manual.cnow replaces_CxxThrowException(sub_002BA881): it walksfs:[0], reads the MSVC tables, runs destructors, then longjmps to a wrapper that runs the catch funclet and its continuation.[EH]lines log each throw.Limits: only C++ throws are handled. Raises through
RtlRaiseExceptionstill return, and__exceptis not dispatched. Each function with a catch needs a wrapper, and each continuation an entry intools/add_eh_entries.py. The game has 11 such functions, and all are covered, except one in an XDK section (funclet0x374BF1), which was not decoded. A throw with no site logsNO CATCH SITEand falls through as before. -
Frozen map load.
sub_002043A0, the wrapper for GetVisibilityTestResult, waited for a report the executor never writes.src/recomp_manual.cnow reports the test done with 640x480 pixels visible, so occlusion culling never culls. That may cost speed. -
Flicker and popping. D3D runs recorded pushbuffers by jumping into them. A non-zero
NO_OPERATIONbefore the jump (argument<< 5| code) traps to D3D's interrupt handlersub_0038D600, whose codes 12-14 write the recording's return jump and fixups (sub_003863F0).d3d_software_methodinrecomp_manual.cdoes that from the walk. Unhandled, each tail returned to its first caller and old commands replayed, which was also whyRECOMP_PB_WALK=dmalivelocked. D3D patches thoseNO_OPERATIONs while GET shows the GPU has not reached them, so GET must be exact, which only the DMA walk gives. -
Low frame rate.
src/gpu_d3d11.cdraws on the GPU throughnv2a_backend.h. The kick's PFB flush spin is gone (sub_00386FA0inrecomp_manual.c), so the game thread no longer waits while the executor runs vertex programs. Those run on the raster pool with duplicate indices removed.RECOMP_LOGreplaces PowerShell's slow stderr pipe. SSX3-recomp (GPL, Vulkan) was a useful reference for this toolkit's GPU path; its code was read for approach, not copied. -
Checkerboard of missing triangles. Strips alternate winding, and culling added for the GPU path did not allow for it.
raster_batch_programnow swaps every other triangle's first two vertices. -
Arena exhausted. Contiguous frees were ignored without
RECOMP_HEAP_RECLAIM, so the arena ran out about two minutes into a match. Reusing blocks then crashed on pages the last owner had protected, soxbox_ContiguousAllocExnow resets their protection. -
Crashes in XPP.
sub_00399A84,sub_003998CAand the others faulted on0xFFFFFFFF, reached through a transfer descriptor that had been freed:sub_00398505sets a freed descriptor's link to that value. USB submits run on a game thread at DISPATCH and completions in a DPC on the timer thread, with nothing keeping them apart, so the free list and the queues raced.RECOMP_DISPATCH_GATE=1serializes them as the single CPU does. A scripted match crashed at about 3.5 minutes without it, and did not crash in four runs of 400 s or in a longer soak with it. The stray[OHCI0] STALL: 21 09before the crash in a played match did not appear in any gated run, so it looks like a symptom of the race, not a gap insrc/usb. -
Chopped audio and a 10 ms stall per update.
sub_002F96C7, on every DirectSound DoWork, tests0xFE85A018, word 6 of EP program memory, for0xCCCCCC, and otherwise takes the DSP to have crashed and resets it (sub_002F9487). No EP program runs here, so the word stayed 0: about 50 resets a second, each stopping the sequencer (SECTL XCNTMODE off) and stalling 10 ms. The frame thread filled that time with silent periods, so about half the output was digital zero, and the voices resumed where they stopped.mcpx_apu_dsp_ack_pollnow writes the word, and a stopped sequencer produces no frames for up to 50 ms, as in xemu. In a 400 s capture, runs of zero with sound on both sides went from 17,020 to 3, click candidates from 3,993 to 2, and resets to 0. Match frame rate rose from the 40s to about 60 at the same point. The GP and EP memories are plain RAM (only0xFE800000..0xFE830000traps), somcpx_apu_mmio_*never sees them. -
Black boxes. UC2 draws its projected shadows into 256x256 B8 surfaces (format
0x119, pitch 256), then multiplies the scene by them with blendDST_COLOR, SRC_COLORand a combiner that lerps from 0.5 grey to the texture. The vertex-program path dropped triangles for 1 byte a pixel, so the map stayed all zero and the projector darkened its whole frustum. Those triangles now reach the back end, andgpu_d3d11.creads a target sampled as format0x13from blue, as luminance.tools/play.ps1 -DrawLogfound this: it logs one frame's draws each second. -
Black boxes on explosions. Explosions draw sprites into a 320x240 distortion map (
0x801CD000), then a full-screen pass with stage program0xA621reads the scene through it:DOT_PRODUCTthenDOT_ST, with an alpha test on the map. The shader returned zero for those modes, so wherever a sprite had written alpha the pass drew black, blocky from the low-resolution map. A colour grading pass (0x2621) uses the same pair and was losing about a quarter of its light. The modes are implemented for stage 1 followed by stage 2. Blending can't darken here, so the clue was that hiding additive draws removed the box: they fed the map. -
Cutscenes hitched. In Story Mode videos 1-8 frames a second took 25-80 ms and audio underran. The guest core spent half its time in
sub_002C6B80, the XMV player's YUV 4:2:0 to BGRA converter for a 16x16 macroblock, because lifted MMX/SSE does every op lane by lane on thread-local register globals. It is now hand-written inrecomp_manual.cwith SSE2 intrinsics on locals, instruction for instruction, reading mm4-mm7 and xmm4-xmm7 from the guest and writing back the registers the original leaves. A harness running both bodies on 5000 random macroblocks (including saturating inputs and non-standard constants) matched every output byte and register, and it is about 12x faster (17.0 to 1.45 us a macroblock). A cutscene then held 157-159 fps with no underruns. -
Boot movies stalled now and then. In about one boot in five the logo movie froze for up to a second at a time,
[IRQ] wait ... gate holder has reached no safe pointlines appeared and audio underran. The holder was the timer thread inside D3D's GPU interrupt DPC (sub_0038CFA0), which writes the vblank ack to PCRTC_INTR_0 and spins until PMC_INTR_0's PCRTC bit drops. The suspected cycle (a vblank posted to the DPC withtick_busyup) was wrong: logged while it spun, PMC_INTR_EN_0 was 0,tick_busy0 and the ack written, but the vblank-ack thread that takes it was not running. Its stack showed it insideSwitchToThread, from the watch's first 2 ms. That call yields only to a thread ready on the same processor, and that was the timer thread, just woken to run the DPC: the watch handed it its core and queued behind the spin for 60-600 ms. The watch now spins on a pause for those 2 ms, which cost no more CPU (the yield returned at once whenever nothing else was ready). That alone left 1 boot in 15 with a 340 ms ack, the thread woken from its 1 ms wait into the same queue, so the thread also runs time-critical; it works for microseconds a vblank. With both, 15 boots in a row had no[IRQ] wait, no underruns, vblank gaps of 12-21 ms and no ack later than 7 ms, against gaps of up to 686 ms before. -
Distortion effects showed through walls. The purple barrier on Sovereign, and cloaked players, were visible through anything in front of them. Both are distortion effects. A full-screen pass reads the scene's Z24S8 depth buffer (
0x80620000) as an A8R8G8B8 texture and draws it into a half-size colour surface (0x807FA000on Sovereign,0x8074C000on Aqueduct); the effect's sprites then draw into the distortion map with that surface as their depth buffer, so walls hide them. Depth lived only in D3D11 depth buffers and colour in render targets, so the read found nothing and the sprites tested against an empty depth buffer. Depth buffers are now sampleable, and two passes carry the bytes across in the console's layout:zeta_encodewhen a draw samples a depth buffer's address,zeta_decodewhen a depth buffer's address was last written as colour. Visibility tests were the first suspect (they always answered "all visible") and now return real counts too, but did not change the glow: the draw log showed the glow covering a pillar in front of it, which no culling decision can do. -
The countdown before a match was silent. "The match is about to begin... 3, 2, 1" plays
A_Gameplay.Countdownonce a second, and the game did ask XACT for it each time, but no voice started. Its wave is inA_Weapon.xwb, the one streaming wave bank: XACT fills each of a voice's two packets with an overlapped read. The tick fits one packet, so on the second XACT finds no data left and askssub_00362D65whether anything is in flight before ending the stream. A packet whose read had finished but which had not gone to DirectSound counted as done, so the stream was ended empty and the packet dropped. On the Xbox the read is still running at that point; the runtime completes reads before they return. At that one call (returning to0x00369C08) such a packet now counts as in flight, and XACT hands it over the next time it services the voice. Other short sounds in that bank, such asA_Weapon.SN_Raise, were silent for the same reason. -
Game clock 0.2-0.4% off real time, different every boot. The main loop (
sub_0001A310) times frames withrdtsctimes seconds per cycle (0x0040C590), whichsub_00068010calibrates at boot by counting cycles whileKeTickCountmoves 200 ms. The runtime wroteKeTickCountfromGetTickCount(), which moves in steps of about 15.6 ms, so the calibration came out 0.996-1.002x the emulated clock's 733 MHz rate and the level clock and match timer ran that much off (#20).KeTickCountnow counts milliseconds from the performance counter (patches/xboxrecomp-gpu-backend.patch), and the calibration comes out exact. The frame rate never mattered: the delta is unclamped up to the level's 0.0005-0.4 s, andtools/tick_rates.pymeasured the same movement, fire and timers at 60, 144, 240 and no limit.