Skip to content

Recompiler: preserve relative VGPR moves across compute lowering - #1961

Draft
WebIdentity1 wants to merge 1 commit into
xcl-dev:mainfrom
WebIdentity1:codex/nov24-relative-vgpr-current
Draft

WebIdentity1 wants to merge 1 commit into
xcl-dev:mainfrom
WebIdentity1:codex/nov24-relative-vgpr-current

Conversation

@WebIdentity1

@WebIdentity1 WebIdentity1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1890. Compute-entry relative VGPR writes could be silently dropped when their destination was only referenced later; per-lane relative reads could also be refused. The bound depended on lowering order and the bridge's per-instruction register set.

What is in it

  • Retain the program-wide VGPR bound for relative-indexing programs and initialize register gaps.
  • Transfer the possible relative range through the per-lane bridge, preserving inactive lanes. Keep main's source-hashed cache and initialization state.
  • One compute-output regression covers four move forms and inactive lanes; README describes the behavior. Separate swaprel destination semantics remain with Recompiler: v_swaprel_b32 indexes the destination with M0[25:16] #803.

Tested

  • Head 1bb18a942c6c9d7f18b4d0079c3209c1f9fafeae, based on main cbc296ab65a2661a61e3e2da109134bcd5319f60. Tested snapshots match all 322 source hashes before/after and the committed files; each source switch rebuilt. Windows 10 Home 19045, Ryzen 7 7800X3D, Rust/Cargo 1.98.1 MSVC, DXC/DXIL 1.8.2502.11, debug. RTX 3090 driver 591.74; AMD Radeon(TM) Graphics iGPU driver 32.0.21030.2001.
  • cargo build --locked --workspace: passed on main+regression and head. XCL_ADAPTER=3090 cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: 1152 passed / 3 failed / 46 ignored → 1154 passed / 1 failed / 46 ignored, across 21 harnesses, both exit 101. The same CLAMP mismatch remains. Baseline also fails this regression and the previously intermittent d32s8_targets_take_their_own_size_of_video_memory (Close, 0x80004005); the latter is not credited to this fix.
  • The same 27 SKIPPED notices in both full runs: 20 native-wave64 subcases, 3 refused per-lane arithmetic/conversion subcases, 2 unavailable debug-layer checks, 1 unavailable driver-cache-disable check, 1 disabled heap-window check. Some suite fixtures select adapter 0 independently. No optional game assets configured.
  • The regression confirms RTX 3090 and passes all 20 dispatches, checking all 64 output words each. With XCL_ADAPTER=AMD, cargo test --locked -p xcl --lib -- gpu::recomp::lower_dxil::tests::relative_registers_reach_compute_output --exact --test-threads=1 --show-output: 0/1/0 → 1/0/0, zero skips; head passes all 30 dispatches, including native wave64. Baselines produce 64/64 wrong words on four NVIDIA/six AMD writes, then refuse the per-lane relative read.

Regression run
Not run: no retail title available. This remains draft; required clean exact-head/main smoke blocks remain outstanding. Earlier smoke results from other branches do not qualify this revision.

Not tested
Full AMD suite, graphics-stage draws, retail gameplay, and game-scale compilation time or memory. The NVIDIA-selected full suite is not green. The earlier bounded bridge-cost experiment retains its exact snapshot and limits.

AI use
Codex with GPT-6 Astra authored the original fix and regression. Codex with GPT-6 integrated the existing fix on current main, reviewed the diff, ran the paired native Windows tests and prepared this report.

@raylitebull

Copy link
Copy Markdown
Member

Diff audit on draft 62b85c1 (max_vgpr scan up front in kernel.rs/lower.rs plus relative_registers_reach_compute_output covering both direct and per-lane compute) looks solid.

When ready to undraft: rebase onto main (dropping the manual TRANSLATOR_VERSION = 8 bump in kernel.rs, as #1947 now auto-hashes gpu/dxil sources), add the xcl-smoke block for PR description, and add AMD + NVIDIA verification.

@WebIdentity1
WebIdentity1 force-pushed the codex/nov24-relative-vgpr-current branch from 62b85c1 to 4b4c111 Compare November 25, 2026 01:16
@WebIdentity1

Copy link
Copy Markdown
Contributor Author

Addressed the source-hash and GPU-verification parts in 4b4c111098a3b22e21dce00d41bc95ab3c11da8e on main aa9ab8a3e7b738ec48899e37805f6a7d2d22da53. The old 62b85c1 worktree/revision is preserved; the manual cache bump is gone.

The new regression passes all 20 RTX 3090 dispatches and all 30 AMD Radeon(TM) Graphics iGPU dispatches (including native wave64), checking 64 output words per dispatch, with no regression-test skips. Main + the same test fails on both GPUs. Full Windows workspace comparison: baseline 1080/3/46, candidate 1082/1/46; both have the same 26 explicit skips and shared CLAMP failure. The baseline's additional intermittent depth/stencil Close failure did not recur; I am not attributing that to this fix. Exact commands, hardware/drivers and limits are in the updated description; 314 source hashes matched before/after each run.

Retail smoke is still outstanding, so this remains draft. No gameplay or compilation-performance claim. Current update/testing/report assisted by Codex (GPT-6); original fix by Codex (GPT-6 Astra).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@WebIdentity1

WebIdentity1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

The bounded comparison supports retaining per-lane relative-register support, while acknowledging its translation overhead. I would consolidate #1961/#2037 around the compute-entry regression rather than refuse per-lane execution based on register-range cost alone. This is synthetic evidence, not a claim about representative game shaders.

Tested an isolated integration of #1961 4b4c111 on main cbc296a (preserving upstream Init fields), with a diagnostic fixture. Published head unchanged. Native Windows 10 / RTX 3090 driver 591.74, Ryzen 7800X3D, Rust 1.98.1, DXC 1.8.2502.11, debug. All 322 source hashes matched before/after/local.

  • Existing compute-entry regression: 1 passed / 0 failed / 0 ignored, zero skips, all 20 dispatches correct.
  • Cost fixture: 16 completed cases, each 1/0/0, zero skips; each checks 128 output words plus 16 guards on GPU.
  • HLSL bound 255 / eight pairs reached a 30-second whole-process limit before GPU; no timing or correctness result claimed. The larger HLSL case was not run.

Three-call warm translation medians, ms (bound is highest VGPR; pairs are repeated relative write/read pairs):

Bound / pairs Per-lane Direct DXIL HLSL + DXC
31 / 1 1.583 1.250 12.801
31 / 8 3.733 3.003 37.814
31 / 32 11.806 7.526 116.377
255 / 1 6.001 5.128 43.511
255 / 8 36.596 27.547 incomplete
255 / 32 121.152 108.670 not run

At the largest completed case, per-lane/direct DXIL were 103,388/104,980 bytes and both produced correct GPU output. Timings exclude explicit validation and GPU work; debug, fixed order, no production speedup claim.

No full integrated workspace suite, AMD rerun, retail smoke, memory or GPU-throughput measurement. Remains draft; #2037's retail blocks cannot qualify a different #1961 head. AI assistance: Codex (GPT-6).

Exact method, limitations and diagnostic patch

Relative-register bridge: current-main cost decision

Retaining the full per-lane bridge remains reasonable in this bounded synthetic comparison. It costs more translation time than the direct path, but all six per-lane cases completed with correct GPU output; refusing per-lane execution is not justified by these fixtures alone. This does not establish game-wide performance or an upper bound for arbitrary shaders.

Source: main cbc296ab65a2661a61e3e2da109134bcd5319f60 + the existing #1961 patch from 4b4c111098a3b22e21dce00d41bc95ab3c11da8e, with the kernel Init conflict resolved by preserving upstream slots/mem alongside max_vgpr. Added diagnostic fixture only. Published #1961 head remains unchanged. This does not test #2037's head or its automatic fallback routing.

Tested: native Windows 10 Home build 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74 / 32.0.15.9174, Rust/Cargo 1.98.1 MSVC, SDK DXC/DXIL 1.8.2502.11, debug. Actual selected adapter printed NVIDIA GeForce RTX 3090. Build cargo test --locked -p xcl --lib --no-run --message-format=json succeeded. All 322 source hashes match before/after and local snapshot. Exact binary SHA256: 7897947141b6e13bd932eb521b43f72615e22d59c587087317d81d1b8707c686.

  • Existing compute-entry regression: 1 passed / 0 failed / 0 ignored, zero SKIPPED; all 20 dispatches checked all 64 output words (direct/per-lane, native32/split64, four move forms and inactive lanes).
  • Cost probe: 16 completed case processes, each 1 passed / 0 failed / 0 ignored, zero SKIPPED. Each dispatched one native-wave32, 64-thread compute group, checking 64 updated registers + 64 untouched high-register values + 16 tail guards. The read/write chains depend on runtime M0=2 and evolving per-lane values.
  • One additional HLSL case (bound255, eight pairs) was deliberately terminated at the 30-second whole-process limit. Last marker was phase=translation, before GPU dispatch. That region contains the first translation, explicit DXIL validation and three warm translations: the logs cannot identify which call was still active. No timing or GPU correctness result is claimed for it. HLSL bound255/pairs32 was not run after this limit. Intermediate bound127 was not needed for the decision and was not run.

Warm translation medians in milliseconds (three calls, after one reference call; every timed DXIL byte-identical to the reference):

Highest VGPR Write/read pairs Per-lane Direct DXIL HLSL + DXC
31 1 1.583 1.250 12.801
31 8 3.733 3.003 37.814
31 32 11.806 7.526 116.377
255 1 6.001 5.128 43.511
255 8 36.596 27.547 incomplete
255 32 121.152 108.670 not run

The largest completed per-lane/direct outputs were 103,388 / 104,980 DXIL bytes, respectively; both produced correct GPU output. Compilation clocks exclude explicit DXIL validation, pipeline creation, dispatch and readback. Debug measurements, one process per case, fixed order, no production speedup claim. HLSL calls include text emission and DXC; direct API includes its own lowering machinery. No separate phase attribution, GPU throughput or memory measurement.

Reproduce diagnostic: use the supplied integration patch on cbc296a, build with the command above, then select one case per fresh process. Set XCL_ADAPTER=3090, XCL_DIRECT_COMPACT=0, XCL_REL_BOUND=31 or 255, XCL_REL_PAIRS=1, 8 or 32, XCL_REL_BACKEND=per-lane, direct or hlsl; unset XCL_REQUIRE_GPU, XCL_DIRECT_DXIL, XCL_SPLIT_WAVE64. Run the built library test executable with --exact gpu::recomp::lower_dxil::tests::relative_registers_bridge_cost --test-threads=1 --nocapture. Existing regression uses gpu::recomp::lower_dxil::tests::relative_registers_reach_compute_output instead. Fixture uses a 64MiB test-owned thread stack. Env selection is diagnostic scaffolding, not proposed permanent full-suite test behavior.

Harness provenance: the initial buffered two-test attempt was deliberately stopped without claiming results; retained under attempt1-buffered. Initial streamed completed cases have null individual ExitCode metadata due to losing the Process handle after Refresh, but terminal wait and passing test summaries are preserved. Retaining the handle was verified with cmd exit7; all 13 completed later cases recorded exit0, the time-limited case exit-1. All three scheduled wrappers finished0. No inference from wrapper0 that the limited case passed.

Recommendation: consolidate #1961/#2037 around the actual compute-entry regression, preserve per-lane support unless representative shader evidence demonstrates unacceptable cost, and keep this diagnostic out of the permanent full suite. No additional cost grid or speculative rewrite is needed for this decision. A future narrowly scoped optimization could avoid exporting the whole VGPR range for a fixed-destination relative read, but it is neither implemented nor claimed beneficial here.

Not tested: full current-main integrated workspace suite, AMD on this integration, native64 on this integration, retail smoke/gameplay, arbitrary live-register pressure/divergent programs, production release timings, memory, cold PSO or GPU throughput. Earlier #1961 AMD/full-suite results remain results of their exact older snapshot. Retail smoke from #2037 cannot qualify a different #1961 head. Still draft, not merge-ready.

AI assistance: Codex (GPT-6), integration, synthetic fixture, native testing and report.

Exact local integration and diagnostic patch against cbc296a
diff --git a/README.md b/README.md
index bdb2076..b246a3f 100644
--- a/README.md
+++ b/README.md
@@ -141,6 +141,8 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
 - **The game folder is never modified** – writes go to the overlay.
 - Translated shaders are reused across XCL rebuilds when the translator sources and DXC
   toolchain are unchanged; `XCL_TRANSLATED_CACHE=0` disables that disk cache.
+- Direct DXIL (`XCL_DIRECT_DXIL=1`), including per-lane compute (`XCL_PER_LANE=1`),
+  preserves relative VGPR moves to registers first used later in the program.
 - Huge pipelines (translated DXIL of `XCL_HUGE_PSO_BYTES` or more, default 262144) built on the
   background `xcl-pso*` workers take turns in the driver's compiler: `XCL_HUGE_PSO_CONCURRENCY`
   at once (default 1, maximum 64). Pipelines of 4 MiB or more use a separate one-wide lane so
diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs
index 94ce0b3..2eeb238 100644
--- a/crates/xcl/src/gpu/dxil/kernel.rs
+++ b/crates/xcl/src/gpu/dxil/kernel.rs
@@ -450,10 +450,20 @@ impl Lw {
         let (mems, heap_mem) = mem_windows(&mut s, o.mem_windows, cs.is_some());
         let i32 = s.m.i32();
         let z = s.m.i32c(0);
+        // Only relative instructions need a register-file bound; avoid the operand
+        // scan for the common case that never indexes a register dynamically.
+        let relative = insts.iter().any(|d| d.inst.name.starts_with("V_MOVREL") || d.inst.name == "V_SWAPREL_B32");
+        let max_vgpr = if relative {
+            insts.iter().flat_map(|d| {
+                let (r, w) = crate::gpu::rdna2::vgpr_uses(d);
+                r.into_iter().chain(w)
+            }).filter(|&r| r < 256).max().unwrap_or(0)
+        } else { 0 };
         let mut lw = Lw {
             s,
             ssa: Ssa::new(i32),
             init: Init { io: Some(io), compute: None, vgpr_base: None, entry: Block(0), touched: BTreeSet::new(), slots: HashMap::new(), mem: None },
+            max_vgpr,
             wave64: o.wave64,
             split,
             lane: z,
diff --git a/crates/xcl/src/gpu/dxil/lower.rs b/crates/xcl/src/gpu/dxil/lower.rs
index 0e270bb..e682884 100644
--- a/crates/xcl/src/gpu/dxil/lower.rs
+++ b/crates/xcl/src/gpu/dxil/lower.rs
@@ -169,6 +169,8 @@ pub struct Lw {
     pub s: Shader,
     pub ssa: Ssa,
     pub init: Init,
+    /// Highest register named anywhere in this program, independent of lowering order.
+    pub max_vgpr: u64,
     pub wave64: bool,
     /// wave64 program in two hardware wave32 halves
     pub split: bool,
diff --git a/crates/xcl/src/gpu/dxil/lower_wide.rs b/crates/xcl/src/gpu/dxil/lower_wide.rs
index 3927a90..28b2d95 100644
--- a/crates/xcl/src/gpu/dxil/lower_wide.rs
+++ b/crates/xcl/src/gpu/dxil/lower_wide.rs
@@ -267,7 +267,7 @@ impl Lw {
 
     /// The highest VGPR the program names (relative moves index up to it).
     fn top_vgpr(&self) -> u64 {
-        self.init.touched.iter().filter(|&&v| (VAR_VGPR..VAR_VGPR + 256).contains(&v)).map(|&v| (v - VAR_VGPR) as u64).max().unwrap_or(0)
+        self.max_vgpr
     }
 
     pub fn movrel(&mut self, d: &Decoded, name: &str) -> LResult<()> {
diff --git a/crates/xcl/src/gpu/recomp/lower.rs b/crates/xcl/src/gpu/recomp/lower.rs
index ca82cf4..6a9fe71 100644
--- a/crates/xcl/src/gpu/recomp/lower.rs
+++ b/crates/xcl/src/gpu/recomp/lower.rs
@@ -186,6 +186,7 @@ struct Lower<'a, I: Ir> {
     noted: Option<Vec<String>>,
     /// a VS / PS (`lower_graphics`): `s_wqm` only of the launch EXEC (its quads' helper lanes)
     graphics: bool,
+    max_vgpr: u16,
 }
 
 /// A vector memory store: a side effect inactive lanes must not have.
@@ -1266,6 +1267,7 @@ fn lower_with<I: Ir>(insts: &[Decoded], stage: Stage, wave64: bool, mut ir: I, s
         dpp_en: None,
         noted: survey.then(Vec::new),
         graphics,
+        max_vgpr: 0,
     };
     // the registers the program names, and the ones the runner reads back
     let mut sregs: Vec<u8> = vec![VCC, VCC + 1, 124, EXEC, EXEC + 1];
@@ -1281,6 +1283,11 @@ fn lower_with<I: Ir>(insts: &[Decoded], stage: Stage, wave64: bool, mut ir: I, s
     sregs.dedup();
     vregs.sort_unstable();
     vregs.dedup();
+    l.max_vgpr = vregs.iter().copied().filter(|&v| v < 256).max().unwrap_or(0);
+    if insts.iter().any(|d| d.inst.name.starts_with("V_MOVREL") || d.inst.name == "V_SWAPREL_B32") {
+        // Relative addressing can touch gaps between explicitly named registers too.
+        vregs = (0..=l.max_vgpr).collect();
+    }
 
     // prologue: the SGPRs from `io` (kernel: the whole register file; compute: the user data)
     l.ir.at(0);
@@ -1676,7 +1683,13 @@ impl<I: Ir> Lower<'_, I> {
             inputs.push((Var::Scc, s));
         }
         // VGPRs read, and the ones written (a write keeps the old value where the guard is off)
-        let (vr, vw) = rdna2::vgpr_uses(d);
+        let (mut vr, mut vw) = rdna2::vgpr_uses(d);
+        if name.starts_with("V_MOVREL") || name == "V_SWAPREL_B32" {
+            // The foreign lowering indexes dynamically; transfer the whole possible
+            // register range in both directions, including inactive-lane values.
+            vr = (0..=self.max_vgpr as u64).collect();
+            vw = vr.clone();
+        }
         let mut vregs: Vec<u16> = vr.iter().chain(&vw).map(|&v| v as u16).collect();
         vregs.sort_unstable();
         vregs.dedup();
diff --git a/crates/xcl/src/gpu/recomp/lower_dxil.rs b/crates/xcl/src/gpu/recomp/lower_dxil.rs
index 2c200c7..fe930d9 100644
--- a/crates/xcl/src/gpu/recomp/lower_dxil.rs
+++ b/crates/xcl/src/gpu/recomp/lower_dxil.rs
@@ -436,6 +436,117 @@ mod tests {
         true
     }
 
+    #[test]
+    fn relative_registers_reach_compute_output() {
+        const WRITE: &[I] = &[("V_MOVRELD_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 170)])];
+        const READ: &[I] = &[
+            ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 170)]),
+            ("V_MOVRELS_B32", "ENC_VOP1", &[("VDST", 6), ("SRC0", V + 1)]),
+        ];
+        const BOTH: &[I] = &[
+            ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 170)]),
+            ("V_MOVRELSD_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", V + 1)]),
+        ];
+        const SEPARATE: &[I] = &[
+            ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 170)]),
+            ("V_MOVRELSD_2_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", V + 1)]),
+        ];
+        const MASKED: &[I] = &[
+            ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 135)]),
+            ("V_CMPX_GT_U32", "ENC_VOPC", &[("SRC0", 144), ("VSRC1", 0)]),
+            ("V_MOVRELD_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 170)]),
+            ("S_MOV_B64", "ENC_SOP1", &[("SDST", 126), ("SSRC0", 193)]),
+        ];
+        if !gpu() { return; }
+        println!("relative registers GPU: {}", runner::adapter().unwrap());
+        let mut modes = vec![(false, false), (true, true)];
+        if runner::wave64_supported() == Ok(true) { modes.push((true, false)); }
+        let cs = compute_cs();
+        let mut failures = Vec::new();
+        for (name, ops, result, m0) in [
+            ("write-before-use", WRITE, 3, 2), ("read", READ, 6, 2),
+            ("read-write", BOTH, 6, 2), ("separate-offsets", SEPARATE, 7, 0x30002),
+            ("inactive-lanes", MASKED, 3, 2),
+        ] {
+            let mut code = encode_line(&("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 0)]));
+            code.extend(ops.iter().flat_map(encode_line));
+            code.extend(encode_line(&("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 10), ("SRC0", 130), ("VSRC1", 0)])));
+            code.extend(encode_line(&("V_MOV_B32", "ENC_VOP1", &[("VDST", 11), ("SRC0", 128)])));
+            code.extend(crate::gpu::rdna2::encode("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 10), ("DATA", result), ("SADDR", 125), ("OFFSET", 0)], None).unwrap());
+            code.extend(encode_line(&ENDPGM));
+            for &(wave64, split) in &modes {
+                let opts = crate::gpu::dxil::kernel::KernelOptions { wave64, split, mem_windows: 1, sampler_base: 0 };
+                let direct = crate::gpu::dxil::kernel::translate_compute(&code, opts, &cs).unwrap().dxil;
+                let per_lane = super::compute_with(&code, &cs, opts).unwrap().dxil;
+                for (backend, dxil) in [("direct", direct), ("per-lane", per_lane)] {
+                    let got = runner::dispatch(&dxil, [1, 1, 1], &[m0, 0], &vec![0u32; 64]).unwrap();
+                    let bad = got[..64].iter().enumerate().filter(|&(lane, &v)| v != if name == "inactive-lanes" && lane >= 16 { 7 } else { 42 }).count();
+                    println!("{name}, {backend}, wave64={wave64}, split={split}: {bad}/64 mismatches");
+                    if bad != 0 { failures.push((name, backend, wave64, split)); }
+                }
+            }
+        }
+        assert!(failures.is_empty(), "relative register mismatches: {failures:?}");
+    }
+
+
+    /// Quantify the full-range bridge against the two existing fallback translation paths.
+    #[test]
+    fn relative_registers_bridge_cost() {
+        if !gpu() { return; }
+        println!("RELATIVE_COST_GPU={}", runner::adapter().unwrap());
+        std::thread::Builder::new().stack_size(64 << 20).spawn(|| {
+            let cs = compute_cs();
+            for bound in [31u64, 127, 255].into_iter().filter(|v| std::env::var("XCL_REL_BOUND").unwrap() == v.to_string()) {
+                for repeats in [1usize, 8, 32].into_iter().filter(|v| std::env::var("XCL_REL_PAIRS").unwrap() == v.to_string()) {
+                    let mut code = encode_line(&("S_MOV_B32", "ENC_SOP1", &[("SDST", 124), ("SSRC0", 0)]));
+                    code.extend(encode_line(&("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 255), ("VSRC1", 0), ("LITERAL", 100)])));
+                    code.extend(encode_line(&("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 2), ("SRC0", 130), ("VSRC1", 0)])));
+                    for _ in 0..repeats {
+                        code.extend(encode_line(&("V_MOVRELD_B32", "ENC_VOP1", &[("VDST", 16), ("SRC0", V + 1)])));
+                        code.extend(encode_line(&("V_MOVRELS_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", V + 16)])));
+                        code.extend(encode_line(&("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 129), ("VSRC1", 3)])));
+                    }
+                    code.extend(encode_line(&("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 128)])));
+                    for (data, offset) in [(18, 0), (bound, 256)] {
+                        code.extend(crate::gpu::rdna2::encode("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 2), ("DATA", data), ("SADDR", 125), ("OFFSET", offset)], None).unwrap());
+                    }
+                    code.extend(encode_line(&ENDPGM));
+                    let o = crate::gpu::dxil::kernel::KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 };
+                    for backend in ["per-lane", "direct", "hlsl"].into_iter().filter(|v| std::env::var("XCL_REL_BACKEND").unwrap() == *v) {
+                        let compile = || match backend {
+                            "per-lane" => super::compute_with(&code, &cs, o).unwrap().dxil,
+                            "direct" => crate::gpu::dxil::kernel::translate_compute(&code, o, &cs).unwrap().dxil,
+                            _ => {
+                                let t = translate(&code, &Options { mode: Mode::Compute(cs.clone()), wave64: false, mem_windows: 1, ..Default::default() }).unwrap();
+                                assert!(t.complete(), "{:?}", t.unsupported_why);
+                                dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap()
+                            }
+                        };
+                        println!("RELATIVE_STAGE backend={backend} bound={bound} pairs={repeats} phase=translation");
+                        let dxil = compile();
+                        crate::gpu::dxil::validate::validate(&dxil).unwrap();
+                        let mut compile_ms = Vec::new();
+                        for _ in 0..3 {
+                            let start = std::time::Instant::now();
+                            let again = compile();
+                            compile_ms.push(start.elapsed().as_secs_f64() * 1000.0);
+                            assert_eq!(again, dxil);
+                        }
+                        println!("RELATIVE_STAGE backend={backend} bound={bound} pairs={repeats} phase=gpu dxil_bytes={} compile_ms={compile_ms:?}", dxil.len());
+                        let got = runner::dispatch(&dxil, [1, 1, 1], &[2, 0], &vec![0xdeadbeef; 144]).unwrap();
+                        for lane in 0..64 {
+                            assert_eq!(got[lane], 100 + lane as u32 + repeats as u32 - 1, "{backend} bound={bound} repeats={repeats} lane={lane}");
+                            assert_eq!(got[64 + lane], 0, "untouched high register");
+                        }
+                        assert!(got[128..].iter().all(|&v| v == 0xdeadbeef), "tail guard");
+                        println!("RELATIVE_COST backend={backend} bound={bound} pairs={repeats} dxil_bytes={} compile_ms={compile_ms:?} output_words=128 guard_words=16", dxil.len());
+                    }
+                }
+            }
+        }).unwrap().join().unwrap();
+    }
+
     /// A rounding mode #1426's lowering cannot honour refuses the program, as #1426 and the HLSL
     /// path do, instead of the per-lane form computing with the default mode (Kalmarv, #1745):
     /// f32 toward zero by `s_setreg`, f64 by `s_round_mode` and by `s_setreg`.

Use a program-wide register bound and transfer possible relative values through the per-lane bridge, retaining register gaps and inactive lanes. Integrate on current main while preserving its initialization state and source-hashed cache.

The compute regression passes 20 RTX 3090 and 30 AMD dispatches. Paired workspace runs retain the same CLAMP failure; retail smoke remains outstanding.
@WebIdentity1
WebIdentity1 force-pushed the codex/nov24-relative-vgpr-current branch from 4b4c111 to 1bb18a9 Compare November 25, 2026 04:21
@WebIdentity1

Copy link
Copy Markdown
Contributor Author

Updated #1961 to 1bb18a942c6c9d7f18b4d0079c3209c1f9fafeae on current main cbc296a; GitHub now reports it merges without conflicts. The diagnostic cost probe is excluded, and the previous published head is preserved locally.

Paired native workspace qualification: 1152/3/46 → 1154/1/46 (passed/failed/ignored), identical 27 explicit skip notices. The remaining CLAMP failure is shared; the baseline-only intermittent d32s8 failure is not credited to this change. The existing compute regression passes 20 RTX 3090 and 30 AMD dispatches, including native wave64; all 322 source hashes match. Details and exact commands are in the refreshed PR description.

@IAmTheSween, following your offer to help consolidate with a retail smoke run: this is the clean current-main revision to test if that offer still stands. A matched main/head smoke pair would close the missing retail evidence; the bounded compile-cost comparison supports retaining per-lane execution in those synthetic cases, without claiming a game-scale performance result. No new competing PR.

The draft remains open: its description check fails specifically for the two missing smoke blocks, and CI reports action_required rather than a completed test run. AI assistance: Codex (GPT-6), integration and native validation.

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 1bb18a9 integrated locally onto 0829441. The sole merge conflict was in the README. Keeping both notes was enough to build and test the integration.

  • The stock relative-register test completed all 20 dispatches on the RTX 3080 Ti. All 64 output words matched in each dispatch, including the inactive-lane case, across Direct DXIL and the per-lane path.
  • The workspace built and reported 1,273 passed, 0 failed and 46 ignored, including 26 runtime skips.
  • LLVM MC 23.1.6 assembled the four relative-move forms for gfx1030. The integrated XCL disassembler decoded all four with the expected operands.

RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC and DXC 1.8.2502.11. Synthetic tests only. AI-assisted. Codex (GPT-6, exact variant unavailable) resolved the local conflict, ran the tests and drafted this report.

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