Shaders: global byte and half stores keep the rest of their dword #1862

Open
TinkerBell-90 wants to merge 1 commit from upstream-pr/1864 into main
TinkerBell-90 commented 2026-11-24 23:46:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TinkerBell-90 on 2026-11-24T23:46:17Z.


What

global_store_byte, global_store_short, global_store_byte_d16_hi and global_store_short_d16_hi are translated, both into title memory (addresses the program computes) and through a root view. Main refused them by name in flat_write, so any program with one did not translate.

How

The same method buffer_store_byte and buffer_store_short already use: two atomics on the dword holding the field, an and that clears it and an or that sets it, so lanes storing neighbouring bytes of one dword keep each other's values. The _d16_hi forms take the field from bit 16 of the VGPR. Title memory pages are marked written for the bytes actually stored.

Tests

Two GPU tests in memory_tests.rs: 32 lanes store bytes, halves and both _d16_hi forms into shared dwords of a buffer filled with 0xAA, through title memory (pointer in root constants, page table, written-page check) and through a root UAV in a program without title memory.

Run here on Linux with Wine 10, vkd3d-proton 3.1 and DXVK 3.1.1's dxgi, on an RTX 3070 (driver 595.99), tests built for x86_64-pc-windows-gnu. There is no WARP in that setup (DXVK returns the hardware adapter for EnumWarpAdapter), so both loops ran on the RTX 3070; CI's WARP is untested by me.

  • New tests pass. Negative controls: without the lower.rs change both fail (Unsupported { what: "global_store_byte" }); with a plain dword store instead of the two atomics both fail with the neighbours' bytes lost; with the _d16_hi forms read from bit 0 both fail.
  • Whole victory-shader suite: 206 passed, 5 failed, 2 ignored. The same 5 fail on main 70564ae in this setup (204 passed): conversions_match_the_hardware, rounding_matches_the_hardware, hosts_that_do_not_fuse_are_named, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, stub_pipeline_is_created.
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings clean, cargo test -p victory-shader --lib on Linux 118 passed, rustfmt adds no new differences to the two files, cargo xtask policy ok.

Limits

  • As for the sub-dword loads and buffer stores, a field is taken not to cross a dword (a half at byte 3 of a dword).
  • Between the two atomics another lane can briefly read the field as zero; a byte store on the console is a single write.
  • Not checked against the title (no game files used). Claimed in #1633.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5482296901 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864). Originally posted by [TinkerBell-90](https://github.com/TinkerBell-90) on 2026-11-24T23:46:17Z. --- ## What `global_store_byte`, `global_store_short`, `global_store_byte_d16_hi` and `global_store_short_d16_hi` are translated, both into title memory (addresses the program computes) and through a root view. Main refused them by name in `flat_write`, so any program with one did not translate. ## How The same method `buffer_store_byte` and `buffer_store_short` already use: two atomics on the dword holding the field, an `and` that clears it and an `or` that sets it, so lanes storing neighbouring bytes of one dword keep each other's values. The `_d16_hi` forms take the field from bit 16 of the VGPR. Title memory pages are marked written for the bytes actually stored. ## Tests Two GPU tests in `memory_tests.rs`: 32 lanes store bytes, halves and both `_d16_hi` forms into shared dwords of a buffer filled with `0xAA`, through title memory (pointer in root constants, page table, written-page check) and through a root UAV in a program without title memory. Run here on Linux with Wine 10, vkd3d-proton 3.1 and DXVK 3.1.1's dxgi, on an RTX 3070 (driver 595.99), tests built for `x86_64-pc-windows-gnu`. There is no WARP in that setup (DXVK returns the hardware adapter for `EnumWarpAdapter`), so both loops ran on the RTX 3070; CI's WARP is untested by me. - New tests pass. Negative controls: without the `lower.rs` change both fail (`Unsupported { what: "global_store_byte" }`); with a plain dword store instead of the two atomics both fail with the neighbours' bytes lost; with the `_d16_hi` forms read from bit 0 both fail. - Whole `victory-shader` suite: 206 passed, 5 failed, 2 ignored. The same 5 fail on main `70564ae` in this setup (204 passed): `conversions_match_the_hardware`, `rounding_matches_the_hardware`, `hosts_that_do_not_fuse_are_named`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `stub_pipeline_is_created`. - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings` clean, `cargo test -p victory-shader --lib` on Linux 118 passed, rustfmt adds no new differences to the two files, `cargo xtask policy` ok. ## Limits - As for the sub-dword loads and buffer stores, a field is taken not to cross a dword (a half at byte 3 of a dword). - Between the two atomics another lane can briefly read the field as zero; a byte store on the console is a single write. - Not checked against the title (no game files used). Claimed in #1633. AI-assisted.
catminou4 commented 2026-11-24 23:52:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:52:21Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows.

Global byte/half stores keep the rest of their dword: partial-store masking fix for global stores.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049334227 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864#pullrequestreview-6049334227). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T23:52:21Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows. Global byte/half stores keep the rest of their dword: partial-store masking fix for global stores.
kais7654 commented 2026-11-25 00:06:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kais7654 on 2026-11-24T23:53:00Z.


Read the diff and ran it locally (RTX 5070 Laptop, Windows 11):

  • The byte/half path matches how buffer_store_byte and kin already emit the two atomics — same operation codes, the _d16_hi forms take the field from bit 16 of the VGPR as expected, and the title-memory lookup marks the pages the stored bytes belong to.
  • Both new tests pass here: title_memory_byte_and_half_stores_keep_their_neighbours and root_uav_byte_and_half_stores_keep_their_neighbours.
  • cargo clippy -p victory-shader --all-targets -- -D warnings is clean.

One question: flat_atomic still refuses byte and half atomics by name, right? Fine to leave for later — the stores are what the title hits first — just so the follow-up is on record.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7147899594 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864#issuecomment-7147899594). Originally posted by [kais7654](https://github.com/kais7654) on 2026-11-24T23:53:00Z. --- Read the diff and ran it locally (RTX 5070 Laptop, Windows 11): - The byte/half path matches how `buffer_store_byte` and kin already emit the two atomics — same operation codes, the `_d16_hi` forms take the field from bit 16 of the VGPR as expected, and the title-memory lookup marks the pages the stored bytes belong to. - Both new tests pass here: `title_memory_byte_and_half_stores_keep_their_neighbours` and `root_uav_byte_and_half_stores_keep_their_neighbours`. - `cargo clippy -p victory-shader --all-targets -- -D warnings` is clean. One question: `flat_atomic` still refuses byte and half atomics by name, right? Fine to leave for later — the stores are what the title hits first — just so the follow-up is on record.
Marvisak commented 2026-11-25 03:03:22 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

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


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150538849 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864#issuecomment-7150538849). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T02:17:25Z. --- <!-- victory-triage v1 head=583d315ef6cacde6b2b3fe97ce7af236b7668951 verdict=needs-rebase at=2026-11-25T16:06:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/memory_tests.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
TinkerBell-90 commented 2026-11-25 11:05:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TinkerBell-90 on 2026-11-25T10:39:13Z.


Rebased onto main 940d32f. The conflict in memory_tests.rs was both sides adding tests at the end of the file; all are kept.

One change beyond the conflict: since cd94d35 writes through views mark their pages, so the byte and half path now calls mark_view_write on the dword it writes. The root UAV test runs with view_marks on and checks the two pages its stores touch; the title memory test checks that it adds no view marks. Without the new call, or with it pointed at byte 0, the root UAV test fails.

