Skip to content

Shaders: seed uninitialized mesh SGPRs above user_sgprs as zero - #2049

Closed
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-ms-uninitialized-sgprs-815
Closed

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-ms-uninitialized-sgprs-815

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Summary

  • Decode user_sgprs from MS_INFO[6] into MeshIo::user_sgprs and expose MeshIo::initialized_sgprs() (8 + user_sgprs, covering the 8 merged-stage system SGPRs s0..=s7 plus the user SGPR range s8..).
  • Wire StageIo::Ms(ms) => Some(ms.initialized_sgprs()) in io::raise alongside compute and pixel stages so reads of uninitialized SGPRs above 8 + user_sgprs lower to 0 instead of failing with "a hardware SGPR input", while keeping unimplemented hardware SGPRs (s0..=s7 other than s3 MergedWaveInfo) and unmapped user SGPRs (s8..s[8 + user_sgprs - 1]) strictly refused.
  • Add synthetic mesh-pipeline unit and GPU draw/readback tests.

Addresses #815

Testing

  • cargo test -p victory-shader --locked -- mesh_uninitialized_sgprs (verified with dxil.dll and executed on NVIDIA RTX 5090, AMD Radeon Graphics, and D3D12 WARP)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo xtask policy

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Keep the mesh ABI support, align the live-in rule with #1261 (4f3c6a1)

Evidence

Checks and limits

  • Both focused exact-head tests passed. WARP actually ran the mesh draw and all 16 pixels matched for each branch: 0.75 when the write was skipped and 7.75 when it executed.
  • The draw fixture can return success after every adapter is skipped. Its hardware enumeration also excludes adapters reporting zero dedicated memory before asking about mesh support. Adapter eligibility

Next step

This verification was AI-assisted.

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

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. Uninitialized mesh SGPRs above user_sgprs seeded as zero (+1 test) — mesh-shader register initialization; relates to #1961's mesh output budget.

Decode the mesh stage's user SGPR count from MS_INFO byte 6 (E+0x44e) into MeshIo::user_sgprs and wire MeshIo::initialized_sgprs (8 merged-stage system SGPRs plus user_sgprs) into Io::initialized_sgprs (Marvisak#815).

Narrow Lower::inputs so an unmapped SGPR at or above initialized_sgprs reads as zero only when at least one instruction in the program writes that register, refusing registers no instruction writes as unknown inputs (matching Marvisak#1261). Make the multi-adapter SM 6.6 mesh draw test enumerate UMA/software adapters directly and assert at least one adapter executes.
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-ms-uninitialized-sgprs-815 branch from 4f3c6a1 to 71e4bd2 Compare November 25, 2026 05:23
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Thanks @jeremygold02 — pushed 71e4bd2a addressing both points:

  1. Aligned Lower::inputs with #1261 + added unwritten control cases: an unmapped SGPR at or above initialized_sgprs now lowers to 0 only when at least one instruction in the program writes that register, refusing registers no instruction writes with "an SGPR no instruction writes, above the initialized ones". mesh_uninitialized_sgprs_read_as_zero_while_hardware_ones_stay_refused now tests unwritten s10 and s25 controls alongside the branch-around-write s10 fixture.
  2. Adapter enumeration and execution assertion: mesh_uninitialized_sgprs_execute_on_host_gpus no longer skips UMA/software adapters on DedicatedVideoMemory == 0 before checking D3D_SHADER_MODEL_6_6 + D3D12_MESH_SHADER_TIER_1, and asserts executed > 0 (verified on RTX 5090, AMD Radeon Graphics, and WARP).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.
Needs work.

This PR extends the compute "uninitialized SGPRs read zero" rule to mesh programs: native.rs ms_io now reads MeshIo::user_sgprs from MS_INFO[6], and MeshIo::initialized_sgprs returns 8 + user_sgprs. That changes shader semantics on two assumptions the PR does not back up:

What would change the verdict: evidence for the MS_INFO[6] meaning and the 8-SGPR prefix, and the lower.rs overlap with #1261 settled.

CI: passing (check).


Generated by Claude Code

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 71e4bd2 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Closing this PR: deferring Lower::inputs handling to #1261 and closing since validating the mesh MS_INFO[6] ABI requires title shader evidence I do not have locally.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants