Skip to content

Runtime: support RGB96 footprint copies on dedicated COPY queues - #4817

Open
gabrielsteglich wants to merge 3 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/rgb96-copy-queue
Open

gabrielsteglich wants to merge 3 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/rgb96-copy-queue

Conversation

@gabrielsteglich

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue #4683.

Depends on: #4107, #3481, #4577 for merge-order conflicts. This branch builds directly on main (98fa503f).

What and why

A standard RGB96 buffer–texture copy needs compute to repack 12-byte D3D12 texels into the 16-byte Vulkan image format. On a dedicated transfer-only family, submit the affected logical COPY batch on the primary compute-capable queue. Ordinary COPY batches still use the dedicated family. Cross-queue handoffs wait on the previous COPY timeline ticket, including handoffs involving fence signals and sparse binds. Keep the compute write in the readback-to-host barrier and share conversion scratch across the queue families that use it.

This change covers standard RGB96 footprints. The emulated D24-only path on a transfer-only family remains unsupported.

Tested

Head 71821118 against main at 98fa503f.

Windows 11 Pro 26300, Visual Studio 2022 Build Tools (MSVC 19.44.35229, Windows SDK 10.0.26100.0), Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 3090 on 621.01, x64 RelWithDebInfo, with core and synchronization validation enabled.

  • d3d12_rgb96_copy_queue matched 420 texel bytes and 1,436 sentinels for a 7×5 texture and an offset 3×3 patch. It exercises DIRECT → COPY → DIRECT waits on both a dedicated family and a shared primary queue.
  • The Vulkan API trace showed COPY work going from family 1 (ordinary transfer) to family 0 (two compute dispatches) and back to family 1. The internal waits targeted COPY timeline tickets 1 and 2. No Vulkan validation errors were reported.
  • Native D3D12 on the same GPU accepted the standard COPY-queue upload and readback and matched all 35 texels.
  • Full runtime CTest passed with 158 passes, 8 skips, and 1 disabled test. depth24_convert also verifies that the RGB96 readback barrier covers compute writes.

AI-assisted (Codex). No game data, keys, or decryption.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 718211187570798f3dbfe213103bea7d830cb2b0 on Windows 11, RTX 5090 (617.42), Vulkan SDK 1.4.363.0, MSVC 14.44/Ninja x64 RelWithDebInfo.

Built via vcvars64 and cmake --build runtime\build --target d3d12_rgb96_test depth24_convert_test. Ran ctest --test-dir runtime\build -V -R "^(d3d12_rgb96|d3d12_rgb96_copy_queue|depth24_convert)$": 3/3 passed, also 3/3 with LEONIDA_VK_VALIDATION=1 (no validation errors reported). The DIRECT → COPY → DIRECT test matched the 7×5 texels, shifted 3×3 patch and footprint sentinels on dedicated COPY family 1 (flags 0xc) and primary family 0. The standard suite matched eight texture shapes against WARP; the depth24 test verified RGB96 host-readback visibility barriers.

Red control: rebuilt baseline 98fa503f using the PR versions of the two test sources. d3d12_rgb96_test.exe --copy-queue-roundtrip exited 1 (byte 0: got 00, want ee); depth24_convert failed at line 615 (host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT). Restored the PR checkout, rebuilt, and verified clean worktree.

AI-assisted (Devin); no game files.

@XFlawless1

XFlawless1 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 71821118 merged with main de671352 (clean merge) on Windows 11 Pro 26300, MSVC 19.44, Vulkan SDK 1.4.363.0, RelWithDebInfo built with scripts/build_runtime.ps1, LEONIDA_VK_VALIDATION=1: pass on both GPUs.

