shader: read the wave size of slot 67 compute requests (bit 20 of .sa dword 4) instead of assuming wave32 #2999

Closed
opened 2026-11-27 03:54:05 +00:00 by Leyukaka · 0 comments
Leyukaka commented 2026-11-27 03:54:05 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-27T03:54:05Z.


Target branch cpp-migration. Part of #2935. I would like to take this; please say if you already have it locally and I will drop it.

Gap. The C++ compiler compiles every slot 67 .c67 request as wave32. translate_compute passes no container stage, so wave64 = stage && !stage->wave32 is always false (src/gfx1013_compute_native.cpp). Only translate_compute_container reads a wave size, from the FSSM stage record. Nothing in the tree reads one from a request part; on the Python side, gfx2hlsl.py notes that the program text alone does not give the wave size and uses a vcc_hi heuristic.

Observation. In a local capture of 2,689 compute requests (counts and instruction shape only), bit 20 of .sa dword 4 splits the requests the way a wave size would. The compiler reads only bits 15:0 of that dword, for Z; bits 31:16 take only two values in the capture, 0x0000 and 0x0010.

  • Decoded up to the first s_endpgm: every program that contains a *_saveexec_b32 and no *_saveexec_b64 has the bit set (1,385 of 1,385). Every program that contains a *_saveexec_b64 and no *_saveexec_b32 has it clear (565 of 565). The next best bit of .sa or .sb agrees on 87% (bit 5 of dword 3, the X = 32 bit). The 739 programs with no saveexec there are not constrained by this test.
  • v_mbcnt_hi_u32_b32 appears only with the bit clear (197 programs, 0 with the bit set). Every bit-clear program that uses v_mbcnt_lo_u32_b32 also uses v_mbcnt_hi_u32_b32. The 84 bit-set programs that use v_mbcnt_lo_u32_b32 never use v_mbcnt_hi_u32_b32.
  • Group sizes mostly follow the bit. Of the 784 requests with a 64-thread group, 739 have it clear. Of the 1,433 requests with a 32-thread group, 1,405 have it set.

So I read the bit as "wave32" for these requests. This is an inference from the captured data, not from documentation.

Effect today, with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests on cpp-migration 4ff5e36d:

  • 1,154 of the 2,689 requests have the bit clear, and 308 of them compile as wave32 today. 22 of those 308 use v_mbcnt_hi_u32_b32, which the wave32 lowering treats as contributing 0. 36 use v_readfirstlane_b32, and 15 branch wave-wide on VCC. I have not shown a wrong result from any of them. That depends on how each program uses lane indices.
  • In the requests of one start-up run, 433 compute requests stop first at "unbound numeric SGPR". In 290 of them, the bit is clear and the register is the odd (high) word of a pair.

Plan:

  • Read the bit from .sa in read_compute_request and pass it to translate_compute. A clear bit selects the existing wave64 path, the same one translate_compute_container uses for a container stage without wave32.
  • A .sa that is too short, or a request without .sa, keeps today's wave32 behavior.
  • The request revision changes, so cached translations are rebuilt.

Tests:

  • A source-built request with the bit clear that stores v_mbcnt_lo/v_mbcnt_hi lane indices across a 64-thread group. It is compared on hardware with a CPU reference (0..63 per wave).
  • The same program with the bit set keeps the wave32 result.
  • Mutants:
    • ignoring the bit must fail the wave64 case;
    • inverting it must fail the wave32 case.

Measurement: the census and the run's requests, before and after. I will report requests that newly compile, requests that stop compiling, and the requests whose first refusal changes.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6639610174 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2999). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T03:54:05Z. --- Target branch `cpp-migration`. Part of #2935. I would like to take this; please say if you already have it locally and I will drop it. **Gap.** The C++ compiler compiles every slot 67 `.c67` request as wave32. `translate_compute` passes no container stage, so `wave64 = stage && !stage->wave32` is always false (`src/gfx1013_compute_native.cpp`). Only `translate_compute_container` reads a wave size, from the FSSM stage record. Nothing in the tree reads one from a request part; on the Python side, `gfx2hlsl.py` notes that the program text alone does not give the wave size and uses a `vcc_hi` heuristic. **Observation.** In a local capture of 2,689 compute requests (counts and instruction shape only), bit 20 of `.sa` dword 4 splits the requests the way a wave size would. The compiler reads only bits 15:0 of that dword, for Z; bits 31:16 take only two values in the capture, 0x0000 and 0x0010. - Decoded up to the first `s_endpgm`: every program that contains a `*_saveexec_b32` and no `*_saveexec_b64` has the bit set (1,385 of 1,385). Every program that contains a `*_saveexec_b64` and no `*_saveexec_b32` has it clear (565 of 565). The next best bit of `.sa` or `.sb` agrees on 87% (bit 5 of dword 3, the X = 32 bit). The 739 programs with no `saveexec` there are not constrained by this test. - `v_mbcnt_hi_u32_b32` appears only with the bit clear (197 programs, 0 with the bit set). Every bit-clear program that uses `v_mbcnt_lo_u32_b32` also uses `v_mbcnt_hi_u32_b32`. The 84 bit-set programs that use `v_mbcnt_lo_u32_b32` never use `v_mbcnt_hi_u32_b32`. - Group sizes mostly follow the bit. Of the 784 requests with a 64-thread group, 739 have it clear. Of the 1,433 requests with a 32-thread group, 1,405 have it set. So I read the bit as "wave32" for these requests. This is an inference from the captured data, not from documentation. **Effect today**, with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests` on `cpp-migration` `4ff5e36d`: - 1,154 of the 2,689 requests have the bit clear, and 308 of them compile as wave32 today. 22 of those 308 use `v_mbcnt_hi_u32_b32`, which the wave32 lowering treats as contributing 0. 36 use `v_readfirstlane_b32`, and 15 branch wave-wide on VCC. I have not shown a wrong result from any of them. That depends on how each program uses lane indices. - In the requests of one start-up run, 433 compute requests stop first at "unbound numeric SGPR". In 290 of them, the bit is clear and the register is the odd (high) word of a pair. **Plan:** - Read the bit from `.sa` in `read_compute_request` and pass it to `translate_compute`. A clear bit selects the existing wave64 path, the same one `translate_compute_container` uses for a container stage without `wave32`. - A `.sa` that is too short, or a request without `.sa`, keeps today's wave32 behavior. - The request revision changes, so cached translations are rebuilt. **Tests:** - A source-built request with the bit clear that stores `v_mbcnt_lo`/`v_mbcnt_hi` lane indices across a 64-thread group. It is compared on hardware with a CPU reference (0..63 per wave). - The same program with the bit set keeps the wave32 result. - Mutants: - ignoring the bit must fail the wave64 case; - inverting it must fail the wave32 case. **Measurement:** the census and the run's requests, before and after. I will report requests that newly compile, requests that stop compiling, and the requests whose first refusal changes. AI-assisted.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#2999
No description provided.