feat(metal): a MetalFX temporal scaler smoke spike #381

Open
wz11wz wants to merge 18 commits from upstream-pr/381 into main
wz11wz commented 2026-11-27 15:15:28 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T15:15:28Z.


Refs #375, M0 of the plan posted there.

victory-metal gains a metalfx module: a smoke spike that builds an MTLFXTemporalScaler through objc2-metal-fx 0.3 and proves the whole path works on the host Mac with no title involved:

  • descriptor (640x360 in, 1280x720 out, RGBA16Float colour / Depth32Float depth / RG16Float motion)
  • synthetic shared textures, the colour one filled with a gradient
  • per-frame setters (textures, input content size, jitter, motion scale, reset)
  • encodeToCommandBuffer, then readback through getBytes

The test (temporal_scaler_scales_synthetic_input) asserts the output is not flat: 471 distinct values sampled from the upscaled frame on an M1 Max. No Metal Shader Converter involvement, so the spike runs wherever macOS 14+ does.

Next up per the plan: the M1 context seam behind VICTORY_METALFX=1 (ffxCreateContext builds the scaler from CreateUpscale), then M2 dispatch with the motion-vector dump harness.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5528966467 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T15:15:28Z. --- Refs #375, M0 of the plan posted there. `victory-metal` gains a `metalfx` module: a smoke spike that builds an `MTLFXTemporalScaler` through `objc2-metal-fx` 0.3 and proves the whole path works on the host Mac with no title involved: - descriptor (640x360 in, 1280x720 out, RGBA16Float colour / Depth32Float depth / RG16Float motion) - synthetic shared textures, the colour one filled with a gradient - per-frame setters (textures, input content size, jitter, motion scale, reset) - `encodeToCommandBuffer`, then readback through `getBytes` The test (`temporal_scaler_scales_synthetic_input`) asserts the output is not flat: **471 distinct values sampled** from the upscaled frame on an M1 Max. No Metal Shader Converter involvement, so the spike runs wherever macOS 14+ does. Next up per the plan: the M1 context seam behind `VICTORY_METALFX=1` (`ffxCreateContext` builds the scaler from `CreateUpscale`), then M2 dispatch with the motion-vector dump harness.
wz11wz commented 2026-11-27 15:37:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T15:37:45Z.


M1 landed in this branch (30dd7c8): the VICTORY_METALFX=1 seam in fidelityfx.rs. ffxCreateContext's CREATE_UPSCALE branch now decodes and validates the create description into an UpscalerConfig and hands the title a context that is ours; ffxDestroyContext frees it; ffxDispatch refuses loudly until the scaler build lands (M2 - the create description carries no formats, so the scaler is built lazily at the first dispatch, which is also where the module stops being cfg(windows)-only).

Verified: the Windows clippy gate compiles the seam and its roundtrip tests clean (they run in CI there), and both documented suites stay green (384 + 520, 0 failed). Next: M2's un-gating and the dispatch with the motion-vector dump harness.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222289690 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7222289690). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T15:37:45Z. --- M1 landed in this branch (30dd7c8): the `VICTORY_METALFX=1` seam in `fidelityfx.rs`. `ffxCreateContext`'s `CREATE_UPSCALE` branch now decodes and validates the create description into an `UpscalerConfig` and hands the title a context that is ours; `ffxDestroyContext` frees it; `ffxDispatch` refuses loudly until the scaler build lands (M2 - the create description carries no formats, so the scaler is built lazily at the first dispatch, which is also where the module stops being cfg(windows)-only). Verified: the Windows clippy gate compiles the seam and its roundtrip tests clean (they run in CI there), and both documented suites stay green (384 + 520, 0 failed). Next: M2's un-gating and the dispatch with the motion-vector dump harness.
wz11wz commented 2026-11-27 15:59:42 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T15:59:42Z.


