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

Merged
Tyrannys merged 1 commit from upstream-pr/2527 into main 2026-11-29 08:20:04 +00:00
Tyrannys commented 2026-11-28 00:42:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T00:42:31Z.


Claimed in the coordination issue as: RT-ADDRESS-GUARD-QUEUE-SHARING (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231125400). Found by @kevincommits, item 4 of https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285. 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

  • 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.
  • Overlap checked: #2489 shares other buffers (depth24 scratch, device markers), not this one.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5535035263 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T00:42:31Z. --- Claimed in the coordination issue as: RT-ADDRESS-GUARD-QUEUE-SHARING (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231125400). Found by @kevincommits, item 4 of https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285. 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] Overlap checked: #2489 shares other buffers (depth24 scratch, device markers), not this one. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timbot103 commented 2026-11-28 01:34:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T01:34:07Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231759151 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527#issuecomment-7231759151). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T01:34:07Z. --- 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 commented 2026-11-28 07:18:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:18:21Z.


#2527 | head f06577169c (merged cleanly with main 09c1539483) | 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7235848703 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527#issuecomment-7235848703). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T07:18:21Z. --- #2527 | head f06577169c4052e6363256896a9b46eb98ffa10f (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | `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 commented 2026-11-28 08:51:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T08:51:53Z.

Review: APPROVED


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6096839565 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527#pullrequestreview-6096839565). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T08:51:53Z. **Review:** APPROVED --- 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 commented 2026-11-29 01:08:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T01:08:07Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6100846163 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527#pullrequestreview-6100846163). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T01:08:07Z. **Review:** COMMENTED --- 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 commented 2026-11-29 05:58:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T05:58:24Z.


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.

  • Green: address_guard_buffer passes.
  • Red: with address_guard_buffer.h and d3d12_vulkan_device.cpp back to main, the test does not compile (the header is new). For a runtime red, I kept the header and cut share_across_queue_families(create, families); from table_buffer_info. The test then fails with line 20: shared.sharingMode == VK_SHARING_MODE_CONCURRENT.
  • Note: the test covers the helper only. Reverting only the d3d12_vulkan_device.cpp call site keeps it green.
  • No regression: the merge rebuilds 180 executables. Of their 287 other tests, only xbox_present fails, as on plain main here.
  • LINK: gta6rt.exe linked without ws2_32.lib gives main's 26 unresolved Rust-std symbols, nothing new. Its imports are identical to main's.
  • Merge order: it conflicts with #2466, #1988 and #1836 in runtime/CMakeLists.txt. Each adds a test block right after add_test(NAME vulkan_scratch ...). These are add/add conflicts: keep both blocks.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7251568872 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527#issuecomment-7251568872). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T05:58:24Z. --- 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. - Green: `address_guard_buffer` passes. - Red: with `address_guard_buffer.h` and `d3d12_vulkan_device.cpp` back to `main`, the test does not compile (the header is new). For a runtime red, I kept the header and cut `share_across_queue_families(create, families);` from `table_buffer_info`. The test then fails with `line 20: shared.sharingMode == VK_SHARING_MODE_CONCURRENT`. - Note: the test covers the helper only. Reverting only the `d3d12_vulkan_device.cpp` call site keeps it green. - No regression: the merge rebuilds 180 executables. Of their 287 other tests, only `xbox_present` fails, as on plain `main` here. - LINK: `gta6rt.exe` linked without `ws2_32.lib` gives `main`'s 26 unresolved Rust-std symbols, nothing new. Its imports are identical to `main`'s. - Merge order: it conflicts with #2466, #1988 and #1836 in `runtime/CMakeLists.txt`. Each adds a test block right after `add_test(NAME vulkan_scratch ...)`. These are add/add conflicts: keep both blocks. No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 08:20:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T08:20:06Z.


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 451afe327, same head as checked, not frozen, no-game-data green.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253037296 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2527#issuecomment-7253037296). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T08:20:06Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/2527#issuecomment-7251568872): green with this PR merged onto `main`, red without it; `gta6rt.exe` still links) and a re-check here: no conflict with `main` 451afe327, same head as checked, not frozen, `no-game-data` green. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!2527
No description provided.