Skip to content

Runtime: D3D12 queues share a VkQueue when the GPU has no free one (Intel UHD 770 queueCount 1), plus a CPU-signal hang fix - #5110

Merged
shayderrr merged 8 commits into
ItsNotRexed:mainfrom
tedin7:d3d12-queue-sharing
Nov 23, 2026
Merged

shayderrr merged 8 commits into
ItsNotRexed:mainfrom
tedin7:d3d12-queue-sharing

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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

What and why

On a GPU whose queue family exposes one VkQueue (the Intel UHD 770 on Windows, seen by PingasMech on #4863; lavapipe too), the second live D3D12 queue of any type was refused: CreateCommandQueue printed "no independent Vulkan queue available" and returned E_OUTOFMEMORY. A title that creates a DIRECT and a COMPUTE queue stopped at boot. This is also why d3d12_sparse_queue_family failed there (#4841) and d3d12_queue_wait skipped.

This PR lets several D3D12 queues share one VkQueue when no free one is left, and keeps the D3D12 fence semantics. While building it I found a hang that is on main too, on separate queues: a CPU Signal that has to wait behind a pending queue Signal never released the queues waiting for its value. The first commit fixes it.

Design

  • Choosing a VkQueue (pick_queue_slot in runtime/src/queue_families.h, used by CreateCommandQueue). A new D3D12 queue takes an unused VkQueue: its own type's family first, then the graphics family. This is the same as before, so D3D-97 (D3D-97: give live D3D12 queues distinct Vulkan queues #1404) still gives one VkQueue per live D3D12 queue while there are enough. Nothing changes by default on a GPU with enough queues: an RTX 5080 has 16 graphics, 8 compute and 2 transfer queues. When every VkQueue is taken, the D3D12 queue shares the one with the fewest D3D12 queues. On a tie it picks its own family. The layer logs this once per queue type. Leases are now counts per VkQueue, not busy flags.
  • What stays per D3D12 queue. Each D3D12 queue keeps its own VulkanQueue: its own batch order, progress timeline, command pool and held operations. On a shared VkQueue, the batches of the D3D12 queues run one after another, in the order they reach it. So they lose concurrency, but the results stay correct. This is the same as the one-family case that section 4.4 already describes.
  • No deadlock on a shared VkQueue. The danger is a GPU wait that reaches the VkQueue before the Signal it waits for, which never completes. The Wait-before-Signal holding (Runtime: queue Wait before Signal — hold the batch until its Signal is submitted, so layouts follow dependency order across queues #2951 machinery, queue_holds.h) already prevents this. A batch reaches vkQueueSubmit only after every fence value it waits for has a submitted Signal (earlier on the same VkQueue or on another one) or has been set by the CPU. Otherwise the batch, and everything the queue gets after it, is held on the CPU. Then the thread that submits the Signal releases it, in order.
  • The CPU half (first commit). A CPU ID3D12Fence::Signal above a queue Signal the GPU has not reached yet is applied later by the fence wait thread (VUID-VkSemaphoreSignalInfo-value-03259). That thread set the semaphore but never told the tracker, so a queue that waited for the value stayed held forever. The thread now reports the value after vkSignalSemaphore and releases what it satisfies. It must not report the value at the time of the CPU call: the waiting batch could then reach a shared VkQueue ahead of the queue Signal it depends on, and never complete.
  • External synchronisation. vkQueueSubmit, vkQueueBindSparse, vkQueuePresentKHR, vkQueueWaitIdle and the queue labels all already run under the device's one VulkanContext::submit_mutex. That lock covers shared VkQueues, as it already covers the staging queue, which the first DIRECT queue shares today. So this PR adds no lock. Runtime: unblock independent Vulkan queue submissions during calibration #3841 replaces that lock with one per VkQueue; to stay correct it must key the lock on the VkQueue handle, because one handle can now back several D3D12 queues.
  • Costs on a shared VkQueue (documented in section 4.4): concurrency is lost. The GetClockCalibration fallback (without calibrated timestamps) and the destruction of a D3D12 queue also wait for the other D3D12 queues' submitted work. Queue debug labels of the D3D12 queues interleave on the shared queue.
  • Releasing a fence while a queue holds work for it (fourth commit, from review). The fence wait thread could be applying a deferred CPU Signal at the moment the app released the fence. Two things went wrong. If the release applied the value, the held batch was submitted and the VkSemaphore was destroyed right under it (VUID-vkDestroySemaphore-semaphore-05149, formerly -01137). If the wait thread had the callback, the release dropped the batch although the fence had reached its value. Now ~Fence waits for that callback; the release drops only batches waiting for a value no Signal reached; and the semaphore goes to the deferred deletion queue, destroyed once the work submitted before the release has finished.
  • Test settings for the standalone device (docs/testing.md), so this path runs on any GPU. LEONIDA_VK_MAX_QUEUES_PER_FAMILY=N creates at most N VkQueues per family. LEONIDA_VK_GRAPHICS_FAMILY_ONLY=1 puts COMPUTE and COPY queues in the graphics family. With both, the device has one family and one queue, the UHD 770 shape. Only the test executables apply them (fifth commit, from review): the game's device (d3d12_xs, LEONIDA_D3D12=vulkan) ignores them and says so, so a variable left set cannot serialize a game's queues.

Tested

Setup: RTX 5080, Linux, driver 580.65.06, Wine 11.0, clang-cl 21 cross build (xwin). For the RTX 5080 runs, VK_LAYER_KHRONOS_validation from SDK 1.4.363.1 was injected with VK_INSTANCE_LAYERS and VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true. (Wine's vulkan-1 lists no layers to the guest, so LEONIDA_VK_VALIDATION=1 cannot enable the layer under Wine.) I checked that the layer was loaded in /proc/<pid>/maps for the RTX 5080 and lavapipe runs. Positive control: in the same setup, d3d12_subresource_copy reports its known 36 VUID-VkImageCreateInfo-initialLayout-12478 messages. lavapipe is Mesa 23.2.1 llvmpipe: one G|C|T family, queueCount 1.

New d3d12_queue_share_test (36 queues and a buffer copied through all of them, consumer first then producer first; 9 deferred-CPU-Signal cases; a fence released right after the GPU passes the queue Signal its CPU Signal waits behind, while another queue holds a batch for the CPU value; 4 threads × 9 queues):

main this PR
RTX 5080, no setting FAIL: 27th CreateCommandQueue (COPY) 0x8007000e; the first deferred case hangs ("a fence never reached 1") PASS: 36 queues, both chains exact, 9/9 deferred, stress 400/400; stress alone 1,200/1,200
RTX 5080, MAX_QUEUES_PER_FAMILY=1 (setting not in main) PASS; stress alone 2,000/2,000
RTX 5080, both settings (one VkQueue) (not in main) PASS; stress alone 2,000/2,000
lavapipe FAIL: 2nd CreateCommandQueue (COMPUTE) 0x8007000e; stress cannot create its queues PASS; stress alone 80,000/80,000 (all 9 queues on its one VkQueue)

All runs had 0 validation messages. At the head, --case all --iterations 500 passes in the three modes (RTX 5080 with no setting, with both settings, lavapipe), stress 2,000/2,000 each, 0 validation messages.

Fence released while a batch is held (--case release, 300 releases per queue type, validation messages counted with the layer's message limit off):

before the fourth commit head
RTX 5080, no setting VUID-vkDestroySemaphore-semaphore-05149; dropped 216, 290, 19 of 300 (DIRECT, COMPUTE, COPY) 900/900 batches run, 0 validation messages
RTX 5080, both settings 05149; dropped 300, 298, 281 of 300 900/900, 0
lavapipe 05149; dropped 199, 136, 139 of 300 900/900, 0

Argument checks (sixth commit, from review): --case typo used to run nothing and print PASS, and --iterations 0 or banana ran "0 of 0" and passed. An unknown case or argument, or an iteration count that is not a whole number from 1 to 1,000,000, now prints the usage line and exits with code 2 before any device is created. The new ctests d3d12_queue_share_rejects_* (4 bad arguments) were 0/4 before and are 4/4 after, on the RTX 5080 and lavapipe. After it, --case all --iterations 500 still passes in the three modes, stress 2,000/2,000, 0 validation messages.

Test settings ignored by the game's device (run_tiny_frame_queue_test_settings: tiny_frame under gta6rt --run with both settings set): with d3d12_xs applying them (the old behaviour) it fails with 4 problems; at the head it passes on the RTX 5080 and lavapipe.

Existing tests in four modes (RTX 5080 with no setting, with MAX_QUEUES_PER_FAMILY=1, with both settings, and lavapipe), under the layer:

  • d3d12_queue_handover, layer half: 371/371 cases exact in all four modes. On lavapipe, main ran 0 cases (queues 1/0/0). I skipped the host half with a local-only switch for this measurement. Under Wine the host is vkd3d, and its 20× VUID-vkCmdDraw-None-09600 and 10× SYNC-HAZARD-WRITE-AFTER-WRITE appear identically on main.
  • ctest with -j4 over 20 tests: d3d12_queue_share, d3d12_queue_share_one_queue, d3d12_queue_wait, d3d12_queue_wait_timeout, d3d12_queue_wait_one_queue, d3d12_queue_handover, d3d12_sparse_queue_family, d3d12_fence_events, d3d12_fence_timing, d3d12_fence_waiter, d3d12_m4_compute, d3d12_compute, d3d12_fspx_compute, d3d12_set0_compute, queue_proxy, d3d12_multithread, vk_queue_query_sync, vk_fence_dispatcher_sync, run_tiny_frame and run_tiny_frame_queue_test_settings. Numbers at the head:
    • RTX 5080: 18/20 pass in each of the three modes.
    • lavapipe: 18/20 pass and 1 is skipped (d3d12_sparse_queue_family: lavapipe has no sparse binding).
    • The failures are the same on main under Wine: d3d12_fence_timing on the RTX 5080 (line 318, custom heap properties differ from Wine's host d3d12) and d3d12_queue_handover (the host-side VUIDs above; all 30 validation messages of each run come from it, plus 8 shader-capability messages from d3d12_m4_compute on lavapipe, unrelated to queues).
    • d3d12_queue_wait_timeout and d3d12_queue_wait passed in all four modes in this run. Before the fourth commit, both hung at process exit under Wine on main and on this branch (not investigated further).
  • d3d12_sparse_queue_family passes on the RTX 5080 in all three modes. With both settings, its DIRECT, COPY and COMPUTE queues share one VkQueue: this is the case that failed on the UHD 770 (d3d12_sparse_queue_family: skip, not fail, on GPUs without three independent Vulkan queues #4841).
  • d3d12_queue_wait with both settings: 3/3 runs pass when run alone. Without settings, it hangs at process exit under Wine both on main and here (3/3 runs each, killed after 60 s, after the device was destroyed). Under ctest -j4 it passed in all four modes.
  • vk_queue_test, built natively on Linux: the family picker, the new slot checks, and the GPU part on the RTX 5080 (with and without the layer) and on lavapipe all pass.
  • Python tests that read the changed files (17 files: ctest registration, docs rows and flags, check_tiny_frame, runtime paths and others): 248 passed, 14 skipped.

Not covered

  • No Intel GPU here. @PingasMech, could you confirm on the UHD 770? ctest -R "d3d12_queue_(share|wait)|d3d12_sparse_queue_family", plus the title that stopped at boot, should now create its queues. The device line and the "shares one" log line would help.
  • I did not run native Windows or AMD; all results come from Wine 11 on Linux.
  • The cost of sharing (lost overlap between the D3D12 queues on one VkQueue) is documented but not measured.
  • The d3d12_queue_wait exit hang under Wine is on main too. It did not show at the head, but I did not look into why.
  • Lanterns stages 3 and 5 were run before the review fixes (PASS on the RTX 5080 with and without the settings, and on lavapipe), not again after them.
  • With this PR, d3d12_sparse_queue_family no longer meets E_OUTOFMEMORY on one-queue GPUs, so the skip path from d3d12_sparse_queue_family: skip, not fail, on GPUs without three independent Vulkan queues #4841 should no longer trigger there.

No game files.

AI-assisted (Claude Code).


Update after merging main (3fca6d30). main has since fixed the race this PR's c5eed145 fixed, in its own way: fences stay alive until the GPU is done, a fence cancel waits for running callbacks, and the CPU-signal hang is fixed the same way. So queue_holds.h, vulkan_backend.h and d3d12_com.cpp now take main's version as-is, and the earlier description of the c5eed14 design no longer applies. What this PR still adds is the queue sharing itself (D3D12 queues share a VkQueue when the GPU has no free one), its test settings, the validation-layer check and its test, and docs.

Proof at this head: --case release runs 300 of 300 batches with the validation layer and 0 messages. Under Wine all 22 queue and fence tests pass. Since then, @CryingLaughing has passed it on a physical UHD 770 and @XFlawless1 on AMD.

…r its value

A CPU ID3D12Fence::Signal above a queue Signal the GPU has not reached is applied later by the fence wait
thread (VUID-VkSemaphoreSignalInfo-value-03259). That thread set the semaphore but never told the
Wait-before-Signal tracker (queue_holds.h), so a queue whose Wait named that value stayed held on the CPU for
ever and the title hung, on separate VkQueues as on a shared one. The thread now reports the value after
vkSignalSemaphore and releases what it satisfied. Reporting it when the CPU calls Signal would be wrong: the
waiting batch could then reach a VkQueue ahead of the queue Signal it depends on, which never completes when the
two D3D12 queues share that VkQueue.

Test: d3d12_queue_share_test --case deferred (next commit); on main it stops at the first case with
"a fence never reached 1".
…ilies is in use

On a GPU whose queue family exposes one VkQueue (the Intel UHD 770 on Windows, lavapipe), the second live
D3D12 queue of any type was refused with E_OUTOFMEMORY ("no independent Vulkan queue available"), so a title
with a DIRECT and a COMPUTE queue stopped at boot. CreateCommandQueue now takes an unused VkQueue as before
(own family first, then the graphics family: D3D-97's one VkQueue per live D3D12 queue while there are enough,
nothing changes on the RTX 5080), and when none is left shares the VkQueue with the fewest D3D12 queues
(pick_queue_slot, queue_families.h). Each D3D12 queue keeps its own order, progress timeline and held
operations; Wait-before-Signal holding already keeps a GPU wait from reaching a VkQueue before a submitted
Signal satisfies it, and every VkQueue call already holds the device's submit lock.

Test settings for the standalone device, so the path runs on any GPU: LEONIDA_VK_MAX_QUEUES_PER_FAMILY=N and
LEONIDA_VK_GRAPHICS_FAMILY_ONLY=1 (both: one family, one VkQueue, the UHD 770 shape). New
d3d12_queue_share_test (36 queues with a chain through all of them in both submission orders, deferred CPU
Signal cases, a 4-thread stress on 9 queues), registered plain and with both settings, and d3d12_queue_wait
with both settings; vk_queue_test checks the slot choice.
…, and its semaphore outlives them

DeepSeek review of d3d12-queue-sharing: when a D3D12 fence was released while a queue held a batch waiting for a
CPU Signal that was still deferred behind a queue Signal, the release raced the fence wait thread. If the cancel
applied the CPU value, the pump submitted the held batch and ~VulkanFence then destroyed the VkSemaphore it waits
on (VUID-vkDestroySemaphore-semaphore-05149, formerly -01137). If the wait thread had already taken the callback,
remove_fence ran first and dropped the batch although the fence had reached the value.

- ~Fence waits for a held CPU Signal the wait thread is applying (not on that thread itself).
- QueueHolds::remove_fence drops only the held batches that wait for a value no Signal reached.
- VulkanFence hands its semaphore to the deferred deletion queue: destroyed once the work submitted before the
  release has finished.

Test: d3d12_queue_share_test --case release (part of the ctest runs): 300 releases per queue type right after the
GPU passes the queue Signal. Before, on the RTX 5080 under Wine with the validation layer: VUID-...-05149 and 216 to
300 of 300 batches dropped per type; on lavapipe the same. After: all 900 batches run per mode (no setting, one
queue, lavapipe), 0 validation messages.
DeepSeek review of d3d12-queue-sharing: LEONIDA_VK_MAX_QUEUES_PER_FAMILY and LEONIDA_VK_GRAPHICS_FAMILY_ONLY were
read in create_vulkan_device_standalone, which is also the game's device (d3d12_xs, LEONIDA_D3D12=vulkan). Left set,
they would put every D3D12 queue of the game on one VkQueue, with one stderr line.

create_vulkan_device_standalone takes QueueTestSettings (apply by default, for the test executables); d3d12_xs
passes ignore, and the device says once per setting that it ignores it.

Test: run_tiny_frame_queue_test_settings runs tiny_frame under gta6rt --run with both settings set and fails if
the game's device applied them or did not say it ignores them. With d3d12_xs passing apply (the old behaviour) it
fails with 4 problems; with this change it passes (RTX 5080 and lavapipe, Wine 11).

Also: the ctest run of the commit before this (d3d12_queue_share_test --case release) dropped 19 to 300 of 300
batches per queue type before the fix (RTX 5080: 216, 290, 19 with no setting, 300, 298, 281 with one queue;
lavapipe: 199, 136, 139), not "216 to 300" as its message says.
@daemosofchaos

Copy link
Copy Markdown
Contributor

Independent native Windows 11 / MSVC 19.52 check of d8272478 on NVIDIA RTX 5070 Ti (driver 621.24), using synthetic inputs. The targeted build succeeded; the compiler emitted warnings.

With Khronos validation and synchronization validation enabled, 7/7 CTests passed: vk_queue_query_sync, d3d12_queue_wait, d3d12_queue_wait_timeout (expected-failure timeout control), d3d12_queue_share, d3d12_queue_share_one_queue, d3d12_queue_wait_one_queue, and d3d12_fence_waiter. No VUID or Validation Error appeared in their captured output.

Both default and simulated one-queue runs created 36 D3D12 queues, returned exact data through the chain in both submission orders, passed all nine deferred CPU-signal pairings, completed 100/100 held-fence releases per queue type and 400/400 stress iterations. The separate vk_queue_test also passed with validation on, including the family picker, slot-sharing checks and copy readbacks; it reported zero validation errors.

This is a simulated single-queue configuration on NVIDIA, not a test on Intel hardware, and it does not validate game boot. No game files were used.

— LocalFirst-AI

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested d827247 on Intel UHD 770 (driver 32.0.101.7088), Windows 11, MSVC 19.44, Vulkan SDK 1.4.357.0: the queue-sharing tests pass, with one ctest entry that crashes in the api_dump harness.

Native MSVC build of d3d12_queue_share_test, d3d12_queue_wait_test and d3d12_sparse_queue_family_test, exit 0. ctest results:

d3d12_queue_handover and the game-based checks were not run.

AI-assisted.

@daemosofchaos

Copy link
Copy Markdown
Contributor

Follow-up on the validation-layer question: I reran the synthetic deferred-signal case with the same Windows environment as my earlier run, including a process-local VK_LAYER_PATH pointing at the SDK's Bin directory and LEONIDA_VK_VALIDATION=1. Vulkan loader diagnostics explicitly show VK_LAYER_KHRONOS_validation inserted as both instance and device layer. All nine deferred-signal pairings completed exactly, with no VUID/Validation Error in that run. The source enables synchronization validation through its instance configuration.

This confirms layer insertion on my NVIDIA setup; it does not establish the behavior on Intel or on systems without that layer path. No game files used.

— LocalFirst-AI

@XFlawless1

XFlawless1 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Native Windows check of d8272478 merged onto main 3faac557 (clean merge): pass. Next to the native RTX 5070 Ti and UHD 770 runs above, this adds all three queue modes over your 20-test ctest set, with the Khronos layer on.

Setup: Windows 11 Pro 26300, MSVC 19.44, scripts/build_runtime.ps1 (Ninja, RelWithDebInfo, LLVM_MC set so the M4 tests are built), NVIDIA RTX 5080 (621.14), Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1 (natively the device line says validation on, and the harness also turns on synchronization validation). Three modes: no setting; LEONIDA_VK_MAX_QUEUES_PER_FAMILY=1; and both settings (one VkQueue).

no setting MAX_QUEUES_PER_FAMILY=1 both settings
d3d12_queue_share_test --case all --iterations 500 PASS, stress 2000/2000, 0 validation lines PASS, 2000/2000, 0 PASS, 2000/2000, 0
d3d12_queue_share_test --case release --iterations 300 PASS, DIRECT, COMPUTE and COPY 300/300 each, 0 same same
your 20-test ctest set, -j 4 19/20 19/20 20/20
d3d12_queue_wait + d3d12_queue_wait_timeout, -j 1 --repeat until-fail:5 2/2 ×5, slowest 5.25 s 2/2 ×5, 5.14 s 2/2 ×5, 5.41 s

About the two -j 4 misses, which were not hangs:

  • No setting: d3d12_queue_wait_timeout timed out at 10.07 s. With MAX_QUEUES_PER_FAMILY=1: d3d12_queue_wait at 20.13 s. This machine was also running a GPU fuzzer sweep at the time.
  • Run alone with validation, d3d12_queue_wait_test takes 2.7–5.4 s and --timeout-control 3.6–5.2 s, 5 runs each:
    • this PR in both modes: every plain run exits 0 and every control run exits 1, as the test is meant to;
    • main's build (no setting) gives the same times.
  • So it's the TIMEOUT 10 (and 20) on these two tests under validation and parallel load, not this change. Serially they pass in every mode, above.
  • If they flake for others under -j, a bit more headroom on the control's limit would help. Optional.

The Wine-only exit hang you saw on d3d12_queue_wait doesn't show natively: 15 standalone runs (5 on main, 10 on this PR) and 15 serial ctest runs all exited within 5.5 s.

Not run here: AMD (I can add this machine's RDNA2 iGPU later; it's busy with a sweep). No game files. AI-assisted (Claude Code).

@daemosofchaos

Copy link
Copy Markdown
Contributor

One test-driver false-pass case at d8272478 (Windows 11, MSVC 19.52, RTX 5070 Ti):

--case typo --iterations 1       -> exit 0, PASS (no case ran)
--case stress --iterations 0     -> exit 0, 0 of 0 iterations, PASS
--case stress --iterations banana -> exit 0, 0 of 0 iterations, PASS
--case stress --iterations 1     -> exit 0, 4 of 4 iterations, PASS

The case value is not checked against the list in the usage text, and atoi maps a non-number to zero. Could the CLI reject an unknown case and invalid/nonpositive or out-of-range iteration counts before creating the device, with a small negative-argument test? This is a test-driver issue, not a demonstrated runtime failure; the default CTest runs reported earlier used valid options and still stand. Synthetic inputs only.

— LocalFirst-AI

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @daemosofchaos, that's a real false pass. The driver will reject an unknown --case and non-numeric, zero or out-of-range --iterations before it creates the device, with a usage message and a non-zero exit, plus a negative-argument test. I'll post the head here.

@gertify, thanks for the UHD 770 run: 36 queues and the three "shares one" lines are the path this PR is for, on the hardware it was written for. The d3d12_sparse_queue_family_contract crash under api_dump matches your report on #4900, so it is not from this change.

@XFlawless1, thanks for the three-mode table. Agreed that the two -j 4 misses are the 10 s / 20 s TIMEOUT under validation and parallel load. main's build gives the same times, and both pass serially.

…ation count

Review (daemosofchaos, ItsNotRexed#5110): --case typo ran nothing and printed PASS with exit 0, and --iterations 0 or banana
(atoi) ran "0 of 0" and passed too. The arguments are now checked before the device is created: an unknown --case,
an unknown argument, or an --iterations value that is not a whole decimal number from 1 to 1,000,000 prints the
problem and the usage line and exits with code 2.

Test: d3d12_queue_share_rejects_{case_typo,iterations_zero,iterations_word,iterations_too_many} (ctest, the usage
line required). Before, on the RTX 5080 under Wine: 0/4 (no usage line; the binary ran every case or none and said
PASS). After: 4/4 on the RTX 5080 and on lavapipe; exit code 2 also checked by hand for -5, 12x and --bogus.

@throny throny 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.

Tested d827247 on NVIDIA RTX 4080, driver 610.88, Windows 11: pass

This is a native Windows run; the description's runs were all under Wine. Build: MSVC 19.44.35230, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363. Merge base 3faac557 (= current main).

  • The PR's 20 tests plus d3d12_sparse_queue_family_contract (ctest -R "d3d12_queue_(share|wait|handover)|d3d12_sparse_queue_family|d3d12_fence_(events|timing|waiter)|d3d12_m4_compute|d3d12_compute|d3d12_fspx_compute|d3d12_set0_compute|queue_proxy|d3d12_multithread|vk_queue|vk_fence_dispatcher_sync|run_tiny_frame" -j 1): 21/21 pass, including d3d12_queue_share_one_queue, d3d12_queue_wait_one_queue, run_tiny_frame_queue_test_settings and d3d12_fence_timing.
  • Full ctest -j 6: 181/181 pass (9 skip themselves).
  • vk_queue_test (picker and slot checks plus the GPU part): OK.
  • d3d12_queue_share_test --case all --iterations 500 under VK_LAYER_KHRONOS_validation (LEONIDA_VK_VALIDATION=1, VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true, VK_LAYER_MESSAGE_LIMIT=-1), in three modes: no setting, MAX_QUEUES_PER_FAMILY=1, and both settings (one VkQueue). In each mode: 36 queues created, both chains exact, 9/9 deferred, release 500/500 per type, stress 2,000/2,000. 0 validation messages in all three.
  • Negative control for the fourth commit (the head's test on ce9df1c0's runtime, --case release --iterations 300, same layer settings): FAIL. 42, 25 and 35 of 300 batches ran (DIRECT, COMPUTE, COPY), and the layer reported 20× VUID-vkDestroySemaphore-semaphore-05149. So the layer was active, and the fourth commit removes both problems.
  • Control on main (the head's test and CMakeLists over 3faac557's runtime): --case many fails with CreateCommandQueue(COPY) number 27: 0x8007000e. --case deferred hangs at its first case ("DIRECT then DIRECT: a fence never reached 1"). This matches the RTX 5080 rows in the description, here natively on Windows.
  • python -m compileall -q make_game.py tools tests, tests/test_ctest_registration.py, tests/test_docs_links.py: OK.

I read the whole diff. I checked that ~Fence's wait on held_ cannot block for ever: cancel_fence_waits → FenceWaitDispatcher::cancel runs the pending callbacks on the releasing thread, and each callback decrements held_ and notifies. in_fence_callback covers the release from inside a callback. The lease lambdas keep a pointer into queue_users_/compute_users_/copy_users_; those vectors are sized only in the constructor, so the pointer stays valid. No findings.

Not covered here: Intel UHD 770, AMD.

AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@daemosofchaos, fixed in 0451f370. d3d12_queue_share_test now rejects an unknown --case or argument, and any --iterations that isn't an integer from 1 to 1,000,000, before it creates the device. It prints the problem and the usage line, and exits 2.

Four new ctest entries (d3d12_queue_share_rejects_*: typo, 0, banana, 99999999999) fail on d8272478 and pass now, on the RTX 5080 and on lavapipe. --case all --iterations 500 still passes in all three modes, with stress 2,000/2,000 and 0 validation errors.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0451f37 on Intel UHD 770, driver 32.0.101.7088, Windows 11, MSVC, with LEONIDA_VK_VALIDATION=1 and the Khronos validation layer loaded: d3d12_queue_share_test --case all exits 0 ("stress: 400 of 400 iterations completed exact over 4 threads", "created 36 D3D12 queues (12 per type)", and the "every Vulkan queue of the family is in use; this D3D12 queue shares one" lines for types 2 and 3) and --case release exits 0 (DIRECT, COMPUTE and COPY "100 of 100 batches ran"), with 0 validation messages. --case typo, --case all --iterations 0 and --case all --iterations banana each exit 2 with the usage line. ctest -R d3d12_queue_share passes 6 of 6. I did not run the --iterations 500 setting from the PR's table.

AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @gertify, and sorry for the late reply. The important part is your explicit run: with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, share, wait and sparse print 0 VUID lines on the UHD 770, so the sharing path is validation-clean on the GPU it was written for.

  • LEONIDA_VK_VALIDATION=1 not loading the layer: the device shim does read it (runtime/shims/d3d12_vulkan_device.cpp:7991 on main) and adds the layer at instance creation, so it should have worked. I'll check why it didn't for d3d12_queue_share_test with the loader's debug output, and report back here.
  • The d3d12_sparse_queue_family_contract crash in the api_dump harness: it's the same one you reported on check_sparse_queue_family: run api_dump and validation apart (TEST-1089) #4900, and this PR doesn't touch that harness.

AI-assisted.

…d12_queue_share_test fails instead of skipping

The standalone device asked for VK_LAYER_KHRONOS_validation without checking that the loader lists it, so vkCreateInstance failed with no hint and the test exited 77 (skip) as if no Vulkan device existed. The device now lists the layers first and logs the cause; the test exits 1 when validation was requested and no device came up.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gertify. I reproduced it on the RunPod under Wine with llvmpipe. With LEONIDA_VK_VALIDATION=1 alone the layer did not load: the standalone device asked vkCreateInstance for VK_LAYER_KHRONOS_validation without checking that the loader lists it, the call failed, and d3d12_queue_share_test printed "Vulkan standalone device unavailable" and exited 77 (a skip), so a ctest run looked fine without validation. (Under Wine the program is not shown the loader's layers, so only VK_INSTANCE_LAYERS loads it. With VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation the layer loads and the test passes.) Commit 2d65c30: the device now lists the layers first and, if the layer is missing, logs "LEONIDA_VK_VALIDATION is set but VK_LAYER_KHRONOS_validation is not listed by the Vulkan loader" and fails; the test exits 1 instead of 77 when validation was requested and no device came up. Checked on the RunPod: LEONIDA_VK_VALIDATION=1 alone now gives that message and exit 1. I could not check the Windows loader on a UHD 770; if the layer is installed there but not listed, the message now says so. AI-assisted.

main redesigned the fence release path that c5eed14 fixed here: a D3D12
queue now pins the fences it waits on and signals until the submission has
completed on the GPU (f8007dd, 48cee7c), held work keeps its fences alive,
the fence wait dispatcher's cancel waits for in-flight callbacks (df99c89),
and a deferred CPU Signal tells QueueHolds after vkSignalSemaphore (8dfe9bc,
the same fix as 79c55df here). So queue_holds.h, vulkan_backend.h and
d3d12_com.cpp take main's version: discard_waiting_on(semaphore) with
oldest_held_seq and in_pump, the immediate semaphore destroy, no
in_fence_callback wait in ~Fence. This branch's own change stays: D3D12 queues
share a VkQueue when every one is in use (pick_queue_slot), the queue test
settings, the validation layer check, d3d12_queue_share_test, docs.

Tested on an RTX 5080, clang-cl build under Wine: vk_queue,
vk_queue_query_sync, vk_fence_dispatcher_sync, vk_presenter_sync, d3d12_com,
d3d12_multithread, d3d12_queue_wait (+timeout, +one_queue),
d3d12_queue_handover (3 modes), d3d12_queue_share (+one_queue, 4 rejects),
d3d12_fence_timing, d3d12_m4_compute, run_tiny_frame,
run_tiny_frame_queue_test_settings pass (22/22). With VK_INSTANCE_LAYERS=
VK_LAYER_KHRONOS_validation: d3d12_queue_share --case release runs 300 of 300
batches with 0 validation messages, d3d12_queue_share(+one_queue) and
d3d12_queue_wait pass. vk_queue_test native, tests/test_check_tiny_frame.py and
tests/test_docs_*.py pass.
@XFlawless1

Copy link
Copy Markdown
Contributor

Tested 3fca6d30 (which already includes main 561b65a8) on AMD, the Radeon run I said I'd add: pass.

Setup: AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2 gfx1036, subgroup 32..64), AMD Windows driver 32.0.21045.29003 (26.11.2), Windows 11 Pro 26300. Built with MSVC 19.44 via scripts/build_runtime.ps1 (Ninja, RelWithDebInfo, LLVM_MC set). Vulkan SDK 1.4.363.0. LEONIDA_VK_DEVICE=AMD, LEONIDA_VK_VALIDATION=1. Same three modes and commands as my RTX 5080 run above.

no setting MAX_QUEUES_PER_FAMILY=1 both settings (one VkQueue)
d3d12_queue_share_test --case all --iterations 500 PASS, stress 2000/2000, 0 validation lines PASS, 2000/2000, 0 PASS, 2000/2000, 0
d3d12_queue_share_test --case release --iterations 300 PASS, 300/300 per queue type, 0 same same
your 20-test ctest set, -j 4 20/20 20/20 20/20

This time all 20 passed under -j 4 in every mode. The two d3d12_queue_wait* timeouts from my RTX run didn't recur, which fits the earlier explanation: that run shared the machine with a fuzzer sweep.

2d65c3082 (validation requested, layer missing): I hid the layer from the loader with VK_LOADER_LAYERS_DISABLE=VK_LAYER_KHRONOS_validation:

build d3d12_queue_share_test --case all
this PR exit 1. [rt] d3d12: LEONIDA_VK_VALIDATION is set but VK_LAYER_KHRONOS_validation is not listed by the Vulkan loader (...), then Vulkan standalone device unavailable with LEONIDA_VK_VALIDATION set
same tree with only 2d65c3082 reverted (git revert -n) and rebuilt exit 77 (skip). [rt] d3d12: vkCreateInstance (Vulkan 1.3) failed, then Vulkan standalone device unavailable

So the commit does what it says: a missing layer now fails with its cause instead of reading as "no Vulkan device". With the layer present, the rebuilt PR binary still passes.

No game files used. AI-assisted (Claude Code).

@CryingLaughing

Copy link
Copy Markdown
Contributor

Physical UHD 770 retest at 3fca6d30 on Windows 11 build 26200, Intel driver 32.0.101.7088, MSVC 19.44 RelWithDebInfo and Khronos validation 1.4.357. The Intel Vulkan ICD was selected and both queue-limiting overrides were unset. --case all --iterations 100 created 36 D3D12 queues, reported actual sharing for DIRECT, COMPUTE and COPY, and completed all 400 stress iterations exactly. A separate --case release --iterations 100 completed 100/100 batches per queue type. Queue wait, sparse-family and all four invalid-argument CTests passed (6/6). The loader confirmed that LEONIDA_VK_VALIDATION=1 loaded the Khronos device layer via VK_LAYER_PATH with VK_INSTANCE_LAYERS unset. Zero Vulkan validation errors. Synthetic inputs only. AI-assisted with Codex.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review

Reviewed change in PR #5110: Runtime: D3D12 queues share a VkQueue when the GPU has no free one (Intel UHD 770 queueCount 1), plus a CPU-signal ha....

Scope: docs/d3d12_vulkan.md, docs/testing.md, runtime/CMakeLists.txt, +7 more
Diff: +735 / -64 across 10 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @tedin7 - I went through Runtime: D3D12 queues share a VkQueue when the GPU has no free one (Intel UHD 770 queue... and the diff around docs/d3d12_vulkan.md. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

@shayderrr
shayderrr merged commit e76cb47 into ItsNotRexed:main Nov 23, 2026
0 of 5 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.

7 participants