M1.5 and M1.6 landed (b42f9ef), from the review feedback:

  • fidelityfx_common now carries the platform-independent half: descriptions, return codes, the backend link, host_state, the shared once! macro. fidelityfx keeps the PC forwarding behind pc_* helpers under cfg(windows), and the module itself is cfg(any(windows, target_os = "macos")) - the interception compiles on a Mac for the first time, and its roundtrip tests run there too (they were excluded before).
  • serving() now answers yes on macOS under VICTORY_METALFX=1, so the module actually enters the import registry there (it never did before - that gap meant the first M1 was unreachable from the title).

Suites: arm64 145 passed (was 141 - the fidelityfx tests joined), x86 384+520... 388 total, 0 failed; Windows clippy clean for everything but msc.rs's pre-existing errors (#379).

Next: M2 - the dispatch builds the scaler from the seven resources' formats, with the motion-vector dump harness; then a real run to verify the interception end to end.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222729016 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7222729016). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T15:59:42Z. --- M1.5 and M1.6 landed (b42f9ef), from the review feedback: - **fidelityfx_common** now carries the platform-independent half: descriptions, return codes, the backend link, `host_state`, the shared `once!` macro. `fidelityfx` keeps the PC forwarding behind `pc_*` helpers under `cfg(windows)`, and the module itself is `cfg(any(windows, target_os = "macos"))` - the interception compiles on a Mac for the first time, and its roundtrip tests run there too (they were excluded before). - **serving()** now answers yes on macOS under `VICTORY_METALFX=1`, so the module actually enters the import registry there (it never did before - that gap meant the first M1 was unreachable from the title). Suites: arm64 145 passed (was 141 - the fidelityfx tests joined), x86 384+520... 388 total, 0 failed; Windows clippy clean for everything but `msc.rs`'s pre-existing errors (#379). Next: M2 - the dispatch builds the scaler from the seven resources' formats, with the motion-vector dump harness; then a real run to verify the interception end to end.
wz11wz commented 2026-11-27 16:05:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T16:05:45Z.


M1.7 landed (2ce2117), from the call-order catch: the title negotiates before it creates, so M1.6's serving() flip alone left the seam dark. Under VICTORY_METALFX=1:

  • ffxQuery now answers GET_VERSIONS (one provider; the count-then-ids/names two-pass both supported) and GET_PROVIDER_VERSION with our id/name
  • ffxConfigure accepts-and-ignores settings
  • MEMORY_USAGE_WITH_DEVICE keeps the same refusal the Windows path already makes, and that path is known to reach a working upscaling
  • the provider id is our own (0x6d65_7461, "MetalFX (victory)"): create ignores the requested one, and the real DLL's values can be dumped on Windows via the PC versions() helper if the title ever cross-checks

Test: metalfx_query_negotiates_one_provider covers both query kinds. Suites: arm64 146, x86 389, 0 failed; Windows clippy clean for everything but msc.rs (#379).

That closes M1 properly: with the switch on, a macOS run should now show the version query answered, our context created, and the dispatch refusal logged - the three markers to look for in the next real run before M2 wires the scaler in.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222850047 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7222850047). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T16:05:45Z. --- M1.7 landed (2ce2117), from the call-order catch: the title negotiates before it creates, so M1.6's serving() flip alone left the seam dark. Under VICTORY_METALFX=1: - `ffxQuery` now answers `GET_VERSIONS` (one provider; the count-then-ids/names two-pass both supported) and `GET_PROVIDER_VERSION` with our id/name - `ffxConfigure` accepts-and-ignores settings - `MEMORY_USAGE_WITH_DEVICE` keeps the same refusal the Windows path already makes, and that path is known to reach a working upscaling - the provider id is our own (`0x6d65_7461`, "MetalFX (victory)"): create ignores the requested one, and the real DLL's values can be dumped on Windows via the PC `versions()` helper if the title ever cross-checks Test: `metalfx_query_negotiates_one_provider` covers both query kinds. Suites: arm64 146, x86 389, 0 failed; Windows clippy clean for everything but `msc.rs` (#379). That closes M1 properly: with the switch on, a macOS run should now show the version query answered, our context created, and the dispatch refusal logged - the three markers to look for in the next real run before M2 wires the scaler in.
LakshanSivakumar commented 2026-11-27 16:23:49 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:23:49Z.


Leaving this open while it is a spike: with VICTORY_METALFX on, every upscale is still refused, so it does nothing yet, and the switch is not in docs/native-host.md. Its ucrt test and verify.sh commits are on main already through #370, so a rebase will drop them.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223211827 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7223211827). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:23:49Z. --- Leaving this open while it is a spike: with VICTORY_METALFX on, every upscale is still refused, so it does nothing yet, and the switch is not in docs/native-host.md. Its ucrt test and verify.sh commits are on main already through #370, so a rebase will drop them.
wz11wz commented 2026-11-27 16:33:29 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T16:33:29Z.


Step D of the plan landed (5e986bb): a synthetic calibration suite next to the spike in victory-metal/src/metalfx.rs — the check the proposal asked to settle before the dispatch, with one revision to the reference side, noted at the end.

The harness. A bright square pans across known ground truth (+3, +2) input pixels per frame — (+6, +4) output pixels at the spike's 2x scale — while the motion texture is fed independently, so the convention can be checked against the same content. Three tests: a still scene must not drift; the panning scene must track ground truth within 1.5 output pixels with a bright interior and no ghosting at the vacated edge; and a sign-flip differential prints both conventions for the record.

Results on the M1 Max (all green):

  • still scene: drift 0.00 output pixels
  • panning: tracks (+6, +4) within 1.5 px, interior 3.000 of 3.0, trailing bleed 0.000 under Apple's documented convention (output-space pixels, previous frame to current)
  • the suite caught one real measurement bug on the way in: an earlier draft moved the colour content while claiming zero motion, and the drift read exactly the ground truth doubled — which is the failure mode these tests exist to catch

The finding that matters for M2: the sign-flip differential is indistinguishable on synthetic frames — documented (+6, +4) and flipped (-6, -4) both read interior 3.000 / bleed 0.000. Idealized frames hide convention errors (no noise, no jitter, uniform motion), so synthetic calibration alone cannot settle the convention. The real-frame dump-and-compare stays the gate before the dispatch is trusted.

Reference-side revision: the original plan compared FSR vs MetalFX, which wanted a Windows box with VICTORY_FIDELITYFX_DIR as the reference. I do not have one, so the comparison is now same-machine before/after: dump the title's upscale dispatches on main (no interception — the title's own FidelityFX DLL runs, its passes partially refused) and again under VICTORY_METALFX=1, same scene, same frames (deterministic input replay). What to check: the FSR-class passes leave the refused list, MetalFX's output is present and non-degenerate where FSR's was refused, frame meter, stability. The synthetic suite above anchors the ground truth in between.

Next: M2 — the dispatch builds the scaler from the seven resources, with this harness extended to the real dump path.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223399700 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7223399700). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T16:33:29Z. --- Step D of the plan landed (5e986bb): a synthetic calibration suite next to the spike in `victory-metal/src/metalfx.rs` — the check the proposal asked to settle before the dispatch, with one revision to the reference side, noted at the end. **The harness.** A bright square pans across known ground truth (+3, +2) input pixels per frame — (+6, +4) output pixels at the spike's 2x scale — while the motion texture is fed independently, so the convention can be checked against the same content. Three tests: a still scene must not drift; the panning scene must track ground truth within 1.5 output pixels with a bright interior and no ghosting at the vacated edge; and a sign-flip differential prints both conventions for the record. **Results on the M1 Max (all green):** - still scene: drift 0.00 output pixels - panning: tracks (+6, +4) within 1.5 px, interior 3.000 of 3.0, trailing bleed 0.000 under Apple's documented convention (output-space pixels, previous frame to current) - the suite caught one real measurement bug on the way in: an earlier draft moved the colour content while claiming zero motion, and the drift read exactly the ground truth doubled — which is the failure mode these tests exist to catch **The finding that matters for M2:** the sign-flip differential is indistinguishable on synthetic frames — documented (+6, +4) and flipped (-6, -4) both read interior 3.000 / bleed 0.000. Idealized frames hide convention errors (no noise, no jitter, uniform motion), so synthetic calibration alone cannot settle the convention. The real-frame dump-and-compare stays the gate before the dispatch is trusted. **Reference-side revision:** the original plan compared FSR vs MetalFX, which wanted a Windows box with `VICTORY_FIDELITYFX_DIR` as the reference. I do not have one, so the comparison is now same-machine before/after: dump the title's upscale dispatches on `main` (no interception — the title's own FidelityFX DLL runs, its passes partially refused) and again under `VICTORY_METALFX=1`, same scene, same frames (deterministic input replay). What to check: the FSR-class passes leave the refused list, MetalFX's output is present and non-degenerate where FSR's was refused, frame meter, stability. The synthetic suite above anchors the ground truth in between. Next: M2 — the dispatch builds the scaler from the seven resources, with this harness extended to the real dump path.
wz11wz commented 2026-11-27 16:38:57 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T16:38:57Z.


