A PS2 game's models are prebuilt VIF / GIF packets and its textures GS rasters; a native port converts them offline from the user's disc into packs in its build tree and draws them without reading a packet. TMB had all of it in its own runtime and tools; what is not TMB's moves here.
Runtime (ps2xRuntime, all in ps2_runtime):
- runtime/native/native_mesh_pack.h (ps2x::native::packs): MeshPack, the PS2XMSH1 container's loader (every count checked against the file's size) and object store: per file (named as the port's runtime names a loaded file, with the image's size and CRC32) its objects by offset (a port-defined kind and attributes, x y z w positions, PS2 triangle strips as a VU program reads them: StripHeader with PRIM, GIF flags, a material word and a texture slot, 16-byte StripVertex with position index, raw normal, flags, RGBA, raw s t; and port-defined tagged sections) and its GS register blocks (A+D writes recorded at their offset in the image). MeshFile::object / block find them; StripCursor walks strips. LoadedImages: where the game loaded each file in EE memory (bind checks size and CRC32 against the pack, find resolves an address to file and offset, forEach under its lock). crc32.
- runtime/native/native_mesh_draw.h (ps2x::native): MeshBatch / MeshDraw (an object's batches with their GS register writes, object-to-screen matrix, clip volume, context block, interpolation key), MeshGsState (ALPHA, TEST, ZBUF.ZMSK as context and register blocks leave them), MeshViewList<D> (a view's opaque objects in traversal order and its alpha ordering table: pending until the game links it, link(bucket), forEachInOrder: opaque, then the buckets from the farthest, each newest first), MeshSubmitter (the GS state followed in submission order into each batch's material, clipMeshTriangles: cut to the clip volume, |x| |y| |z| <= w, and to w > 1e-3, colour / UV / fog along the cuts; FOGCOL by a port callback, an Observer for a port's checks, MeshLiveToggles: nodepth, nofog, noclip, flat, opaque, noatest, notex, noguard, dump from a file of words), meshBlend.
- runtime/native/native_texture_pack.h (ps2x::native::packs): TexturePack, the PS2XTEX1 loader (per file its records in order: PSM, size, texels unpacked), file / nth lookup, ct16ToRgba and recordColour (TEXA alpha for CT24 / CT16 as the GS), csm1Palette (an indexed texture's palette from the port's CLUT lookup, CSA for T4), decodeRecord (the RGBA image a TEX0 shows).
Tools: tools/native_pack (mesh.py: MeshPackWriter, MeshFile, MeshObject, Strip, read_pack; texture.py: PSM constants, unpack_texels, record, TexturePackWriter, read_pack; ps2.py: vif_codes, unpack_size, dma_chain / chain_stream / image_offset for a DMA chain in an image linked at a fixed address, find_gs_register_blocks, elf_bytes).
Docs: docs/native_packs.md: the formats, what a port implements (converter, file binding hook, per-object hook and its EE state, the game's order, texture keys), TMB as the worked example, a game whose models sit in an archive.
The code is TMB's, moved without a change in behaviour: TMB (TMB_Recomp, packs branch) now uses these, with packs whose contents equal its old ones field for field and the same checks and pictures (numbers in its commit).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every write to an 8 KiB page of GS memory (a draw into a render target, a
transfer, a CPU write) gives it a new version; GS memory and each render
target know the versions they hold. Before GS memory is read (a texture in
another format or width than the target's, a transfer, a CLUT, a buffer
displayed from memory) the target holding a page's newest version writes it
there, page by page on the GPU copy; before a target is drawn into or sampled,
its older pages are reloaded from GS memory. This replaces ensureCoherent,
fillTargetFromMemory, resolveTargetsUnder and dropTargetsUnder: targets are no
longer dropped under uploads, and targets sharing memory in different formats
or widths see each other's pixels as the GS would (VP2's CT16 / CT32 views of
its post-process buffer and the blur levels inside its pages: the colour bands
along the bottom and right edges are gone).
FBMSK keeping part of a channel (VP2 writes CT16 bits 14-15 alone with 0x3FFF
to move a channel into CT32's alpha, SCTPT2 the top alpha bit with
0x7F000000): the kept bits come from a copy of the target when the batch does
not blend; in CT16 only the stored bits count (a channel whose stored bits
are all kept is masked whole). A CT16 reload keeps the stored alpha bit.
A read straight from a target now needs its width too; a colour target used
as Z (depthFromColorTarget) has its pages brought up to date first.
PS2X_GS_NATIVE_STOPDRAW=<n> (diagnostics) draws only the first n batches.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Opt-in per game, default path unchanged. A game that runs its own loop on real time:
- FramePacer (runtime/frame_pacer.h, PS2Runtime::framePacer): frameEnd() holds the frame to the cap (PS2X_FRAME_CAP,
default 60, 0 = unlimited, settable at run time) and returns the frame's real duration;
- EeScheduler::setNativeFrames(true): the game's frame end shows the picture (presentGuestFrame) instead of vblanks,
and due events fire once EE time reaches them, without waiting for their host deadline (the game keeps EE time on
real time at its frame end); the latch code moves to latchGuestFrame();
- the host window follows the cap and uploads one picture per frame the game ends.
docs/native.md: goal, layers (frame loop, audio on wall time, translating renderer, hardware waits, native VU
output), layer 1 API. First user VP2S (VP2S_NATIVE=1): first field scene at cap 60, ~44 distinct frames/s, 48
presented/s, host never idle.
Co-Authored-By: Claude Opus 5.5 <[email protected]>