Skip to content

d3d12: graphics root arguments in the console layout (from s8, one dword per table, heap bases after) - #9276

Open
NiiRoZz wants to merge 3 commits into
ItsNotRexed:mainfrom
NiiRoZz:graphics-root-layout
Open

NiiRoZz wants to merge 3 commits into
ItsNotRexed:mainfrom
NiiRoZz:graphics-root-layout

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Depends on: #9014 (this branch contains its two commits; review the last one).

Problem

The layer lays graphics root arguments out with the first model, pack(): from s0, with two dwords per descriptor table. The game's vertex and pixel shaders read theirs from s8, with one dword per table, so every root argument of every draw reaches the wrong user SGPRs. The heap bases of #9014 had no graphics slot either.

The layout (measured on the retail boot)

pack_stage already gives the console layout for compute. The same order holds for the graphics stages from s8: parameters in root order, one dword per table, two per root view, one per constant, then the heap bases.

The check: the boot's root signatures (temporary local prints, not in this PR) joined with the read sets of the shaders in each graphics pipeline it creates.

  • 226 of 226 vertex shaders read their arguments exactly where this layout puts them: a pointer on a table or heap base, a constant on a constant.
  • 504 of 504 pixel shaders read theirs the same way; 499 of them also read one SGPR past the end. That SGPR goes to m0 (s_mov_b32 m0, s[end]), the hardware's PRIM_MASK, a system value rather than root data.
  • The title's commonest draw signature puts its table at s8, two constants at s9–s10 and the sampler heap base at s11.
  • The graphics signatures it uses are all at D3D12_SHADER_VISIBILITY_ALL.

Change

  • CreateRootSignature lays graphics out with pack_stage(Stage::Pixel) instead of pack(). Descriptor tables are one dword at both bind points.
  • Draws and DispatchMesh write the bound heaps' bases into the graphics slots, as d3d12: write the bound heaps' bases into the compute user SGPRs for direct heap indexing #9014 does for compute.
  • Mesh pipelines. A mesh shader reads the same arguments from s16, while its pixel shader reads from s8 out of the same push-constant block.
    • For DispatchMesh the list copies the window [s8, end) eight SGPRs up.
    • When the two windows would overlap, the mesh draw is refused and logged. Per-stage push-constant windows in the translator would lift this (documented as open). The boot creates no mesh pipeline.
  • Spilling signatures. A valid signature that spills at a bind point (the spill array is not modelled) is now created, as on the console, and marked unusable there.
    • Before, it was refused unless the other layout could place it. That killed the retail boot at startup: one of its signatures (8 root views and 14 constants) fits neither layout from s4/s8.
    • pack_stage reports a spill separately (spills) and still validates every parameter after it, so an over-cost signature is never taken for one that only spills.
  • Test fixtures. The D3D12 tests' hand-written graphics fixtures (vs_m15, ps_m15, ps_m2*, vs_m3, ps_m3*) and GLSL stand-ins (vs_draw, vs_draw_int, vs_depth, ps_draw, ps_depth_write, ms_draw) read their arguments in the console layout. Tables are one SGPR, and the shader zeroes the pointer's high word as the game's shaders do.
  • docs/d3d12_vulkan.md sections 3.4, 3.5 and open question 3 are updated.

What this does on the retail boot (integration tree, not main)

With this layout the first frame loses the device. The first draw's signature is a single root CBV, and its VA (a 41-bit address inside a buffer that the integration branch places on the title's own pages, #7218) is outside the GPU address arena. The translated shader reads it at heap base + VA.

  • With the old s0 layout the same shader read zeros at s8–s9. That is harmless, and it is also why the draws wrote nothing.
  • So the layout is doing its job, and the next blocker on that branch is that buffers on the title's pages need VAs the shaders can reach.
  • main does not have that path. Not verified on the retail boot.

Not in this PR

Tests

