Repository navigation
Description
Scope
Port and reconcile two upstream scalar-memory fixes as one focused shader-correctness change:
- Marvisak/VIctory#1939, head
f7a44b768bce0a5dadc1c494d6b0359202d903e1: independently truncates_buffer_load_dword*immediateOFFSETand SGPRSOFFSETto DWORD alignment before adding them. - Marvisak/VIctory#3351, head
9cad6a17db5fcd95166d4644d842dcd522e5d5cd: honor a code-table descriptor'sNUM_RECORDSandstridefor scalars_buffer_load_dword*; return zero per out-of-range dword, including individual elements of wide loads.
Both change Lower::smem in crates/victory-shader/src/emit/lower.rs. Marvisak#3351 explicitly notes the unaligned SOFFSET case awaits Marvisak#1939, so these should be reconciled together rather than importing either hunk blindly.
Hardware/ISA evidence
AMD's official RDNA2 ISA guide, Chapter 7, says SMEM OFFSET is a signed byte immediate (must be positive for s_buffer operations), SOFFSET is an unsigned byte offset, and the two low bits of address components are ignored. It also documents NUM_RECORDS/stride bounds for buffer constants:
https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf
Upstream Marvisak#1939 reports red/green WARP CI and local AMD RDNA2, NVIDIA RTX 2060 Max-Q and WARP checks. Upstream Marvisak#3351 reports red/green WARP CI and local RX 6800, RTX 2060 Max-Q and WARP checks. These are upstream contributor reports, not fork validation.
Fork integration constraints
- Current
dev:539687eaaeebced7cdce26a62d92a732adc5c963. - Current fork
lower.rs: 521,776 bytes; repository policy cap is 524,288 bytes. - Upstream estimates are +329 bytes for Shaders: truncate s_buffer_load terms to dword alignment independently Marvisak/VIctory#1939 and +957 bytes for Shaders: scalar code-table buffer loads keep NUM_RECORDS Marvisak/VIctory#3351. The combined expected file size is about 523,062 bytes, leaving limited headroom; run the repository policy check on the actual port.
- Current fork has neither change in
Lower::smem; the current implementation adds raw immediate andSOFFSETbefore callingcode_dword, which clamps out-of-range code-table reads to the last word. - No claim is made that shipped GTA VI shaders trigger this path; no game assets are required.
Required fork regressions
- Independent alignment of immediate and SGPR offset (including unaligned combinations).
- Code-table
NUM_RECORDSbounds for stride 0, stride 1 and stride 4. - Per-dword zeroing for wide loads crossing the limit.
- Dynamic
SOFFSETbounds, with address computation using the independently aligned terms. - Out-of-range constant terms emit zero without unnecessary code-table reads or INT64 instructions.
- Existing descriptor-based
s_buffer_loadbehavior remains unchanged for in-range aligned cases.
Run exact-head Windows CI (both Clippy profiles, diagnostics build, full workspace tests), policy checks, and WARP/hardware shader readback where available. Do not claim adapter coverage if the test skips it.
Activity
vanya890 commentedon Nov 26, 2026
Upstream review audit found an unresolved P1 on Marvisak#3351 at head
9cad6a17db5fcd95166d4644d842dcd522e5d5cd: the code alignsimmandsoffsetfor the bounds check but adds an optional dynamicbuilt_offset(src)term to the generated address without including it in the limit check. In this fork,built_offsetcan returnSome(x)for aSource::BuiltCODE address (Address.dynamic), so the port must not copy upstream Marvisak#3351 verbatim.Port plan:
extraterm in the code-table bounds predicate as well as in the address, with unsigned-add overflow treated as out-of-range.NUM_RECORDS.soffset=0xe, immediate2must resolve to byte0xcwhen the dynamic extra is zero.lower.rshas only 2,512 bytes of headroom.This is an intentional fork-side correctness fix for upstream review feedback, not a blind cherry-pick.
vanya890 commentedon Nov 26, 2026
Implementation candidate opened as draft PR #221, based on exact current dev
539687eaaeebced7cdce26a62d92a732adc5c963. It ports Marvisak#1939 + Marvisak#3351 together, includes dynamic PC-relative offset and unsigned-overflow checks in NUM_RECORDS bounds, and extends the code-table readback test to cover unaligned SOFFSET/immediate plus dynamic extra 0/4. Exact-head CI is pending; lower.rs is 523,465 UTF-8 bytes before formatting (823 bytes under policy cap). No merge.