Skip to content

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

Closed
throny wants to merge 2 commits into
ProjectLeonida:mainfrom
throny:doc-graphics-user-sgpr-count
Closed

throny wants to merge 2 commits into
ProjectLeonida: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
Collaborator

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.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @kacper-serewis. Your recount matches (8–20 VS/PS, 13–17 MS/GS, 2,689/2,689 CS). The s23/s24 MS heap assignment is D3D-329's existing sentence in §3.4. This PR adds only the count and the bound ("no pointer read past it"), which your trace also supports. I have not reproduced your sampler-consumer trace, so I have filed "label the MS s24 sampler base as inferred" as a finding on #7049 instead of rewording D3D-329's claim here. AI-assisted.

… through them are all static)

heap_index_census over all 26,503 listings: S# loads through s11 (CS),
s24 (MS) and s16 (PS) all have static offsets; dynamic-offset S# loads
appear only in the 1,043 sampler-only PS (s11, s10). Review on ProjectLeonida#5224.

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

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, and fixed in d813549. python -I tools/heap_index_census.py <work>/shaders/dxbc/disasm over all 26,503 listings:

  • Every S# load through s24 in MS has a static offset: 2,096 in the res+smp shaders and 497 in the smp-only ones, 0 dynamic.
  • s23 carries the MS dynamic loads: 5,177 T# and 3,829 V#. These differ from your 6,308 / 4,536, which presumably count sites differently.
  • The same holds for the other two named sampler bases: every S# load through s11 in CS (1,907) and s16 in PS (64,994) is static.
  • The only dynamic-offset S# loads are in the 1,043 PS that index only the sampler heap (s11: 1,105, s10: 284).

§3.4 now marks the sampler-heap base inferred for all three stages, with these counts. The resource-heap bases (s10 CS, s23 MS, s15 PS) stay as measured, since their loads have run-time offsets. test_docs_*, test_text_write_line_endings and check_no_game_data pass. AI-assisted.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Re-checked d813549be on all 26,503 FSSM blobs and listings of my own 1.0.2.1 copy, WSL Ubuntu, Python 3.14.4, CPU only: every count I could recompute with the repository tools reproduces exactly. Counts only.

python -I tools/fssm_header.py <fssm>

  • CS user SGPRs equal COMPUTE_PGM_RSRC2 USER_SGPR in 2689/2689.
  • Ranges per stage: VS 8–20, PS 8–20, MS 13–17, GS 13–17, CS 4–14. No stage goes above 20.
  • Wave sizes: wave32 2,662 / wave64 23,841.
  • The other set bits of u32[0xD4], outside bit 5 and bits 20:16, counted with a few lines over the tool's _u32 and stage_index: bit 0 in 195 GS, bits 2 and 26 in 788 VS, nothing elsewhere. That matches the PR.

python -I tools/heap_index_census.py <disasm> (8 min 41 s; 1,473 skipped for embedded data words)

  • MS: every S# load through s24 is static, 2,096 in res+smp and 497 in smp, with 0 dynamic. s23 carries the dynamic loads: T# 3,304 + 1,873 = 5,177, and V# 3,829.
  • CS: every S# load through s11 is static, 1,907.
  • PS: every S# load through s16 is static, 64,994. The only dynamic S# loads are in the 1,043 sampler-only PS: s11 1,105 and s10 284. That group also has 119 static ones through s19.

Tests. test_fssm_header 48 OK, test_fssm_crosscheck 6 OK, test_fssm_wave_size 7 OK, test_docs_links 6, test_docs_table_ids 2, test_docs_table_rows 2 and test_text_write_line_endings 3, all OK.

I did not redo the read-bound comparison against spirv/index.json, since the PR describes it as a local script.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Collaborator

