From 39ec915a79f2e018bd50ed1a2ce8ad6422664631 Mon Sep 17 00:00:00 2001 From: John Howard <49204095+Royalflamejlh@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:12:46 -0700 Subject: [PATCH 1/3] Recompiler: the compact form's larger tables on every GPU again This takes out e964ad2, which kept the table limit of 8,192 words on a GPU with 64-lane waves. It was added after a run on an RX 9070 XT at cbc296a, where neither form of the program it let in built within 24 GB and the compact form reached that sooner. Since #2174 the compact form nests its dispatch by default. On RX 9070 XTs with heap memory windows that program's nested compact form built in 138 to 203 s, at 17.6 GB on a 32 GB machine and 33.9 GB on a 64 GB one, where the plain form the guard kept passed 24 and 48 GB (bielfreedom on #2375, komglebissarov on #2088). With the default switch windows neither form built within 24 GB. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/dxil/compact.rs | 8 ++--- crates/xcl/src/gpu/dxil/compact_tests.rs | 44 +++++++----------------- crates/xcl/src/gpu/dxil/kernel.rs | 28 ++++++--------- crates/xcl/src/gpu/recomp/pso.rs | 2 +- 4 files changed, 27 insertions(+), 55 deletions(-) diff --git a/crates/xcl/src/gpu/dxil/compact.rs b/crates/xcl/src/gpu/dxil/compact.rs index b5d615a297..f8dfe6a544 100644 --- a/crates/xcl/src/gpu/dxil/compact.rs +++ b/crates/xcl/src/gpu/dxil/compact.rs @@ -22,9 +22,7 @@ pub struct Plan { } /// Most 32-bit words of tables a program may need to take the form by itself. -pub const TABLE_WORDS: usize = 8192; -/// `TABLE_WORDS` on a GPU that runs only 32-lane waves. -pub const TABLE_WORDS_WAVE32: usize = 12288; +const MAX_TABLE_WORDS: usize = 12288; impl Plan { /// Bits of a table entry: the class, and the taken successor or the index of the pair of offsets. @@ -40,11 +38,11 @@ impl Plan { } /// Whether a program takes the form by itself: large, mostly repeated blocks, small tables. -pub fn wanted(cfg: &Cfg, p: &Plan, tables: usize) -> bool { +pub fn wanted(cfg: &Cfg, p: &Plan) -> bool { let insts = |n: usize| cfg.blocks[p.order[n]].insts.len(); let all: usize = (0..p.order.len()).map(insts).sum(); let once: usize = p.rep.iter().map(|&n| insts(n)).sum(); - large(cfg) && once * 10 < all * 3 && p.words() <= tables + large(cfg) && once * 10 < all * 3 && p.words() <= MAX_TABLE_WORDS } /// Whether a program is large enough for `wanted` to be asked. diff --git a/crates/xcl/src/gpu/dxil/compact_tests.rs b/crates/xcl/src/gpu/dxil/compact_tests.rs index 7602b5da43..5b278ebb40 100644 --- a/crates/xcl/src/gpu/dxil/compact_tests.rs +++ b/crates/xcl/src/gpu/dxil/compact_tests.rs @@ -169,7 +169,16 @@ fn a_mask_read_whole_after_one_copy_only_splits_the_class() { assert_ne!(p.class[0], p.class[2]); } -fn two_segments(copies: usize) -> Vec { +#[test] +fn gpu_compact_inline_table_above_old_cap_checks_late_entries() { + if compact_mode().is_some() { + return; + } + match (runner::adapter(), runner::wave64_programs_supported(), crate::gpu::recomp::dxc::location()) { + (Ok(_), Ok(true), Ok(_)) => {} + (a, _, d) => return runner::skip_test(if a.is_err() { "no GPU" } else if d.is_err() { "no DXC" } else { "no wave64" }), + } + const COPIES: usize = 8192; let i = |n: &str, e: &str, f: &[(&str, u64)]| encode(n, e, f, None).unwrap_or_else(|x| panic!("{n}: {x}")); let mut code = Vec::new(); code.extend(i("S_MOV_B32", "ENC_SOP1", &[("SDST", 2), ("SSRC0", 2)])); @@ -177,50 +186,23 @@ fn two_segments(copies: usize) -> Vec { code.extend(i("V_MOV_B32", "ENC_VOP1", &[("VDST", r), ("SRC0", 256 + r)])); } for marker in [3, 4] { - for k in 0..copies { + for k in 0..COPIES { code.extend(i("S_ADD_U32", "ENC_SOP2", &[("SDST", 0), ("SSRC0", 0), ("SSRC1", 1)])); code.extend(i("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 256), ("VSRC1", 1)])); - let offset = (copies - 1 - k) * 3 + 1; + let offset = (COPIES - 1 - k) * 3 + 1; assert!(offset <= i16::MAX as usize); code.extend(i("S_CBRANCH_SCC1", "ENC_SOPP", &[("SIMM16", offset as u64)])); } code.extend(i("S_MOV_B32", "ENC_SOP1", &[("SDST", marker), ("SSRC0", 129)])); } code.extend(i("S_ENDPGM", "ENC_SOPP", &[])); - code -} - -#[test] -fn a_gpu_with_64_lane_waves_keeps_the_first_table_limit() { - if compact_mode().is_some() { - return; - } - let code = two_segments(8192); - let o = KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 }; - let cs = crate::gpu::recomp::CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [false; 3], tg_size: false, tid_components: 1 }; - let size = |wave32_only| super::kernel::translate_compute_on(&code, o, &cs, wave32_only).unwrap().dxil.len(); - let (compact, plain) = (size(true), size(false)); - assert!(compact * 20 < plain, "{compact} B on a GPU with 32-lane waves only, {plain} B on one with 64-lane waves"); -} - -#[test] -fn gpu_compact_inline_table_above_old_cap_checks_late_entries() { - if compact_mode().is_some() { - return; - } - match (runner::adapter(), runner::wave64_programs_supported(), crate::gpu::recomp::dxc::location()) { - (Ok(_), Ok(true), Ok(_)) => {} - (a, _, d) => return runner::skip_test(if a.is_err() { "no GPU" } else if d.is_err() { "no DXC" } else { "no wave64" }), - } - const COPIES: usize = 8192; - let code = two_segments(COPIES); let o = KernelOptions { wave64: true, split: runner::split_wave64(), mem_windows: 1, sampler_base: 0 }; let cfg = super::cfg::Cfg::build(&code).unwrap(); let leaders = cfg.blocks.iter().filter_map(|b| b.insts.first().map(|&i| cfg.insts[i].pc)).collect(); let lw = super::lower::Lw::new(&cfg.insts, &leaders, o, &super::kernel::Entry::Kernel); let p = super::compact::plan(&cfg, &lw).unwrap(); assert!(p.inline && p.words() > 8192 && p.words() <= 12288); - assert!(super::compact::wanted(&cfg, &p, super::compact::TABLE_WORDS_WAVE32)); + assert!(super::compact::wanted(&cfg, &p)); let k = translate_full(&code, o).unwrap(); for initial in [0u32, u32::MAX - 1, 0u32.wrapping_sub(COPIES as u32), 0u32.wrapping_sub((2 * COPIES) as u32), 0u32.wrapping_sub(COPIES as u32 + 1)] { let mut st = KernelState::default(); diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index 6ef85ad800..064149f42b 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -91,39 +91,39 @@ pub fn compact_nest_tag() -> Option { /// `translate_full` in the compact form (`compact = true`) or the plain one. #[cfg(test)] pub fn translate_full_as(code: &[u8], o: KernelOptions, compact: bool) -> Result { - translate_entry(code, o, Entry::Kernel, Some(compact), None, super::compact::TABLE_WORDS_WAVE32) + translate_entry(code, o, Entry::Kernel, Some(compact), None) } /// `translate_full` in the compact form with an explicit dispatch nesting policy. #[cfg(test)] pub fn translate_full_nested(code: &[u8], o: KernelOptions, nest: super::compact::Nest) -> Result { - translate_entry(code, o, Entry::Kernel, Some(true), Some(nest), super::compact::TABLE_WORDS_WAVE32) + translate_entry(code, o, Entry::Kernel, Some(true), Some(nest)) } pub fn translate_full(code: &[u8], o: KernelOptions) -> Result { - translate_entry(code, o, Entry::Kernel, compact_mode(), None, super::compact::TABLE_WORDS_WAVE32) + translate_entry(code, o, Entry::Kernel, compact_mode(), None) } /// A mesh-mode (NGG) program: the first pass that writes one record per group into /// `res` (the recompiler's `Mode::Mesh`; the pass-through mesh shader draws them). pub fn translate_mesh(code: &[u8], o: KernelOptions, ms: &MsInterface) -> Result { - translate_entry(code, o, Entry::Mesh(ms.clone()), None, None, 0) + translate_entry(code, o, Entry::Mesh(ms.clone()), None, None) } /// A vertex shader (the recompiler's `Mode::Vertex`; wave-size independent). pub fn translate_vertex(code: &[u8], o: KernelOptions, vs: &VsInterface) -> Result { - translate_entry(code, o, Entry::Vertex(vs.clone()), None, None, 0) + translate_entry(code, o, Entry::Vertex(vs.clone()), None, None) } /// A pixel shader (the recompiler's `Mode::Pixel`; wave-size independent). pub fn translate_pixel(code: &[u8], o: KernelOptions, ps: &PsInterface) -> Result { - translate_entry(code, o, Entry::Pixel(ps.clone()), None, None, 0) + translate_entry(code, o, Entry::Pixel(ps.clone()), None, None) } /// A geometry-mode (ES+GS) program: the compute pass that writes one mesh record per /// group of 21 triangles into `res` (the recompiler's `Mode::Geometry`). Always wave64. pub fn translate_geometry(code: &[u8], o: KernelOptions, g: &GsInterface) -> Result { - translate_entry(code, KernelOptions { wave64: true, ..o }, Entry::Geometry(g.clone()), None, None, 0) + translate_entry(code, KernelOptions { wave64: true, ..o }, Entry::Geometry(g.clone()), None, None) } /// The entry ABI. @@ -139,13 +139,7 @@ pub enum Entry { /// A compute-mode program (the CS ABI of `cs`). pub fn translate_compute(code: &[u8], o: KernelOptions, cs: &CsInterface) -> Result { - translate_compute_on(code, o, cs, true) -} - -/// `translate_compute` for a GPU: one that runs only 32-lane waves takes larger compact tables. -pub fn translate_compute_on(code: &[u8], o: KernelOptions, cs: &CsInterface, wave32_only: bool) -> Result { - let tables = if wave32_only { super::compact::TABLE_WORDS_WAVE32 } else { super::compact::TABLE_WORDS }; - translate_entry(code, o, Entry::Compute(cs.clone()), compact_mode(), None, tables) + translate_entry(code, o, Entry::Compute(cs.clone()), compact_mode(), None) } fn translate_entry( @@ -154,7 +148,6 @@ fn translate_entry( entry: Entry, compact: Option, nest: Option, - tables: usize, ) -> Result { // SSA construction recurses along the CFG (one level per guarded memory access between // a register's definition and its use): a thread with a large stack for big programs @@ -162,7 +155,7 @@ fn translate_entry( std::thread::Builder::new() .name("xcl-dxil-translate".into()) .stack_size(256 << 20) - .spawn(move || translate_on_this_thread(&code, o, entry, compact, nest, tables)) + .spawn(move || translate_on_this_thread(&code, o, entry, compact, nest)) .map_err(|e| format!("translator thread: {e}"))? .join() .map_err(|e| { @@ -192,7 +185,6 @@ fn translate_on_this_thread( entry: Entry, compact: Option, nest: Option, - tables: usize, ) -> Result { let geo = match &entry { Entry::Geometry(g) => Some(g.clone()), @@ -279,7 +271,7 @@ fn translate_on_this_thread( } let plan = if (compute || kernel) && compact.unwrap_or_else(|| super::compact::large(&cfg)) { super::compact::plan(&cfg, &lw) } else { None }; - let plan = plan.filter(|p| compact.unwrap_or_else(|| super::compact::wanted(&cfg, p, tables))); + let plan = plan.filter(|p| compact.unwrap_or_else(|| super::compact::wanted(&cfg, p))); if let Some(p) = &plan { crate::xlog_info!("[SHADER] direct DXIL compact form: {} blocks of {} kinds", p.order.len(), p.rep.len()); } diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index da4b25e5fb..57ac9af38d 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -969,7 +969,7 @@ fn direct_compute(blob: &[u8], sampler_base: u32, windows: u32, split_wave64: bo } } } - let k = crate::gpu::dxil::kernel::translate_compute_on(code, o, &cs, split_wave64)?; + let k = crate::gpu::dxil::kernel::translate_compute(code, o, &cs)?; dump_direct(blob, &k.dxil); Ok(Compiled { dispatch_chain: k.dispatch_chain, dxil: k.dxil, samplers: k.static_samplers }) } From 9975836e11bf26370b287b1a4dbd2714212d2146 Mon Sep 17 00:00:00 2001 From: John Howard <49204095+Royalflamejlh@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:43:34 -0700 Subject: [PATCH 2/3] Recompiler: the compact form's larger tables on a 64-lane GPU only with heap windows On a GPU with 64-lane waves the 12,288-word table limit now applies only with heap memory windows (XCL_HEAP_WINDOWS=1); with the default switch windows such a GPU keeps 8,192 words, as on main. Both AMD runs that built 95cc13288a27a96e's compact form on an RX 9070 XT used heap windows; with switch windows neither form built within 24 GB, and since #2120 that program takes the direct translator by default, so without this condition the previous commit changed the default path there. The test of the condition fails without it. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/dxil/compact.rs | 8 +++-- crates/xcl/src/gpu/dxil/compact_tests.rs | 44 +++++++++++++++++------- crates/xcl/src/gpu/dxil/kernel.rs | 28 +++++++++------ crates/xcl/src/gpu/recomp/pso.rs | 21 ++++++++++- 4 files changed, 74 insertions(+), 27 deletions(-) diff --git a/crates/xcl/src/gpu/dxil/compact.rs b/crates/xcl/src/gpu/dxil/compact.rs index f8dfe6a544..7d5b56366b 100644 --- a/crates/xcl/src/gpu/dxil/compact.rs +++ b/crates/xcl/src/gpu/dxil/compact.rs @@ -22,7 +22,9 @@ pub struct Plan { } /// Most 32-bit words of tables a program may need to take the form by itself. -const MAX_TABLE_WORDS: usize = 12288; +pub const TABLE_WORDS: usize = 8192; +/// `TABLE_WORDS` on a GPU that runs only 32-lane waves, or with heap memory windows. +pub const TABLE_WORDS_WAVE32: usize = 12288; impl Plan { /// Bits of a table entry: the class, and the taken successor or the index of the pair of offsets. @@ -38,11 +40,11 @@ impl Plan { } /// Whether a program takes the form by itself: large, mostly repeated blocks, small tables. -pub fn wanted(cfg: &Cfg, p: &Plan) -> bool { +pub fn wanted(cfg: &Cfg, p: &Plan, tables: usize) -> bool { let insts = |n: usize| cfg.blocks[p.order[n]].insts.len(); let all: usize = (0..p.order.len()).map(insts).sum(); let once: usize = p.rep.iter().map(|&n| insts(n)).sum(); - large(cfg) && once * 10 < all * 3 && p.words() <= MAX_TABLE_WORDS + large(cfg) && once * 10 < all * 3 && p.words() <= tables } /// Whether a program is large enough for `wanted` to be asked. diff --git a/crates/xcl/src/gpu/dxil/compact_tests.rs b/crates/xcl/src/gpu/dxil/compact_tests.rs index 5b278ebb40..7602b5da43 100644 --- a/crates/xcl/src/gpu/dxil/compact_tests.rs +++ b/crates/xcl/src/gpu/dxil/compact_tests.rs @@ -169,16 +169,7 @@ fn a_mask_read_whole_after_one_copy_only_splits_the_class() { assert_ne!(p.class[0], p.class[2]); } -#[test] -fn gpu_compact_inline_table_above_old_cap_checks_late_entries() { - if compact_mode().is_some() { - return; - } - match (runner::adapter(), runner::wave64_programs_supported(), crate::gpu::recomp::dxc::location()) { - (Ok(_), Ok(true), Ok(_)) => {} - (a, _, d) => return runner::skip_test(if a.is_err() { "no GPU" } else if d.is_err() { "no DXC" } else { "no wave64" }), - } - const COPIES: usize = 8192; +fn two_segments(copies: usize) -> Vec { let i = |n: &str, e: &str, f: &[(&str, u64)]| encode(n, e, f, None).unwrap_or_else(|x| panic!("{n}: {x}")); let mut code = Vec::new(); code.extend(i("S_MOV_B32", "ENC_SOP1", &[("SDST", 2), ("SSRC0", 2)])); @@ -186,23 +177,50 @@ fn gpu_compact_inline_table_above_old_cap_checks_late_entries() { code.extend(i("V_MOV_B32", "ENC_VOP1", &[("VDST", r), ("SRC0", 256 + r)])); } for marker in [3, 4] { - for k in 0..COPIES { + for k in 0..copies { code.extend(i("S_ADD_U32", "ENC_SOP2", &[("SDST", 0), ("SSRC0", 0), ("SSRC1", 1)])); code.extend(i("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 256), ("VSRC1", 1)])); - let offset = (COPIES - 1 - k) * 3 + 1; + let offset = (copies - 1 - k) * 3 + 1; assert!(offset <= i16::MAX as usize); code.extend(i("S_CBRANCH_SCC1", "ENC_SOPP", &[("SIMM16", offset as u64)])); } code.extend(i("S_MOV_B32", "ENC_SOP1", &[("SDST", marker), ("SSRC0", 129)])); } code.extend(i("S_ENDPGM", "ENC_SOPP", &[])); + code +} + +#[test] +fn a_gpu_with_64_lane_waves_keeps_the_first_table_limit() { + if compact_mode().is_some() { + return; + } + let code = two_segments(8192); + let o = KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 }; + let cs = crate::gpu::recomp::CsInterface { threads: [64, 1, 1], user_sgprs: 4, tgid: [false; 3], tg_size: false, tid_components: 1 }; + let size = |wave32_only| super::kernel::translate_compute_on(&code, o, &cs, wave32_only).unwrap().dxil.len(); + let (compact, plain) = (size(true), size(false)); + assert!(compact * 20 < plain, "{compact} B on a GPU with 32-lane waves only, {plain} B on one with 64-lane waves"); +} + +#[test] +fn gpu_compact_inline_table_above_old_cap_checks_late_entries() { + if compact_mode().is_some() { + return; + } + match (runner::adapter(), runner::wave64_programs_supported(), crate::gpu::recomp::dxc::location()) { + (Ok(_), Ok(true), Ok(_)) => {} + (a, _, d) => return runner::skip_test(if a.is_err() { "no GPU" } else if d.is_err() { "no DXC" } else { "no wave64" }), + } + const COPIES: usize = 8192; + let code = two_segments(COPIES); let o = KernelOptions { wave64: true, split: runner::split_wave64(), mem_windows: 1, sampler_base: 0 }; let cfg = super::cfg::Cfg::build(&code).unwrap(); let leaders = cfg.blocks.iter().filter_map(|b| b.insts.first().map(|&i| cfg.insts[i].pc)).collect(); let lw = super::lower::Lw::new(&cfg.insts, &leaders, o, &super::kernel::Entry::Kernel); let p = super::compact::plan(&cfg, &lw).unwrap(); assert!(p.inline && p.words() > 8192 && p.words() <= 12288); - assert!(super::compact::wanted(&cfg, &p)); + assert!(super::compact::wanted(&cfg, &p, super::compact::TABLE_WORDS_WAVE32)); let k = translate_full(&code, o).unwrap(); for initial in [0u32, u32::MAX - 1, 0u32.wrapping_sub(COPIES as u32), 0u32.wrapping_sub((2 * COPIES) as u32), 0u32.wrapping_sub(COPIES as u32 + 1)] { let mut st = KernelState::default(); diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index 064149f42b..c635e5ffc5 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -91,39 +91,39 @@ pub fn compact_nest_tag() -> Option { /// `translate_full` in the compact form (`compact = true`) or the plain one. #[cfg(test)] pub fn translate_full_as(code: &[u8], o: KernelOptions, compact: bool) -> Result { - translate_entry(code, o, Entry::Kernel, Some(compact), None) + translate_entry(code, o, Entry::Kernel, Some(compact), None, super::compact::TABLE_WORDS_WAVE32) } /// `translate_full` in the compact form with an explicit dispatch nesting policy. #[cfg(test)] pub fn translate_full_nested(code: &[u8], o: KernelOptions, nest: super::compact::Nest) -> Result { - translate_entry(code, o, Entry::Kernel, Some(true), Some(nest)) + translate_entry(code, o, Entry::Kernel, Some(true), Some(nest), super::compact::TABLE_WORDS_WAVE32) } pub fn translate_full(code: &[u8], o: KernelOptions) -> Result { - translate_entry(code, o, Entry::Kernel, compact_mode(), None) + translate_entry(code, o, Entry::Kernel, compact_mode(), None, super::compact::TABLE_WORDS_WAVE32) } /// A mesh-mode (NGG) program: the first pass that writes one record per group into /// `res` (the recompiler's `Mode::Mesh`; the pass-through mesh shader draws them). pub fn translate_mesh(code: &[u8], o: KernelOptions, ms: &MsInterface) -> Result { - translate_entry(code, o, Entry::Mesh(ms.clone()), None, None) + translate_entry(code, o, Entry::Mesh(ms.clone()), None, None, 0) } /// A vertex shader (the recompiler's `Mode::Vertex`; wave-size independent). pub fn translate_vertex(code: &[u8], o: KernelOptions, vs: &VsInterface) -> Result { - translate_entry(code, o, Entry::Vertex(vs.clone()), None, None) + translate_entry(code, o, Entry::Vertex(vs.clone()), None, None, 0) } /// A pixel shader (the recompiler's `Mode::Pixel`; wave-size independent). pub fn translate_pixel(code: &[u8], o: KernelOptions, ps: &PsInterface) -> Result { - translate_entry(code, o, Entry::Pixel(ps.clone()), None, None) + translate_entry(code, o, Entry::Pixel(ps.clone()), None, None, 0) } /// A geometry-mode (ES+GS) program: the compute pass that writes one mesh record per /// group of 21 triangles into `res` (the recompiler's `Mode::Geometry`). Always wave64. pub fn translate_geometry(code: &[u8], o: KernelOptions, g: &GsInterface) -> Result { - translate_entry(code, KernelOptions { wave64: true, ..o }, Entry::Geometry(g.clone()), None, None) + translate_entry(code, KernelOptions { wave64: true, ..o }, Entry::Geometry(g.clone()), None, None, 0) } /// The entry ABI. @@ -139,7 +139,13 @@ pub enum Entry { /// A compute-mode program (the CS ABI of `cs`). pub fn translate_compute(code: &[u8], o: KernelOptions, cs: &CsInterface) -> Result { - translate_entry(code, o, Entry::Compute(cs.clone()), compact_mode(), None) + translate_compute_on(code, o, cs, true) +} + +/// `translate_compute` with the compact form's larger tables (`compact::TABLE_WORDS_WAVE32`) or not. +pub fn translate_compute_on(code: &[u8], o: KernelOptions, cs: &CsInterface, large_tables: bool) -> Result { + let tables = if large_tables { super::compact::TABLE_WORDS_WAVE32 } else { super::compact::TABLE_WORDS }; + translate_entry(code, o, Entry::Compute(cs.clone()), compact_mode(), None, tables) } fn translate_entry( @@ -148,6 +154,7 @@ fn translate_entry( entry: Entry, compact: Option, nest: Option, + tables: usize, ) -> Result { // SSA construction recurses along the CFG (one level per guarded memory access between // a register's definition and its use): a thread with a large stack for big programs @@ -155,7 +162,7 @@ fn translate_entry( std::thread::Builder::new() .name("xcl-dxil-translate".into()) .stack_size(256 << 20) - .spawn(move || translate_on_this_thread(&code, o, entry, compact, nest)) + .spawn(move || translate_on_this_thread(&code, o, entry, compact, nest, tables)) .map_err(|e| format!("translator thread: {e}"))? .join() .map_err(|e| { @@ -185,6 +192,7 @@ fn translate_on_this_thread( entry: Entry, compact: Option, nest: Option, + tables: usize, ) -> Result { let geo = match &entry { Entry::Geometry(g) => Some(g.clone()), @@ -271,7 +279,7 @@ fn translate_on_this_thread( } let plan = if (compute || kernel) && compact.unwrap_or_else(|| super::compact::large(&cfg)) { super::compact::plan(&cfg, &lw) } else { None }; - let plan = plan.filter(|p| compact.unwrap_or_else(|| super::compact::wanted(&cfg, p))); + let plan = plan.filter(|p| compact.unwrap_or_else(|| super::compact::wanted(&cfg, p, tables))); if let Some(p) = &plan { crate::xlog_info!("[SHADER] direct DXIL compact form: {} blocks of {} kinds", p.order.len(), p.rep.len()); } diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index 57ac9af38d..57d0d35314 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -947,6 +947,11 @@ fn direct_fallback(stage: &str, err: &str) { /// A console compute shader through the direct DXIL translator (`gpu::dxil::kernel`). /// FSPX (driver) containers are left to the HLSL path. +/// Whether the compact form may take its larger tables: on a GPU with 32-lane waves only, or with heap memory windows. +fn large_tables(split_wave64: bool, windows: u32) -> bool { + split_wave64 || windows & super::HEAP_WINDOWS != 0 +} + fn direct_compute(blob: &[u8], sampler_base: u32, windows: u32, split_wave64: bool) -> Result { let sh = xbox::parse(blob).ok_or("not a console shader container")?; let f = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == 6)).ok_or("no hardware CS variant")?; @@ -969,7 +974,7 @@ fn direct_compute(blob: &[u8], sampler_base: u32, windows: u32, split_wave64: bo } } } - let k = crate::gpu::dxil::kernel::translate_compute(code, o, &cs)?; + let k = crate::gpu::dxil::kernel::translate_compute_on(code, o, &cs, large_tables(split_wave64, windows))?; dump_direct(blob, &k.dxil); Ok(Compiled { dispatch_chain: k.dispatch_chain, dxil: k.dxil, samplers: k.static_samplers }) } @@ -1381,6 +1386,20 @@ fn abi_signature(dev: &ID3D12Device, graphics: bool, samplers: &[StaticSampler], } } +#[cfg(test)] +mod large_table_tests { + use super::large_tables; + use crate::gpu::recomp::HEAP_WINDOWS; + + #[test] + fn a_gpu_with_64_lane_waves_takes_the_larger_tables_only_with_heap_windows() { + assert!(large_tables(true, 4)); + assert!(large_tables(true, 4 | HEAP_WINDOWS)); + assert!(large_tables(false, 4 | HEAP_WINDOWS)); + assert!(!large_tables(false, 4)); + } +} + #[cfg(test)] mod slab_tests { use super::dispatch_slabs; From 98b60d0876e5a29e60e4078d1ff4885eb1689d6e Mon Sep 17 00:00:00 2001 From: John Howard <49204095+Royalflamejlh@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:03:31 -0700 Subject: [PATCH 3/3] Recompiler: direct_compute keeps its own doc lines large_tables went in between direct_compute's doc comment and its fn. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/recomp/pso.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index 57d0d35314..c586c6a76b 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -945,13 +945,13 @@ fn direct_fallback(stage: &str, err: &str) { crate::xlog_info!("[SHADER] direct DXIL fallback stage={stage} reason=\"{reason}\" detail=\"{}\" – HLSL path", err.lines().next().unwrap_or("")); } -/// A console compute shader through the direct DXIL translator (`gpu::dxil::kernel`). -/// FSPX (driver) containers are left to the HLSL path. /// Whether the compact form may take its larger tables: on a GPU with 32-lane waves only, or with heap memory windows. fn large_tables(split_wave64: bool, windows: u32) -> bool { split_wave64 || windows & super::HEAP_WINDOWS != 0 } +/// A console compute shader through the direct DXIL translator (`gpu::dxil::kernel`). +/// FSPX (driver) containers are left to the HLSL path. fn direct_compute(blob: &[u8], sampler_base: u32, windows: u32, split_wave64: bool) -> Result { let sh = xbox::parse(blob).ok_or("not a console shader container")?; let f = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == 6)).ok_or("no hardware CS variant")?;