fix(vk): keep sparse textures off the GPU unswizzle and disturb descriptors at its bind #925
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!925
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:fix/vk-unswizzle-sparse"
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
The GPU unswizzle stored large textures into sparse images whose blocks had no memory bound yet; stores into an unbound sparse block are dropped, so those textures stayed black or empty. It also left the draw state thinking its compute descriptors were still bound when a level's view failed and the CPU path took over.
How to reproduce
Seen on: not seen in the game: found by reading
upload_unswizzle_gpu()ingpu/vk/vk_texture.cpp; it happens for any sparse texture of 8 MiB or more that takes the GPU unswizzleSettings and switches: defaults
Steps: game-free:
python -I -B tests/test_unswizzle_gpu_guards.py --source <main checkout>(the test from this PR); it readsupload_unswizzle_gpu()Expected: sparse textures take the CPU path, which binds their blocks;
descriptors_disturbed()is called right afterunsw_pipeis boundActual: on main sparse textures take the GPU path, and
descriptors_disturbed()comes only at the end, after thereturn falseof a failed view; the test fails with both problemsWhat changed
upload_unswizzle_gpu()returnsfalse(not a texture for it) for sparse textures, and callsdescriptors_disturbed()right after it bindsunsw_pipeinstead of at its end.upload_unswizzle_gpu()ingpu/vk/vk_texture.cpp:tex.sparsejoins the first guard, with the other kinds of texture it already refuses (ASTC, BC, depth, linear, not 2D, no storage usage).descriptors_disturbed()moved from after the lastfull_barrier(cmd)to right aftervkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, unsw_pipe).tests/test_unswizzle_gpu_guards.py(new).The bug, step by step:
upload_inner()triesupload_unswizzle_gpu()first for a big 2D texture: a compute shader reads the swizzled guest data and stores the texels into a storage view of the image.sparse_flush()has bound. The CPU path queues and binds the blocks it writes (texture_resident_queue,texture_resident_flush); the GPU unswizzle binds nothing.unsw_pipeand pushes its descriptors on the upload command buffer, which is the recording's command buffer (upload_cmd()). If a level's storage view then fails, it returnsfalseand the CPU path takes over, butdescriptors_disturbed()was only reached at the very end, so the draw state's push-descriptor cache (pushed()) still believed its own compute bindings were there.The rules: the first problem is a dropped write, not a broken rule. The second can leave a dispatch with descriptors pushed for another pipeline layout, which VUID-vkCmdDispatch-None-08600 covers, from Khronos
validusage.json: "If a a bound shader was created as a VkShaderEXT without the VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT flag or as part of a pipeline without the VK_PIPELINE_CREATE_2_DESCRIPTOR_HEAP_BIT_EXT flag, and that shader statically uses a set n, a descriptor set must have been bound to n at the same pipeline bind point, with a VkPipelineLayout that is compatible for set n, with the VkPipelineLayout used to create the current VkPipeline or the VkDescriptorSetLayout array used to create the current VkShaderEXT , as described in Pipeline Layout Compatibility"Before:
After:
Measurements
Verdict: it fixes the bug:
tests/test_unswizzle_gpu_guards.pyfails on main (both problems) and passes with this PR, in both interleaved runs. Sparse textures of 8 MiB or more now unswizzle on the CPU, as smaller ones already do; that is slower than the GPU path for those textures, but the GPU path's result was lost anyway.Hardware: AMD Radeon RX 9070 XT, Windows; the test itself is game-free (it reads source, it does not use the GPU); Python 3.12
Scene: none, game-free
Method:
tests/test_unswizzle_gpu_guards.pyfrom this PR with--sourceset to 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 gaveHow to reproduce:
python -I -B tests/test_unswizzle_gpu_guards.py --source <checkout>for each sideb8d2b04e733a4bd6tests/test_unswizzle_gpu_guards.py, run 1tests/test_unswizzle_gpu_guards.py, run 2What the test checks:
return false;ofupload_unswizzle_gpu()teststex.sparse.vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, unsw_pipe);,descriptors_disturbed();comes before the firstreturn false;.Flags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12:
test_unswizzle_gpu_guardspasses (fails on main), and the other check that readsupload_unswizzle_gpu()passes:test_image_view_retry.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: a big sparse texture uploaded in the game and looked at: not checked in the game (which textures are sparse and 8 MiB or more was not traced). 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: big sparse textures take the CPU unswizzle, which is slower than the GPU one; the first upload of such a texture may take longer. Non-sparse textures are unchanged. Draws after a successful GPU unswizzle re-push their descriptors as before; after a failed one they now do too.
Turning it off: revert the commit.
Compatibility: Nothing changes.
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (the checks that read the changed code, on this PR, Windows:test_unswizzle_gpu_guards,test_image_view_retry, all pass)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_unswizzle_gpu_guards.py)tests/that reads changed source updated in this PR, not weakened. (tests/test_unswizzle_gpu_guards.pyadded; no check removed)longshot_vk.sowithout and with AMD FSR 4; no OS-specific code or paths)WIP: fix(vk): keep sparse textures off the GPU unswizzle and disturb descriptors at its bindto fix(vk): keep sparse textures off the GPU unswizzle and disturb descriptors at its bindCode-only review of
733a4bd670; informational findings, with final approval left to another reviewer.No introduced correctness defect found in the two runtime changes. The early sparse guard preserves the existing CPU upload route that queues residency before copies. Moving
descriptors_disturbed()immediately after the compute bind covers failed view creation as well as successful completion; it clears both cached command-buffer identities, so subsequent descriptor binding cannot trust the previous cache entry.The remaining gap is targeted validation. The reported Windows RX 9070 XT playthrough and Windows/Linux builds are useful, but the description explicitly says no large sparse upload was traced. The new test checks source tokens and ordering; it does not exercise sparse residency or failed-view fallback. In particular, replacing
|| tex.sparsewith|| !tex.sparsewould still satisfy its sparse-token assertion. A behavioral fixture should check sparse rejection before any GPU bind and descriptor invalidation when view creation fails, including failure after an earlier mip dispatched. For runtime evidence, identify an affected sparse upload and check its resulting texture and first-upload hitch behavior; a general playthrough does not establish that this path ran.Merge coordination: #671 fixes sparse BC image-creation usage, while this PR excludes sparse images from the uncompressed GPU unswizzle path. These are complementary, not duplicate fixes.
Read the complete diff, upload fallback/residency and descriptor-cache code, and the view-retry test. No tests, builds, or game runs were performed in this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.