Repository navigation
Recompiler: preserve odd high half and saturate ints in D16 FormatLoad - #1977
n-romanovich wants to merge 1 commit into
Conversation
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
On an RTX 3070 (Ampere, driver 616.56, Windows 11, debug) at
The direct translator has its own copy of this packing in Two related points, in case they belong here or in a follow-up:
The rest of the batch matches AI-assisted (Claude Code). Synthetic tests only. |
|
Update for head Update for head Confirming the direct-translator failure above on two more GPUs, so it is the Head
With the default path, the full AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report. |
|
Here's the direct-translator half, in case it saves you time. It applies on
RTX 3070 (Ampere, driver 616.56, Windows 11, debug) with it applied:
It changes the direct translator's containers, so patchdiff --git a/crates/xcl/src/gpu/dxil/lower_mem.rs b/crates/xcl/src/gpu/dxil/lower_mem.rs
index 22df80f..97a5550 100644
--- a/crates/xcl/src/gpu/dxil/lower_mem.rs
+++ b/crates/xcl/src/gpu/dxil/lower_mem.rs
@@ -516,6 +516,20 @@ impl Lw {
self.s.m.set_insert_before_term(prev_ins);
r
}
+ /// A d16 format load's integer channel: 32-bit UINT saturates to 0xFFFF and SINT to
+ /// -32768..32767 (RDNA2, as the HLSL path does); the other integer formats fit already.
+ fn d16_int(&mut self, s: Value, ty: Value) -> Value {
+ let u = self.c(0xFFFF);
+ let us = self.umin(s, u);
+ let lo = self.c(-32768i32 as u32);
+ let hi = self.c(32767);
+ let ss = self.imax(s, lo);
+ let ss = self.imin(ss, hi);
+ let ss = self.andc(ss, 0xFFFF);
+ let is_u = self.cmpc(Pred::Eq, ty, 4);
+ self.sel(is_u, us, ss)
+ }
+
fn fmt_desc(&mut self, d3: Value, mtbuf_fmt: Option<u32>) -> FmtDesc {
let key = (d3, mtbuf_fmt);
if let Some(&cached) = self.fmt_desc_cache.get(&key) {
@@ -1286,7 +1300,7 @@ impl Lw {
let z = self.c(0);
if let Some((_, _, high)) = d16_format {
let cur0 = self.vreg(vdata);
- let lo16 = self.andc(s_val, 0xFFFF);
+ let lo16 = self.d16_int(s_val, c1.desc.ty);
let sf = self.f(s_val);
let h16 = self.s.f32_to_f16(sf);
let h = self.sel(c1.desc.isint, lo16, h16);
@@ -1297,7 +1311,10 @@ impl Lw {
let res = self.or(l, h);
self.write32(&Dst::V(vdata), res);
} else {
- let res = self.sel(ok, h, z);
+ // d16_x: the high half of the register is kept
+ let h = self.sel(ok, h, z);
+ let keep = self.andc(cur0, 0xFFFF_0000);
+ let res = self.or(keep, h);
self.write32(&Dst::V(vdata), res);
}
} else {
@@ -1331,17 +1348,25 @@ impl Lw {
if let Some((_, components, _)) = d16_format {
let half = |lw: &mut Lw, comp: u64| -> Value {
let s = decode_sel(lw, comp);
- let lo = lw.andc(s, 0xFFFF);
+ let lo = lw.d16_int(s, desc.ty);
let sf = lw.f(s);
let h = lw.s.f32_to_f16(sf);
lw.sel(desc.isint, lo, h)
};
for i in 0..count {
let lo = half(self, 2 * i);
- let hi = if 2 * i + 1 < components { half(self, 2 * i + 1) } else { z };
- let hi = self.shlc(hi, 16);
- let v = self.or(lo, hi);
- let v = self.sel(ok, v, z);
+ let v = if 2 * i + 1 < components {
+ let hi = half(self, 2 * i + 1);
+ let hi = self.shlc(hi, 16);
+ let v = self.or(lo, hi);
+ self.sel(ok, v, z)
+ } else {
+ // an odd last channel: the high half of the register is kept
+ let cur = self.vreg(vdata + i);
+ let keep = self.andc(cur, 0xFFFF_0000);
+ let lo = self.sel(ok, lo, z);
+ self.or(keep, lo)
+ };
self.write32(&Dst::V(vdata + i), v);
}
} else {
@@ -1359,17 +1384,25 @@ impl Lw {
let sel = lw.lshrc(d3, 3 * comp as u32);
let sel = lw.andc(sel, 7);
let s = lw.dst_sel(&c, sel, desc.isint);
- let lo = lw.andc(s, 0xFFFF);
+ let lo = lw.d16_int(s, desc.ty);
let sf = lw.f(s);
let h = lw.s.f32_to_f16(sf);
lw.sel(desc.isint, lo, h)
};
for i in 0..count {
let lo = half(self, 2 * i);
- let hi = if 2 * i + 1 < components { half(self, 2 * i + 1) } else { z };
- let hi = self.shlc(hi, 16);
- let v = self.or(lo, hi);
- let v = self.sel(ok, v, z);
+ let v = if 2 * i + 1 < components {
+ let hi = half(self, 2 * i + 1);
+ let hi = self.shlc(hi, 16);
+ let v = self.or(lo, hi);
+ self.sel(ok, v, z)
+ } else {
+ // an odd last channel: the high half of the register is kept
+ let cur = self.vreg(vdata + i);
+ let keep = self.andc(cur, 0xFFFF_0000);
+ let lo = self.sel(ok, lo, z);
+ self.or(keep, lo)
+ };
self.write32(&Dst::V(vdata + i), v);
}
} else {AI-assisted (Claude Code). Synthetic tests only. |
|
Diff audit passed on the HLSL side ( Next step: fold in the |
b4d05e5 to
d39aea9
Compare
|
@raylitebull, updated |
|
Diff audit passed on the Remaining before merge: one independent AMD GPU confirmation on |
|
Tested Independent Intel Arc A770 run on clean PR head Prebuilt with & $testExe gpu::recomp::tests::gpu_buffer_load_format_d16_odd_hi_and_int_sat --exact --nocapture --test-threads=1
Both runs checked that Not tested Full workspace suite, retail smoke, release, AMD/NVIDIA adapters, AI use Codex ( |
|
Re-checked AI-assisted (Claude Code). |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
d39aea9 to
4a736a0
Compare
|
Independent native Windows RDNA2 check on exact head Environment: Windows 11 build 26200, Ryzen 9 5980HX, AMD Radeon RX 6800M (native wave64), driver
The checked-in GPU test covers 32_UINT saturation of 70,000 to Scope: Focused debug test only. I did not run the full workspace suite, a main-vs-PR control, or a retail-title smoke on this branch. AI use: OpenAI Codex inspected the regression test, ran both GPU backends, checked the no-skip logs and exact revision, and prepared this report. |
Addresses xcl-dev#1488 (XCL-BT-020). In BufKind::FormatLoad with d16_format: - Preserve vdst[31:16] on odd trailing channels (d16_x, d16_xyz) instead of overwriting the upper 16 bits with 0. - Saturate 32-bit UINT (min(v, 0xFFFFu)) and SINT (clamp(v, -32768, 32767)) values to 16-bit bounds instead of truncating via & 0xFFFFu. Tested: cargo test --workspace -- --test-threads=4. Assisted-by: Antigravity (model name not provided)
4a736a0 to
ef4642a
Compare
|
Heads-up on Updating the Regression run block to match |
|
@raylitebull, updated the Regression run block - ready for merge. |
Addresses #1488 (
XCL-BT-020).In
BufKind::FormatLoadwithd16_format:d16_x,d16_xyz) previously overwrote the entire 32-bitvdstwith0in[31:16], clobbering packed upper-half register state instead of preserving(vdst & 0xFFFF0000u).UINTandSINTformats previously truncated via& 0xFFFFuinstead of saturating to[0, 65535]/[-32768, 32767].What is in it
crates/xcl/src/gpu/recomp/emit.rs: preservevdst[31:16]on odd trailingd16channels and saturateUINT/SINTvalues to 16-bit bounds.crates/xcl/src/gpu/recomp/tests.rs: add GPU testgpu_buffer_load_format_d16_odd_hi_and_int_sat.Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.
cargo test -p xcl --lib format_d16 -- --test-threads=4: 2 passed, 0 failed, 0 ignored (968 filtered out)cargo test --workspace -- --test-threads=4: 994 passed, 0 failed, 45 ignoredSKIPPED: 22gpu::recompwave64 / refused per-lane f16 tests (no wave64/ refused per-lane f16),shaders::tests::pso_measurement_compiles_an_exact_synthetic_record(Windows Developer Mode is required,0x887A002D),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)Regression run
Main (
5478c4a7c1ae5adba127c8d27018d7fdbf3a8725):PR (
ef4642a48ca821f982bb76139da851f1482d1933):Not tested
AI use
smoke.ps1runs.