Skip to content

Fix Vulkan bindless rollback ordering across queues - #4672

Open
editrice wants to merge 1 commit into
ItsNotRexed:mainfrom
editrice:fix/bindless-failed-submit-rollback
Open

editrice wants to merge 1 commit into
ItsNotRexed:mainfrom
editrice:fix/bindless-failed-submit-rollback

Conversation

@editrice

Copy link
Copy Markdown

Claimed in the coordination issue as: #4571 (comment)

What and why

A failed vkQueueSubmit can consume a bindless upload obligation during prepare, then release tracker_mutex_ before bindless_commit(false) restores it. Another queue can prepare in that gap and submit stale table contents. Keep the tracker lock through commit on both the normal and early-error paths. Add a synthetic two-queue regression that checks queue B observes rollback before prepare; its probe is enabled only for the test target. This is distinct from #4517.

Tested

  • Windows, NVIDIA GeForce RTX 5070, driver 621.01: MSVC 19.44 Release build of vk_queue_query_sync_test passed; ctest -R ^vk_queue_query_sync$ passed 1/1, including regular and early-error rollback cases.
  • Negative controls: reverting only the two commit/unlock reorderings caused the regular and early-error cases to fail separately, with queue B preparing before rollback and missing the retry. Restored patch rebuilt and passed again.
  • Only synthetic callbacks and source code are included; no game-derived material or generated shaders.

AI-assisted: yes (Codex daybreak-blue implementation and independent review).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • Translator contract entry: not applicable; this changes Vulkan queue synchronization only.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built and ran vk_queue_query_sync_test at ee7599dcd on Windows 11, RTX 5070 Ti: exit 0, all six cases ok:

  • remove_query_pool serialized with QueryReplay::commit
  • cross-queue QueryReplay::plan serialized with commit
  • pending Wait() preserved across failed vkQueueSubmit
  • bindless rollback precedes next prepare (regular path)
  • bindless rollback precedes next prepare (early path)
  • concurrent multi-queue query stress

The change keeps tracker_mutex_ through the bindless_commit(submitted) call on both the success and the early-error paths, so another queue's prepare cannot observe the stale pending upload between the failed submit and the rollback; the lock hierarchy comment now names the callback's descriptor_mutex_ position, and the probe hook is under LEONIDA_VULKAN_QUEUE_SYNC_TEST_HOOKS. git diff --check clean. No blocking issue.

Stacking note: the branch also carries db51b7d3f (Mods) and 9e6444fad (archetype hook), both owner-authored, under the fix; merging this PR lands both. It merges cleanly with the other five PRs carrying the same base, but the base itself is not part of this PR's subject.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head ee7599d. Keeping the tracker lock through the bindless rollback callback serializes that rollback before the next queue can prepare or submit against the descriptor state; both the ordinary and early-failure paths are covered by the deterministic two-queue test hook. I found no additional defect in this diff.

@editrice
editrice marked this pull request as ready for review November 23, 2026 04:07
@justr4mzi

Copy link
Copy Markdown
Contributor

Verified commit ee7599dc locally on Windows 11 x64 (AMD Radeon RX 6700 XT):

  • Built vk_queue_query_sync_test.exe cleanly ([2/2]).
  • ctest --test-dir build --output-on-failure -R "^vk_queue_query_sync$" -V:
    • Standard: 1/1 passed (0.29 sec test / 0.31 sec real on AMD Radeon RX 6700 XT, all 6 cases ok).
    • LEONIDA_VK_VALIDATION=1: 1/1 passed (0.30 sec test / 0.31 sec real on AMD Radeon RX 6700 XT (validation on), all 6 cases ok, 0 validation errors).
  • Direct .\build\vk_queue_query_sync_test.exe with LEONIDA_VK_VALIDATION=1: exit 0 (vk_queue_query_sync_test: ok).
  • Repo checks: tests/test_ctest_registration.py (4/4 in 0.638s), scripts/check_no_game_data.py exit 0, and git diff --check exit 0.

Reviewed runtime/CMakeLists.txt, runtime/src/vulkan_backend.h (holding tracker_mutex_ across bindless_commit(submitted) on both the regular and early-error paths), and runtime/test/vk_queue_query_sync_test.cpp; looks solid.

