Skip to content

Runtime: apply backing-buffer offsets to ExecuteIndirect (D3D-17) - #1339

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
mrb-eel:runtime/indirect-buffer-offsets
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
mrb-eel:runtime/indirect-buffer-offsets

Conversation

@mrb-eel

@mrb-eel mrb-eel commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What and why

D3D-17 follow-up. Claim.

The ExecuteIndirect implementation on main passes offsets relative to D3D12 resources directly to Vulkan. If an argument or count resource is a slice of the backing VkBuffer, Vulkan reads bytes from the wrong location.

Add each binding's backing-buffer offset for fixed-count draw, indexed draw, and dispatch, and for both count-buffer draw variants. Validate the stride, alignment, and argument/count spans in preparation, including overflow after adding the backing-buffer offset. The final record only needs to hold the command bytes.

Tested

  • d3d12_state_map_test reproduced the wrong emitted offsets on c0ac5fd. The fix passes on GCC 16.1 and MSVC 19.44, capturing the eight offsets emitted by all five replay paths and rejecting invalid spans before any command is written.
  • Added a real GPU regression to d3d12_indirect_rt_test. The argument and count slices start at offsets 64 and 128 in their backing buffers, and the unadjusted bytes hold different data. The test reported a pixel mismatch on unpatched c0ac5fd. On this branch, count 0 left the target black and count 1 drew the triangle, with zero Vulkan validation errors. Built through CMake/Ninja with MSVC and verified through CTest.
  • Existing vk_command_replay_test passed with Khronos validation enabled on Windows 11 build 26200, RTX 4070 SUPER, driver 616.92.
  • Synthetic resources and fixtures only. AI-assisted implementation and testing.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I reproduced the argument and count offset errors independently with actual vkCmdDrawIndirectCount readback. The table gives painted pixels in a 16×16 target on both RTX 5080 and integrated Radeon. The valid fullscreen triangle has an 11×7 scissor. Every backing-buffer prefix and slice contains a valid record, either three or zero vertices, and every count is zero or one.

Test Expected Parent c0ac5fd6 PR 3b7cbf46
Both bases zero 77 77 77
Only argument base nonzero 77 0 77
Only count base nonzero 77 0 77
Both bases nonzero 77 0 77
Selected argument has zero vertices, prefix would draw 0 77 0
Selected count is zero, prefix would draw 0 77 0

The argument view started at backing offset 64 and used resource-relative offset 16 (absolute 80). The count view started at 160 and used resource-relative offset 8 (absolute 168). The count and the command each ended exactly at the end of their logical view. I compared all 256 RGBA pixels after each draw; all six frames matched on each GPU at 3b7cbf46c78e8373b0cfb5aeea2dddd5103dc54f, with Vulkan validation enabled. Windows 11 26200, NVIDIA 616.92 and AMD 26.10.1.

I used the source-built d3d12_indirect_rt_test render harness, which explicitly opens Vulkan rendering and binds its graphics pipeline before calling replay. This verifies buffer addressing inside the indirect command. The separate draw-state question in the earlier report remains open.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6): pass. ctest: all pass on the RTX 4080 SUPER (65–66). The Intel UHD 770 failures are the known ones (vk_binary_occlusion fixed by #1321, d3d12_vulkan_device fixed by merged #1285, d3d12_descriptor min-LOD, d3d12_copy_xfmt).

@Rainmaker33

Copy link
Copy Markdown

Tested 3b7cbf4 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main f85582e. VS 2022, Vulkan SDK 1.4.363.0. Runtime built with scripts\build_runtime.ps1 (CMake, RelWithDebInfo).

  • d3d12_state_map (ctest, LEONIDA_VK_VALIDATION=1): passed, no VUIDs.
  • ctest: 66/67 pass. process_cmdline fails the same way on main here (code page 1253, RT-84).

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

The fix is already on main (merge commit 41dccfb), so what's left here is the follow-up test commit 21ff2aa. Tested that merged onto main (c2967a5) on AMD Radeon RX 9070 (RDNA4), AMD 26.11.2, Windows 11, with LEONIDA_VK_VALIDATION=1: pass.

  • d3d12_indirect_rt_test: [PASS] ExecuteIndirect with suballocated argument and count buffers (count=0 skipped, count=1 rendered), PASS (0 validation errors).
  • d3d12_state_map_test: exit 0.

AI-assisted (Claude Code).

@Yourrespawn

Copy link
Copy Markdown
Contributor

Tested 21ff2aa2 on NVIDIA GeForce RTX 4080 (Ada), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • ctest RelWithDebInfo: 65/65 (gameinput disabled, no SDL3)
  • run_gpu_tests.py native: 98/126 passed, 28 skipped (native wave64, expected on this 32-lane GPU)
  • run_gpu_tests.py LEONIDA_W64_EMULATE=1: 126/126 passed

Counts differ from my #166 entry (main) because this branch is based on c0ac5fd6 and predates the newest test registrations; no failures anywhere. AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.

@ItsNotRexed
ItsNotRexed merged commit 0648aae into ItsNotRexed:main Nov 22, 2026
11 checks passed
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.

7 participants