RTX 5080, driver 621.14 Radeon iGPU of the Ryzen 7 9800X3D (RDNA2), driver 32.0.21042.62
COPY family used by the test 1, flags 0xc (transfer + sparse, no compute): the transfer-only path this PR adds 1, flags 0xe (compute + transfer + sparse): the conversion can stay on that family
d3d12_rgb96_copy_queue pass: dedicated-family round trip, then COPY on the shared primary family 0; 7x5 texels, shifted 3x3 patch and footprint sentinels match pass, same lines
d3d12_rgb96, depth24_convert, d3d12_depth24_draw pass pass
full ctest 168/168 168/168

No validation messages in either run. So the RTX 5080 run checks the transfer-only handoff to the primary queue on a second NVIDIA generation, after the PR's RTX 3090. The Radeon checks that a COPY family with compute is unaffected.

AI-assisted (Claude Code).

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested 7182111 (on its base main 98fa503f) on an RTX 3070 (610.88, Windows 11 26300, MSVC VS 2022, Vulkan SDK 1.4.363 layers), with the validation layer including synchronization validation: pass. Full ctest is 174/174, including the new d3d12_rgb96_copy_queue. Run directly, it prints RGB96 dedicated COPY family 1 (flags 0xc), primary family 0, so the transfer-only path is reached on this GPU. It then matches the 7×5 texels, the shifted 3×3 patch and the sentinels on both devices, with 0 validation errors. It passed 50 of 50 repeated runs. depth24_convert_test passes, including the host-readback barrier check. The two build warnings (C4456 in d3d12_vulkan_device_test.cpp) are in a file this PR doesn't touch.

Controls (one change at a time, rebuilt, then restored):

Change Result
switch_queue = false in submit(), so a batch that moves between the transfer and primary queues no longer waits on the COPY timeline d3d12_rgb96_copy_queue passed 19 of 20 runs; run 14 failed with byte 0: got 00, want ee. No validation error in any run
execution_kind = kind_, so the repack batch keeps the COPY stage mask depth24_convert_test fails (line 615: host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT); d3d12_rgb96_copy_queue passes 20 of 20

The second row is pinned by the updated depth24_convert_test. The first row is the handoff ordering this PR adds, and the test catches its removal only now and then: here, 1 run in 20. Byte 0 is the footprint prefix, which mixed fills from the upload buffer. So the failure is most likely the last DMA copy, on family 1, reading packed before the mixed batch on family 0 has written it. Synchronization validation didn't report the missing cross-queue wait, so the byte compare is the only thing that notices, and only when the race goes the wrong way. A deterministic check would help. One option is a depth24_convert_test-style hook on vkQueueSubmit: assert that the first submission on the other physical queue waits on the logical queue's own timeline at the previous ticket, in both directions. Another is to make dma_in slow enough that mixed would overtake it without the wait, for example with a much larger buffer copy in dma_in ahead of the patch copy.

AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

ACCEPT. Builds clean, and d3d12_rgb96, the new d3d12_rgb96_copy_queue (7x5 texels, 3x3 patch, sentinels), depth24_convert and d3d12_present all pass on an RTX 5070 with zero validation errors. The test genuinely routes family 1 -> family 0 -> back. Negative control: forcing the conversion onto the COPY family (runtime/src/vulkan_backend.h:1750) fails with ExecuteCommandLists failed: unsupported and byte 00 vs ee, so it is sensitive. Cross-queue ordering is sound: the submitted_ fence is used when the physical queue switches, idle waits both, and pools are per family.

Minor:

  • runtime/test/depth24_convert_test.cpp:615 dropped the queue_supported_stages invariant.
  • The primary_without_compute_ branch at runtime/src/vulkan_backend.h:1750 is effectively unreachable.

Approve. AI-assisted review, no game files.

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent Pascal verification of head 7182111 (based on current main 98fa503f), adding the missing distinct-queue-family case.

Environment (AI-assisted, OpenCode): Windows 11 Pro build 26300, MSVC 19.44.35230, CMake 4.4.4 + Ninja, RelWithDebInfo. GPU: NVIDIA GeForce GTX 1060 6GB, driver 582.78, subgroup sizes 32..32, no Resizable BAR (upload heaps in system memory). No game data, keys or decryption.

