shader: size compute root constants from the pipeline's root signature #114

Manually merged
github merged 1 commit from github-bot/gh-114 into main 2026-11-26 17:21:09 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 17:07 UTC · original
Olima34:feat/compute-root-constant-counts → main · +311 −32 · 6 files · 1 commits · merged 2026-11-26 17:16 UTC

Follow-up to d02869f, as discussed on #4: compute root constants take their exact size from the pipeline's root signature instead of the guess.

Why. An FSPX metadata record gives a root parameter's first user-data dword, not its size. d02869f guesses the size as "up to the next slot's first SGPR, or 1 for a trailing block". That guess is wrong after a gap (it takes the gap's SGPRs) and for a trailing multi-dword block (it stays 1 dword).

What.

  • pipeline::create_compute_pieces (0x218): when desc's root signature is one of ours, its blob (root::blob_of, read back from the object root::create made) goes into the FSPX part as one more entry of our own, native::FSPX_ROOT_SIGNATURE (RTS0).
  • native::fspx_program takes each record's Num32BitValues from it (RTS0 1.0 to 1.2, bare or in a DXBC container). metadata_resources now takes the size per slot instead of a bool.
  • With a root signature, a count that disagrees with the program is refused rather than read wrong, under root type 0:
    • root constants the root signature does not size;
    • root constants overlapping another root parameter;
    • root constants past the user SGPRs.
  • Without one (a container not made by 0x218, a root signature that is not ours, an unreadable blob), d02869f's guess stays as the fallback. Graphics keeps the guess.
  • The translation cache keys on the whole container, so the new entry is part of the key.

Guess (marked in code and docs). The console puts all N dwords of a constant in consecutive user SGPRs from the record's dword. The checks above catch a count that contradicts the other records or the SGPR count.

Tests.

  • compute_root_constants_reach_the_user_data: a 4-dword block followed by a gap; dword 2 (s6) is read. With the root signature, it maps to slot 1 dword 2. Without it, the guess sizes the block at 1 dword and s6 is refused.
  • root_signatures_keep_their_blob (macOS).
  • compute_container with and without the entry.

victory-shader and victory-gpu tests (arm64), Windows clippy and cargo xtask policy pass. Not verified in game (I don't have it yet): a story-load run should show no root type 0 refusals and no change in the shaders that already translate.

**@⁠Olima34** on GitHub · 2026-11-26 17:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/114) `Olima34:feat/compute-root-constant-counts` → `main` · +311 −32 · 6 files · 1 commits · merged 2026-11-26 17:16 UTC Follow-up to d02869f, as discussed on #4: compute root constants take their exact size from the pipeline's root signature instead of the guess. **Why.** An FSPX metadata record gives a root parameter's first user-data dword, not its size. d02869f guesses the size as "up to the next slot's first SGPR, or 1 for a trailing block". That guess is wrong after a gap (it takes the gap's SGPRs) and for a trailing multi-dword block (it stays 1 dword). **What.** - `pipeline::create_compute_pieces` (0x218): when `desc`'s root signature is one of ours, its blob (`root::blob_of`, read back from the object `root::create` made) goes into the FSPX part as one more entry of our own, `native::FSPX_ROOT_SIGNATURE` (`RTS0`). - `native::fspx_program` takes each record's `Num32BitValues` from it (RTS0 1.0 to 1.2, bare or in a DXBC container). `metadata_resources` now takes the size per slot instead of a bool. - With a root signature, a count that disagrees with the program is refused rather than read wrong, under `root type 0`: - `root constants the root signature does not size`; - `root constants overlapping another root parameter`; - `root constants past the user SGPRs`. - Without one (a container not made by 0x218, a root signature that is not ours, an unreadable blob), d02869f's guess stays as the fallback. Graphics keeps the guess. - The translation cache keys on the whole container, so the new entry is part of the key. **Guess (marked in code and docs).** The console puts all N dwords of a constant in consecutive user SGPRs from the record's dword. The checks above catch a count that contradicts the other records or the SGPR count. **Tests.** - `compute_root_constants_reach_the_user_data`: a 4-dword block followed by a gap; dword 2 (s6) is read. With the root signature, it maps to slot 1 dword 2. Without it, the guess sizes the block at 1 dword and s6 is refused. - `root_signatures_keep_their_blob` (macOS). - `compute_container` with and without the entry. victory-shader and victory-gpu tests (arm64), Windows clippy and `cargo xtask policy` pass. Not verified in game (I don't have it yet): a story-load run should show no `root type 0` refusals and no change in the shaders that already translate.
FSPX metadata records name the first user-data dword of a root parameter,
not its size. d02869f guesses the size of compute root constants as up to
the next slot's first SGPR, or one dword when that slot has no record; the
guess is wrong after a gap or for a trailing block. Device method 0x218 now
puts the blob of the pipeline's root signature into the FSPX part as an
entry of our own (RTS0), and fspx_program takes each slot's Num32BitValues
from it. The guess stays only for programs without a readable root
signature. With one, a constant is refused when the root signature does not
size its slot, or when its SGPRs would run into another parameter or past
the user SGPRs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:09:33 +00:00
github manually merged commit d5c8e9e468 into main 2026-11-26 17:21:09 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 17:17 UTC · original

Merged in 182c14f. The root-signature sizing, the three refusal reasons, the d02869f fallback and the cache keying all read correctly, and the new tests pass. Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 17:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/114#issuecomment-7198768170) Merged in 182c14f. The root-signature sizing, the three refusal reasons, the d02869f fallback and the cache keying all read correctly, and the new tests pass. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.