From 5b31ca7808ef8e9cc566fcb88255e2af63d958d7 Mon Sep 17 00:00:00 2001 From: upipibi Date: Tue, 24 Nov 2026 17:48:55 -0600 Subject: [PATCH 1/2] Direct DXIL: TG_SIZE counts a partial last wave The direct translator set TG_SIZE's wave count to threads / lanes, so a group of 96 threads in wave64 read 1 wave where the console (and the HLSL path) give 2. It is now threads.div_ceil(lanes). The existing test gpu_compute_tg_size_counts_a_partial_last_wave now runs through direct_or, so XCL_DIRECT_DXIL=1 covers this path; it fails without the fix (left: 1, right: 2 for 96 threads in wave64). Found with #1934's XCL_DXIL_DIFF=1. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/dxil/kernel.rs | 4 ++-- crates/xcl/src/gpu/recomp/tests.rs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index d28a2ffcb..8c9c8c251 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -568,8 +568,8 @@ pub fn compute_init(lw: &mut Lw, cs: &CsInterface, tid: Value, gtid: [Value; 3]) let lanes: u32 = if lw.wave64 { 64 } else { 32 }; let total: u32 = cs.threads.iter().product(); if cs.tg_size { - // (threads / lanes) | (gi / lanes) << 6 - let w = lw.c(total / lanes); + // the group's wave count (a partial last wave counts) | (gi / lanes) << 6 + let w = lw.c(total.div_ceil(lanes)); let l = lw.c(lanes); let i = lw.bin(super::module::BinOp::UDiv, tid, l); let i = lw.shlc(i, 6); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index e1f73ef48..42a166551 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -6299,9 +6299,11 @@ fn gpu_compute_tg_size_counts_a_partial_last_wave() { for (threads, wave64) in [(96u32, true), (96, false), (64, true), (40, false), (128, true)] { let lanes = if wave64 { 64 } else { 32 }; let cs = super::CsInterface { threads: [threads, 1, 1], user_sgprs: 2, tgid: [false; 3], tg_size: true, tid_components: 1 }; - let t = translate(&p, &on_gpu(Options { mode: Mode::Compute(cs), wave64, ..Default::default() })).unwrap(); + let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64, ..Default::default() }); + let t = translate(&p, &opt).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); - let dxil = super::dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl)); + // `XCL_DIRECT_DXIL=1`: the direct translator's kernel, which sets up TG_SIZE on its own + let dxil = direct_or(&p, &opt, super::dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl))); let mem = runner::dispatch(&dxil, [1, 1, 1], &[0u32; 128], &vec![0xFFFF_FFFFu32; threads as usize]).unwrap(); let waves = threads.div_ceil(lanes); for (k, &got) in mem.iter().take(threads as usize).enumerate() { From 415fc5ef4307ccbdf1cb91c45bb1db5c0deba1e6 Mon Sep 17 00:00:00 2001 From: upipibi Date: Tue, 24 Nov 2026 17:53:43 -0600 Subject: [PATCH 2/2] Direct DXIL: TRANSLATOR_VERSION 8, so cached kernels pick up the TG_SIZE change Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/dxil/kernel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index 8c9c8c251..3b8c98449 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -37,7 +37,7 @@ pub struct KernelOptions { /// Version of the direct translator's output, part of the on-disk translation cache's /// identity (`recomp::pso`): bump it on any change that alters the emitted containers /// (the `gpu/dxil` sources are not in build.rs's translator source hash). -pub const TRANSLATOR_VERSION: u32 = 7; +pub const TRANSLATOR_VERSION: u32 = 8; /// `XCL_DIRECT_DXIL=1`: console compute shaders (and the kernel tests) go through this /// translator, with the HLSL path as the fallback for what it cannot translate yet.