GPU: VICTORY_LIBRARY_TIMING measures the host FidelityFX upscaler's GPU and CPU cost #1902

Open
AwkGrep256 wants to merge 2 commits from upstream-pr/1904 into main
AwkGrep256 commented 2026-11-25 00:29:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AwkGrep256 on 2026-11-25T00:29:30Z.


Important

Measure what FSR costs inside a frame. main runs the host FidelityFX upscaler. This PR adds Windows D3D12 diagnostics that isolate the upscaler’s GPU work and CPU recording time from the rest of the frame. That makes it possible to assess the cost of FSR when comparing render scales.

✅ On an RX 9070 XT, VICTORY_LIBRARY_TIMING=1 measured 1.32 ms GPU and 80 µs CPU per FSR 4.1.2 upscale at the median. The GPU work was about 1% of frame GPU time in that run. Timing is off by default.

The Series X measurement used #1793’s switches. The instrumentation works independently of #1793 and #1917. Passing Windows CI for this head

Diagnostics switch

Switch Effect
VICTORY_LIBRARY_TIMING=1 Each host library call gets a GPU timestamp before and after it, read when its list is reset (its submission has finished), plus the CPU time of the call. Every 60 calls one line reports the GPU time (average, median, slowest) and the average CPU time. Each call is also logged at debug level (VICTORY_LOG=victory_gpu::library_timing=debug).

Off by default and diagnostics-only; when off nothing is recorded. Up to 64 calls can be in flight; past that a call is not timed.

Measurement in the title

Series X profile, title 1.0.2.1, AMD Radeon RX 9070 XT, Windows 11, diag build of main 02fcf5b with #1793 applied for the Series X switches, FidelityFX SDK 2.4.0 signedbin, FSR 4.1.2, 1080p rendered to a 4K output. 50 upscales in the world.

Min Median Max
GPU time per upscale 1.18 ms 1.32 ms 1.36 ms
CPU time to record it 51 µs 80 µs 36.6 ms (first call: the provider's one-time setup)

For scale, the same frames took 100 to 187 ms on the GPU (1.1 to 2.9 s per frame in all), so the upscaler is about 1 % of the frame's GPU time. Rendering 1080p instead of native 4K saves far more than that.

Tested

Check Result
Unit tests: milliseconds from ticks, report statistics ✅
GPU test: a timed call on a real list reads ordered, non-zero timestamps (RX 9070 XT) ✅
cargo clippy --workspace --all-targets -- -D warnings, with and without diagnostics ✅
The title run above ✅
<!-- greyfinch-sync:Marvisak/VIctory:issue:5482753351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1904). Originally posted by [AwkGrep256](https://github.com/AwkGrep256) on 2026-11-25T00:29:30Z. --- > [!IMPORTANT] > **Measure what FSR costs inside a frame.** `main` runs the host FidelityFX upscaler. This PR adds Windows D3D12 diagnostics that isolate the upscaler’s GPU work and CPU recording time from the rest of the frame. That makes it possible to assess the cost of FSR when comparing render scales. > > ✅ On an RX 9070 XT, `VICTORY_LIBRARY_TIMING=1` measured **1.32 ms GPU** and **80 µs CPU** per FSR 4.1.2 upscale at the median. The GPU work was about **1%** of frame GPU time in that run. Timing is off by default. > > The Series X measurement used #1793’s switches. The instrumentation works independently of #1793 and #1917. [Passing Windows CI for this head](https://github.com/Marvisak/VIctory/actions/runs/45522867288) ## Diagnostics switch | Switch | Effect | |---|---| | `VICTORY_LIBRARY_TIMING=1` | Each host library call gets a GPU timestamp before and after it, read when its list is reset (its submission has finished), plus the CPU time of the call. Every 60 calls one line reports the GPU time (average, median, slowest) and the average CPU time. Each call is also logged at debug level (`VICTORY_LOG=victory_gpu::library_timing=debug`). | Off by default and diagnostics-only; when off nothing is recorded. Up to 64 calls can be in flight; past that a call is not timed. ## Measurement in the title Series X profile, title 1.0.2.1, AMD Radeon RX 9070 XT, Windows 11, diag build of main `02fcf5b` with #1793 applied for the Series X switches, FidelityFX SDK 2.4.0 `signedbin`, FSR 4.1.2, 1080p rendered to a 4K output. 50 upscales in the world. | | Min | Median | Max | |---|---|---|---| | GPU time per upscale | 1.18 ms | **1.32 ms** | 1.36 ms | | CPU time to record it | 51 µs | **80 µs** | 36.6 ms (first call: the provider's one-time setup) | For scale, the same frames took 100 to 187 ms on the GPU (1.1 to 2.9 s per frame in all), so the upscaler is about 1 % of the frame's GPU time. Rendering 1080p instead of native 4K saves far more than that. ## Tested | Check | Result | |---|---| | Unit tests: milliseconds from ticks, report statistics | ✅ | | GPU test: a timed call on a real list reads ordered, non-zero timestamps (RX 9070 XT) | ✅ | | `cargo clippy --workspace --all-targets -- -D warnings`, with and without `diagnostics` | ✅ | | The title run above | ✅ |
catminou4 commented 2026-11-25 00:32:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T00:32:51Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

VICTORY_LIBRARY_TIMING measures the host FidelityFX upscale: timing instrumentation behind an env var — debug tooling.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049698034 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1904#pullrequestreview-6049698034). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T00:32:51Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. VICTORY_LIBRARY_TIMING measures the host FidelityFX upscale: timing instrumentation behind an env var — debug tooling.
Marvisak commented 2026-11-25 09:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:18:51Z.


Automated triage for the maintainers.

Merge candidate.

Adds VICTORY_LIBRARY_TIMING=1 (diagnostics feature only, off by default): external::record brackets the host library's recording with two timestamp queries, resolves them into a read-back buffer, and HostList::reset (called only after the list's submissions finished) reads them and logs GPU/CPU statistics every 60 calls (crates/victory-gpu/src/library_timing.rs). The query heap/read-back setup, the 64-pair cap and the out-of-order guard in ticks_ms read correctly, and nothing runs when the switch is off. The README line is a single row in the existing switch table.

Optional: main reads switches with crate::switch::on (treats any value but 0 as on); using it here instead of the hand-written == "1" check would match the other VICTORY_* switches. Pairs taken by a list that is dropped without a reset stay busy, which only reduces how many calls get timed.

CI (check): passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156871719 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1904#issuecomment-7156871719). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:18:51Z. --- <!-- victory-triage v1 head=841dc30949f85fb14a92759e92212ced272b1499 verdict=merge-candidate at=2026-11-25T16:42:19Z --> Automated triage for the maintainers. **Merge candidate.** Adds `VICTORY_LIBRARY_TIMING=1` (diagnostics feature only, off by default): `external::record` brackets the host library's recording with two timestamp queries, resolves them into a read-back buffer, and `HostList::reset` (called only after the list's submissions finished) reads them and logs GPU/CPU statistics every 60 calls (`crates/victory-gpu/src/library_timing.rs`). The query heap/read-back setup, the 64-pair cap and the out-of-order guard in `ticks_ms` read correctly, and nothing runs when the switch is off. The README line is a single row in the existing switch table. Optional: main reads switches with `crate::switch::on` (treats any value but `0` as on); using it here instead of the hand-written `== "1"` check would match the other `VICTORY_*` switches. Pairs taken by a list that is dropped without a reset stay busy, which only reduces how many calls get timed. CI (`check`): passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 19:38:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:38:12Z.

Review: APPROVED


Reviewed and verified 841dc30949f85fb14a92759e92212ced272b1499 merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, --features diagnostics with VICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).

Code Audit

  • Fully gated behind #[cfg(feature = "diagnostics")] (crates/victory-gpu/src/lib.rs:66-67, external.rs:44-50, host.rs:1009-1013, 1762-1763), so default builds carry zero overhead and diagnostics builds with VICTORY_LIBRARY_TIMING unset short-circuit via a cached OnceLock<bool> without creating a query heap or readback buffer.
  • library_timing.rs:93-162 properly brackets external::record with EndQuery(TIMESTAMP, pair * 2) / EndQuery(TIMESTAMP, pair * 2 + 1) and ResolveQueryData into a D3D12_HEAP_TYPE_READBACK buffer in D3D12_RESOURCE_STATE_COPY_DEST, and serializes Map/Unmap (with an empty write range { Begin: 0, End: 0 }) under t.state in list_reset.

Local Verification

  • cargo xtask policy — pass (192 files ok).
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --features diagnostics --lib library_timing::tests:: (RTX 5090 and WARP) — 3/3 passed.
  • Additional live probe with both VICTORY_LIBRARY_TIMING=1 and VICTORY_GPU_TIMING=1 under VICTORY_D3D12_DEBUG=1:
    • begin -> end -> close -> host.execute -> list.reset() recorded valid GPU durations (0.001504 ms on RTX 5090, 0.001024 ms on WARP), freed busy[pair], and produced GetDeviceRemovedReason() == Ok(()) with 0 ID3D12InfoQueue messages on both backends.
    • 4-way co-merge with #2272, #2098, and #2478 on 63bcca43c6a0 also built with 0 clippy warnings and passed all targeted tests on RTX 5090 and WARP.