Windows 11, MSVC 2022, Ninja RelWithDebInfo, Vulkan SDK 1.4.363, NVIDIA GeForce RTX 5090 and AMD Radeon gfx1036 iGPU.

  • d3d12_heap_index
    • New graphics part: ps_heap_index.asm reads k at s8 and the heap base at s9, loads a raw view at heap slot k and draws its four floats. Three draws over two heaps: 192 texels, error 0.
    • It also checks both layouts of signatures with each flag combination, and that 25/28/29-constant signatures are created with the right bind points usable.
    • Passes with LEONIDA_VK_VALIDATION=1 on both GPUs.
    • Negative control: without the graphics heap-base write, every pixel reads back 0 and the test fails.
  • root_signature_test: spill vs invalid, an invalid parameter after a spill, and graphics spills. Passes.
  • The 14 D3D12 graphics tests fail against the new layout with the old fixtures and pass after the migration: d3d12_translated_draw, m2_textured, m2_formats, m3_frame, m3_first_pass, draw, msaa_draw, geometry, depth24_draw, pipeline_library, bundle, mesh, plus heap_index and compute.
  • Full ctest -R "d3d12|root_sig|fsr|rootsig" on the RTX 5090: 110 of 112 pass.
  • d3d12_vulkan_device and d3d12_depth_resolve exit 1 here and at d3d12: write the bound heaps' bases into the compute user SGPRs for direct heap indexing #9014's commit alike (d3d12_vulkan_device_test: ask the PC device for Device10, since the proxy's slot 78 is the Xbox frame interval #9175 addresses the first).

AI-assisted (Claude Code). No game files.

🤖 Generated with Claude Code

NiiRoZz and others added 3 commits November 23, 2026 20:51
…irect heap indexing

A root signature with CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED or SAMPLER_HEAP_DIRECTLY_INDEXED now gets the bound
heaps' 32-bit base VAs in the user SGPRs right after its root arguments, CBV/SRV/UAV heap first, as the
console does (docs/d3d12_vulkan.md section 3.4). pack_stage places them; Dispatch and a dispatch
ExecuteIndirect write them from the heaps SetDescriptorHeaps bound. Before this the list tracked the bases
(ItsNotRexed#6674) but no shader ever saw them, so a heap-indexing compute shader loaded its descriptors from VA 0.

Measured on the retail boot: 13 of about 45 root signatures set a heap flag; the heap-indexing compute
shaders it creates read the base where this puts it, and so do 453 pixel shaders counted from s8.
Graphics stays open (its root layout starts at s0, the game's VS/PS read from s8), and so does the sampler
heap's stride (16 bytes in the shaders, 32 in the layer).

d3d12_heap_index: a translated compute shader loads V#s at heap slot k (run-time offset) and slot 1 (static)
from the heap base; two heaps bound in turn must route the writes to each heap's buffers. With the old
user data every word stays at its sentinel. root_signature_test covers the slot placement and the refusal
when a heap base does not fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fourth dispatch goes through ExecuteIndirect (one DISPATCH of 1, 1, 1) with heap B bound and k = 3; its
writes must land in B[3]'s buffer. With the indirect path's old user data they stay at the sentinel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ord per table, heap bases after)

The layer laid graphics root arguments out with pack(): from s0, two dwords per descriptor table. The game's
vertex and pixel shaders read theirs from s8, one dword per table, so every root argument of every draw
reached the wrong user SGPRs. Measured on the retail boot, joining its root signatures with the read sets of
the shaders of each graphics pipeline: all 226 vertex and 504 pixel shaders read their arguments where
pack_stage(Stage::Pixel) puts them (499 pixel shaders also read one SGPR past them, into m0: PRIM_MASK, a
system value).

- CreateRootSignature lays graphics out with pack_stage(Stage::Pixel); tables are one dword at both bind points.
- Draws and DispatchMesh write the bound heaps' bases after the graphics arguments, as ItsNotRexed#9014 does for compute.
- A mesh draw copies the window [s8, end) to s16, where the mesh shader reads it; when the windows overlap the
  draw is refused and logged (per-stage push-constant windows are open).
- A valid signature that spills at a bind point is created, as on the console, and unusable there; pack_stage
  reports spills apart from invalid signatures and validates every parameter after a spill. The retail boot
  creates one signature that spills at both bind points and stopped at startup when it was refused.
- The D3D12 tests' graphics fixtures and GLSL stand-ins read the console layout.

d3d12_heap_index gains a pixel-shader part (192 texels through heap-indexed views, two heaps; 0 without the
graphics heap-base write) and layout checks of every flag combination and of spilling signatures.

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

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review

Checked: graphics root arguments in the console layout (from s8, one dword per table, heap bases after) across root_signature + d3d12 shims + extensive test/shader fixtures. Large D3D12/Vulkan path — not built/run on this Linux CPU agent; docs and layout comments read consistent.

Looks correct from review; no game files. (Did not execute GPU/D3D12 tests here.)

@AAyberkU

Copy link
Copy Markdown
Contributor

An independent measurement of the problem this PR fixes, made before I found it. Retail title, Windows 11, RTX 5060 Ti, a stack with #2490, #7021, #7880, #7448, #8304/#8225 and #9137. At the first UI draws, a blit pass and a composite pass that both bind one descriptor table:

The PS-probe results that narrowed this down are on #6750 and use #9322's switches. I'm merging this branch next and will report whether the first UI draws produce pixels.

AI-assisted (Claude Code).

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 5060 Ti driver 610.88 / Vulkan 1.4.341), PR head a8dbcb53d merged onto main (6312c057f):

  • python -I scripts/check_no_game_data.py ... (all 28 changed files): clean (exit 0).
  • cmake --build runtime/build --target root_signature_test d3d12_heap_index_test d3d12_m2_textured_test d3d12_draw_test d3d12_depth24_draw_test d3d12_mesh_test --parallel: built cleanly (including translated cs_heap_index, vs_m2, ps_heap_index fixtures).
  • LEONIDA_VK_VALIDATION=1 ctest --test-dir runtime/build -R "^(root_signature|d3d12_heap_index|d3d12_m2_textured|d3d12_draw|d3d12_depth24_draw)$" --output-on-failure: 5/5 passed (0 validation errors).
  • ctest --test-dir runtime/build -R ^d3d12_mesh$ --output-on-failure: 1/1 passed.

AI-assisted.

@MarcPique

Copy link
Copy Markdown

checked: #9276@a8dbcb53 (+ #9014) | with: MSVC 19.44.35228, RelWithDebInfo, ctest -R '^(root_signature|d3d12_heap_index)$' -V | on: Windows 11 26200, RTX 4090 (32.0.16.1656) and Ryzen 7800X3D Radeon Graphics (32.0.13066.12) | result: 2/2 on each GPU, 384 expected words and 192 drawn texels matched per device. This host does not have the optional Khronos validation layer.

Retail: the runtime delta applies to the local #9137 + #8869 integration with three mechanical resolutions preserving the title-VA remap and descriptor table scan. On the RTX 4090 it survived the first present and reached its 225 s external limit, with at least 70,144 successful swapchain presents and no logged device loss. The title-memory copy path ran. Three window captures during successful presents had black client pixels. The test retains 32-byte sampler slots and does not wire the optional title-written descriptor source.

agent: yes

@Yoshi-OOF

Copy link
Copy Markdown

I am integrating a8dbcb5 on a private Windows 11 / RTX 5070 Ti runtime for a retail check. The present baseline already has #9137 title-VA aliases and dirty shadow copies, the #8754 input-layout parser, and 1,266 translated/spirv-val-valid native graphics programs covering all demanded hashes observed in my 10,241-call slot-57 census. The five-module baseline served 5/10,241 calls and presented black. I will distinguish layout/PSO results, actual submission and GPU readbacks rather than reporting first present as game output.

@AAyberkU

Copy link
Copy Markdown
Contributor

Result with this PR (which includes #9014) merged into my retail stack. The stack also has #9137, plus a local copy of the title's #7021 heap backing into the layer heap before each submit. Windows 11, RTX 5060 Ti, retail title.

  • User data at the first UI draws: s0 to s7 are 0 and s8 is the bound table's VA, for both the blit pass and the composite pass. s9 to s11 are 0 at those draws (these two signatures declare no constants or heap flags). The earlier fullscreen pass gets its root view at s8/s9.
  • Still no coverage. With the real title shaders, every presented frame stays the clear colour. With the title's VS and a built-in PS (d3d12: LEONIDA_PROBE swaps a pipeline's stages for built-in ones; LEONIDA_DEBUG_CLEAR (first-frame bring-up) #9322's probe, blending off), the composite still covers nothing.

So this layout is necessary, since without it every table read is at heap_base + 0, but it isn't sufficient for these draws on retail. Next I'm checking which table offsets the UI VS loads (from its SPIR-V) and what the arena holds there at draw time.

AI-assisted (Claude Code).

@MatyEjsr

Copy link
Copy Markdown

Independent Windows + NVIDIA GPU verification of a8dbcb53d (AI-assisted)

Depends on: #9014 (this branch contains its two commits, as the description says)

Environment: Windows 11 Pro for Workstations (build 26200), NVIDIA GeForce RTX 3090, driver 617.42, Vulkan SDK 1.4.363.0, MSVC 14.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, LEONIDA_D3D12_SHIM_TESTS=ON. llvm-mc is LLVM 23.1.5 with the AMDGPU target, run through WSL. Everything ran with 8 jobs. I built the PR head exactly as pushed, on its own base (it is not rebased onto current main). No game files were used.

Build and ctest (ctest -C RelWithDebInfo -j 8)

  • The build succeeds with no compile errors. One first attempt stopped on two build.py assembler steps with an empty error. Those steps pass when run alone, and the rerun with -k 0 built clean. I put it down to a WSL start-up flake under 8 parallel llvm-mc launches, not the PR.
  • 275 of 277 tests pass. The skips are the usual game-package or environment gates, and gameinput is disabled.
  • The tests this PR touches pass on the RTX 3090: root_signature, root_signature_oracle, d3d12_xs_root_signature, d3d12_m2_textured, d3d12_m3_frame, d3d12_m3_first_pass and d3d12_heap_index.
  • 2 failures, d3d12_vulkan_device and d3d12_depth_resolve, are not caused by this PR. I built the merge-base (867d922f0) with the same configuration and ran just those two tests. Both fail the same way there:
    • d3d12_vulkan_device stops at line 6574: tiles == 1.
    • d3d12_depth_resolve reports refused D24S8 depth AVERAGE rect 1 and refused D32S8 depth AVERAGE rect 0, both with Close 0x80070057.
    • The failing lines are identical on the base and on the PR head.

scripts/run_gpu_tests.py on the PR head

The suite translates 249 shaders, and all 249 pass spirv-val. Result: 192 passed, 48 skipped, 2 failed.

  1. ps_heap_index FAILS with vkQueueWaitIdle -> -4 (VK_ERROR_DEVICE_LOST) — this one is the PR's.
    • The fixture is added by this PR, and its header says it is run by d3d12_heap_index_test (a graphics PSO that needs the layer's root arguments and heap base).
    • It is not listed in OTHER_HARNESS in scripts/run_gpu_tests.py (around line 652). So the generic harness draws it with vs_ids.asm and no layer-provided s8/s9. The buffer-descriptor load at s9 then goes through a null base, and the device is lost.
    • A plain --filter ps_heap_index run reproduces it.
    • Likely fix: add "ps_heap_index": "d3d12_heap_index_test" to OTHER_HARNESS, as ps_m2, ps_m3 and the others are. With that entry the runner reports SKIP (run by d3d12_heap_index_test), which is the same pattern as the existing M2/M3/M15 fixtures.
    • d3d12_heap_index itself passes in ctest on this GPU.
    • The same sweep shows --filter cs_heap_index is refused with "no runnable GPU test cases". That compute fixture is not run by the generic harness, so the ps_ entry looks like the only gap.
  2. ms_wave_info_s3 fails with got (-1,-1,-1,-1), want (0.0078,0.0078,0.5,1.0). This PR doesn't touch that fixture or the mesh path. I did not rerun it on the base, so I can't say whether it is pre-existing. Treat it as unrelated unless someone sees it pass on this GPU.

Not covered

  • A rebase onto current main (the head's base is 867d922f0).
  • Other GPUs and drivers.
  • The claim that all 226 vertex and 504 pixel shaders read their arguments at the new layout. That was measured on the retail boot, and I have no game files.

@tiagonleal

Copy link
Copy Markdown

checked: #9276a8dbcb5 | base: main@867d922f0 + #9276 (fast-forward) | on: Windows 11, MSVC 14.44, RTX 5070 Ti (617.42) | result: pass

  • 11/11 touched tests pass (root_sig, root_signature, root_signature_oracle, d3d12_m2_textured, d3d12_m2_formats, d3d12_m3_frame, d3d12_m3_first_pass, d3d12_heap_index, d3d12_draw, d3d12_depth24_draw, d3d12_mesh); tests/test_pc_tail_ubo.py 8/8.
  • LEONIDA_VK_VALIDATION=1: d3d12_heap_index, d3d12_m2_textured, d3d12_m3_frame clean; d3d12_mesh 3x VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076, identical on main.
  • Full ctest: 273/276. d3d12_vulkan_device and d3d12_depth_resolve fail the same on main; run_tiny_game_dir failed once because my own tooling killed a process, 3/3 on rerun.

AI-assisted.

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