Repository navigation
Port upstream shader-lowering wave 3 (17 PRs: samplers, SGPR init, atomics, overflow helpers) - #3
Merged
Merged
Conversation
DXIL has no operation for these five, so they stopped the program. Each is now a compare-and-swap loop on the dword: the new value is made from the old one by RDNA2's definition, starting from a guess of 0, until the exchange finds the value it was made from. A null view reads 0, so the loop leaves at once there. inc and dec wrap at the data as the ISA says; fcmpswap compares as floats (-0 matches +0, NaN matches nothing); fmin and fmax follow v_min_f32 and v_max_f32. Tests: synthetic GFX10 compute shaders for each, validated by dxil.dll and run on the host GPU and WARP, checking the returned old value and the texel left behind.
Set SCC for S_ADD_I32, S_SUB_I32, and S_ADDK_I32 from the signs of their inputs and wrapping result. Exercise branches that consume SCC and compare GPU readback against signed arithmetic.
Emit one store element for equal-offset DS_WRITE2 and DS_WRITE2ST64. Exercise 32-bit and 64-bit stores with equal and distinct offsets through compute dispatch and readback.
…_sub_i32
AI-generated & verified with Gemini 4 Neon (not written by a human engineer).
s_add_i32, s_addk_i32, and s_sub_i32 previously left SCC as
Val::Missing("the carry of a scalar operation"), causing any shader that
reads SCC after these instructions (e.g. via s_cselect_b32 or s_cbranch_scc*)
to fail lowering.
Compute 32-bit two's-complement signed overflow directly in i32 (no i64
capability required), matching the AMD RDNA2 ISA:
- s_add_i32 / s_addk_i32: ((a ^ r) & (b ^ r)) <s 0
- s_sub_i32: ((a ^ b) & (a ^ r)) <s 0
Verified with synthetic GPU + WARP + dxil.dll tests in valu_tests.rs on
NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used.
Co-Authored-By: Gemini 4 Neon <noreply@google.com>
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer.
`v_pk_fmac_f16` (packed 2x f16 multiply-accumulate into the destination VGPR)
is decoded by gfx10 (VOP2 0x3c / VOP3 0x13c) but previously routed into
`packed16`, which rejected it with `Err("a packed 16-bit operation")`.
Add `pk_fmac_f16` in `lower.rs` to compute both f16 halves (`lo` and `hi`) via
`legacyF16ToF32` -> `fmad` -> `legacyF32ToF16`, honoring DPP (`self.src0`),
GFX10 inline-constant expansion (low half = constant, high half = 0), and VOP3
`abs`/`neg`/`omod`/`clamp` modifiers across both halves.
Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on
NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used.
Co-Authored-By: Gemini 4 Neon (High Mode) <noreply@google.com>
…{add,sub,mad}_{u16,i16})
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer.
`packed16` in `lower.rs` previously rejected `v.clamp` on all packed 16-bit
integer instructions with `Err("modifiers on a packed integer operation")`.
Under the AMD RDNA2 ISA (VOP3P), `clamp` on `v_pk_add_u16`, `v_pk_sub_u16`,
`v_pk_mad_u16`, `v_pk_add_i16`, `v_pk_sub_i16`, and `v_pk_mad_i16` saturates
each 16-bit lane to `[0, 65535]` (unsigned) or `[-32768, 32767]` (signed).
Because `packed16` computes each lane in 32 bits (`u16*u16+u16 <= u32::MAX`,
`i16*i16+i16` fits in `i32`), saturation is exact in 32-bit integer compares
before masking to 16 bits. Non-saturating packed integer ops keep rejecting
`clamp`.
Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on
NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used.
Co-Authored-By: Gemini 4 Neon (High Mode) <noreply@google.com>
…4 special-case semantics
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer. Lower the four RDNA2 `frexp` instructions (`v_frexp_mant_f32`, `v_frexp_exp_i32_f32`, `v_frexp_mant_f16`, `v_frexp_exp_i16_f16`) via a shared 32-bit bitwise `frexp_f32` helper: - finite non-zero (normal and subnormal via DXIL `FirstbitHi` op 33): mantissa in `(-1, -0.5] U [0.5, 1)` and unbiased exponent `exp` where `a == mantissa * 2^exp`; - `±0`, `±inf`, `NaN`: mantissa preserves the input (sign/special value), exponent is `0`. - f16 variants widen through `half_fsrc` (exact even for all f16 subnormals), apply `frexp_f32`, and preserve the destination's untouched half via `write_half`. Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used. Co-Authored-By: Gemini 4 Neon (High Mode) <noreply@google.com>
… ops AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer. - Add `v_mad_u16` (VOP3 0x340) and `v_mad_i16` (VOP3 0x35e) to `valu16` / `valu16_op` in `crates/victory-shader/src/emit/lower.rs`, preserving the untouched half of the destination VGPR via `write_half`. - Allow saturating `v.clamp` on `v_add_nc_u16`, `v_sub_nc_u16`, `v_subrev_nc_u16`, `v_mad_u16`, and `v_mad_i16` (clamping to `[0, 65535]` for unsigned and `[-32768, 32767]` for signed in 32-bit intermediate precision). Non-saturating 16-bit integer ops continue to reject `v.clamp`. Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used. Co-Authored-By: Gemini 4 Neon (High Mode) <noreply@google.com>
AI-generated & verified with Gemini 4 Neon (High Mode) — not written by a human engineer. Lower `v_ldexp_f16` (`D.f16 = S0.f16 * 2^(S1.i16)`) in `valu16` / `valu16_op`: - Widens `S0` via `half_fsrc` (exact for all f16 normals and subnormals, honoring `opsel[0]`, `abs[0]`, `neg[0]`) and sign-extends `S1` from 16 bits via `half_src`. - Clamps the exponent to `[-64, 64]` and constructs `2^e` directly as a normal finite f32 (`(e + 127) << 23`), so `±0 * finite = ±0` (never `0 * inf = NaN`), `±inf * finite = ±inf` (never `inf * 0 = NaN`), and extreme exponents (`i16::MIN` / `i16::MAX`) overflow/underflow f16 cleanly without intermediate f32 faults. - Writes back via `float_result` (honoring `clamp`, `opsel[3]`, and preserving the untouched half of the destination VGPR). Verified with synthetic GPU + WARP + dxil.dll tests in `valu_tests.rs` on NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used. Co-Authored-By: Gemini 4 Neon (High Mode) <noreply@google.com>
…the quad A console compute program may sample with an implicit level of detail (image_sample, image_sample_b): the hardware takes the coordinates' coarse derivatives across each quad of lanes. As DXIL `sample` and `sampleBias`, these programs failed validation with "Function uses features incompatible with the shader stage (cs) of the entry function". The gradients are now read from the quad (lane 1 less lane 0, lane 2 less lane 0, through waveReadLaneAt) and passed to `sampleGrad`; a bias scales them by 2^bias. Pixel and mesh shaders are unchanged. `victory translate --validate` over the title's shaders on Windows (dxil.dll 10.0.26100), on top of #439: compute programs validated go from 1,658 to 2,193 of 2,193 emitted; no other count changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SDn5GupcrERtCYPyoztdtG
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/lower.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/lower.rs # crates/victory-shader/src/emit/valu_tests.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/lower.rs # crates/victory-shader/src/emit/shader.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # crates/victory-shader/src/emit/mod.rs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ap, descriptor words) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third porting wave from upstream Marvisak/VIctory: 17 instruction-lowering and shader-translator fix PRs (#1237, #1223, #1211, #1197, #1190, #1149, #1148, #1142, #1136, #1095, #1090, #1088, #1057, #1108, #1099, #1103, #1176), all inside
victory-shader.Notable changes:
sampler_handle(block, n, comparison)— immediate samplers now carry a per-use comparison flag; a sampler used both with and without comparison splits into two static samplers (#1108).Unsupported(#1176).signed_overflow(c, a, b, r, signed)helper dedupes SOP2/SOPK add/sub carry-out lowering (#1088).is_64for image atomics keys onpair = matches!(op, "cmpswap" | "fcmpswap")so ATOMIC_LOOP ops keep the 64-bit atomic lowering from the previous wave (#1148 merged with #1127).valu_tests.rsconflicts); test helpers (vop3p,sopk,build_test_cs,run_output_cases,run_signed_scc_cases,check_lds_paired_write) pulled in with them.Test-fixup commit adapts the ported tests to post-#1198 signatures:
resource::track(..., Some(&st))andHostShader { address_map: false, descriptor_words: false }.cargo clippy -D warningsandcargo fmt --checkclean onx86_64-pc-windows-msvc.cargo test --workspace: 116 pass; 35 failures are allneither hardware nor WARP SM 6.6 device available— environmental on this GPU-less VM, same class as the 15 pre-existing failures onmain.Link to Devin session: https://app.devin.ai/sessions/39a24dfe2c184165b42b2108a96286b6
Open in Devin Desktop: https://app.devin.ai/desktop/session/39a24dfe2c184165b42b2108a96286b6?variant=devin
Requested by: @Personed