GPU: check a sampled texture once per submission, not once per list #79

Manually merged
github merged 1 commit from gh-pr/79/head into gh-pr/79/base 2026-11-26 03:49:29 +00:00
Owner

@⁠TG0000 on GitHub · 2026-11-24 00:16 UTC · original
TG0000:perf/texture-check-once-per-submission → main · +125 −9 · 2 files · 1 commits · merged 2026-11-24 00:41 UTC

What

A title texture's staging refresh (texture::Staging::refresh) ran as a host step of every list that sampled it. When several lists in one submission sample the same texture, it was checked again for each list. In physical-page memory, which cannot be write-watched, each check is a VirtualQuery walk (texture::committed) plus a blake3 hash of the whole texture.

Checks after the first one in a submission did nothing:

  • every list's CopyTextureRegion reads the same staging buffer, and
  • the GPU runs those copies only after all of the submission's CPU-side steps (run_deferred for every list, then ExecuteCommandLists).

So a second check could change only what the GPU reads if title memory had been written in between.

How

  • Texture refreshes are now their own step: Step::Texture(Arc<Staging>), added via HostList::defer_texture. Before, they went through the generic defer_host closure.
  • The submission's Batch, which already merges buffer refreshes across lists, now also records the staging buffers it has refreshed (texture_due).
  • Step::Copy (a write into title memory) and Step::Run (work that may write title memory) call Batch::title_written(). It flushes pending buffer refreshes, as before, and clears the texture record, so a texture is checked again after any such write. This is the same rule Step::Refresh follows ("once per submission … until a Copy or Run intervenes").
  • GpuWrite still only flushes, because it doesn't write title memory.

Two files: crates/victory-gpu/src/host.rs and crates/victory-gpu/src/texture.rs (the Staging type and its refresh become pub(crate)).

Benchmark (synthetic)

host::tests::texture_checks_per_submission (ignored) runs on one submission. It times the blake3 hashing done when each of 12 lists checks the same 48 textures of 4 MiB, then the same with the new per-submission check. The list and texture counts are made up, not measured from a title.

cargo test --release -p victory-gpu --lib -- --ignored --nocapture texture_checks
12 lists sampling 48 textures of 4 MiB: before 576 hashes in 676.2ms, after 48 in 56.5ms (12.0x)
12 lists sampling 48 textures of 4 MiB: before 576 hashes in 685.3ms, after 48 in 64.7ms (10.6x)
12 lists sampling 48 textures of 4 MiB: before 576 hashes in 715.3ms, after 48 in 57.5ms (12.4x)

The real gain depends on how many lists of a world submission sample the same physical-page textures. This PR doesn't measure that, because the title wasn't run.

Tests

  • New: a_texture_is_checked_once_per_submission and title_writes_make_textures_due_again.
  • cargo test --workspace (stable MSVC): all pass.
  • cargo clippy --workspace --all-targets: same 16 warnings as main, none in the changed code.
  • cargo fmt --check: no new diffs. main already has rustfmt diffs in victory-gpu; those remain.
  • cargo xtask policy: asset policy: 150 files ok.
  • Windows 11. Not run against the title and not GPU-tested: the change is CPU-side submission bookkeeping, and the unit tests don't need a host device.

