shader: accept byte-window buffer descriptors for stores in the direct C++ compute path #2967

Merged
Leyukaka merged 1 commit from upstream-pr/2967 into cpp-migration 2026-11-27 00:36:09 +00:00
Leyukaka commented 2026-11-27 00:09:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-27T00:09:31Z.


Fixes #2965 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch cpp-migration.

Change (src/gfx1013_compute_native.cpp): a loaded structured-buffer descriptor is often turned into a raw byte window before a buffer store:

  • word 1 & 0xc000ffff clears the stride;
  • word 2 is multiplied by the clamped stride (s_bfe_u32 ..., 0xe0010, then s_max_u32 ..., 1);
  • word 3 | 0x30000000 sets OOB_SELECT to 3.

The analysis already recognised these edits, but only loads used them (byte_window_srv). This change does two things:

  • binding() accepts the same byte-window word pattern for a buffer_store_raw through a 4-word raw_buffer_uav whose word 1 is the cleared stride. It binds the unmodified descriptor as before, as tools/startup/gfx2hlsl.py does, so the manifest and runtime are unchanged. Buffer atomics, which also bind raw_buffer_uav, keep the strict check, as in gfx2hlsl.py.
  • s_or_b32 x, 0x30000000 on a plain loaded word 3 now also yields byte_oob, in addition to the cleared form, as gfx2hlsl.py accepts it for stores. The OR forces DW3[29:28] to 3 and touches no other bit. This also lets byte_window_srv loads use the OR-only form, which gfx2hlsl.py does not lower. It gives the same word as the cleared form, but it is not covered by the new test.

The stride proof and descriptor identity checks are unchanged. Out-of-range behaviour is that of the bound raw view; sizing the view to the converted byte count would be runtime work and is not in scope.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on cpp-migration f934df52 plus this commit.

  • native_bytewin_store_hardware passed. The issue's exact sequence feeds stores of 1, 2, 3 and 4 dwords, fully inside the bound view, in two 32-lane groups. All written words, the unwritten words and the guards matched.
  • native_bytewin_store_controls passed. Four forms stay refused:
    • a plain SGPR constant as the multiplier;
    • word 2 taken from a different descriptor;
    • s_or_b32 with 0x20000000;
    • a buffer_atomic_add through the byte-window descriptor.
  • native_salu64_hardware, native_shift64_hardware, native_lane_access_hardware and native_compute_clear still pass.

