retire_tickets: coalesce pending_through per semaphore and guard completed_ monotonicity #935

Merged
narekshaghoyandev merged 1 commit from upstream-pr/935 into main 2026-11-24 18:38:55 +00:00
narekshaghoyandev commented 2026-11-24 15:17:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:17:19Z.


Summary

  • Coalesce RetireTickets::pending_through(ticket) in runtime/src/retire_tickets.h so multiple pending submissions on the same timeline semaphore collapse to a single (semaphore, max_value) entry instead of passing duplicate VkSemaphore handles to vkWaitSemaphores in wait_retire_ticket().
  • Guard completed_ in RetireTickets::completed() so a non-monotonic ticket can never move the completed retirement prefix backward.
  • Expand runtime/test/retire_tickets_test.cpp with regression checks for per-semaphore coalescing, idle queue exclusion, cutoff filtering, and monotonic completed_.

Verification

  • g++ -std=c++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -O1 -g runtime/test/retire_tickets_test.cpp -o /tmp/retire_tickets_test && /tmp/retire_tickets_test — pass.
  • Negative control against main: fails with exit code 5 before the patch and passes cleanly after.
  • python3 -I scripts/check_no_game_data.py runtime/src/retire_tickets.h runtime/test/retire_tickets_test.cpp — clean.

Claimed in the coordination issue as: RT-RETIRE-TICKETS-DEDUP-WAIT
AI-assisted: yes (Gemini)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474958238 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/935). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:17:19Z. --- ## Summary - Coalesce `RetireTickets::pending_through(ticket)` in `runtime/src/retire_tickets.h` so multiple pending submissions on the same timeline semaphore collapse to a single `(semaphore, max_value)` entry instead of passing duplicate `VkSemaphore` handles to `vkWaitSemaphores` in `wait_retire_ticket()`. - Guard `completed_` in `RetireTickets::completed()` so a non-monotonic ticket can never move the completed retirement prefix backward. - Expand `runtime/test/retire_tickets_test.cpp` with regression checks for per-semaphore coalescing, idle queue exclusion, cutoff filtering, and monotonic `completed_`. ## Verification - `g++ -std=c++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -O1 -g runtime/test/retire_tickets_test.cpp -o /tmp/retire_tickets_test && /tmp/retire_tickets_test` — pass. - Negative control against `main`: fails with exit code 5 before the patch and passes cleanly after. - `python3 -I scripts/check_no_game_data.py runtime/src/retire_tickets.h runtime/test/retire_tickets_test.cpp` — clean. Claimed in the coordination issue as: RT-RETIRE-TICKETS-DEDUP-WAIT AI-assisted: yes (Gemini)
KernelSmoker commented 2026-11-24 15:32:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T15:32:02Z.

Review: APPROVED


Verified on head 9392bbd9e03b88fd4746f51e2fb1e7cd7b0e5b86. The CPU-only regression binary builds with GCC 16 using -std=c++20 -Wall -Wextra -Werror -pedantic and passes; check_no_game_data.py and git diff --check are clean. The per-semaphore maximum is appropriate for the caller: each queue progress timeline is monotonic and global tickets are recorded in order, while idle entries are excluded after successful queue-idle.

ASan/UBSan could not be independently run here: linking fails because this environment lacks /usr/lib64/libasan.so.8.0.0. I therefore make no sanitizer claim. Hosted GitHub checks were still pending when I reviewed.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6042279400 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/935#pullrequestreview-6042279400). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T15:32:02Z. **Review:** APPROVED --- Verified on head `9392bbd9e03b88fd4746f51e2fb1e7cd7b0e5b86`. The CPU-only regression binary builds with GCC 16 using `-std=c++20 -Wall -Wextra -Werror -pedantic` and passes; `check_no_game_data.py` and `git diff --check` are clean. The per-semaphore maximum is appropriate for the caller: each queue progress timeline is monotonic and global tickets are recorded in order, while idle entries are excluded after successful queue-idle. ASan/UBSan could not be independently run here: linking fails because this environment lacks `/usr/lib64/libasan.so.8.0.0`. I therefore make no sanitizer claim. Hosted GitHub checks were still pending when I reviewed.
SweatierKey commented 2026-11-24 15:33:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by SweatierKey on 2026-11-24T15:33:12Z.

Review: APPROVED


Independent verification on Windows 11 against origin/main@a28927849:

  • Built retire_tickets_test.exe (clang-cl + xwin SDK 10.0.26100) and ran natively on Windows 11:
    • out-of-order queue completion kept the retirement prefix safe (rc=0), exercising per-semaphore max-value coalescing in pending_through() (skipping idle queues and post-cutoff tickets) and monotonic completed_ clamping.
  • python3 -I scripts/check_no_game_data.py: clean.

