Repository navigation
Conversation
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).
- Enforcing
NUM_RECORDS * stride.max(1)per dword (both statically for fixed offsets and dynamically viaIUGTonsoffset & !3) ensures scalar code-table buffer loads return 0 past the descriptor's bounds. cargo test -p victory-shader --lib emit::stride_tests::scalar_buffer_loads_of_a_code_table -- --test-threads=1: 2 passed, 0 failed on RTX 5090 and 2 passed, 0 failed onVICTORY_WARP=1.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.
Thanks for adding NUM_RECORDS / stride bounds enforcement for scalar code-table buffer loads. The aligned paths and tests look solid, and emit/lower.rs stays within the size limit (521,520 bytes), but there is one correctness mismatch in the CODE path that needs fixing before merge:
- P1 — Bounds check aligns
immandsoffsetindependently whilecode_dwordloads from the unmasked sum (crates/victory-shader/src/emit/lower.rs:4149-4191):- The
NUM_RECORDSguard computesend = u64::from(imm & !3) + 4andal = so & !3independently (matching RDNA2 hardware), whileaddrpassed toself.code_dword(a)still adds unmaskedimm + base + extra + so. - On current
main(without#1939), an access with aligned base,imm = 2,soffset = 0xe, andNUM_RECORDS = 16(limit = 16) passes the bounds check (0 + 0xc + 4 <= 16) and then loads frombase + 0x10— reading one dword pastNUM_RECORDSinstead of reading0xc(or returning0). - Also, if
built_offset(src)returnsextra: Some(x),extrais added intoaddr(lower.rs:4152-4154) without being included in thelimitcheck. - Building the
CODEbyte address directly from(imm & !3).wrapping_add(base)+al(plus accounting forextraor keeping it guarded) inside theaddress.param == CODEbranch would make the load and the bounds check agree without waiting on#1939.
- The
Local checks on head 9cad6a17 cleanly merged onto main (63bcca43):
cargo run -p xtask -- policy:191 files ok(emit/lower.rs:521,520bytes).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.cargo test --locked -p victory-shader --lib emit::stride_tests:8 passed; 2 failedunderVICTORY_WARP=0(RTX 5090 — both newscalar_buffer_loads_of_a_code_table_*tests pass; only the two pre-existing#1835a_heap_buffer_read_*tests fail) and10 passed; 0 failed(0.08s) underVICTORY_WARP=1.cargo test --locked -p victory-shader --lib emit::lower:33 passed; 0 failed(0.02s).
|
WARP verification of head New tests present at head (in
So both tests catch a real bug on main (assertion Setup (Windows 11, no physical GPU): Suites ( Synthetic tests only; no game files, dumps, shader names or hashes. Test report only, no code changes. Claimed on #1633. AI use: Claude Code (Claude Sonnet 5.5). |
|
Addressed in
Verification on the updated commit (
— Neon |
|
AMD check at
Synthetic shaders only, no game files. AI-assisted. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Thanks for addressing the previous review items in 2060d202 — the NUM_RECORDS guard and code_dword address now align cleanly, clearing the earlier blocking items.
Verified on 2060d202
crates/victory-shader/src/emit/lower.rs:4149-4196: movingaddress.param == CODEahead of the shared path and buildingcode_adirectly from((base + extra) & !3) + (imm & !3) + (soffset & !3)aligns the load and bounds check identically. Confirmedbuilt_offset(base + extra) represents only the descriptor'ss_getpc_b64-relative base, and the updatedstride_tests.rstest covers unalignedsoffset = 0xewithimm = 2(reads0xc = 0xC0DE_0003) andimm = 4(reads0).crates/victory-shader/src/emit/lower.rssize: 522,272 bytes (under the 524,288-byte limit).cargo run --locked -p xtask -- policy:191 files ok.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--all-features): clean.VICTORY_WARP=0(RTX 5090):emit::stride_tests8 passed, 2 failed (only the two pre-existing#1835a_heap_buffer_read_*failures; bothscalar_buffer_loads_of_a_code_table_*tests pass).VICTORY_WARP=1:emit::stride_tests10 passed, 0 failed;emit::lower33 passed, 0 failed.
Minor non-blocking notes
- Note on signed/large edge cases:
fields.rs:255sign-extends the 21-bit SMEM immediate intoi32, whereaslower.rs:4154widens*offset as u32 & !3intou64(so a negative decoded immediate would evaluate pastlimit, matching your "Not checked: Bit-20 signedness" note). Also, if a synthetic descriptor ever hadlimit >= 2^32,code_a'si32addition (4177) would wrap mod2^32. rustfmt --edition 2024reports two minor formatting diffs in thelower.rshunk (4149,4186);stride_tests.rsis formatting-clean on the new code.
What
Scalar
s_buffer_load_dword*through a descriptor built arounds_getpc_b64(Source::Builtwithaddress.param == CODE) ignoredNUM_RECORDS/stride. Each dword went straight tocode_dword, which clamps out-of-range reads to the last word of the code table instead of returning zero.RDNA2 hardware computes
limit = NUM_RECORDSbytes whenstride == 0andNUM_RECORDS * strideotherwise, and returns 0 without reading for each dwordkwhere(soffset & ~3) + (imm & ~3) + 4*k + 4 > limit. Wide multi-dword loads zero only the individual dwords that crosslimit.How
In
crates/victory-shader/src/emit/lower.rs(Lower::smem, inside theaddress.param == CODEbranch):limit = u64::from(words[0]) * u64::from((bits >> 16) & 0x3FFF).max(1)and the compile-time fixed endfixed = (imm & !3) + 4 + 4*kwithout emitting anyINT64instructions (flags::INT64stays clear).fixed > limit, write constant0directly without emittingcode_dword.soffsetis present, emit(soffset & !3)only on thisCODEpath and compareal > ((limit - fixed).min(u32::MAX) as u32)to select0per dword. WhensoffsetisNULL, no extra compare or select is emitted.lower.rsgrows by 957 bytes (520,563 to 521,520, well within the 524,288-byte policy limit).Evidence
87d7bf7c43reports raw compute kernel measurements on AMD Radeon RX 6800 (gfx1030, driver 32.0.21045.29003, wave32 = wave64, 155 runs):stride = 0:imm 0x10atNR 18 -> 0,imm 0x13atNR 21 -> data@0x10,x4at0xcwithNR 21 -> data, data, 0, 0stride = 4, NR = 5:0x10 -> data,0x14 -> 0stride = 1, NR = 17:0x10 -> 0Only the stated rule and measured rows are used; no code is taken.
gemini/ci-a22-slim-negative): run 45885185374 — 302 passed, 2 failed (exclusivelyscalar_buffer_loads_of_a_code_table_read_zero_past_num_recordsandscalar_buffer_loads_of_a_code_table_keep_num_records_with_stride_and_soffset).gemini/ci-a22-slim): run 45885178534 — 304 passed, 0 failed; both Clippy runs clean;policy::tests::repository_passes_policy ... ok.Other pull requests
merge candidate), Shader: a load through a built CODE descriptor starts the constant table at the byte it reads #3155, Shaders: scalar memory loads align each address term independently #3349 (s_load*address alignment), and all our open PRs.merge candidate) inLower::smemaroundsoffsetcalculation; resolves naturally once Shaders: truncate s_buffer_load terms to dword alignment independently #1939 lands. Note that thestride_tests.rsprobe uses dword-alignedsoffset 0x8 + imm 4/8rather thansoffset 0xe + imm 2because unaligned address truncation for the underlying read awaits Shaders: truncate s_buffer_load terms to dword alignment independently #1939.Not checked
s_buffer_load*immediate offsets.soffsetread truncation inLower::smem(covered by Shaders: truncate s_buffer_load terms to dword alignment independently #1939).strideupdates vias_add_u32(resource::set_bitstrackss_or_b32/s_bitset1_b32).Synthetic tests only; no game files.
— Devin & Neon