From f46ebd6280652057a9ed2ef377cd9c2103f58f70 Mon Sep 17 00:00:00 2001 From: b3IKK <278540256+b3IKK@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:58:12 +0000 Subject: [PATCH] Recompiler: XCL_RECOMP_NO_STRUCTURED picks the default, not an override The switch was read inside translate(), so it also overrode an explicit Options { structured: true }: three tests that assert what the structured form generates failed whenever a developer ran the suite with it set (as I did: 3 of 843), with output that reads like a regression in the translator rather than a configuration switch. Read it in Options::default() (the runtime asks for the default), where an explicit request then wins, and have the tests that check the structured form ask for it outright. Assisted-by: OpenCode (Gemini 4 Neon) --- crates/xcl/src/gpu/recomp/mod.rs | 8 ++++++-- crates/xcl/src/gpu/recomp/tests.rs | 13 ++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index fdaefc29ac..103915f476 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -514,7 +514,11 @@ pub struct Options { impl Default for Options { fn default() -> Self { - Options { mode: Mode::Kernel, wave64: true, hw_wave: 0, split_wave64: false, static_sampler_base: 0, mem_windows: 1, heap_windows: false, structured: true } + // `XCL_RECOMP_NO_STRUCTURED=1` (a debug switch): the guarded block chain by default. + // An explicit `structured: true` still asks for the structured form - a test that + // checks what it generates must not depend on the environment it runs in. + let structured = std::env::var_os("XCL_RECOMP_NO_STRUCTURED").is_none(); + Options { mode: Mode::Kernel, wave64: true, hw_wave: 0, split_wave64: false, static_sampler_base: 0, mem_windows: 1, heap_windows: false, structured } } } @@ -1485,7 +1489,7 @@ pub fn translate(code: &[u8], opt: &Options) -> Result { let mut code = String::new(); let nested = nested_loop_ranges(&insts); let sctx = Ctx { insts: &insts, starts: &starts, leaders: &leaders, loops: &nested, edges: &edges, phase_split, memo: Default::default() }; - if gs_jump.is_none() && opt.structured && std::env::var_os("XCL_RECOMP_NO_STRUCTURED").is_none() && structurable(&sctx, 0, u64::MAX).is_some() { + if gs_jump.is_none() && opt.structured && structurable(&sctx, 0, u64::MAX).is_some() { // structured control flow: plain if / loops, no block dispatch on `pc` (much // smaller for DXC and the driver on big programs) emit_structured(&sctx, &mut em, &mut code, 0, u64::MAX, None, 0, &Conts::default(), &BTreeSet::new(), 1, &mut blocks, &mut flags); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 55ef19082f..3a7fb344cb 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -188,7 +188,9 @@ fn hlsl_is_generated_for_straight_line_and_branches() { ("S_CBRANCH_SCC1", "ENC_SOPP", &[("SIMM16", 1)], None), ("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 128)], None), ]); - let t = translate(&code, &Options::default()).unwrap(); + // (the structured form asked for outright: `XCL_RECOMP_NO_STRUCTURED` only changes what + // `Options::default()` picks, and this asserts what the structured form generates) + let t = translate(&code, &Options { structured: true, ..Default::default() }).unwrap(); assert!(t.complete(), "{:?}", t.unsupported); assert_eq!(t.blocks, 3, "{}", t.hlsl); // forward branches only: a plain `if`, no loop and no block dispatch on pc @@ -205,10 +207,10 @@ fn hlsl_is_generated_for_straight_line_and_branches() { ("S_CBRANCH_SCC1", "ENC_SOPP", &[("SIMM16", 0xFFFD)], None), // back to s_sub ("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 128)], None), ]); - let t = translate(&code, &Options::default()).unwrap(); + let t = translate(&code, &Options { structured: true, ..Default::default() }).unwrap(); // only the range of the backward branch loops; its condition is the loop's exit test assert!(t.hlsl.contains("[loop] for (;;)") && t.hlsl.contains("break;") && !t.hlsl.contains("pc =="), "{}", t.hlsl); - let t = translate(&prog(&[("V_ADD_F32", "ENC_VOP2", &[("VDST", 1), ("SRC0", V + 2), ("VSRC1", 3)], None)]), &Options::default()).unwrap(); + let t = translate(&prog(&[("V_ADD_F32", "ENC_VOP2", &[("VDST", 1), ("SRC0", V + 2), ("VSRC1", 3)], None)]), &Options { structured: true, ..Default::default() }).unwrap(); assert!(!t.hlsl.contains("pc =="), "{}", t.hlsl); // unknown to the recompiler: reported, HLSL still produced let t = translate(&prog(&[("V_INTERP_P1_F32", "ENC_VINTRP", &[("VDST", 0), ("VSRC", 0), ("ATTR", 0)], None)]), &Options::default()).unwrap(); @@ -5778,7 +5780,7 @@ fn far_jumps_are_direct_branches() { let t = super::translate(&other, &Options::default()).unwrap(); assert!(!t.complete()); - let t = super::translate(&code, &Options::default()).unwrap(); + let t = super::translate(&code, &Options { structured: true, ..Default::default() }).unwrap(); assert!(t.complete(), "{:?}", t.unsupported); assert!(!t.hlsl.contains("pc =="), "far jump left the structured form:\n{}", t.hlsl); if !gpu_ready() { @@ -7618,7 +7620,8 @@ fn oversized_structured_code_falls_back_to_pc_blocks() { code.extend(i("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 0), ("VSRC1", 1)])); } code.extend(i("S_ENDPGM", "ENC_SOPP", &[])); - let t = translate(&code, &Options::default()).unwrap(); + // (the structured form asked for outright: the size bound is about what it generates) + let t = translate(&code, &Options { structured: true, ..Default::default() }).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); t.hlsl.contains("pc ==") };