Skip to content

Runtime: preserve queue order for sparse buffer tile mappings - #4224

Open
gabrielsteglich wants to merge 2 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/sparse-tile-queue-order
Open

gabrielsteglich wants to merge 2 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/sparse-tile-queue-order

Conversation

@gabrielsteglich

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue #4084. This follows the reserved-buffer mappings in #987 and queue hold ordering in #2951.

What and why

When a D3D12 queue held a copy batch for an unresolved fence, later UpdateTileMappings and CopyTileMappings calls could reach Vulkan first. The earlier copy could then read a different tile mapping from the one it should have seen.

Both mapping operations now enter the same FIFO as held command batches and signals. A deferred operation owns its mapping arguments and keeps the sparse buffers and heap backing alive. CopyTileMappings reads the source mapping when it reaches the front of the queue. A no-op or rejected bind passes its waits to the next submission.

Tested

  • Commit bc15a8bb097f700b04187b32944b1cb397f9342f against aa2988cc555bad7ecd508b48a702adbb32fe7c95. Windows 11 build 26300, NVIDIA RTX 3090 driver 621.01, MSVC 19.44.35229, Windows SDK 10.0.28000.0, Vulkan SDK 1.4.363.0, RelWithDebInfo, Vulkan synchronization validation enabled.
  • On the base, the original control passed. With the copy batch held, both the CPU and COPY-queue Signal variants read zero in the first tile in the Vulkan layer, where native D3D12 read 0x23456789.
  • With the fix, all 36 full tiles matched the expected bytes on both the Vulkan layer and native D3D12 across the control and the two held cases. The Vulkan API trace showed the first copy submitted between the initial binds and the subsequent remap, with zero validation errors or synchronization hazards.
  • The full runtime suite passed 138 tests, with eight skipped, one disabled and zero failures. The additional vk_sparse_queue_order CPU test passed all four wait-forwarding cases. The final targeted run also passed d3d12_buffer_tiles and d3d12_queue_handover.

Checklist

  • No game data, keys or decryption.
  • Runtime-only change. No translator rule changes.

AI-assisted (OpenAI Codex).

Defer reserved-buffer tile updates and copies alongside held command batches and signals. Keep sparse backing alive, resolve source mappings at submission order, and carry waits past no-op or rejected binds.

Compare all tile readbacks with native D3D12 for CPU and COPY queue signals, and test wait forwarding with a fake incomplete Vulkan producer.

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

Built vk_sparse_queue_order_test and d3d12_buffer_tiles_test at bc15a8bb and ran them on Windows 11, RTX 5070 Ti:

  • vk_sparse_queue_order_test -> exit 0: "Sparse queue order: deferred no-op and rejected mappings preserve GPU waits".
  • d3d12_buffer_tiles_test -> exit 0: Vulkan replay with a held batch (CPU Signal and copy-queue Signal): 12 full tiles match across all readbacks; native D3D12 tier 4, original order and both held-batch orders: 12 full tiles match each; the arena reports 3 allocations / 0 refused.
  • ctest -R 'vk_sparse_queue_order|d3d12_buffer_tiles' -> 2/2 passed.

The new test covers the two cases the old path mishandled — a deferred mapping that turns into a no-op and one rejected at release — while the normal held-batch order still reads back every tile correctly on both the layer and native D3D12. No blocking issue.

@MKmajster

Copy link
Copy Markdown

Tested bc15a8b on NVIDIA GeForce RTX 3070 (Ampere, sparse binding), driver 617.42, Windows 11 24H2, MSVC 19.44 RelWithDebInfo: pass.

  • d3d12_buffer_tiles, vk_sparse_queue_order and the queue neighbours (d3d12_queue_wait, d3d12_queue_wait_timeout, d3d12_queue_handover, queue_proxy, vk_queue_query_sync): 7/7.
  • With LEONIDA_VK_VALIDATION=1 (VK_LAYER_KHRONOS_validation 1.4.350), no VUID or sync-hazard messages:
    • d3d12_buffer_tiles_test: 12 full tiles match across all readbacks on the layer and on native D3D12 (held batch, copy-queue Signal).
    • vk_sparse_queue_order_test: deferred no-op and rejected mappings preserve GPU waits (the a held tile mapping failed when it was released line is the rejected case it provokes).
  • Full CTest: 155/155.