Retested on Linux under Wine + vkd3d-proton (RTX 3070): victory-shader 244 passed and 5 failed, the same 5 that fail on main 940d32f on this host (242 passed). Clippy for windows-msvc with -D warnings is clean.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159990435 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864#issuecomment-7159990435). Originally posted by [TinkerBell-90](https://github.com/TinkerBell-90) on 2026-11-25T10:39:13Z. --- Rebased onto main `940d32f`. The conflict in `memory_tests.rs` was both sides adding tests at the end of the file; all are kept. One change beyond the conflict: since `cd94d35` writes through views mark their pages, so the byte and half path now calls `mark_view_write` on the dword it writes. The root UAV test runs with `view_marks` on and checks the two pages its stores touch; the title memory test checks that it adds no view marks. Without the new call, or with it pointed at byte 0, the root UAV test fails. Retested on Linux under Wine + vkd3d-proton (RTX 3070): victory-shader 244 passed and 5 failed, the same 5 that fail on main `940d32f` on this host (242 passed). Clippy for windows-msvc with `-D warnings` is clean. AI-assisted.
TinkerBell-90 commented 2026-11-26 20:34:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TinkerBell-90 on 2026-11-26T20:34:10Z.


Rebased onto main 63bcca4. The code is unchanged (git range-diff); only the place of the two tests in memory_tests.rs moved. Of the commits since 940d32f, the one that reaches this path is e815cef (#2484): it changed how Lower::memory marks the last byte of a write. The byte and half stores call it with 1 or 2 bytes inside one dword, so they get the new marking with no second lookup, and #2484's straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages passes on this branch. mark_view_write has not changed.

Tested on a GPU this time: an RX 9070 XT under Linux (Wine 10, vkd3d-proton 3.1 with DXVK's dxgi, Mesa 26.0.8 RADV). Not Windows, nothing run in game.

  • emit::memory_tests: 7 passed, the two new tests included.
  • Negative control, lower.rs from main with these tests: both panic at translation with Unsupported { offset: 48, what: "global_store_byte" }.
  • Whole victory-shader suite: 301 passed, 3 failed, 3 ignored, against 299, 3, 3 for main at the same commit. The 3 failures are the same tests on both (stub_pipeline_is_created, hosts_that_do_not_fuse_are_named, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros) and come from this host, not from the change.
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202837253 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864#issuecomment-7202837253). Originally posted by [TinkerBell-90](https://github.com/TinkerBell-90) on 2026-11-26T20:34:10Z. --- Rebased onto main `63bcca4`. The code is unchanged (`git range-diff`); only the place of the two tests in `memory_tests.rs` moved. Of the commits since `940d32f`, the one that reaches this path is `e815cef` (#2484): it changed how `Lower::memory` marks the last byte of a write. The byte and half stores call it with 1 or 2 bytes inside one dword, so they get the new marking with no second lookup, and #2484's `straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages` passes on this branch. `mark_view_write` has not changed. Tested on a GPU this time: an RX 9070 XT under Linux (Wine 10, vkd3d-proton 3.1 with DXVK's dxgi, Mesa 26.0.8 RADV). Not Windows, nothing run in game. - `emit::memory_tests`: 7 passed, the two new tests included. - Negative control, `lower.rs` from main with these tests: both panic at translation with `Unsupported { offset: 48, what: "global_store_byte" }`. - Whole `victory-shader` suite: 301 passed, 3 failed, 3 ignored, against 299, 3, 3 for main at the same commit. The 3 failures are the same tests on both (`stub_pipeline_is_created`, `hosts_that_do_not_fuse_are_named`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`) and come from this host, not from the change. - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. AI-assisted.
fuzeofficlal commented 2026-11-26 22:20:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:20:26Z.

Review: CHANGES_REQUESTED


Clean merge onto 63bcca43 (lower.rs is 522,500 bytes), cargo xtask policy passed (191 files ok), clippy passed (default and --all-features), PR hunks pass rustfmt --edition 2024 --check, and emit::memory_tests:: emit::lower:: passes (39/39 on VICTORY_WARP=0 skipping the pre-existing heap_direct_texture_reads_mark_their_heap_index, and 40/40 on VICTORY_WARP=1).

However, one correctness bug and test gaps need attention before landing:

  1. global_store_short / global_store_short_d16_hi silently drop the second byte at dword offset 3 (crates/victory-shader/src/emit/lower.rs:1019-1048): Unlike a split store or an odd-offset guard, when off & 3 == 3, sh = 24 shifts mask (0xFFFF << 24 = 0xFF00_0000) and x into byte 3 of the first dword and silently discards the upper byte without touching the next dword. On the title-memory path, self.memory(lo, hi, 2, true, None) still receives bytes = 2, so a short at byte 0xFFFF of a 64 KiB page can mark the following page dirty even though its byte was dropped. Please either split unaligned dword-crossing shorts across both dwords or explicitly guard/reject unaligned offsets where unsupported.
  2. Test coverage & concurrency note (crates/victory-shader/src/emit/memory_tests.rs:939-1187): In byte_and_half_stores, all 32 lanes collectively overwrite every byte of every touched dword (bytes[0..32], 0x100..0x140, etc.), so the test does not verify that untouched 0xAA neighbor bytes within a partially written dword actually survive (nor does it test odd-offset shorts or masked/inactive EXEC lanes). Also note that the separate AND-then-OR atomicBinOp.i32 pair preserves disjoint fields across lanes, though overlapping writes to the same byte can interleave.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081076141 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1864#pullrequestreview-6081076141). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:20:26Z. **Review:** CHANGES_REQUESTED --- Clean merge onto `63bcca43` (`lower.rs` is `522,500` bytes), `cargo xtask policy` passed (`191 files ok`), `clippy` passed (default and `--all-features`), PR hunks pass `rustfmt --edition 2024 --check`, and `emit::memory_tests:: emit::lower::` passes (**39/39** on `VICTORY_WARP=0` skipping the pre-existing `heap_direct_texture_reads_mark_their_heap_index`, and **40/40** on `VICTORY_WARP=1`). However, one correctness bug and test gaps need attention before landing: 1. **`global_store_short` / `global_store_short_d16_hi` silently drop the second byte at dword offset 3 (`crates/victory-shader/src/emit/lower.rs:1019-1048`)**: Unlike a split store or an odd-offset guard, when `off & 3 == 3`, `sh = 24` shifts `mask` (`0xFFFF << 24 = 0xFF00_0000`) and `x` into byte 3 of the first dword and silently discards the upper byte without touching the next dword. On the title-memory path, `self.memory(lo, hi, 2, true, None)` still receives `bytes = 2`, so a short at byte `0xFFFF` of a 64 KiB page can mark the following page dirty even though its byte was dropped. Please either split unaligned dword-crossing shorts across both dwords or explicitly guard/reject unaligned offsets where unsupported. 2. **Test coverage & concurrency note (`crates/victory-shader/src/emit/memory_tests.rs:939-1187`)**: In `byte_and_half_stores`, all 32 lanes collectively overwrite every byte of every touched dword (`bytes[0..32]`, `0x100..0x140`, etc.), so the test does not verify that untouched `0xAA` neighbor bytes within a partially written dword actually survive (nor does it test odd-offset shorts or masked/inactive `EXEC` lanes). Also note that the separate `AND`-then-`OR` `atomicBinOp.i32` pair preserves disjoint fields across lanes, though overlapping writes to the same byte can interleave.
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/1864:upstream-pr/1864'
git switch 'upstream-pr/1864'

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/1864'
git switch 'upstream-pr/1864'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1864'
git switch 'upstream-pr/1864'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1864'
git switch 'main'
git merge --squash 'upstream-pr/1864'
git switch 'main'
git merge --ff-only 'upstream-pr/1864'
git switch 'main'
git merge 'upstream-pr/1864'
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!1862
No description provided.