AI-assisted (Gemini, Antigravity).

@tupacfan04

Copy link
Copy Markdown
Contributor

PASS. CMake+Ninja/MSVC built vk_queue_query_sync_test, ctest 1/1, and 1/1 again with LEONIDA_VK_VALIDATION=1 on an RTX 5070. Negative control: reverting the two tracker_lock.unlock()/bindless_commit orderings fails exactly as intended (acquired_tracker=1 prepared_early=1 saw_retry=0), and the restored patch passes. Merge clean.

No blocking issue: the test-only hook is target-scoped (runtime/src/vulkan_backend.h:1395,1908, runtime/CMakeLists.txt:975), and it SKIPs without a Vulkan 1.3 device.

Approve. AI-assisted review, no game files, no game GPU.

@tupacfan04

Copy link
Copy Markdown
Contributor

One extra nit from a second pass: runtime/test/vk_queue_query_sync_test.cpp:354-358 waits on a condition variable with no timeout, so a missed probe hangs until the new 90 s ctest timeout (runtime/CMakeLists.txt:991) instead of failing with a message. Also, EXPECT (:26) returns on the first failure, so the two broken paths are only observable in separate runs.

Not blocking - the fix and its negative control both reproduce as claimed.

AI-assisted review, no game files, no game GPU.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Tested ee7599dc on Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51 (VS 2026), Vulkan SDK 1.4.363.0, RelWithDebInfo, clean build with -DLEONIDA_LLVM_MC (translated-shader D3D12 gate tests included), full LEONIDA_VK_VALIDATION=1 ctest -j4: 163/163 passed, 0 VUIDs, 0 build errors. AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Reviewed on Linux without building (no cmake/GPU here): moving bindless_commit() inside the tracker_mutex_ hold on both failed-submit paths is the right serialization, the test hook is properly ifdef-gated to the test target, and the updated lock-hierarchy comment matches the call sites. Nothing on the Python side is affected; compileall is clean. Needs a vk_queue_query_sync ctest on a Vulkan device to close out; no CI checks were scheduled on this branch. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@editrice

Copy link
Copy Markdown
Author

Thanks for reviewing. The current ee7599dc head already has the requested Vulkan-device CTest evidence: the focused vk_queue_query_sync test passed all six cases on an AMD RX 6700 XT, both normally and with LEONIDA_VK_VALIDATION=1 (0 validation errors): #4672 (comment). It also passed on an RTX 5070 Ti in Kam471's review, and the full validation-enabled CTest run passed 163/163 on an RTX 5060 Ti: #4672 (comment). The three GitHub workflows are present but currently show action_required pending maintainer approval; that is why they have not run. No patch change is needed for this point. AI-assisted response.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested ee7599dc on Windows 11 with an NVIDIA GeForce RTX 4090 (32.0.16.2101) and AMD Radeon(TM) Graphics (32.0.21043.5001): pass.

I built vk_queue_query_sync_test.cpp with MSVC and LEONIDA_VULKAN_QUEUE_SYNC_TEST_HOOKS. All six checks pass on each adapter. Queue B sees the pending upload after queue A's submit fails. This holds for both the regular and early-error paths.

For the negative control, I moved both tracker unlocks back before the bindless commit callback and kept the test hook. I ran the regular and early-error cases separately. Each case exits 1 on both adapters with acquired_tracker=1 prepared_early=1 saw_retry=0. Queue B starts preparation before rollback and misses the retry.

This run covers the focused synchronization test with real Vulkan queues and synthetic submit failures. Vulkan validation layers were unavailable.

AI-assisted.

Keep the tracker lock through bindless commit on both submit paths, and add a synthetic two-queue regression that demonstrates the stale upload interleaving.
# Conflicts:
#	runtime/src/vulkan_backend.h
#	runtime/test/vk_queue_query_sync_test.cpp
@editrice
editrice force-pushed the fix/bindless-failed-submit-rollback branch from ee7599d to c6846f7 Compare November 23, 2026 13:38
@editrice

Copy link
Copy Markdown
Author

