Repository navigation
Conversation
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Independent local verification of PR #3333 (
AI-assisted (Hy4 flash). GPU/driver: N/A for this CPU test. No game data used. |
Dukestar69
left a comment
There was a problem hiding this comment.
LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).
- Joining byte 3 of
atwith byte 0 ofat + 4for straddling 16-bit raw buffer loads (while reusingatwhen non-straddling to avoid reading past the buffer end) cleanly fixes unaligned 16-bit loads without introducing out-of-bounds reads. cargo test -p victory-shader --lib emit::memory_tests:: -- --skip heap_direct_texture_reads_mark_their_heap_index --test-threads=1: 5 passed, 0 failed on RTX 5090 and 5 passed, 0 failed onVICTORY_WARP=1(includingbuffer_load_ushort_joins_bytes_across_dwords).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Looks good to me — joining byte 3 of the aligned dword (>> 24) with byte 0 of at + 4 (<< 8) for straddling 16-bit raw buffer loads while re-reading at when non-straddling cleanly fixes buffer_load_ushort/sshort across dword boundaries without reading extra memory on non-straddling lanes.
Verified locally on Windows 11 with head 80e8cede cleanly merged onto main (63bcca43):
- Byte-size & audit:
crates/victory-shader/src/emit/lower.rsis520,936bytes (3,352bytes below524,288); bit extraction (shl (32 - width)+lshr/ashr) and sign/zero extension inlower.rs:9758-9775match in-bounds semantics for bothushortandsshort. cargo run -p xtask -- policy(191 files ok) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(both default and--all-features) pass.cargo test --locked -p victory-shader --lib emit::memory_tests(withWindows Kits\10\bin\10.0.26100.0\x64\dxil.dllpresent):VICTORY_WARP=0(--skip heap_direct_texture_reads_mark_their_heap_index):5 passed; 0 failed(1.70s, includingbuffer_load_ushort_joins_bytes_across_dwords).VICTORY_WARP=1(fullemit::memory_tests):6 passed; 0 failed(0.32s).
cargo test --locked -p victory-shader --lib emit::lower:33 passed; 0 failed(0.02s).
Minor non-blocking notes:
rustfmt --edition 2024 --checkflags one long line on the validation call atcrates/victory-shader/src/emit/memory_tests.rs:1049; the added lines inlower.rsare clean.- Consistent with your "Not checked" list, for title-memory (
root_address) reads straddling a 64 KiB page boundary or0xFFFF_FFFC, the secondraw_dwordreuses the first view handlehrather than re-resolvingat + 4, and for bounded raw buffers at the exact last byte (size - 1), per-dwordraw_dwordzeroing can return0x00ABrather than0.
What
buffer_load_ushortandbuffer_load_sshortthrough a raw view (no format, no index) read one aligned dword and took the half from it. At a byte offset of 3 mod 4 the half's second byte is in the next dword, so only the low byte came back: bits 15:8 were always 0. Such a load now also reads the next dword and takes its byte 0 as the high byte.At the other three offsets the result is what it was. The second read then repeats the first dword, so no load reads memory it did not read before. Byte loads are unchanged; they cannot straddle.
The code had this marked as
shortcut: the field is taken not to cross a dword. This removes that one shortcut and no other.The open question, and what I can add to it
The triage notes on #1536, #1669 and #1795 leave the same point open: the ISA guide (§8.1.7) puts the alignment of non-formatted ops under
SH_MEM_CONFIG.alignment_mode, and nothing says which mode the console's driver sets. I cannot settle that. Two things that bear on it:d333572reportsbuffer_load_ushortand_sshorton gfx1036 under AMD's Windows driver 32.0.21043.5001: 512 rows withsoffset, an immediate offset and a short range, wave32 and wave64, and both bytes come back wheneveroffset + 2 <= NUM_RECORDS. That is a PC card, not a console, and I take only the stated result from it.mainalready reads unaligned. A half at byte 1 returns bytes 1 and 2;DWORDmode ("automatic alignment to multiple of the smaller of element size or a dword") would give bytes 0 and 1. At byte 3mainreturns byte 3 and a zero, which is neither mode's answer:UNALIGNEDgives bytes 3 and 4,DWORDbytes 2 and 3. So this change does not introduce the assumption. It makes byte 3 follow the one byte 1 already follows.If the console turns out to align down, bytes 1 and 3 both need a different change (clear bit 0 of the address) and this one should be dropped.
How
The first read now goes through the existing
raw_dword, the same call it used to spell out. For a 16-bit field the next dword's address is selected when the byte offset is 3 (otherwise the same address again), read withraw_dword, shifted left by 8 and OR-ed in when the byte offset is 3.lower.rsgrows by 373 bytes (520,563 to 520,936).Evidence
The new test
buffer_load_ushort_joins_bytes_across_dwords: 32 lanes read a half at byte4 * lane + 3of a raw view whose byteiholdsi, and expect(4 * lane + 3) | (4 * lane + 4) << 8.repository_passes_policy ... ok.3, 7, 11, ...instead of1027, 2055, 3083, .... With it the test passes on both and on WARP.victory-shaderon the RTX 2060: 300 passed, 3 failed with the change. The three are the ones that fail there on unmodified63bcca4(299 and 3).Other pull requests
extract_sub. Whichever goes in second needs a small rebase; I will do mine._d16and_d16_hiloads #2003 (_d16loads) do not merge intomainat the moment, so I could not try them together. Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA) #2037 and Shaders: use atomicCompareExchange CAS loop for buffer_store_byte and buffer_store_short #2208 merge cleanly with this.global_load_ushort/_sshort(Shaders: assemble dword-straddling global_load_ushort and global_load_sshort #1536, closed by its author), byte and half stores (Shaders: use atomicCompareExchange CAS loop for buffer_store_byte and buffer_store_short #2208, Shaders: global byte and half stores keep the rest of their dword #1864).Not checked
+ 4in the same view, as multi-dword loads do; Shaders: assemble dword-straddling global_load_ushort and global_load_sshort #1536 did a second page lookup for the flat path.buffer_load_sshortand wave64 have no case in the test. The signed form differs only in the final shift, which this does not touch.Synthetic tests only; no game files.
— Devin & Fable