Shaders: LDS sub-dword writes, typed buffers at offsets and of some channels, typed loads by index #1957

Open
RaghavVijayanand wants to merge 5 commits from upstream-pr/1959 into main
RaghavVijayanand commented 2026-11-25 01:45:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RaghavVijayanand on 2026-11-25T01:45:24Z.


Buffer and LDS gaps in the translator, in four commits. Each builds and passes tests.

  • LDS byte and half writes keep one lane's value. Main (0b35b7f) already reads and writes LDS bytes and halves, but writes them with an atomic AND then OR, noted there as a shortcut. When several lanes write the same byte, that merges their bits. The write is now a compare-exchange loop on the dword, so neighbouring bytes are never clobbered and exactly one lane's value lands, as on the console. Main's read path is kept.
  • Typed buffer loads and stores at a byte offset: the access goes to element index + offset / element size.
    • The element size is taken from the used-resource entry's stride. This is a documented assumption: it is not verified that the console compiler records the format size there.
    • Still refused: a constant offset inside an element, and any offset when no stride is known.
  • Typed stores of fewer than four channels: dxil.dll requires full masks on typed UAV stores. So the store loads the element, keeps the channels it isn't given, and stores all four, inside the same EXEC guard.
    • Documented limits: it assumes the console leaves those channels untouched; an snorm -128 round-trips as -127; and the store is not atomic against other lanes writing the same element.
  • tbuffer_load_format_* by index: reads at byte index * stride + offset, through main's bindless-stride conversions (a root view's built descriptor takes its stride from dword 1, and a heap descriptor from the view-stride table).
    • Behaviour change to main's raw path: the lane-index-added refusal (dword 3 bit 23) now also applies to raw accesses through a root view, which main translated silently and incorrectly. This is easy to revert if you prefer main's behaviour.
    • Swizzled and add-tid descriptors are still refused.

Tests: the new emit/buffer_lds_tests.rs (8 tests) and a View::FormatUav in the test host. Every program is hand-assembled, validated with dxil.dll, run on the default hardware adapter and WARP, and checked against a CPU model.

  • LDS: 64 threads in two waves write neighbouring and identical bytes, with EXEC-only guards, and read back in every width and form.
  • Typed offsets: four ways of adding offsets, through RGBA32F and RGBA16F views, plus the refusals.
  • Partial stores: x, xy, xyz and d16_xy, with EXEC masking.
  • Loads by index: three formats with 20-byte records, plus a built descriptor whose own stride differs from the entry's.

A new test, typed_format_loads_by_index_from_the_heap_take_the_views_stride, covers the heap path. Each change was broken by hand to confirm the tests fail: AND-then-OR instead of compare-exchange, the offset ignored, kept channels zeroed, the index multiply dropped, and typed loads left out of the view-stride table.