Clean, minimal fix preventing duplicate VkSemaphore entries in vkWaitSemaphores and backward retirement regression.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6042301753 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/935#pullrequestreview-6042301753). Originally posted by [SweatierKey](https://github.com/SweatierKey) on 2026-11-24T15:33:12Z. **Review:** APPROVED --- Independent verification on Windows 11 against `origin/main@a28927849`: - Built `retire_tickets_test.exe` (`clang-cl` + xwin SDK 10.0.26100) and ran natively on Windows 11: - `out-of-order queue completion kept the retirement prefix safe` (`rc=0`), exercising per-semaphore max-value coalescing in `pending_through()` (skipping idle queues and post-cutoff tickets) and monotonic `completed_` clamping. - `python3 -I scripts/check_no_game_data.py`: clean. Clean, minimal fix preventing duplicate `VkSemaphore` entries in `vkWaitSemaphores` and backward retirement regression. AI-assisted: yes
moffington commented 2026-11-24 15:33:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by moffington on 2026-11-24T15:33:16Z.


Reviewed 9392bbd9e against a28927849 on Linux. No issues found.

The checked-in retire_tickets_test and an independent adversarial test suite passed with ASan/UBSan enabled.

The differential suite reproduced the duplicate-semaphore issue on baseline and passed on HEAD. Also verified per-semaphore maximum-value coalescing, out-of-order completion, monotonic retirement, semaphore isolation, and recording new tickets after queue_idle().

Full Vulkan vkWaitSemaphores integration was not tested locally. From the CPU-side correctness review, LGTM.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7136222416 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/935#issuecomment-7136222416). Originally posted by [moffington](https://github.com/moffington) on 2026-11-24T15:33:16Z. --- Reviewed `9392bbd9e` against `a28927849` on Linux. No issues found. The checked-in `retire_tickets_test` and an independent adversarial test suite passed with ASan/UBSan enabled. The differential suite reproduced the duplicate-semaphore issue on baseline and passed on HEAD. Also verified per-semaphore maximum-value coalescing, out-of-order completion, monotonic retirement, semaphore isolation, and recording new tickets after `queue_idle()`. Full Vulkan `vkWaitSemaphores` integration was not tested locally. From the CPU-side correctness review, LGTM.
Timon360SB commented 2026-11-24 15:48:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Timon360SB on 2026-11-24T15:48:28Z.


Testing results

Independently tested PR #935 against the baseline on
two NVIDIA GPU configurations.

Tested revisions

  • BASE: a28927849adb4e40dfdec8c32fb6758dcd205a37
  • HEAD: 9392bbd9e03b88fd4746f51e2fb1e7cd7b0e5b86

Test environments

Component System 1 System 2
CPU AMD Ryzen 7 7800X3D AMD Ryzen 5 3600X
GPU NVIDIA GeForce RTX 5070 NVIDIA GeForce RTX 2060 SUPER
VRAM 12227 MiB 8192 MiB
RAM (reported) 31.11 GiB 15.93 GiB
GPU driver 621.14 621.14
OS Windows 11 Pro (26200) Windows 11 Pro (28000)
Vulkan SDK 1.4.363.0 1.4.363.0
Resizable BAR Enabled Disabled

Test configuration

  • Compiler: MSVC
  • Build configuration: RelWithDebInfo
  • Build generator: Ninja Multi-Config
  • Build scope: selected targets
  • Vulkan validation: enabled
  • GPU-assisted validation: enabled
  • Synchronization validation: enabled
  • Repetitions: 3 per revision on each system

All selected build targets compiled successfully
for both BASE and HEAD on both systems.

CTest results

Test RTX 5070 BASE RTX 5070 HEAD RTX 2060 SUPER BASE RTX 2060 SUPER HEAD
retire_tickets 3/3 3/3 3/3 3/3
vk_queue_query_sync 3/3 3/3 3/3 3/3
d3d12_queue_wait 3/3 3/3 3/3 3/3
d3d12_queue_handover_two_queues 3/3 3/3 3/3 3/3
vk_sync_validation 3/3 3/3 3/3 3/3
Total PASS 15/15 15/15 15/15 15/15
  • BASE: 30/30 PASS
  • HEAD: 30/30 PASS
  • Combined: 60/60 PASS
  • FAIL: 0
  • SKIP: 0
  • Regressions: 0

All 12 CTest invocations completed with exit code 0.

Retire tickets

The retirement prefix remained safe during
out-of-order queue completion.

The test passed consistently across all repetitions,
both revisions and both hardware configurations.

No retirement-ordering failures were observed.

Queue and query synchronization

The following scenarios completed successfully:

  • Serialization of remove_query_pool with
    QueryReplay::commit.
  • Cross-queue serialization of QueryReplay::plan
    with commit.
  • Preservation of pending waits across failed
    vkQueueSubmit operations.
  • Preservation of waits for retry after a failed
    held batch.
  • Correct handling of failed and retried signals.
  • Concurrent multi-queue query stress.
  • Injected nonfatal execution failures.
  • Injected device-loss handling and rejection of
    subsequent work.