No game files. AI-assisted (Claude).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested bc15a8b on NVIDIA GeForce RTX 4090 (driver 32.0.16.2101), Windows 11, MSVC 14.51: pass. The build has no validation layers, and it does not include the fixtures that need llvm-mc or SPIRV-Tools.

Vulkan and native D3D12 both report NVIDIA GeForce RTX 4090. Native D3D12 reports tiled resources tier 4.
ctest -R "^(d3d12_buffer_tiles|vk_sparse_queue_order)$" -V passes. Each backend matches 12 full tiles in each of three cases: original order, held work with a CPU signal, and held work with a copy-queue signal. The CPU mock passes the deferred no-op case and the rejected sparse-bind case.

Negative control: the new mock test, built with the backend of main aa2988cc, exits with 1. It fails the rejected mapping case and the higher following wait case.

Full ctest: this head gives 123 pass, 2 fail, 9 skip, 1 disabled. Main gives 122 pass with the same 2 failures. The extra pass is the new vk_sparse_queue_order. The 2 failures are d3d12_present and xbox_present; they fail on main on this computer too, because of the window size.

I found no defect. AI-assisted.

@theswiss24

Copy link
Copy Markdown

Tested bc15a8bb merged onto main 03b09a08 (clean) on NVIDIA GeForce RTX 4070 (Ada), driver 621.24, Windows 11 (26300), MSVC from Visual Studio 2026 (Ninja, RelWithDebInfo), Vulkan SDK 1.4.363.1, with LEONIDA_VK_VALIDATION=1: pass.

ctest -R "d3d12_buffer_tiles|vk_sparse_queue_order": 2/2 passed. From d3d12_buffer_tiles:

Vulkan replay (original mapping order)
  12 full tiles match across all readbacks
Vulkan replay (held batch, CPU Signal)
  12 full tiles match across all readbacks
Vulkan replay (held batch, copy-queue Signal)
  12 full tiles match across all readbacks
Native D3D12: NVIDIA GeForce RTX 4070, tiled resources tier 4

The first replay also logs UpdateTileMappings: invalid mapping or buffer sparse residency unavailable once, and the test still passes. I took that to be one of the test's deliberately rejected calls. I did not run the test on unpatched main. No game files.

AI-assisted (Claude Code).

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f56726d on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^(d3d12_buffer_tiles|vk_sparse_queue_order)$" (the tests this PR adds/changes): pass on both GPUs, 2/2 each. No game files.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested f56726d merged with main 98fa503 (merged tree 08808ba2b9) on Windows 11, RTX 4080 SUPER + Intel UHD 770 (MSVC 14.51): pass. Full runtime build.

  • ctest -R "sparse|buffer_tiles|vk_queue|vk_sync|d3d12_tiled|d3d12_reserved" (6 tests): NVIDIA 4 pass, 2 skip, 0 fail. Intel 3 pass, 2 skip, 1 fail: d3d12_sparse_queue_family fails on Intel with "no independent Vulkan queue available" / CreateCommandQueue hr=0x8007000e. It fails identically on main's build (5/5 runs on main and 5/5 on the PR), so it is not from this PR: the UHD 770 has no second queue family.
  • vk_sparse_queue_order passes 20/20 repeated runs on NVIDIA, and passes on Intel.
  • Control: main's runtime/src/vulkan_backend.h with the PR's tests: vk_sparse_queue_order and d3d12_buffer_tiles both fail on both GPUs.

@nakebx

nakebx commented Nov 23, 2026

Copy link
Copy Markdown

Tested f56726d on NVIDIA GeForce RTX 3070 (Ampere), driver 610.88, Windows 11 Pro 10.0.26200: pass

  • ctest with LEONIDA_VK_VALIDATION=1: 100% tests passed, 0 failed out of 164
  • d3d12_buffer_tiles_test run directly with the same setting: exit 0, "12 full tiles match across all readbacks"
  • vk_sparse_queue_order_test run directly: exit 0, "Sparse queue order: deferred no-op and rejected mappings preserve GPU waits"

Built with MSVC through scripts\build_runtime.ps1, Vulkan SDK 1.4.363.0. DISABLE_RTSS_LAYER=1 and DISABLE_VULKAN_OBS_CAPTURE=1 were set. Run with an AI-assisted script; the numbers are copied from the tool output.

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.

8 participants