vkback: shift clear_compressed by Img::base and clear BC prefixes via copy #192

Open
github-bot wants to merge 1 commit from github-bot/gh-192 into main AGit
Owner

@⁠Mhyster on GitHub · 2026-12-02 07:00 UTC · original
Mhyster:fix/tex-bc-clear-base-level → main · +122 −32 · 2 files · 1 commits · open

What

Fixes two Vulkan validation and out-of-bounds copy bugs when clearing streamed block-compressed (BC) textures:

  1. Shift clear_compressed mip extents by Img::base (fill.rs clear_compressed / clear_compressed_regions, imgmake.rs make_image): when a streamed 2D placed texture is created from console level base > 0, the Vulkan image's level 0 has dimensions (width >> base, height >> base). Previously, clear_compressed computed (desc.width >> m, desc.height >> m) without adding base, recording vkCmdCopyBufferToImage extents 2^base× larger than the image (VUID-vkCmdCopyBufferToImage-imageExtent-00207, out-of-bounds GPU write on unfilled streamed BC textures). Now clear_compressed_regions shifts by base + m (with overflow-safe checked_shr) and skips empty region lists.
  2. Use clear_compressed (or cmd_clear_depth_stencil_image) for from > img.base prefix clears in upload (fill.rs upload): when hold_from keeps levels starting at from > img.base (which happens on streamed BC textures whenever width >> from or height >> from is not block-aligned, so base_level steps img.base down below from), upload previously called vkCmdClearColorImage on a compressed image (VUID-vkCmdClearColorImage-image-00007). It now calls clear_compressed for BC formats and cmd_clear_depth_stencil_image for depth formats.

Reproduces console texture streaming without corrupting or issuing invalid clears on compressed mip chains.

The reference

  • crates/victory-gpu/src/resource.rs (base_level, placed_bytes_from): the D3D12 path creates reduced-base textures starting at a block-aligned level (base_level) and uploads from read_from onward (texture.rs), leaving unheld levels clear; D3D12 has no vkCmdClearColorImage compressed-format restriction (Vulkan spec VUID-vkCmdClearColorImage-image-00007 and VUID-vkCmdCopyBufferToImage-imageExtent-00207).

Evidence

  • Unit test in greenfield/vkback/src/fill.rs (clear_compressed_regions_shifts_extents_by_base_and_fits_zero_buffer): verifies base = 8 on a 2048×1024 BC7 texture yields image mips [(0, 8, 4), (1, 4, 2), (2, 2, 1), (3, 1, 1)], prefix clear (from = 9, base = 8) yields only (0, 8, 4), empty mip count yields no regions, and 8192×8192 BC7 splits into 4-row-aligned bands each <= ZERO_BYTES.
  • Local CI checks passed (Linux x86_64):
    • cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked
    • (cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked) (169 passed, 3 ignored; 6/6 policy tests)
    • cargo clippy --all-targets --locked -- -D warnings on root native crates, greenfield, greenfield/wine, and greenfield/vkback/translate.
  • Not run: live game / AMD GPU Vulkan validation run (house scene), screenshots, and A/B frame timing (frames.py) could not be run in this session (no live game run performed); cargo xwin clippy runs in GitHub Actions CI.

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the fixed item named above (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits)
  • No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9)
  • Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b)
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2)
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35)
  • Every unsafe block has a // SAFETY: comment; no raw pointer around the borrow checker (rule 36)
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION bumped if the translator's output changes (rule 27)
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
**@⁠Mhyster** on GitHub · 2026-12-02 07:00 UTC · [original](https://github.com/vktory6/VKtory/pull/192) `Mhyster:fix/tex-bc-clear-base-level` → `main` · +122 −32 · 2 files · 1 commits · open ## What Fixes two Vulkan validation and out-of-bounds copy bugs when clearing streamed block-compressed (BC) textures: 1. **Shift `clear_compressed` mip extents by `Img::base`** (`fill.rs` `clear_compressed` / `clear_compressed_regions`, `imgmake.rs` `make_image`): when a streamed 2D placed texture is created from console level `base > 0`, the Vulkan image's level 0 has dimensions `(width >> base, height >> base)`. Previously, `clear_compressed` computed `(desc.width >> m, desc.height >> m)` without adding `base`, recording `vkCmdCopyBufferToImage` extents 2^base× larger than the image (`VUID-vkCmdCopyBufferToImage-imageExtent-00207`, out-of-bounds GPU write on unfilled streamed BC textures). Now `clear_compressed_regions` shifts by `base + m` (with overflow-safe `checked_shr`) and skips empty region lists. 2. **Use `clear_compressed` (or `cmd_clear_depth_stencil_image`) for `from > img.base` prefix clears in `upload`** (`fill.rs` `upload`): when `hold_from` keeps levels starting at `from > img.base` (which happens on streamed BC textures whenever `width >> from` or `height >> from` is not block-aligned, so `base_level` steps `img.base` down below `from`), `upload` previously called `vkCmdClearColorImage` on a compressed image (`VUID-vkCmdClearColorImage-image-00007`). It now calls `clear_compressed` for BC formats and `cmd_clear_depth_stencil_image` for depth formats. Reproduces console texture streaming without corrupting or issuing invalid clears on compressed mip chains. ## The reference - `crates/victory-gpu/src/resource.rs` (`base_level`, `placed_bytes_from`): the D3D12 path creates reduced-base textures starting at a block-aligned level (`base_level`) and uploads from `read_from` onward (`texture.rs`), leaving unheld levels clear; D3D12 has no `vkCmdClearColorImage` compressed-format restriction (Vulkan spec `VUID-vkCmdClearColorImage-image-00007` and `VUID-vkCmdCopyBufferToImage-imageExtent-00207`). ## Evidence - Unit test in `greenfield/vkback/src/fill.rs` (`clear_compressed_regions_shifts_extents_by_base_and_fits_zero_buffer`): verifies `base = 8` on a 2048×1024 BC7 texture yields image mips `[(0, 8, 4), (1, 4, 2), (2, 2, 1), (3, 1, 1)]`, prefix clear (`from = 9, base = 8`) yields only `(0, 8, 4)`, empty mip count yields no regions, and 8192×8192 BC7 splits into 4-row-aligned bands each `<= ZERO_BYTES`. - Local CI checks passed (Linux x86_64): - `cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked` - `(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)` (169 passed, 3 ignored; 6/6 policy tests) - `cargo clippy --all-targets --locked -- -D warnings` on root native crates, `greenfield`, `greenfield/wine`, and `greenfield/vkback/translate`. - **Not run**: live game / AMD GPU Vulkan validation run (house scene), screenshots, and A/B frame timing (`frames.py`) could not be run in this session (no live game run performed); `cargo xwin clippy` runs in GitHub Actions CI. ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the fixed item named above (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits) - [x] No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9) - [x] Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b) - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2) - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35) - [x] Every `unsafe` block has a `// SAFETY:` comment; no raw pointer around the borrow checker (rule 36) - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION` bumped if the translator's output changes (rule 27) - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 07:03:26 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/192/head:github-bot/gh-192'
git switch 'github-bot/gh-192'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-192'
git switch 'github-bot/gh-192'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-192'
git switch 'github-bot/gh-192'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-192'
git switch 'main'
git merge --squash 'github-bot/gh-192'
git switch 'main'
git merge --ff-only 'github-bot/gh-192'
git switch 'main'
git merge 'github-bot/gh-192'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.