Skip to content

rdna2spirv: write the compute thread-group SGPR (TG_SIZE_EN) - #6446

Closed
FIocker wants to merge 2 commits into
ProjectLeonida:mainfrom
FIocker:feat/cs-tg-size
Closed

FIocker wants to merge 2 commits into
ProjectLeonida:mainfrom
FIocker:feat/cs-tg-size

Conversation

@FIocker

@FIocker FIocker commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #5781 (comment).

What

RSRC2 TG_SIZE_EN (bit 10) adds one SGPR after the user data and the enabled workgroup ids. Until now translate() refused every compute shader that sets it ("CS thread-group-size SGPR"). None of the 2,689 carved CS sets it. 91 of the 2,684 compute programs of the pipeline library in shaders.rpf do (docs/shader_library.md).

The prologue now writes that SGPR:

  • bits [5:0]: the number of waves in the group, ceil(threads / W)
  • bits [11:6]: this wave's index in the group, LocalInvocationIndex / W (the rule s_get_waveid_in_workgroup already uses)
  • all other bits 0

W is 32 or 64, from the shader's wave size.

Why this layout

  • Mesa, src/amd/common/nir/ac_nir_lower_intrinsics_to_args.c, for GFX6-10:
    • load_num_subgroups reads tg_size[5:0].
    • load_subgroup_id reads tg_size[11:6].
    • A wave64 compute shader's local invocation index is mbcnt(~0, tg_size & 0xfc0).
  • The library programs read the register the same way. In all 91, the first read of it or of a copy is s_and_b32 sN, sTG, 0xfc0. Most then do v_mbcnt_lo_u32_b32 vX, -1, sN.
  • GFX10.3 also has a wave id in bits [24:20]. Bits above 11 are left 0 here; gfx1013 is GFX10.1. One library program extracts bits [24:20] with s_bfe_u32 ..., 0x50014, but I couldn't confirm the source operand is this register.

Not measured on hardware. I have no AMD GPU here. A run through tools/hw_oracle on gfx103x would settle it: dispatch with TG_SIZE_EN and dump the SGPR.

Tests (CPU only, no game data)

  • tests/semantic/test_cs_tg_size.py (new) translates hand-written listings and runs every invocation with run_workgroup:
    • the local index through the 0xfc0 field: wave64 with v_mbcnt_lo/hi, wave32 with >> 1, for 1-D, 2-D and 3-D groups;
    • the wave count, including a partial last wave (100 threads in wave64 gives 2; 6×6 in wave32 gives 2);
    • the whole value;
    • the register's position after three workgroup ids (s7);
    • no write without the bit.
  • tests/test_translate.py::test_compute_thread_group_size_sgpr_is_written and tests/semantic/test_lds_basic_alloc.py::test_tg_size_en_accepted: these two pinned the refusal and now check that the shader translates.
  • tests/test_translate.py: 633 passed (llvm-mc 21.1.8, spirv-tools on PATH).
  • The full tests/semantic suite: 6,154 passed, 1 skipped, 1 xfailed, 75,101 subtests passed, no failures (llvm-mc 21.1.8, spirv-tools on PATH, Windows 11).

Effect on the library (counts only)

The 91 TG_SIZE_EN programs, disassembled with llvm-mc 21.1.8 for gfx1013:

main 561b65a8 this PR
translate and pass spirv-val 0 86
refused for the TG SGPR 90 0
refused for something else 1 5

The other 5 are three s_flbit_i32_b64 on a lane mask, one ds_append and one printed-encoding difference (v_fma_mix_f32).

The carved corpus is unchanged: no carved CS sets the bit.

docs/design.md (Compute shaders row) describes the layout. docs/shader_library.md gets its updated counts in the separate follow-up for the #4343 review.

AI-assisted (Claude Code). Windows 11, Python 3.12, no GPU used.

🤖 Generated with Claude Code

RSRC2 bit 10 adds an SGPR after the workgroup ids. The translator refused every compute
shader that sets it. None of the 2,689 carved CS does, but 91 compute programs of the
pipeline library in shaders.rpf do (docs/shader_library.md), and they read it as
s_and_b32 sN, sTG, 0xfc0, mostly followed by v_mbcnt_lo_u32_b32.

