Repository navigation
Conversation
…ages current copy_back read each 64 KiB piece of title memory, put the GPU's bytes in, and wrote the whole piece back. A title write to any other byte of the piece in between was undone. It now writes back only the runs of bytes the GPU changed. It then marked every synced page current from one write-watch query made after all pieces. That query also cleared any title write made after a page was read, so the page counted as current while holding old data. A page is now marked current only if title memory, read again after the query, still matches the copy; the others stay stale for the next refresh. Fixes Marvisak#721, fixes Marvisak#722.
…able Writing each run back through the kernel cost a system call per run, and shaders' scattered writes make thousands of runs a piece: 1.3-1.9 s of copy-back a frame in the world. One query per piece now checks that the runs lie in committed read-write memory, and they are stored directly; otherwise each still goes through write_mapped. The query is shared with the guard handler's check.
|
The three copyback tests passed at 67125b3 on an RTX 4090 under Wine/vkd3d-proton 3.2. They covered preserving a concurrent title write, seeing it in the host copy after refresh, and leaving a read-only title page untouched. We also combined #1024 with #1019 and #322. The existing guest compute test wrote two 56-byte records through an off-element placed UAV. After submission, both GPU-written fields were present in guest memory and all surrounding bytes matched on both ordinary and write-watched allocations. The combined GPU suite had 64 passes, one ignored test and the known Wine empty-library failure. These runs used stable mappings. They did not measure title copyback time or same-submission visibility through another backing copy. |
|
Ran the three copy-back tests at Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by
Not tested: the title itself (no game data here, and its world can hang the adapter per the README), RDNA2/RDNA4 and Intel GPUs. AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used. |
|
Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree:
So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232). AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described. |
|
A measured hint on speed, from my own port of this idea (not your build; head 67125b3), RX 6800, Windows 11, one launch, 8 looped world frames of 36 submissions: the write-back with The correctness part, writing only what the GPU changed, looks right to me. AI-assisted (Claude Code). |
|
@TG0000 thanks for measuring. 302 against 292 ms is what this PR aims for: only the GPU's bytes are written, at I agree a fault-tolerant store is the better end state: there's no query, and no window between the query and the stores. It needs the store direction of #1010's copy, though, and #1010 only reads title memory. If #1010 merges first, I'll switch |
|
No new routine: the port called #1010's (302 against 292 ms is the port on this PC; I did not measure the per-run AI-assisted (Claude Code). |
|
Thank you for this, @Dufftwt! 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/36. You're credited as the author there. This stays the original. Test results
|
…ly if it still matches Shadow::copy_back read a title page, merged the GPU's bytes in and wrote the whole page back. A title thread writing another byte of that page in between lost its write. With VICTORY_ROOT_UAVS=1 much more of the title's big GPU heap (which also holds its command memory and fence lists) is copied back every submission, and the title crashed at world load reading 0xffff... pointers (patterns/d13z4-crash.txt). Same idea as upstream Marvisak#1024 (Dufftwt), redone on this stack's page snapshots: - merge_gpu_runs records the exact byte runs the GPU changed; only those go back, stored directly when one VirtualQuery says they lie in committed read-write memory (host::write_runs/writable), else through write_mapped run by run. - After the write-watch query that marks synced pages current, a page is marked only if title memory, read again, still equals the copy: the query also cleared a title write made after the page was read. Logic of merge_gpu_runs checked against the byte-by-byte merge (test word_merge_matches_byte_merge extended; also run standalone on Linux). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSE7XjLLUipXi15813g
|
I retained Duff's authored 3b2181a byte-run copyback in a #387 test branch. Both concurrent title-write controls passed on native Windows with the GPU crate optimized. In a CPU-only 4 MiB snapshot/copyback fixture, changing one byte per 32 bytes generated 131,072 guarded writes and raised median copyback from 1.37 ms to 718.99 ms. The dense and sparse controls are in the reproduction. I kept this candidate separate from #387. The later direct-store shortcut needs the mapping to remain the same generation from VirtualQuery through the stores. An address protection snapshot alone does not provide that lifetime across unmap and reuse. The byte-ownership regressions remain useful for checking a guarded fast path. |
|
@aycow thanks for the controls and the fixture. Your numbers are for On the lifetime point, agreed: a query doesn't pin the mapping, and the PR marks the window as a |
|
Linux/Wine integration test of head Setup: RTX 5090, NVIDIA 620.73.04, CachyOS7.3.6, Wine11.22, vkd3d-proton3.2.0 The production delta merged into The first diagnostic GPU suite was 60 passed / 1 failed / 1 ignored. The failing test was Full Windows workspace on the adapted integration: 350 passed / 2 failed / 7 ignored, 14 test executables. Default-feature GPU58/0/1, shader122/0/2. The two unchanged Wine harness failures are the load probe's nested Linux cargo invocation and xtask's Linux git invocation. All-target/all-feature Clippy with warnings denied and native asset policy pass. Four shader differential tests still early-return without console/compiler tools; the local opt-in buffer-view diagnostic is the extra ignored test. Native Microsoft d3dcompiler_47 used; GPU tests ran on the RTX5090, serially, offline. No concurrent title GPU workload. No title run with this patch yet, so this establishes regression-test compatibility only, not a fix for world rendering, #698, or the GPU execution fault. AI-assisted with Codex. No game data or derived artifacts attached. |
|
Title follow-up to my synthetic Linux report: #1024 was tested for world loading, but it did not get past the later #698 pool exhaustion. Same RTX5090 / NVIDIA620.73.04 / Wine11.22 / vkd3d-proton3.2.0 setup and diagnostics as above. The direct control was the #747-style capped split (737856 mirrored / 262144 dynamic) on proton-fixes993dff8 + #852/#454/#206. The candidate adds only this PR's production delta at67125b3; its test fixtures retain the two submission-boundary adaptations described above. Both runs disabled VK_NV_raw_access_chains, used default loop limit, no shader skips, debug pixel shader and intermediate-target display.
Local captures show partial roads, signs and character geometry in debug colours; normal shaded rendering and controllable movement remain unverified. The #774 spin did not recur in this one candidate run, but that failure is intermittent, so this does not establish that #1024 fixes it. #698 is still reproduced. These runs are not a performance benchmark. Combined candidate checks: full Windows workspace350passed/2unchanged Wine harness failures/7ignored across14executables, diagnostic GPU61/0/1, all-target/all-feature Clippy-Dwarnings and native policy pass. Binary SHA256 AI-assisted with Codex; offline/app-muted, read-only title input. All runs stopped. No game-derived files attached. |
|
@ThomasHFWright thanks for running it in the title with a direct control. Agreed: one run doesn't establish a fix for the #774 spin. But it's the second time that freeze has gone with run-only write-back. On #721, xstraok saw the title freeze after about 4 minutes in the world, with two threads spinning in a hash-table probe at A probe that never ends fits #721's race: copy-back writes a whole 64 KiB piece back and puts older bytes over a table entry a title thread just wrote. Two runs on different GPUs and drivers point the same way. A few more control/candidate pairs would turn that into evidence. #698's |
…y unchanged pages current) onto Marvisak#346 + Marvisak#334 + integ/next Taken instead of Marvisak#693 (shadow buffers in DEFAULT VRAM with staging readback): both rewrite how shaders' writes reach title memory, on incompatible models (Marvisak#1024 stores from the CPU-mapped host copy; Marvisak#693 has no CPU mapping and merges from readback snapshots), so only one can land. Marvisak#693 has unfixed in-title regressions on its last head's predecessor and no title run since: about 2x slower frames and 5-7x GPU time on an RX 6700 XT (Marvisak#693 (comment)), GPU page faults inside freed `shadow readback/upload staging` on RX 6950 XT and RX 6700 XT (Marvisak#693 (comment)), and a changes-requested review (mercuryVM). Its last commit (1c94839) fixes the review's failure paths but not the performance loss, and was not run in the title. Marvisak#1024 has no negative report; its tests pass on RTX 4090/Wine, RTX 5070 Ti, RX 7700 XT, RTX 5090/Wine, and a title run with it (and Marvisak#472, Marvisak#322) had shorter frames and less copy-back time (AgneyaK). Conflicts, crates/victory-gpu/src/shadow.rs: 1. `Shadow::copy_back`: the stack (Marvisak#124, TG0000) skips pages already found unchanged against this submission's snapshot (`UnchangedPages`) and allocates the title buffer lazily, by PAGE; Marvisak#1024 writes back only the runs of bytes the GPU changed (`write_runs`) and marks a synced page current only if title memory still equals the copy after the final write-watch query. Independent: both kept. The loop keeps the stack's `unchanged.differs` guard and lazy buffer, with Marvisak#1024's run collection and `write_runs` inside; the final check takes the (by then allocated) lazy buffer for its page re-reads. 2. Tests: the stack's `mod tests` and Marvisak#1024's `mod copy_back_tests` at the same place. The shared text holds the closing `);`, `}` and `}`, so the stack's module is closed in the hunk and Marvisak#1024's module follows as its own `#[cfg(test)]` item (not nested). No other non-textual fix needed (cargo check --all-targets --all-features).
…us) onto Marvisak#1024 + Marvisak#346 + Marvisak#334 + integ/next One conflict, crates/victory-gpu/src/host.rs tests: the stack adds `adapter_filter_parses_index_and_name` and the capability tests, Marvisak#211 adds `present_compositor_builds_both_pipeline_states`, at the same place. The shared text holds the `#[test]` before and the closing brace after, so the stack's last test is closed in the hunk and Marvisak#211's follows as its own test (not nested). `Host::present` (single plane fast path, compositor for 2+) and `queue::present` merged without conflict; the stack does not change either. No non-textual fix needed (cargo check --all-targets --all-features). No negative report on Marvisak#211: the Series S menus render on RTX 2070 SUPER, RTX 4070 SUPER, RTX 3060 Laptop, RTX 4080, RX 7600 and WARP, and the device removals seen later in the world also happen in Series X mode without it.
…6B16A16_FLOAT) onto Marvisak#211 + Marvisak#1024 + Marvisak#346 + Marvisak#334 + integ/next Conflicts, both in tests: 1. crates/victory-gpu/src/descriptor/host.rs: the stack's tests (`raw_views_start_on_16_bytes` and the raw/structured view tests after it, from Marvisak#1426/Marvisak#704) and Marvisak#492's four `rgb9e5_srv_*` tests at the same place; git interleaved them over shared lines (a resource description's `SampleDesc`, a closing brace), so the two hunks are not separable texts. Resolved by keeping the stack's tests exactly as they were and adding Marvisak#492's four tests whole, as Marvisak#492 has them, before `dynamic_slots_are_held_until_released` (where Marvisak#492 put them). The resulting diff of the file against the previous head equals Marvisak#492's own (+235/-5 against main). 2. crates/victory-gpu/src/resource.rs: the stack's `get_desc_reports_the_allocated_mip_chain` and Marvisak#492's `r9g9b9e5_target_format_substitutes_rgba16f` / `r9g9b9e5_render_target_and_uav_textures_create_on_host` at the end of the module. The shared text holds the `#[test]` before and the closing braces after: the stack's test is closed in the hunk and Marvisak#492's follow as separate tests (not nested). The non-test changes (`target_format`, `fits` taking a resource description, `fits_texture_srv`, RTV and pipeline formats) merged without conflict. `fits` has no other caller in the stack. Uploads from title memory still skip render-target/UAV textures (`texture::title_written`), so no 4-byte RGB9E5 rows are detiled into a substituted 8-byte texture. Known open point from the review, not fixed by Marvisak#492: a copy between a substituted target and a sampled-only RGB9E5 texture would mismatch formats on the host; no report shows the title doing that. No non-textual fix needed (cargo check --all-targets --all-features).
…sak#98, Marvisak#334 to Marvisak#492, validation) The line rebuilt on the bundles' current heads (Marvisak#1402 119b763, Marvisak#1492 5bbc098 without Marvisak#98, Marvisak#1504 1d41891, Marvisak#1511 ca601f0) with every merge replayed, and the merges after this file's first version (Marvisak#334, Marvisak#346, Marvisak#1024, Marvisak#211, Marvisak#492): merge order, the runner's numbers on 967d3ae (RTX 571, WARP 570 + the known Marvisak#1084 failure, all features 580; Marvisak#98's one test leaves), what is not included (Marvisak#98, Marvisak#282 for Marvisak#346, Marvisak#693 for Marvisak#1024, Marvisak#306's latest commit), and the open pull requests whose head is contained here (109, from the 18:24 collection). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
Fixes #721, fixes #722.
What's wrong
After a submission,
Shadow::copy_back(crates/victory-gpu/src/shadow.rs) brings what shaders wrote back into title memory. It has two problems, both while the title's own threads keep writing the same memory:What the fix does
VirtualQueryper piece (the newhost::writable) checks that the runs lie in committed read-write memory. Where they don't, each run still goes throughwrite_mapped, which skips pages it can't write. Onewatch::writingper piece opens our guarded view blocks first. A block another thread guards again before the stores faults into our handler, which opens it.writable(at)check inwatch.rsnow callshost::writable(at, 1), the same query.How it behaves after the fix
Title writes made while copy-back runs are kept, and they reach the host copy at the next refresh. When the title doesn't write meanwhile, the result is the same as before. Copy-back takes about as long as writing whole pieces did, however scattered the GPU's writes are (timings below). The added cost is one 64 KiB read per page the GPU wrote, and one memory query per piece. The copy-back figure in the frame log now counts only the bytes actually written, so it drops.
shortcut:a title thread that unmaps or protects memory between the query and the stores would crash us. The GPU's bytes go back before the title is told the submission is done, so only a title that frees memory the GPU is still writing could do that.Tests
Three new tests in
shadow.rs(copy_back_tests), on write-watched memory and a host copy fromhost().shared_buffer. They skip without a host GPU. A test-onlywatch::forgetclears the journal for their memory when they free it, so a later test's allocation at the same address starts clean.copy_back_does_not_undo_title_writes_made_while_it_runs: a title thread keeps bumping a word in each of 64 pages whilecopy_backwrites a shader byte back into each. No write may go back to an older value.a_title_write_during_copy_back_reaches_the_copy: once copy-back has finished page 0, the title writes it while 62 pages are still to go. The next refresh must bring that write into the copy.a_read_only_title_page_is_left_alone: the title made one page read-only. Copy-back must not crash on it, and must leave it alone, aswrite_mappedalways did (the kernel's write fails there). The other 63 pages still get the shader's byte.I ran
cargo test -p victory-gpu -- --test-threads=1on GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml(the runner has a hardware D3D12 device as well as WARP):victory-gpu: 53 passed, 1 ignored).main(ffe310e): both fail.copy_back_does_not_undo_title_writes_made_while_it_runs:title writes undone by the copy-back,left: 64, right: 0, so every one of the 64 pages lost its title write.a_title_write_during_copy_back_reaches_the_copy:in the copy,left: 0, right: 7. The write reached title memory but never reached the copy.cargo clippy -p victory-gpu --all-targets -- -D warningsis clean, with and without--all-features.Timings. A scratch test (not in this PR) timed one
copy_backof 64 pages in which the shaders changed every Nth byte. It ran as a release build on the same runner, 3 rounds each, against this PR without its second commit (onewrite_mappedper run):write_mappedper runNot tested: a title run with this branch. Vaximous (RTX 4070 Ti, Windows) and xstraok (Wine) saw a crash and a freeze in the world go away with run-only write-back on #721.
Related: #124, #401 and #693 restructure
copy_backbut keep the whole-piece write; #261 fixes other cases where older bytes went back; #943 changeswrite_mapped's fallback and #991 merges overlapping write-back ranges, on the same lines. Whichever merges second needs a rebase. Fixes for this were also posted on #721 and #722 as branches, since PRs were closed to non-collaborators: xstraok (plain stores, without a check of the memory), Vaximous, Hiiva (with #722), and Machad3x (with #722; pieces with more than 64 runs are still written whole, which keeps the race in them). Their in-game runs are the evidence that this race matters.