Skip to content

vulkan: depth24 scratch and the device marker buffer are shared across queue families (RT-QUEUE-FAMILY-SHARING-DEPTH24-MARKERS) - #2489

Open
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-queue-family-sharing-depth24-markers
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-queue-family-sharing-depth24-markers

Conversation

@Tyrannys

@Tyrannys Tyrannys commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-QUEUE-FAMILY-SHARING-DEPTH24-MARKERS (#1608 (comment))

What and why

Items 1 and 2 of @kevincommits' finding in #1608 (#1608 (comment)). Thanks for the audit.

The device's other shared pools get state_.families and call share_across_queue_families: ScratchBuffers, IndirectArgumentClamp and BindlessSet. Two buffers that every queue uses were still VK_SHARING_MODE_EXCLUSIVE, with no queue-family ownership transfer. On a GPU with separate graphics, async-compute and copy families, that use is invalid (Vulkan "Resource Sharing Mode").

  1. Depth24Converter scratch chunks (vulkan_depth24.h).
  2. The LEONIDA_DEVICE_MARKERS buffer (vulkan_device_markers.h).
    • Every queue writes its own slot with vkCmdWriteBufferMarker[2]AMD.
    • configure_device_fault, DeviceFaultDiagnostics and DeviceMarkers::create now take the families, and the buffer is shared across them.

The new parameters are optional and default to no families. With one family, or none given, both buffers stay EXCLUSIVE, as before (share_across_queue_families needs two or more). Callers and tests that construct these classes directly are unchanged.

Separate from #2469 (the depth24 barriers on a copy queue). This PR does not depend on it. Overlap, checked with git merge-tree:

Not included: the early return before the query pool is destroyed in depth24_convert_test.cpp, which kevincommits also noted. That file is #2469's.

Tested

Windows 11, MSVC (VS 18), RelWithDebInfo, on main 43a9d56.

  • New depth24_scratch_sharing_test (CPU, faked driver). prepare() makes one scratch chunk, and its VkBufferCreateInfo is checked:

    • families {0, 1, 2} and {0, 2}: CONCURRENT over them;
    • {0} and none: EXCLUSIVE.

    With main's vulkan_depth24.h the converter has no families parameter, so the test does not compile. With only the parameter threaded through and make_chunk left as on main, it fails on the first case.

  • vulkan_device_markers_test gains queue_family_sharing. Through DeviceFaultDiagnostics and through DeviceMarkers::create, the marker buffer is CONCURRENT over {0, 1, 2}, {0, 2} and {3, 1}, and EXCLUSIVE with {0}. With make_chunk's and create's EXCLUSIVE lines as on main, the new checks fail.

  • ctest -R "^(depth24_scratch_sharing|vulkan_device_markers|vulkan_device_fault|depth24_convert|vk_device_markers|vk_semaphore_lifetime|d3d12_depth24_draw)$": 7/7 pass. The GPU tests among them (depth24_convert, vk_device_markers, vk_semaphore_lifetime, d3d12_depth24_draw) run on the RTX 4070 SUPER, which has separate graphics, compute and transfer families; together they take about 12 s.

  • scripts/check_no_game_data.py: clean.

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

…ue families

The depth24 converter's scratch chunks are reused by copies on every D3D12 queue (direct, compute and
compute-backed copy). Every queue writes the LEONIDA_DEVICE_MARKERS buffer. Both were created
VK_SHARING_MODE_EXCLUSIVE and used by several queue families with no ownership transfer.

They now take the device's distinct queue families and call share_across_queue_families, as
ScratchBuffers, IndirectArgumentClamp and BindlessSet do. With two or more families a buffer is
CONCURRENT; otherwise it stays EXCLUSIVE, as before.

From kevincommits' finding in ProjectLeonida#1608 (items 1 and 2). A new CPU test, depth24_scratch_sharing_test, and a
new queue_family_sharing case in vulkan_device_markers_test check the create infos with a faked driver.

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

@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 9df6b03cc (vulkan_depth24.h, vulkan_device_markers.h, vulkan_device_fault.h, vulkan_backend.h, d3d12_vulkan_device.cpp, tests) and tested:

  • Passing state_.families into enable_depth24 and configure_device_fault -> DeviceMarkers::create and applying share_across_queue_families cleanly matches ScratchBuffers, IndirectArgumentClamp, and BindlessSet for multi-family devices (while keeping VK_SHARING_MODE_EXCLUSIVE when there is only one family).
  • Tested on Windows 11 (MSVC 19.44): vulkan_device_markers passed (0.04 s) and depth24_scratch_sharing passed (0.03 s).

Looks good to merge.

AI-assisted (Antigravity, Gemini).

@timbot103

Copy link
Copy Markdown
Contributor

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

Verification

  • Built depth24_scratch_sharing_test, vulkan_device_markers_test, and gta6rt.
  • depth24_scratch_sharing_test: passed.
  • vulkan_device_markers_test: passed.

Notes

  • Deduplicating direct/compute/copy queue families, skipping absent-family sentinels, and switching VK_SHARING_MODE_EXCLUSIVE vs VK_SHARING_MODE_CONCURRENT cleanly satisfies VkBufferCreateInfo sharing rules for both the depth24/RGB96 scratch pool and the AMD device-marker buffer (d3d12_vulkan_device.cpp:14601-15054, vulkan_depth24.h:153-174, vulkan_device_markers.h:171-212).

Approve.

AI-assisted review + local MSVC verification.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@Tyrannys — thanks for catching the MSVC C2397 in our marker test. I checked 9df6b03cc merged with 2d4735682 on physical gfx906 / RADV Mesa 26.0.8, then tested that tree with ccaad2dd added.

Sharing works on two real queue families. I recorded the create infos passed to the driver: both the marker buffer and converter-owned depth scratch stayed EXCLUSIVE for one family. For families 0 and 1, main still created both as EXCLUSIVE; #2489 created both as CONCURRENT over exactly those two families. I did not submit cross-family work on the exclusive main buffers.

On both the PR merge and the combination, graphics family 0 converted 64 D24 words into scratch; family 1 copied the float payload and converted it back using the same retired/reused scratch handle and range. 64/64 float words and 64/64 returned D24 words matched, and each queue’s own marker pair read back correctly. The copy used the compute-capable family, not a third DMA family. Zero Khronos validation errors or sync hazards in this cross-family check.

Separate same-slot regression: depth24_scratch_sharing (mock create-info checks), the CPU marker tests, depth24_convert and vk_semaphore_lifetime passed. The stock vk_device_markers CTest uses a single family: main and #2489 alone both reported 10 write-after-write hazards (the layer’s cap) despite correct readbacks. With ccaad2dd, the marker CTest passed with zero validation errors on the legacy and synchronization2 marker paths, reading 5/5 then 8/8. Queue-family sharing and ordering repeated writes are distinct fixes.

AI-assisted.

@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 9df6b03cc. In runtime/shims/d3d12_vulkan_device.cpp, both buffer creation paths receive the deduplicated list of configured queue families. The helper in runtime/src/queue_families.h selects concurrent sharing with two or more families and leaves the create info exclusive with zero or one. The family arrays stay alive through each vkCreateBuffer call in runtime/src/vulkan_depth24.h and runtime/src/vulkan_device_markers.h.

I traced scratch retirement and reuse in runtime/src/vulkan_backend.h, the transfer and compute barriers in runtime/src/vulkan_replay.h, and marker writes to per-queue slots in runtime/src/vulkan_device_fault.h. The CPU tests in runtime/test/depth24_scratch_sharing_test.cpp and runtime/test/vulkan_device_markers_test.cpp check multi-family create infos and the exclusive fallback. I reviewed their CMake registration for Windows and Linux.

Static audit only. No builds, tests, or GPU runs performed as part of this review. No findings.

AI-assisted.

@TheGeogeo

Copy link
Copy Markdown
Contributor

Tested 9df6b03 merged (no commit) with main 8fb9748: MSVC 19.52, Windows 11 10.0.26300.
GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40.

  • Green: vulkan_device_markers and depth24_scratch_sharing pass. The 295 relinked CTests pass, except xbox_present, which fails on main too (its resize case).
  • Red: with the five non-test files back to main, the tests do not compile (vulkan_device_markers_test.cpp(303): C2661, no DeviceFaultDiagnostics constructor takes 6 arguments). No runtime red was shown here, because the test needs the new parameter.
  • gta6rt links with nothing new over main: no new unresolved symbol, same imports.
  • Merge order: conflicts with vulkan_device_markers: clamp memoryTypeCount, guard null proc/target and unmap #2308 (runtime/src/vulkan_device_markers.h and its test). Whichever lands second needs a rebase.
  • No game data check passes.

AI-assisted (Claude Code).

@ammonium231

Copy link
Copy Markdown
Contributor

RTX 3090 (621.40), validation on: 9df6b03 merged onto main 4364a4f, 7/7 of the PR's depth24/marker/fault/semaphore ctest set pass, 0 validation errors. Plain main: the same 6 pre-existing tests pass.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent native Linux cross-family check of 9df6b03cc merged onto 878b024f4 (tree 75e9d6379), extending the earlier two-family RADV check to a dedicated transfer family. CachyOS, clang 23.1.5, RTX 4070 SUPER / NVIDIA 620.73.04 and Radeon 610M / RADV Mesa 26.3.1. Khronos validation 1.4.363, including synchronization validation.

  • Depth24 scratch reuse: A 16×16 synthetic dispatch ran on graphics, then a different pattern ran on compute after retiring and collecting the first batch. The fixture observed exactly one converter scratch allocation and verified the same VkBuffer in both batches. On NVIDIA, sharing covered graphics/compute/transfer 0/2/1; the second readback followed a compute-to-transfer semaphore handoff and ran on family 1. RADV used 0/1/1, with sharing over the two distinct families. Both patterns matched all 256 reference words on both GPUs, with zero validation errors.
  • EXCLUSIVE control: The same fixture with no sharing families supplied still matched the first batch on graphics, then rejected the second-family use before submission.
  • Device markers: The stock marker test passed with sync validation on both plain main and the PR. A variant using distinct graphics and compute queues on the PR left the graphics marker slot at 5/5 and the compute slot at 8/8 on both GPUs, with zero validation errors. The two stock CPU sharing tests also passed.

Synthetic fixtures only. AI-assisted with OpenAI Codex.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants