Skip to content

Translator: --pc-tail-ubo moves the push-constant tail to a uniform block (128-byte push-constant devices, 1/3) - #2046

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
whoalin1:pc-tail-ubo
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
whoalin1:pc-tail-ubo

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 1 of 3.

What and why

A device whose maxPushConstantsSize is 128, Vulkan's minimum, can't take the translator's 144-byte push-constant block (152 with --mesh-compute). AMD's Windows driver reports 128 on RDNA2 iGPUs (Radeon 680M on 22.40.84.06, 610M on 24.10.16.14, and the Ryzen 5 7600's iGPU on 24.10.24 here), and so do some Intel Arc drivers. Today the D3D12 layer refuses every PSO on such a device "until the uniform-buffer tail exists" (80e5caca), and vk_harness crashes or hangs there (#1873). This PR is the translator side of that tail.

--pc-tail-ubo:

  • The push-constant block keeps s0..s31 only (128 bytes).
  • The tail that follows them by default (heap base, code base and, with --mesh-compute, the output address) becomes %pc_tail, a uniform block at set 1, binding 0, with the same members in the same order at offsets 0, 4, … (16 bytes, 24 with --mesh-compute). Set 1 is unused today, so set 0's update-after-bind table doesn't change.
  • The block is declared, and listed in the entry point's interface, only when the shader reads the tail: a memory access through the heap base, s_getpc_b64, or the --mesh-compute epilogue.
  • The index records "pc_tail": {"set": 1, "binding": 0, "bytes": 16} (24 with --mesh-compute), and "push_constant_bytes" is 128 for every module. "bindings" still lists set 0 only: the regex that builds it skips %pc_tail. mesh_compute_layout() reports pc_tail_address_dwords: [4, 5] in place of address_dwords.
  • All three tail reads go through one helper, pc_tail_chain(), so the flag changes the access chains and declarations and nothing else.

Without the flag the output is unchanged (checked below). docs/design.md gets a contract row ("Push-constant tail as a uniform block"), and the "User data" and "Metadata index" rows mention it.

Next steps, as claimed: (2) vk_harness/vk_compute_test bind the block when the index asks for it, with LEONIDA_PC_TAIL_UBO=1 for the runners, so a 128-byte device runs the tests that skip there today; (3) the D3D12 layer gives PSOs the set-1 layout and a per-PSO tail buffer instead of E_NOTIMPL when push_constants_need_fallback is set.

Tested

AI-assisted (Claude Code). Windows 11, Python 3.14.4, llvm-mc 21.1.8 (WSL Ubuntu 26.04), SPIRV-Tools v2026.4. No game files.

On GPUs, through step 2's test programs that bind the block (branch whoalin1:pc-tail-gpu-compute, its PR follows), run_gpu_tests.py, whole suite:

device LEONIDA_PC_TAIL_UBO unset LEONIDA_PC_TAIL_UBO=1
AMD Radeon Graphics (Ryzen 5 7600 iGPU, RDNA2), driver 24.10.24, maxPushConstantsSize 128 85/173 passed, 88 skipped, 0 failed 160/173 passed, 11 skipped, 2 failed
NVIDIA RTX 4070 SUPER, driver 610.88, 256 bytes 133/173 passed, 40 skipped, 0 failed 133/173 passed, 40 skipped, 0 failed

With the flag, 75 tests that skip on the 128-byte device run and pass, every compute, pixel, vertex, mesh and geometry test among them reading the heap base from the block. On NVIDIA the result is identical either way. The two AMD failures aren't from the block:

  • ms_clip still crashes in vk_harness with a valid 128-byte layout, so GPU tests: vk_harness skips a device with fewer push-constant bytes than it pushes #1873's push-constant range isn't the whole story (SHADER-167 tracks ms_clip crashing on this driver family).

  • ps_gather_wrap (it never ran on this device before) gets zeros in exactly the cases whose wrap or mirror coordinate is negative going into OpSMod. The address-mode arithmetic (Gen.gather_addr) isn't touched here, and NVIDIA passes the same module. I'm looking into it separately.

  • tests/test_pc_tail_ubo.py (new, 8 tests): the default is unchanged; with the flag, the push-constant block is 128 bytes and every tail read goes through %pc_tail at set 1, binding 0, which is in the interface; the function body is otherwise identical to the default's; s_getpc_b64 reads code base members 2/3; a shader with no tail read declares no block; the --mesh-compute output address is members 4/5 (24 bytes); and the metadata. Each module passes spirv-val.

  • All 185 hand-written GPU test shaders (runtime/test/shaders/build.py, with the flag added to its translator call): every one translates and passes spirv-val. Without the flag, all 185 report 144 push-constant bytes and none has pc_tail. With it, all 185 report 128, and 109 have pc_tail (16 bytes). The set-0 bindings lists are identical in all 185.

  • python -m pytest tests/test_mesh_compute.py tests/test_shader_index.py tests/test_translate.py: 510 passed, 2 skipped.

  • python -m unittest discover -s tests/semantic: 1644 OK.

  • python -m pytest tests --ignore=tests/semantic: 4422 passed, 66 skipped, 5 failed. All 5 fail on main (6a6704d) too: two test_cf_ref subtests (fixed by test_cf_ref: drop exec_hi from the Unsupported list now that cf_ref models it #1852) and three test_world_names subtests (world_names test: check the overwrite diagnostic for the path as printed #1848).

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.

🤖 Generated with Claude Code

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 6489f630 merged onto current main 4eb6155d (clean auto-merge; the branch is 204 commits behind) on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), Vulkan SDK 1.4.363, llvm-mc 23.1.6: pass, without the flag.

  • run_gpu_tests.py: 136/180 passed, 44 skipped, 0 failed, same as main.
  • tests/semantic: 1671 OK, same as main.

AI-assisted (Claude Code).

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

Reviewed the translator change and its contract/test coverage. The 128-byte tail layout is isolated behind the opt-in flag, preserves set 0, and the reported GPU/semantic checks cover the new rule. I found no blocking defect. I did not run tests; this approval covers step 1, with the separate Vulkan binding and D3D12 PSO integration still tracked as follow-ups.

@Impre-visible

Copy link
Copy Markdown

Tested 6489f63 (as is, base 6a6704d) on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18), llvm-mc 23.1.5, SPIRV-Tools v2026.4: pass. This device has more than 128 bytes of push constants, so it only checks that the default is unchanged and that the flag's output is valid; it cannot run the modules with the tail in a uniform block (that is #2048).

  • Default unchanged: build.py at this head against main 6a6704d: 185 test modules on both sides, all 185 byte-identical.
  • With --pc-tail-ubo, repository test shaders (the 178 listings run_gpu_tests.py assembles): 178 translated, 178 pass spirv-val; push_constant_bytes is 128 for all 178, and 108 carry pc_tail.
  • With --pc-tail-ubo, a slice of the real corpus (my own 1.0.2.1 copy, counts only; --limit 200): 200 translated, 200 pass spirv-val with the flag, and 200 / 200 without it; push_constant_bytes is 128 for all 200, and 194 carry pc_tail.
  • tests/test_pc_tail_ubo.py (pytest): 8 passed; tests/semantic: 1644 OK
  • Native build of runtime/ from this head; run_gpu_tests.py: 178/178 translated and pass spirv-val; 133/173 passed, 40 skipped, 0 failed; with LEONIDA_W64_EMULATE=1: 164/173 passed, 9 skipped (8 fixtures run by the d3d12 tests, 1 needs a 64-wide fragment subgroup), 0 failed

AI-assisted run (Claude). Counts only; nothing from the game leaves this machine.

@AvantBras

Copy link
Copy Markdown
Contributor

Tested the rebased head 8d89bfa6471a8a95d8ef65fa8b458dc4701129f6 (earlier results in this thread are at 6489f630) on Pop!_OS 22.04 / Python 3.12, RTX 3060 12 GB, NVIDIA 580.178.04.

  • tests/test_pc_tail_ubo.py (pytest): 8/8. Those translate the real fixtures cs_store and ps_m15 both ways, so the flag's module shape, the spirv-val result and the pc_tail metadata are covered by them.
  • Full scripts/run_gpu_tests.py run at this head, all six harnesses built at main 49475796: 137/185 passed, 48 skipped, zero failures — the same counts as main itself on that build, so the default (no-flag) path is unchanged by the rebase.

Scope: I did not run the flag on the GPU. run_gpu_tests.py at this head has no LEONIDA_PC_TAIL_UBO knob, and vk_compute_test binds no set-1 block, so the 128-byte translation has no harness to run through until #2048's harness commit lands on top of this one.

No game files. AI-assisted verification.

…lock for 128-byte devices

A device whose maxPushConstantsSize is 128, Vulkan's minimum (AMD's Windows driver on RDNA2 iGPUs, some
Intel Arc drivers), can't take the 144-byte block (152 with --mesh-compute). With --pc-tail-ubo the
push-constant block keeps s0..s31 (128 bytes), and the tail that follows them by default (heap base, code
base, the --mesh-compute output address) becomes %pc_tail, a uniform block at set 1, binding 0, with the same
members in the same order. It is declared only when the shader reads the tail; the index records "pc_tail"
and 128 push-constant bytes, and "bindings" still lists set 0 only. Without the flag nothing changes.

Step 1 of the uniform-buffer tail claimed in ItsNotRexed#1902; the GPU harnesses and the D3D12 layer that bind the
block follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
whoalin1 added a commit to whoalin1/Leonida that referenced this pull request Nov 22, 2026
…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>
@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested bf1c90e on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 175/189 passed, 14 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base ec8ec4c on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 4137 OK
  • tests/test_pc_tail_ubo.py: 8 passed in 0.17s
  • Both GPUs report maxPushConstantsSize 256 under RADV, so this run shows no regression; it doesn't exercise the 128-byte path the flag is for.

No game files. AI-assisted.

@crastinator

Copy link
Copy Markdown
Contributor

Tested bf1c90e as part of the stack below on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

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

NiiRoZz pushed a commit to NiiRoZz/Leonida that referenced this pull request Nov 22, 2026
…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>
@ItsNotRexed
ItsNotRexed merged commit 2ca3ab5 into ItsNotRexed:main Nov 22, 2026
NiiRoZz pushed a commit to NiiRoZz/Leonida that referenced this pull request Nov 22, 2026
…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>
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