Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down Expand Up @@ -1485,7 +1489,7 @@ pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
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);
Expand Down
13 changes: 8 additions & 5 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 ==")
};
Expand Down
Loading