Repository navigation
Conversation
Typed-format stores whose format is in the instruction (MTBUF) were refused by name. They now lower as raw stores of the element's dwords when no conversion is involved: formats of 32-bit channels (uint, sint, float; 32 to 32_32_32_32) store the data's bits, and the _d16_ forms of the 16-bit float formats (16_16, 16_16_16_16) store their halves as they are. The instruction must supply every channel of the format, as the typed loads' layout gives it. Everything else stays refused with a reason: norm, scaled and narrow integer formats (conversions), elements under a dword (a read-modify-write lanes would race on), and f32 data for half formats, because DXIL's f32-to-f16 op rounds toward zero (measured below) where the console rounds to nearest even; Marvisak#422 addresses that. GPU tests store each lowered layout on the host GPU and WARP and read the dwords back; another test checks the refusals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Tested on Windows 11 MSVC (rustc 1.98.1):
- cargo test -p victory-shader: 71 passed, 0 failed (including both new buffer_store_format_writes_the_formats_layout and buffer_store_format_refuses_what_it_does_not_convert unit tests)
- cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings)
- cargo xtask policy: 151 files ok
Direct bit-for-bit raw store lowering for 32-bit channels and d16 16-bit float formats operates cleanly without unverified rounding or race-prone narrow read-modify-writes.
|
Tested PR head 837bb40 on 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 Additional regression test against 837bb40diff --git a/crates/victory-shader/src/emit/valu_tests.rs b/crates/victory-shader/src/emit/valu_tests.rs
index 4349028..25d8cfc 100644
--- a/crates/victory-shader/src/emit/valu_tests.rs
+++ b/crates/victory-shader/src/emit/valu_tests.rs
@@ -832,3 +832,31 @@ fn tbuffer_store_format_refuses_what_it_does_not_convert() {
}
}
}
+
+#[test]
+fn tbuffer_store_adds_scalar_and_vector_byte_offsets() {
+ // v1 = payload, v2 = vector byte offset, s2 = scalar byte offset,
+ // v4 = sentinel. Fill the window first so stray writes are observable.
+ let mut body = Vec::new();
+ for offset in (16..44).step_by(4) {
+ body.extend(buffer_store_dword(4, 8, offset));
+ }
+ body.push(vop1(0x001, 5, vgpr(2))); // v_mov_b32 v5, v2
+ let [opcode, operands] = mtbuf_store(4, 20, 1); // 32_UINT, immediate byte offset 16
+ body.extend([opcode | (1 << 12), (operands & 0x00ff_ffff) | (2 << 24)]); // offen, soffset = s2
+ let shader = build_valu_cs(&body);
+
+ let payload = 0x1357_9bdf;
+ let sentinel = 0xa5a5_a5a5;
+ for (vector, scalar) in [(0, 0), (4, 0), (0, 8), (4, 8), (12, 8)] {
+ let mut expected = [sentinel; 7];
+ expected[((vector + scalar) / 4) as usize] = payload;
+ for (backend, words) in run_dwords(&shader, [payload, vector, scalar, sentinel], 11) {
+ assert_eq!(
+ &words[4..],
+ &expected,
+ "{backend}: vector={vector} scalar={scalar}"
+ );
+ }
+ }
+}AI-assisted contribution using a synthetic shader. |
catminou4
left a comment
There was a problem hiding this comment.
Heads-up: this no longer merges cleanly with current main (7374bfb) — textual conflict in crates/victory-shader/src/emit/valu_tests.rs (the shader test file several recently-merged PRs touched). Needs a rebase before merge.
For the record, the PR head itself compiles and passes on macOS 26 arm64, rustc 1.98.1 (cargo test -p victory-shader: 56 passed / 0 failed against its own base).
Resolves the conflict at the end of valu_tests.rs (both sides added tests) and moves Marvisak#433's ONE_AT_A_TIME lock to module scope so run_dwords takes it too. Adds the offset test @aziaconsal2026 posted on the pull request: vector and scalar byte offsets add to the immediate one, and neighbouring dwords stay untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged current @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 Note for testing: AI-assisted (Claude Code). |
catminou4
left a comment
There was a problem hiding this comment.
Re-checked after the rebase: merges cleanly with current main (8e79c80), and cargo test -p victory-shader --locked on macOS arm64 / rustc 1.98.1 → 70 passed / 0 failed (1 ignored, the Windows-only execution suite).
Static pass: format_store_words refuses exactly the cases it documents — partial channel sets, elements under a dword (bits % 32 != 0), conversions/narrowing, and indexed stores — and only lowers the no-conversion forms (32-bit channels as-is, _d16_ float halves packed two-per-dword). The // shortcut: comment matches the repo's convention of stating the current limitation and why.
The three new tests (tbuffer_store_format_writes_the_formats_layout, ..._refuses_what_it_does_not_convert, ..._adds_scalar_and_vector_byte_offsets) live in valu_tests.rs, which is #[cfg(all(test, windows))], so they run in the new Windows CI — I can't execute them on this Mac, but the harness helpers (try_build_valu_cs, mtbuf_store, run_dwords) follow the existing patterns in that file.
|
@catminou4 thank you for the re-check. I merged AI-assisted (Claude Code). |
|
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. Three more passing tests than the baseline, so the lowered 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 |
# Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
|
Merged current AI-assisted (Claude Code). |
|
Re-verified on the new head Clean 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). |
|
Retail shader check for
Offline translation and validation only; no shader contents or extracted data included. AI-assisted (Claude Code); run on my machine. |
|
@Parakeet-Wheat thank you, that answers the open question. No AI-assisted (Claude Code). |
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
What
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. Shaders: narrow f32 to f16 to nearest even, as the console does #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