OLD-2402: Runtime: D3D12 PSOs bind the --pc-tail-ubo set-1 block for 128-byte push-constant devices #767

Open
github-bot wants to merge 1 commit from github-bot/gh-767 into main AGit
Owner

@⁠whoalin1 on GitHub · 2026-11-24 13:35 UTC · original
whoalin1:pc-tail-runtime → main · +967 −340 · 12 files · 1 commits · open

Restores my open PR from the original repository (OLD-2402), rebased onto current main (2d73c242f).

Claim: #14

Summary

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

With --pc-tail-ubo (already merged in main), 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 PR wires that path through the D3D12 → Vulkan layer:

  • runtime/src/shader_library.h: ShaderEntry parses pc_tail.bytes into pc_tail_bytes (covered by 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, Draw).
  • 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 (including VS+GS+PS), 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.
  • runtime/test/d3d12_compute_test.cpp & runtime/test/d3d12_draw_test.cpp: 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 real 128-byte GPUs, skipping the 144-byte passes on real 128-byte hardware.
  • docs/d3d12_vulkan.md & runtime/shims/d3d12_com.h: documentation updates.

Verification (rebased on 2d73c242f, LEONIDA_VK_VALIDATION=1)

  • CPU: shader_library_test — pass (rc=0)
  • NVIDIA GeForce RTX 4070 SUPER (Windows 11, driver 610.88, 256B push constants):
    • d3d12_compute_test (rc=0, 0 validation errors)
    • d3d12_draw_test (rc=0, 0 validation errors)
    • d3d12_bundle_test (rc=0, 0 validation errors)
    • d3d12_geometry_test (rc=0, 0 validation errors)
    • d3d12_mesh_test (LEONIDA_VK_VALIDATION=0, rc=0; VUID-07076 under validation is tracked separately in #506)
  • AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, Windows 11, AMD driver 24.10.24, real 128B maxPushConstantsSize):
    • d3d12_compute_test (rc=0, 0 validation errors): --pc-tail-ubo 64/64 elements matched on simulated 128B device and real 128B GPU; 144B passes cleanly skipped
    • d3d12_draw_test (rc=0, 0 validation errors): --pc-tail-ubo VS+PS (VS without pc_tail, PS with set-1 tail) 4096/4096 pixels matched on simulated 128B device and real 128B GPU; 144B passes cleanly skipped

AI-assisted (Gemini 4 Neon).

**@⁠whoalin1** on GitHub · 2026-11-24 13:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/767) `whoalin1:pc-tail-runtime` → `main` · +967 −340 · 12 files · 1 commits · open Restores my open PR from the original repository (OLD-2402), rebased onto current `main` (`2d73c242f`). Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 ### Summary A Vulkan device whose `maxPushConstantsSize` is 128 bytes (AMD Windows driver on RDNA2 iGPUs, some Intel Arc drivers) cannot hold the 144-byte `ShaderUserData` push-constant block, so previously every D3D12 PSO was refused there with `E_NOTIMPL`. With `--pc-tail-ubo` (already merged in `main`), 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 PR wires that path through the D3D12 → Vulkan layer: - `runtime/src/shader_library.h`: `ShaderEntry` parses `pc_tail.bytes` into `pc_tail_bytes` (covered by `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`, `Draw`). - `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` (including VS+GS+PS), 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`. - `runtime/test/d3d12_compute_test.cpp` & `runtime/test/d3d12_draw_test.cpp`: 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 real 128-byte GPUs, skipping the 144-byte passes on real 128-byte hardware. - `docs/d3d12_vulkan.md` & `runtime/shims/d3d12_com.h`: documentation updates. ### Verification (rebased on `2d73c242f`, `LEONIDA_VK_VALIDATION=1`) - **CPU**: `shader_library_test` — pass (`rc=0`) - **NVIDIA GeForce RTX 4070 SUPER (Windows 11, driver 610.88, 256B push constants)**: - `d3d12_compute_test` (`rc=0`, 0 validation errors) - `d3d12_draw_test` (`rc=0`, 0 validation errors) - `d3d12_bundle_test` (`rc=0`, 0 validation errors) - `d3d12_geometry_test` (`rc=0`, 0 validation errors) - `d3d12_mesh_test` (`LEONIDA_VK_VALIDATION=0`, `rc=0`; `VUID-07076` under validation is tracked separately in #506) - **AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, Windows 11, AMD driver 24.10.24, real 128B `maxPushConstantsSize`)**: - `d3d12_compute_test` (`rc=0`, 0 validation errors): `--pc-tail-ubo` 64/64 elements matched on simulated 128B device and real 128B GPU; 144B passes cleanly skipped - `d3d12_draw_test` (`rc=0`, 0 validation errors): `--pc-tail-ubo` VS+PS (VS without `pc_tail`, PS with set-1 tail) 4096/4096 pixels matched on simulated 128B device and real 128B GPU; 144B passes cleanly skipped AI-assisted (Gemini 4 Neon).
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 #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 #1902.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Gemini 4 Neon <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:20 +00:00
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 20:09 UTC · original

Rebased cleanly onto current main (db1a22d29) as a07b677bf to refresh the stale CI baseline; no conflicts. The branch remains the single pc-tail runtime/PSO binding change. AI-assisted with Devin.

**@⁠whoalin1** on GitHub · 2026-11-25 20:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/767#issuecomment-7173263502) Rebased cleanly onto current main (`db1a22d29`) as `a07b677bf` to refresh the stale CI baseline; no conflicts. The branch remains the single pc-tail runtime/PSO binding change. AI-assisted with Devin.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 21:07 UTC · original

Local dual-GPU verification of a07b677bf (rebased onto current main), full MSVC/Ninja runtime build 986/986 clean, then the pc-tail test executables run directly with LEONIDA_VK_VALIDATION=1 on both devices:

AMD Radeon(TM) Graphics — the 128-byte push-constant iGPU this PR is for (VK_LOADER_DRIVERS_SELECT=*amd-vulkan*):

  • d3d12_compute_test rc=0, 0 VUIDs — --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/CBV/SRV checks are skipped honestly (this GPU reports 128 push-constant bytes (< 144))
  • d3d12_draw_test rc=0, 0 VUIDs — --pc-tail-ubo graphics: a 128-byte device built the tail VS+PS PSO (VS without pc_tail, PS with set-1 tail) and 4096/4096 pixels matched; 144-byte graphics passes skipped honestly
  • shader_library_test rc=0

NVIDIA GeForce RTX 4070 SUPER (VK_LOADER_DRIVERS_SELECT=*nv-vk*):

  • d3d12_compute_test rc=0, 0 VUIDs — same tail-PSO 64/64 element match (the 128-byte simulated device cross-check plus this GPU)
  • d3d12_draw_test rc=0, 0 VUIDs — 4096/4096 pixels matched
  • shader_library_test rc=0

The set-1 uniform block is bound and read correctly by both drivers' shader pipelines; no validation noise on either. AI-assisted (Devin).

**@⁠whoalin1** on GitHub · 2026-11-25 21:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/767#issuecomment-7174646317) Local dual-GPU verification of `a07b677bf` (rebased onto current main), full MSVC/Ninja runtime build 986/986 clean, then the pc-tail test executables run directly with `LEONIDA_VK_VALIDATION=1` on both devices: **AMD Radeon(TM) Graphics — the 128-byte push-constant iGPU this PR is for** (`VK_LOADER_DRIVERS_SELECT=*amd-vulkan*`): - `d3d12_compute_test` rc=0, 0 VUIDs — `--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/CBV/SRV checks are skipped honestly (`this GPU reports 128 push-constant bytes (< 144)`) - `d3d12_draw_test` rc=0, 0 VUIDs — `--pc-tail-ubo graphics: a 128-byte device built the tail VS+PS PSO (VS without pc_tail, PS with set-1 tail) and 4096/4096 pixels matched`; 144-byte graphics passes skipped honestly - `shader_library_test` rc=0 **NVIDIA GeForce RTX 4070 SUPER** (`VK_LOADER_DRIVERS_SELECT=*nv-vk*`): - `d3d12_compute_test` rc=0, 0 VUIDs — same tail-PSO 64/64 element match (the 128-byte simulated device cross-check plus this GPU) - `d3d12_draw_test` rc=0, 0 VUIDs — 4096/4096 pixels matched - `shader_library_test` rc=0 The set-1 uniform block is bound and read correctly by both drivers' shader pipelines; no validation noise on either. AI-assisted (Devin).
github-bot force-pushed github-bot/gh-767 from 03a68645bf to a53ca73ca1 2026-11-26 14:53:32 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/767/head:github-bot/gh-767'
git switch 'github-bot/gh-767'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-767'
git switch 'github-bot/gh-767'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-767'
git switch 'github-bot/gh-767'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-767'
git switch 'main'
git merge --squash 'github-bot/gh-767'
git switch 'main'
git merge --ff-only 'github-bot/gh-767'
git switch 'main'
git merge 'github-bot/gh-767'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.