Skip to content

GPU: queries run on the host GPU - #3138

Open
FoxxoOwO wants to merge 2 commits into
Marvisak:mainfrom
FoxxoOwO:gpu/queries-host-2
Open

FoxxoOwO wants to merge 2 commits into
Marvisak:mainfrom
FoxxoOwO:gpu/queries-host-2

Conversation

@FoxxoOwO

@FoxxoOwO FoxxoOwO commented Nov 26, 2026 •

Copy link
Copy Markdown

Replaces #2354, which no longer merges (conflict in crates/victory-gpu/src/host.rs) and had the timestamp overflow from its review. Rebased onto main 63bcca4.

Rebase. Both sides added a field to Deferred (waits from main, resolves here), so both are kept.

Timestamp fix (the review's finding). crates/victory-gpu/src/host.rs scaled with at.saturating_mul(TIMESTAMP_FREQUENCY) / host, and both reviewed tick counts overflow u64 before the division, so every guest timestamp came out identical. Scaling now goes through title_ticks(at, host_hz) in u128:

let title_hz = u128::from(crate::queue::TIMESTAMP_FREQUENCY);
(u128::from(at) * title_hz / u128::from(host_hz.max(1))) as u64

timestamps_scale_to_the_title_clock pins both intervals from the review: 26,509,312 ticks on a 1 GHz host → 2,650,931, and 254,637 on a 10 MHz host → 2,546,370, plus a zero frequency.

The README row no longer lists real queries as missing.

TeresaPC added 2 commits November 26, 2026 10:46
BeginQuery, EndQuery and ResolveQueryData now record into the host list:
a console query heap gets a host heap on first use, of the matching type
(occlusion kinds share one, timestamps their own, pipeline statistics
theirs). Resolutions land in a read-back buffer the list maps once it has
run and copies into title memory.

Timestamps are the host GPU's clock, so they are rescaled to the title's
TICKS (100 MHz) on the way out; the queue's frequency comes from
GetTimestampFrequency. D3D12 has no BeginQuery for timestamps, so
begin_query skips them and only EndQuery marks them, as the API requires.

A heap whose kind or device cannot give a host heap keeps the previous
plausible answers, marked as a shortcut.
The copy-back multiplied in u64, so a tick count times 100 MHz saturated to
u64::MAX before the division and every guest timestamp came out identical:
a 1 GHz host passes u64::MAX / 100_000_000 with a 26.5 ms interval, and a
10 MHz host with 0.25 s. The product is now taken in u128; both of the
reviewed intervals scale correctly, which the test pins.

Rebased onto main 63bcca4 to resolve the conflict in host.rs (both sides
add a Deferred field, so both are kept), and the README row no longer lists
real queries as missing.
@steven-seagull27

steven-seagull27 commented Nov 26, 2026 •

Copy link
Copy Markdown

I ran a guest timestamp heap through EndQuery and ResolveQueryData on native Windows. Both the RTX 5080 and inbox WARP rejected the command list at Close on 1a7750b7 in two runs each. With the D3D12 debug layer enabled, the error was 0x80070057, “Query type does not match query heap type.” The test stopped before submitting that list.

Host::query_heap receives the guest heap descriptor’s kind. A timestamp heap is 1, while an EndQuery timestamp operation is 2. At this revision heap kind 1 creates an occlusion heap. I corrected the three supported heap mappings and kept the operation mapping intact. The test resolves the same two native slots through the guest path and directly on the same queue, and checks the words on either side of the guest destination. Heap enum · Operation enum

With that correction, the new timestamp scaling on this PR agrees with the native readback. Two runs per adapter gave exact timestamps and preserved both guard words. One interval per adapter is shown below. Guest deltas are in the title’s 100 MHz clock.

Adapter Native frequency Native delta Guest delta
RTX 5080, 621.40 1 GHz 7,223,328 722,332
Windows inbox WARP 10 MHz 70,417 704,170

For comparison, with the same heap correction on parent eed5cb69, both RTX timestamps saturated to 18446744073, giving a zero interval. WARP’s absolute ticks in these runs were still below the old overflow threshold and matched on the parent. Heap fix and opt-in GPU regression

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3138-query-heap-kind
git cherry-pick 4a47605a66f47dec0d9cdd9074e26f5a5a853108
$env:VICTORY_D3D12_DEBUG = '1'
$env:VICTORY_D3D12_WARP = '0'
cargo test --locked -p victory-gpu --features diagnostics --lib query::timestamp_readback::timestamp_heap_resolves_the_same_slots_as_native_d3d12 -- --exact --ignored --nocapture

Set VICTORY_D3D12_WARP=1 for the software comparison.

I also checked the other affected mapping using empty query intervals. The unmodified head refused a pipeline-statistics heap (kind 2, operation 3) on both adapters with the same debug-layer error. With the patch, all 88 bytes of the guest statistics matched the native result on each device, and both neighboring guards stayed intact. Ordinary and binary occlusion queries (heap 0, operations 0 and 1) matched the native results before and after the patch on both adapters.

AI-assisted implementation and verification using synthetic queries.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib query:: -- --test-threads=1: 3/3 passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: 4/4 passed; queue::: passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly executes timestamp/occlusion queries on the host GPU and resolves them back to title memory.

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

Callimann8 pushed a commit to Callimann8/VIctory-fork that referenced this pull request Nov 26, 2026
…y are (pull request Marvisak#927), SDWA sign extension of 16-bit results (upstream VIctory Marvisak#3124); two switches off by default (clamp windows, occlusion queries) and offline tools

- Marvisak#927 (tippythetaidum): a buffer_load_format whose every use takes a half as
  f16, and d16 typed loads and stores at a table's fixed places, move 16-bit
  integers bit-exactly through unsigned twin views (HostShader::half_views).
  The face network reads its indices this way: mouths open and move (confirmed
  in a test run on an RTX 4070). Thank you, tippythetaidum.
- upstream Marvisak#3124: SDWA dst_unused 1 (sext) with WORD_0 copies bit 15 upward;
  the reserved dst_unused 3 is refused.
- VICTORY_CLAMP_WINDOW=1|alt (after upstream Marvisak#3197): indirect draws clamped a
  window at a time. Measured on this layer: 1.0 draw a pass (nothing joins):
  stays off.
- VICTORY_OCCLUSION=1|alt (after upstream Marvisak#3138): the title's occlusion
  queries answered by the card; a counter of queries by kind (the title begins
  thousands). Not yet measured: off.
- translate: VICTORY_NATIVE_HEADS lists each container program's first bytes;
  an ignored test decodes a raw GFX10 code file; the native pipeline dump
  writes root signatures. (Device methods 0x1c8 / 0x218 turned out to be a
  precompiled-pipeline cache the title falls back from.)

The shader translator changed: delete both shader caches before the first run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants