xshader: initial MODE from PGM_RSRC1, fixture scan for its FSSM location #309

Closed
github-bot wants to merge 3 commits from gh-pr/309/head into gh-pr/309/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 17:31 UTC · original
QuentinDanblon:pr/f16-omod-initial-mode → main · +945 −16 · 4 files · 3 commits · closed without merging

Library / area: tombox-xshader (hlsl.rs, hlsl/mode.rs, tests/exec.rs), d3d12_xs/src/shader_xlat.rs (one log line per shader hash)

Exports changed (exports.txt rows): none

Source of the behaviour:

  • docs/BLOCKERS.md, "f16 output modifiers depend on the initial MODE" (gfx1036 measurement): an omod on an f16 VALU result acts only with MODE IEEE 0 and f16/f64 denormals flushed.
  • AMD RDNA2 ISA reference: MODE register fields (FP_ROUND [3:0], FP_DENORM [7:4], DX10_CLAMP [8], IEEE [9]) and round modes.
  • LLVM AMDGPU (AMDGPUUsage compute_pgm_rsrc1 table, SIDefines.h) and Mesa (MIT, sid.h S_00B848_*): PGM_RSRC1 field layout, register granules, and that the CP loads FLOAT_MODE / DX10_CLAMP / IEEE_MODE into MODE at wave launch. Facts only, no code taken.

What it does

