fix(vk): a read-back pool whose command buffer or fence failed is made again, not used half made #1251

Merged
HumanBean merged 1 commit from jcabarca/Longshot:fix/vk-readback-pending into main 2026-11-16 22:53:44 +00:00
Contributor

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

Why

If allocating the read-back command buffer or fence fails, the pool is kept, so the next read-back skips creation and begins a null command buffer (VUID-vkBeginCommandBuffer-commandBuffer-parameter): a crash.

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 readback_begin() in gpu/vk/vk_texture.cpp; it happens when vkAllocateCommandBuffers or vkCreateFence fails (out of memory) on the first read-back
Settings and switches: defaults
Steps: game-free: python -I -B tests/test_readback_pending.py with this PR's test on a main checkout
Expected: the pool is destroyed and all three handles are nulled, so the next call makes them again
Actual: on main: "a read-back pool whose command buffer or fence failed is kept half made"

What changed

On that failure readback_begin() destroys rb_pool (which frees its command buffer) and sets rb_pool, rb_cmd and rb_fence to VK_NULL_HANDLE.

  • vk: gpu/vk/vk_texture.cpp: readback_begin() as above.
  • tests: tests/test_readback_pending.py (new) and tests/test_readback_timeout_reuse.py (one line: it still finds its code).

The bug, step by step:

  1. readback_begin() creates rb_pool only when it is null, then allocates rb_cmd and creates rb_fence.
  2. If either fails it returned false with rb_pool set.
  3. The next call skipped creation and called vkResetCommandPool and vkBeginCommandBuffer with a null rb_cmd.

The rules:

  • VUID-vkBeginCommandBuffer-commandBuffer-parameter: "commandBuffer must be a valid VkCommandBuffer handle"

vkDestroyCommandPool frees the pool's command buffers; none is pending here (nothing was submitted), so VUID-vkDestroyCommandPool-commandPool-00041 holds.

Measurements

Verdict: it fixes the bug: tests/test_readback_pending.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_readback_pending.py on each side

Before: main @ ac778751 After: this PR @ 2efece40
tests/test_readback_pending.py, run 1 fails (fails) passes (passes)
tests/test_readback_pending.py, run 2 fails (fails) passes (passes)
Median fails passes
run 1, main @ ac778751: exit 1: a read-back pool whose command buffer or fence failed is kept half made
run 1, this PR @ 2efece40: exit 0: the read-back pool is never used half made
run 2, main @ ac778751: exit 1: a read-back pool whose command buffer or fence failed is kept half made
run 2, this PR @ 2efece40: exit 0: the read-back pool is never used half made

Flags and settings

None.

Testing

Tested: on this branch, Windows, Python 3.12, clang++ from llvm-mingw: tests/test_readback_pending.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: none expected: only the failure path changes.

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)
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • 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_readback_pending.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_readback_pending.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 If allocating the read-back command buffer or fence fails, the pool is kept, so the next read-back skips creation and begins a null command buffer (VUID-vkBeginCommandBuffer-commandBuffer-parameter): a crash. 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 `readback_begin()` in `gpu/vk/vk_texture.cpp`; it happens when `vkAllocateCommandBuffers` or `vkCreateFence` fails (out of memory) on the first read-back **Settings and switches:** defaults **Steps:** game-free: `python -I -B tests/test_readback_pending.py` with this PR's test on a main checkout **Expected:** the pool is destroyed and all three handles are nulled, so the next call makes them again **Actual:** on main: "a read-back pool whose command buffer or fence failed is kept half made" ## What changed On that failure `readback_begin()` destroys `rb_pool` (which frees its command buffer) and sets `rb_pool`, `rb_cmd` and `rb_fence` to `VK_NULL_HANDLE`. - vk: `gpu/vk/vk_texture.cpp`: `readback_begin()` as above. - tests: `tests/test_readback_pending.py` (new) and `tests/test_readback_timeout_reuse.py` (one line: it still finds its code). The bug, step by step: 1. `readback_begin()` creates `rb_pool` only when it is null, then allocates `rb_cmd` and creates `rb_fence`. 2. If either fails it returned false with `rb_pool` set. 3. The next call skipped creation and called `vkResetCommandPool` and `vkBeginCommandBuffer` with a null `rb_cmd`. The rules: - VUID-vkBeginCommandBuffer-commandBuffer-parameter: "commandBuffer must be a valid VkCommandBuffer handle" `vkDestroyCommandPool` frees the pool's command buffers; none is pending here (nothing was submitted), so `VUID-vkDestroyCommandPool-commandPool-00041` holds. ## Measurements **Verdict:** it fixes the bug: `tests/test_readback_pending.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_readback_pending.py` on each side | | Before: main @ ac778751 | After: this PR @ 2efece40 | |---|---|---| | `tests/test_readback_pending.py`, run 1 | fails (fails) | passes (passes) | | `tests/test_readback_pending.py`, run 2 | fails (fails) | passes (passes) | | Median | fails | passes | ``` run 1, main @ ac778751: exit 1: a read-back pool whose command buffer or fence failed is kept half made run 1, this PR @ 2efece40: exit 0: the read-back pool is never used half made run 2, main @ ac778751: exit 1: a read-back pool whose command buffer or fence failed is kept half made run 2, this PR @ 2efece40: exit 0: the read-back pool is never used half made ``` ### Flags and settings None. ## Testing **Tested:** on this branch, Windows, Python 3.12, clang++ from llvm-mingw: `tests/test_readback_pending.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:** none expected: only the failure path changes. **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] Measurements has a verdict, or one line saying why there is nothing to measure. - [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_readback_pending.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_readback_pending.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): a read-back pool whose command buffer or fence failed is made again, not used half made
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 4s
2efece406f
When vkAllocateCommandBuffers or vkCreateFence failed in readback_begin, rb_pool stayed set with a null rb_cmd or rb_fence: the next call skipped the creation, reset the pool and began a null command buffer. Now the pool is destroyed and all three are made again next time. New tests/test_readback_pending.py.

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.
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): a read-back pool whose command buffer or fence failed is made again, not used half made to fix(vk): a read-back pool whose command buffer or fence failed is made again, not used half made 2026-11-16 22:20:31 +00:00
HumanBean deleted branch fix/vk-readback-pending 2026-11-16 22:53:45 +00:00
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 4s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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!1251
No description provided.