Repository navigation
Releases
v0.6.0 — "Open House"
WTF goes from its title screen, through the Job Share menu, into a game of
Lumberjack and its paycheck screen. A second microgame, Pendemonium, plays
too: a lit 3D factory scene where you cap pens. Ten pull requests from two
people: andy, still on LocoRoco, and a new contributor bringing DJMAX Portable
up, who made long guest loops stop eating the host stack and let a PRX be
lifted at the address it really loads at.
From contributors
- A
jto an address its own body owns is agoto, even at a function
entry. A loop whose back edge jumped to its own entry was a tail call
through the wrapper, and MSVC does not promise to make that a jump. On DJMAX
Portable a song's playback thread overflowed a 1 MiB stack after about 90
seconds; 472 bodies did this —
@nworkers (#35) --base <addr>andrelocate: lift a PRX where it loads. Applies the
module's own relocations (R_MIPS_32,R_MIPS_26,HI16/LO16pairs) at
a chosen base, so a host can keep the real memory layout. Without--base
nothing changes. Pointer seeds now honour a relocation's segment indices.
The relocated DJMAX image matches an independent loader word for word —
@nworkers (#36)-DPSPRECOMP_LOOP_HOOK: a safe point in every guest loop. Every backward
branch can callpsp_loop_hook(), where a host scheduler can preempt. Off by
default, and then the output is unchanged. On DJMAX the latest resume of the
sound thread went from 1000 ms to 6.7 ms —
@nworkers (#38)- A linking
jalrat the end of a body carries on after its slot. It was
treated as terminal, so a callee's normal return skipped the caller's
epilogue and left$sp16 bytes low —
@andyst-dev (#31) - Guest call frames live in the runtime, not in emitted bodies.
psp_call_guest_fn/psp_call_guest_addrown the return-site frame, so a
body that calls and then transfers in tail position no longer keeps a host
frame per iteration (959,952 bytes over 20,000 iterations before). Re-emit
to pick it up —
@andyst-dev (#32) emit --hints <path>: force labels for computed jumps. A per-title TOML
file whose[[label]]addresses become entries of the body that owns them.
The first kind of hint; see HINTS.md. Partly answers #15 —
@andyst-dev (#34)sceIoGetstatfills its buffer from the host file (type, mode, 64-bit
size, timestamps). It used to return success and write nothing —
@andyst-dev (#29)sceIoOpenrejects a null or empty filename instead of opening the
disc directory, or reading a module at address 0 as a name —
@andyst-dev (#28)sceCtrlReadLatch/sceCtrlPeekLatch: make, break, press and release
masks accumulated across samples, consumed on read —
@andyst-dev (#30)- Several watch sites at once.
psp_trace_watch_addand
psp_trace_watch_label_addtake up to eight each and say when the table is
full, so an unwatched address can't pass for an unreached one —
@andyst-dev (#33)
Emitter
- A jump that leaves runs its delay slot even when another body owns it.
jandjrnow emit a copy of a foreign slot before they go, as branches
already did. Pendemonium builds the struct offset 0x44AF0 with
lui/ori, which discovery took for a code address; it landed on the slot
of ajr $rawhoseaddiu $sp, $sp, 16was then dropped, and every call
leaked 16 bytes of stack. - A branch-and-link is a conditional call.
bgezal/bltzaland the
likely forms call their target and carry on after the delay slot, and link
$rawhether or not they are taken. The taken path used to be a tail
transfer, so the caller's frame was abandoned. Reported, with the analysis,
by @Tzeentchnet (#16). jr $rafollows the guest's calls, not C's. Every call pushes the return
site it expects onto a shadow stack on the host stack. Ajr $rato that
site is a return; to an outer call's site it unwinds to that call; to anywhere
else it is a jump through dispatch. WTF's decompressor uses$raas a
continuation and returns from helpers by branching to its own epilogue, and
leaked an 896-byte frame per call into the heap. Every call's return site is
now a label.
Hosting a game
psprecomp/window.h: a window to play in. Shows the front buffer
scaled with whole-pixel nearest sampling, letterboxed, and feeds the
keyboard and the first XInput controller to sceCtrl, on a host thread of
its own. Windows (Win32, GDI, XInput: no dependencies); elsewhere it
reports that it cannot open, until an SDL2 backend like ps3recomp's.psprecomp/module.h: load and start a module. Places the image, reads
module_start from the ELF header and$gpfrom the module info, finds the
constructor table, and starts the module the way the loader would. What a
bring-up harness used to hard-code per game.psp_display_read()gives the front buffer as pixels; the capture uses it.- Constructor discovery stops a run at a zero word: a module linked at 0 has
zeros that read as pointers to its first byte.
VFPU
- Operand prefixes are applied, not trapped.
vpfxs/vpfxtswizzle,
negate, take absolute values and substitute constants on each source lane;
vpfxdsaturates and masks the destination. WTF broadcasts a lane before a
clamp, builds box corners with them, and compares against |x|. The matrix
ops still trap on a pending prefix. mfv/mtvandmfvc/mtvc, the integer packing ops (vi2uc,vi2c,
vi2us,vi2s,vuc2i,vc2i,vus2i,vs2i),vocp,vsgn,vsge,
vslt,vscmp,vhdp,vcrs,vcrsp/vqmul,vdet,vrot, the
vcmpconditions 8-15 andvnop/vsync/vflush. WTF's colour helper
endsvi2uc; mfv; unimplemented, it returned whatever$v0held, so every
menu glyph was drawn in the display-list pointer's "colour", alpha 9.vidtwrites the identity column its register names (vidt.q C730is
(0, 0, 0, 1)). It used bits 6-7 instead. WTF keeps s733 = 1 that way for its
quaternion-to-matrix code, so every animated node had a zero 3x3 and the
microgames' title cards were drawn at a point: an invisible screen that
looked like a 25-second load.
Renderer
- Lighting: four lights (directional, point, spot; ambient, diffuse,
specular, powered diffuse), material colours with CMAT, per vertex in world
space. - Depth: a 16-bit depth buffer in VRAM, ZTEST/ZMSK, ZSCALE/ZPOS, and depth
clears. - DXT1/3/5 textures, in the PSP's block layout (indices first).
- Indexed drawing, and PRIM leaves VADDR/IADDR after what it used, so the
next PRIM continues from there. WTF draws runs of PRIMs with one VADDR;
they had all re-read the first vertices. - Attributes are sampled at the pixel centre. At the corner, a row of a
1:1 texture landed on the texel edge and float error floored it to the row
before; WTF's LED panels lost whole rows of dots. - Triangles with a vertex behind the eye are dropped one by one, not the
whole 256-vertex batch they arrived in.
Runtime and HLE
- A new thread starts with its creator's
$gp. Under real threads it
started at 0, and Pendemonium, whose globals are$gp-relative, read its
own code as data. - An unbounded wait does not time out while another thread could end it.
WTF's sound thread waits forever on a request queue and does not check the
result; a fake timeout made it open a file named NULL. A waiter with no other
live thread still reports and gives up. - Blocking audio output models the hardware queue on the host clock, and
sceAudioSetChannelDataLenis implemented. WTF's audio ran at about a
tenth of real time, so its title jingle, which it waits for, never finished. - SAS voices honour the ADPCM block loop flags. A loop end without the
repeat bit stops the voice even in loop mode. The title jingle had looped
forever. - Windows timer resolution is raised to 1 ms under real threads, and
deadlines use the performance counter. Each scheduler tick had cost 15.6 ms. psp_call_from_host()runs guest code from thread entries, callbacks,
interrupt handlers and constructors.
Rendering
-
Textures. 565/5551/4444/8888 and CLUT 4/8/16/32-bit, linear or
swizzled, with the CLUT captured at CLOAD as the hardware does. Texture
functions modulate, decal, blend, replace and add. Alpha test, blending
(every factor and equation), clear mode with its colour/alpha flags, scissor,
16-bit framebuffers, and vertices with no colour take the material colour.
DXT is drawn magenta and counted. -
Transformed geometry. World, view and projection matrices, viewport and
offset, UV scale and offset, and normalised 8/16-bit vertex formats. A
primitive with a vertex behind the eye is dropped and counted, since there is
no clipping yet. -
psp_ge_dump_stats()lists every undecoded GE command by opcode, with
its last argument, instead of printing the first 64 to stderr. -
A finished display list frees its queue slot. Slots were never
released, so the ninthsceGeListEnQueuefailed and every frame after it was
dropped. WTF ran its loop at full speed and drew 15 lists in 60 seconds; it
now draws all of them. Stall updates on a finished list succeed.
Instruments
PSPRECOMP_TRACE_GE=<frame>logs every command, primitive and its first
vertices during one frame.- The write watch prints the guest calls in flight, not just the last
function entered. psp_hle_dump_counts()prints call counts per firmware function,
busiest first, wit...
v0.5.0 — "Taking Turns"
Six pull requests from two people. Guest threads can now really take turns,
behind a build flag. A new contributor, measuring against Killzone: Liberation,
fixed five places where the decoder, the emitter or discovery read something at
the wrong moment or from the wrong field.
Runtime and HLE
- Opt-in cooperative threads (
-DPSPRECOMP_REAL_THREADS=ON). One host
thread per guest thread and a single CPU baton, handed over at blocking
calls.sceKernelStartThreadno longer has to run the entry to completion,
so a caller can post work to a worker that waits on it. Sub-interrupt
handlers and callbacks are delivered where the guest waits, on the thread
that owns them. Native Win32 and pthreads adapters. The default build keeps
the inline model. AlsosceKernelMaxFreeMemSizeand a deeper trace history.
See THREADING.md —
@andyst-dev (#9) vi2f/vf2izapply their 5-bit scale, and the float-to-int conversions
saturate to int32, with NaN giving0x7FFFFFFF.vi2f.q ..., 16was
coming out 65536 times too large. Checked against hardware values recorded
on a PSP-3000 —
@Tzeentchnet (#17)vf2in/vf2iu/vf2idare emitted (nearest-even, up, down) instead of
trapping —
@Tzeentchnet (#18)
Decoder
lv.s/sv.s/lv.q/sv.qread their register from the load/store
fields. It used to take bits from the base GPR. 10,019 of 15,444 VFPU
loads and stores on KZL changed register —
@Tzeentchnet (#12)
Emitter
jr/jalrread their target before the delay slot runs, andjalr
links therdit encodes (nothing for$zero). A slot that steps the
target register no longer moves the jump —
@Tzeentchnet (#13)
Discovery
jal .+8is the get-PC idiom, not a call. Its target is no longer made
a function, so the rest of the routine no longer runs twice —
@Tzeentchnet (#14)
Known open
bgezal/bltzalto another function drops the code after the call (#16).- Computed jumps into unlabelled blocks need a way to force labels (#15).
- Jump-table operands traced to their definitions (#19) is in review.
Contributors: @andyst-dev (#9) and, for the first time, @Tzeentchnet (#12, #13, #14, #17, #18). Full credit in CONTRIBUTORS.md.
v0.4.0 — "Handed Over"
The first outside contributions: eight pull requests from two people. Most of
it came from bringing LocoRoco (UCES00304) and Monster Hunter Portable 3rd
(NPJB40001) up on the toolkit, and it fixed the open lead in
BRINGUP.md. On the WTF Lumberjack module the object pointer
that was coming out as zero is now correct. The run makes no bad memory
accesses where it used to make 253 million, and it now stops at the thread
model rather than on corrupted state.
Emitter
- A body that falls out into another body's label continues there, through
that label's thunk, instead of silently returning. 579 bodies on LocoRoco
ended this way. The label map is now built module-wide before any body is
emitted, and the thunk declarations go in the shared header —
@andyst-dev (#7) - A delay slot belongs to its branch. A slot that another body owns is no
longer stepped over, so the fall-out is looked for at the right address. The
branch's taken path now runs the slot too. On LocoRoco this removed ten
negative stack leaks and two reads of the module's own code as a table —
@andyst-dev (#10) - A body-ending transfer stays a tail jump. Nothing is emitted between the
call and thereturn, so the compiler can reuse the frame. A guest loop
whose back-edge crosses a body boundary used to exhaust a 16 MB host stack.
It now runs at 9 KB —
@andyst-dev (#11) viim/vfimwrite the register the encoding names (bits 16..22, not the
genericvd), and non-finite immediates are spelledNAN/INFINITYrather
than the invalid tokensnanf/inff—
@andyst-dev (#3)
Discovery
- Code pointers built with
lui+addiu/oriare harvested as entries.
This catches the thread entry handed tosceKernelCreateThread, which is
never ajaltarget —
@Invictus-potens (#2)
Runtime and HLE
psp_syscall()andpsp_unimplemented()are defined by the runtime
(src/traps.c), so emitted C links without a host shim. They come with
counters and a reset —
@andyst-dev (#4)- The unimplemented-call message is rate-limited. One 30-second LocoRoco
run wrote 1.37 GB of it. The message now prints a bounded number of times,
then one line saying further calls are only counted. The zero-return ring
counter is 64-bit, so it no longer wraps negative and reads out of bounds —
@andyst-dev (#5) - Stack imbalances are grouped by site.
psp_sp_hist()and
psp_sp_call_hist()return one row per distinct(site, delta), largest
magnitude first, so a-656leak no longer hides behind a crowd of+16s —
@andyst-dev (#8) - A hand-over is judged by its own sign.
PSP_SP_LEAVE/
psp_trace_sp_leavetreat$spbelow the entry as expected at a fall-out,
and report it only when it is above. This explains BRINGUP's-64group —
@andyst-dev (#11) sceKernelSleepThreadandsceKernelSleepThreadCBare registered, with
the same immediate-return approximation assceKernelDelayThread—
@Invictus-potens (#2)
Maintainer fixups during integration
All eight PRs were written against caca759, before the corpus was split into
translation units (39f1f4b). These fixups are mine, one commit each:
- #2's harvest now only accepts targets inside the scanned range. Without that
restriction it lifted.dataas code: 1,282 extra functions and 1,125 extra
VFPU trap sites on Lumberjack. With it, #2 adds 78 functions there and
87–214 on each of the other five WTF modules. - The #7 merge resolution puts the thunk declarations in the shared header, so
that every unit sees them, and runs the module-wide label pass indump
too. - #3, #7 and #11's tests read split units. #11's checks had been skipping
silently on that and also failed on Windows line endings; both are fixed. - #10's fall-out check expects #11's
PSP_SP_LEAVE, and #11's high hand-overs
are recorded in #8's site report.
Not in this release: #9 (real threads with an explicit CPU hand-over) is
still under review. It needs a build that works on MSVC.
Full history: CHANGELOG.md. Contributors: CONTRIBUTORS.md.