The translator always assumed MODE 0xf0 at entry. This PR lets the initial MODE come from the stage's PGM_RSRC1, and reports when it does not have it.

  • mode::mode_from_pgm_rsrc1 maps FLOAT_MODE [19:12] to MODE [7:0], DX10_CLAMP [21] to MODE [8], IEEE_MODE [23] to MODE [9]. PRIV, DEBUG_MODE and the register counts are dropped.
  • reachable / analyze start from that MODE, and tb_hw1 (the MODE copy read by s_getreg and the f16 omod check) is initialised with it. The f32 and f16/f64 denormal paths follow the same value.
  • New entry point hlsl::translate_with_pgm_rsrc1(ex, feeds_ps, rsrc1) for a caller that has the value.
  • Every other entry point asks the container. The reader picks a location by the sub-version dword at FSSM byte 0x10 (as #257 does for COMPUTE_PGM_RSRC2), refuses Durango blobs and any location at or past the ISA. Its location table is empty: where PGM_RSRC1 sits in the FSSM container is not proven, so no container yields a value today and MODE 0xf0 stays the default. Behaviour on main does not change, except for the log line below.
  • Without PGM_RSRC1, a shader with an f16 VOP3 result carrying an omod gets a line in a new Translated.unknowns: Vec<String>, and d3d12_xs logs it once per shader hash (shader_xlat "UNKNOWN hash=...").

Finding the location: a fixture test, for whoever has fixtures

hlsl::mode::tests::pgm_rsrc1_candidates_in_every_fssm_fixture, same gating and fixture walk as the #257 RSRC2 test (tombox_fixtures_shaders, analysis/shaders, TOMBOX_SHADER_DUMPS). For each fixture of any stage it counts the VGPRs and SGPRs the ISA names and the wave size, then lists every dword before the ISA preamble that fits as PGM_RSRC1:

  • VGPRS [5:0]: (VGPRS + 1) × granule covers the VGPRs used (granule 8 in wave32, 4 in wave64);
  • SGPRS [9:6]: 0 (GFX10+ rule) or (SGPRS + 1) × 8 covers the SGPRs used (older rule; the console compiler is not LLVM, so both are accepted);
  • PRIORITY, PRIV, DEBUG_MODE clear for every stage; BULKY, CDBG_USER, [28:27] clear for compute;
  • round bits [15:12] zero (round to nearest even, the D3D rule).

It prints the dword 4 bytes before #257's RSRC2 (0x12c for sub-version 5, 0x134 for sub-version 6; the hardware registers RSRC1/RSRC2 are consecutive), and per sub-version the offsets that fit every fixture. It asserts no location. It fails only if the reader reads Durango, if a table entry does not fit every fixture, or with "not proven" under two FSSM fixtures. I have no fixtures, so here it is ignored (forced: "not proven: 0 FSSM fixtures").

If someone with fixtures (the people who ran the #257 test) runs
cargo test -p tombox-xshader --release --lib pgm_rsrc1_candidates -- --nocapture
and 0x12c / 0x134 fit every fixture, PGM_RSRC1_AT can be filled in a separate PR.

Commit 3 (23b199c): one fixture run should settle the container layout

The scan now also looks for RSRC2 on every stage and probes two layouts, so a single run on real fixtures can decide where the registers sit. Printing only, no location is asserted, nothing goes into a production table.

  • Per stage: offsets that fit every fixture are now aggregated per (sub-version, stage) and per (sub-version, stage slot), not only per sub-version. An intersection across compute and graphics stages could be empty even if 0x134 is right for compute.
  • RSRC2 by user SGPR count: #289 reads the user SGPR count at byte 0xD6 and checks it against the binding table. COMPUTE_PGM_RSRC2 and SPI_SHADER_PGM_RSRC2_PS/VS/GS/HS carry the same count in USER_SGPR [5:1] (plus USER_SGPR_MSB, bit 27, for the graphics stages). The scan lists every dword before the ISA whose USER_SGPR equals byte 0xD6 (or 0xD6 + 8 for the merged slots) with the must-be-zero bits clear, per stage, and runs the RSRC1 filter on the dword just before it.
  • AMDHSA kernel descriptor hypothesis (LLVM AMDGPUUsage, Code Object V3 descriptor): if the container embeds it, RSRC2 at R gives RSRC1 at R-4, RSRC3 at R-8, GROUP_SEGMENT_FIXED_SIZE at R-52 (to compare with LDS_SIZE and the static LDS reach), and an entry offset at R-36 that should land on the ISA (0x4c for RSRC2 at 0x138 and the ISA at 0x150). With RSRC2 at 0x130 in sub-version 5 the descriptor would overlap #289's table at 0xE8..0x100; the scan flags it.
  • Code-region hypothesis (public notes of other projects, not verified): a u64 code offset and size at 0xC0/0xC8, relative to +0x10, with COMPUTE_PGM_RSRC2 as the first dword of the region followed by the group size. The scan compares the three dwords after R with the PSV0 numthreads.
  • Stage slots (#289, 0x18..0x58): the difference between the set slot's value and the ISA and each candidate is printed, to see whether the registers sit at a fixed position from the slot.
  • A "k of n" summary per (sub-version, stage, hypothesis, R) tells which layout holds.

Command for anyone with fixtures (TOMBOX_SHADER_DUMPS=<dir> if they are not under analysis/shaders):

cargo test --release -p tombox-xshader --lib hlsl::mode::tests::pgm_rsrc1_candidates_in_every_fssm_fixture -- --exact --nocapture --include-ignored 2> rsrc_scan.txt

Tests: two new unit tests on synthetic containers (USER_SGPR match with MSB and +8, must-be-zero bits, LDS, per-stage aggregation keeping 0x138/0x134 for compute when a pixel shader has RSRC2 elsewhere; a full descriptor at 0x104, the 0x130 overlap, a code region with 64x1x1, a merged GS). Mutation: ignoring byte 0xD6 makes both fail. tombox-xshader lib on WARP: 122 passed, 0 failed, 4 ignored. Gate: 0 problems.

Limits: byte 0xD6 is read even when 0xE8 holds no table, where its meaning is not established. PS, GS and HS have no reserved RSRC2 bits on gfx10.3, so their filter rests on USER_SGPR and TRAP/EXCP. Whether a Vertex shader without a slot uses the VS or the GS registers (NGG) is a guess, printed per fixture.

Not covered, not claimed

  • The RSRC1 location in any container.
  • Only the f16 omod is reported as depending on the unknown MODE. f32 denormal handling also depends on it and is not reported.
  • A shader with few registers is weak evidence for the scan (many small dwords fit). The register count is a lower bound, so the filter is more permissive, never stricter.
  • Fields above bit 23 differ between SPI_SHADER_PGM_RSRC1_* stages and are only checked for compute.

For you

  • Conflicts with #257 (hlsl.rs, next to mode::analyze) and #306 (Translated gets unknowns here and gather_lod_blind there). Both are side-by-side additions. I can rebase on whichever lands first.
  • unknowns is generic; #306's gather_lod_blind is the same idea for one case. If you prefer one mechanism, I can fold #306's into unknowns, in whichever PR lands second.
  • Noticed while working near resinfo, not changed here: image_mimg_query in tests/exec.rs expects 3 array layers at level 1, while the gfx1036 measurement in docs/BLOCKERS.md ("image_get_resinfo array layers are not minified", max(1, layers >> (BASE_LEVEL + level))) gives 1. The test encodes the current unminified behaviour. I did not touch it; it moves when that OPEN item is done.

Tests

On ba84a79 (base f89e410), WARP and RTX 5090 (TOMBOX_EXEC_HW=1), Windows 11.

  • f16_omod_follows_initial_mode_from_pgm_rsrc1 (tests/exec.rs), 58 cases: v_add_f16 / v_mul_f16 with each omod and clamp under 7 PGM_RSRC1 values (f16 denormals kept or flushed, IEEE on or off, DX10_CLAMP, PRIV, DEBUG_MODE and register counts set, all zero), an s_setreg after a flushing or keeping RSRC1, v_add_f32 of a denormal under 4 FLOAT_MODE values, and the unknowns line present only without PGM_RSRC1. Passes on both.

  • hlsl::mode unit tests: RSRC1 to MODE mapping; the reader on synthetic sub-version 5/6 containers (table hit, unknown sub-version, location past the ISA, short blob, Durango refused, production table empty); the reachable set seeded by the initial MODE; rsrc1_scan_checks_register_granules_and_reserved_bits_on_synthetic_containers.

  • Mutations: initialising tb_hw1 with 0xf0 again makes 26 of the 58 cases fail; swapping the wave32/wave64 granules makes the scan unit test fail. Both restored.

  • Full tombox-xshader suite on WARP: 350 passed, 0 failed, 19 ignored.

  • pr_gate.py --base origin/main: 0 problems.

  • cargo test -p tombox-xshader passes for what is listed above

  • No game or console files and no binaries included

  • No fake success: nothing is read from an unproven location; the unknown MODE is logged

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 17:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/309) `QuentinDanblon:pr/f16-omod-initial-mode` → `main` · +945 −16 · 4 files · 3 commits · closed without merging **Library / area:** `tombox-xshader` (`hlsl.rs`, `hlsl/mode.rs`, `tests/exec.rs`), `d3d12_xs/src/shader_xlat.rs` (one log line per shader hash) **Exports changed (exports.txt rows):** none **Source of the behaviour:** - `docs/BLOCKERS.md`, "f16 output modifiers depend on the initial MODE" (gfx1036 measurement): an omod on an f16 VALU result acts only with MODE IEEE 0 and f16/f64 denormals flushed. - AMD RDNA2 ISA reference: MODE register fields (FP_ROUND [3:0], FP_DENORM [7:4], DX10_CLAMP [8], IEEE [9]) and round modes. - LLVM AMDGPU (`AMDGPUUsage` compute_pgm_rsrc1 table, `SIDefines.h`) and Mesa (MIT, `sid.h` `S_00B848_*`): PGM_RSRC1 field layout, register granules, and that the CP loads FLOAT_MODE / DX10_CLAMP / IEEE_MODE into MODE at wave launch. Facts only, no code taken. ### What it does The translator always assumed MODE `0xf0` at entry. This PR lets the initial MODE come from the stage's PGM_RSRC1, and reports when it does not have it. - `mode::mode_from_pgm_rsrc1` maps FLOAT_MODE [19:12] to MODE [7:0], DX10_CLAMP [21] to MODE [8], IEEE_MODE [23] to MODE [9]. PRIV, DEBUG_MODE and the register counts are dropped. - `reachable` / `analyze` start from that MODE, and `tb_hw1` (the MODE copy read by `s_getreg` and the f16 omod check) is initialised with it. The f32 and f16/f64 denormal paths follow the same value. - New entry point `hlsl::translate_with_pgm_rsrc1(ex, feeds_ps, rsrc1)` for a caller that has the value. - Every other entry point asks the container. The reader picks a location by the sub-version dword at FSSM byte 0x10 (as #257 does for COMPUTE_PGM_RSRC2), refuses Durango blobs and any location at or past the ISA. **Its location table is empty**: where PGM_RSRC1 sits in the FSSM container is not proven, so no container yields a value today and MODE `0xf0` stays the default. Behaviour on main does not change, except for the log line below. - Without PGM_RSRC1, a shader with an f16 VOP3 result carrying an omod gets a line in a new `Translated.unknowns: Vec<String>`, and `d3d12_xs` logs it once per shader hash (`shader_xlat` "UNKNOWN hash=..."). ### Finding the location: a fixture test, for whoever has fixtures `hlsl::mode::tests::pgm_rsrc1_candidates_in_every_fssm_fixture`, same gating and fixture walk as the #257 RSRC2 test (`tombox_fixtures_shaders`, `analysis/shaders`, `TOMBOX_SHADER_DUMPS`). For each fixture of any stage it counts the VGPRs and SGPRs the ISA names and the wave size, then lists every dword before the ISA preamble that fits as PGM_RSRC1: - VGPRS [5:0]: (VGPRS + 1) × granule covers the VGPRs used (granule 8 in wave32, 4 in wave64); - SGPRS [9:6]: 0 (GFX10+ rule) or (SGPRS + 1) × 8 covers the SGPRs used (older rule; the console compiler is not LLVM, so both are accepted); - PRIORITY, PRIV, DEBUG_MODE clear for every stage; BULKY, CDBG_USER, [28:27] clear for compute; - round bits [15:12] zero (round to nearest even, the D3D rule). It prints the dword 4 bytes before #257's RSRC2 (0x12c for sub-version 5, 0x134 for sub-version 6; the hardware registers RSRC1/RSRC2 are consecutive), and per sub-version the offsets that fit every fixture. It asserts no location. It fails only if the reader reads Durango, if a table entry does not fit every fixture, or with "not proven" under two FSSM fixtures. I have no fixtures, so here it is ignored (forced: "not proven: 0 FSSM fixtures"). If someone with fixtures (the people who ran the #257 test) runs `cargo test -p tombox-xshader --release --lib pgm_rsrc1_candidates -- --nocapture` and 0x12c / 0x134 fit every fixture, `PGM_RSRC1_AT` can be filled in a separate PR. ### Commit 3 (`23b199c`): one fixture run should settle the container layout The scan now also looks for RSRC2 on every stage and probes two layouts, so a single run on real fixtures can decide where the registers sit. Printing only, no location is asserted, nothing goes into a production table. - **Per stage**: offsets that fit every fixture are now aggregated per (sub-version, stage) and per (sub-version, stage slot), not only per sub-version. An intersection across compute and graphics stages could be empty even if 0x134 is right for compute. - **RSRC2 by user SGPR count**: #289 reads the user SGPR count at byte 0xD6 and checks it against the binding table. COMPUTE_PGM_RSRC2 and SPI_SHADER_PGM_RSRC2_PS/VS/GS/HS carry the same count in USER_SGPR [5:1] (plus USER_SGPR_MSB, bit 27, for the graphics stages). The scan lists every dword before the ISA whose USER_SGPR equals byte 0xD6 (or 0xD6 + 8 for the merged slots) with the must-be-zero bits clear, per stage, and runs the RSRC1 filter on the dword just before it. - **AMDHSA kernel descriptor hypothesis** (LLVM AMDGPUUsage, Code Object V3 descriptor): if the container embeds it, RSRC2 at R gives RSRC1 at R-4, RSRC3 at R-8, GROUP_SEGMENT_FIXED_SIZE at R-52 (to compare with LDS_SIZE and the static LDS reach), and an entry offset at R-36 that should land on the ISA (0x4c for RSRC2 at 0x138 and the ISA at 0x150). With RSRC2 at 0x130 in sub-version 5 the descriptor would overlap #289's table at 0xE8..0x100; the scan flags it. - **Code-region hypothesis** (public notes of other projects, not verified): a u64 code offset and size at 0xC0/0xC8, relative to +0x10, with COMPUTE_PGM_RSRC2 as the first dword of the region followed by the group size. The scan compares the three dwords after R with the PSV0 numthreads. - **Stage slots** (#289, 0x18..0x58): the difference between the set slot's value and the ISA and each candidate is printed, to see whether the registers sit at a fixed position from the slot. - A "k of n" summary per (sub-version, stage, hypothesis, R) tells which layout holds. Command for anyone with fixtures (`TOMBOX_SHADER_DUMPS=<dir>` if they are not under `analysis/shaders`): ``` cargo test --release -p tombox-xshader --lib hlsl::mode::tests::pgm_rsrc1_candidates_in_every_fssm_fixture -- --exact --nocapture --include-ignored 2> rsrc_scan.txt ``` Tests: two new unit tests on synthetic containers (USER_SGPR match with MSB and +8, must-be-zero bits, LDS, per-stage aggregation keeping 0x138/0x134 for compute when a pixel shader has RSRC2 elsewhere; a full descriptor at 0x104, the 0x130 overlap, a code region with 64x1x1, a merged GS). Mutation: ignoring byte 0xD6 makes both fail. `tombox-xshader` lib on WARP: 122 passed, 0 failed, 4 ignored. Gate: 0 problems. Limits: byte 0xD6 is read even when 0xE8 holds no table, where its meaning is not established. PS, GS and HS have no reserved RSRC2 bits on gfx10.3, so their filter rests on USER_SGPR and TRAP/EXCP. Whether a Vertex shader without a slot uses the VS or the GS registers (NGG) is a guess, printed per fixture. ### Not covered, not claimed - The RSRC1 location in any container. - Only the f16 omod is reported as depending on the unknown MODE. f32 denormal handling also depends on it and is not reported. - A shader with few registers is weak evidence for the scan (many small dwords fit). The register count is a lower bound, so the filter is more permissive, never stricter. - Fields above bit 23 differ between `SPI_SHADER_PGM_RSRC1_*` stages and are only checked for compute. ### For you - Conflicts with #257 (`hlsl.rs`, next to `mode::analyze`) and #306 (`Translated` gets `unknowns` here and `gather_lod_blind` there). Both are side-by-side additions. I can rebase on whichever lands first. - `unknowns` is generic; #306's `gather_lod_blind` is the same idea for one case. If you prefer one mechanism, I can fold #306's into `unknowns`, in whichever PR lands second. - Noticed while working near resinfo, not changed here: `image_mimg_query` in `tests/exec.rs` expects 3 array layers at level 1, while the gfx1036 measurement in `docs/BLOCKERS.md` ("image_get_resinfo array layers are not minified", `max(1, layers >> (BASE_LEVEL + level))`) gives 1. The test encodes the current unminified behaviour. I did not touch it; it moves when that OPEN item is done. ### Tests On `ba84a79` (base `f89e410`), WARP and RTX 5090 (`TOMBOX_EXEC_HW=1`), Windows 11. - `f16_omod_follows_initial_mode_from_pgm_rsrc1` (`tests/exec.rs`), 58 cases: `v_add_f16` / `v_mul_f16` with each omod and clamp under 7 PGM_RSRC1 values (f16 denormals kept or flushed, IEEE on or off, DX10_CLAMP, PRIV, DEBUG_MODE and register counts set, all zero), an `s_setreg` after a flushing or keeping RSRC1, `v_add_f32` of a denormal under 4 FLOAT_MODE values, and the `unknowns` line present only without PGM_RSRC1. Passes on both. - `hlsl::mode` unit tests: RSRC1 to MODE mapping; the reader on synthetic sub-version 5/6 containers (table hit, unknown sub-version, location past the ISA, short blob, Durango refused, production table empty); the reachable set seeded by the initial MODE; `rsrc1_scan_checks_register_granules_and_reserved_bits_on_synthetic_containers`. - Mutations: initialising `tb_hw1` with `0xf0` again makes 26 of the 58 cases fail; swapping the wave32/wave64 granules makes the scan unit test fail. Both restored. - Full `tombox-xshader` suite on WARP: 350 passed, 0 failed, 19 ignored. - `pr_gate.py --base origin/main`: 0 problems. - [x] `cargo test -p tombox-xshader` passes for what is listed above - [x] No game or console files and no binaries included - [x] No fake success: nothing is read from an unproven location; the unknown MODE is logged 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An output modifier on an f16 VALU result acts only with MODE IEEE 0 and
f16/f64 denormals flushed (gfx1036 measurement, docs/BLOCKERS.md, "f16
output modifiers depend on the initial MODE"). The initial MODE comes from
the stage's PGM_RSRC1, which the translator did not receive; it always
assumed MODE 0xf0.

Plumbing:
- hlsl/mode.rs: mode_from_pgm_rsrc1 maps PGM_RSRC1 FLOAT_MODE [19:12] to
  MODE [7:0] (FP_ROUND, FP_DENORM), DX10_CLAMP [21] to MODE [8] and
  IEEE_MODE [23] to MODE [9]; PRIV [20], DEBUG_MODE [22] and the register
  counts are dropped.
- reachable/analyze start from that MODE instead of a fixed 0xf0, and
  tb_hw1 (the MODE copy read by s_getreg and by the f16 omod check) is
  initialised with it. The f32 and f16/f64 denormal paths follow the same
  value.
- hlsl::translate_with_pgm_rsrc1 takes PGM_RSRC1 from the caller.
- Every other entry point asks the container. The reader selects a
  location by the sub-version dword at FSSM byte 0x10, refuses Durango
  blobs and any location at or past the ISA. Its location table is empty:
  where PGM_RSRC1 sits inside the FSSM container is not proven (the
  COMPUTE_PGM_RSRC2 offsets found for #257 do not prove RSRC1, nor any
  graphics stage), so no container yields a value and MODE 0xf0 stays the
  default.
- With no PGM_RSRC1, a shader with an f16 VOP3 result carrying an omod
  gets a line in the new Translated.unknowns list, and d3d12_xs records
  the list once per shader hash (shader_xlat "UNKNOWN hash=...").

Not proven: the RSRC1 location in any container. Only the f16 omod is
reported as depending on the unknown MODE; f32 denormal handling also
depends on it and is not reported.

Tests:
- f16_omod_follows_initial_mode_from_pgm_rsrc1 (tests/exec.rs), 58 cases:
  v_add_f16/v_mul_f16 with each omod and clamp under 7 PGM_RSRC1 values
  (f16 denormals kept or flushed, IEEE on or off, DX10_CLAMP, PRIV,
  DEBUG_MODE and register counts set, all zero), an s_setreg after a
  flushing or keeping RSRC1, v_add_f32 of a denormal under 4 FLOAT_MODE
  values, and the unknowns line present only without PGM_RSRC1. WARP and
  an NVIDIA RTX 5090 (TOMBOX_EXEC_HW=1).
- hlsl::mode unit tests: the RSRC1 to MODE mapping, the reader on
  synthetic sub-version 5/6 containers (table hit, unknown sub-version,
  location past the ISA, short blob, Durango refused, production table
  empty), and the reachable set seeded by the initial MODE.
- Mutation: initialising tb_hw1 with 0xf0 again makes 26 of the 58 cases
  fail.

Sources: AMD RDNA2 ISA reference (MODE register: FP_ROUND [3:0],
FP_DENORM [7:4], DX10_CLAMP [8], IEEE [9]); LLVM AMDGPU (AMDGPUUsage
compute_pgm_rsrc1 table, SIDefines.h) and Mesa (MIT, sid.h
S_00B848_FLOAT_MODE / DX10_CLAMP / IEEE_MODE) for the PGM_RSRC1 fields and
the fact that the CP loads them into MODE at wave launch. Facts only, no
code taken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The PGM_RSRC1 location table stays empty. This adds the test that can
fill it from fixtures, modelled on the COMPUTE_PGM_RSRC2 fixture test of
#257: same gating (tombox_fixtures_shaders), same fixture walk
(analysis/shaders and TOMBOX_SHADER_DUMPS, default %TEMP%\tombox_shaders).

pgm_rsrc1_candidates_in_every_fssm_fixture, for every fixture of any stage:
- counts the VGPRs and SGPRs the ISA names (highest register + 1 from the
  disassembler's operands, a lower bound: multi-dword operands count their
  first register only) and the wave size from the existing mesh::wave_size;
- lists every dword before the ISA preamble, except the sub-version dword
  at 0x10, that fits as PGM_RSRC1:
  - VGPRS [5:0]: (VGPRS + 1) * granule covers the VGPRs used, granule 8
    in wave32 and 4 in wave64 (LLVM AMDGPUUsage, GFX10 compute_pgm_rsrc1
    GRANULATED_WORKITEM_VGPR_COUNT);
  - SGPRS [9:6]: 0 (GFX10 and later, LLVM AMDGPUUsage) or
    (SGPRS + 1) * 8 covering the SGPRs used (pre-GFX10 rule);
  - PRIORITY [11:10], PRIV [20], DEBUG_MODE [22] clear for every stage;
    for compute also BULKY [24], CDBG_USER [25] and [28:27] clear;
  - FLOAT_MODE round bits [15:12] zero (round to nearest even, the D3D
    rule); denormal bits, DX10_CLAMP and IEEE_MODE free;
- prints the dword 4 bytes before #257's COMPUTE_PGM_RSRC2 (0x12c for
  sub-version 5, 0x134 for sub-version 6) decoded, since the hardware
  registers COMPUTE_PGM_RSRC1/RSRC2 are consecutive (0x2e12/0x2e13);
- prints per sub-version the offsets that fit every fixture, fixed and
  counted back from the ISA, and how many fixtures the adjacent dword fits;
  Durango separately.
It fails only if the reader reads a Durango container, if a table entry
does not fit every fixture, or with "not proven" when fewer than two FSSM
fixtures exist. It asserts no location.

rsrc1_scan_checks_register_granules_and_reserved_bits_on_synthetic_containers
covers the wave32/wave64 granules, the SGPR rule, each reserved bit for
compute and for a non-compute stage, the round-mode bits, and the scan
recovering a planted dword from two synthetic containers while rejecting
an undersized VGPR field and a dword inside the ISA preamble. Mutation:
swapping the wave32/wave64 granules makes it fail.

Limits: a shader with few registers is weak evidence (many small dwords
fit), so a proof rests on fixtures with many VGPRs. Fields above bit 23
differ between SPI_SHADER_PGM_RSRC1_* stages and are only checked for
compute. No fixtures on this machine: the test is ignored, and forced it
fails with "not proven: 0 FSSM fixtures".

Sources: LLVM AMDGPU (AMDGPUUsage compute_pgm_rsrc1 table, SIDefines.h)
and Mesa (MIT, sid.h S_00B848_* fields) for the field layout and the
register offsets; AMD RDNA2 ISA reference for the MODE round modes. Facts
only, no code taken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fixture scan is run once by a contributor who has fixtures, so this
makes that single run settle as many location questions as possible.
Still print only: the test fails, as before, only if a production table
entry does not fit every fixture, if a Durango blob is read, or with "not
proven" under two FSSM fixtures. No location is added to any table.

pgm_rsrc1_candidates_in_every_fssm_fixture now:
- groups the RSRC1 offsets that fit every fixture by (sub-version, stage)
  and by (sub-version, hardware stage slot), besides the existing
  per-sub-version line that the production-table check uses; a graphics
  RSRC1 elsewhere than the compute one no longer empties the intersection.
- adds an RSRC2 scan, independent of RSRC1. Byte 0xd6 is the user SGPR
  count (#289). The hardware register is taken from the stage slot when
  one is set (0x40 PS, 0x38 VS, 0x28/0x30/0x58 GS), else from the stage
  (Pixel PS, Vertex VS, Hull HS, Compute and Amplification CS, others GS).
  A dword before the ISA preamble, outside 0x10..0x14, 0xd6 and
  0xe8..0x100, is an RSRC2 candidate when:
  - USER_SGPR [5:1], plus USER_SGPR_MSB [27] as bit 5 for PS/VS/GS/HS,
    equals byte 0xd6, or byte 0xd6 + 8 for the merged slots 0x28/0x30/0x58
    (the 8 system SGPRs of #289), the match kind is printed;
  - its must-be-zero bits are clear: reserved bits (CS 31; VS 23, 25, 26)
    and TRAP_PRESENT/EXCP_EN (and EXCP_EN_MSB for CS), the mask #257
    already uses for compute;
  - for CS, LDS_SIZE * 512 bytes covers the static LDS reach (largest DS
    offset plus element size, GDS forms left out, as in #257).
  It prints, per (sub-version, stage) and per (sub-version, slot), the
  RSRC2 offsets that fit every fixture.
- for each fixture, probes R = the RSRC2 offsets common to its
  (sub-version, stage) (up to 8), plus #257's 0x130/0x138 for CS, and
  prints and counts per (sub-version, stage, R):
  - RSRC2: R is a candidate of this fixture; the dword at R-4 decoded and
    whether it fits the existing RSRC1 filter.
  - AMDHSA kernel descriptor (CS only), descriptor at R-52:
    GROUP_SEGMENT_FIXED_SIZE rounds up to LDS_SIZE (512-byte granule)
    and covers the static LDS reach; KERNEL_CODE_ENTRY_BYTE_OFFSET (i64
    at R-36) lands on the ISA or on its preamble; reserved bytes at
    R-40..R-36 and R-28..R-8 are zero; RSRC1 at R-4 fits;
    ENABLE_WAVEFRONT_SIZE32 of KERNEL_CODE_PROPERTIES (u16 at R+4) matches
    the wave size; the 64-byte descriptor does not overlap the
    0xe8..0x100 table of #289 (for sub-version 5 with RSRC2 at 0x130 the
    descriptor would start at 0xfc and overlap it). RSRC3 at R-8,
    KERNARG_PRELOAD and the last dword are printed.
  - code region: u64 at 0xc0 and 0xc8 as offset (relative to +0x10) and
    size of a code region; whether it starts at R, at the ISA or at the
    ISA preamble; whether the dword before it fits RSRC1; for CS whether
    the three dwords after R equal the PSV0 group size.
- prints every set stage slot (0x18..0x58, 8 bytes each, 0 and
  0xdeadbeefdeadbeef empty) with its value minus the ISA offset, minus
  each probed R and minus the common RSRC1 offsets, and per (sub-version,
  slot) how many distinct differences there are, so a register at a fixed
  position from the slot value shows as one value.
- prints the 0xd6 byte, whether 0xe8 holds a table pointer, the slots,
  the RSRC2 register and the LDS reach per fixture. Hex output is compact
  (one line per item) since a run covers thousands of fixtures.

New unit tests on synthetic containers:
- rsrc2_scan_matches_user_sgprs_and_must_be_zero_bits_and_groups_by_stage:
  the USER_SGPR field with and without the MSB, CS reserved/trap bits,
  the LDS reach, a count that differs from 0xd6 rejected, the +8 merged
  match, VS bit 23 and PS EXCP_EN rejected, PS SHARED_VGPR_CNT allowed,
  register selection from slot and stage, and the grouping: two compute
  fixtures with RSRC2 at 0x138 and RSRC1 at 0x134 plus a pixel fixture
  with RSRC2 at 0x140 keep 0x138 for compute and 0x134 among the compute
  RSRC1 offsets, while the per-sub-version intersection is empty.
- amdhsa_descriptor_and_code_region_probes_on_synthetic_containers: a
  full descriptor at 0x104 (entry 0x4c to an ISA at 0x150) passes every
  check except the preamble one, RSRC2 at 0x130 is flagged as overlapping
  the #289 table, a code-region container (0xc0 = 0x128, group size
  64x1x1 after R) passes the region checks, a merged-slot GS fixture
  matches with +8, and the summary runs over these fixtures.
Mutation: making the USER_SGPR comparison ignore byte 0xd6 fails both.

Limits: byte 0xd6 is read even when 0xe8 holds no table, where its
meaning is not established. PS, GS and HS have no reserved RSRC2 bits on
gfx10.3, so their filter rests on USER_SGPR and TRAP/EXCP only. Which
register a Vertex shader without a slot uses (VS or GS under NGG) is a
guess, printed with each fixture. The code-region layout comes from notes
that are not verified. No fixtures on this machine: the fixture test was
only forced, and fails with "not proven: 0 FSSM fixtures".

Sources: #289 (GDAgent) for the user SGPR byte at 0xd6, the stage slots at
0x18..0x58 and their stage meaning; LLVM AMDGPUUsage (Code Object V3
Kernel Descriptor table, compute_pgm_rsrc2 table) and Mesa (MIT,
src/amd/registers/gfx103.json, the register definitions behind sid.h)
for the COMPUTE_PGM_RSRC2 and SPI_SHADER_PGM_RSRC2_PS/VS/GS/HS fields;
public notes of other Xbox runtime projects for the 0xc0/0xc8 code region
layout; #257 for the CS must-be-zero mask and the LDS reach rule. Facts
only, no code taken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:18:08 +00:00
github-bot closed this pull request 2026-11-26 06:18:08 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 18:13 UTC · original

@⁠GDAgent, a request since you have the fixtures (and ran the #257 test): could you run the scan on this branch (23b199c) and attach or paste the summary at the end of the output?

cargo test --release -p tombox-xshader --lib hlsl::mode::tests::pgm_rsrc1_candidates_in_every_fssm_fixture -- --exact --nocapture --include-ignored 2> rsrc_scan.txt

(TOMBOX_SHADER_DUMPS=<dir> if they are not under analysis/shaders.) It needs neither #289 nor #257. It uses the user SGPR byte at 0xD6 from #289 as a second, independent key for RSRC2 on every stage, and checks two layouts (AMDHSA kernel descriptor vs code region at 0xC0/0xC8). One run should tell where PGM_RSRC1 sits, whether 0x130 holds in sub-version 5, and where the graphics-stage RSRC2 is, which BLOCKERS lists as not checked. The only things it prints are offsets and decoded register fields.

**@⁠QuentinDanblon** on GitHub · 2026-11-23 18:13 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/309#issuecomment-7109844457) @⁠GDAgent, a request since you have the fixtures (and ran the #257 test): could you run the scan on this branch (`23b199c`) and attach or paste the summary at the end of the output? ``` cargo test --release -p tombox-xshader --lib hlsl::mode::tests::pgm_rsrc1_candidates_in_every_fssm_fixture -- --exact --nocapture --include-ignored 2> rsrc_scan.txt ``` (`TOMBOX_SHADER_DUMPS=<dir>` if they are not under `analysis/shaders`.) It needs neither #289 nor #257. It uses the user SGPR byte at 0xD6 from #289 as a second, independent key for RSRC2 on every stage, and checks two layouts (AMDHSA kernel descriptor vs code region at 0xC0/0xC8). One run should tell where PGM_RSRC1 sits, whether 0x130 holds in sub-version 5, and where the graphics-stage RSRC2 is, which BLOCKERS lists as not checked. The only things it prints are offsets and decoded register fields.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:49 UTC · original

Applied on main in 4c7c544 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/309#issuecomment-7164337279) Applied on main in 4c7c544 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.