Skip to content

Runtime: a bundle's draws run with the parent's state, and what the bundle set stays on the parent - #2145

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
nightmoon1996:fix/bundle-draw-inheritance
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
nightmoon1996:fix/bundle-draw-inheritance

Conversation

@nightmoon1996

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1548 (comment) (new D3D item)

What and why

A draw recorded in a bundle was dropped. record_draw snapshots the recording list's own viewport, render targets, root arguments and vertex/index buffers, and skips the draw when the list has no viewport. A bundle may not call RSSetViewports, RSSetScissorRects or OMSetRenderTargets, so its viewport is always empty: every bundle draw was skipped, with no error. execute_bundle copied the bundle's already-recorded commands, so none of the parent's state could reach them either, and of what a bundle sets only the stencil reference and the blend factor (#1660) came back to the parent.

Measured on the PC runtime first (RTX 4060 Ti and WARP, the same in every valid case):

Question PC runtime
A bundle draw sees the parent's target, viewport, scissor, root signature and arguments, VB, IB yes
The bundle sets the same root signature first the parent's root arguments are kept
The same bundle twice, the parent changing arguments and viewport between two regions, two colours: inherited when executed, not when recorded
The PSO a bundle starts with the one it was created (or Reset) with, not the parent's
After the bundle the parent has the bundle's PSO, topology, root constants, root CBV, VB and IB
The bundle sets another root signature and its arguments the parent goes on with those

