Skip to content

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

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
narekshaghoyandev:ubiq-retire-tickets-dedup-wait
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
narekshaghoyandev:ubiq-retire-tickets-dedup-wait

Conversation

@narekshaghoyandev

Copy link
Copy Markdown
Contributor

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

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

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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 added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** D3D-CLEAR-DEPTH-RANGE: enables VK_EXT_depth_range_unrestricted where the device has it, so depth clears outside [0,1] (and NaN) behave like D3D12 instead of being clamped. Without the extension it keeps clamping, and NaN becomes 0. Four independent passes; on AMD (660M, 7900 XTX), d3d12_clear still fails only on the NaN rows, which is the driver issue tracked in #307, not this PR.

**Why it's good:** On the 4070 SUPER with validation on, main's d3d12_clear_test exits 1 with 4x VUID-VkClearDepthStencilValue-depth-00022. With this PR it exits 0 with no VUIDs, and the 1.5 / -0.5 / NaN clears match WARP. The new d3d12_clear_restricted_depth passes, and so do d3d12_clear and d3d12_clear_formats.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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 added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** VK-SAMPLER-UNNORM-BIAS: an unnormalized-coordinates sampler gets mipLodBias 0, which VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074 requires. kawaii-shakal ran it under ASan/UBSan and showed the new check fails on main.

**Why it's good:** gfx10_descriptors and d3d12_descriptor pass 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 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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 added a commit that referenced this pull request Nov 24, 2026
…opy-clear-stage

Merging.

**Why merged:** OLD-10048: SYNC_COPY maps to COPY|CLEAR, so WriteBufferImmediate (vkCmdUpdateBuffer) and the query zero-fill are ordered before later copies. moffington reproduced the read-after-write hazard on the base, and Timon360SB and SweatierKey checked it independently. Part K of vk_command_replay_test covers it.

**Why it's good:** vk_command_replay, d3d12_state_map and replay_query_edges pass 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 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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
QemmHD merged commit 6293c1c into ProjectLeonida:main Nov 24, 2026
7 of 13 checks passed
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.

6 participants