Rebased onto current main (940d32f). On this machine, 5 tests fail on main itself, with or without this change: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, the two stride_tests::a_heap_buffer_read_* tests, and synthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with -D warnings, with and without --all-features.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5483515122 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959). Originally posted by [RaghavVijayanand](https://github.com/RaghavVijayanand) on 2026-11-25T01:45:24Z. --- Buffer and LDS gaps in the translator, in four commits. Each builds and passes tests. - **LDS byte and half writes keep one lane's value.** Main (0b35b7f) already reads and writes LDS bytes and halves, but writes them with an atomic AND then OR, noted there as a shortcut. When several lanes write the same byte, that merges their bits. The write is now a compare-exchange loop on the dword, so neighbouring bytes are never clobbered and exactly one lane's value lands, as on the console. Main's read path is kept. - **Typed buffer loads and stores at a byte offset:** the access goes to element `index + offset / element size`. - The element size is taken from the used-resource entry's stride. This is a documented assumption: it is not verified that the console compiler records the format size there. - Still refused: a constant offset inside an element, and any offset when no stride is known. - **Typed stores of fewer than four channels:** dxil.dll requires full masks on typed UAV stores. So the store loads the element, keeps the channels it isn't given, and stores all four, inside the same EXEC guard. - Documented limits: it assumes the console leaves those channels untouched; an snorm -128 round-trips as -127; and the store is not atomic against other lanes writing the same element. - **`tbuffer_load_format_*` by index:** reads at byte `index * stride + offset`, through main's bindless-stride conversions (a root view's built descriptor takes its stride from dword 1, and a heap descriptor from the view-stride table). - **Behaviour change to main's raw path:** the lane-index-added refusal (dword 3 bit 23) now also applies to raw accesses through a root view, which main translated silently and incorrectly. This is easy to revert if you prefer main's behaviour. - Swizzled and add-tid descriptors are still refused. **Tests:** the new `emit/buffer_lds_tests.rs` (8 tests) and a `View::FormatUav` in the test host. Every program is hand-assembled, validated with dxil.dll, run on the default hardware adapter and WARP, and checked against a CPU model. - LDS: 64 threads in two waves write neighbouring and identical bytes, with EXEC-only guards, and read back in every width and form. - Typed offsets: four ways of adding offsets, through RGBA32F and RGBA16F views, plus the refusals. - Partial stores: x, xy, xyz and d16_xy, with EXEC masking. - Loads by index: three formats with 20-byte records, plus a built descriptor whose own stride differs from the entry's. A new test, `typed_format_loads_by_index_from_the_heap_take_the_views_stride`, covers the heap path. Each change was broken by hand to confirm the tests fail: AND-then-OR instead of compare-exchange, the offset ignored, kept channels zeroed, the index multiply dropped, and typed loads left out of the view-stride table. **Rebased onto current main (940d32f).** On this machine, 5 tests fail on main itself, with or without this change: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`, the two `stride_tests::a_heap_buffer_read_*` tests, and `synthetic_tests::gathers_at_a_level_match_the_hardware`. Everything else passes, and clippy passes with `-D warnings`, with and without `--all-features`.
copilot-pull-request-reviewer[bot] commented 2026-11-25 01:45:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T01:45:33Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6050344768 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959#pullrequestreview-6050344768). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T01:45:33Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
upstream-sync changed title from [PR #1959] Shaders: LDS bytes and halves, typed buffers at offsets and of some channels to [PR #1959] Shaders: LDS sub-dword writes, typed buffers at offsets and of some channels, typed loads by index 2026-11-25 03:03:01 +00:00
Marvisak commented 2026-11-25 03:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T02:19:37Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150581723 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959#issuecomment-7150581723). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T02:19:37Z. --- <!-- victory-triage v1 head=40770f9468960ea095f54723bba4978b2d99d38e verdict=needs-rebase at=2026-11-25T16:16:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
catminou4 commented 2026-11-25 03:14:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:14:11Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. LDS bytes and halves, typed buffers at offsets and of some channels — sub-dword LDS/buffer access completeness; relates to the LDS sub-dword cluster (#632/#116/#101/#571/#996) and #2003's MUBUF d16.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051314474 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959#pullrequestreview-6051314474). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:14:11Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. LDS bytes and halves, typed buffers at offsets and of some channels — sub-dword LDS/buffer access completeness; relates to the LDS sub-dword cluster (#632/#116/#101/#571/#996) and #2003's MUBUF d16.
sinan-cmyk commented 2026-11-25 11:05:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:01:53Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 40770f94 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160493960 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959#issuecomment-7160493960). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T11:01:53Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 40770f94 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
RaghavVijayanand commented 2026-11-26 12:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RaghavVijayanand on 2026-11-26T11:25:49Z.


Rebased onto main 63bcca4. Merged with what main gained since:

  • LDS sub-dword writes: the compare-exchange loop now sits inside main's bounds guard from #1949. A write past the allocation is dropped, and of lanes writing the same byte, one value wins.
  • Typed buffer stores: they use main's typed_h handle (made once per store, for the d16 integer-view path) together with this branch's byte-offset element and partial-channel merge.

Each commit builds. Locally (RTX 5060 Laptop): the buffer/LDS/typed tests pass (14 of 15), and clippy is clean. typed_stores_of_some_channels_keep_the_others fails on the RTX with "dispatch failed: The parameter is incorrect". That is the same NVIDIA 1M-view-heap-cap failure that main's own stride_tests::a_heap_buffer_* hit there. On WARP it passes along with those two (VICTORY_WARP=1). Before the rebase it passed on the RTX as well.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7190715915 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959#issuecomment-7190715915). Originally posted by [RaghavVijayanand](https://github.com/RaghavVijayanand) on 2026-11-26T11:25:49Z. --- Rebased onto `main` 63bcca4. Merged with what `main` gained since: - **LDS sub-dword writes:** the compare-exchange loop now sits inside `main`'s bounds guard from #1949. A write past the allocation is dropped, and of lanes writing the same byte, one value wins. - **Typed buffer stores:** they use `main`'s `typed_h` handle (made once per store, for the d16 integer-view path) together with this branch's byte-offset element and partial-channel merge. Each commit builds. Locally (RTX 5060 Laptop): the buffer/LDS/typed tests pass (14 of 15), and clippy is clean. `typed_stores_of_some_channels_keep_the_others` fails on the RTX with "dispatch failed: The parameter is incorrect". That is the same NVIDIA 1M-view-heap-cap failure that `main`'s own `stride_tests::a_heap_buffer_*` hit there. On WARP it passes along with those two (`VICTORY_WARP=1`). Before the rebase it passed on the RTX as well.
ColorMeBoom commented 2026-11-27 03:26:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T03:26:52Z.


RDNA1 run (AMD RX 5700 XT, Navi 10, driver 32.0.21045.29003, Windows 11 26200; from the batch in #3410). Head a5bb542 merged onto main 63bcca4.

typed_stores_of_some_channels_keep_the_others removes the device on the RX 5700 XT. It fails within half a second, every run:

hardware: dispatch failed: device removed: The GPU will not respond to more commands, most likely because of an invalid command passed by the calling application.

The cause looks like the test, not the lowering. The _d16_xy store reads main's view-stride table (t255, space 1, VIEW_STRIDES) to tell an integer view from a float one, and the test runs with no root views (run(&shader, &views, &[], …)). So the shader reads through an unset root SRV at address 0. WARP tolerates that and passes; this card page-faults. That may also be your RTX 5060's "The parameter is incorrect" since the rebase, which is when the d16 integer-view path came in. I haven't checked it on NVIDIA.

How I narrowed it down, one store per run on the hardware adapter:

  • buffer_store_format_x and _xy, at element offsets 0–3: pass.
  • _xyz with all lanes, and under the half-lane EXEC mask: pass.
  • _d16_xy at offsets 0, 1 and 3: device removed, at every offset and in both formats. Its DXIL is the only one with a rawBufferLoad from t255.
  • WARP alone: the original test and both d16 probes pass, with the right values.

Giving the test the table, as stride_tests does, fixes it:

-        for (label, uavs) in run(&shader, &views, &[], &table_at_0) {
+        // The view-stride table the `_d16` store reads: a raw view at heap
+        // index 0, the float typed view at 1.
+        let strides = [Root::View {
+            srv: true,
+            data: vec![4, size],
+        }];
+        for (label, uavs) in run(&shader, &views, &strides, &table_at_0) {

With that, the test passes 5 of 5 on the RX 5700 XT, run alone with a pause between runs. The full victory-shader --lib suite passes: 311 passed, 0 failed, 3 ignored. The host side is fine as it is: draw.rs binds the stride table whenever a shader declares VIEW_STRIDES.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7208995335 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1959#issuecomment-7208995335). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T03:26:52Z. --- **RDNA1 run** (AMD RX 5700 XT, Navi 10, driver 32.0.21045.29003, Windows 11 26200; from the batch in #3410). Head `a5bb542` merged onto main `63bcca4`. `typed_stores_of_some_channels_keep_the_others` removes the device on the RX 5700 XT. It fails within half a second, every run: ``` hardware: dispatch failed: device removed: The GPU will not respond to more commands, most likely because of an invalid command passed by the calling application. ``` The cause looks like the test, not the lowering. The `_d16_xy` store reads main's view-stride table (`t255`, space 1, `VIEW_STRIDES`) to tell an integer view from a float one, and the test runs with no root views (`run(&shader, &views, &[], …)`). So the shader reads through an unset root SRV at address 0. WARP tolerates that and passes; this card page-faults. That may also be your RTX 5060's "The parameter is incorrect" since the rebase, which is when the d16 integer-view path came in. I haven't checked it on NVIDIA. How I narrowed it down, one store per run on the hardware adapter: - `buffer_store_format_x` and `_xy`, at element offsets 0–3: pass. - `_xyz` with all lanes, and under the half-lane EXEC mask: pass. - `_d16_xy` at offsets 0, 1 and 3: device removed, at every offset and in both formats. Its DXIL is the only one with a `rawBufferLoad` from `t255`. - WARP alone: the original test and both d16 probes pass, with the right values. Giving the test the table, as `stride_tests` does, fixes it: ```diff - for (label, uavs) in run(&shader, &views, &[], &table_at_0) { + // The view-stride table the `_d16` store reads: a raw view at heap + // index 0, the float typed view at 1. + let strides = [Root::View { + srv: true, + data: vec![4, size], + }]; + for (label, uavs) in run(&shader, &views, &strides, &table_at_0) { ``` With that, the test passes 5 of 5 on the RX 5700 XT, run alone with a pause between runs. The full `victory-shader --lib` suite passes: 311 passed, 0 failed, 3 ignored. The host side is fine as it is: `draw.rs` binds the stride table whenever a shader declares `VIEW_STRIDES`. AI use: Claude Code (Claude Opus 5.5).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1959:upstream-pr/1959'
git switch 'upstream-pr/1959'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1959'
git switch 'upstream-pr/1959'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1959'
git switch 'upstream-pr/1959'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1959'
git switch 'main'
git merge --squash 'upstream-pr/1959'
git switch 'main'
git merge --ff-only 'upstream-pr/1959'
git switch 'main'
git merge 'upstream-pr/1959'
git push origin 'main'
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
Marvisak/VIctory!1957
No description provided.