metal: one upscale type for MetalFX SR, and a way to hand it a title texture #640

Closed
github-bot wants to merge 279 commits from github-bot/gh-636 into main AGit
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 18:02 UTC · original
AnastasisKon:vibe/metalfx-upscale-seam-4f9c68 → main · +32994 −2586 · 178 files · 279 commits · closed without merging

Part of #378. Builds on the first commit of this branch, which added metalfx::Upscale and Texture::mtl.

What

A MetalFX upscale is now a pass of a submission: Pass::MetalFx(MetalFx { color, depth, motion, out, jitter, motion_scale, reset }). The backend makes the scaler the pass needs from the sizes, formats and mode it names, keeps it (one per size and format pair, in a cache on the device) and encodes it in its place in the submission.

The interesting part was ordering. encodeToCommandBuffer: takes the whole command buffer, so a MetalFX encode can neither wait on nor update the fence the other encoders of a residency-set submission order through — and this Mac runs residency sets by default, so refusing there would have refused every upscale. Instead a MetalFX pass ends the command buffer it is in, and the submission's piece event orders the next one; that is the mechanism VICTORY_PASSES_PER_BUFFER already uses. The encoders before it in the same buffer name their attachments, so the pass's inputs are ready when it runs.

metalfx::View carries the frame's jitter, its motion-vector scale and the reset. Temporal::encode used to hard-code a motion scale of 1 and no jitter, which would have been wrong for FSR's dispatch values.

Testing

  • cargo test -p victory-metal --target x86_64-apple-darwin --test metalfx_pass — 3 passed on this Mac's GPU:
    • a_spatial_metalfx_pass_fills_its_output: a red 16x16 render target scaled into 32x32 reads back red (255,0,0,255 within 8).
    • a_temporal_metalfx_pass_fills_its_output_from_depth_and_motion: the same with depth at the far plane, zero motion vectors and a [0.5, -0.5] jitter.
    • a_metalfx_pass_into_a_texture_metalfx_may_not_write_is_refused: an output that is not a render target is refused, and the submission reports the pass it lost.
  • cargo test -p victory-metal --target x86_64-apple-darwin --lib metalfx — 10 passed.
  • nice -n 10 sh tools/macos/verify.sh full — == gate PASSED == (suite-hle 554, suite-shader 593, suite-gpu 493, policy, clippy-win), so neither the Windows build nor the other backends mind the new variant.

What is still missing for MetalFX in the game

Two pieces, both now mechanical rather than unknown:

  1. victory-gpu's native list records a Cmd::Metalfx at the title's dispatch and emits this pass with the four textures resolved from the resource pointers (the registry is keyed by them).
  2. modules/fidelityfx.rs answers the title's ffxCreateContext / ffxConfigure / ffxQuery / ffxDispatch itself on the native path, gated behind a switch, instead of letting the title's own DLL run; the dispatch's rest is already the layout MetalFX needs (jitter, motion-vector scale, render and output sizes, reset).

Frame generation is a third: keep the previous frame's colour and depth, and interpolate between them with metalfx::Interpolator through the same pass.

I did not guess at those here: none of them can be checked without a run, and the folder on this machine is 66% downloaded (#636), so a run cannot validate anything yet.

**@⁠AnastasisKon** on GitHub · 2026-11-28 18:02 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/636) `AnastasisKon:vibe/metalfx-upscale-seam-4f9c68` → `main` · +32994 −2586 · 178 files · 279 commits · closed without merging Part of #378. Builds on the first commit of this branch, which added `metalfx::Upscale` and `Texture::mtl`. ## What A MetalFX upscale is now a **pass of a submission**: `Pass::MetalFx(MetalFx { color, depth, motion, out, jitter, motion_scale, reset })`. The backend makes the scaler the pass needs from the sizes, formats and mode it names, keeps it (one per size and format pair, in a cache on the device) and encodes it in its place in the submission. The interesting part was ordering. `encodeToCommandBuffer:` takes the whole command buffer, so a MetalFX encode can neither wait on nor update the fence the other encoders of a residency-set submission order through — and this Mac runs residency sets by default, so refusing there would have refused every upscale. Instead a MetalFX pass **ends the command buffer it is in**, and the submission's piece event orders the next one; that is the mechanism `VICTORY_PASSES_PER_BUFFER` already uses. The encoders before it in the same buffer name their attachments, so the pass's inputs are ready when it runs. `metalfx::View` carries the frame's jitter, its motion-vector scale and the reset. `Temporal::encode` used to hard-code a motion scale of 1 and no jitter, which would have been wrong for FSR's dispatch values. ## Testing - [x] `cargo test -p victory-metal --target x86_64-apple-darwin --test metalfx_pass` — 3 passed on this Mac's GPU: - `a_spatial_metalfx_pass_fills_its_output`: a red 16x16 render target scaled into 32x32 reads back red (255,0,0,255 within 8). - `a_temporal_metalfx_pass_fills_its_output_from_depth_and_motion`: the same with depth at the far plane, zero motion vectors and a `[0.5, -0.5]` jitter. - `a_metalfx_pass_into_a_texture_metalfx_may_not_write_is_refused`: an output that is not a render target is refused, and the submission reports the pass it lost. - [x] `cargo test -p victory-metal --target x86_64-apple-darwin --lib metalfx` — 10 passed. - [x] `nice -n 10 sh tools/macos/verify.sh full` — `== gate PASSED ==` (suite-hle 554, suite-shader 593, suite-gpu 493, policy, clippy-win), so neither the Windows build nor the other backends mind the new variant. ## What is still missing for MetalFX in the game Two pieces, both now mechanical rather than unknown: 1. `victory-gpu`'s native list records a `Cmd::Metalfx` at the title's dispatch and emits this pass with the four textures resolved from the resource pointers (the registry is keyed by them). 2. `modules/fidelityfx.rs` answers the title's `ffxCreateContext` / `ffxConfigure` / `ffxQuery` / `ffxDispatch` itself on the native path, gated behind a switch, instead of letting the title's own DLL run; the dispatch's `rest` is already the layout MetalFX needs (jitter, motion-vector scale, render and output sizes, reset). Frame generation is a third: keep the previous frame's colour and depth, and interpolate between them with `metalfx::Interpolator` through the same pass. I did not guess at those here: none of them can be checked without a run, and the folder on this machine is 66% downloaded (#636), so a run cannot validate anything yet.
Co-authored-by: AnastasisKon <[email protected]>
Refs #470. imports_by_dll now holds the grouping lib_exports prints with
(DLL names lowercased, DLLs in name order, exports in file order, ordinals
as #N); unit tests pin those rules. No change to the printed output.
It moved above append_ir when the two appends were split, so append_ir
carried two doc blocks and dump_ir had none. Comment move only.
A run that ends in a segfault leaves the log without a line naming the
fault: nothing else says anything when native code faults (#392: a 122 s
run died at "Segmentation fault: 11" with no crash line, after GPU
errors). SIGSEGV, SIGBUS, SIGILL and SIGFPE now write one line to
stderr — the signal, its code and the faulting address — through
async-signal-safe calls only, then re-raise: SA_RESETHAND restored the
default action, so the exit code and the crash report stay as before.

A fork test checks the line, and that the child still dies by the signal
with the status a run without the logger leaves.

Refs #392
Refs #458 measure-first step. Every 64 submissions, one line with the
bytes of texture levels whose title pages are all unmapped, total and per
format (top six): mip-streamed textures are placed whole but their fine
levels map as they stream in, while the host texture is made with the whole
chain. New PoolTable::mapped_len (bytes of a range currently mapped in a
live pool); the level aggregation is a pure function, both pinned by unit
tests. Documented in docs/native-host.md.
Refs #500 (for #461 and #458). submit timing: lines are collected into
count, prep/encode_commit/total sums and the slowest, printed under shader
work and added as --compare rows; unmapped levels: lines keep the last one
verbatim. --self-test covers both.
Stage the built native host executable inside Victory.app beside the Cargo
release output with LSApplicationCategoryType=public.app-category.games and
LSSupportsGameMode=true so macOS Game Mode engages in full screen when launched
via run-native.sh, and mark the NSWindow as fullScreenPrimary.

Promote the title's main thread and CreateThread worker threads to
QOS_CLASS_USER_INTERACTIVE on startup so macOS schedules frame-driving title
threads as interactive work.

Resolve both worktree gitdir and shared commondir refs (loose branch refs and
packed-refs) in apps/victory/build.rs so VICTORY_GIT_COMMIT in the
ScarlettMac Native | <console> (<commit>) window title updates whenever a
commit advances the branch ref.

Closes #533
Folds the two #[cfg(test)] modules in apps/victory/src/inspect.rs into one
(imports_by_dll's tests next to dll_flags's, with both imports), as the
review asked.
run-native.sh is the first thing a tester or an agent runs, and its early
exits are what turn a wrong folder or a forgotten value into a clear message
rather than a confusing run. None of them had a test.

Writing one turned up an inconsistency: the space form already refuses a model
that starts with a dash (the next word is a switch, not a model), but the
--console=<value> form accepted it and handed it to the game, so the mistake
surfaced as the game's parser error. Both forms now answer the same way.

The test covers the usage paths, each refused value, a path that is not a
file, and a folder holding no game_*master.exe: every case stops before a
game would be launched, so it needs no game and no build. It joins the
macos-scripts CI job beside the other script tests.

Refs #580
Keeps both diagnostics entries in docs/native-host.md (main's
VICTORY_SUBMIT_TIMING from the landed batch, this branch's
VICTORY_TRACE_UNMAPPED_LEVELS).
Keeps both sets of self-test chk lines (#494's fatal-signal line landed on
main meanwhile).
Refs #582. The diagnostics list in docs/native-host.md now names VICTORY_LOG
(the log filter, RUST_LOG fallback, diagnostics builds for debug/trace),
VICTORY_NARROW_WAVES and VICTORY_DEBUG_ELSEWHERE (shader-cache-keyed
translator switches), and records that the remaining undocumented VICTORY_*
names are Windows-path-only or tool/test scaffolding.
The three diagnostics-build switches that triage a title assert were
documented nowhere: skipping named int3 asserts (crash.rs skip_list), the
first-chance breakpoints in the crash log, and saving title ranges on a
crash (run.rs, Windows path only). Part of the inventory in #582.

Refs #582
VICTORY_SKIP_PIPELINES takes a group of draws out of a run, but the run
it leaves has nothing to compare against: the frames show either the
scene with them or without them, and two runs of a title never match
frame for frame. Alternating frames lets one run's dumps be compared
directly, which is what a bisect of a broken or dark target needs.

The parity is a pure function over the presents so far
(glue::skip_this_present), counted in present() before it presents, and
read by skipped_pipeline only when the switch is set, so an unset switch
costs one relaxed load.
Unit tests for the u128 scale/saturate in ticks_from_counter (zero,
identity at the native frequency, ratio scaling, round-down, u64::MAX
saturation) and a monotonicity bracket for the live ticks() read.

Refs #584
The switch saved the ranges it names only on the Windows path, from the
vectored exception handler. The native host's equivalent is the fatal-
signal handler, which runs on the faulting thread and may allocate
nothing and take no lock: the fault can have happened in the allocator or
the file system. So crash_save reads the switch and the cache directory at
startup, resolves each range against the title image's base and size into
an address and a length, and turns each path into a C string; the handler
then only calls open, write and close.

A range that does not parse, and one past the image, is left out, as on
the Windows path. The module is built only for the native host (x86_64
macOS, diagnostics), so no other target sees it. Tests:
crash_save::tests::crash_save_takes_hex_pairs_inside_the_image and
crash_save::tests::a_saved_range_is_the_memory_it_named, which drives the
handler's path end to end and checks the bytes it wrote.
Unit tests for the path-to-key mapping (full Windows paths, forward
slashes, bare names gaining .dll, lower-casing, dots in directory
names). Runs under the x86_64-apple-darwin test target.

Refs #587
Unit tests for set_from_thread_state (gpr order, rip, eflags truncation,
cs/fs/gs from the state, ds/es/ss fixed to 0x2B), set_mxcsr's write to
mx_csr and flt[1][8..12], and xmm(i) addressing flt[10 + i]. Runs under
the x86_64-apple-darwin test target.

Refs #589
A forked child cannot test the save: it inherits whatever the parent's
static holds, so a OnceLock it tries to set is already set (its handler
then writes into another test's directory), and a Mutex it tries to lock
can be held by a thread the fork copied. Both were seen; the second hung
the suite. The handler is the wrong place for a lock anyway, so the list
is a OnceLock again, read by an atomic load, and the test that matters
runs in-process: it names a range of its own, calls write_all, and reads
the bytes back out of the file.

The handler's own call is three lines and stays covered by the signal
test beside it, which asserts the process still dies by the signal.
The switch list marks some switches "Diagnostics build only" but says
nowhere that a plain release build compiles them out, so a switch that
does nothing looks like a switch that is broken. The run section now
gives the build command.
Another slice of #582: VICTORY_LOG (the filter every path and build reads,
with the diagnostics build's cap on levels) joins the switch list, and a
new subsection records the switches only the Windows/Wine path and its
D3D12 backend read -- frame capture, the window limit, copies in video
memory, the copy mode, and audio capture -- each with the native host's
equivalent named, so a switch that does nothing on macOS is not a mystery.

Counted after this: 34 of the runtime names are still documented nowhere,
down from 43 (and from 59 before #486 and the crash-triage bullet).

Refs #582
The range list is set before the fork, so the child inherits it and needs
no setup: it installs the handler, raises SIGSEGV, and the parent asserts
the fault line, the signal that killed the child, and the bytes the
handler wrote from the address the switch named. That closes the gap the
in-process test left -- nothing proved the handler ran the save -- without
the failure the earlier attempt had, where the child tried to set the list
itself: a fork inherits a OnceLock already set (its handler then wrote into
another test's directory) and could inherit a held Mutex (it hung).

Stable over six runs, parallel and --test-threads=1.
run-native.sh always launched whatever Cargo's target directory held, so
the switches marked "Diagnostics build only" -- VICTORY_CRASH_SAVE,
VICTORY_SKIP_TITLE_INT3 -- could only be used by hand, outside the script
that sets up the run (keys, console, log, the GPU lock pattern).

native_binary now prints VICTORY_BINARY when it is set, asking Cargo
nothing, and run-native.sh names the variable when that path is not
executable instead of sending the user to native-setup.sh, which is about
the build it would have made. Tests: the resolver prints the path as given
without consulting Cargo, and a path that is not executable stops the run
with a line naming VICTORY_BINARY, both in run-native-args.sh; the rest of
that script's cases still pass, and no case leaves a runs/ directory
behind.
VICTORY_PAIRS, VICTORY_EMIT_DUMP, VICTORY_PREBUILD_KEYS, VICTORY_DXIL,
VICTORY_PC_DXC and VICTORY_WARP were read by apps/victory/src/translate.rs
and the shader checks and documented nowhere, so building one pipeline by
hand -- how a fault is pinned on a pipeline -- had no written procedure.
Each is described from its call site.

Two names I had counted as undocumented are not user-facing at all:
VICTORY_REF_VS and VICTORY_REF_PS sit inside a #[cfg(test)] function in
emit/mod.rs, so the inventory's count is an upper bound (it cannot see test
blocks in non-test files); the issue says so.
Carried into this fork from tarcisioads's open pull request, which is
Closes #571 upstream: a raw root SRV (opcode 11) whose root parameter names
no resource type is now lowered as the SRV it is, as the raw root UAV
(0x100B) and root CBV (13) arms beside it already were.
Carried into this fork from Sheffy007's open pull request (#533). Its
run-native.sh hunk collides with this fork's VICTORY_BINARY change in the
same place; both are kept: the refusal names VICTORY_BINARY when that is
what pointed at the path, and the run then stages the Game Mode bundle from
whichever binary was resolved.
Ports the resolution module kept on lit-world/base-3 (itself ported from
avatarmanz/VIctory-7900XTX): the title picks its output size from its own
five-mode display list and renders a fixed 2/3 of it through its own
upscaler, so neither could be changed from the host side at all. This
patches the blocks that decide them at load, byte-checked first:

- VICTORY_OUTPUT=<w>x<h> takes the settings' size, the screen-size writer
  and the back buffers, and jumps the back-buffer pool's int3 off 4K;
- VICTORY_RENDER_SCALE=<0.5..1.0> replaces the 2/3 the title's own
  upscaler multiplies by, so it renders less and scales up: the render
  cost lever on a Mac;
- VICTORY_UPSCALER=<6|7> makes its picker return its own or FidelityFX.

Applied with --execute only, before bind/TLS/DllMain, while the image is
still writable. A site whose bytes differ is left alone and logged, so a
build these offsets were not measured on is unchanged. The hang-watchdog
patches base-3 carries beside these are not ported: main's build table has
no such entries.

Tests: the module's own five (parsing, the output block and its else path,
the scale codes, and the macOS write_together check that validates every
site before writing any). Full workspace green, clippy clean on the Windows
target, policy ok.
The IR and Metal have no f64, so the conversion is emulated in i64 ops:
the source register pair holds the IEEE-754 double bits, the result is
the f32 bits with round-to-nearest-even. The emitted sequence mirrors
cvt_f32_f64_reference, pinned against f64 as f32 over millions of
patterns, plus a lowering test (host) and a GPU execution test
(Windows CI). One of the refused shaders of #531.

Refs #531
The present pass takes the title's plane with a bilinear full-screen
triangle, so everything above the plane's own size is a stretch. MetalFX's
spatial upscaler does that pass with its own reconstruction instead.

MetalFX is not linked and its classes are not in the Metal bindings this
crate uses, so metalfx.rs opens the framework with dlopen and drives
MTLFXSpatialScalerDescriptor by message sends. Its properties, as the
runtime lists them, are the two formats, the two sizes and the colour
processing mode -- not outputTextureUsage, which an earlier version of
this sent and which turned out not to exist. The scaler and the texture it
writes are made once per size and format pair and cached on the surface;
a format MetalFX or the triangle cannot take, a system without MetalFX, and
matching sizes all fall back to the triangle with a single line.

MetalFX's temporal scaler and its frame interpolator are on this system
(macOS 27.3 reports all three classes), and metalfx::temporal /
metalfx::interpolator report that, but neither can be driven: they need the
frame's depth, motion vectors and jitter, and the interpolator the previous
frame's colour and depth plus a UI texture. Nothing in this backend knows
which of the title's textures holds depth or motion vectors, so that
identification is the first step of any such pass, and the module says so.

Tests: metalfx::tests::metalfx_says_which_scalers_the_system_has and
a_spatial_scale_runs_on_the_gpu (64x64 into 128x128 on the GPU), and
present::tests::metalfx_scales_the_plane_up_into_the_drawable, which
presents a 2x2 red plane into an 8x8 drawable through the switch and reads
the red back out of the drawable. Full workspace green (39 suites), clippy
clean on the Windows target, policy ok.
Both are drivable from here now: the descriptor's and the instance's
setters are as the runtime lists them, with the types it reports -- `Bool`
for the reset flags and `f32` for the scalars, since `bool` has no objc2
encoding. A test encodes one of each on this machine's GPU and waits for
the command buffer, and both complete.

Neither is on a path yet: each needs the frame's depth, its motion vectors
and a jitter offset, and nothing here identifies which of the title's
textures holds depth or motion vectors. What is missing for a temporal or
interpolating pass is those inputs, not the MetalFX side.

Two differences from the spatial descriptor, from its property lists: the
temporal one has no colour-processing mode, and the interpolator's takes
no mode either but wants a previous colour texture per frame.
With `VICTORY_METALFX=spatial` a frame with one plane was scaled into a
texture the size of the drawable and then drawn from it by the full-screen
triangle: at 4K that is a write of the whole frame, a sampled read of it and
another write, per frame. MetalFX writes into whatever output texture it is
given, so with nothing to composite over the plane it fills the drawable
itself and the triangle has nothing left to draw.

A frame with a second plane (a video overlay) still needs the triangle to
blend it, so that one keeps the intermediate, made on first use instead of
with the scaler.

The tests hold both: a single-plane frame leaves the triangle count
unchanged where the same frame with the switch off draws one, and every
pixel of the drawable is the plane (corners included), while a second plane
still composites over the scaled first.
The whole command buffer's GPUEndTime - GPUStartTime cannot tell a slow pass
in a world frame from the others. With VICTORY_PASS_TIMING=1 (or =<n>), an
MTLCounterSampleBuffer of the timestamp counter set is sampled at each pass
encoder's start and end (stage-boundary sampling), resolved when the command
buffer completes, and at each present the frame's n most expensive passes
(10 for =1) are logged most-expensive-first by pipeline (shader hash) and work
(draws, thread groups, blit ops), then the frame total.

Only encoder kinds the device reports as sampling at their own boundary are
sampled (dispatch/draw/blit): Metal asserts on sampleCountersInBuffer for an
unsupported kind, and support differs per GPU family (a G15X samples dispatch
and draw boundaries, not blit). A render pass with indirect draws starts its
sample pair on its gate encoder when compute boundaries are sampled, so the
gate's time is inside the pass's. Split submissions (VICTORY_PASSES_PER_BUFFER)
get one sample buffer per piece. Passes whose kind is not sampled are not
labelled, keeping sample indices aligned with labels.

Off by default; needs a device with the timestamp counter set. New module
pass_timing.rs; sampling hooks in gfx.rs's submit path and completion
handlers; frame boundary at each present in present.rs; pipeline names are
now kept without VICTORY_TRACE_GPU_FAILS so the log can name them. Documented
in docs/native-host.md. Test: a synthetic two-pass command buffer (blit fills
or a zero-draw render pass, whichever the device samples) yields one resolved
sample per pass.
The texture scanner already read a changed texture whole on its own
thread; the submission then read the same memory again to detile it.
The scanner now keeps those bytes (up to 64 MiB per texture, 512 MiB
in all, evicted oldest-first) and the submission's Job detiles them
directly, halving the reads of scanner-found changes. Torn stashes
self-heal: the next round's hash differs and the texture is read whole.

The sync read threads were a fixed 6; they now use all the host's
cores but two (sync_threads), so an 8-core M1 uses 6 and a 12-core
M1 Pro 10.

Refs #179
A title whose state changes per draw makes thousands of pipeline variants a
minute, and `Libraries` kept every one for the run: it had no release path at
all (`glue::pipe` drops its per-object entries on release, the library table
it looks them up in kept its own copy). Each entry is a Metal pipeline, so
the tables and the memory behind them grew without a limit.

Each table now drops its least recently used half past 8192 entries
(`VICTORY_PIPELINE_CACHE` overrides the count, `0` keeps none). What is kept
is what was used most recently, which is the working set: a world draws
through a few hundred. A dropped pipeline is made again at its next use,
which is a hit in the disk cache rather than a conversion.

The roadmap also gets the scanner's measured cost (blake3 through the
scanner's buffer at 1.76 GB/s, so a round over a world's 7.8 GB of copies is
about 4.4 s of a core) and why a cheaper hash is not the fix.
A traced run (VICTORY_PASS_TIMING=1, #460) logs per-pass GPU times, and the
summary said nothing about them. New section, only when the log has pass
time lines (other logs' summaries are unchanged, golden outputs included):
frames and passes timed, total/mean/max GPU pass time per frame, the run's
slowest individual passes, and pipelines aggregated by total GPU time (by
shader hash). --compare gets pass-timing rows when present. --self-test
gains pass time lines and checks the new output; the Bash 3.2 script tests
(run-summary-compare.sh et al.) still pass.
`run-native.sh` looked for `game_*master.exe` in a game folder and stopped
with "No game_*master.exe found" whether the download was partial or the
folder was the wrong one. The title's manifest names its executable
(`ExecutableList`), and the host already reads that file for the title id and
the persistent storage quota, so the script now takes the name from there
when the file it names is present and keeps the pattern as the fallback.

The message when neither finds anything names the folder and both, which is
what a partial download shows until its executable lands.
At low frame rates the title polls the pad once a frame, so a press and
release between two readings is never seen. With VICTORY_INPUT_LATCH=1 a
button change the title has not read yet waits for its next reading (up
last time and pressed since shows down; down last time and released
since shows up; pressed again shows down again); triggers show their
peak since the last reading, sticks their latest value. Readings within
15 ms agree; with no reading for 2 s the latch lets go. Off by default.

VICTORY_STICK_DEADZONE=<share> applies a round dead zone per stick at
each poll, the rest of the travel spread over 0..1. Off by default.

Ported from halfwave50's VIctory-macOS-halfwave50 (52e0325, GPL-3.0,
credited there). Both switches are per-hub settings read once at start;
tests drive them on a fake hub through GetCurrentReading.

Refs #429
The page table is bound for every stage (Binding::memory, memory_args
in native/host.rs), guessed and described alike, so the gate in
shaders::unsupported refusing a graphics pipeline whose shader reads
title memory through it had no technical reason. Remove it and the
memory parameter that carried it; the dfafaf38/06295fb1 pair (the
first draw of each frame) now gets a host pipeline.

Refs #303
The Windows shader tests validate emitted DXIL with dxil.dll found at
VICTORY_DXIL, else the newest Windows SDK. Note the GDK-X package as a
source (used locally only; never committed, per the asset policy).

Refs #303
A finer mode of #460's switch: =draw (or =draw,<n>) also samples at each
draw/dispatch boundary inside a render/compute pass (one sample per
draw, between the pass's start and end samples), and each logged pass then
names its 3 slowest draws (pass time draw ... draw=<j> ms=<ms>). Blit
passes get no mid samples (no draw boundary). The sample buffer is sized
for the submission's passes plus their draws/dispatches/ops.

The sampling gate stays on the per-boundary supportsCounterSampling points
(draw/dispatch/blit), not AtStageBoundary: an AGXG15X (M4 Pro) reports the
stage boundary yet every encoder asserts on sampleCountersInBuffer
(SIGABRT), so on that GPU family the switch stays off and the tests skip.
Documented in docs/native-host.md. Test: draw_mode_samples_each_dispatch_inside_a_pass
(two dispatches of the test compute shader in one pass yield one pass
sample with two per-dispatch intervals).
#548: ten threads of `cargo test -p victory-gpu` reached 80 command queues
within half a second on a 16 GB M1 Pro, the GPU stopped answering, and the
Mac panicked on WindowServer's watchdog. The same tests one at a time pass,
so `--test-threads=1` is the workaround, and the docs now say so where the
GPU tests are described.

A gate in the library does not work, and this is worth knowing before
someone builds one: a test thread that claims the GPU at its first `Metal`
and holds the claim until the thread ends deadlocks every test that makes a
device on a thread it then joins. Tried here; the `victory-metal` test
binary hung at 0% cpu until it was killed. What would work is a lock taken
by each GPU test body -- about a hundred of them across `native/*_tests.rs`
-- or a permit carried by the `Host`/`Title` a test makes, with room for the
tests that make more than one.
The comment on the attributes said "alignment as log2 (5 bits at 24, 4 bytes
and up from 2), then the memory type, then bit 33", which was read off the
title. The GDK's `xmem.h` says the same and says the rest: the word is
`ObjectType:14, PageSize:2, AllocatorId:8, Alignment:5, MemoryType:4,
Address32BitMapping:1, reserved:30`, and its `XALLOC_ALIGNMENT_*` names are
the log2 of the bytes (`_4` is 2, `_256` is 8).

So the two constants are the union's fields, and a test now builds the word
the way the header's `MAKE_XALLOC_ATTRIBUTES` does and checks what we read
out of it: a 256-byte alignment out of field 8, a memory type at 29 that
does not move it, bit 33 for the 32-bit mapping, and the 16-byte floor for
`ANY`, `_4` and `_8`.
The scanner, the per-submission read, and the GPU-written copy-back all
hashed whole textures with blake3::hash on one core while the other cores
idled. Textures at or above 1 MiB now hash with Hasher::update_rayon, which
splits the input over the rayon pool; smaller ones keep the single-shot
hash. The hash is unchanged: a test checks hash_of against blake3::hash for
sizes straddling the cutoff.

blake3 gains the rayon feature (Cargo.lock: rayon, crossbeam-deque and
deps).

Refs #179

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
A changed texture was detiled mip by mip, slice by slice on one
submission thread; a 4K RGBA texture spends its whole detile serialized
there while the other cores idle. Levels read the tiled bytes and write
only their own staging buffer, so they detile independently:
detile_changed now collects the (mip, slice) work and runs it on the
rayon pool when the texture is at least 1 MiB (smaller ones stay serial,
no pool overhead). The all-zero mip skip checks its slices on the pool
too, and is_all_zero checks big ranges on the pool.

Results are sorted back into mip/slice order, so upload order and the
detiled-mips bitmask are unchanged. A test detile a 1024x1024x4 RGBA
texture (parallel path) and compares every level byte-for-byte with the
serial per-level detile.

Adds rayon as a workspace dependency of victory-gpu.

Refs #179

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
The scanner and each submission read a watched texture's whole memory on
one thread: a 4K texture's 32 MiB were a single memcpy chain while the
other cores idled. read_into now splits buffers over 1 MiB into
par_chunks_mut and reads each chunk independently on the rayon pool
(the PoolTable lock only walks the maps; the copies run outside it), so
Job::read, the GPU-written copy-back and the scanner's big path all
spread over the pool. Smaller buffers keep the single call.

scan_round reads a texture over 1 MiB whole in one read_into and hashes
it in one blake3::hash; smaller ones still stream through its buffer
chunk by chunk.

A test reads buffers straddling the 1 MiB cutoff (parallel path) and
below it byte-for-byte.

Refs #179

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
The scanner thread hashed every watched texture one after another on its
single thread, so a round over hundreds of textures was one long serial
read+hash chain every 5 ms no matter how many cores were idle.

scan_round now maps the watched entries over the rayon pool: each scan_one
snapshots the entry's compare-state under the lock, then reads and hashes
its own texture without holding it (each pool thread keeps a thread-local
scratch buffer), and the results are applied under the lock in one pass
with the same released/changed re-check as before. Semantics are
unchanged: same hashes, same seen/partial/dirty updates, same skip when
the entry was released or a submission began meanwhile.

Refs #179

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
The reverb section of native-host.md and dsp.rs called the hardware's
partitioned frequency-domain IR layout unknown. The public GDK 2026.10
docs (XDSP audio reference and overviews) now specify it, in our own
words: frequency-domain interleaved complex float pairs (N bins = N*2
floats), processed in 512/1024-frame blocks, mono or stereo (stereo IR
doubles the buffer), with an optional trailing reduction block signed
0xFFFFACE1 followed by up to 15 little-endian (u16 cutoff, u16 block
index) entries with strictly increasing block indices; the connection's
base buffer is 64K-aligned physical XMemAlloc memory of at least 64 KB.
Marked as not yet verified against a real run; VICTORY_GUESS_DSP stays
the synthetic fallback until one confirms it. Finding also posted on #17.
The Xbox GDK's console headers were not available to this project before, so
the HLE's struct layouts, result codes and limits were read off the title.
They are now (2026.10 GDKX, `261000/xbox/include`), and three passes over
them turned up six things to fix and a lot to confirm.

Wrong, and fixed:

- DStorage answered a read past the end of a file with
  `HRESULT_FROM_WIN32(ERROR_HANDLE_EOF)`; the code a title matches, and that
  lands in its status record, is `E_DSTORAGE_END_OF_FILE` (0x89240007).
- A request with no decompression accepted a destination larger than its
  length and rejected one with `E_INVALIDARG`; the header requires the two to
  be equal and names `E_DSTORAGE_INVALID_DESTINATION_SIZE` (0x8924000F).
- XGameSave applied a 16 MB cap to a whole update. The header caps one blob
  at `GS_MAX_BLOB_SIZE` (16 MB) and a provider at 256 MB, and states no
  update-level cap, so an atomic save of 20 MB in legal blobs was refused.
- `GS_MAX_CONTAINER_NAME_SIZE` (256) and `GS_MAX_BLOB_NAME_SIZE` (65) count
  the NUL, so names are 255 and 64 characters: we accepted 256 and any
  length at all for a blob, and a display name of any length (128 counts the
  NUL). All three are now refused, at `write_blob` and again at `submit`.
- `GameInputDeviceInfo::deviceFamily` was 0, `GameInputFamilyAggregate`, for
  every pad: a title gating on "not an aggregate bucket" discarded the pad.
  A pad is `GameInputFamilyXboxOne` (1), the keyboard `Hid` (3).
- The game input device table stopped at 0xA0 and answered the two `bool`
  methods with `E_NOTIMPL`, whose low byte is 1: the header's interface ends
  at `ReleaseExclusiveRawDeviceAccess` (0xA8), and a bool we do not implement
  is false.
- `IsFeatureAvailable` claimed accessibility (0) and app capture (1) while
  neither area has an export, so a title that believed it resolved
  `XClosedCaptionSetEnabled` to null. `XError`'s `XErrorSetCallback` and
  `XErrorSetOptions` are now exported as no-ops, so claiming 19 is true.
- `put_string` left `*used` alone on a short buffer, where the headers type it
  `_Out_writes_bytes_to_(size, *used)`: a title sizing its retry read its own
  stale zero.

Pinned by tests, from the headers: `XMemAlloc`'s attribute word
(`ObjectType:14, PageSize:2, AllocatorId:8, Alignment:5 at 24, MemoryType:4 at
29, Address32BitMapping:1 at 33`), `D3D12XBOX_CREATE_DEVICE_PARAMETERS`
(40 bytes, version at 0), and the DStorage result codes.

Confirmed correct, so left alone: every `E_GS_*`, `E_GAMEUSER_*`,
`E_GAMEPACKAGE_*`, `APU_E_*` and GameInput code we return; the save blob,
container and space-info struct layouts field for field; `XAsyncBlock` and
`XAsyncProviderData`; the game-save provider's and the input interfaces'
slot orders; `XNetworkingConnectivityHint`; the console-id, sandbox-id and
package-identifier maxima.
The comment on UNREACHABLE called 0x800704CF ERROR_NETWORK_UNREACHABLE; it is
ERROR_HOST_UNREACHABLE (1231). The GDK's XNetworking.h pins no code for the
offline case, so this is a comment that claimed a vendor rule it does not
have: it now says what the value is and names the neighbouring code a title
might match instead.
# Conflicts:
#	docs/native-host.md
# Conflicts:
#	tools/macos/run-summary.sh
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	crates/victory-gpu/src/native/textures.rs
# Conflicts:
#	Cargo.toml
#	crates/victory-gpu/src/native/textures.rs
# Conflicts:
#	Cargo.toml
#	crates/victory-gpu/src/native/textures.rs
A wave64 compute program the fast path refuses, whose group is several
console waves and a multiple of 64 threads, is retried in lockstep in a
paired form behind VICTORY_PAIRED_WAVES=1 (Options::paired_waves, off by
default): one host wave per console wave, each host thread holding
console lanes n and n + 32. Votes, lane reads and first-lane reads stay
inside one host wave, so nothing crosses host waves and no barrier of
our own is needed; the title's s_barrier is the group barrier.

The design follows TaynanGT/Vice-Tay's paired lanes, lowered our own
way in emit/lower/paired.rs (a second copy of the per-lane state,
swapped per lane). It replaces #438's spinning pair barrier, which hung
the GPU once more groups were dispatched than run at once.

Tests (victory-gpu, Metal): lane reads in groups of two and four waves,
per-wave loops sharing LDS, whole-wave prefix sums behind branches each
wave takes differently (the shape of eee76bf6), the two vote shapes of
#527 under an EXEC skip, a title barrier refused in a divergent loop,
and a world-scale run (4,096 groups of four waves, 5.5 ms on an M1 Pro).

Refs #527
Refs #376
A corpus sweep of the paired form needed a local edit to pass the switch
through. The sweep now reads it as the native host does. native-host.md
records the sweep and game runs alexballvideos-netizen reported on #541.

Refs #527
Rosetta does not implement `rdpid` (`f3 0f c7 /7`), the AMD64 instruction that reads
IA32_TSC_AUX, so a title that reads its processor number faults with SIGILL; with nothing
emulating it, that fault ends in the unhandled-exception path. The SIGILL path already did
the other console-only instructions (`clzero`, `clwb`/`clflushopt`, `monitorx`/`mwaitx`, the
SSE4a `insertq`/`extrq`) but not this one, so it was the one console instruction the native
host could not survive.

The gap was visible in a sibling port that runs the same title through Rosetta: XCL-Mac
(utkarshxdev/xcl-mac) lists `rdpid` among the instructions a Mac has to emulate for it. Its
implementation is GPL-2.0 and this tree is GPL-3.0, so nothing is copied: the decoder here is
written from the instruction's encoding, and the test that covers it is ours.

The value written is 0. IA32_TSC_AUX holds the processor number, and nothing in the native
host pins a thread to a core, so one number is the truth; what matters is that it is a valid
processor number and the same for the thread's whole life, since per-processor state is
indexed with it. Recorded in docs/native-host.md beside the other instructions this path
emulates.

Left alone, and both outside this change: the Windows-only `crash.rs` handler has the same
`rdpid` gap (it is `#[cfg(windows)]`, so it cannot be tested on the native host), and it
emulates `rdpru` where this path does not.
loader(seh): emulate rdpid in the SIGILL path
`rdpru` (`0f 01 fd`) reads MPERF (`ecx` 0) or APERF (1), the cycles at the nominal and at the
actual frequency, into `edx:eax`. Rosetta does not implement it, so on the native host it
faults with SIGILL; the Windows handler in `crash.rs` has emulated it for a while, and this
path had not, which made the same title behave differently by host: a crash on macOS, a
counted instruction on Windows.

Both counters get the time-stamp counter, as `crash.rs` already does: a caller that
differences two reads then sees cycles at one frequency, which is what a core that never
changes frequency reports. A counter it does not know reads 0, as it does on the console.
Flags are left alone, which is what the instruction does. `EMULATED` counts it like the other
emulations, and `docs/native-host.md` lists it with them.

Found by comparing the instruction set XCL-Mac (utkarshxdev/xcl-mac) emulates for the same
title through Rosetta against this path: it lists `rdpru`, and its `insn.rs` documents the same
"no PC equivalent, emulate and step over it" contract. Nothing is copied from it (GPL-2.0
against this tree's GPL-3.0); the decoder is a three-byte compare, and the test is ours.
loader(seh): emulate rdpru in the SIGILL path
shader: carry paired lanes into this fork (#527, #541)
The list of instructions the SIGILL path emulates was written from what titles crashed on, not
from a measurement of Rosetta itself, so it did not say which console-only instructions are
still unhandled. A probe now answers that: one instruction per child, an x86-64 binary run
under Rosetta, SIGILL caught. `clzero`, `clwb`, `monitorx`, `rdpru`, `rdpid`, `extrq`,
`insertq`, `adcx`, `adox`, `rdseed`, `movntss` and `movntsd` all raise SIGILL there;
`clflushopt`, `rdrand` and ordinary code run.

So the hole is five instructions: ADX's `adcx`/`adox`, `rdseed`, and the SSE4a stores
`movntss`/`movntsd`. Recording them rather than emulating them blind: none has been seen in a
run, each is rare in compiled game code, and a wrong emulation of `adcx`/`adox` (they read and
write CF and OF, and nothing else) would corrupt arithmetic silently where a trap at least
names itself.

It also corrects the list: `clflushopt` does run under this Rosetta, so only `clwb` has to be
skipped, and `rdrand` is available where `rdseed` is not.
docs: what Rosetta rejects, measured on an M3 Pro with macOS 27.3
gpu(native): carry mesh-output trimming into this fork (#528, #568)
The title's own code is x86-64 and runs under Rosetta 2 today: the loader maps the console's PE
into the host process and calls Windows APIs. Rosetta is the one piece of the port that cannot be
made native by writing more native host code, so this brings in `crates/victory-recomp`, the lifter
that turns the title's x86-64 into C ahead of time — the first half of the arm64 path, and the half
that needs no GPU, no title at runtime and no Wine to develop.

What it is: an analysis pass (`analyze`, `coverage`), function discovery beyond `.pdata` (call
targets, relocations, exports), and a lifter covering integer ALU, shifts, rotates, mul/div,
`lock`/`xchg`/`cmpxchg`, string ops, `bt*`, BMI1/2, the VEX forms the title actually uses (AVX, AVX2,
FMA, F16C), loads and stores, push/pop, call/ret/jmp/jcc, jump tables, setcc/cmovcc, bsf/bsr/popcnt,
SSE scalar and packed float, conversions and compares. `src/rt_host.c` and `src/rt.h` are the C
runtime the lifted code calls into: hash dispatch over the generated table, import thunks with win64
to native marshalling, host-to-guest callbacks, a per-thread TEB and stack, Zen 2 CPUID/XGETBV/RDTSC.
`docs/recompiler.md` is the design and the measurements.

Not in this change: the arm64 host crate (`crates/victory-rt`) and the `victory-hle` crossings. They
are written on the branch this comes from and land separately; the doc says so where it describes
them.

`cargo xtask policy` refused the crate's source: the allowlist had no `h`, `hpp` or `cpp`, and the
recompiler emits C, its runtime and harness are C with headers, and its tests build C++ fixtures for
MSVC exception tables. Three extensions added, with the reason in `policy.rs`.

Tests: `cargo test -j6 -p victory-recomp --locked` gives 11 suites, 35 passed, 0 failed: the crate's
analyze and lift unit tests, and the differential suites (diff, diff_bits, kat, litmus, e2e,
diff_forms, diff_vex, diff_legacy) that run lifted C against the same code built for x86-64 and
executed under Rosetta. The full instruction-form sweep is opt-in (`VICTORY_FORMS_SWEEP=1`, narrowed
by `VICTORY_FORMS`/`VICTORY_FORMS_LIST`): it is every form of every opcode, each batch a clang build
and an x86-64 run, which is hours. `VICTORY_FORMS=mov,cmp VICTORY_FORMS_BATCH=64` with the sweep on
gives 1 passed in 178 s. `cargo clippy --workspace --all-targets --locked --target
x86_64-pc-windows-gnullvm -- -D warnings` is clean, and `cargo xtask policy` reports 470 files ok.
s_bcnt1 behind a branch translates in a one-wave group (four barriers) and is
refused as DIVERGENT_EXCHANGE in a two-wave group, which is the shape the
lighting computes hit. s_and vcc, exec, mask then s_cbranch_vccz translates at
every group size with no exchange, reading each half's own vcc: where the halves
differ that is not the console's answer, so a lowering has to replace it rather
than only stop refusing it. metal-backend.md records both.
gpu, metal: carry cube/3D views and shadow samplers into this fork (#573, #577)
A group of two console waves voting differently: v_cmp_lt_u32 vcc, 64, v0
leaves wave 0 whole and wave 1 empty, s_bcnt1_i32_b64 counts 64 and 0, and
s_cbranch_scc0 sends the two waves down different arms. The fast path refuses
the program (DIVERGENT_EXCHANGE, #527); the paired form runs it on Metal and
gives each wave its own arm (1 in threads 0..63, 2 in 64..127).
The title ships its own C++ runtime and XCurl.dll, and both import GetProcessHeap, HeapAlloc,
HeapReAlloc and HeapFree straight from api-ms-win-core-heap-l1-1-0.dll rather than reaching the
C runtime's malloc, which ucrt already serves. Nothing answered them: `victory run --list-imports`
on the title's own XCurl.dll showed all four STUB, and a stub traps when it is called.

One process heap, never closed, so GetProcessHeap answers a fixed handle and the other three
forward to the host's malloc/realloc/free - the same allocator ucrt::heap gives the C runtime,
with GetLastError instead of errno. The details that a title can notice are kept: a zero-byte
allocation fails instead of handing back a block the host would let it write, a null block frees
as success, and HEAP_REALLOC_IN_PLACE_ONLY either keeps the block where it is or fails rather than
moving it, so a caller that kept the old pointer is never wrong.

Measured on this machine, against the title's own DLL: XCurl.dll goes from 23 stubbed imports to
19, with the four heap calls binding as host functions. The 19 that remain are CRYPT32's certificate
calls, the registry reads, the WPP tracing calls, RaiseFailFastException and the threadpool wait
calls; none of them is emulated here.

Not done: HeapSize, HeapCreate/HeapDestroy for private heaps, HeapValidate, HeapSetInformation. A
title that asks for a private heap still traps, and no run has shown that this one does.
hle(host_posix): implement the Win32 heap the title's CRT DLLs import
v_cmp_lt_u32 vcc, 32, v0 puts lanes 33 and up in vcc, so exec & vcc is not
zero for either wave and the console runs the guarded body for the whole
wave: every lane stores 7. On the GPU the fast path stores 0 in lanes 0..32
and 7 in the rest, because the branch tests each lane's own vcc bit. Marked
ignored with the observed values; the paired form answers per wave, so the
fix is to run these programs there.
The SIGILL path covers the instructions Rosetta does not run, but five of the ones measured on this
host were still missing, and each is a way the title dies that we could remove without a run.
`rdseed` (`0f c7 /7`; `rdrand` is `/6` and does run) now takes the host's own `rdrand`, or a value
built from the time-stamp counter on a host without it, and sets CF to say the seed is valid.
`movntss` and `movntsd` (`f3`/`f2 0f 2b /r`, AMD's SSE4a) store the low 4 or 8 bytes of the
register: non-temporal is only a hint, so a plain store is the whole instruction. Both decoders
handle the operand forms the instructions have, `rip`-relative and SIB included, through a small
`modrm` reader (`rm`) the two share.

The other two cannot be done this way, and the measurement is why. `adcx` and `adox` add the
incoming CF or OF, and Rosetta hands the handler a saved RFLAGS with every arithmetic flag cleared:
a thread that arrives with OF set (an `add` of 1 to `0x7fffffffffffffff`) is handed `rflags = 0x206`,
IF and the reserved bit. Writes from the handler do take effect — the `adcx` carry out read back as
written, as `rdpid`'s clears and the `clzero` loop's `cmp` do — so only the incoming flag is
unavailable. An emulation would have to guess the carry, which is silently wrong in exactly the
big-integer chains ADX exists for, so neither is emulated and `docs/native-host.md` says so; the
recompiler is where they are handled, since it keeps the flags in the lifted `Cpu`. I had written
both, and the probe below is what showed the second one wrong.

Tests: the probe PE gains `probe_isa`, which runs `rdseed`, `movntsd` and `movntss` and sets a bit
per wrong answer, so a title's own x86-64 code takes the fault in the handler and the checked value
comes back out. `crates/victory-hle/tests/native_probe.rs` asserts 0 bits:
`cargo test -p victory-hle --target x86_64-apple-darwin --test native_probe` gives 18 passed, 0
failed. Unit tests cover the decoders and every addressing form of the shared `rm`
(`cargo test -p victory-loader --target x86_64-apple-darwin --lib`: 43 passed, 3 ignored). The
gates: 27 test suites ok over `victory-hle`, `victory`, `victory-gpu`, `victory-metal`,
`victory-recomp` and `xtask`; `cargo clippy --workspace --all-targets --locked --target
x86_64-pc-windows-gnullvm -- -D warnings` clean; `cargo xtask policy` 472 files ok. Clippy for the
x86_64 host target, which is where this code compiles at all, adds no warnings of its own (the ones
it reports there are already on `main`).
run_group translates with paired_waves, but lockstep is only tried after the
fast path refuses a program. For s_and vcc, exec, mask then s_cbranch_vccz the
fast path accepts and answers per lane, so the retry never runs and the paired
lowering is never reached. Ignored with the answer to expect once the fast path
refuses the shape, which is what makes the retry - and lockstep's mask-as-number
branch - apply.
`victory run --execute some.dll` called the image's entry point the way an
executable's is called: one argument in `rcx` (0), `fdwReason` and
`reserved` left to whatever the registers held. A DLL's entry point is
`DllMain`, which reads all three.

It is now started as `LoadLibrary` starts one: `DllMain(DLL_PROCESS_ATTACH)`
with no `reserved` argument, its `BOOL` result deciding whether it started
(`STATUS_DLL_INIT_FAILED` when FALSE, with the dependencies started before
it detached), a `DLL_PROCESS_DETACH` when it is done, and `DllMain` hearing
of threads from then on. An executable is unchanged.
#527's second shape is `v_cmp_lt_u32 vcc, 32, v0; s_and_b64 vcc, exec, vcc;
s_cbranch_vccz`, a question about the whole wave's mask. The fast structurer
answers it per lane (`vcc & exec`), so lanes 0..32 store 0 where the console
stores 7 in all 128, and no lowering of that form is right: a wave-wide
reduction is not expressible in the per-lane booleans.

`Options::strict_vccz_branch` (off by default, `VICTORY_STRICT_VCCZ_BRANCH=1`,
named in `TRANSLATION_SWITCHES` so it keys the shader cache) makes
`structure::structure_with` refuse such a branch instead of answering it, and
`emit::translate_native` - the stages of `translate_with` after the container is
read, shared with callers that hold a program already - hands that refusal to
the lockstep retry, whose `s_cmp_eq_u64 vcc, 0` answers it for the wave.

Measured on the GPU: `a_vccz_branch_where_the_lanes_disagree_answers_for_the_wave_with_the_strict_switch`
(128 lanes, all store 7, no refusal left); the two pre-existing pins keep
showing what the default form does, and the structure test pins the refusal.
`XGameSaveFiles.h` declares three exports of `xgameruntime.dll` that nothing implemented: a title
that saves through plain files rather than the container API — `XGameSaveFilesGetFolderWithUiAsync`,
`...GetFolderWithUiResult` and `...GetRemainingQuota` — got a raw-import miss, which the loader
serves as a logged zero. So the folder call looked like a successful call whose result was a null
path, and the save code then opened nothing.

They are the container API's provider, seen as a folder. `xgamesave` gains `files_folder`, which is
`Provider::open`'s own root (the title's `saves` folder, the one user's folder under it, then the
configuration id made file-safe) so a file the title writes there is a save every container call
sees, and `files_remaining`, the same quota figure `remaining` gives, taken under the saves lock as
an update's check is. There is no UI to show and no cloud copy, so the async call completes with the
folder at once, as the path and its NUL; the result export is `XAsyncGetResult` with the size the
title passed, which refuses a buffer too small with `E_NOT_SUFFICIENT_BUFFER` and writes nothing.
Both user arguments are unused: there is one local user and the provider is its own.

Tests: `the_file_save_api_hands_out_a_folder_a_file_can_be_written_in` sets a title with a tempdir
storage, asks for the folder, checks it is under `<storage>/saves/<XUID>/` and ends in the
configuration id, writes a file into it, checks the short-buffer refusal writes nothing, and reads
the quota. `title_stub_loads_the_runtime_dynamically` now also resolves the three names through
`GetProcAddress`, so the module's export table is pinned. `cargo test -p victory-hle --lib` gives 161
passed, 1 ignored. The gates: 32 test suites ok over `victory-hle`, `victory`, `victory-gpu`,
`victory-metal`, `victory-recomp`, `victory-loader` and `xtask`; `cargo clippy --workspace
--all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` clean; `cargo xtask policy`
474 files ok.
loader(native): start a DLL image as LoadLibrary does, not as an exe entry
The reason line ("a draw without a host render pipeline (refused or not
translated)") does not say which pipeline was dropped, and it is logged once per
reason for the run, so a log could not name the draws nothing else had explained
(#531's three hashes). Each dropped pipeline now gets one warning of its own with
`pipeline =` its stages' hashes and render targets, up to 64 keys, before the
`VICTORY_TRACE_TARGETS` frame trace that had this detail only under a switch.

Test: `glue::a_dropped_pipeline_is_named_once`.
The roadmap lists "a lane-mask join of an untracked mask" among the largest
refusal groups left, and #524 would lower it in the fast path. Measured here on
the GPU, the paired form already answers one such program the console's way: the
refused join (a mask loaded into s[8:9] under one EXEC, a v_cmp into it under
another, then s_or_b64 and s_and_b64 with EXEC) gives 3 in lanes 0..2, 1 in
3..19 and 0 above in the wave whose compares pass, and 0 in the wave whose are
all empty - which is the console's per-wave answer, not a per-lane one.

So the class needs the paired form (`VICTORY_PAIRED_WAVES=1`), not if-conversion
in the fast path. docs/native-host.md and docs/ROADMAP.md say so, and the test
pins the answer, so a change to the paired lowering shows up here.
`_get_stream_buffer_pointers` is the CRT handing a C++ `basic_filebuf`
the *addresses* of the `FILE`'s `_base`, `_ptr` and `_cnt`, so that the
filebuf and the CRT share one buffer. This host wrote nulls instead.

`msvcp140`'s `basic_filebuf::_Init` stores what it is given as its own area
pointers, so a stream it wrapped held null area pointers: its destructor
then found the stream open, followed the null, and faulted. Every shipped
runtime DLL that starts a C++ runtime over a stream and then shuts down hit
that (the sweep of all 16 ended in `msvcp140+0x4879` nine times, issue #615).

A `FILE*` here is a block of ours either way; it now carries those three
fields after the opaque words, and the function hands out their addresses,
stable for the life of the handle. A handle that is not a stream is refused
with EINVAL, as the CRT does.

All 16 shipped DLLs now start and shut down cleanly: `victory run --execute
--unimplemented zero` over the game folder's DLLs exits 0 for each, where
nine of them previously faulted in `msvcp140.dll`.
hle(stdio): hand out the stream's buffer fields, not nulls
The fast path refuses this program for "no reduction or prefix": a DPP max chain
read at lane 0. In the paired form a console wave is one host wave, and the
answer is the console's - the chain's quad_perm, row_half_mirror, row_mirror and
v_permlanex16_b32 steps never cross the 32-lane halves, so lane 0 holds the lower
half's maximum (31) and lane 63 the upper half's (39), and the scalar step's
`39 >> 1` and `31 << 8` store 19 | 31 << 8 = 7955 in lanes 0..39. The second wave
has an empty mask and stores nothing.

The measurement also corrects a reading of the shape: the console's whole-wave
maximum here is not one number spread over the wave, it is each half's own.
The registry is served for `advapi32.dll`, but a DLL built against the API
sets imports it from `api-ms-win-core-registry-l1-1-0.dll` (and `-l2-1-0`),
and the generic `api-ms-win-core-*` table is consulted first and carries
none of it. Stubbed, `RegOpenKeyExW` returns 0 — which the Win32 layer reads
as "opened", with a null key handed back. `XCurl.dll` then queries that
key and gets an untouched buffer.

Those two names now answer with the same four functions `advapi32.dll`
answers with: the console's `ConsoleMode` key where it is ours, and
"no such key" for every other path, which is what a machine without the
key reports.

`victory run --list-imports XCurl.dll`: 19 stubbed, then 15.
hle(system): answer the registry where the API sets name it
Three tests translate a program with a switch on and assert first that the
default translation refuses it. They read that precondition from `shaders::options()`,
so a run with `VICTORY_PAIRED_WAVES=1` or `VICTORY_STRICT_VCCZ_BRANCH=1` set made
them fail on their own precondition rather than on what they measure.
`default_refusal` pins both switches off, so they hold either way - checked with
the switches unset and with both set.
`wait_on_address_handles_sizes_timeouts_and_isolated_wakes` spawned three
waiters on one address and required the first one spawned to be the one
`WakeByAddressSingle` reached. A single wake reaches the waiter that
registered first, and three spawned threads register in whatever order the
scheduler starts them: the test failed about one run in three here.

It now reads all three after the wake and requires exactly one of them to have
returned, then the broadcast to reach the rest — which is what Win32 promises —
and that neither reaches the fourth waiter on the other address in the same
stripe.

10 runs of the test and 3 runs of `victory-hle`'s suite: no failures, against
one in three before.
test(hle/sync): assert what a single wake guarantees, not which waiter
`XCurl.dll` (and the runtime components that trace) import the classic
provider from `api-ms-win-eventing-classicprovider-l1-1-0.dll`, which nothing
answered: stubbed, `RegisterTraceGuidsW` returns 0 — "registered", with a
null registration — and every gate after it reads a logger that never
existed.

This host has no ETW, so the six now answer as a machine with no trace session
does: a registration with a non-null token, no logger, no enable level, no
flags, and a `TraceMessage` that drops what it is handed. `advapi32.dll`, where
the classic API also lives, answers them too.

`victory run --list-imports XCurl.dll`: 15 stubbed, then 9.
hle(system): answer classic (WPP) tracing where the API sets name it
`addr_stripe` mixes the page bits in (`(addr >> 2) ^ (addr >> 12)`), so the
address the test took for granted — 128 bytes past the first one — is in the
same stripe only while it does not cross a page boundary. When the allocation
happened to sit in a page's last 128 bytes, the premise failed and the test
panicked before testing anything: two runs in five here.

It now walks forward to an 8-byte-aligned address whose stripe really matches,
and asserts the invariant it found rather than assuming it.
test(hle/sync): find an address that really is in the same stripe
Every helper in `split_wave_tests` read `shaders::options()`, so running the
suite with `VICTORY_PAIRED_WAVES=1` or `VICTORY_STRICT_VCCZ_BRANCH=1` set made
twelve refusal pins translate instead and fail. `defaults()` names the default
translation - both switches off, the rest of the host's options - and the
helpers, and the per-test translations, use it. The pins are the same pins, and
the switch-on behaviour is measured where a test asks for it (`several_waves`,
explicit `Options`).

Checked with the switches unset and with both set: 492 passed, 0 failed, 10
ignored, both ways.
The strict refusal covered both `s_cbranch_vccz` and `s_cbranch_vccnz`, but only
the first was measured. With the negated form on the same split mask
(`v_cmp_lt_u32 vcc, 32, v0; s_and_b64 vcc, exec, vcc; s_cbranch_vccnz`), neither
console wave's mask is zero - wave 0's lanes 33..63, wave 1's whole wave - so
neither takes the branch and every lane keeps the 0 written before it, where the
fast path's per-lane reading leaves the 7 in lanes 0..32 of wave 0.

Measured on the GPU: 128 lanes all store 0, no refusal left. The default
translation takes the shape, which is the defect the switch exists for; the
ignored pin keeps that answer.
#14 replaced the address the wake test assumed with a search forward for one in
the same stripe. The stripes repeat per page — `addr_stripe` is
`((addr >> 2) ^ (addr >> 12)) & 31` — so a 128-byte search only finds a match
while `a` is far enough from the end of its page, and the test still panicked,
now on its own `expect`, on one run in fifteen.

It now steps 128 bytes on whichever side of `a` still has room in its page,
which is deterministic: the buffer is two pages, and `a` is a page into it, so
one side always does.

20 runs of the test and 15 runs of `victory-hle`'s suite: no failures.
test(hle/sync): take the neighbour on the side of the page that has room
`VICTORY_DUMP_DSP` is process-wide and so is the counter that numbers each
stream's capture, so a stream another test activates while the variable is set
takes `stream0_*` — and the dump test, reading the right file name, got that
stream's zeros:

```
panicked at modules/dsp.rs:949:
assert_eq!(read_f32("stream0_ir.f32"), ir)
  left: [0.0, 0.0, ... ]
```

One run in four of the whole suite, never alone. The two tests that activate
streams now take a turn, so nothing can start a stream inside the other's
capture.

15 runs of `victory-hle`'s suite: no failures.
test(hle/dsp): the two tests that activate streams take turns
`glue::warn_drop_pipe` names each pipeline a draw or dispatch was dropped for,
once per pipeline; the summary read those lines as one more template in the
dropped-work list. They now have a section of their own - how many were named and
the pipelines themselves - and the `--compare` table carries the count, so a
before/after run says which pipelines gained a host pipeline.

The self-test log has such a line, with the escaped shader hashes and targets
tracing writes, and checks the section and the count.
The Winsock tests take a turn (`serial()`) because the startup count is the
process's — but `modules::net`'s `only_loopback_is_reachable` drives the same
functions by name (`host!("ws2_32.dll", "socket")`, `connect`,
`WSAConnectByNameA`, `WSAIoctl`, `closesocket`) without it. It can therefore
start the stack up inside `off_machine_traffic_is_refused`'s "not started
again" assertion, or take an ephemeral port inside
`final_cleanup_invalidates_sockets_and_releases_their_ports`'s rebind of one it
just released — the two winsock failures reported in #616.

The turn now lives in `host_posix` (`winsock_turn`), and both modules take it;
it is compiled only where that host is. The Winsock module alone never failed
(0 of 20 runs), which is what pointed at the other module rather than at the
socket code.

12 runs of `victory-hle`'s suite: no failures.
test(hle): take one turn for everything that drives Winsock
`XCurl.dll` imports `CertOpenStore`, `CertFindCertificateInStore` and
`CertFreeCertificateContext` from `CRYPT32.dll`, plus `RaiseFailFastException`
from the error-handling API set. All four were stubs, so the loader filled them
with the same do-nothing routine: `CertOpenStore` answered zero, which a caller
reads as "the open failed", but `CertFindCertificateInStore` answering zero is
the same as "no such certificate" and `CertFreeCertificateContext` answering
zero means "that handle was invalid".

This host has no certificate store, so the open says so - null with
`ERROR_FILE_NOT_FOUND` - rather than handing back a handle that cannot be read.
The lookup reports the same, and freeing a certificate nobody has is a success.

`RaiseFailFastException` is not a call to ignore: its whole purpose is that the
process stops. It now logs the code from the exception record and exits with it,
which is what the title will see. It is deliberately not covered by a test that
calls it.

Measured with `victory run --list-imports --unimplemented zero XCurl.dll`: the
dll's stubs go from 9 to 5. What is left is the threadpool-wait family and
`CryptStringToBinaryW` (left alone on purpose: a subtly wrong base64 decode
corrupts proxy-auth headers silently, and a visible refusal is better).
hle(crypt32): answer the certificate-store calls, and fail fast honestly
`CreateThreadpoolWait`, `SetThreadpoolWait`, `WaitForThreadpoolWaitCallbacks`
and `CloseThreadpoolWait` were stubs, so `XCurl.dll` armed a wait and its
callback never ran: a connection that was meant to complete on an event simply
never completed, with nothing logged to say why.

A wait is now a worker of its own that blocks on the title's handle through the
host's own waitable objects, the same ones `WaitForSingleObject` takes, so an
auto-reset event is consumed by the wait exactly as Windows consumes it and a
semaphore or mutex is taken the same way. The callback is called once per
arming, with the wait result Windows passes as its fourth argument - zero for a
signalled object, 258 for a due time that passed first - and one callback per
arming is what makes a wait on an object that stays signalled safe rather than a
callback loop nobody asked for. Arming again, a null handle, a cancel, or a
close retires the arming: the worker notices within a slice of 20 ms, so
`WaitForThreadpoolWaitCallbacks(TRUE)` and `CloseThreadpoolWait` return instead
of blocking until the title's object happens to change.

`PoolState` grows `armed`, so "nothing of mine is still pending" covers a worker
blocked on an object and not only a queued or running callback.

Measured with `victory run --list-imports --unimplemented zero XCurl.dll`: stubs
go from 5 to 1, with only `CryptStringToBinaryW` left. `victory run --execute
--unimplemented zero` on all 16 shipped dlls: 16 exit 0.
hle(threadpool): arm real waits on the title's objects, not stubs
This was the last stub in `XCurl.dll`, and the one left deliberately: the dll
decodes the user name and password out of a proxy URL here, and a decode that is
plausible but wrong corrupts the auth header with nothing to show for it.

So it is decoded for real, against RFC 4648: four characters to three bytes,
`=` once at the end, whitespace anywhere as encoders wrap lines, and the armored
flavours read past the dashes and header lines to the body, reporting the
encoding used and how far in the body began. What is not base64 is
`ERROR_INVALID_DATA` rather than a best guess, a character left over from a
truncated group included, and data after the padding included. Hex and the other
encodings stay unanswered with `ERROR_INVALID_PARAMETER` and a warning, because
nothing here asks for them and guessing at them would be the same mistake in
another alphabet.

The rest is the contract a caller depends on: a null buffer is the size query,
a buffer too small is `ERROR_MORE_DATA` with the size it needs, and
`CRYPT_STRING_BINARY` copies.

The tests caught one mistake in this change while it was being written:
`CRYPT_STRING_BASE64_ANY` is six, so a bit test for binary read armored text as
a plain copy. The format is matched as a value now.

Measured: `victory run --list-imports --unimplemented zero XCurl.dll` reports 0
stubbed imports, down from 23 at the start of this work, and all 16 shipped dlls
still exit 0 under `--execute --unimplemented zero`.
hle(crypt32): decode CryptStringToBinaryW rather than stub it
`GetStdHandle` and `ExitProcess` were not implemented at all, so the loader
stubbed them. Both then do nothing visible, and both are wrong in a way that
hides:

- `GetStdHandle` answered zero, which is not a handle: a library that writes its
  own diagnostics through it writes them nowhere, and reads nothing from it.
  It now hands back a handle to a copy of the host's descriptor, made the same
  way an opened file is, so `WriteFile` and `ReadFile` take it. The same handle
  comes back on every call, as on Windows, and a value that is not one of the
  three streams is refused rather than guessed at.

- `ExitProcess` answered as if it had exited, and the title's threads carried
  on. It now ends the process with the title's code. The images still detach
  first, through the exit table registered when the first one attached, which is
  `ExitProcess`'s order.

Both are on `vcomp140.dll`'s import list, so the OpenMP runtime the shipped dlls
link was getting silence from both.

Measured: `victory run --list-imports --unimplemented zero vcomp140.dll` reports
17 stubbed imports, down from 19, and the 16 shipped dlls still all exit 0 under
`--execute --unimplemented zero`.
hle(process): answer GetStdHandle and ExitProcess
Six calls `vcomp140.dll` (the OpenMP runtime the shipped dlls link) and
`concrt140.dll` import were stubs, so each answered zero and said nothing:

- `LocalAlloc` hands back a block from the process heap, zeroed when
  `LMEM_ZEROINIT` is asked for, and refuses a movable block instead of calling a
  pointer a movable handle. `LocalFree` still keeps nothing to free, which this
  note on the function says, so a title that allocates in a loop would grow.
- `lstrlenW` counts the characters, and a null string is length zero.
- `lstrcmpiW` compares by folding case a character at a time rather than by the
  host's locale, so an accented letter folds too.
- `GetUserDefaultUILanguage` answers the language the locale here already
  answers with.
- `GetSystemTimeAdjustment` says what is true: the clock is not adjusted, and
  the increment is Windows' 15.625 ms in 100 ns units.
- `FlushProcessWriteBuffers` is the fence that call means, since the host's
  memory is already coherent between threads.

Measured: `vcomp140.dll` stubs go 17 to 12 and `concrt140.dll` 2 to 1, with all
16 shipped dlls still exiting 0 under `--execute --unimplemented zero`.
hle(system): answer the obsolete strings, LocalAlloc and the clock's adjustment
This was the last stub in `concrt140.dll`. The C++ concurrency runtime
duplicates a handle so two of its own objects can wait on the same thing; a stub
answered false, so the second one waited on nothing, with no error to say so.

A duplicate is now a second handle to the same object. Every kind of object is
shared with its handle already, so the copy shares the state the way Windows does
- an event's signal, a file's position, a thread's end - and closing either
handle leaves the other. `DUPLICATE_CLOSE_SOURCE` closes the source as part of
the duplication, which is how a caller moves a handle. A handle from another
process is refused: it is not in this table, and pretending otherwise would hand
back a handle to something else.

Measured: `victory run --list-imports --unimplemented zero concrt140.dll` reports
0 stubbed imports, and all 16 shipped dlls still exit 0 under `--execute
--unimplemented zero`.
hle(handles): duplicate a handle rather than stub DuplicateHandle
`vcomp140.dll` writes its diagnostics with `WriteConsoleW` and asks first
whether there is a console to write to. All three calls were stubs, so the answer
was "no console, and the write went nowhere": the OpenMP runtime's own reports
were dropped with nothing to say they had been.

There is a console here, because the host has streams: `GetConsoleWindow` answers
a handle of its own, the way `CreateWindowExA` answers for a library's message
window, and `GetConsoleScreenBufferInfo` answers the 80x25 screen buffer with the
attributes a Windows console starts with. Nothing draws on that handle.

`WriteConsoleW` converts the title's UTF-16 and writes it to the stream it names
- stderr for the error handle, stdout otherwise - and reports the count in
characters, as Windows does, not in the bytes the host wrote.

Measured: `victory run --list-imports --unimplemented zero vcomp140.dll` reports
9 stubbed imports, down from 12, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(console): a console that answers, and writes that reach a stream
Whether `VICTORY_PAIRED_WAVES` and `VICTORY_STRICT_VCCZ_BRANCH` should be the
default needs two numbers nobody could get without running the title twice: what
they bring back, and what they take away. `warm::switch_delta` answers both from
the containers earlier runs kept: each is translated twice, once as the defaults
do and once with both switches on, and counted as translated both ways, recovered
by the switches, lost by them (translated today, refused with them - the risk a
default flip carries), or refused both ways. Nothing is written to the cache,
whose keys part by the switches anyway.

`--compare-switches` needs `--cache`, is refused on a Windows host (only a Mac run
keeps containers), and the count itself is pinned by
`warm::tests::a_switch_recovers_or_loses_a_container`.

Tried here: no containers kept yet, so it stops with "no containers kept in
~/.cache/victory/cache/native-shaders/containers yet: run the title once, then
compare the switches".
Five calls `vcomp140.dll` imports were stubs, so the OpenMP runtime's work queue
never ran its item, its thread start got null back as if the thread had failed,
and the attribute list it builds answered false with no error to say why.

- `QueueUserWorkItem` runs the callback on a thread of its own, with its context -
  the legacy work queue's whole job.
- `CreateRemoteThreadEx` starts a thread of this process, with the attributes it
  was handed applied to nothing, which is what they would apply to here. A thread
  in another process is refused: it is not this process's to start.
- `InitializeProcThreadAttributeList`, `UpdateProcThreadAttribute` and
  `DeleteProcThreadAttributeList` describe a process this host does not start, so
  they say so with `ERROR_NOT_SUPPORTED` rather than leaving a list that accepts
  attributes and applies none. The size query still answers the size, since that
  is what a caller asks before it allocates.

Added to the loader's table, and the test for these names asks that table rather
than this module's, which is the mistake it caught the first time it ran.

Measured: `victory run --list-imports --unimplemented zero vcomp140.dll` reports
4 stubbed imports, down from 9, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(threads): run queued work, start threads, and refuse process attributes
`vcomp140.dll` sizes the OpenMP pool from this call. It was a stub, so it
answered false with no error: the runtime fell back to whatever it could guess,
and a title's parallel loops would not have known what the machine is.

The cores are described now, one entry per logical processor with its own bit in
the single group, and each carries an efficiency class from `hw.perflevel0` - 6
of this host's 12 cores are the fast kind, so the first six say so and the
scheduler's placement is not blind. The package entry covers every processor, and
the group entry says the same about the one processor group.

Caches and NUMA nodes are refused with `ERROR_INVALID_PARAMETER` and a warning
rather than described with numbers made up: an entry that a caller parses as a
cache it does not have is worse than no entry. `RELATION_ALL` gives the entries
this host does answer, each tagged with its own relationship.

Measured: `victory run --list-imports --unimplemented zero vcomp140.dll` reports 3
stubbed imports, down from 4, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(sysinfo): describe the processors to GetLogicalProcessorInformationEx
The counts say whether a default flip is safe; the names and reasons say what to
look at when it is not. A container a switch changes is now printed under "lost:"
or "recovered:" with the refusal of the mode that refused it - the switch's own
for a lost one, the defaults' for a recovered one - the first 40 of the run, 10
printed, and logged with the container's kept name so `RUST_LOG` carries all of
them.
`vcomp140.dll` asks for character categories through `GetStringTypeExW`, which
was a stub: every character came back unclassified, so anything the OpenMP
runtime decides by character - whether text is a number, where an identifier ends
- saw a string of nothing.

The classification `GetStringTypeW` already did is now shared by both, and two
things in it were wrong:

- `C1_DEFINED` was never set, so every character read as undefined even though
  the table had just decided it was a letter.
- punctuation was `is_ascii_punctuation`, which makes a guillemet a letter of
  nothing and a non-breaking space punctuation. It is `ispunct`'s rule now: a
  graphical character that is neither a letter, a digit nor a space.

`C1_DIGIT` is now every numeric character rather than the ASCII digits, so a
digit in another script is a digit and, more to the point, is not punctuation.

The bidirectional and width-and-kana tables (`CT_CTYPE2`, `CT_CTYPE3`) stay
unanswered, with a warning that names them, rather than returning zero for every
character as if no character had a direction.

Measured: `victory run --list-imports --unimplemented zero vcomp140.dll` reports 2
stubbed imports, down from 3, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(locale): answer GetStringTypeExW, and classify as the characters are
`FindResourceExW` and `LoadResource` were stubs - the last two in
`vcomp140.dll` - so the OpenMP runtime found no resource where it looks and got
null back for the bytes, with nothing to say whether the resource or the call was
missing.

A lookup now walks the module's own resource directory, read out of the mapped
image's headers: the type, then the name, then the language, each level matching
an integer id or a name without case, as Windows matches it. `LoadResource`
answers with the data's address in the image, which is what Windows also hands
back for a mapped module.

The three ways a lookup fails are told apart, as they are on Windows: a type that
is not there, a name that is not there, and a language that is not there each get
their own error, so a title's diagnostics say which level it was.

Measured: `victory run --list-imports --unimplemented zero vcomp140.dll` reports 0
stubbed imports, the third shipped dll to reach that, and all 16 still exit 0
under `--execute --unimplemented zero`.
hle(resources): find a resource in the image, and load its bytes
`vccorlib140.dll` - the C++/CX runtime every WinRT-facing Xbox component links -
imports the whole `Windows*String` family. All nine were stubs, so every string it
built was null, and every hand-off to a WinRT interface would have carried nothing
where a string belongs.

The nine are answered now: created, borrowed (`WindowsCreateStringReference`,
which copies nothing and writes its header into the caller's `HSTRING_HEADER`),
duplicated, deleted, measured, read, tested for emptiness and for an embedded
terminator, and compared in code unit order over their real length - which is what
makes an embedded null a character rather than the end.

An owned string is one allocation: the count, a 16-byte header, then the
characters, so a duplicate shares it and the last handle frees it. A borrowed
string is never freed, because its characters are the caller's.
`WindowsCreateString(NULL, 0)` answers no handle at all, and no handle answers as
the empty string everywhere, which is what a caller reads without a null check.

The header is 16 bytes on purpose: that fits inside any `HSTRING_HEADER` a caller
allocates, so writing it cannot run past what the caller made.

Measured: `victory run --list-imports --unimplemented zero vccorlib140.dll` reports
24 stubbed imports, down from 33, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(winrt): a working HSTRING, rather than nine stubs
`vccorlib140.dll` imports the COM and WinRT calls a C++/CX component makes before
it does anything else: which apartment it is in, whether it may hand an interface
to another thread, and what a failed call's message was. All were stubs, so
`RoInitialize` answered success without initialising, `CoGetApartmentType` left
its out words untouched, and a WinRT failure carried no message at all.

- `RoInitialize`/`RoUninitialize` keep the thread's model: the first call answers
  `S_OK`, the same model again `S_FALSE`, and another model `RPC_E_CHANGED_MODE`,
  which is what COM answers and what a caller's error path is written against.
  `RoGetApartmentIdentifier` names the one apartment, and the shutdown
  registration is answered and never called back, since nothing shuts down.
- `CoGetApartmentType` says the multithreaded apartment, which is the model
  `CoInitializeEx` here is answered with. `CoAddRefServerProcess` and
  `CoReleaseServerProcess` count callers and stop at zero.
- `RoGetActivationFactory` reports `REGDB_E_CLASSNOTREG` and logs the class name,
  so a title asking for a runtime class this host does not implement says which.
- `RoOriginateError` and `RoTransformError` read the message out of its `HSTRING`
  and log it at once, so a WinRT failure inside the title is readable in the log
  even though no `IRestrictedErrorInfo` object is handed out.
- What needs an object behind it - the object context, its token, the
  free-threaded marshaler, stream marshaling, setting error info - is refused
  with `E_NOINTERFACE`, `E_NOTIMPL` or `S_FALSE` as the case is, because a
  refusal a caller checks beats an object that does nothing.
- `CoTaskMemAlloc` gives a block from the process heap.

A test caught an overflow in `CoReleaseServerProcess` while this was being
written: the count could go below zero, which in a debug build is a panic and in a
release build a wrap to four billion callers.

Measured: `victory run --list-imports --unimplemented zero vccorlib140.dll` reports
3 stubbed imports, down from 24, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(com): answer the apartment, task memory and WinRT initialization
Open a title thread by its id and report it back
`victory-gpu`'s and `victory-metal`'s GPU tests in parallel have hung an M1 Pro's
GPU and panicked the Mac, WindowServer's watchdog 120 s later (#548); the reporter's
advice was `-- --test-threads=1` until the tests serialize themselves. The script
every agent and tester runs for the native host now sets `RUST_TEST_THREADS=1`
unless the caller already has one - libtest reads it, and an explicit
`-- --test-threads=N` still wins - so the default is safe on a machine somebody is
using, and the CPU-only crates pay a little wall clock for it.

`tools/macos/tests/test-native.sh` pins it with a stub toolchain: the default, a
caller's own `RUST_TEST_THREADS`, and the converter check that stops before cargo
(#379).
`vccorlib140.dll` imports `SysAllocStringLen` and `SysFreeString` by number
(`OLEAUT32.dll!#4` and `#6`), which is how the C++ runtime reaches them. Both were
stubs, so every `BSTR` the C++/CX layer built was null and nothing it made was
ever freed.

The family is answered now, by name and by the ordinals `oleaut32.dll` has always
had: allocate from a NUL-terminated string, allocate with a caller's length,
reallocate either way, free, and measure in characters and in bytes. A `BSTR` is
what it is on Windows - the characters, with their byte length in the four bytes
before them - which is what lets a terminator be a character of its own, and a
length of nothing be a string that is not null.

The other half of this was the gate: `oleaut32.dll` was not on the host policy's
list, so its names were never even asked for. It is now, with `combase.dll`, which
answers the WinRT activation calls through the same policy.

Measured: `victory run --list-imports --unimplemented zero vccorlib140.dll` reports
0 stubbed imports, down from 3, and all 16 shipped dlls still exit 0 under
`--execute --unimplemented zero`.
hle(oleaut): a working BSTR, reached by ordinal
`_aligned_offset_malloc` was the last stub in `vccorlib140.dll`, and the one the
CRT's own decorated types are allocated with: a pointer that sits `offset` bytes
past an aligned address, so a structure can carry a header of its own and keep its
body aligned.

Answering it meant the aligned family needed a header: `_aligned_free` was
`free(pointer)`, which cannot work once the pointer is not the block's start.
Every aligned block now carries the block to free and the size that was asked for
in the 16 bytes before its pointer, which also makes `_aligned_msize` answer the
size the caller asked for rather than the host allocator's own idea of it - the
number `_aligned_realloc` copies.

Measured: `victory run --list-imports --unimplemented zero vccorlib140.dll` reports
0 stubbed imports, and all 16 shipped dlls exit 0 under `--execute --unimplemented
zero` with no stubs between them.
hle(heap): answer _aligned_offset_malloc, and let an aligned block be freed
Answer the processor count, the processor number and a thread's name
Closes #617. Six calls a job system or a crash reporter asks for had no
implementation, so they landed in the loader's stub and answered zero without an
error. The worst of them was `GetActiveProcessorCount`: a pool sized by it decided
the machine had no processors, and nothing failed.

- `GetActiveProcessorCount`, `GetMaximumProcessorCount` and
  `GetActiveProcessorGroupCount` answer this machine: one group with every
  processor in it, and no other group.
- `GetCurrentProcessorNumber` answers a processor that exists. The processor a
  thread last ran on is not something this host can ask, and Windows only promises
  a hint, so the thread's own id decides.
- `GetProcessIdOfThread` answers this process for the calling thread's pseudo
  handle and for any thread of the handle table, and refuses anything else.
- `SetThreadDescription`/`GetThreadDescription` keep a thread's name - what a
  crash reporter prints next to a fault - per thread, handing back a
  `LocalAlloc`ed copy as Windows does, and answering success with no string for a
  thread that has no name.
- `GetThreadPriorityBoost`/`SetThreadPriorityBoost` keep and report the setting.
  Nothing about the host's scheduling changes, and the call says what it was told
  rather than inventing a value.
- `SetThreadStackGuarantee` accepts the caller's number and leaves it: the title's
  stack is a fixed reservation here.

One mistake was caught while writing this: `Option<T>: From<T>` made a
`LocalAlloc(...).into()` read as `Some` even when the allocation failed, which
would have copied the name to a null pointer.

Measured: the six names resolve under their own API sets, all 16 shipped dlls
still exit 0 under `--execute --unimplemented zero`, and the HLE suite is 429
tests, six of them new here.
#15's leading guess is that a refused shader's unordered access keeps what it held
and the CPU reads it later; that guess is only checkable if the log says which
textures. A dropped dispatch now warns with `uavs=`, the same list the frame trace
had only under VICTORY_TRACE_TARGETS, and only the first time for each pipeline -
with the trace on, every drop is still counted, not printed.

`first_drop_pipe` splits "is this the first of its pipeline" from the log so a
caller can add what only the first line is worth computing.
hle(process): the processor and thread calls a job system asks for
The counts say whether the switches are safe; nothing said which translation gap
to take next. Containers neither mode translates are now counted by their refusal
reason, offsets blanked so one defect is one line (`reason_key`: "GFX10 code at
0x120: ..." and "at 0x4f8: ..." are the same), and the ten most common printed.

Pinned by `warm::tests::a_refusal_reason_is_counted_without_its_offsets`: offsets
blank, an `0x` with no hex digits left alone, a reason without one unchanged.
Two runs of the same commit with `VICTORY_PAIRED_WAVES` or
`VICTORY_STRICT_VCCZ_BRANCH` set and unset were indistinguishable in their logs,
which is exactly the comparison the switches are meant to be judged on.
`run-native.sh` now writes `# switches ...` in the header (or `none`), listing the
switches that are set among the ones that change translations, and
`run-summary.sh` prints them under the header and carries a `translation switches`
row in the `--compare` table.

Checked by hand: the header block with both set and with neither (no `set -u`
complaint, `none` for the empty case), and the summary reading such a log; the
self-test log and its checks have the line.
`ExitThread` was not served, so a title that called it ran on past the call
with whatever garbage its thread routine left in registers, and the thread's
own exit code never reached `GetExitCodeThread`. It now leaves the entry frame
the loader recorded for the thread (`bridge::exit_title_thread`, which
`_endthreadex` already used), so the thread's `DLL_THREAD_DETACH` notices run
and it ends with the code it passed.

A host thread of ours running a title callback (a thread-pool worker) has no
such frame: there `in_title_thread()` says so and the call sets
`ERROR_CALL_NOT_IMPLEMENTED` and returns, rather than aborting the process
out of `exit_title_thread`'s precondition.

The probe's `probe_threads` starts a thread whose routine calls
`ExitThread(7)` and stores a flag after it: the flag must stay clear and
`GetExitCodeThread` must say 7.
hle(threads), loader: ExitThread ends a title thread where it is called
Map a file's bytes into title memory, and write them back
Report a finished overlapped read to the completion port it belongs to
`FlsAlloc` dropped `lpCallback`: a title that keeps per-thread state in an FLS
slot (a CRT, a job system, a D3D12 allocator) never saw it released, so every
thread that ended leaked what it held.

The slot's callback is kept, and runs with the value the thread holds:

- at the thread's end, through `victory_platform::thread`'s exit hooks, which
  the loader runs on a title thread before it tells the images
  `DLL_THREAD_DETACH` (`spawn_title_thread_with`), and which `FlsAlloc` arms
  with the first callback a title gives (no hook, and no work, until one does);
  a destructor that sets its slot again is called again, four rounds of it, as
  Windows does;
- for the thread that frees the slot, as `FlsFree` does on Windows, with the
  slot's lock not held (a destructor allocates slots of its own).

The value is cleared before its destructor is called, so what a callback sets
in its place is a new value rather than the same one again.

The probe imports the `Fls*` calls and checks both paths: a thread that sets a
value and returns has its destructor run with that value (and the slot reads 0
after), and freeing a slot runs the destructor for the thread that frees it.
hle(fls), loader: run a slot's destructor at thread exit and on FlsFree
Section 3 listed three groups as open that lockstep's paired form and the strict
structuriser already answer per wave, and left the reader to guess whether they
were work to do. They now say so, name the tests and the issues, and point at the
measurement that decides whether either switch becomes the default
(`victory translate --cache --compare-switches`).

Section 1's stale-data guess gets the diagnostic that can check it: a dropped
dispatch names the unordered-access textures it would have written.
Answer the error mode, the priority class and the image's own path
`SubmitThreadpoolWork` (and a timer that was already due) started a bare
`std:🧵:spawn` per submission: 2 MiB of stack and a fresh TEB every time,
for code that reaches title callbacks — where a guessed draw builds Metal
pipelines, which overflowed 2 MiB during the runs behind #559.

Submitted work is now queued and taken by a pool of workers that keeps its
stack and its TEB for the next item, `MIN_STACK` (8 MiB) each, and the pool
starts a worker when none is waiting, up to 12. A timer that has to wait for its
deadline, a repeating timer, and every armed wait keep a thread of their own
(same stack), so a long deadline cannot hold a worker the title's work items
need. Cancelling still drops a queued item by its ticket, and the
`WaitFor...Callbacks` calls still wait for queued, running and armed callbacks.

The probe submits one item through the real imports and checks, from title code,
that it ran once and that the TEB stack it ran on is 8 MiB (gs:[8] - gs:[0x10]).
`null_out_pointers_fail_without_leaking_lanes_or_handles` reads the scheduler's
`next_id` before a call that must fail and asserts it did not move. The counter is
one for the process, and the other 27 tests in the module create queues and files
on their own threads, so the assertion failed under `cargo test` whenever one of
them allocated in the window (seen as `left: 10, right: 9` in a gate run).

The tests now take a turn, as `host_posix::winsock_turn` already does for the
tests that own the Winsock startup count: the module's tests are a handful of
milliseconds each, and serial they cost nothing measurable.
hle(dstorage) tests: one test at a time, so a queue id cannot move under another
Copy, replace, move and name a file as the title asks
Tell the title which Windows it is on and what the machine is
Answer the resource size and lock, and the version info inside it
hle(threadpool): run submitted work on pooled workers with a title thread's stack
The write watch publishes a set of ranges into one of two tables and flips `CURRENT`;
the signal handler reads `CURRENT`, then the table it names, then the other one. The
writer can move between those two reads, so the table `CURRENT` named can be the one
being written by the time it is read: both reads come back empty, `classify` calls the
store someone else's, the page stays read-only, and the store faults again — the
process dies with `EXC_BAD_ACCESS`/SIGBUS `KERN_PROTECTION_FAILURE` at the page it was
writing.

Seen as a gate flake: `cargo test -p victory-loader --lib` died in
`native::seh::signal::watch_tests::stores_during_updates_never_escape_the_watch` about
one run in six with 4-16 copies of the test binary running at once, with a crash report
of exactly that shape (`si_addr` = watched page + 8). The handler's rejection was
caught in the act with both tables unreadable at the moment it classified the fault.

- the handler looks again, up to 128 times, when the table `CURRENT` names cannot be
  read: a write is a handful of stores, so the next look finds it whole;
- if it still cannot read it, the fault is the watch's: the page was made read-only by
  the update that is still writing its table, so it is opened and nothing is counted
  (`fault`, the new rule beside `classify`). Reading it as someone else's is what killed
  the process.

Pinned by `watch::tests::a_fault_whose_table_is_being_written_is_the_watchs`, and
exercised under real churn by `watch_tests::a_fault_during_an_update_is_the_watchs`,
which asks the handler directly while another thread swaps the sets.
platform(watch), loader(seh): a fault taken while an update writes its table is still the watch's
`victory translate --cache --compare-switches` counted the containers the
paired form and the strict `vccz` refusal change between them, but not which
of the two does the work: flipping one switch and then the other was the only
way to find out, and that is not the decision the counts inform (whether to
flip one, the other, or the pair).

Each container the pair changes is now translated twice more, once with each
switch alone, and credited to the switch that gives on its own what the pair
gives: `the paired form alone`, `the strict vccz alone`, or `neither switch
alone` (each alone, or only the two together). Two extra translations, and
only for the handful of containers the pair changes.
List the mapped modules for the title's own crash handler
`run-summary.sh` told how a run ended from the unhandled-exception, fatal-signal,
watchdog and exit-status lines. A run whose GPU failed every command buffer has
none of them: the commands come back as `NSError` with
`kIOGPUCommandBufferCallbackErrorOutOfMemory`, the title keeps running and
presenting, and the summary described that as "killed by --seconds or clean
exit" - the opposite of what happened (the black screen with sound of #569, and
the OOM before the torn world of #521).

The last out-of-memory now decides: `-- how it ended` names the count, the
OutOfMemory lines and when the last one happened, says whether frames continued
after it ("the title kept running after it: sound without pictures") or that
nothing ran after it, and the `--compare` row reads `GPU out of memory` ahead of
the time limit (an exception, a fatal signal or SIGSEGV still come first).

Checked on the M5 Pro 24 GB log of #569 (series-s, series 1.0.2.1): GPU at
frame~2428 after 20 OutOfMemory command buffers, frames continuing to 2440 -
which is the tested symptom, stated as the run's ending.
VICTORY_PEEK printed the qwords rcx points at whenever rcx looked like a
pointer, by runtime range alone. A register is not a pointer for being
large: the title held 0xfffffffd in rcx at a breakpoint, the read faulted
inside the dispatch that reports faults, and the run wrote 1.8 million
"fatal signal 11 at 0xfffffffd" lines (118 MB of log) instead of dying on
the title's own fault. Both the list and rcx now go through
dump::read_checked, the kernel-checked read the dump already uses, so an
address that names nothing prints as not mapped.
docs/native-host.md documents the switch under the native path's bring-up
diagnostics, and the Windows path has read it since #24, but the native
dispatch never did: asking to skip an assert changed nothing on macOS and
the run stopped at the first int3. The list is read here now, on the same
rule (a breakpoint whose rip is that RVA of a mapped image), the one-byte
int3 is stepped over, and the run resumes as a debugger continues past an
assert. Compiled out without --features diagnostics, as on Windows.
seh(dispatch): read a peeked address through the kernel, not through a pointer
seh(native): step a title int3 assert over where VICTORY_SKIP_TITLE_INT3 names it
A skipped assert logs its RVA on every hit, which says a run was patched but not
what the assert is: the title's sites carry no message string, an inlined
__debugbreak-style int3 followed by a jump. The first step over each RVA now
also logs the chain that reached it, frames in the title image as RVAs and
anything else as an absolute address, so image+0x1330a44 reads as the retry loop
of a stream writer called from a worker's job (0x51d2319 0x248f43e 0x248dc46
0x93886a 0x3751e5f 0x22406ff 0x23cf00a 0x2215eca) rather than a bare address.

Once per RVA: one of the title's asserts is hit a million times a run.
seh(native): name the callers of a stepped-over assert
The line named rax, rcx, rdx, rsp, r8 and r10. A fault in title code
takes its operands where the title keeps them: the object a function was
called for is in rsi or rdi, its size in rbx or rbp, and the call the
fault came from left rcx and r8..r11 as the callee did. Reading a real
assert needed all of them: at image+0x1330a44 the title held the manager
in rsi (0x10000 in rbp, the 64 KiB block it was reading) and the
predicate it had just called left 0xfffffffd in rcx, none of which the
line showed.
seh(native): name the argument registers in the first-chance log
The trap #48 stepped over is recorded only in that pull request's body, so the
next run that meets it starts from nothing. Written down with what names it: the
buffer being written is an SGD5 shader database (33 records, 0x40000 bytes), the
loop is a stream writer's retry, and the check that fails is a name-to-object
lookup on the writer's interface (vtable +0x3f0 with the 64-bit hash
0xE0C12D7A5D4884C5, then +0x3f8 answering the 0xfffffffd sentinel).

The chain the first step over an assert logs puts it on a pool worker, so the
host's thread pool was the first suspect; three runs with submitted work given a
thread of its own fail in the same place, and the completion port and the
console's persistent storage are served or not imported at all, so both are
ruled out here rather than tried again.
docs(native-host): what the int3 at image+0x1330a44 is
`VICTORY_SKIP_TITLE_INT3` (diagnostics build) logs one line per assert it continues
past, and a run that steps over one assert a million times is a run looping in
title code there: the Series 1.0.2.1 build does exactly that at image+0x1330a44,
the boot's SGD5 cache writer (docs/native-host.md), and the log says nothing about
it in the summary a reader gets.

`run-summary.sh` now counts those lines, names each RVA with its count in an
"asserts stepped over" section, and carries the total in the `--compare` table, so
one before/after row says whether a change stopped the loop or moved it. Counted
once per line, matched with `index` rather than a regex: the log of that run has
1,023,590 of them.

Checked on the run that produced them (commit 720a3891, series-x): `1023590 steps
over 1 assert ... rva=0x1330a44`, self-test extended with the two synthetic lines
and both assertions.
Follow-up to the analysis section on that trap, with the measurements that
narrow it: the key the retry cannot find (0xE0C12D7A5D4884C5) heads eight or
more records already in the title's heap, the interface's state word is written
once on the main thread and never again, no storage lane holds work while the
loop spins, and both packages ship one and the same executable.

Together those rule out a missing host service as the reason the lookup fails,
and the section says where the records' shape points instead (shared state
blocks referenced by hash, marked as a hypothesis).
docs(native-host): what the hash lookup at image+0x1330a44 is not missing
Stepping over a title assert logged one warning per hit. One of the title's
asserts sits in a retry loop that runs about twenty thousand times a second, so
25 s of a run wrote 494,416 lines and a 90 MB log -- from the fault path, while
the loop it documents kept spinning and nothing else could be read out of it.

The first 8 hits of an RVA stay warnings, then every ten-thousandth with the
count so far, so a log still shows the run was patched and how far it got (a
skipping run now ends at a 30 KB log whose last line reads hits=800000), and
the rest go to debug, where RUST_LOG=debug still shows every one.
seh(native): count the steps over an assert instead of a line each
VICTORY_TRACE_HANDLES logged the handles a title made and nothing about
what happened to them, and the half that watched them was a set nothing
ever filled: the only way to see a release was VICTORY_WATCH_HANDLE=<hex>
on one handle per run, which needs the handle known before the run.

The switch now logs every release, every set and every wait that got its
object, on every handle, and VICTORY_WATCH_HANDLE narrows the same log to
one. SetEvent is traced too: a title whose workers wait on events said
nothing at all about the events the run never set. Found by waiting for
one: a spinning title showed fourteen lines for the whole run.
hle(host_posix): trace every handle a run waits for and every release, from one switch
Every other hex switch here strips the 0x (the assert skip, the write trap, the
dump's addresses), and VICTORY_PEEK did not: an address written with the prefix
it is usually copied with was silently dropped, so a peek list of them printed
nothing at all and looked like unmapped memory rather than a parse miss.

The list is parsed by a helper with a test now, and the docs say the prefix is
taken.
seh(native): let VICTORY_PEEK take 0x-prefixed addresses
`VICTORY_PEEK` prints a qword of the run from inside the exception dispatch, so its
entries are what a reader can write down: an RVA of the faulting image, or an absolute
address. Neither can name a field of the object the faulting code is about when the
heap decides where that object lives, which is what a first-chance breakpoint in the
title usually needs: the boot's SGD5 writer keeps its state in `[rsi+0x10020]` and the
object it asks in `[... + 0x50]`, and the log prints no `rsi`.

An entry may now be `reg+offset`, any general register of the faulting frame (offset
hex, `0x` optional, case and spacing ignored); `rip` is not one. The parser lives in
`peek`, outside the x86_64-only dispatch, so its tests run on any host, and an entry
that names nothing is still skipped rather than read, so a bad entry cannot fault
inside the dispatch that reports the fault.

Read the Series 1.0.2.1 boot with it: `rsi` = 0x1478f6a50, `[rsi+0x10020]` = 0x181b1ec00
(owner back to the writer, `+0x08` = 0x10000, `+0x50` = 0x181796a00, `+0x58` = 0x40000 =
the buffer's length), so the object the check consults is populated, and `check` fails
later, at the id test: `[0x181796a00]` slot +0x3f0 is asked for `0xE0C12D7A5D4884C5` and
answers false, which is why the writer never finishes the write.
Kept both sides of the VICTORY_PEEK line: the other edit names that its hex takes an
optional 0x, and this one adds what a register entry means.
VICTORY_TRAP_WRITES took one page and its watched addresses, so a hunt that
needs two -- an object's state word, and the table it looks the state up in --
cost a run per page, and the two runs had to meet the same state to be compared.

A page and its addresses are one group now and ';' separates groups, each page
optionally followed by ':' before its addresses, so the form the switch took
before (page,addr,addr) is still read the same way, and the closing thread
guards every page named.
seh(native): watch several pages in one write trap
Four measurements that close off the cheap explanations before the next person
spends runs on them: a periodic dump shows every other thread idle (so nothing
can ever satisfy the wait), the console model makes no difference, the records
around the missing key are an index of {size, hash, kind, offset} entries that
already names it, and the table slots the lookup reads are never written.

The pool's alias views are coherent too -- the same record reads the same
through both, so aliasing is not what fails.
docs(native-host): the trap at image+0x1330a44 is a livelock, not a slow start
The submission is two lookups and a copy: the submit calls the sink's vtable
+0x3f0 with 0x286030A358A789FB and goes on only when that answers true, and the
check that fails asks the same object with 0xE0C12D7A5D4884C5. Both are entries
of the index already recorded beside it, so what separates the two operations is
the record each wants.

Also what the buffer's head says: SGD5, a u64, 33 blocks, the first 0x840 bytes
from 0x14 -- so the offsets the index quotes fall inside that first block.
docs(native-host): what the two hash lookups at the trap ask for
Checked rather than assumed: none of the five hashes in the index beside the
trap is CityHash64 of any span of the 512 bytes around them, brute-forced over
every start and length with the repo's own implementation. They therefore name
runtime states, the way pipelines.rs names state hashes from databases, and
naming this one offline wants 'victory translate --pipelines', which a Mac
refuses because translation needs the Windows DXC host.
docs(native-host): the index hashes key runtime structures, not file bytes
An unmodified run reaches the assert at image+0x1330a44 3.3 s in, as the only
first-chance exception in the log, and its Breakpad handler takes over 4 ms
later; a windowed .app run then reads through a null list at
image+0x55e56f8 (cmpq %rax,(%r10) with r10 = [rcx+0x38]) and aborts, which is
what the macOS crash report shows. Downstream of the assert, not a second
blocker: the headless run of the same build exits 3 without that fault.
The block at 0x1428cd409 asks vtable +0x3f0 with 0xE0C12D7A5D4884C5 into
r13b, asks again with 0x286030A358A789FB into r14b, and testb/je on r13b is
the give-up path, so the container answers both questions at the same moment
and only the 0xE0C1 id is absent. Both ids are movabs immediates in the
image (10 and 8 sites), so neither is a runtime-resolved name.
The merge of the peek change (d5e9cfca) committed the conflict markers
themselves, so victory-loader did not compile and the gate failed for
everyone: `unsafe fn dispatch` never closed.

Resolved in favour of the newer side, which names an entry as a register
plus an offset as well as an RVA or an address (#58), and keeps the
kernel-checked read the peek makes (#49). The helper the older side kept
for parsing is gone with its test: `crate::peek::address` is the parser
now, and it has its own.
seh(native): main did not build — resolve the conflict left in the VICTORY_PEEK block
Every test that needs Metal makes its own device and command queues. In
parallel they reached a high-water mark of eighty queues, hung the GPU of
an M1 Pro and took WindowServer with it, and the kernel panicked two
minutes later (#548). test-native.sh has run one test thread since then;
the gate everyone actually runs did not, so a `tools/macos/verify.sh` on a
Mac in use could still take the machine down.

libtest reads RUST_TEST_THREADS, so setting it for the suite-gpu line is
the whole change, and a caller who sets it higher still gets what they
asked for. Measured here: 493 tests, 16 s either way.
tools(macos): the gate runs the GPU tests one at a time, as test-native.sh does
d5e9cfca committed the unresolved conflict in dispatch.rs, so the crate did
not parse and no build of the host succeeded since. Keep this side of it (the
peek::address entries, which carry the same 0x-optional parsing) and drop
peek_list, the entry parser it replaced, with the test for it: peek.rs's own
test covers RVA, absolute and register entries.

docs: correct the frame-3 analysis while here. The id the writer asks for is
index 3 of the container's own five-entry table, so the scan finds it; what
is unproven is the earlier reading that the lookup answers false.
Both sides removed their entry-parser tests, so what was left is a module with
only `use super::*` in it, which the clippy gate would refuse.
Two results that decide what to try next. Stepping over the failing block
lookup (the je at image+0x1330970 turned into a jump to the writer's epilogue)
does carry boot past the trap, and the run then dies at once on a read whose
buffer base is past the end of the image: the engine consumes the database it
is building, so the state has to be provided, not stepped over.

And the state of main from 2026-11-26 takes the same breakpoint on this folder,
so nothing since introduced it: the runs the +0x4dcbc9d analysis describes used
another data set -- they open core_restofworld.rpf, which this folder has no
counterpart for.
docs(native-host): the shader database write cannot be skipped, and is not a regression
The trap is the je at 0x141330970 (check returning false); its two early exits
do not fire, the id is found and has() is true (the byte it resolves through
reads 0 via VICTORY_DUMP_MEM=0x181b90e40,16), so check takes the get branch and
its answer comes from 0x1330cd0(record, S). That function, not the lookup, is
what reports the chunk as not written.
The data question cannot be answered yet, and this records how far a first look
got so the next attempt starts there: the archives are RPF9 (not the RPF7 the
GTA V tooling knows), with the entry count at +0x24, a names length at +0x0c,
the same 32 bytes at +0x40 in all three looked at, and everything past +0x60
encrypted or compressed -- AES-256-ECB with those bytes over the table of
contents does not open it, and an 8.8 KB two-entry archive holds no printable
name.

Also where the boot database is not: not on disk (the title reads nothing
before it, by either trace switch) and not in the executable (its two SGD5
hits are the magic alone).
docs(native-host): what the archives are, and where the boot database is not
MetalFX's spatial scaler, temporal scaler and frame interpolator were all wrapped
and GPU-tested, and the spatial one was already on the present path, but nothing
outside victory-metal could give any of them a title texture: gfx::Texture keeps
its MTLTexture private. So the seam an upscaler needs did not exist, and the
temporal scaler had no way to be called at all.

Texture::mtl is that way out.

metalfx::Upscale is the other half: one scaler made in the mode its inputs allow
(Mode::Temporal when the caller has the frame's depth and motion vectors and the
system has a temporal scaler, Mode::Spatial otherwise), with the descriptor
formats taken from the textures the caller will pass. Encoded in either mode, and
it refuses a temporal frame handed colour only instead of scaling something it
cannot accumulate from, so a caller keeps its own path.

The inputs both need are not a pass this backend has to identify: the title names
them in its own FidelityFX dispatch, which modules::fidelityfx already parses, and
victory-gpu/src/native/textures.rs keys its textures by the same resource pointer.
Wiring that to this type is what is left (#375); no run can validate it until the
game folder is downloaded (#632).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 18:04:49 +00:00
The seam from the previous commit had no way to run: a MetalFX encode takes the
whole command buffer (encodeToCommandBuffer:), so it can neither wait on nor
update the fence the other encoders of a residency-set submission order through,
and this Mac runs residency sets by default. Refusing it there would have refused
every upscale.

So Pass::MetalFx ends the command buffer it is in and the submission's piece
event orders the next one, which is the mechanism passes_per_buffer already uses.
Metal orders the encoders before it in the same buffer, and they name their
attachments, so the pass's inputs are ready when it runs.

The scaler is made for the sizes, formats and mode the pass names, from
metalfx::Upscale, and kept in a cache on the device: one scaler per size and
format pair, not one per frame. View carries the frame's jitter, its
motion-vector scale and the reset, which FSR's dispatch supplies and MetalFX
needs, so Temporal::encode no longer hard-codes a motion scale of 1 and no jitter.

Tested on the GPU (victory-metal/tests/metalfx_pass.rs): a red 16x16 frame
scaled into 32x32 by the spatial scaler reads back red; the temporal one does the
same from zero motion vectors, depth at the far plane and a jitter; and an
upscale into a texture MetalFX may not write is refused rather than encoded.
The FidelityFX module is Windows-only (it loads the PC build with LoadLibraryExW
and takes the host D3D12 device), so nothing in it can serve a native Mac: its
descriptions could not even be compiled there. They are data, so they move to
modules::fidelityfx_api, which both providers share, and a macOS provider of its
own (modules::metalfx_ffx) answers the same five functions when
VICTORY_METALFX=upscale.

ffxDispatch is the only one that does work: it resolves the dispatch's colour,
depth, motion-vector and output resources to the host's textures, and records one
Cmd::Metalfx on the title's own list with the jitter, motion-vector scale and
reset FSR's description carries (rest[0..2], rest[2..4], rest[12]). The native
host emits that command as Pass::MetalFx, which is the temporal scaler when the
frame brought depth and motion vectors and the spatial one when it did not.

Off unless asked for; where the system has no MetalFX, or the variable is unset,
the title's own DLLs run exactly as before. No run has validated it yet: the
folder on this machine is 66% downloaded and shaders.rpf reads as zeros (#632).
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 20:03 UTC · original

Full gate on 4bbf5b8f, in a clean worktree of this branch (sh tools/macos/verify.sh full):

suite-hle      ... PASS (558 passed, 0 failed)
suite-shader   ... PASS (597 passed, 0 failed)
suite-gpu      ... PASS (493 passed, 0 failed)
policy         ... PASS
clippy-win     ... PASS
== gate PASSED ==

The MetalFX pass tests (crates/victory-metal/tests/metalfx_pass.rs: spatial, temporal, and the refusal) pass on this Mac's GPU. The scaler is selected by VICTORY_METALFX=upscale, and the title's own FidelityFX upscale reaches it through the new Cmd::Metalfx path in crates/victory-gpu/src/native/list.rs and host.rs.

Not run: the title itself. The game folder on this machine is still 66% downloaded (shaders.rpf reads as zeros), so nothing here has presented a frame yet, and the MetalFX path has therefore never been handed a real frame from the title.

**@⁠AnastasisKon** on GitHub · 2026-11-28 20:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/636#issuecomment-7244999229) Full gate on `4bbf5b8f`, in a clean worktree of this branch (`sh tools/macos/verify.sh full`): ``` suite-hle ... PASS (558 passed, 0 failed) suite-shader ... PASS (597 passed, 0 failed) suite-gpu ... PASS (493 passed, 0 failed) policy ... PASS clippy-win ... PASS == gate PASSED == ``` The MetalFX pass tests (`crates/victory-metal/tests/metalfx_pass.rs`: spatial, temporal, and the refusal) pass on this Mac's GPU. The scaler is selected by `VICTORY_METALFX=upscale`, and the title's own FidelityFX upscale reaches it through the new `Cmd::Metalfx` path in `crates/victory-gpu/src/native/list.rs` and `host.rs`. Not run: the title itself. The game folder on this machine is still 66% downloaded (`shaders.rpf` reads as zeros), so nothing here has presented a frame yet, and the MetalFX path has therefore never been handed a real frame from the title.
github-bot closed this pull request 2026-11-28 20:33:35 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 20:31 UTC · original

This is the same branch against a base that has moved on: upstream main here is the README pointer, so the diff shows 178 files of the fork's whole history rather than the three commits this is. The reviewable pull request is https://github.com/AnastasisKon/Native-Victory-macOS/pull/79 (base: the fork's main, 14 files, +1179/−89), and the work left — depth/motion on a real frame, and why frame generation has no caller — is written down in #642 so it can be taken in parallel. Closing this one rather than leaving two.

**@⁠AnastasisKon** on GitHub · 2026-11-28 20:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/636#issuecomment-7245345040) This is the same branch against a base that has moved on: upstream `main` here is the README pointer, so the diff shows 178 files of the fork's whole history rather than the three commits this is. The reviewable pull request is https://github.com/AnastasisKon/Native-Victory-macOS/pull/79 (base: the fork's `main`, 14 files, +1179/−89), and the work left — depth/motion on a real frame, and why frame generation has no caller — is written down in https://git.gtahub.st/github/LakshanSivakumar--Native-Victory-macOS/issues/642 so it can be taken in parallel. Closing this one rather than leaving two.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.