The fault-injection results were consistent across
BASE and HEAD:

Property BASE HEAD
Nonfatal execute result 0 0
Device-loss execute result 10 10
Context lost 1 1
Interceptions 2 2

The reported execution failures and device-loss
messages belong to the intentional fault-injection
scenarios.

D3D12 queue waits

Both Wait-before-Signal scenarios completed
successfully:

  • Copy/compute queues.
  • Direct/direct queues.

No test failures, hangs or timeouts were observed.

Two-queue handover

The test used a caller-owned Vulkan device with
two VkQueues handed to the layer.

The reported queue availability was 3/3/3 for
COPY/COMPUTE/DIRECT on both systems.

Results per invocation:

Implementation BASE HEAD
Vulkan layer 592/592 exact 592/592 exact
Host D3D12 587/587 exact 587/587 exact

These results were consistent across all repetitions
on both GPUs.

The never-signaled fence scenario also completed
successfully:

  • Dependent operations remained held.
  • Other queues were unaffected.
  • Queue destruction completed without a hang.

The diagnostic reporting two held operations that
were never submitted is expected for this scenario.

Both upload heap configurations were covered:

  • RTX 5070: VRAM with Resizable BAR.
  • RTX 2060 SUPER: system memory without Resizable BAR.

Vulkan synchronization validation

The synchronization validation self-test produced
the expected results in every execution.

Scenario BASE HEAD
Without a barrier 1 validation error 1 validation error
With a barrier 0 validation errors 0 validation errors

The reported WRITE_AFTER_WRITE hazard was
intentionally triggered by the self-test.

Synchronization validation was confirmed to be
active in all 12 self-test executions.

The validation layers also reported configuration
warnings related to GPU-assisted validation,
feature adjustments and unsupported validation
options.

These diagnostics were consistent between BASE
and HEAD.

No unexpected validation errors or new validation
diagnostics were observed within the tested scope.

Limitations

  • Synthetic tests only.
  • No real-title execution was performed.
  • Only five selected CTest targets were tested.
  • Only NVIDIA hardware was tested.
  • Both systems used the same GPU driver version.
  • This was not a performance benchmark.
  • The results do not establish correctness for
    untested synchronization or retirement scenarios.

Conclusion

All selected tests passed consistently on both
hardware configurations and both tested revisions.

The retirement prefix remained safe during
out-of-order queue completion. Queue synchronization,
fault recovery, Wait-before-Signal and two-queue
handover tests completed successfully.

No functional regressions, unexpected validation
errors or test failures were observed between BASE
and HEAD within the tested scope.

Result: PASS — no regressions detected.

