GPU/texture: fall back to copy_mapped for never-filled partly mapped textures under no_wait #1392

Manually merged
github merged 1 commit from gh-pr/1392/head into gh-pr/1392/base 2026-11-27 01:03:07 +00:00
Owner

@⁠n-romanovich on GitHub · 2026-11-26 22:33 UTC · original
n-romanovich:fix/1284-no-wait-partly-mapped → main · +85 −24 · 1 files · 1 commits · merged 2026-11-26 23:06 UTC

Related to #923 and #1284.

Problem

When VICTORY_TEXTURE_NO_WAIT=1 is active and watch::title_memory_reading_now() returns None (because the runtime is remapping title memory), Staging::refresh_timed delegates to Staging::refresh_unlocked. refresh_unlocked reads the texture through the kernel via host::read_into, which fails whenever any page inside [memory, memory + size) is uncommitted.

For a partly mapped streamed texture (such as indexed BC7/BC5 character skin textures), read_into always fails while the tail mips are uncommitted. If the staging buffer has never been filled yet (last.hash.is_none()), refresh_unlocked returns 0 without detiling anything; an indexed texture that receives no subsequent refresh keeps an all-zero staging buffer and renders black.

Changes (crates/victory-gpu/src/texture.rs)

  • Extract Staging::refresh_unlocked into refresh_unlocked_with so the unlock-path logic can be unit-tested against virtual memory reservations without a D3D12 device.
  • Inside refresh_unlocked_with, when host::read_into returns false and last.hash.is_none():
    • Read through host::copy_mapped (which copies mapped pages and zero-fills uncommitted pages safely).
    • If any mapped byte is non-zero, record last.hash = Some(blake3::hash(read)) and last.partial = Some(frame::current()), detile into the staging buffer, and return size (incrementing UNLOCKED[0]).
    • If all bytes are zero (nothing mapped yet), leave last.hash as None, reset last.asked = 0, and return 0.
  • When last.hash.is_some() (the staging buffer already holds previously detiled data), preserve the existing early-return behavior on read_into failure so an already-valid texture is never overwritten with partial/zeroed data during a concurrent remap.

Verification

  • Added unit test texture::title_memory_tests::no_wait_unlocked_falls_back_for_never_filled_partly_mapped_texture using VirtualAlloc (MEM_RESERVE + partial MEM_COMMIT), verifying:
    1. Initial refresh_unlocked_with with last.hash == None detiles mapped pages and zero-fills the uncommitted tail, setting last.hash and last.partial.
    2. Subsequent refresh_unlocked_with with last.hash.is_some() and an uncommitted tail returns 0, resets last.asked = 0, and does not invoke detile.
  • cargo test --locked -p victory-gpu --lib: 224 passed; 0 failed; 6 ignored
  • cargo test --locked -p victory-gpu --features diagnostics --lib texture: 15 passed; 0 failed; 1 ignored
  • cargo build --release --locked -p victory
**@⁠n-romanovich** on GitHub · 2026-11-26 22:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/1392) `n-romanovich:fix/1284-no-wait-partly-mapped` → `main` · +85 −24 · 1 files · 1 commits · merged 2026-11-26 23:06 UTC Related to #923 and #1284. ### Problem When `VICTORY_TEXTURE_NO_WAIT=1` is active and `watch::title_memory_reading_now()` returns `None` (because the runtime is remapping title memory), `Staging::refresh_timed` delegates to `Staging::refresh_unlocked`. `refresh_unlocked` reads the texture through the kernel via `host::read_into`, which fails whenever any page inside `[memory, memory + size)` is uncommitted. For a partly mapped streamed texture (such as indexed BC7/BC5 character skin textures), `read_into` always fails while the tail mips are uncommitted. If the staging buffer has never been filled yet (`last.hash.is_none()`), `refresh_unlocked` returns `0` without detiling anything; an indexed texture that receives no subsequent refresh keeps an all-zero staging buffer and renders black. ### Changes (`crates/victory-gpu/src/texture.rs`) - Extract `Staging::refresh_unlocked` into `refresh_unlocked_with` so the unlock-path logic can be unit-tested against virtual memory reservations without a D3D12 device. - Inside `refresh_unlocked_with`, when `host::read_into` returns `false` and `last.hash.is_none()`: - Read through `host::copy_mapped` (which copies mapped pages and zero-fills uncommitted pages safely). - If any mapped byte is non-zero, record `last.hash = Some(blake3::hash(read))` and `last.partial = Some(frame::current())`, detile into the staging buffer, and return `size` (incrementing `UNLOCKED[0]`). - If all bytes are zero (nothing mapped yet), leave `last.hash` as `None`, reset `last.asked = 0`, and return `0`. - When `last.hash.is_some()` (the staging buffer already holds previously detiled data), preserve the existing early-return behavior on `read_into` failure so an already-valid texture is never overwritten with partial/zeroed data during a concurrent remap. ### Verification - Added unit test `texture::title_memory_tests::no_wait_unlocked_falls_back_for_never_filled_partly_mapped_texture` using `VirtualAlloc` (`MEM_RESERVE` + partial `MEM_COMMIT`), verifying: 1. Initial `refresh_unlocked_with` with `last.hash == None` detiles mapped pages and zero-fills the uncommitted tail, setting `last.hash` and `last.partial`. 2. Subsequent `refresh_unlocked_with` with `last.hash.is_some()` and an uncommitted tail returns `0`, resets `last.asked = 0`, and does not invoke `detile`. - `cargo test --locked -p victory-gpu --lib`: `224 passed; 0 failed; 6 ignored` - `cargo test --locked -p victory-gpu --features diagnostics --lib texture`: `15 passed; 0 failed; 1 ignored` - `cargo build --release --locked -p victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:03:02 +00:00
github manually merged commit 89e30f7fb7 into gh-pr/1392/base 2026-11-27 01:03:07 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.