Skip to content

Shaders: buffer byte and half stores of a VGPR's high half (_d16_hi) - #2333

Open
TinkerBell-90 wants to merge 1 commit into
Marvisak:mainfrom
TinkerBell-90:shaders-buffer-store-d16-hi
Open

TinkerBell-90 wants to merge 1 commit into
Marvisak:mainfrom
TinkerBell-90:shaders-buffer-store-d16-hi

Conversation

@TinkerBell-90

Copy link
Copy Markdown

buffer_store_byte_d16_hi and buffer_store_short_d16_hi were refused by name, so a program using one did not translate. They now store bits 16-23 or 16-31 of their VGPR, through the same two atomics on the dword as buffer_store_byte and buffer_store_short (and the same limits: no store by index, the field does not cross a dword).

Claimed in #1633: #1633 (comment)

Test: stride_tests::high_half_buffer_stores_take_the_vgprs_high_half. 32 lanes store a half and a byte from the high half of a VGPR whose low half is junk, two or four lanes per dword.

Run here: Linux, tests built for x86_64-pc-windows-gnu and run under Wine + vkd3d-proton on an RTX 3070. There is no WARP in this setup, so both loops of the test run on the card.

  • The new test passes. It fails without the change (Unsupported { what: "buffer_store_short_d16_hi" }) and when the field is taken from bit 0 (the junk lands).
  • victory-shader on GPU: 243 passed, 5 failed, 3 ignored. Main 940d32f on the same host: 242 passed and the same 5 failures (the three hardware conversion and fusing checks, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, stub_pipeline_is_created).
  • cargo test -p victory-shader --lib on Linux: 144 passed. Clippy for windows-msvc with -D warnings: clean. rustfmt: no new differences. cargo xtask policy: ok.

Not tested with the game. #2003 adds the _d16 loads and #2208 changes how the plain byte and half stores write; this touches the same lines of buffer() but not the same cases.

AI-assisted.

buffer_store_byte_d16_hi and buffer_store_short_d16_hi were refused by
name, so a program using one did not translate. They store bits 16-23 or
16-31 of their VGPR through the same two atomics on the dword as
buffer_store_byte and buffer_store_short.

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

Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware tests not run here). Approving — buffer byte/half stores of a VGPR's high half (_d).

@steven-seagull27

Copy link
Copy Markdown

Confirmed on native Windows D3D12 at 6d0f5f9 with an RTX 5080 and built-in Microsoft WARP, in separate processes. Both adapters passed the PR's packed test: all 32 halfwords and 32 bytes matched, and all eight trailing dwords stayed zero.

I also split the two instructions and prefilled the UAV with 0xab897654 to check the neighboring fields. On each adapter, the high-half byte store matched 128/128 dwords across byte positions 0–3, and the high-half short store matched 64/64 dwords across byte positions 0 and 2. For example, lane 5 stored 0x45 at byte position 1 and read back 0xab894554, preserving all three neighboring bytes.

On the exact parent 940d32f, the isolated cases each stopped during lowering with the corresponding unsupported opcode, before dispatch. The ordinary byte and short store controls returned 64/64 correct dwords per adapter on both revisions. These were synthetic 32-thread compute dispatches. Both device identities were checked, including the loaded system WARP DLL.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Clean handling of _d16_hi byte/half buffer stores reading the VGPR's high 16 bits.
  • cargo test -p victory-shader half_buffer_stores: 2/2 passed on RTX 5090, 2/2 passed on WARP (including high_half_buffer_stores_take_the_vgprs_high_half).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (worth a look). This adds buffer_store_byte_d16_hi and buffer_store_short_d16_hi to Lower::buffer in lower.rs, through the existing byte/half store path (two atomics on the dword) with the data shifted right by 16 first. That matches the RDNA2 ISA, where these opcodes store bits 23:16 and 31:16 of the VGPR. I decoded the test's MUBUF words by hand (opcodes 0x1B and 0x19, matching gfx10/opcodes.rs; vaddr, vdata, srsrc and offset fields right) and the expected buffer contents match. Another contributor reports the test passing on native RTX and on WARP with neighbouring bytes preserved. It touches the same lines as #2003 and #2208, but not the same cases. CI: passing.


Generated by Claude Code

@fuzeofficlal fuzeofficlal 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 and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll, VICTORY_D3D12_DEBUG=1) — clean and ready to merge:

  • Shifting VGPR source right by 16 (Bin::LShr) before the existing byte/short store path for buffer_store_byte_d16_hi (0x019) and buffer_store_short_d16_hi (0x01b) mirrors ds_write_b{8,16}_d16_hi and keeps emit/lower.rs at 520,901 B (3,387 B under the 512 KiB cap).

Local verification:

  • emit::stride_tests::high_half_buffer_stores_take_the_vgprs_high_half: passed on both RTX 5090 and WARP (dxil.dll + DEBUG=1)
  • emit::tests 17/17, emit::semantics_tests 34/34
  • cargo clippy --all-targets -p victory-shader -- -D warnings + cargo xtask policy (191 files ok): 0 warnings

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants