Max, min, legacy products, medians and fractions as the RDNA card's own (VICTORY_RDNA_FLOAT, on; 0: spelled out as before)

The console's v_max/v_min (seven host operations each, for the order of the
two zeros), v_mul_legacy (a product, two comparisons, an or and a select;
two thirds of all products of the lighting program), v_med3 and v_fract are
written as the one operation the driver makes the same instruction of, where
the host is an AMD card with waves of 32 and 64. Checked on the RX 7900 XTX
against the spelled-out forms with zeros, infinities and NaN (a legacy
product's zero may have the other sign).

RX 7900 XTX, yard capture replayed turn by turn with and without (12 loops
each): dispatches and draws 18.41 -> 17.58 ms, the lists' 29.2 -> 28.4 of a
36.6 ms frame; 0.4 of it without the legacy products. The picture is the same
(79 dB; two replays of one set differ by 68). A product that is only a
product would give 0.65 ms more and NaN where the console has 0.

Measured and left out (nothing): v_mad as one multiply-add, fast
reciprocals, scalar loads of four dwords at once, buffers picked from the
heap read without asking for their kind (0.12 ms), a wave size for every
compute program (32: +0.26 ms, 64: +0.1, the console's: +0.1), no barriers
at all (0). Changes the translator: every shader is translated again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 12:49:12 -06:00
1 parent 3a99ee610c
commit 20b9834252
7 files changed
+377 -5

No files matched your search

+74 -3
View File
@@ -1111,9 +1111,33 @@ fn own_bits_on() -> bool {
}
/// What the translator was told of the host, for a cache's key: the widest
/// wave, the view heap's limit and where the raw twins of its views start.
pub fn host_settings() -> [u32; 3] {
[host_max_wave(), super::shader::view_heap_limit(), super::shader::raw_views()]
/// wave, the view heap's limit, where the raw twins of its views start, and
/// what it writes for the console's own hardware.
pub fn host_settings() -> [u32; 4] {
[host_max_wave(), super::shader::view_heap_limit(), super::shader::raw_views(), host_rdna()]
}
static HOST_RDNA: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
/// Tells the translator that the host's shaders run on AMD RDNA hardware
/// ([`super::rdna_float`]).
pub fn set_host_rdna(on: bool) {
HOST_RDNA.store(on, std::sync::atomic::Ordering::Relaxed);
}
#[cfg(test)]
thread_local! {
/// A test's choice for [`host_rdna`], for its thread only.
pub(super) static TEST_RDNA: std::cell::Cell<Option<u32>> = const { std::cell::Cell::new(None) };
}
/// The bits of [`super::rdna`] that count on this host.
pub(super) fn host_rdna() -> u32 {
#[cfg(test)]
if let Some(bits) = TEST_RDNA.get() {
return bits;
}
if HOST_RDNA.load(std::sync::atomic::Ordering::Relaxed) { super::rdna_float() } else { 0 }
}
/// The refusal of a first half of an interpolation whose result is read
@@ -3674,6 +3698,9 @@ impl<'a> Lower<'a> {
fn max_min(&mut self, max: bool, a: V, b: V) -> V {
let c = self.cur;
let r = self.binary(if max { 35 } else { 36 }, a, b);
if host_rdna() & super::rdna::MAX_MIN != 0 {
return r;
}
let (ia, ib) = (self.as_int(a), self.as_int(b));
let either = self.s.m.bin(c, Bin::Or, ia, ib);
let magnitude = self.s.m.i32(0x7FFF_FFFF);
@@ -3807,6 +3834,25 @@ impl<'a> Lower<'a> {
/// is the smallest number among them).
fn med3(&mut self, a: V, b: V, third: V) -> V {
let c = self.cur;
// Between two constants in order: the lower one for a NaN either way.
if host_rdna() & super::rdna::MED3 != 0 {
let k = [a, b, third].map(|x| self.s.m.float_k(x));
let ordered = match k {
[None, Some(x), Some(y)] => Some((a, b, third, x, y)),
[Some(x), None, Some(y)] => Some((b, a, third, x, y)),
[Some(x), Some(y), None] => Some((third, a, b, x, y)),
_ => None,
};
if let Some((v, p, q, x, y)) = ordered
&& !x.is_nan()
&& !y.is_nan()
&& x != y
{
let (low, high) = if x < y { (p, q) } else { (q, p) };
let t = self.binary(35, v, low);
return self.binary(36, t, high);
}
}
let lo = self.binary(36, a, b);
let hi = self.binary(35, a, b);
let t = self.binary(36, hi, third);
@@ -3829,6 +3875,9 @@ impl<'a> Lower<'a> {
fn fract(&mut self, a: V, threshold: f32, below_one: f32) -> V {
let c = self.cur;
let r = self.unary(22, a);
if host_rdna() & super::rdna::FRACT != 0 && below_one == f32::from_bits(0x3F7F_FFFF) {
return r;
}
let limit = self.s.m.f32(threshold.to_bits());
let k = self.s.m.f32(below_one.to_bits());
let over = self.s.m.cmp(c, pred::OGE, r, limit);
@@ -3878,6 +3927,28 @@ impl<'a> Lower<'a> {
/// `0 × anything = 0`, as in D3D9.
fn legacy_mul(&mut self, a: V, b: V) -> V {
let c = self.cur;
if host_rdna() & super::rdna::LEGACY != 0 {
let m = self.s.m.bin(c, Bin::Mul, a, b);
let zero = self.s.m.f32(0);
// A product is not 0 only where one factor is 0 and the other an
// infinity or no number: never of a value with itself, nor of two
// finite ones, and only where the finite one of two is 0.
let (fa, fb) = (self.s.m.bounded(a, 12).is_some(), self.s.m.bounded(b, 12).is_some());
let not_zero = |l: &Self, x: V| l.s.m.float_k(x).is_some_and(|k| k != 0.0 && k.is_finite());
if a == b || fa && fb || not_zero(self, a) || not_zero(self, b) {
return m;
}
let asked = match (fa, fb) {
(true, _) => a,
(_, true) => b,
_ => {
let (a, b) = (self.unary(6, a), self.unary(6, b));
self.binary(36, a, b)
}
};
let z = self.s.m.cmp(c, pred::OEQ, asked, zero);
return self.s.m.select(c, z, zero, m);
}
let m = self.s.m.bin(c, Bin::Mul, a, b);
let zero = self.s.m.f32(0);
let az = self.s.m.cmp(c, pred::OEQ, a, zero);