GPU: occlusion, statistics and timestamp queries run on the host #159
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!159
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-159"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@r4tedx on GitHub · 2026-11-24 01:01 UTC · original
r4tedx:gpu/host-queries→main· +932 −28 · 6 files · 4 commits · openRebased onto
main940d32fand reworked (headb7249e5, 2026-11-25).mainstill has no host queries (BeginQuery/EndQuerydo nothing,ResolveQueryDatawrites stand-ins), so the change is still needed. What is different from the earlier head: results no longer go into the title buffer's host copy; they go through read-back memory, see "What".mainalready has the overflow-safe bounds check of #52, so this no longer touches it.What
The README lists real queries as missing for the world:
BeginQuery/EndQuerydid nothing andResolveQueryDatawrote stand-ins (2^20 samples, visible, zero statistics, the clock after the submission).First commit:
BeginQuery/EndQueryare recorded into the list's host list in order with its draws, by D3D12's rules: timestamps only end, a query already running does not begin again, an end without its begin in the same list is dropped, queries still running at close are ended there (and keep the stand-in).ResolveQueryDataresolves every measured query, of any type, into read-back memory the list owns: mapped 64 KiB chunks that stay copy destinations and are reused after a reset. No title buffer's host copy is touched, so the resolve does not depend on the state the title's shaders and indirect executions left that copy in. An earlier head resolved into the host copy and assumed it was in COMMON, which a review found does not hold in the world (indirect::doneleaves the copy in UNORDERED_ACCESS, and a submission's lists share oneExecuteCommandLists).main's copy-back of shader writes is unchanged, and a list whose shaders read title memory with no host copy still delivers its query results, since deferred writes are not withheld.GetTimestampFrequencyand bottom-of-pipe timestamps use) from the host queue's clock calibration, read once before the writes, so a stand-in timestamp written first never reads earlier than a host one after it.Second commit: an occlusion or binary occlusion query with a title draw inside that the host did not run (pipeline not ready, a shader that does not translate, an indirect execution that cannot run) is ended on the host but keeps the stand-in "visible". Otherwise, while draws of untranslated shaders are still dropped, real queries would report nothing visible and the title would cull by that.
Known limits
mainhas no predication, the one D3D12 feature that reads a resolve buffer on the GPU.y * z != 1runs only itsxgroups.main's heap-view, title-memory and depth-twin dispatches) are counted in pipeline statistics.Not verified
Nothing has run on a hardware GPU, under the D3D12 debug layer or in the title since the rebase; the RTX 5070 runs were of the earlier head. No game files were used.
Tested
At
b7249e5, on WARP only (VICTORY_D3D12_WARP=1,--features diagnostics, one test thread), synthetic. The tests call the title's list, queue and heap methods; the draws come from a small host pipeline recorded into the title list's host list, since title pipelines need translated console shaders.DrawInstancedwith nothing bound inside occlusion queries resolves to the stand-ins while a query begun after it measures 0.cargo test -p victory-gpu: 153 passed, 0 failed, 2 ignored (the two aremain's benchmarks).cargo test -p xtask: 6 passed.cargo clippy --workspace --all-targets --locked -- -D warningsand the--all-featuresvariant: clean.#32 rewrites parts of
host.rsthis touches; whichever lands second needs a rebase.AI-assisted; no game assets were used.
🤖 Generated with Claude Code
842b0cb) into the host queries branch 543de3b676@r4tedx on GitHub · 2026-11-24 03:11 UTC · original
Two corrections to my own PR.
1. A claim I have withdrawn. The first commit's message said the query tests were clean under the debug layer and GPU-based validation. That was wrong: the D3D12 debug layer (
d3d12SDKLayers.dll) is not installed on the machine these tests ran on, so nothing was validated. I have reworded the commit message (force-pushed, no code change; head is now29c52d2). The tests still pass (47), but resource-state mistakes in the resolve would not have shown.2. This needs adapting once a buffer-state tracker lands (#334 or #367).
host_resolverelies on the buffer's host copy being in COMMON whenResolveQueryDataruns (promotion to COPY_DEST), then issues its own COPY_DEST to COMMON barrier. That holds onmain. It does not hold with either tracker:refresh/gpu_writesleave it explicitly in UNORDERED_ACCESS just before the resolve.The fix is to drop the manual barrier and ask the tracker for COPY_DEST before the resolve (
list.buffer_state(&shadow.buffer, COPY_DEST)with #334,list.resource_state(..)with #367). I will do that on top of whichever of the two is merged; a trial merge with #334 is textually clean and passes tests, which is exactly why this needs saying.If someone with the debug layer installed can run
cargo test -p victory-gpu querywithVICTORY_D3D12_DEBUG=1on this branch, the output would be useful.@465d6a0eac on GitHub · 2026-11-24 16:29 UTC · original · edited 2026-11-24 17:20 UTC
Thank you for this, @r4tedx! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/28. You're credited as the author there. This pull request stays the original.
Test results
cargo clippy(both variants) andcargo test --workspacepass (346 passed, 0 failed), including the fourquery::testson the GPU (occlusion around draws, draw statistics, timestamps on the title clock, queries not run).@Marvisak on GitHub · 2026-11-25 00:18 UTC · original · edited 2026-11-26 03:19 UTC
Automated triage for the maintainers.
Thanks for the merge of
mainand the test update. Re-reviewed atba872ae2: occlusion, binary occlusion, pipeline statistics and timestamp queries are recorded into the host list (list.rsbegin_query/end_query,HostList::begin_query/end_query), resolved into list-owned read-back chunks (HostList::query_readback,host_resolve), and copied into title memory by the existing ordered deferred writes, with timestamps converted to the 100 MHz title clock viaHost::clock. Queries around draws the host dropped keep the "visible" stand-in (missed_drawindraw.rsand the indirect paths). This avoids the earlier dependence on the title buffer's host-copy state, and the README line is updated to match. The cfg(windows) gating looks consistent withmod state/host_list. A third-party run on an RTX 3050 reported matching occlusion, statistics and timestamp results.Open items, as the description lists them: no debug-layer or DRED run yet, and GPU reads of a resolve buffer later in the same submission still see the old bytes.
Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.
Generated by Claude Code
@r4tedx on GitHub · 2026-11-25 04:30 UTC · original
@JurajSimicevic thank you, both for closing #1740 in this one's favour and for the offer there, which I only saw now. Yes please.
This branch is being brought up to
main(940d32f) at the moment. It conflicts inhost.rs,list.rs,shadow.rsand the README, andhost_resolvehas to be checked against howmainhandles the states of its buffer copies today (my note of 24 Nov above: it relies on the host copy being in COMMON whenResolveQueryDataruns). I will post the new head here when it is pushed.What a run in the game with the debug layer and DRED would settle, and what I cannot check here (this machine has no debug layer, and the title is not launched on it):
ResolveQueryDataand the copy that follows it;Nothing was run for this comment.
AI-assisted (Claude Code).
@r4tedx on GitHub · 2026-11-25 05:26 UTC · original
@JurajSimicevic the head for your run is
b7249e5: rebased ontomain940d32f, two commits.One thing changed beyond the rebase, and it bears on what your debug-layer run would have shown. The earlier head resolved occlusion and statistics results straight into the title buffer's host copy and assumed that copy was in COMMON. A review of the rebased code found that this does not hold in the world:
indirect::doneleaves the copy in UNORDERED_ACCESS, and a submission's lists share oneExecuteCommandLists, so a resolve after a shader write or an indirect execution on the same buffer would have been two state errors. Now every query type resolves into read-back memory the list owns, and the results reach title memory by the same ordered CPU writes as the stand-ins once the submission has run.main's copy-back is untouched.What a run would settle now:
ResolveQueryData(the destination is always the list's own read-back buffer);Tested at
b7249e5on WARP only (diagnostics build, one test thread):cargo test -p victory-gpu153 passed, 0 failed, 2 ignored; both clippy commands clean. Nothing has run on a hardware GPU or under the debug layer since the rebase. The description has the details and the limits.No game data was used. AI-assisted.
@Dathinel on GitHub · 2026-11-25 09:51 UTC · original
Hardware result for
b7249e5on an NVIDIA GeForce RTX 3050 Laptop GPU (adapter identified from the D3D12 device LUID). I extended the synthetic triangle test to bracket its draws with two timestamps, resolve all three query types into separate ranges of the same buffer, and submit the list once.940d32f.This exercises CPU readback after completion. D3D12GetDebugInterface(ID3D12Debug) returned 0x887A002D here. Debug-layer/DRED diagnostics and GPU consumption of the result within the same submission remain open. AI-assisted, synthetic inputs only.
@r4tedx on GitHub · 2026-11-26 02:58 UTC · original
Merged main
842b0cbinto the branch (merge543de3b6, no force-push), head nowba872ae2. The follow-up commit updates the query-resolve test for main's three-argumentindirect::bound(#158's clamp) and renames it to say what it checks. Verified on this head:cargo clippyclean;VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 253 passed, 0 failed, 1 ignored. Synthetic tests on WARP only, no title data used.AI-assisted
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.