The case only this hardware covers: the test reports RGB96 dedicated COPY family 1 (flags 0xc), primary family 0 — i.e. a genuinely separate COPY queue family, unlike a single unified queue. The --copy-queue-roundtrip run still passes: DIRECT -> COPY -> DIRECT: 7x5 texels, shifted 3x3 patch and footprint sentinels match.

Results:

  • d3d12_rgb96_test.exe -> exit 0: 8 texture shapes matched WARP and expected texels bit for bit, CPU copies with and without host image copies; hardware and WARP both report no tiling for the four formats.
  • d3d12_rgb96_test.exe --copy-queue-roundtrip -> exit 0 (above).
  • depth24_convert_test.exe -> exit 0: all 16,777,216 words round-trip, specials/NaNs/pitches/concurrent queues all ok.
  • ctest -R "rgb96|depth24_convert" --output-on-failure -> 100% passed, 3/3 (depth24_convert, d3d12_rgb96, d3d12_rgb96_copy_queue).

Build of the two changed targets was clean. Depends on: none — verification only, no competing fix.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 7182111 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_rgb96|depth24_convert)$" (the tests this PR adds/changes): pass on both GPUs, 2/2 each. No game files.

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55 (clean merge): compileall clean, the docs guards (repo paths, CLI flags, links) pass, no game data in the diff and the fixture values are procedurally generated. Static review is consistent — timeline progress_ orders the physical-queue switch and the doc claims match the code — but the new d3d12_rgb96 / d3d12_rgb96_copy_queue ctest targets need a Vulkan build and were not run on this CPU-only host. Two spots a human should eyeball: the new state_mutex_ acquisition in idle() (lock order against submit_mutex_ is not provable statically) and the device-lost path through conversion_pending / scratch_ticket = UINT64_MAX. Checks still pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only review).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 7182111 on Intel UHD 770, driver 32.0.101.7088, Windows 11, MSVC, with LEONIDA_VK_VALIDATION=1 and the Khronos validation layer loaded: ctest -R rgb96 passes 2 of 2. d3d12_rgb96 (1.40 sec) reports "8 texture shapes matched WARP and the expected texels bit for bit", and d3d12_rgb96_copy_queue (0.23 sec) reports "RGB96 DIRECT -> COPY -> DIRECT: 7x5 texels, shifted 3x3 patch and footprint sentinels match", with no validation errors. This GPU has a single queue family, and the test prints "RGB96 COPY on the primary family 0", so the dedicated transfer-family path this PR adds is not exercised here.

AI-assisted.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested f9f29ed09 merged into main 1cc6e3c12 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "rgb96|depth24" --output-on-failure: 4/4 passed (depth24_convert, d3d12_rgb96, d3d12_rgb96_copy_queue, d3d12_depth24_draw).

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested f9f29ed merged with main 8575d36 on Windows 11 (MSVC 14.51, RelWithDebInfo, Ninja): pass
Real merge was clean (four files auto-merged). Built d3d12_rgb96_test, depth24_convert_test and d3d12_depth24_draw_test, and ran ctest -R "rgb96|depth24": depth24_convert, d3d12_rgb96, d3d12_rgb96_copy_queue and d3d12_depth24_draw all pass on NVIDIA GeForce RTX 4080 SUPER. The first three also pass on Intel(R) UHD Graphics 770 (VK_LOADER_DRIVERS_DISABLE=nv plus LEONIDA_VK_DEVICE=Intel, device name confirmed); d3d12_depth24_draw was run on NVIDIA only.
Negative control: with runtime/src/vulkan_backend.h, vulkan_depth24.h, vulkan_scratch.h and runtime/shims/d3d12_vulkan_device.cpp reverted to main, d3d12_rgb96 still passes but d3d12_rgb96_copy_queue fails, so the new case discriminates.
Only these tests were run, not the full ctest suite. The build prints a C4189 warning at vulkan_present.h(669), which is not touched by this PR.

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.