Skip to content

Recompiler: reload::changes misses VOPC SDWA SDST writes, mimg_unorm_sample passes unclamped mip to GetDimensions, and partition.rs unsound Tier::Exact escapes #2464

Backlog

Description

@microwave805

Static audit on main @ c7e1799 found three correctness bugs in recently merged Direct DXIL / Recompiler modules (reload.rs #2207, lower_image.rs #1951, partition.rs). Part of #1269.

1. reload::changes() misses VOPC SDWA SDST writes, causing stale scalar reload elision

  • Where: crates/xcl/src/gpu/dxil/reload.rs:94, 121-125 (contrast crates/xcl/src/gpu/dxil/lower_valu.rs:1380-1394)
  • Root cause: reload::changes(d) reads ["SDST", "SDATA", "VDST"] only from d.enc. For ENC_VOPC with Variant::Sdwa and SD == 1 (VOPC_VOP_SDWA_SDST_ENC), SDST lives in super::lower::ext_encoding(d) (dword 1). lower_valu.rs:1382-1389 writes s[sd..=sd+1], while reload::changes marks only VCC/EXEC and leaves s[sd..=sd+1] unmarked.
  • Trigger:
    s_load_dwordx4 s[12:15], s[4:5], 0x40
    v_cmp_eq_u32_sdwa s[4:5], v0, v1   ; SD=1, SDST=4 overwrites s[4:5]
    s_load_dwordx4 s[12:15], s[4:5], 0x40
    reload::analyze marks the second load available and lower_mem.rs:1097-1103 elides it, returning stale data from the old s[4:5].
  • Fix: In reload::changes, when d.variant == Variant::Sdwa, inspect ext_encoding(d): if SD == 1, mark pair(sdst, 2).

2. mimg_unorm_sample passes unclamped level to GetDimensions (leaving coordinates unnormalized when lod >= num_mips) and mismatches mip level on IMAGE_SAMPLE_C_L

  • Where: crates/xcl/src/gpu/dxil/lower_image.rs:630-665, 685-688 (added in dxil: emulate explicit-LOD gather4_l(_o) and support UNORM=1 non-cube sampling #1951)
  • Root cause:
    1. For explicit-LOD UNORM=1 sampling (IMAGE_SAMPLE_L, IMAGE_SAMPLE_L_O, IMAGE_SAMPLE_C_L), lines 632-640 pass unclamped level = ftoui(fmax(round_ne(lod), 0.0)) to get_dimensions(tex.handle, Some(level)) (unlike mimg_gather4_lod directly above at lines 471-488, which clamps mip_i = umin(mip_raw, max_mip)). Per D3D12 spec, GetDimensions returns 0 when level >= num_mips; line 648 clamps 0 to 1, so line 664 divides coords[k] / 1.0 and passes raw unnormalized texel coordinates to sampleLevel.
    2. For IMAGE_SAMPLE_C_L with UNORM=1, line 632 queries mip level while line 685 lowers to sample_cmp_level_zero (mip 0), mis-scaling coordinates by 2^level.
  • Fix: Force level = 0 when cmp.is_some() && (has_lz || !ps); otherwise query mip 0 for num_mips and clamp level = umin(level, num_mips - 1) before get_dimensions(tex.handle, Some(level)).

3. Unsound Tier::Exact escapes in recomp/partition.rs

  • Where: crates/xcl/src/gpu/recomp/partition.rs:154-181, 247-309, 330, 378-402, 844-851
  • Root causes:
    1. Narrowed-EXEC uniform_mask (partition.rs:378, 382): vcmp_uniform = is_vcmp(d) && all_uniform omits st.exec_launch && (under narrowed EXEC, V_CMP_* writes 0 in inactive lanes, producing a non-uniform mask), and mask_uniform includes || s == EXEC || s == EXEC + 1 unconditionally even when !st.exec_launch. Under narrowed EXEC, v_cmp_eq_u32 vcc, v7, v7 or s_mov_b64 vcc, exec sets uniform_mask[VCC] = true; after restoring EXEC, s_cbranch_vccz is falsely classified Tier::Exact even though split wave32's upper half takes the wrong branch.
    2. DS_BPERMUTE_B32 / DS_PERMUTE_B32 (partition.rs:330, 247-309): Excluded from is_store and never tainted with CROSS_LANE in source_taint(), so ds_bpermute_b32 v0, v4, v5; exp is classified Tier::Exact.
    3. VOPC SDWA SDST (partition.rs:154-181): uses(d) calls rdna2::sgpr_uses(d) (which ignores ext_encoding(d)), so v_cmp_gt_f32_sdwa s[10:11], v4, v5 (SD=1) never sets st.mask[10..=11].
    4. S_MOVREL* (partition.rs:154-181, 336-449): Indirect SGPR indexing via M0 is unhandled (sgpr_uses sees only the base register), allowing tainted SGPRs to escape Exact.
    5. or_launch (partition.rs:384): Uses .any(|&s| is_launch(s)) (accepts a pair with one half clobbered) and permits -1 as the other operand (s_or_b64 exec, s[10:11], -1 sets exec_launch = true while activating non-launch lanes).
  • Fix direction: Gate vcmp_uniform on st.exec_launch, remove s == EXEC || s == EXEC + 1 from mask_uniform, taint DS_BPERMUTE_B32/DS_PERMUTE_B32 with CROSS_LANE, conservatively taint S_MOVREL*, parse SDWA SD == 1 SDST in uses(d), and require both halves of the launch pair + a lane-mask other operand in or_launch.

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ c7e1799 and issue drafting.

Activity

  1. oni-swr commented on Nov 25, 2026

    @oni-swr
    Contributor

    Claiming Parts 2 (mimg_unorm_sample mip clamping / IMAGE_SAMPLE_C_L mip 0) and 3 (recomp/partition.rs Tier::Exact soundness) of #2464 — leaving Part 1 (reload::changes VOPC SDWA SDST) to open PR #2479.
    AI use: orchestrated with Antigravity; implementation by Claude Code (Claude Opus 5.5).

  2. oni-swr commented on Nov 26, 2026

    @oni-swr
    Contributor

    Claiming Part 1 (reload::changes missing VOPC SDWA SDST writes); oni-swr has Parts 2 and 3.
    Plan: mark s[SDST..+1] when the SDWA VOPC has SD=1, with a CPU unit test in reload.rs (no GPU needed).

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