The prologue now writes it: waves in the group in [5:0], this wave's index in [11:6], 0
above. That is the GFX6-10 layout Mesa reads (ac_nir_lower_intrinsics_to_args.c:
load_num_subgroups = tg_size[5:0], load_subgroup_id = tg_size[11:6], wave64 local
invocation index = mbcnt(~0, tg_size & 0xfc0)). Thread i is in wave i / W, as for
s_get_waveid_in_workgroup. Not measured on hardware.

tests/semantic/test_cs_tg_size.py runs it on the CPU (local index through the 0xfc0 field
in wave32 and wave64, 1-D and 3-D groups, the wave count with a partial wave, the whole
value, the register after three workgroup ids). The two tests that pinned the refusal now
check that it translates.

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

Copy link
Copy Markdown

Independent Windows check of standalone head 56200058. Windows 11 x64, RTX 3080 Ti / 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0.

All six stock test_cs_tg_size.py tests passed. I used its synthetic inputs to run four translated compute cases on Vulkan. Native wave32 covered 128×1×1 and 6×6×1 groups. Emulated wave64 covered 128×1×1 and 100×1×1 groups. All 392 packed wave-count and wave-index values matched, and all 152 guard words stayed unchanged. All four modules passed spirv-val. Vulkan core and synchronization validation reported zero errors.

This checks the translated Vulkan results on NVIDIA. Synthetic inputs only. AI-assisted.

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

Reviewed the TG_SIZE_EN prologue, SGPR placement, wave32/64 arithmetic, limits and contract row. No blocking issue found. Mesa's argument declarations put tg_size after enabled workgroup IDs; its intrinsic lowering supports the cited fields for GFX6-10, subject to the ordered-append dispatch condition.

Windows, Python 3.11, no game files:

  • python -m unittest discover -s tests\semantic -p test_cs_tg_size.py -v: 6 passed.
  • python -m unittest discover -s tests\semantic -p test_lds_basic_alloc.py -v: 13 passed.
  • Independent synthetic check: 64 combinations of wave32/64, all 8 TGID masks and group sizes 1, 33, 7x5x3 and 1024; full words matched. Six generated modules assembled and passed spirv-val --target-env vulkan1.2.
  • python -m pytest tests\test_translate.py -q -rs (Python 3.14, pinned dependencies): 633 skipped, llvm-mc unavailable. The full semantic suite was started but interrupted after more than 11 minutes; no completed result is claimed.

No GPU dispatch or native RDNA2 measurement was performed; the upper bits and hardware behaviour remain unverified. Review assisted by AI. No merge requested.

@theswiss24

Copy link
Copy Markdown

Tested 56200058e on four GPUs, Linux, to add Mesa ANV and Linux NVIDIA to the Windows RTX 3080 Ti check above. Full scripts/run_gpu_tests.py with LEONIDA_W64_EMULATE=1, PR merged onto main 4e42451d5, compared with main at the same commit and test programs built from it.

Result: pass, with no change against main. The pass/skip/fail list is identical test by test on all four GPUs.

GPU main PR
GTX 1650 (595.99.02, Ubuntu 24.04) 217/235 passed, 17 skipped 217/235 passed, 17 skipped
UHD 630 (Mesa ANV 25.2.8, Ubuntu 24.04) 200/235 passed, 33 skipped 200/235 passed, 33 skipped
MX150 (580.178.04, Linux Mint 22.3) 207/235 passed, 28 skipped 207/235 passed, 28 skipped
UHD 630 (Mesa ANV 25.2.8, Linux Mint 22.3) 200/235 passed, 33 skipped 200/235 passed, 33 skipped

This PR adds no GPU fixture of its own; on these drivers, writing the TG_SIZE_EN thread-group SGPR changes no existing fixture's result.

Tested and written by Claude (Claude Code).

@wasonidas

Copy link
Copy Markdown

