fix(vk): a sparse upload that runs out of staging binds what it queued #1250
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!1250
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:fix/vk-sparse-staging-failure"
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 sparse texture upload that runs out of staging memory part-way returns with this image's sparse binds still queued, so the next flush binds them into another texture's image: corrupt or missing textures.
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
upload_inner()ingpu/vk/vk_texture.cpp; it happens on devices with sparse residency when staging runs out during a sparse uploadSettings and switches: defaults
Steps: game-free:
python -I -B tests/test_sparse_staging_failure.pywith this PR's test on a main checkoutExpected: the binds queued by the rows before are flushed into this texture before returning
Actual: on main: "a sparse upload that fails part-way leaves its queued binds for another texture's flush"
What changed
When
staging()fails inupload_inner(), it now callstexture_resident_flush(&tex)before returning false.gpu/vk/vk_texture.cpp:upload_inner()as above.tests/test_sparse_staging_failure.py(new): readsupload_inner()and checks the staging failure flushes before it returns.The bug, step by step:
upload_inner()queues sparse binds row by row.staging()returned no buffer it returned false at once, leaving them insparse_binds.sparse_flush(), for another texture, sent them with that texture's image.The rules:
Bound with another image, the offsets and memory are checked against the wrong image (01107 is one such rule). No new Vulkan call: the flush is the one used a few lines below for a new staging arena.
Measurements
Verdict: it fixes the bug:
tests/test_sparse_staging_failure.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_sparse_staging_failure.pyon each sideac778751c002de82tests/test_sparse_staging_failure.py, run 1tests/test_sparse_staging_failure.py, run 2Flags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12, clang++ from llvm-mingw:
tests/test_sparse_staging_failure.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: none expected: the flush is the same one the function already does when it changes staging arena.
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_sparse_staging_failure.py)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_sparse_staging_failure.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): a sparse upload that runs out of staging binds what it queuedto fix(vk): a sparse upload that runs out of staging binds what it queuedA sparse upload that runs out of staging memory now binds the tiles it already queued into this image, instead of leaving them for the next texture's flush. I read head
c002de82. Approved.sparse_bindsis one list.sparse_flushsends that list with the image it is given and then clears it. The other way out of this loop, a new staging arena, already flushes first. The failure return did not, so the next texture's flush bound these offsets into the wrong image. The new return callstexture_resident_flush(&tex)first. An empty list flushes as a no-op.The rows already copied into the previous staging buffer are still not submitted: this return is before
vkCmdCopyBufferToImage. The tiles are resident and the upload still fails, which is what the caller already saw. The test searches the source for the flush before that return. It does not run the upload. #1160 has the same fix; this pull request is the one to take. The Windows play did not run out of staging. The full-suite box names onlytests/test_sparse_staging_failure.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.