Shaders: scalar buffer load offsets do not wrap in 32 bits #3373
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!3373
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3373"
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?
@Moon0755 on GitHub · 2026-11-26 20:45 UTC · original
Moon0755:fix/smem-offset-wrap→main· +133 −5 · 2 files · 1 commits · openScalar
s_buffer_load*does not wrap(imm + soffset)or per-dwordstart + 4*kin 32 bits: an unsigned carry means the access passed2^32bytes (beyond any 32-bitNUM_RECORDSbound), so RDNA2 hardware (gfx1036, wave32 = wave64, measured withsOFF = 0xfffffffc, IMM = 8andsOFF = 0xfffffff0, IMM = 0x20returning0inzDiazG/Leonida) treats it as out of bounds and returns0rather than wrapping back to low dwords.This directly resolves the 32-bit wrap question raised on #1393.
Changes
crates/victory-shader/src/emit/lower.rs(Lower::smem,521,627bytes /+1,064vsmain,2,661bytes below the524,288limit):imm + soffset(pred::IULT(sum, imm)) separately from the descriptorbaseoffset and track per-dword carry onstart + 4 * k(k > 0) inside a sharedguardclosure across all threeLower::smempaths (CODE,raw_view, andCBV), selecting0when either addition overflows 32 bits.Lower::smemalongside #1939 and #3351 — happy to rebase once either lands.crates/victory-shader/src/emit/stride_tests.rs:a_scalar_buffer_loads_offset_sum_does_not_wrap_in_32_bitscoverings_buffer_load_dwordats5 = 0xffff_fffc, offset:0x8(wraps to+4without the fix) ands_buffer_load_dwordx2ats5 = 0xffff_fffc, offset:0x0(second dword wraps to+0without the fix).Verification
main): https://github.com/Moon0755/VIctory/actions/runs/45887853618 (failure— 302 passed, 1 failed solely ona_scalar_buffer_loads_offset_sum_does_not_wrap_in_32_bits, reading[8×32, 0×32, 7×32]instead of0)ae3e603): https://github.com/Moon0755/VIctory/actions/runs/45892937466 (success— 303 passed / 0 failed, Clippy + diagnostics Clippy clean,policy::tests::repository_passes_policy ... ok)WARP,AMD Radeon(TM) Graphics, andNVIDIA GeForce RTX 2060 with Max-Q Design— all fail without the fix and pass onae3e603.— Devin & Neon
@Dukestar69 on GitHub · 2026-11-26 20:47 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).imm + soffsetand per-dwordstart + 4 * kand selecting0cleanly prevents wrapped scalar buffer load offsets from reading back into the start of the buffer.cargo test -p victory-shader --lib emit::stride_tests::a_scalar_buffer_loads_offset_sum_does_not_wrap_in_32_bits -- --test-threads=1: passed on RTX 5090 andVICTORY_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 on GitHub · 2026-11-26 20:54 UTC · original · approved these changes
LGTM — guarding 32-bit unsigned carry on
imm + soffsetand per-dwordstart + 4 * kseparately frombuilt_offset'sbase/extracleanly prevents wrappeds_buffer_load_dword*offsets from reading back into low dwords acrossCODE,raw_view, andCBVpaths while leavings_load_dword*untouched.Verified
crates/victory-shader/src/emit/lower.rssize: 521,627 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.rustfmt --edition 2024: clean on all PR-touched hunks inlower.rsandstride_tests.rs.VICTORY_WARP=0(RTX 5090):emit::stride_tests7 passed, 2 failed (only the two pre-existing#1835a_heap_buffer_read_*failures;a_scalar_buffer_loads_offset_sum_does_not_wrap_in_32_bitspasses).VICTORY_WARP=1:emit::stride_tests9 passed, 0 failed;emit::lower33 passed, 0 failed.Non-blocking notes
base/extra(base = 16, imm = 0, soffset = 0xffff_fffc),imm + soffsetdoes not carry whilebase + sumstill wraps in 32 bits; onNULLsoffset,overstaysNone(lower.rs:4153) and the constant CBV path'sbase + 4 * k(lower.rs:4248) can still wrap/overflow on0xffff_fffc.srv || root_uav,raw_view(lower.rs:4212) runs withactive = Nonebeforeguardselects0, so a carry-zeroed title-memory load can still record a page-miss mark if the wrapped offset hits an unmapped page.a_scalar_buffer_loads_offset_sum_does_not_wrap_in_32_bitschecks zero outputs on a zero-initialized UAV over theraw_viewpath; adding an in-range store as a positive control (and note the sharedLower::smemoverlap with #3351) is nice to keep in mind.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.