GPU: route non-overlapping CopyMemoryToMemoryX through Step::Copy and scope invalidation to written ranges #1660

Open
anlnimus wants to merge 1 commit from upstream-pr/1661 into main
anlnimus commented 2026-11-24 20:33:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by anlnimus on 2026-11-24T20:33:40Z.


Summary

  1. Route non-overlapping CopyMemoryToMemoryX through HostList::defer_copy (Step::Copy)
    • In crates/victory-gpu/src/list.rs, non-overlapping CopyMemoryToMemoryX calls now use list.defer_copy(...) (Step::Copy -> copy_mapped with watch::writing, page-wise fallback on unmapped pages, PREPARING accounting, and range-scoped invalidation) instead of resetting all cached refreshes via Step::Run.
    • Overlapping copies keep list.defer(...) + std::ptr::copy (memmove semantics) and hold a crate::watch::writing(d, len) guard around the copy so guarded title pages do not fault on submission.
  2. Scope Deferred and Batch invalidation to the written title range
    • Added Staging::title_range() in crates/victory-gpu/src/texture.rs so each staged texture tracks its [start, end) title address span in Batch::textures.
    • Tracked bindless heap dedup in Deferred::heaps rather than overloading Deferred::refreshed with usize::MAX, clearing heaps on any non-empty title write while retaining non-overlapping refreshed buffer ranges and fills.
    • In Batch::title_written(Some((from, to))), flush only overlapping pending refreshes (rebuilding pending indices for kept refreshes) and evict only overlapping current copy ranges, staged textures, and cached fills. Unbounded Step::Run closures (HostList::defer) conservatively keep full invalidation (title_written(None)).
  3. Deduplicate repeated Step::Fill upload copies across a list and submission
    • Deferred::first_fill and Batch::fill_due share record_fill(...), skipping identical (upload_dst, title_src, len) fills when neither the title source range nor an overlapping slice of the upload destination buffer has been overwritten since the earlier fill.

Verification (Windows 11 x64, rebased on main @ 940d32f)

  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
  • cargo test --workspace --locked: 703 passed, 0 failed, 10 ignored across all 17 test executables, including:
    • victory-gpu: 146 passed, 0 failed, 2 ignored, including a_texture_is_checked_once_per_submission, title_writes_make_textures_due_again, a_copy_is_refreshed_once_per_submission_by_the_pages_written, disjoint_title_copy_preserves_unrelated_textures, upload_fill_dedup_respects_overlapping_writes_and_dst_overwrite, and deferred_title_written_scopes_refreshes_and_fills
    • xtask: 6 passed, 0 failed (policy::tests::repository_passes_policy passed)

Prepared and tested with AI assistance.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590864221 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1661). Originally posted by [anlnimus](https://github.com/anlnimus) on 2026-11-24T20:33:40Z. --- ### Summary 1. **Route non-overlapping `CopyMemoryToMemoryX` through `HostList::defer_copy` (`Step::Copy`)** - In `crates/victory-gpu/src/list.rs`, non-overlapping `CopyMemoryToMemoryX` calls now use `list.defer_copy(...)` (`Step::Copy` -> `copy_mapped` with `watch::writing`, page-wise fallback on unmapped pages, `PREPARING` accounting, and range-scoped invalidation) instead of resetting all cached refreshes via `Step::Run`. - Overlapping copies keep `list.defer(...)` + `std::ptr::copy` (`memmove` semantics) and hold a `crate::watch::writing(d, len)` guard around the copy so guarded title pages do not fault on submission. 2. **Scope `Deferred` and `Batch` invalidation to the written title range** - Added `Staging::title_range()` in `crates/victory-gpu/src/texture.rs` so each staged texture tracks its `[start, end)` title address span in `Batch::textures`. - Tracked bindless heap dedup in `Deferred::heaps` rather than overloading `Deferred::refreshed` with `usize::MAX`, clearing `heaps` on any non-empty title write while retaining non-overlapping `refreshed` buffer ranges and `fills`. - In `Batch::title_written(Some((from, to)))`, flush only overlapping pending `refreshes` (rebuilding `pending` indices for kept refreshes) and evict only overlapping `current` copy ranges, staged `textures`, and cached `fills`. Unbounded `Step::Run` closures (`HostList::defer`) conservatively keep full invalidation (`title_written(None)`). 3. **Deduplicate repeated `Step::Fill` upload copies across a list and submission** - `Deferred::first_fill` and `Batch::fill_due` share `record_fill(...)`, skipping identical `(upload_dst, title_src, len)` fills when neither the title source range nor an overlapping slice of the upload destination buffer has been overwritten since the earlier fill. ### Verification (Windows 11 x64, rebased on `main` @ `940d32f`) - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `cargo test --workspace --locked`: 703 passed, 0 failed, 10 ignored across all 17 test executables, including: - `victory-gpu`: 146 passed, 0 failed, 2 ignored, including `a_texture_is_checked_once_per_submission`, `title_writes_make_textures_due_again`, `a_copy_is_refreshed_once_per_submission_by_the_pages_written`, `disjoint_title_copy_preserves_unrelated_textures`, `upload_fill_dedup_respects_overlapping_writes_and_dst_overwrite`, and `deferred_title_written_scopes_refreshes_and_fills` - `xtask`: 6 passed, 0 failed (`policy::tests::repository_passes_policy` passed) _Prepared and tested with AI assistance._
catminou4 commented 2026-11-24 23:04:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T22:19:49Z.

Review: COMMENTED


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

Non-overlapping CopyMemoryToMemoryX transfers go through the upload path: ranges_overlap() half-open interval check + cached identical-fill eviction on overlapping destinations, 3 tests. The overlap predicate is the correctness core — half-open intervals are the right choice for byte ranges.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048310919 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1661#pullrequestreview-6048310919). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T22:19:49Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Non-overlapping CopyMemoryToMemoryX transfers go through the upload path: ranges_overlap() half-open interval check + cached identical-fill eviction on overlapping destinations, 3 tests. The overlap predicate is the correctness core — half-open intervals are the right choice for byte ranges.
Marvisak commented 2026-11-25 02:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:33:43Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/host.rs, crates/victory-gpu/src/texture.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149689045 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1661#issuecomment-7149689045). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:33:43Z. --- <!-- victory-triage v1 head=e524046a74e19d28074cc0d2394cf7831c98af0a verdict=needs-rebase at=2026-11-25T15:56:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/texture.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
anlnimus commented 2026-11-25 06:02:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by anlnimus on 2026-11-25T05:57:31Z.


Rebased onto current main (940d32f); all CI checks (cargo clippy --workspace --all-targets --locked -- -D warnings, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --locked) pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154300253 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1661#issuecomment-7154300253). Originally posted by [anlnimus](https://github.com/anlnimus) on 2026-11-25T05:57:31Z. --- Rebased onto current `main` (`940d32f`); all CI checks (`cargo clippy --workspace --all-targets --locked -- -D warnings`, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`, `cargo test --workspace --locked`) pass.
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/1661:upstream-pr/1661'
git switch 'upstream-pr/1661'

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