Tested d813549 merged with main 00f5ce6 on Linux (WSL2), CPython 3.12.16, CPU only: pass. The merge of docs/d3d12_vulkan.md was automatic; python -I tests/test_fssm_header.py ran 48 tests, OK. Negative control: with tools/fssm_header.py reverted to main's version the same test file fails (6 errors), and passes again once restored.

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d813549be on my own 1.0.2.1 copy (Windows 11, Python 3.12, no GPU needed): pass, every count reproduces.

  • python -I tools/fssm_header.py <work>/shaders/dxbc/fssm reads 26,503 files (wave32 2,662, wave64 23,841) and reports CS user SGPRs equal COMPUTE_PGM_RSRC2 USER_SGPR in 2689/2689.

  • Per-stage ranges match the PR text:

    Stage User SGPRs
    CS 4–14
    VS 8–20
    PS 8–20
    MS 13–17
    GS (195 blobs) 13–17

    No value is above 20.

  • tests/test_fssm_header.py, test_fssm_crosscheck.py, test_fssm_wave_size.py and test_user_sgpr_census.py pass: 100 tests, 9 subtests.

  • It merges cleanly onto the current main.

I didn't re-run the read-bound comparison against spirv/index.json (that local script isn't in the PR). Counts only. AI-assisted (Claude Code).

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
…otRexed#5092 ItsNotRexed#5232 ItsNotRexed#5263 ItsNotRexed#5408 ItsNotRexed#5410 ItsNotRexed#5411 ItsNotRexed#5418 ItsNotRexed#5423 ItsNotRexed#5434 ItsNotRexed#5437 ItsNotRexed#5446 ItsNotRexed#5458 ItsNotRexed#5461 ItsNotRexed#5465 ItsNotRexed#5473 ItsNotRexed#5486 ItsNotRexed#5495 ItsNotRexed#5562 ItsNotRexed#5594 ItsNotRexed#5619 ItsNotRexed#5644

ItsNotRexed#8919 fork integration. Each parent after the first is an exact reviewed PR head.

ItsNotRexed#5224 d813549 ItsNotRexed#5224 (comment)
ItsNotRexed#5336 d0e66fa ItsNotRexed#5336 (comment)
ItsNotRexed#5092 36be9f5 ItsNotRexed#5092 (comment)
ItsNotRexed#5232 2d9649a ItsNotRexed#5232 (comment)
ItsNotRexed#5263 9cabfcf ItsNotRexed#5263 (comment)
ItsNotRexed#5408 133f7ef ItsNotRexed#5408 (comment)
ItsNotRexed#5410 08faade ItsNotRexed#5410 (comment)
ItsNotRexed#5411 dd278f5 ItsNotRexed#5411 (comment)
ItsNotRexed#5418 605dbc4 ItsNotRexed#5418 (comment)
ItsNotRexed#5423 1775bf6 ItsNotRexed#5423 (comment)
ItsNotRexed#5434 4c399d8 ItsNotRexed#5434 (comment)
ItsNotRexed#5437 ab12086 ItsNotRexed#5437 (comment)
ItsNotRexed#5446 eb9a54c ItsNotRexed#5446 (comment)
ItsNotRexed#5458 4444f0d ItsNotRexed#5458 (comment)
ItsNotRexed#5461 d6a973a ItsNotRexed#5461 (comment)
ItsNotRexed#5465 2107ca9 ItsNotRexed#5465 (comment)
ItsNotRexed#5473 aaf5bd2 ItsNotRexed#5473 (comment)
ItsNotRexed#5486 6d3a621 ItsNotRexed#5486 (comment)
ItsNotRexed#5495 eb7dd0c ItsNotRexed#5495 (comment)
ItsNotRexed#5562 5c450f5 ItsNotRexed#5562 (comment)
ItsNotRexed#5594 560bf65 ItsNotRexed#5594 (comment)
ItsNotRexed#5619 b782d57 ItsNotRexed#5619 (comment)
ItsNotRexed#5644 9984867 ItsNotRexed#5644 (comment)

AI-assisted integration.
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.

9 participants