Mutation checks, run by hand; each fails the controls:

  • dropping the clamped-stride proof lets the constant-multiplier control compile;
  • comparing descriptor fields by type only (ignoring which descriptor they come from) lets the foreign word 2 control compile;
  • dropping the store-only restriction lets the atomic control compile.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests.

  • Of 2,689 compute requests, 297 compiled on f934df52 and 388 with this commit; none that compiled before stops compiling.
  • On f934df52, 119 requests stop first at "non-contiguous resource descriptor". With this commit:
    • 91 of them compile;
    • 9 still stop there (atomics, and the out-of-scope multipliers);
    • the rest stop at later refusals: "unbound numeric SGPR" (11), "unsupported wave64 scalar operation" (4), image descriptor modifiers (3) and one other.
  • The runtime still uses the Python translator, so I matched pipelines by request key against a 600 s start-up run. Over that run's 2,718 requests, 104 more compile with this commit. 69 of them were dispatched 25,073 times in that run, all left untranslated by the Python translator.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518936203 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2967). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T00:09:31Z. --- Fixes #2965 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch `cpp-migration`. **Change** (`src/gfx1013_compute_native.cpp`): a loaded structured-buffer descriptor is often turned into a raw byte window before a buffer store: - word 1 `& 0xc000ffff` clears the stride; - word 2 is multiplied by the clamped stride (`s_bfe_u32 ..., 0xe0010`, then `s_max_u32 ..., 1`); - word 3 `| 0x30000000` sets `OOB_SELECT` to 3. The analysis already recognised these edits, but only loads used them (`byte_window_srv`). This change does two things: - `binding()` accepts the same byte-window word pattern for a `buffer_store_raw` through a 4-word `raw_buffer_uav` whose word 1 is the cleared stride. It binds the unmodified descriptor as before, as `tools/startup/gfx2hlsl.py` does, so the manifest and runtime are unchanged. Buffer atomics, which also bind `raw_buffer_uav`, keep the strict check, as in `gfx2hlsl.py`. - `s_or_b32 x, 0x30000000` on a plain loaded word 3 now also yields `byte_oob`, in addition to the cleared form, as `gfx2hlsl.py` accepts it for stores. The OR forces DW3[29:28] to 3 and touches no other bit. This also lets `byte_window_srv` loads use the OR-only form, which `gfx2hlsl.py` does not lower. It gives the same word as the cleared form, but it is not covered by the new test. The stride proof and descriptor identity checks are unchanged. Out-of-range behaviour is that of the bound raw view; sizing the view to the converted byte count would be runtime work and is not in scope. **Tests.** The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on `cpp-migration` `f934df52` plus this commit. - `native_bytewin_store_hardware` passed. The issue's exact sequence feeds stores of 1, 2, 3 and 4 dwords, fully inside the bound view, in two 32-lane groups. All written words, the unwritten words and the guards matched. - `native_bytewin_store_controls` passed. Four forms stay refused: - a plain SGPR constant as the multiplier; - word 2 taken from a different descriptor; - `s_or_b32` with `0x20000000`; - a `buffer_atomic_add` through the byte-window descriptor. - `native_salu64_hardware`, `native_shift64_hardware`, `native_lane_access_hardware` and `native_compute_clear` still pass. **Mutation checks**, run by hand; each fails the controls: - dropping the clamped-stride proof lets the constant-multiplier control compile; - comparing descriptor fields by type only (ignoring which descriptor they come from) lets the foreign word 2 control compile; - dropping the store-only restriction lets the atomic control compile. **Measured on a local capture** (counts and instruction shape only) with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests`. - Of 2,689 compute requests, 297 compiled on `f934df52` and 388 with this commit; none that compiled before stops compiling. - On `f934df52`, 119 requests stop first at "non-contiguous resource descriptor". With this commit: - 91 of them compile; - 9 still stop there (atomics, and the out-of-scope multipliers); - the rest stop at later refusals: "unbound numeric SGPR" (11), "unsupported wave64 scalar operation" (4), image descriptor modifiers (3) and one other. - The runtime still uses the Python translator, so I matched pipelines by request key against a 600 s start-up run. Over that run's 2,718 requests, 104 more compile with this commit. 69 of them were dispatched 25,073 times in that run, all left untranslated by the Python translator. AI-assisted.
MasterDomino commented 2026-11-27 00:36:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T00:36:06Z.

Review: APPROVED


Review of head e14954fd, tested merged onto cpp-migration 0b1456ce (after #2964 and #2966). It auto-merges cleanly, and CI on the head is green. Approving and merging.

Code read:

  • A 4-word raw_buffer_uav store (buffer_store_raw) whose word 1 is the cleared stride now goes through the same descriptor, zero_stride_word, byte_count and byte_oob field chain that byte_window_srv loads use. The descriptor-identity and stride proofs are unchanged, and atomics keep the strict check.
  • s_or_b32 x, 0x30000000 on a plain word 3 now yields byte_oob too. As you note, that also widens byte_window_srv loads to the OR-only form, which the new test does not cover.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. ctest --preset release --no-tests=error -R '^native_' gives 50 tests, 49 passed and 1 skipped (77, native_comparison_pso_warp), including native_bytewin_store_hardware and native_bytewin_store_controls.

Mutation here: disabling the store byte-window path (false && in front of i.name == "buffer_store_raw") makes native_bytewin_store_hardware fail at compile with native compute +0x4c: non-contiguous resource descriptor, the refusal this PR removes. The controls still pass. With it restored, both pass.

Nit: as on your other PRs, docs/experiments.md gains a pointer section next to the topic note. I will close #2965 by hand.

AI-assisted; the commands above were run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6081999908 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2967#pullrequestreview-6081999908). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T00:36:06Z. **Review:** APPROVED --- Review of head `e14954fd`, tested merged onto `cpp-migration` `0b1456ce` (after #2964 and #2966). It auto-merges cleanly, and CI on the head is green. Approving and merging. **Code read:** - A 4-word `raw_buffer_uav` store (`buffer_store_raw`) whose word 1 is the cleared stride now goes through the same descriptor, `zero_stride_word`, `byte_count` and `byte_oob` field chain that `byte_window_srv` loads use. The descriptor-identity and stride proofs are unchanged, and atomics keep the strict check. - `s_or_b32 x, 0x30000000` on a plain word 3 now yields `byte_oob` too. As you note, that also widens `byte_window_srv` loads to the OR-only form, which the new test does not cover. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. `ctest --preset release --no-tests=error -R '^native_'` gives 50 tests, 49 passed and 1 skipped (77, `native_comparison_pso_warp`), including `native_bytewin_store_hardware` and `native_bytewin_store_controls`. **Mutation here:** disabling the store byte-window path (`false &&` in front of `i.name == "buffer_store_raw"`) makes `native_bytewin_store_hardware` fail at compile with `native compute +0x4c: non-contiguous resource descriptor`, the refusal this PR removes. The controls still pass. With it restored, both pass. **Nit:** as on your other PRs, `docs/experiments.md` gains a pointer section next to the topic note. I will close #2965 by hand. AI-assisted; the commands above were run locally.
Sign in to join this conversation.
No reviewers
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!2967
No description provided.