Skip to content

d3d12_vulkan.md: the graphics stages' user-SGPR count, from FSSM u32[0xD4] bits 20:16 (whole corpus) - #5224

Open
throny wants to merge 1 commit into
ItsNotRexed:mainfrom
throny:doc-graphics-user-sgpr-count
Open

throny wants to merge 1 commit into
ItsNotRexed:mainfrom
throny:doc-graphics-user-sgpr-count

Conversation

@throny

@throny throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claim: #5156 (comment) (no item ID assigned yet).
Related: the graphics root-argument layout proposal on #313 (D3D-448 follow-up) and #4312, which use the compute USER_SGPR count; this gives the same count for VS/PS/GS/MS.

What the doc said

docs/d3d12_vulkan.md §3.4 (lines 1348-1351): "For VS, PS, MS and GS no user-SGPR count is measured; every base lies below s32 … the user count of the graphics stages … is what would confirm it." §3.5 (line 1594): "below s32 for the graphics stages, whose user count is not measured yet".

What was measured (all 26,503 FSSM blobs of 1.0.2.1)

  • FSSM u32[0xD4] (bit 5 = wave size, already used) holds the user-SGPR count in bits 20:16. In 2,689/2,689 compute blobs it equals COMPUTE_PGM_RSRC2 USER_SGPR (u32[0x138] bits 5:1).
  • Graphics values: VS 8–20, PS 8–20, MS 13–17, GS 13–17 (CS 4–14). Never above 20. Other set bits in the word: bit 0 in all 195 GS, bits 2 and 26 in 788 VS, none elsewhere.
  • Against user_sgpr_reads in spirv/index.json (all 26,503): no pointer read (ptr32_lo, ptr64_lo/hi, vsharp, tsharp) lies at or past the count in CS/VS/PS, or past count + 8 in MS/GS. So the heap bases of D3D-329 are user data in every stage. Reads past those bounds are all const32: 4 VS, 129 PS (besides s[count]), 10 MS.
  • PS read s[count] as const32 in 10,277 of 12,101; 10,267 of those have an FSSM interpolant table (40 PS with a table don't read it, 10 without one do). Consistent with PRIM_MASK following the user SGPRs. MS/GS read up to count + 7, consistent with user data starting at s8 in the merged stages. Both are labelled hypotheses in the doc.

Method and limits

  • Blobs enumerated with os.listdir (26,503, matches index.json; 0 missing in spirv/index.json).
  • user_sgpr_reads comes from a linear read-before-write scan: it says nothing about values a loop carries. The PRIM_MASK and s8-base readings are inferred from counts, not from a driver or the executable.
  • The field-vs-RSRC2 identity and the per-stage histograms reproduce with the repository tool; the read-bound comparison was a local script over spirv/index.json (counts only, not committed).

Changes

  • docs/d3d12_vulkan.md: §3.4 paragraph and the §3.5 "Direct heap indexing" item updated with the counts and the command.
  • tools/fssm_header.py: user_sgpr_count() (bits 20:16 of u32[0xD4]) and compute_rsrc2_user_sgprs(); per-file user_sgprs=, a user SGPRs <stage> histogram per stage, and CS user SGPRs equal COMPUTE_PGM_RSRC2 USER_SGPR in N/M. Docstring updated.
  • tests/test_fssm_header.py: 6 tests on synthetic headers, including a lookalike word with only the neighbouring bits set (wave32 bit, bits 0, 2, 21-23, 26), which reads as 0.

Run

  • python -I tools/fssm_header.py <work>/shaders/dxbc/fssm → CS user SGPRs equal COMPUTE_PGM_RSRC2 USER_SGPR in 2689/2689 and the per-stage lines above.
  • python -m compileall -q make_game.py tools tests; tests/test_fssm_header.py (48 OK), test_fssm_crosscheck.py, test_fssm_wave_size.py, all tests/test_docs_*.py, tests/test_text_write_line_endings.py, scripts/check_no_game_data.py: pass. (tests/test_user_sgpr_census.py needs pytest, not installed here; that file is unchanged.)

AI-assisted (Claude Code). No GPU needed. Counts only; no shader names or content.

🤖 Generated with Claude Code

…0xD4] bits 20:16 (whole corpus)

The field equals COMPUTE_PGM_RSRC2 USER_SGPR in all 2,689 compute blobs and
is 8-20 in VS/PS, 13-17 in MS/GS. No pointer read lies past it (+8 for
MS/GS) in any of the 26,503 shaders. fssm_header.user_sgpr_count() reads it;
the CLI prints it per stage with the compute check.

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

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

Ran this at 06634796e on Windows 11: pytest tests/test_fssm_header.py -q -> 48 passed, 6 subtests passed; test_docs_table_rows.py 2 OK; git diff --check clean.

fssm_header now decodes the graphics stages' user-SGPR count from u32[0xD4] bits 20:16, and the D3D12-on-Vulkan doc states the whole-corpus count; the added cases cover the field next to the existing wave-size bit. I cannot recount the corpus here; the synthetic test and docs validate. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 0663479 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_fssm_header.py -> Ran 48 tests, OK
  • Negative control (tools/fssm_header.py swapped to upstream/main): FAILED (errors=6)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@kacper-serewis kacper-serewis 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.

AI-assisted independent CPU recount at 0663479. Across all 23,814 cached graphics listings, the field was 8–20 in VS/PS and 13–17 in MS/GS. Resolved descriptor bases fit the proposed windows. In MS the trace found 6,308 texture and 4,536 buffer load sites through s23, but zero dynamic 32-bit loads with a sampler consumer. Please qualify the MS s24 sampler assignment as inferred. The CS field matched USER_SGPR in 2,689/2,689 sidecars; the independent CS descriptor trace reconstructed 2,676 of those listings. Static counts support register bounds but cannot establish hardware assignment.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Reviewed change in PR #5224: d3d12_vulkan.md: the graphics stages' user-SGPR count, from FSSM u32[0xD4] bits 20:16 (whole corpus).

Scope: docs/d3d12_vulkan.md, tests/test_fssm_header.py, tools/fssm_header.py
Diff: +113 / -5 across 3 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants