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

Closed
leonida/mandy
Tortoche wants to merge 0 commits from feat/d3d12x-execute-command-lists into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

Tortoche commented 2026-11-24 14:51:13 +00:00

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.
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 approved these changes 2026-11-24 14:53:15 +00:00
abnalstlll-byte left a comment

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.

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 approved these changes 2026-11-24 14:54:00 +00:00
abnalstlll-byte left a comment

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

### 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

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.

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

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.

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

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.

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.
Sign in to join this conversation.
No description provided.