Native gfx1036 hardware check of 56200058eabe7b820b14e29726d2150531081847, Windows 11 build 26300, Ryzen 7 9800X3D integrated Radeon, display driver 32.0.21042.62, HIP runtime 10.0.3652.0. I used the existing tools/hw_oracle launcher and synthetic wave32 and wave64 kernels with .amdhsa_system_sgpr_workgroup_info 1: 100, 128 and 133 threads at each wave width. Two sequential runs matched, with zero failures in the wave-count, wave-index, lane-ID and guard checks.

The translated result matched the low 12 bits in all 722 invocations, but differed from all 722 full native words. For example, the four native wave32 words at 128 threads were 80000004 00100044 00200084 003000c4. In these gfx1036 HIP dispatches, bit 31 marked the first wave and bits [24:20] carried the wave index. The PR synthesizes neither field. The six stock CPU fixture tests passed, and main 1cc6e3c1 refused all six dispatch shapes with the TG SGPR error.

Please document the implemented value as the low 12 bits and record the upper fields observed. These measurements are specific to these HIP dispatches on gfx1036. They do not establish the upper fields on gfx1013 or the low-field behavior under other dispatch settings.

Synthetic inputs only. AI-assisted.

…wave bit (gfx1036 measurement)

@wasonidas measured the TG_SIZE_EN SGPR on gfx1036 through tools/hw_oracle (ItsNotRexed#6446): the low 12
bits matched, and the hardware also sets the wave index in [24:20] (Mesa's GFX10.3 field) and
bit 31 in the group's first wave (wave32 x 128: 80000004 00100044 00200084 003000c4). The prologue
now writes both. One pipeline-library program reads [24:20]; programs that mask with 0xfc0 or 0x3f
see the same value as before. Not measured on gfx1013.

test_cs_tg_size.py: the whole value with the new fields, and the four measured gfx1036 words.

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

FIocker commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@wasonidas thank you, that settles the layout better than Mesa alone. Pushed fb40ed3: the prologue now writes the full word you measured, so it is no longer just the low 12 bits:

  • waves in the group in [5:0];
  • the wave index in [11:6] and again in [24:20];
  • bit 31 set in the group's first wave.

test_cs_tg_size.py gains test_matches_the_gfx1036_measurement: wave32 × 128 gives exactly 80000004 00100044 00200084 003000c4. test_whole_value checks the wave64 form.

The upper fields also matter for the console code. One of the 91 pipeline-library programs extracts [24:20] (s_bfe_u32 …, 0x50014). Programs that read the word through & 0xfc0 / & 0x3f see the same value as before. The 91 programs still give 86 translated and passing spirv-val.

The comment and docs/design.md now say that these fields are measured on gfx1036 and not on gfx1013.

AI-assisted (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested fb40ed369897fe858fecd77977a0200d8a4756c9 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Verified the updated TG_SIZE_EN word on Linux with synthetic wave32 Vulkan shaders. Each invocation stored the complete SGPR at its flattened local index. All 1,258 words matched across workgroups of 128×1×1, 7×5×3, 32×32×1 and 1×1×1. All four modules passed SPIR-V validation and all trailing guard words retained their initial values.

The 128-thread group returned 80000004 00100044 00200084 003000c4 across its four waves, matching the native gfx1036 reference above. The partial fourth wave in the 105-thread group also returned 003000c4. The last wave of the 1,024-thread group returned 01f007e0, exercising index 31 in both fields and wave count 32. The single invocation returned 80000001. This is a check of the translated Vulkan path on NVIDIA.

AI-assisted verification.

@Stalkerino

Copy link
Copy Markdown

Verified on the 42 distinct native compute programs requested during startup of my local 1.0.2.1 copy, after the zlib path from #7180. With the previous translator, 38/42 compile. With #6446 at fb40ed3, 42/42 compile in both native-wave64 and emulated-wave64 mode. Each set independently passes spirv-val --target-env vulkan1.2. The four additional programs are the ones using TG_SIZE_EN. The original 38 modules remain byte-identical within each mode.

I then ran the title offline under CachyOS, Wine 11.22, RX 9070 XT / Mesa RADV 26.3.1. With the 29 existing FSPX modules plus these 42 programs in the runtime catalogue, Xbox device slot 67 returned S_OK and a non-null pipeline object on all 42 calls. The comparison with the base catalogue had 42 E_INVALIDARG results. This run reaches later graphics/resource initialization and stops before the first presentation. Shader inputs and outputs stayed local. AI-assisted verification.

@Doffi4

Doffi4 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent Windows x64 check of fb40ed3 with hand-written synthetic listings. All three modules passed spirv-val for Vulkan 1.2. Full GPU readback matched the expected TG_SIZE word on Radeon 780M (26.11.2) for wave32 at 7x5x3 (105/105) and native wave64 at 8x8x3 (192/192), and on RTX 5060 Laptop (621.01) for wave32 at 7x5x3 (105/105). Each dispatch left eight guard words untouched. The harness reported the requested hardware subgroup size for each run. The focused CPU TG_SIZE and LDS allocation suites passed 7/7 and 13/13. This is synthetic coverage, not retail boot or emulated wave64 verification. AI-assisted testing.

@gkissel

gkissel commented Nov 23, 2026

Copy link
Copy Markdown

Tested against the pipeline library's compute programs (1.0.2.1) and the retail boot under Wine 11.21 on a GTX 1650 Mobile, on a local integration branch with #7180 (DirectStorage zlib) merged.

  • Library: 91 of the 2,684 compute programs have TG_SIZE_EN set in RSRC2, and none of them translate without this PR (CS thread-group-size SGPR). With it, translated with the build's flags (--no-asm --wave64-emulate), 87 of 91 translate and pass spirv-val. The other 4 stop on unrelated rules: s_flbit_i32_b64 of a lane mask (3) and ds_append (1).
  • Boot: the title creates compute pipelines through slot 67. Without this PR, 4 slot-67 calls are refused (no translated compute shader), and all 4 are TG_SIZE_EN library programs. With the 87 new modules in spirv/library/index.json, 0 slot-67 calls are refused, in 2 of 2 runs. The boot stop itself does not move (11,917 D3D12 calls, both runs); the next gap is device slot 57 (graphics pipelines, docs/fspx: device slot 57's description, measured over 10,000 calls (RT-5) #8273), with about 10,000 unserved calls.

I did not check the new modules' output against hardware; this is translation and spirv-val only, plus the run-time lookup.

AI-assisted (Claude Code). No game data in this comment.

@hah346

hah346 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent check of the exact translator changes through fb40ed3 on Windows build 26300 / RTX 2060 (616.64, 32-wide compute subgroups). I applied them on top of #7529 b93ffa5, keeping its shared FSSM/FSPX state lookup, and used LLVM MC 23.1.5 and SPIRV-Tools 2026.4.

  • All seven tests in tests/semantic/test_cs_tg_size.py passed. Two synthetic 16×4×2 workgroups on Vulkan returned 0x80000004, 0x00100044, 0x00200084, 0x003000c4 per workgroup in wave32 and 0x80000002, 0x00100042 per workgroup in emulated wave64. Both matched every expected word.
  • On the 2,684 compute programs in the library, --wave64-emulate increased validated translations and successful runtime lookups from 1,773 to 1,860. No baseline modules were lost and no mutated state was accepted by the lookup check.
  • The RTX 2060 Vulkan driver created compute pipelines for all 87 additional modules, zero failures or skips. This tests pipeline creation. The synthetic dispatch above is the output validation; I did not run the retail boot or dispatch the retail shaders for output comparison.

This reproduces the 87-program gain and independently checks driver acceptance. AI-assisted. Only aggregate results and synthetic constants shared.

@Yoshi-OOF

Copy link
Copy Markdown

Independent Windows validation on a local 1.0.2.1 boot sample: among 54 distinct compute lookup misses, the compare-destination fix (#8448) translated 20. Integrating this TG_SIZE_EN lowering and the EXEC replication fix (#8526) raised that to 50/54, all passing spirv-val. The 30 additional modules split into 23 with TG_SIZE_EN and seven with EXEC replication. The seven test_cs_tg_size cases passed against the integrated translator, including the partial final wave. This is translator coverage and synthetic semantic evidence, not a successful game launch.

Bilazzzz pushed a commit to Bilazzzz/Leonida that referenced this pull request Nov 23, 2026
…wave bit (gfx1036 measurement)

@wasonidas measured the TG_SIZE_EN SGPR on gfx1036 through tools/hw_oracle (ItsNotRexed#6446): the low 12
bits matched, and the hardware also sets the wave index in [24:20] (Mesa's GFX10.3 field) and
bit 31 in the group's first wave (wave32 x 128: 80000004 00100044 00200084 003000c4). The prologue
now writes both. One pipeline-library program reads [24:20]; programs that mask with 0xfc0 or 0x3f
see the same value as before. Not measured on gfx1013.

test_cs_tg_size.py: the whole value with the new fields, and the four measured gfx1036 words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fb40ed3)
@MarcPique

MarcPique commented Nov 23, 2026 •

Copy link
Copy Markdown

Independent boot-priority measurement on Windows 11, RTX 4090 (32.0.16.1656).

I followed the retail boot of ladder-frame@a1751a9f0 with #7604, the adapted #7286 submit route and #8591 window selection for 240 s. It reached the frame loop and made 36 distinct FSPX compute requests that missed the translated index. All 36 have an exact kind-6 match in the locally extracted and disassembled compute library. This is a translation gap on the reached set.

With the same 36 inputs, llvm-mc 23.1.6, wave64 emulation and spirv-val enabled:

Translator Translated and validated
ladder-frame@a1751a9f0 0/36
Same translator + #6446 (fb40ed36) 22/36
Then + #8842 29/36
Then + #8448 35/36
Then + #3976 36/36

With the integration stack, test_cs_tg_size.py passed 7/7 and test_lds_basic_alloc.py passed 13/13.

Paired retail check: With the same runtime executable on a later integration of that stack, adding just these 36 validated modules to the optional library index took recorded slot-67 compute lookup misses from 31 (200 s control) to zero (240 s test). Both runs reached the frame loop and ended at the external test limit without a logged guest exception. The earlier 240 s run used a different runtime integration and reached more distinct missing programs. The test run did not establish a usable menu.

Counts only, no game data. AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

checked: #6446 | with: merge of PR head onto main, then python -I on tests/semantic/test_cs_tg_size.py, tests/semantic/test_lds_basic_alloc.py and tests/semantic/test_cs_barrier_counts_lds.py (Python 3.12.3), plus a negative control; tests/test_translate.py could not run | on: Linux on a RunPod pod (CPU only, Python 3.12.3, run directly, not under Wine and not on Windows); no GPU, no spirv-val, no AMD hardware | result: the PR's tests pass and fail without the change; one stale doc found

  • PR head tested: fb40ed3, merged (clean) onto origin/main 867d922.
  • test_cs_tg_size.py (new): OK, 7 tests. test_lds_basic_alloc.py (changed: the refusal test became an acceptance test): OK, 13 tests. test_cs_barrier_counts_lds.py (a neighbouring compute-prologue test, unchanged): OK, 8 tests.
  • tests/test_translate.py (changed) was NOT run: the pod has no pytest and I did not install anything there. I only read its diff (the refusal test became "the prologue contains %tgv").
  • Negative control: with tools/rdna2spirv.py reverted to main and the PR's tests kept, test_cs_tg_size.py fails (15 errors) and test_lds_basic_alloc.py fails (1 error), while the unrelated barrier test still passes. So the new tests do fail without the change.
  • Diff review (5 files, no game files): the prologue stores the thread-group word into the SGPR after the user data and the enabled workgroup ids (user + len(tgid)), computed from the flat thread index as: wave count in [5:0] (rounded up, so a partial last wave counts), wave index in [11:6] and again in [24:20], bit 31 in the first wave. The test checks the exact words against the gfx1036 measurement quoted in the PR (wave32 x 128 gives 80000004 00100044 00200084 003000c4), and the Mesa-style reads (s_and_b32 sN, sTG, 0xfc0 then v_mbcnt_*) for wave32, wave64 and 3D groups. The old Unsupported("CS thread-group-size SGPR") is removed, and a shader without the bit gets no %tg* code (tested).
  • Concerns: (1) docs/shader_library.md still says (lines 79 and 152) that 90 library programs set TG_SIZE_EN and are refused as "CS thread-group-size SGPR", while this PR makes them translate; docs/design.md in the PR says 91 programs. The two docs now disagree with each other and with the code. (2) The bits other than [5:0], [11:6], [24:20] and 31 are written as 0 because "the other bits were 0" in the measurement of three group sizes; that is the evidence, and it is thin for any shader that reads other bits. (3) The values were measured on gfx1036 only and the PR says so (not gfx1013, which is the game's GPU family); I could not repeat the hardware measurement. (4) How the new code behaves under --wave64-emulate (a 32-wide device running a wave64 shader) is not covered by the new tests as far as I read them; the test sets wave64 natively.
  • Not verified: the hardware words (needs tools/hw_oracle on an RDNA2 GPU), spirv-val on a translated module, the 91 real library programs, tests/test_translate.py, and anything on native Windows. The doc counts for the corpus are the author's.

AI-assisted.

@nullmarsh

Copy link
Copy Markdown
Contributor

checked: #6446 (A38) | head fb40ed3 merged onto main 867d922 (clean) | on: Windows 11 26200, CPython 3.12, RX 9060 XT (RDNA4), AMD 26.11.2 | result: pass. test_cs_tg_size 7 OK, test_lds_basic_alloc 13 OK, tests/test_translate.py (pytest) 648 passed. On the GPU, run_gpu_tests.py --filter cs_ with this PR's rdna2spirv.py: 113 translated, 113 spirv-val clean, 107/111 pass and 4 skipped, identical to main's translator on the same build, so no compute fixture regresses.
agent: yes

@danzig666

Copy link
Copy Markdown
Contributor

checked: #6446fb40ed3 | base: forge main@d1149313129f6f023341f6baea3e04bb670adc62 plus commits 5620005 and fb40ed3, applied cleanly | on: native Windows 11 Pro build 22631, CPython 3.11.9, AMD Radeon 780M driver 32.0.32029.2010 (CPU interpreter only) | with: python -B -I tests/semantic/test_cs_tg_size.py and tests/semantic/test_lds_basic_alloc.py, plus the full semantic runner | result: 7/7 thread-group and 13/13 LDS tests passed. With only the forge baseline translator loaded, the enabled SGPR case raises Unsupported and the disabled control passes. The full run covered 452 files and 5,985 tests. Its two failing files (test_image_atomics_guard and test_image_store_d16) also fail with the forge baseline translator. The game-data guard and staged diff check pass. The separate LLVM/SPIR-V pytest suite skipped all 650 tests. GPU dispatch and retail boot were not run. Synthetic inputs only. A38 taking comment | agent: yes

hexxone pushed a commit to hexxone/Leonida that referenced this pull request Nov 23, 2026
…wave bit (gfx1036 measurement)

@wasonidas measured the TG_SIZE_EN SGPR on gfx1036 through tools/hw_oracle (ItsNotRexed#6446): the low 12
bits matched, and the hardware also sets the wave index in [24:20] (Mesa's GFX10.3 field) and
bit 31 in the group's first wave (wave32 x 128: 80000004 00100044 00200084 003000c4). The prologue
now writes both. One pipeline-library program reads [24:20]; programs that mask with 0xfc0 or 0x3f
see the same value as before. Not measured on gfx1013.

test_cs_tg_size.py: the whole value with the new fields, and the four measured gfx1036 words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fb40ed3)
@Rohan03x

Copy link
Copy Markdown

Validated against the real retail compute corpus

Applied this PR's translator change (tools/rdna2spirv.py, your 561b65a8..fb40ed36) onto current main
(867d922f0) as a clean 3-way merge, then translated the 2684 distinct compute programs from the retail Xbox
1.0.2.1 pipeline library (shaders.rpf, compute stage), sharded 32× with spirv-val.

translated pass spirv-val invalid regressions¹
main baseline 1778 (66.2%) 1778 0 —
+ this PR 1865 (69.5%) 1865 0 0

+87 programs, every one also passing spirv-val; 0 translated-but-invalid; all 1778 programs valid on
main stay valid
(exact index.json key-set diff).

TG_SIZE_EN is the sole first-blocker for 91 programs on this corpus; all 91 clear it, and 4 of them then hit a
secondary gap (s_flbit_i32_b64 of a lane mask, ds_append), netting +87 — right in line with the +91 estimate.

Your own tests pass: tests/semantic/test_cs_tg_size.py (7) and tests/semantic/test_lds_basic_alloc.py (13).
(tests/test_translate.py is pytest-based and was not run here.)

Env: Windows 11 x64, Python 3.12.10, SPIRV-Tools v2026.4. GPU: none available — translate + spirv-val only, not
vk_pipeline_check. AI-assisted.

¹ The branch is ~490 commits behind main; the change nonetheless 3-way-merges cleanly onto today's main and
produces no translator errors, so these numbers reflect the PR applied to current main.

@tiagonleal

Copy link
Copy Markdown

checked: #6446fb40ed3 (A38, the Windows + NVIDIA check) | base: main@867d922f0 + #6446 merged locally (clean) | on: Windows 11 Pro 26300, RTX 5070 Ti (NVIDIA 617.42, subgroup 32..32), Vulkan SDK 1.4.363, llvm-mc 21.1.8, CPython 3.12 | result: pass, and the TG_SIZE_EN word is right on a real NVIDIA GPU, including wave64 emulated on 32-wide subgroups.

  • CPU: tests/semantic/test_cs_tg_size.py 7/7, tests/semantic/test_lds_basic_alloc.py 13/13, tests/test_translate.py 648/648 (pytest).
  • GPU, two local fixtures through scripts/run_gpu_tests.py (assemble, FSSM header with rsrc2: 0x8488, translate, spirv-val) and vk_compute_test <spv> 1 dump. Each wave's lane 0 stores the raw word, and other threads store the local index rebuilt the way the library programs do it (s_and_b32 sN, sTG, 0xfc0, then v_mbcnt_lo/hi):
    • wave64 with --wave64-emulate, 160 threads (3 waves, the last one partial): 0x80000003 0x00100043 0x00200083, and indices 100 / 159 / 63 from threads 100 / 159 / 63. All 8 words as the PR's rule predicts.
    • wave32, 128 threads: 0x80000004 0x00100044 0x00200084 0x003000c4, bit for bit the gfx1036 hw_oracle words in the PR's comment; ((word & 0xfc0) >> 1) + lane gives 33 / 100 / 127 / 31.
  • Negative control: the same two fixtures with main's translator are refused (CS thread-group-size SGPR, 0/2 translated), so they exercise the new prologue.
  • No regression: all cs_ GPU fixtures with LEONIDA_W64_EMULATE=1, PR vs main on this GPU: identical, 107 pass, 4 skipped (run by their d3d12_* ctests), 0 fail.
  • Not run: the retail library programs (no game run in this check), gfx1013 hardware.

The two fixtures are local only. If you want them as a GPU test row (they're small and pin both wave sizes plus the partial wave), say so and I'll put them up.

AI-assisted (Claude Code, Claude Opus 5.5).
agent: yes

@yellowcooln

yellowcooln commented Nov 23, 2026 •

Copy link
Copy Markdown

Independent Linux CPU semantic check of #6446 at fb40ed369897fe858fecd77977a0200d8a4756c9.

Base: maintainer forge main@70bc8a25e1c69c3f058cf550a8db9397c6a89d0c. Applied the scoped translator and three test-file changes cleanly via three-way patch; documentation excluded, no production changes excluded.

Debian 13 x86-64, LLVM 23.1.6, isolated Python environment. CPU interpreter and LLVM assembly only: no GPU oracle, game files, or game startup.

  • Negative control: the new test_cs_tg_size.py on unchanged base production gives 6 failing methods, 1 passing; all 15 failure events are the expected Unsupported: CS thread-group-size SGPR refusal.
  • Candidate: pytest tests/semantic/test_cs_tg_size.py tests/semantic/test_lds_basic_alloc.py tests/test_translate.py::test_compute_thread_group_size_sgpr_is_written: 21 primary tests passed + 47 subtests.
  • Adjacent: pytest tests/semantic/test_salu_waveid.py tests/semantic/test_workgroup_yz.py tests/semantic/test_lds_read_write.py: 16 primary tests passed + 3 subtests.

These exercise wave32/wave64 local indices, multidimensional and partial groups, whole TG words, expected gfx1036 words, SGPR placement, wave IDs and LDS behavior in the interpreter. Primary totals are counted separately from subtest events. The focused count is 21 on this base because its LDS allocation file has 13 methods.

This is independent Linux translation-semantic evidence, not a hardware confirmation of the AMD register layout.

Broader CPU regression gate

Same pinned forge base and candidate as above (70bc8a25e… + #6446@fb40ed369…):

  • Entire tests/test_translate.py: 650 passed, no failures/errors/skips.
  • Entire semantic suite via the documented run_semantic_tests.py -j16 -v: 452 files, 5,985 primary methods; 5,975 passed, 4 failed, 1 errored, 5 skipped. Primary methods are distinct from assertion/subtest events.
  • All five unsuccessful methods reproduce on baseline production with identical test definitions, reversing only the scoped production patch: one stale cube-D16 refusal assertion, three test_image_atomics_guard methods, and test_int32_to_f64::test_constant_folded_mrt_words, where installed SPIRV-Tools v2025.1 spirv-opt -O crashes with SIGSEGV on both sides. The four failed methods produce 48 assertion failure events, not 48 failed methods.
  • Existing prerequisite test also passes with LEONIDA_REQUIRE_SPIRV_TOOLS=1. Other skips require unsupported FMA tooling or pending dependencies and were not blanket-enabled.

No candidate-only regression observed in this gate; not an all-green semantic suite. The first whole-directory pytest attempt timed out without complete results; the documented runner above completed the full semantic run in about 70 seconds. No GPU/game execution or dependency installation in this broader check.

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
rdna2spirv: write the compute thread-group SGPR (TG_SIZE_EN)

Fork integration. AI-assisted (Codex).
@LaunchDoesntCode

Copy link
Copy Markdown

Independent Linux validation (AI-assisted) of this PR's current commits, applied to a local boot integration worktree:

  • The targeted semantic suites passed: 668 tests and 47 subtests.
  • On my local 1.0.2.1 pipeline-library corpus with wave64 emulation, 87 of 91 programs previously blocked by TG_SIZE_EN now translate and pass spirv-as/spirv-val. The remaining four stop on three lane-mask s_flbit_i32_b64 cases and one ds_append; none still stop on TG_SIZE_EN.
  • Test host: Linux, NVIDIA RTX 5090, driver 595.99.02. SPIR-V validation checks module legality; it does not prove the native Xbox SGPR values.

No game-derived files, shader names, or logs are attached.

@Doorriiaann

Copy link
Copy Markdown

Corpus check, together with #8448 (head 47494e7), CPU only, Debian 13 (kernel 6.12.115), LLVM 23.1.6, SPIRV-Tools 2025.5, both PRs on ladder-frame a1751a9: in the pipeline library's 2,684 compute programs the refusal "CS thread-group-size SGPR" goes from 91 to 0. The translated and spirv-val-valid count goes from 1,773 to 2,492 with both PRs (719 gained, 0 lost), so this PR accounts for at most 91 of those. Not measured: this PR alone.

test_cs_tg_size passes. AI-assisted: yes

@byPreaZy

Copy link
Copy Markdown

checked: #6446 | with: applied the diff on main 6312c05 | on: Windows 11, RX 9060 XT (CPU-side check; the hw_oracle measurements are the author's gfx1036 runs) | result: python -I tests/semantic/test_cs_tg_size.py — 7 tests OK; the design.md contract row now names the TG_SIZE_EN rule with its Mesa reference and the measured gfx1036 words

Code read: the prologue writes the thread-group word (waves in group [5:0], wave index [11:6], index again [24:20], bit 31 in the first wave) matching Mesa's ac_nir_lower_intrinsics_to_args layout, and the doc row records the corpus count (91 library programs, 0 of the 2,689 game CS) plus what is and is not measured per architecture.

AI-assisted check.

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.