runtime: D3D12.X command submission, multi-segment sync points, and Vulkan presentation swapchain #869

Closed
Tortoche wants to merge 2 commits from upstream-pr/869 into main
Tortoche commented 2026-11-24 14:51:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tortoche on 2026-11-24T14:51:13Z.


Claimed in the coordination issue as: RUNTIME-D3D12X-EXECUTE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135050832)

What and why

  1. D3D12.X Command Submission (CommandQueueX):

    • Implements ExecuteCommandListsX, wrapping ID3D12CommandQueue with extended metadata parsing and command list unwrapping.
    • Decouples CPU command dispatch from GPU completion by deferring D3D12 fence signaling until the Vulkan queue/fence actually retires, eliminating race conditions and premature CPU completion bugs.
  2. Multi-Segment Sync Point Splitting:

    • Vulkan queue submissions require splitting batches into multiple segments whenever intermediate synchronization points occur.
    • Implements automatic segment grouping, preserving wait/signal dependency ordering across command lists.
  3. Vulkan Presentation Swapchain:

    • Provides VulkanPresentationSwapchain with robust surface creation, format negotiation, and clean resource deallocation on window resize (preventing fence/semaphore leaks).
    • Includes automatic headless fallback when running in displayless or virtualized environments.
    • Releases presenter lock prior to invoking frame callbacks to eliminate lock reentrancy hazards.
  4. Empirical Regression & Stress Tests:

    • Implements runtime/test/d3d12_x_stress_test.cpp covering 9 comprehensive test cases: multi-threaded command recording, 64-list batch submissions, queue flushes, headless swapchain lifecycle, sync point placement, and resource leak regression checks.

Tested

  • Linux / GCC: CTest / CMake build target d3d12_x_stress_test passes 9/9 tests with 0 failures:
    • test_command_list_recording_stress: PASSED
    • test_command_list_concurrent_recording: PASSED
    • test_execute_command_lists_x_multiple_lists: PASSED
    • test_queue_flushes_and_frame_boundaries: PASSED
    • test_headless_presentation_swapchain: PASSED
    • test_headless_detection_environment: PASSED
    • test_bug_sync_point_wait_placement: PASSED
    • test_bug_premature_cpu_fence_signal: PASSED
    • test_bug_swapchain_resize_resource_leak: PASSED
  • Line endings compliant (newline="\n").
  • scripts/check_no_game_data.py: 0 violations.