No game data is in the commit, the tests or this description.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 00:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/79) `TG0000:perf/texture-check-once-per-submission` → `main` · +125 −9 · 2 files · 1 commits · merged 2026-11-24 00:41 UTC ## What A title texture's staging refresh (`texture::Staging::refresh`) ran as a host step of **every list** that sampled it. When several lists in one submission sample the same texture, it was checked again for each list. In physical-page memory, which cannot be write-watched, each check is a `VirtualQuery` walk (`texture::committed`) plus a **blake3 hash of the whole texture**. Checks after the first one in a submission did nothing: - every list's `CopyTextureRegion` reads the same staging buffer, and - the GPU runs those copies only after all of the submission's CPU-side steps (`run_deferred` for every list, then `ExecuteCommandLists`). So a second check could change only what the GPU reads if title memory had been written in between. ## How - Texture refreshes are now their own step: `Step::Texture(Arc<Staging>)`, added via `HostList::defer_texture`. Before, they went through the generic `defer_host` closure. - The submission's `Batch`, which already merges buffer refreshes across lists, now also records the staging buffers it has refreshed (`texture_due`). - `Step::Copy` (a write into title memory) and `Step::Run` (work that may write title memory) call `Batch::title_written()`. It flushes pending buffer refreshes, as before, and clears the texture record, so a texture is checked again after any such write. This is the same rule `Step::Refresh` follows ("once per submission … until a `Copy` or `Run` intervenes"). - `GpuWrite` still only flushes, because it doesn't write title memory. Two files: `crates/victory-gpu/src/host.rs` and `crates/victory-gpu/src/texture.rs` (the `Staging` type and its `refresh` become `pub(crate)`). ## Benchmark (synthetic) `host::tests::texture_checks_per_submission` (ignored) runs on one submission. It times the blake3 hashing done when each of 12 lists checks the same 48 textures of 4 MiB, then the same with the new per-submission check. The list and texture counts are made up, not measured from a title. ``` cargo test --release -p victory-gpu --lib -- --ignored --nocapture texture_checks 12 lists sampling 48 textures of 4 MiB: before 576 hashes in 676.2ms, after 48 in 56.5ms (12.0x) 12 lists sampling 48 textures of 4 MiB: before 576 hashes in 685.3ms, after 48 in 64.7ms (10.6x) 12 lists sampling 48 textures of 4 MiB: before 576 hashes in 715.3ms, after 48 in 57.5ms (12.4x) ``` The real gain depends on how many lists of a world submission sample the same physical-page textures. This PR doesn't measure that, because the title wasn't run. ## Tests - New: `a_texture_is_checked_once_per_submission` and `title_writes_make_textures_due_again`. - `cargo test --workspace` (stable MSVC): all pass. - `cargo clippy --workspace --all-targets`: same 16 warnings as `main`, none in the changed code. - `cargo fmt --check`: no new diffs. `main` already has rustfmt diffs in `victory-gpu`; those remain. - `cargo xtask policy`: `asset policy: 150 files ok`. - Windows 11. Not run against the title and not GPU-tested: the change is CPU-side submission bookkeeping, and the unit tests don't need a host device. No game data is in the commit, the tests or this description. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A title texture's staging refresh ran as a host step of every list that
sampled it. When several lists in one submission sampled the same
texture, it was checked again for each of them. In physical-page memory,
which cannot be write-watched, each check is a VirtualQuery walk and a
blake3 hash of the whole texture. Every list's GPU copy reads the same
staging buffer after all submission-time steps have run, so checks after
the first one in a submission did nothing unless title memory had been
written in between.

Texture refreshes are now their own step. The submission's Batch, which
already merges buffer refreshes, records the staging buffers it has
refreshed. A Copy into title memory or a Run step (work that may write
title memory) clears that record, so a texture is checked again after
any such write, as buffer refreshes are.

A synthetic benchmark (ignored test, release build, 12 lists sampling
48 textures of 4 MiB): 576 hashes in ~690 ms before, 48 in ~60 ms
after (~11x).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:28 +00:00
github manually merged commit 73d776b9c9 into gh-pr/79/base 2026-11-26 03:49:29 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:57 UTC · original

Tested 73d776b under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.\n\n- victory_gpu: 38 passed, 3 failed, 1 ignored; the three are the environment-only failures (argument_clamp_builds, a_rejected_blob_gives_an_empty_library, #128's upload skip).\n- The change is a per-submission deduplication, and the suite still passes with it.\n\nNo game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/79#issuecomment-7118616889) Tested `73d776b` under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with `cargo xwin ... --target x86_64-pc-windows-msvc`: **pass, no regression**.\n\n- `victory_gpu`: **38 passed, 3 failed, 1 ignored**; the three are the environment-only failures (`argument_clamp_builds`, `a_rejected_blob_gives_an_empty_library`, #128's upload skip).\n- The change is a per-submission deduplication, and the suite still passes with it.\n\nNo game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!79
No description provided.