Shaders: descriptors joined by nested control flow stay refused for now
Takes back PR #1012's recursive heap index (an edge into a descriptor's join that is itself a join). Across the title's shader list it lets one program through, `indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays` (issued every cutscene frame), and that program's host pipeline does not fit the machine: the DXIL validates in 4 s, but the AMD driver's compile passed 6 GB after 64 s under a watchdog (unwatched it reached 26.7 GB commit and starved a title run, drops2). Its DXIL has 22,382 branches, 2,609 heap handles and 2,478 size queries (151k lines), against 3,857 branches for the next largest newly emitted program, which compiles in 24 s and 0.8 GB. The refusal is "a descriptor chosen by control flow" again, as on `main`; edges no lane takes still join no heap index (previous commit). The change can come back once pipelines this costly stay off the title's pipeline worker (`shortcut:` at the arm). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e8e9f0c2ae
commit
fbac5bb64c
1 file changed
+34
-91
@@ -4970,10 +4970,41 @@ impl<'a> Lower<'a> {
|
||||
self.s.sampler_choices.push((ha, hb, phi));
|
||||
Ok(ha)
|
||||
}
|
||||
Source::Phi { .. } => {
|
||||
Source::Phi { block, args } => {
|
||||
// Each predecessor computes its heap index at its end; the
|
||||
// join picks one with a phi.
|
||||
// shortcut: an edge that is itself a join (if/else nested in
|
||||
// another) stays refused: the one program it would let
|
||||
// through, `indirect_diffuse_lighting:CS_ScreenProbes_
|
||||
// ActivateRays` (22k branches, 2.6k heap handles), takes the
|
||||
// AMD driver over 6 GB and a minute to compile (PR #1012 did
|
||||
// it; take it once pipelines that costly stay off the title's
|
||||
// pipeline worker).
|
||||
let _ = site;
|
||||
let index = self.uniform_heap_index(src, sampler)?;
|
||||
let index = self.buffer_guard(src, index, sampler, props);
|
||||
let mut incoming = Vec::new();
|
||||
for (&q, arg) in self.x.p.blocks[*block].preds.iter().zip(args) {
|
||||
if self.block[q].is_none() {
|
||||
continue;
|
||||
}
|
||||
let (Some(tail), Source::Loaded { load, first }) = (self.tail[q], arg) else {
|
||||
return Err("a descriptor chosen by control flow");
|
||||
};
|
||||
let at = self.edges.get(&(q, *block)).copied().unwrap_or(tail);
|
||||
// No lane comes this way (`resource` gave it another
|
||||
// edge's source): any index will do.
|
||||
if self.never_taken(q, *block) {
|
||||
incoming.push((self.s.m.i32(0), at));
|
||||
continue;
|
||||
}
|
||||
let here = std::mem::replace(&mut self.cur, at);
|
||||
let index = self.heap_index(*load, *first, sampler);
|
||||
self.cur = here;
|
||||
incoming.push((index?, at));
|
||||
}
|
||||
let join = self.block[*block].ok_or("a descriptor chosen by control flow")?;
|
||||
let phi = self.s.m.phi(join, self.s.t.i32);
|
||||
self.s.m.set_phi(phi, incoming);
|
||||
let index = self.buffer_guard(src, phi, sampler, props);
|
||||
Ok(self.s.heap_handle(self.cur, index, sampler, false, props))
|
||||
}
|
||||
Source::Select { scc, args } => {
|
||||
@@ -5050,41 +5081,6 @@ impl<'a> Lower<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The heap index of a descriptor every lane shares, computed in the
|
||||
/// current block. One chosen by control flow is a phi at its join of the
|
||||
/// index each predecessor computes at its end; an edge may bring another
|
||||
/// join's (nested if/else).
|
||||
fn uniform_heap_index(&mut self, src: &Source, sampler: bool) -> Result<V, Why> {
|
||||
match src {
|
||||
Source::Loaded { load, first } => self.heap_index(*load, *first, sampler),
|
||||
Source::Phi { block, args } => {
|
||||
let mut incoming = Vec::new();
|
||||
for (&q, arg) in self.x.p.blocks[*block].preds.iter().zip(args) {
|
||||
if self.block[q].is_none() {
|
||||
continue;
|
||||
}
|
||||
let tail = self.tail[q].ok_or("a descriptor chosen by control flow")?;
|
||||
let at = self.edges.get(&(q, *block)).copied().unwrap_or(tail);
|
||||
// No lane comes this way (`resource` gave it another
|
||||
// edge's source): any index will do.
|
||||
if self.never_taken(q, *block) {
|
||||
incoming.push((self.s.m.i32(0), at));
|
||||
continue;
|
||||
}
|
||||
let here = std::mem::replace(&mut self.cur, at);
|
||||
let index = self.uniform_heap_index(arg, sampler);
|
||||
self.cur = here;
|
||||
incoming.push((index?, at));
|
||||
}
|
||||
let join = self.block[*block].ok_or("a descriptor chosen by control flow")?;
|
||||
let phi = self.s.m.phi(join, self.s.t.i32);
|
||||
self.s.m.set_phi(phi, incoming);
|
||||
Ok(phi)
|
||||
}
|
||||
_ => Err("a descriptor chosen by control flow"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The heap index of a descriptor that may differ between lanes,
|
||||
/// computed in the current block (or, chosen by control flow, at the
|
||||
/// join).
|
||||
@@ -10543,59 +10539,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn descriptors_joined_by_nested_control_flow_lower_to_one_uniform_handle() {
|
||||
// The view table at s0 (2D textures at entries 0 and 1, a raw UAV at
|
||||
// dword 16) and a root constant at s1: entry 0 if s1 is 0, else
|
||||
// entry 1 if it is 1, else entry 0 again, the inner if/else joined
|
||||
// before the outer one. The join's edges are a load and a join.
|
||||
let words = [
|
||||
0xBE84_0300, // s_mov_b32 s4, s0
|
||||
0xBE85_0380, // s_mov_b32 s5, 0
|
||||
0xF408_0A02,
|
||||
0xFA00_0040, // s_load_dwordx4 s[40:43], s[4:5], 0x40
|
||||
0xBE88_03FF,
|
||||
0x0000_0092, // s_mov_b32 s8, 0x92 (an immediate sampler)
|
||||
0xBE89_0380, // s_mov_b32 s9, 0
|
||||
0xBE8A_0380, // s_mov_b32 s10, 0
|
||||
0xBE8B_0380, // s_mov_b32 s11, 0
|
||||
0xBF06_8001, // s_cmp_eq_u32 s1, 0
|
||||
0xBF84_0003, // s_cbranch_scc0 -> 0x38
|
||||
0xF40C_0302,
|
||||
0xFA00_0000, // s_load_dwordx8 s[12:19], s[4:5], 0x0
|
||||
0xBF82_0008, // s_branch -> 0x58
|
||||
0xBF06_8101, // 0x38: s_cmp_eq_u32 s1, 1
|
||||
0xBF84_0003, // s_cbranch_scc0 -> 0x4c
|
||||
0xF40C_0302,
|
||||
0xFA00_0020, // s_load_dwordx8 s[12:19], s[4:5], 0x20
|
||||
0xBF82_0002, // s_branch -> 0x54
|
||||
0xF40C_0302,
|
||||
0xFA00_0000, // 0x4c: s_load_dwordx8 s[12:19], s[4:5], 0x0
|
||||
0xBE86_0301, // 0x54: s_mov_b32 s6, s1
|
||||
0x7E04_02F0, // 0x58: v_mov_b32 v2, 0.5
|
||||
0x7E06_02F0, // v_mov_b32 v3, 0.5
|
||||
0x3420_0082, // v_lshlrev_b32 v16, 2, v0
|
||||
0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
|
||||
0xF09C_0F08,
|
||||
0x0043_0C02, // image_sample_lz v[12:15], v[2:3], s[12:19], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D
|
||||
0xE070_1000,
|
||||
0x800A_0C10, // buffer_store_dword v12, v16, s[40:43], 0 offen
|
||||
S_ENDPGM,
|
||||
];
|
||||
let (_, mut used) = texture_and_uav_tables();
|
||||
used.retain(|u| u.user_data == 0);
|
||||
let layout = vec![root(RootType::Table, 0, 0), root(RootType::Constants, 1, 1)];
|
||||
let l = lower_with(&words, layout, used).unwrap();
|
||||
// One image handle from the joins' heap index, the same in all lanes.
|
||||
assert_eq!(l.nonuniform_handles, 0);
|
||||
if let Ok(mut v) = super::super::validator::Validator::load(
|
||||
super::super::validator::Validator::default_path().as_deref(),
|
||||
) {
|
||||
v.validate(&mut l.dxil.clone())
|
||||
.expect("DXIL validation failed");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scalar_bit_tests_lower() {
|
||||
// Each tests one bit of a constant into SCC and branches on it (only
|
||||
|
||||
Reference in new issue
Block a user