Shaders: lower tbuffer_store_format_* that need no conversion #707
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!707
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-707"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@mercuryVM on GitHub · 2026-11-24 07:09 UTC · original
mercuryVM:impl/tbuffer-store→main· +261 −5 · 2 files · 4 commits · openWhat
tbuffer_store_format_{x,xy,xyz,xyzw}and their_d16_forms are MTBUF typed stores whose format is in the instruction, the store side of the typed loads the title's vertex fetch uses. The translator refused them by name. They now lower as raw stores (rawBufferStore) of the element's dwords, when no conversion is involved:32up to32_32_32_32, formats 20-22, 62-64, 72-77): the data's bits are stored._d16_forms of the 16-bit float formats (16_16,16_16_16_16, formats 29 and 71): the halves in the data registers are stored as they are.tbuffer_load_format_*. A store by index is refused, as the loads refuse a load by index.Everything else stays refused, each with its own reason:
a typed-format store of a converted or narrow format: norm, scaled and narrow integer formats need conversions whose rounding and clamping I have not checked against hardware. This also covers f32 data stored into a half format: DXIL'slegacyF32ToF16rounds toward zero on the host (see below), while the console rounds to nearest even. #422 fixes that narrowing, and these formats can follow it.a typed-format store of an element under a dword: formats like8,16and8_8would need a read-modify-write that neighbouring lanes could race on.a typed-format store of some of its format's channels: what the hardware writes in the missing channels is unverified.One helper,
Lower::format_store_words, incrates/victory-shader/src/emit/lower.rs, plus a branch inLower::buffer.A measurement on the side (relevant to #422)
While testing the half formats I probed
legacyF32ToF16on the RTX 5070 (driver of the day) and on WARP. Both truncate toward zero and clamp overflow to 65504:1 + 1.5·2⁻¹⁰(a tie) gives0x3c01, where nearest-even gives0x3c02.1 + 1.75·2⁻¹⁰(above the half) gives0x3c01, where nearest-even gives0x3c02.0x7bff, where nearest-even gives infinity.That supports #422's change. I did not touch the existing lowerings that use the op here.
Overlap
I searched open and closed PRs: #342 handles partial-channel
buffer_store_format_*(MUBUF, format from the descriptor), and #422 handles f32→f16 narrowing. No PR handlestbuffer_store_format_*; #163 lists them as refused. This PR touches only the format branch ofLower::buffer.Tested
Windows 11, NVIDIA RTX 5070, AMD CPU. No game data.
tbuffer_store_format_writes_the_formats_layout: hand-assembled compute programs run on the hardware device and on WARP and are validated withdxil.dll. Each one stores at byte offset 16 of a raw UAV, and the test reads back dwords 4-7. Cases:32_32_32_32float (a NaN payload and a denormal kept bit for bit) and sint,32_32_32float (the fourth dword untouched),32_32uint,32float, and the d1616_16/16_16_16_16float forms.tbuffer_store_format_refuses_what_it_does_not_convert:8_8_8_8unorm,16_16uint,16float,32_32_32_32with two channels, a d16 store into a 32-bit format, and f32 data into both half formats. Each is refused with the expected reason.cargo test --workspace: all passed (victory-shader 71 passed).rustfmt --edition 2024 --checkon both changed files: clean.cargo clippy -p victory-shader --all-targets: no warnings.cargo xtask policy: 151 files ok.Effect on the title: none
Measured by @Parakeet-Wheat on the retail 1.0.2.1 shaders, in a comment below. The title uses no
tbuffer_store_format_*(against 52,927tbuffer_load_format_*), andvictory translate --list --validategives the same outcome onmainand on this PR: 21,736 validated, 4,003 failed, 162 rejected. So this PR only completes the instruction set for the store side. It doesn't unblock anything in the game, and it can wait behind work that does.Not tested
buffer_formattable, which the typed loads already use.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@aziaconsal2026 on GitHub · 2026-11-24 07:41 UTC · original
Tested PR head
837bb405on Windows 11 with Radeon 780M and WARP (Rust 1.98.1 MSVC). The original layout test uses an immediate offset of 16 bytes. This test also supplies independent vector and scalar byte offsets and checks the neighboring sentinel words.All five combinations passed on both backends. As a negative control, ignoring the vector offset made the hardware case with vector=4 and scalar=0 write at byte 16 instead of byte 20. After restoring the PR code, all 72 tests passed with
cargo test --locked -p victory-shader --features host -- --test-threads=1.Additional regression test against
837bb405AI-assisted contribution using a synthetic shader.
@mercuryVM on GitHub · 2026-11-24 08:48 UTC · original
Merged current
main(58fed37) in05adffb, no rebase so the reviewed commits stay. @catminou4 thanks, thevalu_tests.rsconflict is resolved. #433's one-at-a-time lock now sits at module scope, so the newrun_dwordshelper takes it too.@aziaconsal2026 thank you for the offset test. It's in the same commit, credited in its doc comment: vector and scalar offsets add to the immediate one, and the neighbouring dwords stay untouched. It passes on the RTX 5070 and WARP, and
victory-shaderpasses in full (93 passed).Note for testing:
cargo test -p victory-shaderdoes not compile on currentmain(#719, a call tolowerswithout its newrsrc2argument; @LAKSHYA-cmd-tech has a fix branch). I ran the suite with that one-line fix applied locally, not committed here.AI-assisted (Claude Code).
@mercuryVM on GitHub · 2026-11-24 09:26 UTC · original
@catminou4 thank you for the re-check. I merged
mainagain (8e79c80, with the new CI) in5e2f089, so CI can run on this PR. Locally on that head, with the CI's own commands:cargo clippy --workspace --all-targets --locked -- -D warningsand the--all-featuresvariant are clean,cargo test --workspace --lockedpasses, andvictory-shaderhas 92 passed on the RTX 5070 and WARP.AI-assisted (Claude Code).
@dcastell1 on GitHub · 2026-11-24 09:58 UTC · original
Verified on native Windows, no Wine: NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build.
main@8e79c80baseline on this box: 311 passed, 0 failed, 6 ignored.With this PR at
5e2f089aapplied clean (patch -p1, no fuzz):Three more passing tests than the baseline, so the lowered
tbuffer_store_format_*forms and their fixtures run green here.Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran
cargo test --workspace, reverted it.@mercuryVM on GitHub · 2026-11-24 10:20 UTC · original
Merged current
main(ffe310e) in7ca777e. The conflict was the GPU test lock, whichmainmoved to module scope (pub(super)) the same way this branch had, so I tookmain's version;run_dwordstakes it as well. The CI's commands pass locally: both clippy runs,cargo test --workspace --locked, andvictory-shader123 passed. @dcastell1 thank you for the RTX 5090 run.AI-assisted (Claude Code).
@dcastell1 on GitHub · 2026-11-24 10:34 UTC · original
Re-verified on the new head
7ca777e5and its base (main@ffe310e), same box:Clean
main@ffe310ebaseline here is 342, so the three new tests still run green on this base. Supersedes my earlier note on5e2f089a(which was measured on8e79c80).Environment: Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.98.1, MSVC 14.44.35207, debug. AI-assisted (opencode).
@Parakeet-Wheat on GitHub · 2026-11-24 10:39 UTC · original
Retail shader check for
7ca777e, for the shader-package question in Not tested:610.88), Ryzen 5 5600X, Rust 1.98.1 (x86_64-pc-windows-msvc),dxil.dll1.8.2502, title 1.0.2.1.victory translate <exe> shaders.rpf --list --validate,mainffe310evs this PR: no program changes outcome (21,736 validated, 4,003 failed, 162 rejected on both).victory shader-info --disasmfinds notbuffer_store_format_*in the title (against 52,927tbuffer_load_format_*), so this PR can't affect it either way.cargo test -p victory-shader --locked: 123 passed, 0 failed, 1 ignored; thetbuffer_store_*tests ran on both hardware and WARP.Offline translation and validation only; no shader contents or extracted data included. AI-assisted (Claude Code); run on my machine.
@mercuryVM on GitHub · 2026-11-24 11:06 UTC · original
@Parakeet-Wheat thank you, that answers the open question. No
tbuffer_store_format_*in the title means this PR changes nothing for the game, and I've put that at the top of the description. It's only instruction-set completeness now, so it can wait behind PRs that unblock title shaders. @dcastell1 thanks for re-running on the new head.AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 00:28 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/valu_tests.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.