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

Merged
Olima34 merged 1 commit from upstream-pr/114 into main 2026-11-26 17:16:44 +00:00
Olima34 commented 2026-11-26 17:07:42 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T17:07:42Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6631620622 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/114). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T17:07:42Z. --- 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.
LakshanSivakumar commented 2026-11-26 17:17:00 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T17:17:00Z.


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!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198768170 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/114#issuecomment-7198768170). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T17:17:00Z. --- 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!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!114
No description provided.