The change. Inside a bundle, state calls, draws and Dispatch are kept as deferred calls (BundleCall: a function and the bundle's command count at that point). ExecuteBundle plays them on the parent through the private members a direct call uses, and copies the bundle's state-free commands (markers, WriteBufferImmediate) between them in their original order, through a range form of CommandList::execute_bundle. Inheritance and hand-back both follow from that one mechanism.

  • Runtime: carry bundle blend factors back to parent draws #1660 (@Vonsek): blend_factor_set_ and stencil_ref_set_ are gone; deferring OMSetBlendFactor and the stencil setters covers them. Runtime: carry bundle blend factors back to parent draws #1660's block in d3d12_draw_test is unchanged and still describes the behaviour: worked through by hand it gives {64, 0, 255, 64}.
  • Trace: a line is written once, when the bundle records the call; replay does not trace. A bundle's initial PSO is a deferred call without a trace line. Direct lists trace as before, and check_d3d12_trace.py is unchanged.
  • Lifetime: the bundle holds the PSOs and root signatures it deferred until its Reset or release; views, constants and addresses are copied. The parent holds them again when they are played.
  • Closed bundle: nothing is appended after Close; a draw or dispatch then makes the list invalid.
  • Also: ClearUnorderedAccessViewUint/Float are refused in a bundle like the other clears (they were recorded and really cleared).

For open PRs that add per-list state (#1451 RSSetDepthBias, #469 shading rate): after this, a setter works in a bundle by going through defer(...) with its private assignment; a _set_ flag and a line in ExecuteBundle are no longer needed. docs/d3d12_vulkan.md says so.

Known differences left as they are: a bundle that sets no topology gets the parent's, as on the NVIDIA host (Microsoft's rule is "undefined", and WARP removes the device); a bad root argument in a bundle now fails the parent's Close, not the bundle's; ExecuteIndirect and ClearState in a bundle are not deferred.

Tested

Windows 11, NVIDIA GeForce RTX 4060 Ti (driver 32.0.16.2101), clang-cl 23.1.6 with the xwin SDK (10.0.26100) through runtime/cmake/clang-cl-xwin.cmake, run natively. No game files.

  • New d3d12_bundle: 10 scenarios on the layer and on both hosts (RTX 4060 Ti and WARP, 20 host comparisons), all against one measured table: 0 failures, 3 runs. Plus on the layer: trace counts for a bundle executed five times, marker order (p0,p1,b1,draw,b2,draw,b3,p2), a PSO and root signature released right after recording with the bundle run from two parents and released while one is open, state calls and a draw on a closed bundle, zero-count root constants.
  • Negative control: on main's runtime sources all 10 layer scenarios fail (a bundle draw leaves the clear colour; hand-back cases fail the parent's Close), and the 20 host comparisons pass.
  • command_list_test: the range form (first past the end, last clamped, empty ranges, default arguments). d3d12_com_test: a UAV clear in a bundle with a real descriptor is refused (fails with the refusal removed).
  • d3d12_com, d3d12_trace, command_list, d3d12_compute, d3d12_set0_compute, d3d12_pipeline_library, d3d12_indirect_rt, d3d12_indirect_zero, d3d12_query_rules, d3d12_vulkan_device, unimplemented_policy, xs_proxy_mock*, queue_proxy pass. Full ctest: 111 of 113.
  • The two that don't pass, neither from this change: d3d12_subgroup can't be built here (my llvm-mc has no AMDGPU target), and d3d12_draw fails on main too, 0 of 10, at "fence signal 21 is not above 30" and then the bundle blend pixel (Tests: wait for the bundle blend draws in d3d12_draw (fence 31, not 21) #1995 fixes the fence value). With that value set to 31 locally, d3d12_draw passed 10 of 10 on this branch; the file is not changed here.
  • Not run: Vulkan validation (the Khronos layer isn't installed), Wine (the test skips the host there and still checks the layer; written, not run), MSVC, any AMD or Intel GPU. Bundle Dispatch goes through the same mechanism but has no GPU case.

AI-assisted (Claude Code).

Checklist

  • 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. (not a translator change)

🤖 Generated with Claude Code

…undle set stays on the parent

A draw recorded in a bundle took the bundle's own viewport, targets, root
arguments and buffers. A bundle cannot set a viewport, so every bundle draw
was dropped without an error, and nothing of the parent's state reached it.
Only the stencil reference and the blend factor were handed back.

Inside a bundle, state calls, draws and Dispatch are now kept as deferred
calls, and ExecuteBundle plays them on the parent through the members a
direct call uses, between the bundle's state-free commands, in order. A
draw sees the parent's state plus what the bundle set, and what the bundle
set stays on the parent, as measured on the PC runtime. This replaces the
stencil-reference and blend-factor carry-back fields. Trace lines are
written once, when the bundle records the call.

ClearUnorderedAccessView is refused in a bundle, like the other clears.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested b76c78ac on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Vulkan SDK 1.4.363: pass. This is an MSVC build, which the PR lists as not run.

AI-assisted (Claude Code).

@hidrogenone

Copy link
Copy Markdown
Contributor

Tested b76c78ac on NVIDIA GeForce RTX 5080 (Blackwell; driver 32.0.16.2124, Windows 11, Vulkan SDK 1.4.357.0). Build: VS 2026 (MSVC 19.51), Windows SDK 10.0.26100, Ninja RelWithDebInfo.

ctest -R "d3d12_draw|d3d12_bundle|command_list" → 2/3 pass:

  • command_list: pass
  • d3d12_bundle (this PR's new test): pass
  • d3d12_draw: fail, unchanged from main (4eb6155):
[rt] d3d12: fence signal 21 is not above 30; Vulkan timelines cannot go back
bundle blend pixel (0, 0): got 127,0,127,255, expected red 64

So on this Blackwell card the PR's new bundle coverage is green, but the existing d3d12_draw bundle-blend check still reads 127 (expected 64) — the same value as before the PR, i.e. not a regression, but the D3D-308 / #1966 symptom (the parent's OMSetBlendFactor reaching the bundle's own draw) is still present. d3d12_bundle passing alongside it suggests either the new test doesn't exercise that specific parent-factor path, or d3d12_draw's expectation needs revisiting under this PR's model — flagging for the author. Prior check on this PR (itsonlysimbo, RTX 4070 / Ada) wouldn't hit the Blackwell-specific failure.

AI-assisted.

@Gabzinnn12

Copy link
Copy Markdown

Tested b76c78a on AMD Radeon RX 7600 (RDNA3), AMD 26.11.2 (LLPC), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8: d3d12_bundle_test passes.

  • d3d12_bundle_test: exit 0 with and without LEONIDA_VK_VALIDATION=1 (+ VK_LAYER_VALIDATE_SYNC=1), no Vulkan validation errors reported: 10 scenarios on the layer, 20 host comparisons, 0 failures.
  • command_list_test, d3d12_com_test, d3d12_m2_textured, d3d12_m3_frame, d3d12_m4_compute, d3d12_translated_draw, d3d12_buffer_uav, d3d12_compute, d3d12_vulkan_device: exit 0 in both modes, no validation errors reported.
  • ctest: 1 failed out of 117 (110 passed, 6 skipped, gameinput disabled): d3d12_draw (bundle blend pixel 128,0,128,255). Run alone it passes without validation and reports VUID-vkDestroyPipeline-pipeline-00765 with validation. That is the fence-21 issue in this PR's base 4eb6155: in my earlier run of main 4947579, which has Tests: wait for the bundle blend draws in d3d12_draw (fence 31, not 21) #1995's fix, d3d12_draw passed.

AI-assisted (Claude Code, reviewed with Codex). No game files.

@ItsNotRexed
ItsNotRexed merged commit e3c972d into ItsNotRexed:main Nov 22, 2026
4 checks passed
@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested b76c78a (merged onto main 4947579) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Clean configure + build of runtime/ (Visual Studio generator, RelWithDebInfo): the only new warning is a C4996 for fopen at runtime/test/d3d12_bundle_test.cpp:518, in the new test; nothing new in the runtime itself.
  • ctest -C RelWithDebInfo -j 4: 117/117 passed (loader run on its own; 7 skipped for missing inputs or optional components, gameinput disabled, as on main).
  • command_list, d3d12_com, d3d12_vulkan_device, d3d12_fence_timing, d3d12_descriptor, d3d12_compute, d3d12_bundle and d3d12_state_map also pass with LEONIDA_VK_VALIDATION=1.
  • This adds an MSVC build of the same GPU model to the clang-cl run in the description.

AI-assisted (Claude).

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.

6 participants