fix(vk): skip clears of textures kept in ASTC blocks #1242

Open
jcabarca wants to merge 1 commit from jcabarca/Longshot:fix/vk-astc-clear into main
Contributor

Type: fix · Risk: low · Tested on: Windows, AMD Radeon RX 9070 XT · Needs: none

Why

A texture clear on an image kept in ASTC blocks sends it to vkCmdClearColorImage, which does not take a compressed format (VUID-vkCmdClearColorImage-image-00007), or to the region path, which only knows BC blocks; either way the texture becomes garbage.

The same fix was first sent as part of #287 together with other changes; this PR sends it alone, one fix per PR.

How to reproduce

Seen on: not seen in the game: found by reading clear_tex() in gpu/vk/vk_xfer.cpp; it happens on devices that sample ASTC (textureCompressionASTC_LDR, where vk_formats.cpp keeps ASTC blocks as they are) when the game clears an ASTC texture
Settings and switches: defaults
Steps: game-free: python -I -B tests/test_vulkan_clear_mip.py --cxx clang++ --headers <Vulkan-Headers include> with this PR's test on a main checkout
Expected: an ASTC image is left as it is, with a warning
Actual: on main the ASTC image is cleared: the test's ASTC case fails (!tex.gpu_written && clear_count==0 && whole_count==0 && block_copies==0)

What changed

clear_tex() now returns before both clear paths when the image is in an ASTC format (ASTC_4x4_UNORM to ASTC_12x12_SRGB), with a warning (warn(14, ...)).

  • vk: gpu/vk/vk_xfer.cpp: clear_tex() skips ASTC images.
  • tests: tests/test_vulkan_clear_mip.py: an ASTC case: no clear, no whole-image clear, no block copy, and the texture not marked GPU-written.

The bug, step by step:

  1. vk_formats.cpp keeps ASTC textures in ASTC blocks on devices that sample them.
  2. clear_tex() only treats BC formats as raw blocks (raw = BC1..BC7), so an ASTC image is not raw.
  3. A whole-image clear of it calls vkCmdClearColorImage on a compressed image (00007); a region clear writes texel colours into ASTC blocks through the BC-only path.

The rules:

  • VUID-vkCmdClearColorImage-image-00007: "image must not have a compressed or depth/stencil format"

The branch adds no Vulkan call; it only stops one.

Measurements

Verdict: it fixes the bug: tests/test_vulkan_clear_mip.py fails on main and passes with this PR, in both interleaved runs. No speed change is expected: the change is on a failure or check path.

Hardware: AMD Radeon RX 9070 XT, Windows; the test itself is game-free (it runs on the CPU, compiled with clang++ from llvm-mingw where it builds a fixture); Python 3.12
Scene: none, game-free
Method: this PR's test files on each side's checkout, 2 runs each, interleaved (main, PR, main, PR); the result is pass/fail, so the median is the result both runs gave
How to reproduce: python -I -B tests/test_vulkan_clear_mip.py --cxx clang++ --headers <Vulkan-Headers include> on each side

Before: main @ ac778751 After: this PR @ c72c1ff9
tests/test_vulkan_clear_mip.py, run 1 fails (fails at the ASTC case) passes (passes)
tests/test_vulkan_clear_mip.py, run 2 fails (fails at the ASTC case) passes (passes)
Median fails passes
run 1, main @ ac778751: exit 1: FAIL:291 !tex.gpu_written && clear_count==0 && whole_count==0 && block_copies==0
run 1, this PR @ c72c1ff9: exit 0: PASS: array clears and BC volume clears preserve mip and slice addressing; ASTC images are not cleared
run 2, main @ ac778751: exit 1: FAIL:291 !tex.gpu_written && clear_count==0 && whole_count==0 && block_copies==0
run 2, this PR @ c72c1ff9: exit 0: PASS: array clears and BC volume clears preserve mip and slice addressing; ASTC images are not cleared

Flags and settings

None.

Testing

Tested: on this branch, Windows, Python 3.12, clang++ from llvm-mingw: tests/test_vulkan_clear_mip.py passes (fails on main).

Built and played: this commit builds on Windows (llvm-mingw back end) and on Linux (longshot_vk.so, without and with AMD FSR 4). Played on Windows, AMD Radeon RX 9070 XT: the game runs normally.

Not tested: the failure path itself in the game (it needs a driver failure or a format pair the RX 9070 XT does not produce on demand). Linux was built, not run.

Must be tested: None: the change is the same on every GPU and OS, and the game-free test covers it.

Risks

What could break: an ASTC texture the game clears keeps its old contents instead of garbage; a game that clears ASTC textures (rare: they are usually uploaded, not rendered to) would see the old contents.

Turning it off: revert the commit.

Compatibility: Nothing changes.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched). (no issue fits)
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named). (the check that reads the changed code, on this PR, Windows: tests/test_vulkan_clear_mip.py)
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • A game-free test added for the fix, failing on main and passing here. (tests/test_vulkan_clear_mip.py)
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (built on Windows with llvm-mingw and on Linux; no OS-specific code or paths)
**Type:** fix · **Risk:** low · **Tested on:** Windows, AMD Radeon RX 9070 XT · **Needs:** none ## Why A texture clear on an image kept in ASTC blocks sends it to `vkCmdClearColorImage`, which does not take a compressed format (VUID-vkCmdClearColorImage-image-00007), or to the region path, which only knows BC blocks; either way the texture becomes garbage. The same fix was first sent as part of #287 together with other changes; this PR sends it alone, one fix per PR. ## How to reproduce **Seen on:** not seen in the game: found by reading `clear_tex()` in `gpu/vk/vk_xfer.cpp`; it happens on devices that sample ASTC (`textureCompressionASTC_LDR`, where `vk_formats.cpp` keeps ASTC blocks as they are) when the game clears an ASTC texture **Settings and switches:** defaults **Steps:** game-free: `python -I -B tests/test_vulkan_clear_mip.py --cxx clang++ --headers <Vulkan-Headers include>` with this PR's test on a main checkout **Expected:** an ASTC image is left as it is, with a warning **Actual:** on main the ASTC image is cleared: the test's ASTC case fails (`!tex.gpu_written && clear_count==0 && whole_count==0 && block_copies==0`) ## What changed `clear_tex()` now returns before both clear paths when the image is in an ASTC format (`ASTC_4x4_UNORM` to `ASTC_12x12_SRGB`), with a warning (`warn(14, ...)`). - vk: `gpu/vk/vk_xfer.cpp`: `clear_tex()` skips ASTC images. - tests: `tests/test_vulkan_clear_mip.py`: an ASTC case: no clear, no whole-image clear, no block copy, and the texture not marked GPU-written. The bug, step by step: 1. `vk_formats.cpp` keeps ASTC textures in ASTC blocks on devices that sample them. 2. `clear_tex()` only treats BC formats as raw blocks (`raw = BC1..BC7`), so an ASTC image is not `raw`. 3. A whole-image clear of it calls `vkCmdClearColorImage` on a compressed image (00007); a region clear writes texel colours into ASTC blocks through the BC-only path. The rules: - VUID-vkCmdClearColorImage-image-00007: "image must not have a compressed or depth/stencil format" The branch adds no Vulkan call; it only stops one. ## Measurements **Verdict:** it fixes the bug: `tests/test_vulkan_clear_mip.py` fails on main and passes with this PR, in both interleaved runs. No speed change is expected: the change is on a failure or check path. Hardware: AMD Radeon RX 9070 XT, Windows; the test itself is game-free (it runs on the CPU, compiled with clang++ from llvm-mingw where it builds a fixture); Python 3.12 Scene: none, game-free Method: this PR's test files on each side's checkout, 2 runs each, interleaved (main, PR, main, PR); the result is pass/fail, so the median is the result both runs gave How to reproduce: `python -I -B tests/test_vulkan_clear_mip.py --cxx clang++ --headers <Vulkan-Headers include>` on each side | | Before: main @ ac778751 | After: this PR @ c72c1ff9 | |---|---|---| | `tests/test_vulkan_clear_mip.py`, run 1 | fails (fails at the ASTC case) | passes (passes) | | `tests/test_vulkan_clear_mip.py`, run 2 | fails (fails at the ASTC case) | passes (passes) | | Median | fails | passes | ``` run 1, main @ ac778751: exit 1: FAIL:291 !tex.gpu_written && clear_count==0 && whole_count==0 && block_copies==0 run 1, this PR @ c72c1ff9: exit 0: PASS: array clears and BC volume clears preserve mip and slice addressing; ASTC images are not cleared run 2, main @ ac778751: exit 1: FAIL:291 !tex.gpu_written && clear_count==0 && whole_count==0 && block_copies==0 run 2, this PR @ c72c1ff9: exit 0: PASS: array clears and BC volume clears preserve mip and slice addressing; ASTC images are not cleared ``` ### Flags and settings None. ## Testing **Tested:** on this branch, Windows, Python 3.12, clang++ from llvm-mingw: `tests/test_vulkan_clear_mip.py` passes (fails on main). **Built and played:** this commit builds on Windows (llvm-mingw back end) and on Linux (`longshot_vk.so`, without and with AMD FSR 4). Played on Windows, AMD Radeon RX 9070 XT: the game runs normally. **Not tested:** the failure path itself in the game (it needs a driver failure or a format pair the RX 9070 XT does not produce on demand). Linux was built, not run. **Must be tested:** None: the change is the same on every GPU and OS, and the game-free test covers it. ## Risks **What could break:** an ASTC texture the game clears keeps its old contents instead of garbage; a game that clears ASTC textures (rare: they are usually uploaded, not rendered to) would see the old contents. **Turning it off:** revert the commit. **Compatibility:** Nothing changes. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). (no issue fits) - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). (the check that reads the changed code, on this PR, Windows: `tests/test_vulkan_clear_mip.py`) - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] A game-free test added for the fix, failing on `main` and passing here. (`tests/test_vulkan_clear_mip.py`) - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (built on Windows with llvm-mingw and on Linux; no OS-specific code or paths)
fix(vk): skip clears of textures kept in ASTC blocks
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 8s
c72c1ff908
clear_tex sent a whole clear of an image kept in ASTC blocks to vkCmdClearColorImage, which does not take a compressed format, and a region clear down the raw-view path, which only works in BC blocks. Such a clear is now skipped with a warning and the image is left as it is. tests/test_vulkan_clear_mip.py gets an ASTC case.