AI-assisted log analysis and report preparation.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7136644904 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/935#issuecomment-7136644904). Originally posted by [Timon360SB](https://github.com/Timon360SB) on 2026-11-24T15:48:28Z. --- ## Testing results Independently tested PR #935 against the baseline on two NVIDIA GPU configurations. ### Tested revisions - BASE: `a28927849adb4e40dfdec8c32fb6758dcd205a37` - HEAD: `9392bbd9e03b88fd4746f51e2fb1e7cd7b0e5b86` ### Test environments | Component | System 1 | System 2 | |---|---|---| | CPU | AMD Ryzen 7 7800X3D | AMD Ryzen 5 3600X | | GPU | NVIDIA GeForce RTX 5070 | NVIDIA GeForce RTX 2060 SUPER | | VRAM | 12227 MiB | 8192 MiB | | RAM (reported) | 31.11 GiB | 15.93 GiB | | GPU driver | 621.14 | 621.14 | | OS | Windows 11 Pro (26200) | Windows 11 Pro (28000) | | Vulkan SDK | 1.4.363.0 | 1.4.363.0 | | Resizable BAR | Enabled | Disabled | ### Test configuration - Compiler: MSVC - Build configuration: RelWithDebInfo - Build generator: Ninja Multi-Config - Build scope: selected targets - Vulkan validation: enabled - GPU-assisted validation: enabled - Synchronization validation: enabled - Repetitions: 3 per revision on each system All selected build targets compiled successfully for both BASE and HEAD on both systems. ### CTest results | Test | RTX 5070 BASE | RTX 5070 HEAD | RTX 2060 SUPER BASE | RTX 2060 SUPER HEAD | |---|---:|---:|---:|---:| | `retire_tickets` | 3/3 | 3/3 | 3/3 | 3/3 | | `vk_queue_query_sync` | 3/3 | 3/3 | 3/3 | 3/3 | | `d3d12_queue_wait` | 3/3 | 3/3 | 3/3 | 3/3 | | `d3d12_queue_handover_two_queues` | 3/3 | 3/3 | 3/3 | 3/3 | | `vk_sync_validation` | 3/3 | 3/3 | 3/3 | 3/3 | | **Total PASS** | **15/15** | **15/15** | **15/15** | **15/15** | - BASE: 30/30 PASS - HEAD: 30/30 PASS - Combined: **60/60 PASS** - FAIL: 0 - SKIP: 0 - Regressions: 0 All 12 CTest invocations completed with exit code 0. ### Retire tickets The retirement prefix remained safe during out-of-order queue completion. The test passed consistently across all repetitions, both revisions and both hardware configurations. No retirement-ordering failures were observed. ### Queue and query synchronization The following scenarios completed successfully: - Serialization of `remove_query_pool` with `QueryReplay::commit`. - Cross-queue serialization of `QueryReplay::plan` with `commit`. - Preservation of pending waits across failed `vkQueueSubmit` operations. - Preservation of waits for retry after a failed held batch. - Correct handling of failed and retried signals. - Concurrent multi-queue query stress. - Injected nonfatal execution failures. - Injected device-loss handling and rejection of subsequent work. The fault-injection results were consistent across BASE and HEAD: | Property | BASE | HEAD | |---|---:|---:| | Nonfatal execute result | 0 | 0 | | Device-loss execute result | 10 | 10 | | Context lost | 1 | 1 | | Interceptions | 2 | 2 | The reported execution failures and device-loss messages belong to the intentional fault-injection scenarios. ### D3D12 queue waits Both Wait-before-Signal scenarios completed successfully: - Copy/compute queues. - Direct/direct queues. No test failures, hangs or timeouts were observed. ### Two-queue handover The test used a caller-owned Vulkan device with two VkQueues handed to the layer. The reported queue availability was 3/3/3 for COPY/COMPUTE/DIRECT on both systems. Results per invocation: | Implementation | BASE | HEAD | |---|---:|---:| | Vulkan layer | 592/592 exact | 592/592 exact | | Host D3D12 | 587/587 exact | 587/587 exact | These results were consistent across all repetitions on both GPUs. The never-signaled fence scenario also completed successfully: - Dependent operations remained held. - Other queues were unaffected. - Queue destruction completed without a hang. The diagnostic reporting two held operations that were never submitted is expected for this scenario. Both upload heap configurations were covered: - RTX 5070: VRAM with Resizable BAR. - RTX 2060 SUPER: system memory without Resizable BAR. ### Vulkan synchronization validation The synchronization validation self-test produced the expected results in every execution. | Scenario | BASE | HEAD | |---|---:|---:| | Without a barrier | 1 validation error | 1 validation error | | With a barrier | 0 validation errors | 0 validation errors | The reported `WRITE_AFTER_WRITE` hazard was intentionally triggered by the self-test. Synchronization validation was confirmed to be active in all 12 self-test executions. The validation layers also reported configuration warnings related to GPU-assisted validation, feature adjustments and unsupported validation options. These diagnostics were consistent between BASE and HEAD. No unexpected validation errors or new validation diagnostics were observed within the tested scope. ### Limitations - Synthetic tests only. - No real-title execution was performed. - Only five selected CTest targets were tested. - Only NVIDIA hardware was tested. - Both systems used the same GPU driver version. - This was not a performance benchmark. - The results do not establish correctness for untested synchronization or retirement scenarios. ### Conclusion All selected tests passed consistently on both hardware configurations and both tested revisions. The retirement prefix remained safe during out-of-order queue completion. Queue synchronization, fault recovery, Wait-before-Signal and two-queue handover tests completed successfully. No functional regressions, unexpected validation errors or test failures were observed between BASE and HEAD within the tested scope. **Result: PASS — no regressions detected.** AI-assisted log analysis and report preparation.
QemmHD commented 2026-11-24 18:38:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T18:38:52Z.


Merging.

Why merged: RT-RETIRE-TICKETS-DEDUP-WAIT: pending_through() merges entries per semaphore to the highest value, and completed_ can no longer move backwards. moffington (ASan/UBSan, with a differential test that fails on the base), Timon360SB, KernelSmoker and SweatierKey checked it independently.

Why it's good: retire_tickets passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 32950551e, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be34. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e224: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7140938553 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/935#issuecomment-7140938553). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T18:38:52Z. --- Merging. **Why merged:** RT-RETIRE-TICKETS-DEDUP-WAIT: pending_through() merges entries per semaphore to the highest value, and completed_ can no longer move backwards. moffington (ASan/UBSan, with a differential test that fails on the base), Timon360SB, KernelSmoker and SweatierKey checked it independently. **Why it's good:** retire_tickets passes both plain and under validation. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 32950551e, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be34. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e224: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!935
No description provided.