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

Manually merged
github merged 1 commit from gh-pr/935/head into gh-pr/935/base 2026-11-26 09:29:13 +00:00
Owner

@⁠narekshaghoyandev on GitHub · 2026-11-24 15:17 UTC · original
narekshaghoyandev:ubiq-retire-tickets-dedup-wait → main · +31 −3 · 2 files · 1 commits · merged 2026-11-24 18:38 UTC

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)

**@⁠narekshaghoyandev** on GitHub · 2026-11-24 15:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/935) `narekshaghoyandev:ubiq-retire-tickets-dedup-wait` → `main` · +31 −3 · 2 files · 1 commits · merged 2026-11-24 18:38 UTC ## 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:29:11 +00:00
github manually merged commit 9392bbd9e0 into gh-pr/935/base 2026-11-26 09:29:13 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 15:32 UTC · original · approved these changes

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.

**@⁠KernelSmoker** on GitHub · 2026-11-24 15:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/935#pullrequestreview-6042279400) · **approved these changes** 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.
Author
Owner

@⁠SweatierKey on GitHub · 2026-11-24 15:33 UTC · original · approved these changes

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

**@⁠SweatierKey** on GitHub · 2026-11-24 15:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/935#pullrequestreview-6042301753) · **approved these changes** 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
Author
Owner

@⁠moffington on GitHub · 2026-11-24 15:33 UTC · original

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.

**@⁠moffington** on GitHub · 2026-11-24 15:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/935#issuecomment-7136222416) 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.
Author
Owner

@⁠Timon360SB on GitHub · 2026-11-24 15:48 UTC · original

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.

**@⁠Timon360SB** on GitHub · 2026-11-24 15:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/935#issuecomment-7136644904) ## 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.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 18:38 UTC · original

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).

**@⁠QemmHD** on GitHub · 2026-11-24 18:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/935#issuecomment-7140938553) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.