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:
1 parent
3a99ee610c
commit
20b9834252
7 files changed
+377
-5
No files matched your search
@@ -1912,3 +1912,88 @@ fn whole_wave_f64_sum_and_cvt_f32_f64() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the hardware adapter is an AMD RDNA card's: what the translator
|
||||
/// writes for one ([`super::rdna`]) holds there.
|
||||
fn rdna_card() -> bool {
|
||||
use windows::Win32::Graphics::Direct3D12::*;
|
||||
use windows::Win32::Graphics::Dxgi::*;
|
||||
let Ok(host) = Host::new(false) else { return false };
|
||||
let mut waves = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default();
|
||||
// SAFETY: plain queries.
|
||||
unsafe {
|
||||
let amd = CreateDXGIFactory2::<IDXGIFactory4>(DXGI_CREATE_FACTORY_FLAGS(0))
|
||||
.and_then(|f| f.EnumAdapterByLuid::<IDXGIAdapter1>(host.device.GetAdapterLuid()))
|
||||
.and_then(|a| a.GetDesc1())
|
||||
.is_ok_and(|d| d.VendorId == 0x1002);
|
||||
amd && host
|
||||
.device
|
||||
.CheckFeatureSupport(
|
||||
D3D12_FEATURE_D3D12_OPTIONS1,
|
||||
(&raw mut waves).cast(),
|
||||
size_of_val(&waves) as u32,
|
||||
)
|
||||
.is_ok()
|
||||
&& waves.WaveLaneCountMin == 32
|
||||
&& waves.WaveLaneCountMax == 64
|
||||
}
|
||||
}
|
||||
|
||||
/// The forms written for the console's own kind of hardware give, on such a
|
||||
/// card, what the ones spelled out for every host give; a legacy product's
|
||||
/// zero may have the other sign.
|
||||
#[test]
|
||||
fn rdna_forms_give_what_the_spelled_out_ones_give() {
|
||||
if !rdna_card() {
|
||||
eprintln!("no RDNA card; skipped");
|
||||
return;
|
||||
}
|
||||
const ONE: u16 = 242;
|
||||
const MINUS_ONE: u16 = 243;
|
||||
let (a, b, c) = (vgpr(1), vgpr(2), vgpr(3));
|
||||
let saturated = vop3_mod(0x110, 5, vgpr(1), vgpr(1), 0, 0, 0, 0, true);
|
||||
let two = |x: [u32; 2], y: [u32; 2]| [x, y].concat();
|
||||
let bodies: [(&str, Vec<u32>, bool); 14] = [
|
||||
("max", vop3(0x110, 0, a, b, 0).to_vec(), true),
|
||||
("min", vop3(0x10F, 0, a, b, 0).to_vec(), true),
|
||||
("max3", vop3(0x154, 0, a, b, c).to_vec(), true),
|
||||
("min3", vop3(0x151, 0, a, b, c).to_vec(), true),
|
||||
("med3 0 1", vop3(0x157, 0, a, 128, ONE).to_vec(), true),
|
||||
("med3 1 0", vop3(0x157, 0, ONE, a, 128).to_vec(), true),
|
||||
("med3 1 -1", vop3(0x157, 0, ONE, MINUS_ONE, a).to_vec(), true),
|
||||
("fract", vec![vop1(0x020, 0, a)], true),
|
||||
("mul_legacy", vop3(0x107, 0, a, b, 0).to_vec(), false),
|
||||
("mul_legacy by itself", vop3(0x107, 0, a, a, 0).to_vec(), false),
|
||||
("mul_legacy by a constant", vop3(0x107, 0, a, MINUS_ONE, 0).to_vec(), false),
|
||||
("mul_legacy of a saturated", two(saturated, vop3(0x107, 0, vgpr(5), b, 0)), false),
|
||||
("mad_legacy", vop3(0x140, 0, a, b, c).to_vec(), false),
|
||||
("max of a mul_legacy", two(vop3(0x107, 5, a, b, 0), vop3(0x110, 0, vgpr(5), c, 0)), false),
|
||||
];
|
||||
let numbers = [0.0f32, -0.0, 1.0, -1.0, 0.3, -2.5e-7, 3e38, f32::INFINITY, f32::NEG_INFINITY, f32::NAN];
|
||||
let mut cases = Vec::new();
|
||||
for (i, x) in numbers.iter().enumerate() {
|
||||
for (j, y) in numbers.iter().enumerate() {
|
||||
let z = numbers[(3 * i + j) % numbers.len()];
|
||||
cases.push([x.to_bits(), y.to_bits(), z.to_bits(), 0]);
|
||||
}
|
||||
}
|
||||
for (name, body, exact) in bodies {
|
||||
let mut got: Vec<Vec<u32>> = Vec::new();
|
||||
let mut written = Vec::new();
|
||||
for bits in [0, super::rdna::ALL] {
|
||||
lower::TEST_RDNA.set(Some(bits));
|
||||
let shader = build_valu_cs(&body);
|
||||
lower::TEST_RDNA.set(None);
|
||||
written.push(shader.dxil.clone());
|
||||
let mut all = Vec::new();
|
||||
run_cases_on(&shader, &cases, &[("hardware", false)], |_, _, _, r| all.push(r));
|
||||
got.push(all);
|
||||
}
|
||||
assert_ne!(written[0], written[1], "{name}: written alike");
|
||||
for (case, (&was, &is)) in cases.iter().zip(got[0].iter().zip(&got[1])) {
|
||||
let (x, y) = (f32::from_bits(was), f32::from_bits(is));
|
||||
let same = was == is || x.is_nan() && y.is_nan() || !exact && x == 0.0 && y == 0.0;
|
||||
assert!(same, "{name} of {:?}: {x} ({was:#x}), now {y} ({is:#x})", case.map(f32::from_bits));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user