Skip to content

SHADER-190: document the FSSM initial float-mode search - #3782

Open
kacper-serewis wants to merge 4 commits into
ItsNotRexed:mainfrom
kacper-serewis:docs/shader-190-measurements
Open

kacper-serewis wants to merge 4 commits into
ItsNotRexed:mainfrom
kacper-serewis:docs/shader-190-measurements

Conversation

@kacper-serewis

@kacper-serewis kacper-serewis commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

SHADER-190 documents two checks on the initial FSSM float mode. In the packed RSRC1 scan, 63 of 88 candidate positions underallocated VGPRs for at least one of 1,675 qualifying compute shaders. The other 25 always exceeded the smallest sufficient granule.

@465d6a0eac proposed a standalone FLOAT_MODE at +0x104. In all 26,503 indexed 1.0.2.1 headers it is the only aligned word below +0x138 that always equals 0xC0. The low byte at +0x100 identifies all five stages. Only the 2,236 VS match the proposed full-word pattern. Rounded LDS bytes at +0x10C independently predict RSRC2.LDS_SIZE in all 2,689 CS, including 485 nonzero allocations. The constant at +0x104 fits both a fixed mode and a layout value. SHADER-190 stays open and the translator retains its existing defaults.

Original claim, continuation, and standalone-field follow-up claim. Independent of open PRs. #3447 edits separate passages in the same file. #2826 and #2437 edit other files.

AI-assisted. CPU validation used existing exports. The header census reproduced the supplied aggregates exactly. The 52 DLL shaders are the contributor’s separate measurement. All 11 documentation tests passed with python -m unittest discover -s tests -p "test_docs_*.py", and git diff --check passed. No archive extraction or GPU run. GPU and driver inapplicable.

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

Checked the new section against the existing header facts and the arithmetic:

  • 78 FSSM offsets + 10 code-prefix offsets = 88 candidate words; 63 underallocated + 25 over = 88.
  • 1,675 qualifying compute shaders out of 2,689 is consistent with the corpus counts in docs/design.md (2,689 CS).
  • VGPR capacity = (low 6 bits + 1) x 8 (wave32) or x 4 (wave64); the granule sizes match the AMD VGPR allocation granularity, and the wave selector is u32[0xD4] bit 5 (0x20 = wave32), as docs/design.md:261 and fssm_header.wave_size() define it.
  • Excluding graphics stages (merged-stage register sharing) is the right control.

The conclusion does not overreach: 63 positions are refuted, the remaining 25 are only "not refuted" because over-allocation is possible and the fields could be elsewhere, and the mode stays unresolved. 11 docs tests pass at 35909176 (5 links + 2 list + 2 repo-path + 2 design rows), git diff --check clean. No blocking issue.

@465d6a0eac

Copy link
Copy Markdown
Contributor

@kacper-serewis a lead for SHADER-190 that a packed-RSRC1 search can't see: FLOAT_MODE looks like it is stored on its own, as a separate word.

