Address guard: share the page-table buffer across queue families (RT-ADDRESS-GUARD-QUEUE-SHARING) #2527
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2527"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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-guardread through its device address. Those shaders run on the direct and the async-compute queue, but the buffer was created withVK_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 throughDeviceState::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 withfamilies. Nothing else changes.Tested
address_guard_buffer_test(CPU only, no device): two families giveVK_SHARING_MODE_CONCURRENTwith both indices; one family stays exclusive; size and usage are the old ones.gta6rt_d3d12_com(which buildsd3d12_vulkan_device.cpp) builds with MSVC 17, Release; no new warnings.GPUs tested: n/a (CPU test).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T01:34:07Z.
Reviewed at head
f06577169on Windows 11 (MSVC 202219.44).Verification
address_guard_buffer_testandgta6rt(confirmingd3d12_vulkan_device.cppcompiles cleanly with the change).address_guard_buffer_test: ok.Notes
vkCreateBuffer, keepingVK_SHARING_MODE_EXCLUSIVE(count 0, null pointer) for a single distinct family andVK_SHARING_MODE_CONCURRENTwhen 2+ distinct families exist, with the family array outlivingvkCreateBuffer(d3d12_vulkan_device.cpp:15043-15045,address_guard_buffer.h:14-20,queue_families.h:28-36).Approve.
AI-assisted review + local MSVC verification.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:18:21Z.
#2527 | head
f06577169c(merged cleanly with main09c1539483) |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.cppfails to compile (C1083: missingaddress_guard_buffer.h; onmain,DeviceStatecreatedguard.bufferwithVK_SHARING_MODE_EXCLUSIVEeven when graphics and async-compute queues live on distinct queue families) | green on PR+main:3/3CTests pass (address_guard_bufferin0.07s,address_guardin0.26s, andd3d12_inner_coverage_guardson RTX 3090 in0.62swithLEONIDA_VK_VALIDATION=1and0Khronos validation errors);check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesImported 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.hwith dedicated unit coverage inaddress_guard_buffer_test.cppis clean and well scoped.Tests run
ctest --output-on-failure -R "^address_guard_buffer$": 1/1 passed (address_guard_buffer0.02 s).AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T01:08:07Z.
Review: COMMENTED
Reviewed head
f06577169and found no issues.runtime/shims/d3d12_vulkan_device.cpp:15043collects the graphics, compute, and copy family indices before guard initialization, skips absent families, and removes duplicates. The resulting device-owned array stays valid throughvkCreateBufferatruntime/shims/d3d12_vulkan_device.cpp:6569.runtime/src/address_guard_buffer.h:14andruntime/src/queue_families.h:28select 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:14exercises 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:2409builds the CPU test with C++20 and Vulkan headers on Windows and Linux, with MSVC options gated onMSVC. 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.
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T05:58:24Z.
Tested
f06577169merged (no commit) withmainc8bf0e7b6. 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.pyis clean.address_guard_bufferpasses.address_guard_buffer.handd3d12_vulkan_device.cppback tomain, the test does not compile (the header is new). For a runtime red, I kept the header and cutshare_across_queue_families(create, families);fromtable_buffer_info. The test then fails withline 20: shared.sharingMode == VK_SHARING_MODE_CONCURRENT.d3d12_vulkan_device.cppcall site keeps it green.xbox_presentfails, as on plainmainhere.gta6rt.exelinked withoutws2_32.libgivesmain's 26 unresolved Rust-std symbols, nothing new. Its imports are identical tomain's.runtime/CMakeLists.txt. Each adds a test block right afteradd_test(NAME vulkan_scratch ...). These are add/add conflicts: keep both blocks.No blocker from my side. AI-assisted (Claude Code).
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.exestill links) and a re-check here: no conflict withmain451afe327, same head as checked, not frozen,no-game-datagreen.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.