Rebased #4672 onto current main 561b65a8 as focused head c6846f74; GitHub now reports a clean merge. The conflict resolution kept main's newer held-Wait/failed-Signal queue cases and bindless set state, alongside this PR's two-queue rollback regression. Built vk_queue_query_sync_test with MSVC 19.44 on Windows 11 / RTX 5070; the focused CTest passed 1/1 normally and with LEONIDA_VK_VALIDATION=1 (all queue/query and both rollback cases passed, no validation errors). git diff --check and scripts/check_no_game_data.py passed. AI-assisted; synthetic tests only.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested c6846f747 merged into main 1cc6e3c12 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "queue_query_sync|bindless" --output-on-failure: 6/6 passed (vk_queue_query_sync, bindless_sizing, vk_bindless_ps_tex, vk_bindless_ps_imgatomic, d3d12_bindless_churn, d3d12_bindless_churn_validated).

AI-assisted (Claude Code).

@itaskaev2

Copy link
Copy Markdown

Tested c6846f74 (contains main 561b65a8) on Windows 11, NVIDIA GeForce RTX 4080 SUPER, driver 616.92, MSVC 14.51, RelWithDebInfo: pass. AI-assisted (Claude Code), no game files.

  • Full runtime build at the head: clean, no errors.
  • ctest -R "^vk_queue_query_sync$": 1/1. A direct run prints all cases ok, including bindless rollback precedes next prepare (regular path) ok and (early path) ok.
  • With LEONIDA_VK_VALIDATION=1: exit 0 and 0 validation: lines; 10 of 10 repeated runs pass.
  • Neighbours, ctest -R "vk_queue|vk_sync|query|fence": 11/11 passed (vk_sync_validation skipped, as it needs the layer env).

What the rebased head changes. On 561b65a8, both failed-submit paths in VulkanQueue already call bindless_commit(submitted) before tracker_lock.unlock() (vulkan_backend.h lines 2414-2415 and 2560-2561 at the head). So against current main this PR adds the regression test, the test-only set_tracker_lock_probe hook and comments; it does not change runtime behaviour.

Negative control (test kept, order swapped back to unlock() before bindless_commit in the header):

  • Both paths swapped: vk_queue_query_sync fails, bindless rollback regular: ... probe_before_rollback=1 ... prepared_early=1 saw_retry=0, line 481.
  • Only the early-error path swapped: the regular case passes, then bindless rollback early: ... prepared_early=1 saw_retry=0, line 482.
  • Header restored: 1/1 again.

So on this machine the new test catches a regression on each path separately.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c6846f7 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: concern (the new cases pass; the test binary still exits 1 most runs, same as main)

  • Built vk_queue_query_sync_test from the head and ran the binary 10 times with LEONIDA_VK_VALIDATION=0 and 10 times with =1. The two new cases ("bindless rollback precedes next prepare", regular and early path) print ok in 20 of 20 runs. No validation errors in any run.
  • Exit code 0 in 1 of 10 runs with validation off and 4 of 10 with validation on. The failing check is the existing "progress counter device loss" block, vk_queue_query_sync_test.cpp:538-562: it prints device-loss execute=0, context_lost=0, interceptions=2, so the injected DEVICE_LOST was taken but queue_a.execute still returned success. The EXPECT(progress_loss_ok) at line 571 then fails.
  • Main (9077af1) shows the same failure: exit 0 in 0 of 10 runs with validation off, 7 of 10 with validation on. So the PR does not add it, and with ctest the registered test vk_queue_query_sync fails here on both main and the PR (the one ctest pass seen on the head was validation on, and it is not stable).
  • Negative control: head tests with vulkan_backend.h at the merge base. The test does not compile (set_tracker_lock_probe is not a member of VulkanContext, vk_queue_query_sync_test.cpp:410 and :458). The new cases need the production change.
  • Not done: the cause was not traced here; the open Runtime: propagate device loss found by the retire-ticket progress query (D3D-599) #6149 (D3D-599) changes this path, and in an earlier run on this card its head passed this block 6 of 6 times where its merge base failed. The TIMEOUT 90 was not exercised (a run takes under 1 s).

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.