Rebased onto main (b998bb65): the ucrt test and verify.sh commits dropped out of the diff, as expected — this branch is now the seven MetalFX commits and nothing else. All four metalfx tests green on the rebased tree.

Remaining before this is more than a spike, per your note: M2's dispatch (the scaler built from the seven resources at the first real upscale) and a docs/native-host.md entry for VICTORY_METALFX. Both are what's next.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223508334 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7223508334). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T16:38:57Z. --- Rebased onto `main` (b998bb65): the ucrt test and `verify.sh` commits dropped out of the diff, as expected — this branch is now the seven MetalFX commits and nothing else. All four metalfx tests green on the rebased tree. Remaining before this is more than a spike, per your note: M2's dispatch (the scaler built from the seven resources at the first real upscale) and a `docs/native-host.md` entry for `VICTORY_METALFX`. Both are what's next.
wz11wz commented 2026-11-27 16:53:31 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-27T16:53:31Z.


Question for @LakshanSivakumar while we test this seam in a real run: how do you get into the prologue world, and have you seen a deterministic crash at frame ~800?

What we hit (M1 Max, macOS 26, console=series-x, this branch, VICTORY_METALFX=1):

  • Two windowed interactive runs crash deterministically when the user advances past the menus: frame 799 and 807 (~2m15s and ~2m25s in). First-chance 0xc0000005, a write through a null pointer in title code; the title's own breakpad handler then faults a second time during upload and victory exits 134. Two title crash logs saved (Peds 42/600, Cars 122/700, TileHeap 3.4 GB - the world was streaming in, so the transition had started).
  • Two headless runs with auto-Enter (240 s and 600 s, frames 6784 and 17792) never crash - and never call a single ffx* import, so we could not verify the interception end to end yet.

So: which run setup and input sequence reaches the prologue world for you, and does the frame-~800 crash ring a bell? Happy to file a full tester report with both crash logs if that helps, or to try your exact recipe and report back.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223789123 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7223789123). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-27T16:53:31Z. --- Question for @LakshanSivakumar while we test this seam in a real run: **how do you get into the prologue world, and have you seen a deterministic crash at frame ~800?** What we hit (M1 Max, macOS 26, console=series-x, this branch, `VICTORY_METALFX=1`): - Two **windowed interactive** runs crash deterministically when the user advances past the menus: frame **799** and **807** (~2m15s and ~2m25s in). First-chance `0xc0000005`, a write through a null pointer in title code; the title's own breakpad handler then faults a second time during upload and victory exits 134. Two title crash logs saved (Peds 42/600, Cars 122/700, TileHeap 3.4 GB - the world was streaming in, so the transition had started). - Two **headless** runs with auto-Enter (240 s and 600 s, frames 6784 and 17792) never crash - and never call a single `ffx*` import, so we could not verify the interception end to end yet. So: which run setup and input sequence reaches the prologue world for you, and does the frame-~800 crash ring a bell? Happy to file a full tester report with both crash logs if that helps, or to try your exact recipe and report back.
wz11wz commented 2026-11-28 07:16:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by wz11wz on 2026-11-28T07:16:18Z.


Status: the serving seam is now live on the native path, and the unit layer is green on Apple Silicon.

  • use_host_dir was only ever called from the Wine-side runner (run.rs); native_run.rs never called it, so on macOS the serving module was only held in tests. Wired into native startup now (this push) — verified headless: the startup logs FidelityFX: no PC build on this host; MetalFX serves when VICTORY_METALFX=1 and the FidelityFX loader binds (amd_fidelityfx_loader_xbox.dll: 4 hle).

  • All five fidelityfx unit tests pass on Apple Silicon — but only with the right target: cargo test -p victory-hle --lib --target x86_64-apple-darwin. Without --target cargo builds the arm64 test binary, the apple + x86_64 gate silently compiles the module out, and the fidelityfx tests are absent (no error, just missing). Worth a note in the PR docs.

  • Verified against a 240s headless run of Grand Theft Auto VI: the FidelityFX loader binds at startup, but the deep markers (provider version answered / configure accepted) never fire — the title's upscaler dll (amd_fidelityfx_upscaler_xbox.dll, which exports the ffx* entry points itself and imports d3d12_xs.dll) is only loaded at a later game state than any headless run reaches (also blocked by the #404 crash, see the analysis there: the residency-ordered submission path and the fence-lag accumulation model).

Remaining for M2: the dispatch — metalfx_dispatch still refuses ("the scaler itself lands at the first dispatch"), so the real MTLFXTemporalScaler integration with the dispatch's console resources is the last implementation piece.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7235826707 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/381#issuecomment-7235826707). Originally posted by [wz11wz](https://github.com/wz11wz) on 2026-11-28T07:16:18Z. --- **Status: the serving seam is now live on the native path, and the unit layer is green on Apple Silicon.** - `use_host_dir` was only ever called from the Wine-side runner (`run.rs`); `native_run.rs` never called it, so on macOS the serving module was only held in tests. Wired into native startup now (this push) — verified headless: the startup logs `FidelityFX: no PC build on this host; MetalFX serves when VICTORY_METALFX=1` and the FidelityFX loader binds (`amd_fidelityfx_loader_xbox.dll: 4 hle`). - All five fidelityfx unit tests pass on Apple Silicon — but only with the right target: `cargo test -p victory-hle --lib --target x86_64-apple-darwin`. Without `--target` cargo builds the arm64 test binary, the `apple + x86_64` gate silently compiles the module out, and the fidelityfx tests are absent (no error, just missing). Worth a note in the PR docs. - Verified against a 240s headless run of Grand Theft Auto VI: the FidelityFX loader binds at startup, but the deep markers (`provider version answered` / `configure accepted`) never fire — the title's upscaler dll (`amd_fidelityfx_upscaler_xbox.dll`, which exports the `ffx*` entry points itself and imports `d3d12_xs.dll`) is only loaded at a later game state than any headless run reaches (also blocked by the #404 crash, see the analysis there: the residency-ordered submission path and the fence-lag accumulation model). Remaining for M2: the dispatch — `metalfx_dispatch` still refuses ("the scaler itself lands at the first dispatch"), so the real `MTLFXTemporalScaler` integration with the dispatch's console resources is the last implementation piece.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/381:upstream-pr/381'
git switch 'upstream-pr/381'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/381'
git switch 'upstream-pr/381'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/381'
git switch 'upstream-pr/381'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/381'
git switch 'main'
git merge --squash 'upstream-pr/381'
git switch 'main'
git merge --ff-only 'upstream-pr/381'
git switch 'main'
git merge 'upstream-pr/381'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!381
No description provided.