From my own 1.0.2.1 copy (counts and format words only):

  • u32[0x104] is 0x000000C0 in 26,503 / 26,503 FSSM blobs (all five stages), and in all 52 FSSM blobs of XboxBvhBuilder.dll (pe_shader_containers.py --extract, then fssm_unpack.py).
  • With LLVM's FLOAT_MODE layout (llvm/lib/Target/AMDGPU/SIDefines.h: FP_ROUND_MODE_SP [1:0], FP_ROUND_MODE_DP [3:2], FP_DENORM_MODE_SP [5:4], FP_DENORM_MODE_DP [7:6]; FP_DENORM_FLUSH_NONE = 3, FP_DENORM_FLUSH_IN_FLUSH_OUT = 0), 0xC0 decodes as: f32 and f16/f64 both round to nearest, f32 denormals are flushed on input and output, and f16/f64 denormals are kept. docs/fspx.md reads the same FLOAT_MODE value out of the FSPX programs' COMPUTE_PGM_RSRC1 (all 29). It is also the MODE the docs already infer from the code: 102,365 f32 omods, none on an f16 result (as Translator: no omod on f16 results, clamp kept, as RDNA2 with f16 denormals kept (SHADER-297) #1970 counted), and only FP_ROUND ever written.
  • The words around it look like per-hardware-stage state, not a packed register. u32[0x100] is 0x000200NN in 26,503 / 26,503, with NN = 3 for GS, 4 VS, 5 PS, 6 CS and 7 MS. That is the order of PAL's Util::Abi::HardwareStage (inc/core/palPipelineAbi.h: Ls = 0, Hs, Es, Gs, Vs, Ps, Cs); mesh is 7, one past PAL's Count. u32[0x10C] is the LDS allocation in bytes. Rounded up to 512 B, it equals COMPUTE_PGM_RSRC2 LDS_SIZE (u32[0x138] [23:15] × 512) in 2,689 / 2,689 CS and in the 52 BVH-builder CS. It is non-zero in 485 CS and 5 mesh shaders. u32[0x108] is 0 in all 26,503. I haven't found IEEE or DX10_CLAMP.

Caveat: the value never varies in either source, so nothing in the corpus contrasts it, and 0xC0 also happens to be the header offset of code_off. Three things favour the FLOAT_MODE reading: the stage-code and LDS-size neighbours, the identical FSPX RSRC1 field, and the agreement with the inferred MODE.

If the reading holds, it settles the FLOAT_MODE part of SHADER-190: f16 denormals are kept, as #1970 (SHADER-297) assumes. IEEE and DX10_CLAMP stay open. The claim is yours, so use it in #3782 if you agree. If you'd rather keep #3782 as it is, I can open a small follow-up after it: fssm_header.float_mode() with a synthetic test, plus the docs line. Tell me which you prefer.

AI-assisted (Claude Code).

@kacper-serewis

Copy link
Copy Markdown
Contributor Author

Thanks for distinguishing the standalone field from the packed-register search. We are checking +0x104 against existing exports and looking for evidence that distinguishes its meaning from a constant. We will update this PR with the evidence and its limits. AI-assisted.

@kacper-serewis

Copy link
Copy Markdown
Contributor Author

@465d6a0eac Thanks for identifying the standalone interpretation. I credited you in 411b761 and kept +0x104 as a candidate. The full replay found 0xC0 there in 26,503/26,503 headers, unique among aligned offsets below +0x138. Your LDS comparison reproduced in 2,689/2,689 CS, including 485 nonzero. One correction to +0x100: its low byte matches all five stage codes, but the complete 0x000200NN pattern holds only for the 2,236 VS.

The packed VGPR check cannot reject a standalone mode. The constant also fits a layout value, since +0xC0 holds code_off. I’m keeping SHADER-190 open and deferring the accessor until a loader read or an independently known contrasting mode distinguishes those readings. The PR records your 52 DLL shaders as a separate measurement. AI-assisted.

@465d6a0eac

Copy link
Copy Markdown
Contributor

@kacper-serewis thanks for folding it in, and you're right about +0x100. My census masked only the high half (0x0002) and the low byte, so 0x000200NN was wrong. The second byte varies by stage (VS 0, PS 1, GS 2, CS 3, MS 6) and is 0 only for the VS. The low-byte stage codes and the +0x10C LDS check stand as you wrote them. Fine by me to keep SHADER-190 open on that evidence. AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

The numbers match the tree: 26,503 shaders / 2,689 CS / 2,236 VS (tools/fssm_header.py docstring), code_off at 0xC0 (:96), wave32 at 0xD4 bit 5 (:155), RSRC2 0x138[23:15] and 102,365 omods (docs/design.md:316,294), 29 FSPX (docs/fspx.md:73), and the 0xC0 FLOAT_MODE decoding is right. All docs tests pass and the merge is clean.

One sentence is wrong: docs/fssm_crosscheck.md:128-130 pairs "2, 0, 1, 3 and 6" with GS, VS, PS, CS, MS in that order, which gives VS the byte 0, so VS cannot be the stage matching 0x000200NN - that would be GS. Either the order or the stage names need fixing.

Also, the 88-word scan and the 0xC0 census are presented as measurements without naming the tool or test that produced them, while the rest of the file does; add the tool the way the other rows do.

AI-assisted review, docs only.

@kacper-serewis

Copy link
Copy Markdown
Contributor Author

Updated in 3e82e38. The word is 0x00020004 for VS and 0x00020203 for GS, so VS matches 0x000200NN. The text now shows both examples and describes how the local Python census joined the export index to FSSM files, decoded the 88 little-endian candidates and intersected offsets for the constant-word check. All 11 documentation tests passed. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Independent check of 411b761 against my own 1.0.2.1 copy (26,503 FSSM headers, unpacked by make_game.py's shaders stage): 4 of 5 claims match, 1 not run.

Stage counts come from the carve index (the DXBC stage), not from the FSSM header: PS 12,101, MS 9,282, CS 2,689, VS 2,236, GS 195. All 26,503 blobs start with FSSM. My own script, independent of the PR's code, read each header's little-endian words.

  1. Match: +0x104 is 0x000000C0 in 26,503 of 26,503 headers. Of the 78 aligned words in +0x00..+0x134, 46 are constant across the corpus, and +0x104 is the only one equal to 0xC0. The other constant words hold other values (0, 1, 6, 0x101, 0xDEADBEEF, the magic).
  2. Match: the low byte at +0x100 is GS 3 (195), VS 4 (2,236), PS 5 (12,101), CS 6 (2,689), MS 7 (9,282). There is no exception.
  3. Match: the byte at +0x101 is VS 0, PS 1, GS 2, CS 3, MS 6, constant within each stage. Only the 2,236 VS have the full word 0x000200NN. +0x108 is 0 in all 26,503.
  4. Match: rounding the dword at +0x10C up to 512-byte blocks equals (+0x138 >> 15) & 0x1FF in 2,689 of 2,689 CS, including all 485 with a nonzero allocation. 5 MS have a nonzero +0x10C.
  5. Not run: the 63 of 88 packed-RSRC1 under-allocation count. It needs a disassembly of the 1,675 qualifying compute shaders to get each one's highest VGPR, and there is no llvm-mc on this machine. I am not reporting a number I did not measure.

Claims 1 to 4 agree exactly with the counts in the PR text.

@kapitche

Copy link
Copy Markdown
Contributor

Follow-up on claim 5 (the 63 of 88 packed-RSRC1 positions), same 1.0.2.1 copy, checked against 411b761. It matches, so with the earlier four that is 5 of 5.

I used the existing per-shader disassembly from the shaders stage, read only, and my own script. I took each qualifying compute shader's highest VGPR number from the instruction listing, with v[a:b] ranges counted to their upper end, and capacity as ((word & 0x3F) + 1) x 8 for wave32 or x 4 for wave64, using the 0xD4 bit 5 flag.

  • 2,689 CS, all with a disassembly. 1,009 report invalid words and 5 more use no VGPR, which leaves 1,675 qualifying (zero invalid words, at least one explicit VGPR). That is exactly the PR's count. 637 of the 1,675 are wave32.
  • Of the 88 positions (78 words at +0x00..+0x134, 10 at code_off+0x00..+0x24), 63 give too little capacity for at least one qualifying CS. 25 never do.
  • The 25 are the words at +0x18..+0x70 (23 words), +0xB8 and +0xBC. None is in the code-relative group, and none is the +0x104 word.
  • Reading +0x104 as RSRC1 under-allocates in 1,578 of the 1,675, as the PR states.

@MoonYueya

Copy link
Copy Markdown

The +0x104 word reads 0xC0 in all 26,503 indexed headers, and the census in this PR leaves the initial FP32 rounding open - so here is what the retail corpus itself asks for. Counts only, no game data.

My denominator is a different container than the one this PR counts: 13,962 distinct programs (21,522 records) from the PSO cache layer, each decoded to its end (50.98 M dwords, 36.86 M instructions). The 26,503 used above are named modules, so the two are not comparable term for term.

s_round_mode is the corpus's MODE-writing path: 4,663 writes in 3,305 programs, all graphics, none compute, and the immediate takes only two values in the whole corpus - 0xC 4,449 (95.4%) and 0x0 214 (4.6%). There is no third value anywhere.

  • No program changes the FP32 rounding field. Reading SIMM16[3:0] as FP_ROUND (our ISA XML does not define that field and LLVM never emits the instruction, so on my side it stays an inference), both values are FP32 nearest-even; they differ only in FP16/64, where 0xC asks for toward zero. So whatever the entry state is, no program overrides it - and the f32-rounding gap that your rdna2spirv: s_getreg_b32 of MODE.FP_ROUND #2980 getreg translation records (MODE[1:0] reads 0) has no reachable input in this layer either.
  • No program touches the denormal fields. s_denorm_mode appears 0 times, and of the 67 s_setreg_imm32_b32 in the corpus, 3 write MODE bits [3:2] with value 0 (upper bound 8: five candidates sit behind programs the decoder does not get through) and 64 write the flat-scratch base pair; none writes [5:4] or [7:6]. Denormal behaviour here is therefore decided by the descriptor alone - the initial-mode question this PR is about - and not by anything a program does.
  • The mode is set once per invocation. 1 to 8 writes per program with a bimodal 1 and 7; 198 programs write both values and none writes only 0x0; 79% of the writes appear after instruction 256; and none of the 4,663 sits inside a backward-branch region. So the value is late, single, and holds to the end: one per-invocation flag is exact for this corpus, and nothing re-switches mid-program.

Suggested use: if the initial mode ends up undecided for a program, the corpus says a single flag carrying the descriptor's value is enough - there is no in-program save/restore and no mid-program re-switching to model on this path. For the same reason the toward-zero FP16/64 case is not a corner: it is what 3,305 programs run under (that is the population behind PR #4403).

🤖 AI-assisted: drafted by an LLM agent from the measurements above; no game data, no shader names.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SHADER-190, AI-assisted CPU replay across all 26,503 cached headers. Only +0x104 consistently equaled 0xC0 among 78 aligned words examined. We counted 48 invariant words versus the earlier 46; that difference remains unresolved. The contributor’s PSO counts describe static rounding writes during execution. Both reported immediates select FP32 nearest-even when reached. Entry state, bypass paths and paths reaching both writes remain open. We did not replay the PSO-cache corpus. A loader read connecting the field to MODE or a descriptor with independently known contrasting settings would distinguish the candidate interpretations.

@DenRakEiw

Copy link
Copy Markdown

Tested head 63547ca565a1b940b5bc97277ccc5160386a574a on Windows 11 / Python 3.12.10.

  • Trial merge: Merged cleanly onto origin/main (d974c88a), git diff --cached --check passed (docs/fssm_crosscheck.md, +31 lines).
  • Tests:
    • python -I tests/test_docs_links.py: 6/6 passed
    • python -I tests/test_docs_table_rows.py: 2/2 passed
  • Code read: The doc addition clearly records the index.json/fssm/*.fssm scan method and documents the +0x104 0x000000C0 candidate alongside adjacent stage/LDS cross-checks, FSPX comparison, and the unverified code_off (0xC0) alternative without overclaiming SHADER-190 resolution.

AI-assisted review (Gemini 4 Neon).

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.

7 participants