Non-Blocking Notes

  • Dropped lists without reset(): if a HostList with recorded pending entries is dropped without calling reset(), its busy slots stay marked and its raw address remains in s.pending (reproduced locally: dropping 64+ lists exhausts all 64 slots and leaves stale address entries that could match a newly allocated HostList at the same address). A small Drop hook on HostList calling a cleanup helper would prevent both slot exhaustion and pointer-reuse collisions.
  • Test cleanup & switch helper: a_timed_call_is_read_at_the_lists_reset (library_timing.rs:210-236) leaves s.busy[0] = true and a dangling entry in s.pending (and calls Unmap(0, None) rather than { Begin: 0, End: 0 }), and on() could optionally use crate::switch::on("VICTORY_LIBRARY_TIMING") to match the other switches.

Looks good to merge as an opt-in diagnostics tool.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079634410 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1904#pullrequestreview-6079634410). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T19:38:12Z. **Review:** APPROVED --- Reviewed and verified `841dc30949f85fb14a92759e92212ced272b1499` merged onto `origin/main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (RTX 5090 + Microsoft WARP, `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1 MSVC). ### Code Audit - Fully gated behind `#[cfg(feature = "diagnostics")]` (`crates/victory-gpu/src/lib.rs:66-67`, `external.rs:44-50`, `host.rs:1009-1013, 1762-1763`), so default builds carry zero overhead and diagnostics builds with `VICTORY_LIBRARY_TIMING` unset short-circuit via a cached `OnceLock<bool>` without creating a query heap or readback buffer. - `library_timing.rs:93-162` properly brackets `external::record` with `EndQuery(TIMESTAMP, pair * 2)` / `EndQuery(TIMESTAMP, pair * 2 + 1)` and `ResolveQueryData` into a `D3D12_HEAP_TYPE_READBACK` buffer in `D3D12_RESOURCE_STATE_COPY_DEST`, and serializes `Map`/`Unmap` (with an empty write range `{ Begin: 0, End: 0 }`) under `t.state` in `list_reset`. ### Local Verification - `cargo xtask policy` — pass (`192 files ok`). - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings. - `cargo test --locked -p victory-gpu --features diagnostics --lib library_timing::tests::` (RTX 5090 and WARP) — 3/3 passed. - Additional live probe with both `VICTORY_LIBRARY_TIMING=1` and `VICTORY_GPU_TIMING=1` under `VICTORY_D3D12_DEBUG=1`: - `begin` -> `end` -> `close` -> `host.execute` -> `list.reset()` recorded valid GPU durations (`0.001504 ms` on RTX 5090, `0.001024 ms` on WARP), freed `busy[pair]`, and produced `GetDeviceRemovedReason() == Ok(())` with 0 `ID3D12InfoQueue` messages on both backends. - 4-way co-merge with `#2272`, `#2098`, and `#2478` on `63bcca43c6a0` also built with 0 clippy warnings and passed all targeted tests on RTX 5090 and WARP. ### Non-Blocking Notes - **Dropped lists without `reset()`**: if a `HostList` with recorded `pending` entries is dropped without calling `reset()`, its `busy` slots stay marked and its raw address remains in `s.pending` (reproduced locally: dropping 64+ lists exhausts all 64 slots and leaves stale address entries that could match a newly allocated `HostList` at the same address). A small `Drop` hook on `HostList` calling a cleanup helper would prevent both slot exhaustion and pointer-reuse collisions. - **Test cleanup & switch helper**: `a_timed_call_is_read_at_the_lists_reset` (`library_timing.rs:210-236`) leaves `s.busy[0] = true` and a dangling entry in `s.pending` (and calls `Unmap(0, None)` rather than `{ Begin: 0, End: 0 }`), and `on()` could optionally use `crate::switch::on("VICTORY_LIBRARY_TIMING")` to match the other switches. Looks good to merge as an opt-in diagnostics tool.
Dukestar69 commented 2026-11-26 23:47:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T23:47:20Z.

Review: APPROVED


LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Adding opt-in VICTORY_LIBRARY_TIMING for host FidelityFX upscaler GPU/CPU timing is cleanly isolated and leaves default execution unchanged.
  • cargo test -p victory-gpu --lib external:: -- --test-threads=1: all passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6081648477 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1904#pullrequestreview-6081648477). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T23:47:20Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Adding opt-in `VICTORY_LIBRARY_TIMING` for host FidelityFX upscaler GPU/CPU timing is cleanly isolated and leaves default execution unchanged. - `cargo test -p victory-gpu --lib external:: -- --test-threads=1`: all passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/1904:upstream-pr/1904'
git switch 'upstream-pr/1904'

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/1904'
git switch 'upstream-pr/1904'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1904'
git switch 'upstream-pr/1904'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1904'
git switch 'main'
git merge --squash 'upstream-pr/1904'
git switch 'main'
git merge --ff-only 'upstream-pr/1904'
git switch 'main'
git merge 'upstream-pr/1904'
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
Marvisak/VIctory!1902
No description provided.