Skip to content

OLD-8904: restore old upstream PR 8904 - root_signature: accept root constants of 0 values, as the host does (D3D-942) - #657

Merged
aslan2142 merged 4 commits into
ProjectLeonida:mainfrom
aslan2142:root-constants-zero
Nov 25, 2026
Merged

aslan2142 merged 4 commits into
ProjectLeonida:mainfrom
aslan2142:root-constants-zero

Conversation

@aslan2142

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue as: OLD-8904 #14 (comment)

Restoration of my original pull request, old upstream PR 8904 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bc; no changes beyond the rebase.

Depends on: #420 (adjacent-line conflict in pack_stage(); either order resolves easily)

What and why

  • pack() and pack_stage() in runtime/src/root_signature.cpp refused a 32-bit-constants parameter with Num32BitValues == 0. So CreateRootSignature failed where host D3D12 answers S_OK. The serializer warns for versions 1.0 and 1.1, and both devices still create the root signature.
  • Such a parameter now takes no dwords and adds nothing to the cost:
    • In pack() it gets no provenance entry.
    • In pack_stage() it shares its first SGPR with the next parameter, so no other offset changes.
  • No zero-size Vulkan push-constant range is created, because the range is the fixed ShaderUserData block, not one range per parameter. The command list already refuses any write past a parameter's constant count.
  • 65 constants are still refused by the 64-dword cost limit.
  • New cases in root_signature_test (both packers):
    • zero-value constants alone, between other parameters, and in a hand-built RTS0 blob;
    • 64 constants pass the cost limit and are refused only as a spill;
    • 65 constants are refused by the cost limit.

Tested

Built and run on Linux. The Windows build used clang targeting x86_64-w64-mingw32 and ran under Wine 11.22. The same files were also built natively for Linux with clang. MSVC (/W4 /permissive-) is left to CI.

  • root_signature_test on main unchanged: 56 pass, 0 fail.
  • This branch's tests built against main's code: 58 pass, 8 fail (the 8 zero-value cases).
  • This branch: 66 pass, 0 fail, under Wine and natively.
  • git diff --check and scripts/check_no_game_data.py on the changed files: clean.

GPUs tested: n/a (the test needs no GPU)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

…D3D-942)

pack() and pack_stage() refused a 32-bit-constants parameter with Num32BitValues == 0, so CreateRootSignature
failed where host D3D12 answers S_OK (the serializer warns for versions 1.0 and 1.1; both devices create it).
Such a parameter now takes no dwords and no cost: it gets no provenance entry in pack(), and in pack_stage() it
shares its first SGPR with the next parameter, so every other offset is unchanged. The Vulkan push-constant range
is the fixed ShaderUserData block, not per parameter, so no zero-size range is created; the command list already
refuses any write past a parameter's constant count. 65 constants stay refused by the 64-dword cost limit.

root_signature_test: zero-value constants alone, between other parameters and from a hand-built RTS0 blob (both
packers); 64 constants pass the cost limit and are refused only as a spill; 65 by the cost limit.

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

Copy link
Copy Markdown
Contributor

Reviewed a634430. I built and ran the real root_signature_test (CMake + Ninja, g++, Release, Linux arm64 sandbox):

  • This branch: all checks pass, rc 0.
  • The PR's test file on a main worktree: rc 1 with 8 failures, all of them the new zero-value-constant cases (e.g. pack_stage: zero-value constants accepted). The new tests exercise the fix.

The branch also merges cleanly into current main (b4b7756).

I read the diff and the main consumer path (CreateRootSignature -> RootArgumentLayout -> the root-constant writes). A 0-value constant parameter keeps constant_count 0. The bounds check refuses any nonzero write to it, so the SGPR it shares with the next parameter is never written through it.

One consistency note, not blocking: tools/root_sig_contract.py:23 says its packing "mirrors runtime/src/root_signature.{h,cpp}". It still refuses constants with count 0 (:70, "constants need an integer count >= 1"), so after this PR it rejects a signature the runtime accepts. This could be a small follow-up. I could not check the host claim (serializer warns, CreateRootSignature returns S_OK) here.

AI-assisted review.

Recommendation: Merge

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
aslan2142 and others added 3 commits November 25, 2026 16:40
main's pack_stage now spills trailing compute parameters into the array
behind s[0:1] and refuses an unknown parameter type. Keep both; drop only
the zero-value constant refusal, as this branch does. A zero-value
constant takes no SGPRs and no spill dwords, and a new case checks the
spill offsets around one. The old "32-SGPR budget refuses before the
cost limit" comment no longer holds with spilling and goes; main's
over-cost case replaces it.

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

tools/root_sig_contract.py says its packing mirrors
runtime/src/root_signature.{h,cpp}, but it still refused a constant
parameter with count 0, so after this branch it rejected a signature the
runtime accepts. Accept count >= 0; a zero count adds no dwords and its
neighbours pack as if it were absent, in both the s0 and the console
layout. Raised in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a spill for pixel

This branch's check expected pack_stage(Compute) to refuse 64 constants
as an unmodelled spill. main's pack_stage now spills trailing compute
parameters behind s[0:1], so compute takes them (cost 64, one spilled
parameter of 64 dwords). The "refused only as a spill, not for cost"
check moves to a pixel shader, where a spill is still refused.

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

Copy link
Copy Markdown
Collaborator Author

Merged: root_signature accepts root constants of 0 values, as the host does (D3D-942).

AI-assisted (Claude Code, Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants