Skip to content

Address guard: share the page-table buffer across queue families (RT-ADDRESS-GUARD-QUEUE-SHARING) - #2527

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
Tyrannys:claude/address-guard-sharing
Nov 29, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
Tyrannys:claude/address-guard-sharing

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-ADDRESS-GUARD-QUEUE-SHARING (#1608 (comment)). Found by @kevincommits, item 4 of #1608 (comment). Thanks!

What and why

With LEONIDA_ADDRESS_GUARD, DeviceState::create_address_guard() creates the page table that shaders translated with --address-guard read through its device address. Those shaders run on the direct and the async-compute queue, but the buffer was created with VK_SHARING_MODE_EXCLUSIVE. That is the same class of bug as #2489: on a device with more than one queue family, a buffer one family owns is used by another without an ownership transfer. The other buffers every queue reads are shared through DeviceState::share (share_across_queue_families).

Fix. A small header, runtime/src/address_guard_buffer.h, builds the create info (address_guard::table_buffer_info): storage plus device address, shared by the device's queue families (concurrent on two or more, exclusive on one). create_address_guard() uses it with families. Nothing else changes.

Tested

  • New address_guard_buffer_test (CPU only, no device): two families give VK_SHARING_MODE_CONCURRENT with both indices; one family stays exclusive; size and usage are the old ones.
  • gta6rt_d3d12_com (which builds d3d12_vulkan_device.cpp) builds with MSVC 17, Release; no new warnings.
  • Not run on a GPU: the address guard is an opt-in diagnostic, and a boot is using this machine's GPU.

GPUs tested: n/a (CPU test).

AI-assisted: yes (Claude Code)

Checklist

🤖 Generated with Claude Code

create_address_guard() made the page table that shaders translated with
--address-guard read through its device address with
VK_SHARING_MODE_EXCLUSIVE, though those shaders run on the direct and
the async-compute queue. The other buffers every queue reads are shared
by the device's queue families (DeviceState::share).

The create info now comes from address_guard::table_buffer_info(), which
shares it the same way (concurrent on two or more families, exclusive on
one), with a CPU test.

Found by kevincommits (ProjectLeonida#1608).

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

Copy link
Copy Markdown
Contributor

Reviewed at head f06577169 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built address_guard_buffer_test and gta6rt (confirming d3d12_vulkan_device.cpp compiles cleanly with the change).
  • address_guard_buffer_test: ok.

Notes

  • Queue-family collection deduplicates and filters absent graphics/compute/copy families before vkCreateBuffer, keeping VK_SHARING_MODE_EXCLUSIVE (count 0, null pointer) for a single distinct family and VK_SHARING_MODE_CONCURRENT when 2+ distinct families exist, with the family array outliving vkCreateBuffer (d3d12_vulkan_device.cpp:15043-15045, address_guard_buffer.h:14-20, queue_families.h:28-36).
  • Side note (pre-existing, orthogonal to this PR): concurrent sharing resolves queue-family ownership, while host updates to page-table words that an earlier in-flight GPU submission may still read remain a separate memory-ordering question.

Approve.

AI-assisted review + local MSVC verification.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2527 | head f065771 (merged cleanly with main 09c1539) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(address_guard_buffer|address_guard|d3d12_inner_coverage_guards)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: address_guard_buffer_test.cpp fails to compile (C1083: missing address_guard_buffer.h; on main, DeviceState created guard.buffer with VK_SHARING_MODE_EXCLUSIVE even when graphics and async-compute queues live on distinct queue families) | green on PR+main: 3/3 CTests pass (address_guard_buffer in 0.07s, address_guard in 0.26s, and d3d12_inner_coverage_guards on RTX 3090 in 0.62s with LEONIDA_VK_VALIDATION=1 and 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).

Extracting the address guard buffer logic into address_guard_buffer.h with dedicated unit coverage in address_guard_buffer_test.cpp is clean and well scoped.

Tests run

  • ctest --output-on-failure -R "^address_guard_buffer$": 1/1 passed (address_guard_buffer 0.02 s).

AI-assisted (Antigravity, Gemini).

@timbot103 timbot103 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 head f06577169 and found no issues. runtime/shims/d3d12_vulkan_device.cpp:15043 collects the graphics, compute, and copy family indices before guard initialization, skips absent families, and removes duplicates. The resulting device-owned array stays valid through vkCreateBuffer at runtime/shims/d3d12_vulkan_device.cpp:6569. runtime/src/address_guard_buffer.h:14 and runtime/src/queue_families.h:28 select concurrent sharing only for two or more distinct families, so guarded shaders on the graphics and async-compute families can read the page table without an ownership transfer. A single family gets exclusive sharing with a zero count and null pointer.

runtime/test/address_guard_buffer_test.cpp:14 exercises the production helper and would catch an exclusive create-info result for two families. It also checks the single-family fallback, buffer size, and usage flags. runtime/CMakeLists.txt:2409 builds the CPU test with C++20 and Vulkan headers on Windows and Linux, with MSVC options gated on MSVC. The test covers buffer creation parameters. Cross-family shader execution remains unverified by this audit.

Static audit only. No builds, tests, or GPU runs were performed.

AI-assisted.

@TheGeogeo

Copy link
Copy Markdown
Contributor

Tested f06577169 merged (no commit) with main c8bf0e7b6. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. check_no_game_data.py is clean.

No blocker from my side. AI-assisted (Claude Code).

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

Copy link
Copy Markdown
Collaborator

Merged after TheGeogeo's red/green check (check: green with this PR merged onto main, red without it; gta6rt.exe still links) and a re-check here: no conflict with main 451afe3, same head as checked, not frozen, no-game-data green.

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