Skip to content

d3d12, process: null barrier arrays, CopyTiles in a bundle, calibration wait, entry thread argument, getmainargs expand (RT-COM-NULL-BARRIERS-ENTRY) - #2522

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-com-null-barriers-entry
Nov 29, 2026

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-COM-NULL-BARRIERS-ENTRY (#1608 (comment))

What and why

Item 4 of @kevincommits' finding in #1608 (#1608 (comment)). Thanks for the line-by-line report.

runtime/shims/d3d12_com.cpp:

  • ResourceBarrier: count > 0 with a null barriers read through null. It now fails the list (check(false), so Close returns E_INVALIDARG), as WriteBufferImmediate already does.
  • Barrier: the same for groups > 0 with a null group, and for a group with NumBarriers > 0 and no barrier array. The three array pointers of D3D12_BARRIER_GROUP are one union, so one check covers every type. A count of 0 still needs no array.
  • CopyTiles: a bundle was refused only on the sparse-image path; a reserved buffer recorded a copy into the bundle. The check now comes first, as in CopyBufferRegion and CopyTextureRegion: no copy is allowed in a bundle.
  • submitted_calibration: vkGetQueryPoolResults now passes VK_QUERY_RESULT_WAIT_BIT with VK_QUERY_RESULT_64_BIT, as labels: GPU timestamps wait for their query, others record none, store unlocked (RT-GPU-LABEL-COMPLETIONS) #2504 did for the GPU labels. The queue is waited idle before the read, so this is a guard against VK_NOT_READY rather than a change measured here.

runtime/shims/process.cpp:

  • run_entry: the game thread got &call, a struct on run_entry's stack. If another thread ended the run (end_run) before the game thread first ran, run_entry returned and the game thread then read a dead frame. The entry point itself is now the thread's parameter; nothing of run_entry's frame is read.
  • __getmainargs / __wgetmainargs: expand (the CRT's _dowildcard) was ignored. A nonzero value now expands wildcards (mode 2, as _configure_narrow_argv/_configure_wide_argv do), and a null argc or argv returns -1 instead of being written through.

Overlap: #841 and #2492 change other parts of d3d12_com.cpp (bundle DispatchMesh, ExecuteIndirect), not these lines. #1564 changes the start and end of run_entry (exit-handler clearing and the cleanup lock), not the thread's argument; if one lands first the other may need a small rebase. #2405 and pepefroge's VULKAN-COPY-TILES-ALIGN claim touch the sparse and readback side of tile copies, not the bundle check.

Tested

Windows 11, MSVC (VS 18), RelWithDebInfo, on main d442851. Short GPU tests only (the d3d12 tests need a Vulkan device), no game boot.

  • d3d12_com_test, new direct-list cases:
    • ResourceBarrier(1, nullptr), Barrier(1, nullptr), and a group of each type with one barrier and no array (alone, and after a valid group) fail Close with E_INVALIDARG;
    • ResourceBarrier(0, nullptr), Barrier(0, nullptr), a group with no barriers and no array, and a valid transition close with S_OK.
  • d3d12_buffer_tiles_test (layer half): CopyTiles of a reserved buffer recorded in a bundle fails the bundle's Close. The same call on a direct list is the existing case that follows.
  • process_cmdline_test: the command line <temp folder>\*.lx with two synthetic files there gives argc 3 with expand=1 and 2 (the pattern as typed) with expand=0, narrow and wide. A null argc or argv fails.
  • With main's d3d12_com.cpp and process.cpp and the new tests, all three fail: d3d12_com and process_cmdline crash (segfault on the null arrays and pointers), process_cmdline also reports argc 2, want 3 for expand=1, and d3d12_buffer_tiles fails at the bundle's Close.
  • ctest -R "^(d3d12_com|d3d12_buffer_tiles|process_cmdline|d3d12_bundle|d3d12_bundle_forbidden|d3d12_texture_tiles|d3d12_mesh)$": 7/7 pass with the fix.
  • scripts/check_no_game_data.py: clean.

Not tested: the run_entry race has no test (it needs another thread to end the run before the game thread is scheduled). The change removes the stack pointer, so there is nothing left to race on. The calibration path needs a device without calibrated timestamps, which this one has.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…on wait, entry thread and getmainargs expand

From kevincommits' finding (item 4) in ProjectLeonida#1608.

- d3d12_com.cpp:
  - ResourceBarrier: a count with no array fails the list (check(false)) instead
    of reading through null, as WriteBufferImmediate does.
  - Barrier: the same for a null group array, and for a group with barriers but
    no barrier array (the three array pointers are one union).
  - CopyTiles: a bundle is refused for reserved buffers too, not only for sparse
    images; no copy is allowed in a bundle.
  - submitted_calibration: vkGetQueryPoolResults asks VK_QUERY_RESULT_WAIT_BIT,
    so the read cannot answer VK_NOT_READY.
- process.cpp:
  - run_entry passes the entry point itself to the game thread instead of a
    pointer to its own stack: another thread can end the run before the game
    thread first runs, and run_entry's frame is then gone.
  - __getmainargs/__wgetmainargs expand wildcards when `expand` is nonzero
    (mode 2, as _configure_*_argv does) and fail on a null argc or argv.

Tests: d3d12_com_test (null arrays fail Close; counts of 0 and valid calls
do not), d3d12_buffer_tiles_test (CopyTiles of a reserved buffer in a bundle
fails Close), process_cmdline_test (expand 0 and 1, null argc/argv).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timbot103

Copy link
Copy Markdown
Contributor

Reviewed at head d411fe9b4 on Windows 11 (MSVC 2022 19.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363.0).

Verification

  • Built process_cmdline_test, d3d12_com_test, d3d12_buffer_tiles_test, and gta6rt.
  • process_cmdline_test: passed.
  • d3d12_com_test (LEONIDA_VK_VALIDATION=1): passed with 0 validation errors on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02).
  • d3d12_buffer_tiles_test (LEONIDA_VK_VALIDATION=1): passed with 0 validation errors on both RTX 5080 and AMD Radeon.

Notes (non-blocking)

  • Null barrier-array checks, CopyTiles bundle rejection ahead of both paths, calibration wait before query read, passing the entry address by value to the thread proc, and honoring the wildcard expansion flag for both CRT widths all look sound.
  • d3d12_com.cpp:633: checking group[g].pGlobalBarriers for all three barrier types works on the Windows pointer ABI, though reading the active union member selected by group[g].Type avoids relying on inactive-union-member reads in standard C++.
  • d3d12_com_test.cpp:365-370: EXPECT(!invalid_direct_call(...)) passes if allocator/list creation fails or if Close() returns any error other than E_INVALIDARG; asserting S_OK directly on the positive controls would make those checks stricter.
  • process_cmdline_test.cpp:237-251: the narrow wildcard check assumes the absolute temp path round-trips through the host ANSI code page (an ASCII relative pattern under the fixture directory avoids locale sensitivity).

Approve.

AI-assisted review + local MSVC/dual-GPU verification.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2522 | head d411fe9 (merged cleanly with main 09c1539) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(process_cmdline|d3d12_com|d3d12_buffer_tiles)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: process_cmdline_test fails (__getmainargs/__wgetmainargs ignore expand=1) and crashes with 0xC0000005 on null argc/argv; d3d12_com_test crashes with 0xC0000005 on ResourceBarrier(1, nullptr) / Barrier(1, nullptr); d3d12_buffer_tiles_test fails (bundle->Close() == E_INVALIDARG on CopyTiles in a bundle) | green on PR+main: 3/3 CTests pass (process_cmdline, d3d12_com in 0.47s, and d3d12_buffer_tiles in 1.41s) on RTX 3090 with LEONIDA_VK_VALIDATION=1 (0 Khronos validation errors); check_no_game_data.py 0 violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

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

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC) and LEONIDA_VK_VALIDATION=1.

The null barrier array guards, early CopyTiles bundle rejection, VK_QUERY_RESULT_WAIT_BIT on calibration readback, direct entry-point thread argument in run_entry (removing the stack-frame race), and __getmainargs/__wgetmainargs wildcard expansion + null checks are all clean and well-tested.

Tests run

  • ctest --output-on-failure -R "^(d3d12_com|d3d12_buffer_tiles|process_cmdline)$" (with LEONIDA_VK_VALIDATION=1): 3/3 passed (process_cmdline, d3d12_com 0.28 s, d3d12_buffer_tiles 1.53 s).

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341, VK_LAYER_KHRONOS_validation 1.4.363).

AI-assisted (Antigravity, Gemini).

@enlight3d

Copy link
Copy Markdown
Contributor

RUN (Windows 11, red/green)

Tested heads: PR head d411fe9b4a3aab2a75dfbed4d6e4f01d758ef668 (one commit on d44285197); main at 1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3. git merge-tree --write-tree main pr-2522 merges cleanly.

Machine: Windows 11 Pro 10.0.26300, MSVC 14.44 (VS 2022 Build Tools), RelWithDebInfo, Ninja, 8 jobs. GPU NVIDIA GeForce RTX 3090 24 GB, driver 621.40.

Commands (only the three test targets and their dependencies were built, not the whole runtime):

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSDL3_DIR=<SDL3 3.4.20 static>/cmake -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build --target d3d12_com_test d3d12_buffer_tiles_test process_cmdline_test -j 8
ctest --test-dir runtime/build -R "^(d3d12_com|d3d12_buffer_tiles|process_cmdline)$" --output-on-failure

GREEN (PR head): process_cmdline, d3d12_com, d3d12_buffer_tiles: 3/3 passed.

RED (behavioural): PR head with only runtime/shims/d3d12_com.cpp and runtime/shims/process.cpp put back to the parent commit's version, the three test files kept; rebuilt the same three targets and ran the same ctest: 0/3 passed.

  • process_cmdline: SEGFAULT, and before the crash "FAIL __getmainargs(expand=1): argc 2, want 3" and the same for __wgetmainargs.
  • d3d12_com: SEGFAULT (null barrier arrays read through).
  • d3d12_buffer_tiles: FAILED, "line 126: bundle->Close() == E_INVALIDARG" (CopyTiles of a reserved buffer in a bundle).
    This matches the PR description. Not covered by a test, as the PR says: the run_entry thread argument and the calibration wait. I ran only these three tests, not the other six in the PR's ctest list.
    Link check: merged into main 1bc055e, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.

@MoonEyes
MoonEyes merged commit 5c8a9de into ProjectLeonida:main Nov 29, 2026
6 of 12 checks passed
@MoonEyes

Copy link
Copy Markdown
Collaborator

Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and gta6rt.exe still links) and a re-check here: no conflict with main 106e261, same head as run, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).

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

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