Skip to content

Shaders: lower s_abs_i32 through IMax - #3722

Open
Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/scalar-abs-imax
Open

Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/scalar-abs-imax

Conversation

@Ingenioeren

Copy link
Copy Markdown
Contributor

s_abs_i32 currently emits a signed comparison, negation and select. Emit the wrapping negation and DXIL IMax(x, -x) instead: the expression falls from three instructions to two, and the dynamic-input synthetic shader falls from 17 written DXIL instructions to 16 (5.9%). This is an emitted-code reduction; no GPU-time or frame-rate gain is claimed.

INT_MIN remains 0x80000000 because its negation wraps to itself. SCC still comes from the result's nonzero test. DXIL defines IMax as signed integer maximum (opcode 37).

The execution test uses a separate i64-magnitude reference and checks 32,848 inputs, both incoming SCC values, separate and overlapping scalar destinations, and the resulting SCC. Inputs cover ranges around zero, INT_MIN and INT_MAX, every single-bit/complement value, and deterministic random words. RX 6750 XT (driver 32.0.21045.29003) and WARP agree with the reference and each other before and after; DXIL validates.

Validation on fresh main 63bcca4:

  • Tests-only control: cargo test --locked --offline -p victory-shader scalar_abs_ -- --nocapture --test-threads=1 fails the instruction-count assertion (17, expected 16); the execution test passes. With the change, both tests pass and the count is 16.
  • cargo test --locked --offline -p victory-shader -- --test-threads=1: main 300 passed / 2 failed / 3 ignored; branch 302 passed / the same 2 failed / 3 ignored. The existing failures are rectangles_get_their_fourth_corner and elements_sharing_a_row_keep_their_order, both local dxil.dll Pipeline State Validation mismatches.
  • cargo test --locked --offline -p victory-shader --test resource_tracking: 3 passed, 1 ignored. cargo test --locked --offline -p victory-shader --doc: 0 tests.
  • cargo clippy --locked --offline -p victory-shader --all-targets --all-features -- -D warnings: passes before and after.
  • cargo run --locked --offline -p xtask -- policy --staged: passes (3 staged files). git diff --check: clean; changed files introduce no formatting deviations relative to main.

No game files, extracted shaders or game execution were used. No graphics/mesh, wave64 numeric execution, frame-time measurement or RADV/vkd3d runtime validation was performed. This does not resolve or validate the separate RADV pipeline-compilation hold reported on #3027.

Searched all 1,802 open PR titles/bodies for s_abs_i32 and searched open/closed PRs for scalar abs/absolute value; no competing scalar-abs optimization found. The test-only written_instructions helper is identical to the one in #3691 and our other lowering PRs; keep one copy when integrating. Other production lowering is unchanged.

AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.

@cloph-dsp

Copy link
Copy Markdown

Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR Shaders: lower s_abs_i32 through IMax #3722 at head 77bc8c16d1910172f05ce55b5bea23fff71052b4, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::lower::tests::scalar_abs_uses_two_operations --exact --test-threads=1 --quiet → 1 passed, 0 failed, 306 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (3 files, +84/-2).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only shader IR lowering test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I combined your exact 77bc8c1 with #3728 56b89fc in integration commit 06cb03f. Git merged the lowering and test files cleanly, and both commits are direct parents.

The added regression uses s_abs_i32 to produce SCC, then sets or clears a bit in the same destination before reading SCC. It checks both cases where the bit change makes a zero value nonzero and where it makes a nonzero value zero. In each case SCC still reflects the absolute-value result. INT_MIN is also covered.

All four focused tests passed on Windows WARP with Agility 1.620.2, including your instruction count and execution tests. Strict shader Clippy and the asset policy passed. @Ingenioeren, the integration test is available for merge coordination. Please retain the original Git authors when rebasing or cherry-picking.

AI-assisted with OpenAI Codex.

@ColorMeBoom

Copy link
Copy Markdown

Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head 77bc8c1 on 63bcca4.

  • scalar_abs_matches_wide_magnitudes_and_scc passes: 32,848 inputs, zero mismatches on the card and on WARP, SCC included. scalar_abs_uses_two_operations passes.
  • Full victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

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.

4 participants