Skip to content

fix(formats,shader,gpu): guard BC7 rotation, SDWA sext and RDNA 2 legacy FMA, and skip read-only table UAV writeback - #406

Open
gdemontalivet wants to merge 2 commits into
pragyaangaur:mainfrom
gdemontalivet:feat/macos-nov26-visual-fps-ports
Open

gdemontalivet wants to merge 2 commits into
pragyaangaur:mainfrom
gdemontalivet:feat/macos-nov26-visual-fps-ports

Conversation

@gdemontalivet

Copy link
Copy Markdown
Contributor

Three decoding/lowering accuracy bugs and one unnecessary GPU buffer copy-back cost show up across texture unpacking, shader lowering, and root-table UAV bindings:

  1. BC7 channel rotation applied outside modes 4 and 5 (victory-formats/src/bcpack.rs): In the BC7 specification, only modes 4 and 5 carry a 2-bit channel rotation field; modes 0–3, 6, and 7 have none. Reading rotation bits unconditionally on non-4/5 blocks swaps colour and alpha channels or triggers shift overflows on malformed bit patterns.
  2. RDNA 2 v_mac_legacy_f32 / v_mad_legacy_f32 and SDWA 16-bit UNUSED_SEXT (victory-shader/src/emit/lower.rs):
    • On RDNA 2, v_mac_legacy_f32 and v_mad_legacy_f32 compute a fused multiply-add with FTZ inputs where either factor being ±0.0 (after FTZ) forces the product term to +0.0 even if the other factor is NaN or ±Inf. Lowering them as unfused fmul + fadd loses precision and diverges on edge inputs.
    • SDWA instructions writing a 16-bit WORD_0 destination with dst_unused = 1 (UNUSED_SEXT) must sign-extend bit 15 into bits 16..31 (and refuse reserved dst_unused = 3) instead of zero-extending or leaving high bits unchanged.
  3. Unconditional reverse copy-back on read-only table buffer UAVs (victory-gpu/src/pipeline.rs, draw.rs): Shaders frequently bind descriptor tables containing RWBuffer / RWStructuredBuffer / RWByteAddressBuffer slots that a given dispatch only reads (or never touches), while writing to a different UAV slot. Marking every buffer UAV in every bound table range for Shadow::gpu_writes forces full-page forward refresh widening, pre-write snapshot arming, and post-submission reverse copy-back on read-only buffers.

What changed

  1. BC7 modes 4–5 rotation guard, RDNA 2 legacy FMA, and SDWA 16-bit UNUSED_SEXT (732ff99e):
    • Restrict BC7 channel rotation in bcpack.rs to modes 4 and 5.
    • Lower v_mac_legacy_f32 and v_mad_legacy_f32 via DXIL Fma with FTZ-flushed inputs and the RDNA 2 zero-factor select rule.
    • Sign-extend SDWA WORD_0 destinations when dst_unused == 1 (UNUSED_SEXT) and refuse reserved dst_unused == 3.
  2. resource::track-verified table buffer UAV writeback skip (792f2c2d):
    • Trace buffer/SMEM stores and atomics in each translated shader through victory_shader::resource::track back to their (user_data, table_offset_dwords) root-table descriptors, recording per-UsedResource write flags alongside a conservative write_unknown fallback on Translated whenever any store/atomic target cannot be statically proven.
    • In draw::State::tables and readable_entry, skip shadow.gpu_writes and full-page writeback widening for table buffer UAVs proven read-only by that shader (VICTORY_TABLE_UAV_WRITE_SKIP=0 restores unconditional writeback). Texture UAV resource-state transitions remain unchanged.

How it was tested

  • Apple M5 Max, CrossOver Preview with D3DMetal (wave32=true), isolated test bottle:
    • cargo test --workspace (native macOS): all passed (0 failed).
    • Windows + D3DMetal (--test-threads=1):
      • victory-formats (bcpack::tests): 11 passed, verifying BC7 modes 0–7 rotation handling and round-trip unpacking.
      • victory-shader (valu_tests): 7 targeted hardware/WARP execution tests passed, covering RDNA 2 legacy FMA fusing/FTZ/zero-factor semantics and SDWA 16-bit UNUSED_SEXT.
      • victory-gpu: 38 D3DMetal pipeline/draw UAV tests passed, verifying read-only table buffer UAVs skip gpu_writes while written or dynamically indexed UAVs preserve full writeback.
    • cargo xtask policy, git diff --check, and cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings (with and without --features diagnostics): clean. All test inputs are synthetic.

Live M5 Max Verification (Combined Build on CrossOver Preview + D3DMetal)

  • In a combined warm-cache 720p opening-sequence run on Apple M5 Max (CrossOver Preview + D3DMetal, wave32=true), the runtime reached and sustained the 3D world through +8, +24, +48, +90 at 1.5–1.8 FPS (549.7–672.1 ms/frame on 1,021–1,258 draws/frame, 1.275 FPS overall across +8..+90) with 0 2.48 s allocation stalls, 7.2–9.0 ms/frame GUARDS lock hold time (down from 4,887 ms/frame before unlocking GUARDS), 149–154 MB/frame buffer copy volume, 0 DirectStorage decompression or access-violation failures, and 38/38 over-32 KiB aligned mesh/pixel pairs linked with 0 host mesh refusals.

… legacy FMA

- Restrict BC7 channel rotation bits to modes 4 and 5 in bcpack (modes 0/1/2/3/6/7 have no rotation field), preventing channel corruption and shift-overflow panics (upstream #3111 / victory-gta6 06702fe).
- Lower v_mac_legacy_f32 and v_mad_legacy_f32 as RDNA 2 fused multiply-add with FTZ inputs and the legacy zero-factor rule (victory-gta6 f6a09d3 / PR #1026).
- Sign-extend SDWA 16-bit WORD_0 destinations with dst_unused=1 (UNUSED_SEXT) and refuse reserved dst_unused=3 (upstream #3124 / victory-gta6 58de9bf).

Add unit tests covering BC7 rotation, legacy FMA fusing/FTZ/zero-factor semantics, and SDWA sign extension.
Trace buffer/SMEM stores and atomics in each translated shader through
victory_shader::resource::track back to their root-table (user_data,
table_offset_dwords) descriptors, recording per-UsedResource write flags
and a conservative write_unknown fallback in Translated.

In draw::State::tables and readable_entry, skip shadow.gpu_writes and
full-page refresh widening for table buffer UAVs that the shader never
writes (with VICTORY_TABLE_UAV_WRITE_SKIP=0 to disable). Texture UAV
state transitions remain unchanged.

Adapted from VItoriaBr 6d97bea using sound resource::track resolution
instead of comparing SGPR indices against HLSL register lower_bound.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant