GPU: a draw's table entries are looked up once #3059
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3061"
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?
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T05:52:05Z.
Each draw's descriptor tables did two lookups per entry where one is enough. This is on the per-draw path (
tablesandreadableindraw.rs).Changes
tables: it looked up every entry's heap and slot to find tables that need making afresh, then looked them up again to make each entry. Tables are only made afresh for slots past a host heap that's smaller than its title heap (a host's cap, or a paged heap's). The newHeap::capped()says whether a heap is in that state. With no such heap bound, which is the usual case, each entry is made directly.readable: a constant view's copy was found for its first byte, then found again for the range up to that copy's end. The second lookup returns the same copy: the innermost buffer, or the same 4 MiB window of loose memory. Now it's one lookup.Testing
New test
the_copy_holding_a_views_first_byte_holds_it_to_its_end, for the invariant the second change relies on. It checks an inner buffer, its outer buffer, a range running past the inner buffer's end, and loose memory.The new test passes, and
victory-gpu'sdraw::anddescriptor::tests give the same results with and without this change. Both were cross-compiled for Windows in release and run under Wine and CrossOver on macOS. Not run on Windows.Measured with the conformance demo from #3021, on the fork's
demobranch (CrossOver, 720p, no overlay):It's a small win. Most of what's left per draw is making each host view (
HostHeap::mirror) and queueing its refresh.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:55:36Z.
Review: APPROVED
Reviewed head
d427676cline-by-line (CI green):draw::State::tables,freshis only ever populated whenindex >= host.count(), which requires a bound heap withhost.count() < desc.count(Heap::capped()). Checkingcappedup front avoids the redundant table-entry pass when no bound heap is capped.readable(View::Constant),shadow::find(address, 1)returns the innermost registered buffer (or loose-memory window) containingaddress, andlen = size.min(s.left(address))stays inside that copy, so reusingseliminates the secondshadow::findlookup with identical semantics.the_copy_holding_a_views_first_byte_holds_it_to_its_endverifies inner-inside-outer buffers, outer buffers, and loose-memory windows.Clean hot-path optimization.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:01:08Z.
Review: APPROVED
Verified both halves: (1) the capped-heap gate skips the fresh-table path unless a bound heap's host is actually smaller than its title's — the only case tables must be made afresh, so uncapped draws do one lookup per entry as before. (2) The single
findis provably equivalent:len = min(size, s.left(address))keeps the range inside the innermost copy holding the first byte, so the second lookup could only have returned it; the test covers nested inner/outer buffers and loose memory.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:29:52Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):State::tableswhen no bound heap is capped (avoiding double table-entry lookups) and avoiding the redundant secondshadow::findcall inreadableforView::Constantcleanly trims hot-path draw overhead without changing behavior.cargo test -p victory-gpu draw::tests -- --test-threads=1(RTX 5090 & WARP): 20 passed, 0 failed on both.cargo test -p victory-gpu shadow::tests -- --test-threads=1(RTX 5090): 10 passed, 0 failed (includingthe_copy_holding_a_views_first_byte_holds_it_to_its_end).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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:17:02Z.
Automated triage for the maintainers.
Merge candidate. This is a small per-draw speed-up with no change in behaviour, as far as I can tell from reading it.
State::tables(crates/victory-gpu/src/draw.rs) now skips the first pass when no bound heap iscapped().capped()is a new method onHeapindescriptor.rs: host slot count below the title's. Onmainan entry only goes tofreshwhen its index is at or pasthost.count(), and the index is always belowdesc.count. So when no heap is capped,freshwould be empty and every entry would go totable_entryanyway. The capped case keeps the old path unchanged.readableno longer looks up a constant view a second time.shadow::findreturns the innermost entry (largest start) whose end covers the range. The second lookup asks for a range ending at or before that copy's end, so it cannot return a different, more inner entry. Loose memory stays in the same window. The new test inshadow.rschecks both cases.CI:
checkpassing. The measured gain in the description is about 4%, on one configuration.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:24:48Z.
Windows 11,
63bcca4+ this PR, the CI job's own commands:cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: 872 passed, 0 failed, across 30 suitesvictory-gpualone: 232 passed / 0 failed / 1 ignored,the_copy_holding_a_views_first_byte_holds_it_to_its_endincluded.Synthetic only. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-27T15:50:04Z.
A test report: on Windows 11 (NVIDIA), the new test
the_copy_holding_a_views_first_byte_holds_it_to_its_endsometimes hangscargo test -p victory-gpu --lib.Repeated runs with a 60 s limit (a normal run finishes in about 3 s):
main63bcca4main+ this PR (headd427676)main+ this PR,--skip the_copy_holding_a_views_first_byte_holds_it_to_its_endWhen it hangs, the tests left running are always among
memory::tests::lists_share_a_table_and_copies_keep_their_views,memory::tests::a_submission_that_missed_leaves_the_copies_at_once,memory::tests::bitmap_pool_reuses_and_zeroes_across_resets,resource::tests::*,queue::tests::aliased_present_planes_preserve_the_host_texture_stateandwatch::tests::concurrent_writes_and_takes_lose_no_write, using all cores. My guess, not verified: the test registers resources with made-up ids (base | 1,base | 2) and loose-memory copies in the process-wide shadow registry while those tests run in parallel, and frees the memory afterwards, so the other tests can meet those entries.The runtime change itself looked fine: without that test, 20 of 20 runs are clean. I left this PR out of #3409 for now only because of the hang.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.