gpu, shader: a guessed pixel program's user SGPR count from its register image (#432) #455

Manually merged
github merged 1 commit from github-bot/gh-451 into gh-pr/451/base 2026-11-28 00:29:43 +00:00 AGit
Owner

@⁠lautarocherro on GitHub · 2026-11-27 20:14 UTC · original
lautarocherro:fix/ps-user-sgprs-from-image → main · +156 −31 · 4 files · 1 commits · merged 2026-11-28 00:28 UTC

What this changes

Refs #436.

A guessed pixel program's user SGPR count now comes from its register image.

  • The field. The 0x1c8 register image (pair 0) holds SPI_SHADER_PGM_RSRC2_PS. Its USER_SGPR field (bits 1-5) is the word at 0x3c when the image's word 1 is 4, and at 0x50 when it is 6 (graphics::ps_user_sgprs). The word 0x14 bytes later has the same field.
  • How it was found. One Series X run gave 23,044 images. In all 19,342 whose pixel program moves its primitive mask to M0 for interpolation, the field is that mask's SGPR, the one after the user SGPRs. That holds in the 952 where the mask sits above the last root parameter the metadata names, too. This is a guess from values, not a console document, and it is marked so in the code and in docs/native-host.md ("Pixel user SGPRs").
  • What uses it. The pixel container carries the count after the input enables (the enables word is 0 when the image gives none). A pixel program's last root constants reach the count, as compute's reach the count in COMPUTE_PGM_RSRC2 (constants_to_the_end). Without a count, your guess from ba51b833 stays: as far as the program reads on entry.
  • Why that matters. Your guess stops at an SGPR the program leaves unread. The Series X upscale program (effdd754ccbf3efd), which @⁠alexballvideos-netizen found is the only writer of the 2560x1440 picture (#258), reads its b500 as s9, s10 and s12. Its image gives 13 user SGPRs. On main it is refused as "a hardware SGPR input" (s12).

Not covered: 7 more pixel programs refused as "a hardware SGPR input" read their real primitive mask (s17, which the image confirms) for more than M0. That is a different problem.

How it was tested

  • cargo test -p victory-shader -p victory-gpu -p xtask (arm64, with the Metal Shader Converter): all pass. New tests:
    • graphics::tests::the_pixel_user_sgprs_are_read_from_the_register_image_by_its_kind
    • graphics::tests::a_pixel_programs_last_root_constants_reach_its_register_images_user_sgprs: the upscale program's shape (reads s9, s10 and s12). Without the count it is refused as "a hardware SGPR input"; with 13 its constants take s9 to s12 and it translates, also through the container.
  • Windows clippy on the workspace with -D warnings, and cargo xtask policy: pass.
  • Corpus: 21,579 shaders of a Series X run on main b998bb65, each pixel container rebuilt with its image's count (what the host now does at pipeline creation; 9,991 of 10,001 have an image, none disagree), tools/corpus/compare.sh against main:
    • 3 newly translated, all pixel and all "a hardware SGPR input": effdd754ccbf3efd, 6ceb02f77b5024e6, c371ae91d6e36c4a.
    • 0 regressions.
    • 1 changed output: 616aee4a0258dad2 reads s13 as a number. On main its primitive mask was guessed at s11, so s13 was above the initialized SGPRs and read 0. Its image gives 15 user SGPRs, so s13 is now the fourth dword of its root constants (s10 to s14).
  • Ran the game: Series X, headless, 200 s each, main b998bb65 against this branch with the same settings (M5 Pro, 48 GB, macOS 27.2.1). Both reached the time limit with no GPU errors.
    • On main, the upscale pipeline (vertex 7a7f9ab1d7449a22, pixel effdd754ccbf3efd) is refused, and 45 "draws dropped" lines name it.
    • With this change its pixel program translates and gets a host pipeline. Its hash is 781c6db63689ba78 here, because the container now carries the count. One draw is dropped, 0.7 s after its first bind, while the pipeline was still being built (it was ready 11.7 s later); none after that, for the last 80 s of the run.
    • Other pipelines refused as "a hardware SGPR input", the same in both runs: 4 whose vertex (mesh) programs are refused (3a0627643418e45d, 6856b09fdb1de38b, c19f3a46d6c1e89b, cf1751613af42af9), which is #419. Their pixel programs translate. The primitive-mask case above (8cb18f43378f99c9) was bound only in the main run.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none)
**@⁠lautarocherro** on GitHub · 2026-11-27 20:14 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/451) `lautarocherro:fix/ps-user-sgprs-from-image` → `main` · +156 −31 · 4 files · 1 commits · merged 2026-11-28 00:28 UTC ## What this changes Refs #436. A guessed pixel program's user SGPR count now comes from its register image. - **The field.** The 0x1c8 register image (pair 0) holds `SPI_SHADER_PGM_RSRC2_PS`. Its `USER_SGPR` field (bits 1-5) is the word at 0x3c when the image's word 1 is 4, and at 0x50 when it is 6 (`graphics::ps_user_sgprs`). The word 0x14 bytes later has the same field. - **How it was found.** One Series X run gave 23,044 images. In all 19,342 whose pixel program moves its primitive mask to M0 for interpolation, the field is that mask's SGPR, the one after the user SGPRs. That holds in the 952 where the mask sits above the last root parameter the metadata names, too. This is a guess from values, not a console document, and it is marked so in the code and in docs/native-host.md ("Pixel user SGPRs"). - **What uses it.** The pixel container carries the count after the input enables (the enables word is 0 when the image gives none). A pixel program's last root constants reach the count, as compute's reach the count in `COMPUTE_PGM_RSRC2` (`constants_to_the_end`). Without a count, your guess from ba51b833 stays: as far as the program reads on entry. - **Why that matters.** Your guess stops at an SGPR the program leaves unread. The Series X upscale program (`effdd754ccbf3efd`), which @⁠alexballvideos-netizen found is the only writer of the 2560x1440 picture (#258), reads its b500 as s9, s10 and s12. Its image gives 13 user SGPRs. On main it is refused as "a hardware SGPR input" (s12). Not covered: 7 more pixel programs refused as "a hardware SGPR input" read their real primitive mask (s17, which the image confirms) for more than M0. That is a different problem. ## How it was tested - [x] `cargo test -p victory-shader -p victory-gpu -p xtask` (arm64, with the Metal Shader Converter): all pass. New tests: - `graphics::tests::the_pixel_user_sgprs_are_read_from_the_register_image_by_its_kind` - `graphics::tests::a_pixel_programs_last_root_constants_reach_its_register_images_user_sgprs`: the upscale program's shape (reads s9, s10 and s12). Without the count it is refused as "a hardware SGPR input"; with 13 its constants take s9 to s12 and it translates, also through the container. - [x] Windows clippy on the workspace with `-D warnings`, and `cargo xtask policy`: pass. - [x] Corpus: 21,579 shaders of a Series X run on main `b998bb65`, each pixel container rebuilt with its image's count (what the host now does at pipeline creation; 9,991 of 10,001 have an image, none disagree), `tools/corpus/compare.sh` against main: - 3 newly translated, all pixel and all "a hardware SGPR input": `effdd754ccbf3efd`, `6ceb02f77b5024e6`, `c371ae91d6e36c4a`. - 0 regressions. - 1 changed output: `616aee4a0258dad2` reads s13 as a number. On main its primitive mask was guessed at s11, so s13 was above the initialized SGPRs and read 0. Its image gives 15 user SGPRs, so s13 is now the fourth dword of its root constants (s10 to s14). - [x] Ran the game: Series X, headless, 200 s each, main `b998bb65` against this branch with the same settings (M5 Pro, 48 GB, macOS 27.2.1). Both reached the time limit with no GPU errors. - On main, the upscale pipeline (vertex `7a7f9ab1d7449a22`, pixel `effdd754ccbf3efd`) is refused, and 45 "draws dropped" lines name it. - With this change its pixel program translates and gets a host pipeline. Its hash is `781c6db63689ba78` here, because the container now carries the count. One draw is dropped, 0.7 s after its first bind, while the pipeline was still being built (it was ready 11.7 s later); none after that, for the last 80 s of the run. - Other pipelines refused as "a hardware SGPR input", the same in both runs: 4 whose vertex (mesh) programs are refused (`3a0627643418e45d`, `6856b09fdb1de38b`, `c19f3a46d6c1e89b`, `cf1751613af42af9`), which is #419. Their pixel programs translate. The primitive-mask case above (`8cb18f43378f99c9`) was bound only in the main run. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none)
The 0x1c8 register image holds SPI_SHADER_PGM_RSRC2_PS. Its USER_SGPR
field (bits 1-5) of the word at 0x3c (kind 4) or 0x50 (kind 6) is the
pixel program's user SGPR count. In all 19,342 images of a Series X
run whose pixel program moves its primitive mask to M0, the field is
that mask's SGPR, also in the 952 where it sits above the last root
parameter. This is a guess from values, not a console document.

The pixel container carries the count after the input enables, and a
pixel program's last root constants reach it, as compute's reach the
count in COMPUTE_PGM_RSRC2. Without a count the old guess stays: as far
as the program reads on entry. That guess stopped short on the Series X
upscale program (effdd754ccbf3efd), the only writer of the 2560x1440
picture: it reads b500 as s9, s10 and s12, and s12 was refused as "a
hardware SGPR input".

Corpus of 21,579 shaders, pixel containers rebuilt with their image's
count: 3 pixel programs translate, 0 regress, 1 output changes
(616aee4a0258dad2 reads s13, which read as 0 above a primitive mask
guessed at s11 and is now a root constant).

Tests: graphics::tests::the_pixel_user_sgprs_are_read_from_the_register_image_by_its_kind,
a_pixel_programs_last_root_constants_reach_its_register_images_user_sgprs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:18:37 +00:00
github-bot changed target branch from main to gh-pr/451/base 2026-11-28 00:29:41 +00:00
github manually merged commit d9711880b4 into gh-pr/451/base 2026-11-28 00:29:43 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.