Skip to content

Runtime: D3D12 PSOs bind the --pc-tail-ubo set-1 block for 128-byte push-constant devices (3/3) - #2402

Open
whoalin1 wants to merge 1 commit into
ItsNotRexed:mainfrom
whoalin1:pc-tail-runtime
Open

whoalin1 wants to merge 1 commit into
ItsNotRexed:mainfrom
whoalin1:pc-tail-runtime

Conversation

@whoalin1

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new item, the uniform-buffer tail for devices with 128 bytes of push constants (#1902 (comment)). This is step 3 of 3.

Depends on: #2046 (the translator's --pc-tail-ubo, which produces push_constant_bytes: 128 and pc_tail metadata). Independent of #2048 (the standalone GPU test harnesses); rebased on main (49475796).

What and why

A device whose maxPushConstantsSize is below 144 bytes — Vulkan's 128-byte minimum, reported by AMD's Windows driver on RDNA2 integrated GPUs and by some Intel Arc drivers (D3D-14's push_constants_need_fallback) — cannot declare the 144-byte ShaderUserData push-constant range, so d3d12_vulkan_device.cpp previously refused every D3D12 PSO there with E_NOTIMPL.

With --pc-tail-ubo (#2046), translated shaders keep s0..s31 in 128 push-constant bytes and move the 16-byte tail (heap base and code base) to a uniform block at set 1, binding 0 whenever a stage reads it. This wires that path through the D3D12 → Vulkan layer so 128-byte devices can build and run --pc-tail-ubo compute and graphics PSOs while still refusing 144-byte PSOs cleanly:

  • runtime/src/shader_library.h: ShaderEntry parses pc_tail.bytes into pc_tail_bytes (0 when absent); tested in runtime/test/shader_library_test.cpp.
  • runtime/src/vulkan_replay.h: ComputePipeline and GraphicsPipeline gain push_bytes (default 144), tail_set (set 1, null when unused), and tail_offset. detail::bind_user_data binds set 0 (if present), set 1 with dynamic offset tail_offset (if present), and pushes push_bytes at all three push sites (ExecuteIndirect dispatch, Dispatch, and Draw). All three bind_descriptor_sets capability checks cover tail_set.
  • runtime/shims/d3d12_vulkan_device.cpp:
    • DeviceState::pc_tail creates one UNIFORM_BUFFER_DYNAMIC descriptor over the arena (range 16, aligned to minUniformBufferOffsetAlignment) and one empty set-0 layout once per device (create_pc_tail(), destroyed in ~Device), avoiding per-PSO descriptor pools.
    • PipelineState::user_data_layout() replaces push_constants_fit(): sizes the push-constant range to 128 bytes when every stage fits in 128 bytes (including --pc-tail-ubo stages that read neither heap base nor code base and therefore omit pc_tail), adds set 1 when any stage declares pc_tail (with the empty set-0 layout when the PSO has no bindless bindings), refuses pc_tail sizes other than 16 bytes (--mesh-compute) or push_constant_bytes > 144, and still refuses 144-byte pipelines on < 144-byte devices with a log pointing to --pc-tail-ubo.
    • Both create_compute and create_graphics allocate 16 bytes from the arena in write_tail() once code_base is known, write {arena.address, code_base}, and release it in ~PipelineState.
    • Updated the startup warning and runtime/shims/d3d12_com.h comment.
  • Tests (runtime/CMakeLists.txt, runtime/test/glsl/{cs_user_data.comp,vs_draw.vert,ps_draw.frag}, runtime/test/d3d12_compute_test.cpp, runtime/test/d3d12_draw_test.cpp):
    • Existing GLSL test shaders gain -DPC_TAIL variants compiled alongside the 144-byte ones (cs_user_data_tail.spv, vs_draw_tail.spv, ps_draw_tail.spv).
    • d3d12_compute_test checks that a 128-byte device refuses the 144-byte PSO with E_NOTIMPL, builds and dispatches the --pc-tail-ubo PSO (verifying heap base + code base + user data) on both a simulated 128-byte device and the host GPU, and skips the 144-byte passes when run on a real < 144-byte GPU.
    • d3d12_draw_test checks the graphics path the same way, pairing a --pc-tail-ubo VS without pc_tail (push_constant_bytes: 128, no set 1) with a --pc-tail-ubo PS that reads heap_base from set 1 (pc_tail: 16), verifying all 4,096 pixels on both a simulated 128-byte device and the host GPU, and skipping the 144-byte passes on a real < 144-byte GPU.
  • Docs: updated docs/d3d12_vulkan.md (section 3.2 "Push constants", test descriptions, section 5.2, and Q13).

Without --pc-tail-ubo, 144-byte PSOs behave unchanged.

Tested

AI-assisted (initial implementation by Claude Opus 5.5; review, tail-less stage fix in user_data_layout, graphics tail test, rebase onto 49475796, and verification by Gemini 4 Neon / Antigravity).

Windows 11 (build 26200), MSVC 14.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363 (glslangValidator, VK_LAYER_KHRONOS_validation, SPIRV-Tools v2026.4), Python 3.14.4, llvm-mc 21.1.8 (WSL). No game files.

  • Build: scripts\build_runtime.ps1 at head (49475796 + this commit): 266/266 targets built, 0 errors.
  • shader_library_test.exe: pass (pc_tail_bytes parsed as 16 when present, 0 when absent).
  • d3d12_compute_test.exe (LEONIDA_VK_VALIDATION=1):
    • NVIDIA RTX 4070 SUPER (Ada, driver 610.88, maxPushConstantsSize 256): pass, 0 validation errors — simulated 128-byte device refused the 144-byte PSO (E_NOTIMPL), built and dispatched the --pc-tail-ubo PSO (64/64 elements exact on both simulated 128-byte device and host GPU), plus all 3 144-byte dispatches and CBV checks.
    • AMD Radeon Graphics (Ryzen 5 7600 iGPU, RDNA2, AMD Windows driver 24.10.24, Vulkan 1.3.280, maxPushConstantsSize 128): pass, 0 validation errors — real 128-byte device refused the 144-byte PSO (E_NOTIMPL, matching clean main where d3d12_compute_test exits 1 at that refusal), built and dispatched the --pc-tail-ubo PSO on the real 128-byte device (64/64 elements exact), skipped the 144-byte passes.
  • d3d12_draw_test.exe (LEONIDA_VK_VALIDATION=1):
    • NVIDIA RTX 4070 SUPER (driver 610.88, 256 bytes): pass, 0 validation errors — simulated 128-byte device refused the 144-byte VS+PS PSO (E_NOTIMPL), built and drew the --pc-tail-ubo VS (no pc_tail) + PS (set-1 tail) PSO (4096/4096 pixels exact on both simulated 128-byte device and host GPU), plus all M1 / B8G8R8X8 / strip-cut / 4x MSAA draws.
    • AMD Radeon Graphics (Ryzen 5 7600 iGPU, driver 24.10.24, 128 bytes): pass, 0 validation errors — real 128-byte device refused the 144-byte VS+PS PSO (E_NOTIMPL, matching clean main where d3d12_draw_test exits 1 at that refusal), built and drew the --pc-tail-ubo VS+PS PSO on the real 128-byte device (4096/4096 pixels exact), skipped the 144-byte passes.
  • ctest --test-dir runtime\build -C RelWithDebInfo --output-on-failure (NVIDIA RTX 4070 SUPER): 100% passed out of 116 (109 passed, 7 skipped, 1 disabled gameinput, 0 failed).
  • py -3.14 -I scripts\run_gpu_tests.py (regression check; harnesses unchanged):
    • NVIDIA RTX 4070 SUPER (driver 610.88): 190/190 translated & pass spirv-val; 139/185 passed, 46 skipped, 0 failed.
    • AMD Radeon Graphics (driver 24.10.24, 128 bytes): 190/190 translated & pass spirv-val; 88/185 passed, 97 skipped, 0 failed.

Checklist

🤖 Generated with Antigravity (Gemini 4 Neon) & Claude Code (Claude Opus 5.5)

@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent hardware check of 5fbd998 on Windows 11 build 26300, NVIDIA GeForce RTX 5070, driver 621.24. Synthetic fixtures only.

  • Stock shader_library, d3d12_compute, and d3d12_draw passed (3/3). The simulated 128-byte cap rejected the legacy 144-byte layouts and the tail layouts matched 64/64 compute elements and 4,096/4,096 pixels. Those tail checks also passed at the GPU's physical 256-byte limit.
  • To exercise the changed indirect replay branch, I made a local test-only substitution in the tail compute helper: ExecuteIndirect with one DISPATCH command at byte offset 64 in an upload buffer. The first 64 bytes were zero, so a dispatch from the wrong offset could not produce the expected results. Replay succeeded and the same 64/64 assertions passed at both the simulated and physical limits.

The indirect probe covered compute with no count buffer. I restored the test source after running it. AI-assisted test setup and review.

@umnitus

umnitus commented Nov 22, 2026

Copy link
Copy Markdown

Tested 5fbd998 on an RTX 3060 12 GB, NVIDIA 621.14, Vulkan 1.4.357, Windows 11 26H2: pass.

Built and ran the stock d3d12_compute_test and d3d12_draw_test from this commit. Both exited 0. With the simulated 128-byte push-constant limit, the set-1 tail path matched 64/64 compute elements and 4,096/4,096 graphics pixels. The stock 4x MSAA resolve also matched 4,096/4,096 pixels.

Build: clang-cl 23.1.6, Windows SDK 10.0.26100 via xwin, CMake 4.5.1, Ninja 1.13.2 and glslang 16.6.0. Vulkan validation layers were disabled. Synthetic inputs only. AI-assisted setup and verification; tests ran locally.

@Ingenioeren

Copy link
Copy Markdown
Contributor

Independent SwiftShader check of 5fbd9987 on Windows 11, clang-cl/lld 23.1.5, Vulkan SDK 1.4.341.1 validation enabled. SwiftShader Device (Subzero) reported an actual maxPushConstantsSize of 128 bytes. I applied the SDK 612 build fix and selected only SwiftShader with an explicit ICD manifest.

  • shader_library, d3d12_compute and d3d12_draw all exited 0. The fallback matched 64/64 compute elements and 4,096/4,096 pixels. The tests confirmed the 144-byte PSOs were refused.
  • d3d12_msaa_draw on the baseline refused the 144-byte layout. I extended the MSAA fixture to select this PR’s set-1 shaders when the adapter reports fewer than 144 push-constant bytes. The 4× resolve matched all 4,096 pixels, the one-sample mask passed, and the mismatched target was rejected. No Vulkan validation errors in the passing runs.

The attached patch changes only the MSAA fixture and its CMake target. Synthetic inputs only. AI-assisted.

msaa-128-byte-test.patch.txt

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head 5fbd998 merged onto main 4947579 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 116 | new failures vs main: none. The main baseline on the same machine passes 107/107; the PR adds its own tests on top.

AI-assisted (Claude Code); runs on my machine.

@RipcuBAN

Copy link
Copy Markdown
Contributor

Independent verification of head 5fbd9987 (base 49475796), requested in #166 for the 128-byte push-constant hardware. AI-assisted run; synthetic shaders only, no game files.

Hardware / environment. Windows 10 build 19045, VS 2026 Community (Visual Studio 18 2026, x64), MSVC 19.51.36260, CMake 4.5.0-rc3, MSYS2 glslangValidator.

  • AMD Radeon(TM) Graphics, Ryzen 5 7600X iGPU (Raphael, gfx1036 / RDNA2), driver 23.40.02, wave64, maxPushConstantsSize = 128.
  • NVIDIA GeForce RTX 3060, driver 621.14, wave32, maxPushConstantsSize = 256.

A fresh build in a new build directory completed with 0 errors. I did not need to merge #2046: the runtime tests use the hand-written PC_TAIL GLSL variants committed in this PR, so this run does not exercise the translator's --pc-tail-ubo path end to end.

Full ctest -C RelWithDebInfo -j 6 --output-on-failure, compared against main 49475796 built and run on the same machine:

tree AMD iGPU (128 B) RTX 3060 (256 B)
main 49475796 99/107; 8 failed 106/107; 1 failed
PR 5fbd9987 101/107; 6 failed 105/107; 2 failed

The 8 AMD failures on main were d3d12_compute, d3d12_fspx_compute, d3d12_draw, d3d12_msaa_draw, d3d12_set0_compute, d3d12_pipeline_library, d3d12_typeless_rtv and d3d12_vulkan_device. With this PR, d3d12_compute and d3d12_draw pass on the real 128-byte device; the other six are unchanged from main. Four of those still print pipelines need 144 bytes of push constants ... maxPushConstantsSize is 128 (d3d12_fspx_compute, d3d12_msaa_draw, d3d12_set0_compute, d3d12_pipeline_library). d3d12_typeless_rtv and d3d12_vulkan_device fail with the same host/WARP comparison symptoms as on main.

Verbose runs of the two changed tests:

  • AMD, d3d12_compute: the simulated 128-byte device refuses the 144-byte PSO with E_NOTIMPL; the --pc-tail-ubo PSO is built on the real 128-byte device and 64/64 elements match there and on the host GPU. The 144-byte dispatch/CBV passes are skipped because this GPU reports 128 bytes.
  • AMD, d3d12_draw: the tail VS (no pc_tail) plus PS (set-1 tail) PSO is built on the real 128-byte device and 4096/4096 pixels match there and on the host GPU. The 144-byte graphics passes are skipped for the same reason.
  • RTX 3060: both tests pass all their 144-byte and tail paths; the tail compute gives 64/64 elements and the tail draw gives 4096/4096 pixels.

The extra NVIDIA failure, d3d12_depth_resolve, is a parallel-run flake: it fails once under -j 6 with ResolveSubresourceRegion refused / CreateCommandQueue output, but passes 5/5 in isolation on both the PR build and main (--repeat until-fail:5, -j 1). It is not caused by this PR.

Bottom line: this is the first run of the D3D12 tail path on the coordinator's 7600X iGPU, and it confirms the compute and graphics tail paths work on real 128-byte hardware. The remaining six AMD failures need tail variants in their own synthetic shaders; that is outside this PR's stated scope.

@aguedou-34

Copy link
Copy Markdown

Tested 5fbd99877d7caa90c22a3e0b18b476c3a7e52919 on Windows 11 build 26300.9974 with Vulkan validation enabled.

  • Ryzen 7 5800H Radeon iGPU, driver 31.0.21921.1000, physical 128-byte limit: shader_library, d3d12_compute and d3d12_draw passed. The fallback matched 64/64 compute values and 4,096/4,096 pixels. On base 49475796c226c8511b9470bf97a4daf57b8af323, compute and draw failed at 144-byte PSO creation.
  • A test-only ExecuteIndirect probe on the Radeon matched 64/64 values at argument offset 64 with no count buffer. The zero-offset control failed as expected. The original test was restored and rerun successfully.
  • The same three stock tests passed on the RTX 3070 Laptop, driver 591.59. No Vulkan validation errors in the passing runs.

Synthetic inputs only. Tested with assistance from OpenAI Codex.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (MSVC 14.51, llvm-mc 23.1.6): pass. ctest: 124/124 on the RTX 4080 SUPER. On the Intel UHD 770 only the known d3d12_descriptor, d3d12_present and d3d12_subgroup fail (#2516).

@ghost

ghost commented Nov 22, 2026

Copy link
Copy Markdown

Hardware validation on Radeon RX 580, Windows x64, driver 31.0.21924.61, actual maxPushConstantsSize=128: d3d12_compute_test and d3d12_draw_test both exit 0 on this PR's exact head 5fbd998. I built it via https://github.com/aidity1377/Leonida/actions/runs/45048617750 and downloaded its runtime-windows artifact.

The artifact has CI-machine absolute shader paths. For this diagnostic I redirected only those fixture strings to the packaged generated/ directory in local copies of the two executables. This preserves their compiled test/runtime code and fixtures. Both tests then pass on the physical 128-byte device. Clean main's equivalent tests reach PSO creation and refuse the 144-byte push-constant requirement on the same device.

The CI run's Windows job failed d3d12_msaa_draw; Linux succeeded. The artifact was still produced. This is a focused compute/draw hardware result, not a full-suite pass. No game files. AI-assisted with Codex. Related fixture-path draft: #2500.

@QCFELIX

QCFELIX commented Nov 22, 2026

Copy link
Copy Markdown

Tested the whole series (#2046 8d89bfa6 + #2048 0ec464b0 + this PR 5fbd9987, merged locally onto 4947579 without conflicts) on a second real 128-byte device: AMD RX 580 (GCN4, Polaris), legacy Windows driver 22.20.27.09, Vulkan 1.3.217, maxPushConstantsSize 128, subgroup 64..64. Full entry: #166 (comment)

  • run_gpu_tests.py with LEONIDA_PC_TAIL_UBO=1: 91/185 → 142/185. 51 SKIP→PASS, no PASS→FAIL.
  • ctest: 104/124 on main → 106/124 with the series (d3d12_compute and d3d12_draw pass on the real device) → 113/124 with the build.py test shaders regenerated with LEONIDA_PC_TAIL_UBO=1 (d3d12_translated_draw, d3d12_m2_textured, d3d12_m2_formats, d3d12_m3_frame, d3d12_m3_first_pass, d3d12_m4_compute, d3d12_buffer_uav pass too).
  • Still refused at PSO creation ("translate the shaders with --pc-tail-ubo for this device"), since their shaders have no --pc-tail-ubo variant yet: d3d12_fspx_compute, d3d12_msaa_draw, d3d12_set0_compute, d3d12_pipeline_library, and the compute probe in d3d12_subgroup (generated at run time, line 590). They report a failure rather than a skip (77) on a 128-byte device.
  • No regression on a 256-byte device (RX 6800 XT, AMD 26.11.2): run_gpu_tests.py 170/185 both without and with the flag, test by test identical to main; ctest 124/124 with both kinds of test shaders.

AI-assisted (Claude Code); no validation layers in these runs.

@FaKL-Code

FaKL-Code commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 5fbd998 (merged onto main 4947579, on its own: #2046 is not in this tree; the runtime tests build their PC_TAIL shaders with glslang, so they do not need the translator side) 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): no new warnings (same C4201/C4456/C4996 set as main).
  • ctest -C RelWithDebInfo -j 4: 116/116 passed, d3d12_compute, d3d12_draw and shader_library included (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 and d3d12_state_map also pass with LEONIDA_VK_VALIDATION=1. So the --pc-tail-ubo set-1 compute path runs clean under the layer.
  • This GPU reports more than 128 bytes of push constants, so its own PSOs take the regular path. The tail path ran on real NVIDIA hardware through the tests' simulated 128-byte device (limited_info.max_push_constants_size = 128), not through a real 128-byte device. An RDNA2 iGPU on AMD's Windows driver would still be the real check.
  • Not covered: the current head d230040 is a rebase onto ec8ec4c (round 40). Its patch differs in the rebased parts, for example the CachedPSO block in d3d12_compute_test.cpp now sits in a new scope. This run doesn't cover that rebase.

AI-assisted (Claude).

RipcuBAN added a commit to RipcuBAN/Leonida that referenced this pull request Nov 22, 2026
Resolve runtime/test/d3d12_compute_test.cpp by keeping both sides: ItsNotRexed#2402's
dispatch_once helper and 128-byte tail path, and main's CachedPSO helpers and
host comparison. The CachedPSO block is nested in the fallback else branch
with the right indentation.

Rebuilt from scratch on VS 2026 x64: AMD 107/112 (main 100/112), NVIDIA
110/112 with the known d3d12_depth_resolve parallel flake (main 111/112).
No game data.

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

Copy link
Copy Markdown

Tested 5fbd998 on real 128-byte hardware: AMD Radeon(TM) Graphics, the Ryzen 9 7900X iGPU (RDNA2, gfx1036), AMD driver 24.10.24, Windows 11, maxPushConstantsSize 128. Pass, 0 validation errors.

Built the whole runtime with #2046 + #2048 + #2402 merged on 49475796 (merges cleanly), MSVC 14.50 (VS Build Tools 2026), Windows SDK 10.0.26100, Vulkan SDK 1.4.363, Ninja: 346/346 targets.

  • shader_library_test: ok.
  • d3d12_compute_test with LEONIDA_VK_VALIDATION=1: exit 0, 0 validation errors. "--pc-tail-ubo: a 128-byte device built the tail PSO and 64/64 elements matched there and on this GPU"; the 144-byte PSO, dispatch and CBV checks were skipped for 128 bytes.
  • d3d12_draw_test with LEONIDA_VK_VALIDATION=1: exit 0, 0 validation errors. "4096/4096 pixels matched there and on this GPU" (VS without pc_tail, PS with the set-1 tail); the 144-byte graphics passes were skipped.
  • Full ctest, LEONIDA_VK_DEVICE=AMD: main 4947579 fails 6 (d3d12_compute, d3d12_draw, d3d12_fspx_compute, d3d12_msaa_draw, d3d12_set0_compute, d3d12_pipeline_library); with this series 4 fail. This PR fixes d3d12_compute and d3d12_draw. The other four already fail on main: each builds a 144-byte PSO, which the layer refuses with E_NOTIMPL on this device as intended. That is a test gap, not this PR; I'll post it separately.
  • Full ctest, LEONIDA_VK_DEVICE=NVIDIA (RTX 3060 Ti, 610.88, 256 bytes): 100% of 116, 0 failed.

The same machine's run_gpu_tests.py result for #2048 is posted there (169/185 with the flag, 61 SKIP -> PASS).

AI-assisted. No game files.

@lunisahdidouch

Copy link
Copy Markdown

Tested d230040 on an RX 9070 (RDNA4), AMD 26.11.1 (LLPC), Vulkan 1.4.359, Windows 11: pass

Full ctest run: 129/129 passed (d3d12_compute and d3d12_draw included; gameinput off, no SDL3 in this build). Full run_gpu_tests.py: 175/189 passed, 14 skipped, nothing failed. AMD has more than 128 bytes of push constants so this doesn't exercise the set-1 fallback itself, but nothing regressed on the normal path. The earlier head 5fbd998 was clean too.

AI-assisted

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

I tested d2300403 on top of 03b09a08 on Debian 13. The local conflict resolution keeps current main's arena accounting, draw pipeline variants, geometry capability checks, and the newer compute SRV and draw instance-step assertions.

One rebase detail is easy to miss. Main's graphics stage table now has VS, GS and PS in that order. The two-entry user_data_layout call applies cleanly but excludes the PS after the rebase. I passed vs_stage.entry, gs_stage.entry and ps_stage.entry. I also used DeviceState::arena_shader for the tail's allocation and release, and kept PreparedDraw's selected pipeline handle when applying the new user-data binding.

  • Native shader_library and vk_command_replay CTests passed.
  • Windows clang-cl/xwin build with a static C++ runtime, run under Wine 10.0 on Mesa llvmpipe 25.0.7 (LLVM 19.1.7). shader_library_test, d3d12_draw_test and d3d12_compute_test all passed. The simulated 128-byte device refused the old 144-byte pipeline and accepted the tail path. The graphics tail fixture matched 4,096 pixels and the compute tail fixture matched 64 words, both on the simulated limit and the normal device. Khronos validation and synchronization validation reported zero errors. In the compute test I disabled Wine's d3dcompiler_47 to skip its separate host CachedPSO comparison.
  • As a compile-only check, Mesa 26.1.6 ANV accepted both the 144-byte and 128-byte-plus-UBO cs_buf_fmt8 translations on three Intel DRM-shim profiles (Alder Lake, DG2 and Battlemage). Those profiles reported 256 bytes. The constrained runtime result comes from the Wine tests above.

Synthetic fixtures only. Physical 128-byte hardware coverage is still pending. AI-assisted with Codex.

NiiRoZz pushed a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
The test's two stages declared one 144-byte push-constant range, so a device
whose maxPushConstantsSize is the 128-byte Vulkan minimum refused the PSO
(E_NOTIMPL at make_context) and none of the nine input-assembler bounds cases
ran there; the AMD Windows driver reports 128 bytes on RDNA2 iGPUs.

The fixtures now also come as a --pc-tail-ubo twin: the same GLSL compiled
with -DPC_TAIL, whose stages declare s0..s31 alone (128 bytes) and no set-1
tail, since neither stage reads a root argument. A device with room for both
layouts runs both and their probes must agree; one whose maxPushConstantsSize
is below 144 runs the twin alone, which is where the cases were measured on
RDNA2 hardware.

Case E is information only where the bounded and the unbounded layer pass
draw alike and the host differs: AMD's driver reads a vertex attribute past
its view instead of zeroing it, so the case is not the layer's to decide
there. A16, A32 and C keep their pass/fail condition on that device.

Stacked on ItsNotRexed#2402's head (d230040) with ItsNotRexed#2676 applied, because the test and
the layer path it needs are not on main yet.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
NiiRoZz added a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
…sh-constant devices

Both tests' shaders declared 144 push-constant bytes, so a device whose
maxPushConstantsSize is the 128-byte Vulkan minimum refused their PSOs and
neither reached its checks (d3d12_bundle_test.cpp:130 via make_pso).

d3d12_bundle reuses d3d12_draw_test's --pc-tail-ubo twins (vs_draw/ps_draw
compiled with -DPC_TAIL) from a second library folder, and runs every
scenario and the layer-only checks on a layer device limited to 128 bytes as
well as with the 144-byte shaders. d3d12_typeless_families gets a -DPC_TAIL
build of vs_fullscreen.vert (its pixel shaders declare no push constants) and
draws each case on both. A device below 144 bytes runs the twins alone. Both
layouts are held to the same grids or host bytes.

Tested with LEONIDA_VK_VALIDATION=1 on an RTX 5090 (NVIDIA 621.35) and an AMD
Radeon iGPU (AMD 26.5.2): bundles 10 scenarios with both layouts, 20 host
comparisons, 0 failures; typeless draws 16 of 16 equal the host;
d3d12_draw_test still passes. Both devices report 256 bytes, so the 128-byte
limit is simulated; a real 128-byte device has not run it.

Stacked on ItsNotRexed#3013 (and ItsNotRexed#2402), which add the fallback the twins need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NiiRoZz added a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
ItsNotRexed#2402's user_data_layout call took {stages[0], stages[1]}, written when a
graphics PSO's stages were {vs, ps}. Since ItsNotRexed#2109 they are {vs, gs, ps}, so on
main stages[1] is the (usually empty) GS slot: the PS's pc_tail never reached
the pipeline layout, set 1 was left out, and a --pc-tail-ubo PS failed
VUID-VkGraphicsPipelineCreateInfo-layout-07988 and drew nothing
(d3d12_draw_test line 358, d3d12_bundle's twin run). All three stages are
passed now; user_data_layout skips the absent ones. This is the same slip
81ec7f7 fixed for the f16 halves link.

Found rebasing ItsNotRexed#3106 onto main f847748. With it, d3d12_draw_test,
d3d12_bundle, d3d12_typeless_families, d3d12_ia_bounds and d3d12_compute pass
with LEONIDA_VK_VALIDATION=1 and no validation error on an RTX 5090 (NVIDIA
621.35) and an AMD Radeon iGPU (AMD 26.5.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NiiRoZz pushed a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
The test's two stages declared one 144-byte push-constant range, so a device
whose maxPushConstantsSize is the 128-byte Vulkan minimum refused the PSO
(E_NOTIMPL at make_context) and none of the nine input-assembler bounds cases
ran there; the AMD Windows driver reports 128 bytes on RDNA2 iGPUs.

The fixtures now also come as a --pc-tail-ubo twin: the same GLSL compiled
with -DPC_TAIL, whose stages declare s0..s31 alone (128 bytes) and no set-1
tail, since neither stage reads a root argument. A device with room for both
layouts runs both and their probes must agree; one whose maxPushConstantsSize
is below 144 runs the twin alone, which is where the cases were measured on
RDNA2 hardware.

Case E is information only where the bounded and the unbounded layer pass
draw alike and the host differs: AMD's driver reads a vertex attribute past
its view instead of zeroing it, so the case is not the layer's to decide
there. A16, A32 and C keep their pass/fail condition on that device.

Stacked on ItsNotRexed#2402's head (d230040) with ItsNotRexed#2676 applied, because the test and
the layer path it needs are not on main yet.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
NiiRoZz added a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
…sh-constant devices

Both tests' shaders declared 144 push-constant bytes, so a device whose
maxPushConstantsSize is the 128-byte Vulkan minimum refused their PSOs and
neither reached its checks (d3d12_bundle_test.cpp:130 via make_pso).

d3d12_bundle reuses d3d12_draw_test's --pc-tail-ubo twins (vs_draw/ps_draw
compiled with -DPC_TAIL) from a second library folder, and runs every
scenario and the layer-only checks on a layer device limited to 128 bytes as
well as with the 144-byte shaders. d3d12_typeless_families gets a -DPC_TAIL
build of vs_fullscreen.vert (its pixel shaders declare no push constants) and
draws each case on both. A device below 144 bytes runs the twins alone. Both
layouts are held to the same grids or host bytes.

Tested with LEONIDA_VK_VALIDATION=1 on an RTX 5090 (NVIDIA 621.35) and an AMD
Radeon iGPU (AMD 26.5.2): bundles 10 scenarios with both layouts, 20 host
comparisons, 0 failures; typeless draws 16 of 16 equal the host;
d3d12_draw_test still passes. Both devices report 256 bytes, so the 128-byte
limit is simulated; a real 128-byte device has not run it.

Stacked on ItsNotRexed#3013 (and ItsNotRexed#2402), which add the fallback the twins need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NiiRoZz added a commit to NiiRoZz/Leonida that referenced this pull request Nov 23, 2026
ItsNotRexed#2402's user_data_layout call took {stages[0], stages[1]}, written when a
graphics PSO's stages were {vs, ps}. Since ItsNotRexed#2109 they are {vs, gs, ps}, so on
main stages[1] is the (usually empty) GS slot: the PS's pc_tail never reached
the pipeline layout, set 1 was left out, and a --pc-tail-ubo PS failed
VUID-VkGraphicsPipelineCreateInfo-layout-07988 and drew nothing
(d3d12_draw_test line 358, d3d12_bundle's twin run). All three stages are
passed now; user_data_layout skips the absent ones. This is the same slip
81ec7f7 fixed for the f16 halves link.

Found rebasing ItsNotRexed#3106 onto main f847748. With it, d3d12_draw_test,
d3d12_bundle, d3d12_typeless_families, d3d12_ia_bounds and d3d12_compute pass
with LEONIDA_VK_VALIDATION=1 and no validation error on an RTX 5090 (NVIDIA
621.35) and an AMD Radeon iGPU (AMD 26.5.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ush-constant devices

A device whose maxPushConstantsSize is 128 (AMD Windows driver on RDNA2 iGPUs, some Intel Arc drivers; D3D-14's push_constants_need_fallback) cannot hold the 144-byte ShaderUserData push-constant block, so previously every D3D12 PSO was refused there with E_NOTIMPL.

With --pc-tail-ubo (PR ItsNotRexed#2046), translated shaders keep s0..s31 in 128 push-constant bytes and move the 16-byte tail (heap base, code base) to a uniform block at set 1, binding 0 when a stage reads it. This wires that path through the D3D12 -> Vulkan layer:

- runtime/src/shader_library.h: ShaderEntry parses pc_tail.bytes into pc_tail_bytes (tested in shader_library_test).
- runtime/src/vulkan_replay.h: ComputePipeline and GraphicsPipeline carry push_bytes, tail_set and tail_offset; detail::bind_user_data binds set 0 (if present), set 1 with dynamic offset (if present), and pushes push_bytes at all three push sites (ExecuteIndirect dispatch, Dispatch, Draw); the three unsupported checks cover tail_set.
- runtime/shims/d3d12_vulkan_device.cpp: DeviceState::pc_tail creates one UNIFORM_BUFFER_DYNAMIC descriptor over the arena (range 16) plus an empty set-0 layout once per device. PipelineState::user_data_layout sizes the push-constant range from each stage's push_constant_bytes / pc_tail_bytes (so a --pc-tail-ubo stage that reads neither heap nor code base still fits 128 bytes), adds set 1 when any stage has pc_tail, writes the 16-byte tail once into the arena, and releases it on destruction. 144-byte shaders remain refused on <144-byte devices with a log pointing to --pc-tail-ubo.
- Tests: d3d12_compute_test and d3d12_draw_test verify 144-byte refusal and --pc-tail-ubo dispatch/draw (including VS without pc_tail + PS with set-1 tail) on both simulated 128-byte devices and the host GPU, and skip the 144-byte passes when run on a real 128-byte device.
- Docs: docs/d3d12_vulkan.md (sections 3.2, 5.2, Q13) and d3d12_com.h comment updated.

Step 3 of the uniform-buffer tail claimed in ItsNotRexed#1902.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Gemini 4 Neon <noreply@google.com>
@whoalin1

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main (561b65a83, new head 190e685a6).

Thanks @ddm-j and @iurysf for catching the silent rebase hazard: create_graphics now passes all three stages (user_data_layout({stages[0].entry, stages[1].entry, stages[2].entry}, user)), keeps the geometryShader guard on graphics_.push_stages, preserves vk.bindless_set in detail::bind_user_data, passes DeviceState::arena_shader for tail_offset_, and keeps the updated s[4]/s[5] compute layout in cs_user_data.comp.

Rebuilt (RelWithDebInfo, Ninja, MSVC 2022, 0 warnings in touched files) and re-verified with LEONIDA_VK_VALIDATION=1 (0 validation errors):

  • shader_library_test: pass
  • NVIDIA RTX 4070 SUPER (256 B push constants): d3d12_vulkan_device_test, d3d12_compute_test (64/64 on 128 B tail + host + 144 B passes), d3d12_draw_test (4096/4096 on 128 B tail + host + M1 144 B passes), d3d12_bundle_test, d3d12_geometry_test (VS+GS+PS, 4096/4096) — all pass.
  • AMD Ryzen 5 7600 iGPU (128 B push constants): d3d12_vulkan_device_test, d3d12_compute_test (64/64 on 128 B tail, 144 B skipped), d3d12_draw_test (4096/4096 on 128 B tail, 144 B skipped) — all pass.

AI-assisted.

whoalin1 added a commit to whoalin1/Leonida that referenced this pull request Nov 23, 2026
The test's two stages declared one 144-byte push-constant range, so a device
whose maxPushConstantsSize is the 128-byte Vulkan minimum refused the PSO
(E_NOTIMPL at make_context) and none of the nine input-assembler bounds cases
ran there; the AMD Windows driver reports 128 bytes on RDNA2 iGPUs.

The fixtures now also come as a --pc-tail-ubo twin: the same GLSL compiled
with -DPC_TAIL, whose stages declare s0..s31 alone (128 bytes) and no set-1
tail, since neither stage reads a root argument. A device with room for both
layouts runs both and their probes must agree; one whose maxPushConstantsSize
is below 144 runs the twin alone, which is where the cases were measured on
RDNA2 hardware.

Case E (partial vertex, vertex_extra_bytes != 0) is information only where
the bounded and the unbounded layer pass draw alike and the host differs:
AMD's driver reads a vertex attribute past its view instead of zeroing it, so
the case is not the layer's to decide there. The informational rule is scoped
to partial-vertex cases only so A16, A32, C and B1..B3 always fail if the
sized index bind or whole-vertex bounds regress.

Stacked on ItsNotRexed#2402's head (190e685) with ItsNotRexed#2676 (5547bbc) applied, because
the test and the layer path it needs are not on main yet.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@AimLogin

Copy link
Copy Markdown
Contributor

@whoalin1, a heads-up on how this PR interacts with #5128 (SHADER-67, mine). It is open, so it only matters for whichever of the two lands second. The fix is a few lines in either PR.

What changes. After #5128, leonida::ShaderUserData is 160 bytes, not 144. A pixel shader that reads its code base gets its own slot at dwords 38–39 (vulkan_replay.h:780). The 144-byte block is named separately as leonida::shader_user_data_bytes (:781). Compute layouts keep 144 (d3d12_vulkan_device.cpp:3275). A graphics layout grows to 160 only when a stage declares push_constant_bytes 160 (:2808).

Where they meet. At 190e685a6, user_data_layout() takes its full size from sizeof:

I merged your head with my local integration of #5128 on the same main (561b65a83), file by file with git merge-file. vulkan_replay.h and d3d12_vulkan_device.cpp conflict in several places, including your static_assert(sizeof(ShaderUserData) == 144) against mine. Those two sizeof lines merge without a conflict. Kept as they are, after both PRs:

  • Every layout without a tail is 160 bytes, compute included. A 144-byte shader's need is kFull (:2879).
  • No VUID shows it, because 160 bytes are pushed into a 160-byte range. But a device whose maxPushConstantsSize is 144–159 would refuse every pipeline, not only the ones with a code-base PS.
  • vk_pipeline_check's compute layout (144) would no longer match the runtime's.
  • push_constants_fit() is rewritten on both sides, so that part shows up as a conflict anyway.

Suggested resolution, whoever is second:

  • kFull and the UserDataLayout default become leonida::shader_user_data_bytes (144).
  • A stage's need is its own push_constant_bytes when that is above 128, not kFull. A code-base PS then asks for 160 and everything else for 144.
  • Refuse push_constant_bytes > sizeof(leonida::ShaderUserData) (160).
  • Keep a single push_bytes field in GraphicsPipeline/ComputePipeline. Both PRs add one.

Under --pc-tail-ubo nothing conflicts. There the translator keeps every stage's code base at dword 34, which is dwords 2–3 of the tail (rdna2spirv.py code_base_dword). Your single 16-byte tail per pipeline stays correct, and a VS+PS code-base pair is still refused as a collision. Locally I've also added a static_assert(shader_user_data_bytes == offsetof(ShaderUserData, mesh_output)) to #5128, next to the constant, with a note that layout sizes must not come from sizeof. It isn't pushed yet.

What I checked: the file-level merge above, and reading both diffs. I have not built or run the combination. If #2402 lands first, I'll make this change on #5128's side.

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

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.