Assisted-by: GitHub Copilot
Author
Contributor

Tested in game: Played on Windows, AMD Radeon RX 9070 XT: the game runs normally.

Tested in game: Played on Windows, AMD Radeon RX 9070 XT: the game runs normally.
Collaborator

Possibly related, for context:

  • PR #1160 WIP: fix(vk): six Vulkan calls checked against what the device allows (blits, ASTC clears, mesh ranges, texel views, sparse binds) — Open Vulkan robustness PR includes the ASTC-clear skip
Possibly related, for context: - PR #1160 WIP: fix(vk): six Vulkan calls checked against what the device allows (blits, ASTC clears, mesh ranges, texel views, sparse binds) — Open Vulkan robustness PR includes the ASTC-clear skip
Author
Contributor

I am juliotec, the original author of this fix. It was first sent as part of #287 together with other changes; this PR sends it alone, one fix per PR, rebased on current main.

I am juliotec, the original author of this fix. It was first sent as part of #287 together with other changes; this PR sends it alone, one fix per PR, rebased on current main.
jcabarca changed title from WIP: fix(vk): skip clears of textures kept in ASTC blocks to fix(vk): skip clears of textures kept in ASTC blocks 2026-11-16 21:51:07 +00:00
TrashPanda approved these changes 2026-11-16 23:56:03 +00:00
TrashPanda left a comment

A clear of a texture kept in ASTC blocks is skipped, instead of calling vkCmdClearColorImage on a compressed image. I read head c72c1ff9. Approved.

The range is VK_FORMAT_ASTC_4x4_UNORM_BLOCK through VK_FORMAT_ASTC_12x12_SRGB_BLOCK, which is every LDR block format and nothing else. That is the set vk_formats.cpp uploads as blocks on a device that samples ASTC. The return is after the barrier and before both the whole-image clear and the region clear, so neither runs, and the texture is not marked written. The fixture calls the real clear_tex and checks that an ASTC image produces no clear. HDR ASTC (ASTC_*_SFLOAT) is outside the range; those are not the blocks this path keeps.

The Windows run was on an RX 9070 XT, which does not sample ASTC, so that play did not take this path. The fixture is what covers it. #1160 also has this skip; this pull request is the one to take. The full-suite box names only tests/test_vulkan_clear_mip.py.

A clear of a texture kept in ASTC blocks is skipped, instead of calling `vkCmdClearColorImage` on a compressed image. I read head `c72c1ff9`. Approved. The range is `VK_FORMAT_ASTC_4x4_UNORM_BLOCK` through `VK_FORMAT_ASTC_12x12_SRGB_BLOCK`, which is every LDR block format and nothing else. That is the set `vk_formats.cpp` uploads as blocks on a device that samples ASTC. The return is after the barrier and before both the whole-image clear and the region clear, so neither runs, and the texture is not marked written. The fixture calls the real `clear_tex` and checks that an ASTC image produces no clear. HDR ASTC (`ASTC_*_SFLOAT`) is outside the range; those are not the blocks this path keeps. The Windows run was on an RX 9070 XT, which does not sample ASTC, so that play did not take this path. The fixture is what covers it. https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1160 also has this skip; this pull request is the one to take. The full-suite box names only `tests/test_vulkan_clear_mip.py`.
Owner

Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).

  • Tested on my own PC: ticked: Testing's Tested and the author's comment: played in game on Windows, AMD Radeon RX 9070 XT, the game runs normally.
  • Nothing gets worse that I know of: ticked: Measurements expects no speed change, and Risks names only the rare ASTC clear's contents, not a performance cost.
Brought up to the [ready-for-review standard](https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/CONTRIBUTING.md#ready-for-review-out-of-wip) (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know). - *Tested on my own PC*: ticked: Testing's Tested and the author's comment: played in game on Windows, AMD Radeon RX 9070 XT, the game runs normally. - *Nothing gets worse that I know of*: ticked: Measurements expects no speed change, and Risks names only the rare ASTC clear's contents, not a performance cost.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 8s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
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 'fix/vk-astc-clear:jcabarca-fix/vk-astc-clear'
git switch 'jcabarca-fix/vk-astc-clear'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
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
MagicBeanDev/Longshot!1242
No description provided.