AI-assisted: yes.

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • Portable subset builds cleanly under Linux.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474491462 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/869). Originally posted by [Tortoche](https://github.com/Tortoche) on 2026-11-24T14:51:13Z. --- Claimed in the coordination issue as: RUNTIME-D3D12X-EXECUTE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135050832) ### What and why 1. **D3D12.X Command Submission (`CommandQueueX`)**: - Implements `ExecuteCommandListsX`, wrapping `ID3D12CommandQueue` with extended metadata parsing and command list unwrapping. - Decouples CPU command dispatch from GPU completion by deferring D3D12 fence signaling until the Vulkan queue/fence actually retires, eliminating race conditions and premature CPU completion bugs. 2. **Multi-Segment Sync Point Splitting**: - Vulkan queue submissions require splitting batches into multiple segments whenever intermediate synchronization points occur. - Implements automatic segment grouping, preserving wait/signal dependency ordering across command lists. 3. **Vulkan Presentation Swapchain**: - Provides `VulkanPresentationSwapchain` with robust surface creation, format negotiation, and clean resource deallocation on window resize (preventing fence/semaphore leaks). - Includes automatic headless fallback when running in displayless or virtualized environments. - Releases presenter lock prior to invoking frame callbacks to eliminate lock reentrancy hazards. 4. **Empirical Regression & Stress Tests**: - Implements `runtime/test/d3d12_x_stress_test.cpp` covering 9 comprehensive test cases: multi-threaded command recording, 64-list batch submissions, queue flushes, headless swapchain lifecycle, sync point placement, and resource leak regression checks. ### Tested - Linux / GCC: CTest / CMake build target `d3d12_x_stress_test` passes 9/9 tests with 0 failures: - `test_command_list_recording_stress`: PASSED - `test_command_list_concurrent_recording`: PASSED - `test_execute_command_lists_x_multiple_lists`: PASSED - `test_queue_flushes_and_frame_boundaries`: PASSED - `test_headless_presentation_swapchain`: PASSED - `test_headless_detection_environment`: PASSED - `test_bug_sync_point_wait_placement`: PASSED - `test_bug_premature_cpu_fence_signal`: PASSED - `test_bug_swapchain_resize_resource_leak`: PASSED - Line endings compliant (`newline="\n"`). - `scripts/check_no_game_data.py`: 0 violations. AI-assisted: yes. ### Checklist - [x] Based on current main and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md). - [x] Portable subset builds cleanly under Linux.
abnalstlll-byte commented 2026-11-24 14:53:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:53:15Z.

Review: APPROVED


Audited and verified. Implements console D3D12.X command submission (ExecuteCommandListsX), resource state translation to Vulkan layouts/access flags, multi-segment submit planning with timeline semaphores, and Vulkan presentation swapchain with headless fallback. Deferral of fence signaling prevents premature CPU completion. Comprehensive test coverage in
untime/test/d3d12_x_stress_test.cpp. Clean-room compliant. Approved.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041546299 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/869#pullrequestreview-6041546299). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:53:15Z. **Review:** APPROVED --- Audited and verified. Implements console D3D12.X command submission (ExecuteCommandListsX), resource state translation to Vulkan layouts/access flags, multi-segment submit planning with timeline semaphores, and Vulkan presentation swapchain with headless fallback. Deferral of fence signaling prevents premature CPU completion. Comprehensive test coverage in untime/test/d3d12_x_stress_test.cpp. Clean-room compliant. Approved.
abnalstlll-byte commented 2026-11-24 14:54:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:54:00Z.

Review: APPROVED


Clean-Room Audit & Runtime Verification — PR #869 (D3D12.X / Vulkan Swapchain)

Massive step forward for command submission and Vulkan presentation!

Technical Verification

  1. Timeline Semaphores & Submission:
    • ExecuteCommandListsX translates resource states to Vulkan barrier stages and submits via multi-segment timeline semaphores.
    • Handles headless swapchain fallback gracefully.
  2. Clean-Room Compliance:
    • Conforms strictly to Vulkan 1.3 / D3D12 runtime contracts. 0 proprietary code.

Verdict: APPROVED

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041560166 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/869#pullrequestreview-6041560166). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:54:00Z. **Review:** APPROVED --- ### Clean-Room Audit & Runtime Verification — PR #869 (`D3D12.X / Vulkan Swapchain`) Massive step forward for command submission and Vulkan presentation! #### Technical Verification 1. **Timeline Semaphores & Submission**: - `ExecuteCommandListsX` translates resource states to Vulkan barrier stages and submits via multi-segment timeline semaphores. - Handles headless swapchain fallback gracefully. 2. **Clean-Room Compliance**: - Conforms strictly to Vulkan 1.3 / D3D12 runtime contracts. 0 proprietary code. **Verdict: APPROVED**
MoonEyes commented 2026-11-28 17:51:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:51:50Z.


Blocker: tests/test_docs_env_vars.py fails with this PR merged onto main: LEONIDA_HEADLESS is read in runtime/src/vulkan_device.cpp but documented in no .md. Could you add it to the docs page that lists the runtime variables?

Checked locally on main c1ecf04ed: the same test file(s) pass on main without this PR.

AI-assisted (Claude Code, Claude Opus 5.5), posted for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243346055 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/869#issuecomment-7243346055). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:51:50Z. --- Blocker: `tests/test_docs_env_vars.py` fails with this PR merged onto `main`: `LEONIDA_HEADLESS` is read in `runtime/src/vulkan_device.cpp` but documented in no `.md`. Could you add it to the docs page that lists the runtime variables? Checked locally on `main` c1ecf04ed: the same test file(s) pass on `main` without this PR. _AI-assisted (Claude Code, Claude Opus 5.5), posted for MoonEyes._
fiestorra commented 2026-11-30 08:36:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T08:36:26Z.


Independent verification on this machine (Windows 11, MSVC 19.44.35226): this pull request's new test target cannot compile, because it links the wrong dependencies for the sources it lists.

1. It applies. merge-tree clean; the commit cherry-picks onto main e236b19c6 without a conflict.

2. Building its target:

cmake --build runtime/build-ninja --target d3d12_x_stress_test
src/vulkan_device.h(26): fatal error C1083: Cannot open include file: 'vulkan/vulkan.h': No such file or directory

3. The cause is in the registration the PR adds:

add_executable(d3d12_x_stress_test
  test/d3d12_x_stress_test.cpp
  shims/d3d12_x.cpp
  src/vulkan_device.cpp          # <- includes <vulkan/vulkan.h>
  src/vulkan_presenter.cpp
)
target_link_libraries(d3d12_x_stress_test PRIVATE Threads::Threads)
if(NOT WIN32)
  target_link_libraries(d3d12_x_stress_test PRIVATE dl)
endif()
add_test(NAME d3d12_x_stress COMMAND d3d12_x_stress_test)

It compiles src/vulkan_device.cpp, which includes <vulkan/vulkan.h>, but never links Vulkan::Headers - the dependency the neighbouring targets carry (target_link_libraries(d3d12_compute_test PRIVATE gta6rt_d3d12_com) and the Vulkan target elsewhere). Threads::Threads and dl do not provide the include path.

The fix is one line, next to the other target_link_libraries:

target_link_libraries(d3d12_x_stress_test PRIVATE Vulkan::Headers)

What I could not test: anything the test does. The target has never linked on this machine, so its assertions have never run.

How it was found: sweeping the open pull requests that replay onto current main, building each one's test targets through ctest --show-only=json-v1 to get the names, and running them. Of the 25 in this batch, this is the only one that does not build.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7273115260 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/869#issuecomment-7273115260). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T08:36:26Z. --- Independent verification on this machine (Windows 11, MSVC 19.44.35226): **this pull request's new test target cannot compile, because it links the wrong dependencies for the sources it lists.** **1. It applies.** `merge-tree` clean; the commit cherry-picks onto `main` `e236b19c6` without a conflict. **2. Building its target:** ``` cmake --build runtime/build-ninja --target d3d12_x_stress_test src/vulkan_device.h(26): fatal error C1083: Cannot open include file: 'vulkan/vulkan.h': No such file or directory ``` **3. The cause is in the registration the PR adds:** ```cmake add_executable(d3d12_x_stress_test test/d3d12_x_stress_test.cpp shims/d3d12_x.cpp src/vulkan_device.cpp # <- includes <vulkan/vulkan.h> src/vulkan_presenter.cpp ) target_link_libraries(d3d12_x_stress_test PRIVATE Threads::Threads) if(NOT WIN32) target_link_libraries(d3d12_x_stress_test PRIVATE dl) endif() add_test(NAME d3d12_x_stress COMMAND d3d12_x_stress_test) ``` It compiles `src/vulkan_device.cpp`, which includes `<vulkan/vulkan.h>`, but **never links `Vulkan::Headers`** - the dependency the neighbouring targets carry (`target_link_libraries(d3d12_compute_test PRIVATE gta6rt_d3d12_com)` and the Vulkan target elsewhere). `Threads::Threads` and `dl` do not provide the include path. **The fix is one line**, next to the other `target_link_libraries`: ```cmake target_link_libraries(d3d12_x_stress_test PRIVATE Vulkan::Headers) ``` **What I could not test:** anything the test does. The target has never linked on this machine, so its assertions have never run. **How it was found:** sweeping the open pull requests that replay onto current `main`, building each one's test targets through `ctest --show-only=json-v1` to get the names, and running them. Of the 25 in this batch, **this is the only one that does not build**. Written with an AI assistant.
aslan2142 commented 2026-12-01 16:32:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:32:30Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317777321 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/869#issuecomment-7317777321). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:32:30Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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!869
No description provided.