fix(vk): skip clears of textures kept in ASTC blocks #1242
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1242
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:fix/vk-astc-clear"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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()ingpu/vk/vk_xfer.cpp; it happens on devices that sample ASTC (textureCompressionASTC_LDR, wherevk_formats.cppkeeps ASTC blocks as they are) when the game clears an ASTC textureSettings 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 checkoutExpected: 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_UNORMtoASTC_12x12_SRGB), with a warning (warn(14, ...)).gpu/vk/vk_xfer.cpp:clear_tex()skips ASTC images.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:
vk_formats.cppkeeps ASTC textures in ASTC blocks on devices that sample them.clear_tex()only treats BC formats as raw blocks (raw = BC1..BC7), so an ASTC image is notraw.vkCmdClearColorImageon a compressed image (00007); a region clear writes texel colours into ASTC blocks through the BC-only path.The rules:
The branch adds no Vulkan call; it only stops one.
Measurements
Verdict: it fixes the bug:
tests/test_vulkan_clear_mip.pyfails 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 sideac778751c72c1ff9tests/test_vulkan_clear_mip.py, run 1tests/test_vulkan_clear_mip.py, run 2Flags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12, clang++ from llvm-mingw:
tests/test_vulkan_clear_mip.pypasses (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
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (the check that reads the changed code, on this PR, Windows:tests/test_vulkan_clear_mip.py)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_vulkan_clear_mip.py)tests/that reads changed source updated in this PR, not weakened.Tested in game: Played on Windows, AMD Radeon RX 9070 XT: the game runs normally.
Possibly related, for context:
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.
WIP: fix(vk): skip clears of textures kept in ASTC blocksto fix(vk): skip clears of textures kept in ASTC blocksA clear of a texture kept in ASTC blocks is skipped, instead of calling
vkCmdClearColorImageon a compressed image. I read headc72c1ff9. Approved.The range is
VK_FORMAT_ASTC_4x4_UNORM_BLOCKthroughVK_FORMAT_ASTC_12x12_SRGB_BLOCK, which is every LDR block format and nothing else. That is the setvk_formats.cppuploads 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 realclear_texand 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.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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.