Skip to content

[Upstream PR #1939/#3351] Align scalar buffer-load terms and enforce code-table bounds #218

Backlog

Description

@vanya890

Scope

Port and reconcile two upstream scalar-memory fixes as one focused shader-correctness change:

  • Marvisak/VIctory#1939, head f7a44b768bce0a5dadc1c494d6b0359202d903e1: independently truncate s_buffer_load_dword* immediate OFFSET and SGPR SOFFSET to DWORD alignment before adding them.
  • Marvisak/VIctory#3351, head 9cad6a17db5fcd95166d4644d842dcd522e5d5cd: honor a code-table descriptor's NUM_RECORDS and stride for scalar s_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

Required fork regressions

  1. Independent alignment of immediate and SGPR offset (including unaligned combinations).
  2. Code-table NUM_RECORDS bounds for stride 0, stride 1 and stride 4.
  3. Per-dword zeroing for wide loads crossing the limit.
  4. Dynamic SOFFSET bounds, with address computation using the independently aligned terms.
  5. Out-of-range constant terms emit zero without unnecessary code-table reads or INT64 instructions.
  6. Existing descriptor-based s_buffer_load behavior 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

  1. vanya890 commented on Nov 26, 2026

    @vanya890
    OwnerAuthor

    Upstream review audit found an unresolved P1 on Marvisak#3351 at head 9cad6a17db5fcd95166d4644d842dcd522e5d5cd: the code aligns imm and soffset for the bounds check but adds an optional dynamic built_offset(src) term to the generated address without including it in the limit check. In this fork, built_offset can return Some(x) for a Source::Built CODE address (Address.dynamic), so the port must not copy upstream Marvisak#3351 verbatim.

    Port plan:

    • Apply Shaders: truncate s_buffer_load terms to dword alignment independently Marvisak/VIctory#1939's independent immediate/SOFFSET DWORD truncation.
    • Include the dynamic extra term in the code-table bounds predicate as well as in the address, with unsigned-add overflow treated as out-of-range.
    • Add a hardware/WARP readback regression with a CODE descriptor whose PC-relative address has a dynamic extra term; verify the dynamic term cannot bypass NUM_RECORDS.
    • Keep the unaligned CODE case in the same regression: soffset=0xe, immediate 2 must resolve to byte 0xc when the dynamic extra is zero.
    • Keep the file-size policy check explicit; current lower.rs has only 2,512 bytes of headroom.

    This is an intentional fork-side correctness fix for upstream review feedback, not a blind cherry-pick.

  2. vanya890 commented on Nov 26, 2026

    @vanya890
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions