feat(6gb/16gb): RAM-pressure trims, allocator peak-cap, submission toggles, diagnostics
Opt-in, inert-by-default performance work for 6 GB VRAM / 16 GB RAM PCs: - VICTORY_RAM_PRESSURE_MB: physical-RAM-gated fence-safe idle trims - VICTORY_LIST_ALLOC_CAP_MB: shed D3D12 command-allocator high-water peak - VICTORY_TRIM_MIN_MS: hold back zero-yield heavy sweeps to stop frame spikes - VICTORY_JOIN_FEWER / RELAY_EACH / TABLED_BITS: submission-path latency toggles - diagnostics-only per-frame refresh/read/dip timers (copystat/dipstat) - play-6gb.ps1 + play-6gb.cmd launcher preset (OPT=447, INPLACE=0, the above) The title is referred to only as "the title" throughout.
This commit is contained in:
1 parent
f0d1eb7682
commit
86184c68f3
42 files changed
+4166
-522
No files matched your search
@@ -60,14 +60,20 @@ pub const FIRST: u32 = 32;
|
||||
/// the yard's frame replayed turn by turn, dispatches and draws 18.47 -> 18.45
|
||||
/// ms (12 loops) and 18.23 -> 18.16 (5 loops): the driver joins the loads.
|
||||
pub const WIDE: u32 = 64;
|
||||
/// Strip dead single-block `waveReadLaneFirst` waterfall loops whose payload
|
||||
/// (e.g. a sample using a uniform heap handle) is loop-invariant.
|
||||
pub const WATERFALL: u32 = 128;
|
||||
/// Hoist loop-invariant and duplicated pure `createHandleFromHeap` (+
|
||||
/// `annotateHandle`) chains to their dominating preheader / definition block
|
||||
/// so [`REUSE`] deduplicates them.
|
||||
pub const HOIST_HANDLES: u32 = 256;
|
||||
/// The passes over the module.
|
||||
pub const MODULE: u32 = DEAD | FOLD | REUSE | FACTS | LOADS;
|
||||
pub const MODULE: u32 = DEAD | FOLD | REUSE | FACTS | LOADS | WATERFALL | HOIST_HANDLES;
|
||||
/// Every pass.
|
||||
pub const ALL: u32 = MODULE | FIRST | WIDE;
|
||||
/// The passes that run when nothing says which: every one but [`WIDE`],
|
||||
/// which no card has shown a gain for yet (`VICTORY_SHADER_OPT=127` asks
|
||||
/// for it).
|
||||
pub const DEFAULT: u32 = ALL & !WIDE;
|
||||
/// The passes that run when nothing says which: the baseline 63 set until
|
||||
/// newer passes (`WATERFALL`, `HOIST_HANDLES`) are verified and promoted.
|
||||
pub const DEFAULT: u32 = DEAD | FOLD | REUSE | FACTS | LOADS | FIRST;
|
||||
|
||||
/// What the instructions a module writes use, of the features a shader
|
||||
/// declares by flag (the validator's "flags must match usage").
|
||||
@@ -109,6 +115,26 @@ struct Tree {
|
||||
children: Vec<Vec<usize>>,
|
||||
/// Per block: the reached blocks that branch to it, once per edge.
|
||||
preds: Vec<Vec<usize>>,
|
||||
/// Immediate dominator of each block (`usize::MAX` if unreachable).
|
||||
idom: Vec<usize>,
|
||||
/// Depth in the dominator tree (entry = 0).
|
||||
depth: Vec<u32>,
|
||||
}
|
||||
|
||||
impl Tree {
|
||||
fn dominates(&self, a: usize, mut b: usize) -> bool {
|
||||
if a == b {
|
||||
return true;
|
||||
}
|
||||
if self.idom[b] == usize::MAX {
|
||||
return false;
|
||||
}
|
||||
let da = self.depth[a];
|
||||
while self.depth[b] > da {
|
||||
b = self.idom[b];
|
||||
}
|
||||
a == b
|
||||
}
|
||||
}
|
||||
|
||||
/// The comparison that holds exactly when `p` does not (floats 0-15,
|
||||
@@ -229,12 +255,21 @@ pub(super) fn effect(f: &Func) -> Effect {
|
||||
impl Module {
|
||||
/// Runs the clean-up passes named in `passes` ([`ALL`]: every one).
|
||||
pub(crate) fn optimise(&mut self, passes: u32) {
|
||||
if passes & (FOLD | REUSE | FACTS | LOADS) != 0 {
|
||||
if passes & (FOLD | REUSE | FACTS | LOADS | WATERFALL | HOIST_HANDLES) != 0 {
|
||||
// Values merged in one round can make two joins the same in
|
||||
// the next (a loop's registers that only go round), and a
|
||||
// branch that goes one way leaves blocks with one way in.
|
||||
for _ in 0..4 {
|
||||
let mut changed = self.merge(passes);
|
||||
let mut changed = false;
|
||||
if passes & WATERFALL != 0 {
|
||||
changed |= self.strip_dead_waterfalls();
|
||||
}
|
||||
if passes & HOIST_HANDLES != 0 {
|
||||
changed |= self.hoist_handles();
|
||||
}
|
||||
if passes & (FOLD | REUSE | FACTS | LOADS) != 0 {
|
||||
changed |= self.merge(passes);
|
||||
}
|
||||
if passes & FOLD != 0 {
|
||||
changed |= self.prune();
|
||||
}
|
||||
@@ -341,13 +376,17 @@ impl Module {
|
||||
}
|
||||
}
|
||||
let mut children = vec![Vec::new(); n];
|
||||
let mut depth = vec![0u32; n];
|
||||
for &b in &order[1..] {
|
||||
children[idom[b]].push(b);
|
||||
depth[b] = depth[idom[b]] + 1;
|
||||
}
|
||||
Tree {
|
||||
order,
|
||||
children,
|
||||
preds,
|
||||
idom,
|
||||
depth,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -997,6 +1036,735 @@ impl Module {
|
||||
true
|
||||
}
|
||||
|
||||
/// [`WATERFALL`]: strips single-block `waveReadLaneFirst` waterfall loops
|
||||
/// whose payload is loop-invariant (e.g. sampling through a uniform heap
|
||||
/// handle where the original console shader kept a dead per-lane copy of
|
||||
/// the descriptor words for waterfall comparison).
|
||||
fn strip_dead_waterfalls(&mut self) -> bool {
|
||||
let effects = self.effects();
|
||||
let tree = self.dominator_tree();
|
||||
let n_insts = self.insts.len();
|
||||
let mut def_block = vec![usize::MAX; n_insts];
|
||||
for &b in &tree.order {
|
||||
for &i in self.blocks[b].phis.iter().chain(&self.blocks[b].body) {
|
||||
def_block[i as usize] = b;
|
||||
}
|
||||
}
|
||||
let mut repl: Vec<Option<V>> = vec![None; n_insts];
|
||||
let mut changed = false;
|
||||
|
||||
for &b in &tree.order {
|
||||
let Some(Term::CondBr(cond, t, f)) = self.blocks[b].term else {
|
||||
continue;
|
||||
};
|
||||
let (back_is_true, exit) = if t == b && f != b {
|
||||
(true, f)
|
||||
} else if f == b && t != b {
|
||||
(false, t)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
if tree.preds[b].len() != 2 {
|
||||
continue;
|
||||
}
|
||||
let Some(&entry_pred) = tree.preds[b].iter().find(|&&p| p != b) else {
|
||||
continue;
|
||||
};
|
||||
if self.blocks[b].phis.is_empty() {
|
||||
continue;
|
||||
}
|
||||
// Body must have no writes (stores/atomics/barriers) and every
|
||||
// lane op must be a `waveReadLaneFirst` of a loop-invariant value.
|
||||
let mut has_wrlf = false;
|
||||
let mut body_ok = true;
|
||||
for &i in &self.blocks[b].body {
|
||||
let c = self.class(&effects, i);
|
||||
if c == Effect::Writes {
|
||||
body_ok = false;
|
||||
break;
|
||||
}
|
||||
if c == Effect::Lanes {
|
||||
match self.wrlf_arg(V::Inst(i)) {
|
||||
Some(arg) if !matches!(arg, V::Inst(a) if def_block[a as usize] == b) => {
|
||||
has_wrlf = true;
|
||||
}
|
||||
_ => {
|
||||
body_ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !body_ok || !has_wrlf {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Identify optional counter limit (`iter_next < K`, `K >= 64`) and
|
||||
// the negated waterfall match condition (`!match_mask`).
|
||||
let (retry_v, iter_phi) = if back_is_true {
|
||||
self.split_waterfall_back(b, entry_pred, cond)
|
||||
} else {
|
||||
// `CondBr(match_or_done, exit, b)` — uncommon, skip conservatively.
|
||||
continue;
|
||||
};
|
||||
let Some(mut retry_terms) = self.collect_negated_wrlf_terms(b, &def_block, retry_v, 8) else {
|
||||
continue;
|
||||
};
|
||||
retry_terms.sort_unstable();
|
||||
retry_terms.dedup();
|
||||
if retry_terms.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compute tainted instructions in `b` (phis, lane ops, and anything
|
||||
// transitively depending on them).
|
||||
let mut tainted = std::collections::HashSet::<u32>::new();
|
||||
for &p in &self.blocks[b].phis {
|
||||
tainted.insert(p);
|
||||
}
|
||||
for &i in &self.blocks[b].body {
|
||||
let mut is_t = self.class(&effects, i) == Effect::Lanes;
|
||||
if !is_t {
|
||||
for_each_operand(&self.insts[i as usize].op, |v| {
|
||||
if let V::Inst(u) = v
|
||||
&& tainted.contains(&u)
|
||||
{
|
||||
is_t = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if is_t {
|
||||
tainted.insert(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Every non-counter phi must be `select(match_mask, inv_val, phi)`
|
||||
// where `inv_val` is NOT tainted.
|
||||
let mut phi_updates: Vec<(u32, u32, V)> = Vec::new();
|
||||
let mut phis_ok = true;
|
||||
for &p in &self.blocks[b].phis {
|
||||
if Some(p) == iter_phi {
|
||||
continue;
|
||||
}
|
||||
let Op::Phi(inc) = &self.insts[p as usize].op else {
|
||||
phis_ok = false;
|
||||
break;
|
||||
};
|
||||
if inc.len() != 2 {
|
||||
phis_ok = false;
|
||||
break;
|
||||
}
|
||||
let Some(&(V::Inst(ni), _)) = inc.iter().find(|&&(_, from)| from == b) else {
|
||||
phis_ok = false;
|
||||
break;
|
||||
};
|
||||
if def_block[ni as usize] != b {
|
||||
phis_ok = false;
|
||||
break;
|
||||
}
|
||||
let Op::Select(sc, tv, fv) = self.insts[ni as usize].op else {
|
||||
phis_ok = false;
|
||||
break;
|
||||
};
|
||||
let new_val = if fv == V::Inst(p) {
|
||||
let Some(mut mt) = self.collect_wrlf_terms(b, &def_block, sc, 8) else {
|
||||
phis_ok = false;
|
||||
break;
|
||||
};
|
||||
mt.sort_unstable();
|
||||
mt.dedup();
|
||||
if mt != retry_terms {
|
||||
phis_ok = false;
|
||||
break;
|
||||
}
|
||||
tv
|
||||
} else if tv == V::Inst(p) {
|
||||
let Some(mut nt) = self.collect_negated_wrlf_terms(b, &def_block, sc, 8) else {
|
||||
phis_ok = false;
|
||||
break;
|
||||
};
|
||||
nt.sort_unstable();
|
||||
nt.dedup();
|
||||
if nt != retry_terms {
|
||||
phis_ok = false;
|
||||
break;
|
||||
}
|
||||
fv
|
||||
} else {
|
||||
phis_ok = false;
|
||||
break;
|
||||
};
|
||||
if matches!(new_val, V::Inst(u) if tainted.contains(&u)) {
|
||||
phis_ok = false;
|
||||
break;
|
||||
}
|
||||
phi_updates.push((p, ni, new_val));
|
||||
}
|
||||
if !phis_ok {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure no other tainted instruction in `b` escapes to another block.
|
||||
let mut allowed_escape = std::collections::HashSet::<u32>::new();
|
||||
for &(p, ni, _) in &phi_updates {
|
||||
allowed_escape.insert(p);
|
||||
allowed_escape.insert(ni);
|
||||
}
|
||||
let mut escapes = false;
|
||||
for &ob in &tree.order {
|
||||
if ob == b {
|
||||
continue;
|
||||
}
|
||||
for &i in self.blocks[ob].phis.iter().chain(&self.blocks[ob].body) {
|
||||
for_each_operand(&self.insts[i as usize].op, |v| {
|
||||
if let V::Inst(u) = v
|
||||
&& tainted.contains(&u)
|
||||
&& !allowed_escape.contains(&u)
|
||||
{
|
||||
escapes = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if let Some(Term::CondBr(c, ..)) = self.blocks[ob].term
|
||||
&& let V::Inst(u) = c
|
||||
&& tainted.contains(&u)
|
||||
&& !allowed_escape.contains(&u)
|
||||
{
|
||||
escapes = true;
|
||||
}
|
||||
if escapes {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if escapes {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sound to eliminate the loop! Keep `b` executing once straight to `exit`.
|
||||
for &(p, ni, new_val) in &phi_updates {
|
||||
repl[p as usize] = Some(new_val);
|
||||
repl[ni as usize] = Some(new_val);
|
||||
}
|
||||
self.blocks[b].phis.clear();
|
||||
self.blocks[b].term = Some(Term::Br(exit));
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if !changed {
|
||||
return false;
|
||||
}
|
||||
for blk in &mut self.blocks {
|
||||
if let Some(Term::CondBr(c, t, f)) = blk.term {
|
||||
blk.term = Some(Term::CondBr(resolve(&repl, c), t, f));
|
||||
}
|
||||
}
|
||||
let (blocks, insts) = (&self.blocks, &mut self.insts);
|
||||
for blk in blocks {
|
||||
for &i in blk.phis.iter().chain(&blk.body) {
|
||||
map_operands(&mut insts[i as usize].op, |v| resolve(&repl, v));
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn wrlf_arg(&self, v: V) -> Option<V> {
|
||||
let V::Inst(i) = v else { return None };
|
||||
let Op::Call(f, args) = &self.insts[i as usize].op else {
|
||||
return None;
|
||||
};
|
||||
if self.funcs[*f as usize].name.starts_with("dx.op.waveReadLaneFirst") && args.len() >= 2 {
|
||||
Some(args[1])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn unpack64(&self, v: V) -> Option<(V, V)> {
|
||||
let V::Inst(i) = v else { return None };
|
||||
let Op::Bin(Bin::Or, a, b) = self.insts[i as usize].op else {
|
||||
return None;
|
||||
};
|
||||
let as_lo = |x: V| match x {
|
||||
V::Inst(k) => match self.insts[k as usize].op {
|
||||
Op::Cast(Cast::ZExt, src) => Some(src),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let as_hi = |x: V| match x {
|
||||
V::Inst(k) => match self.insts[k as usize].op {
|
||||
Op::Bin(Bin::Shl, V::Inst(z), sh) if self.int_k(sh) == Some((64, 32)) => {
|
||||
match self.insts[z as usize].op {
|
||||
Op::Cast(Cast::ZExt, src) => Some(src),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
if let (Some(lo), Some(hi)) = (as_lo(a), as_hi(b)) {
|
||||
Some((lo, hi))
|
||||
} else if let (Some(lo), Some(hi)) = (as_lo(b), as_hi(a)) {
|
||||
Some((lo, hi))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn is_wrlf_eq(&self, b: usize, def_block: &[usize], i: u32) -> bool {
|
||||
if def_block[i as usize] != b {
|
||||
return false;
|
||||
}
|
||||
let Op::Cmp(pred::EQ, a, c) = self.insts[i as usize].op else {
|
||||
return false;
|
||||
};
|
||||
let in_b = |v: V| matches!(v, V::Inst(x) if def_block[x as usize] == b);
|
||||
let pair_matches = |w: V, raw: V| -> bool {
|
||||
if in_b(w) && !in_b(raw) && self.wrlf_arg(w) == Some(raw) {
|
||||
return true;
|
||||
}
|
||||
if let (Some((w0, w1)), Some((r0, r1))) = (self.unpack64(w), self.unpack64(raw)) {
|
||||
return in_b(w0)
|
||||
&& in_b(w1)
|
||||
&& !in_b(r0)
|
||||
&& !in_b(r1)
|
||||
&& self.wrlf_arg(w0) == Some(r0)
|
||||
&& self.wrlf_arg(w1) == Some(r1);
|
||||
}
|
||||
false
|
||||
};
|
||||
pair_matches(a, c) || pair_matches(c, a)
|
||||
}
|
||||
|
||||
fn collect_wrlf_terms(&self, b: usize, def_block: &[usize], v: V, depth: u32) -> Option<Vec<u32>> {
|
||||
if depth == 0 {
|
||||
return None;
|
||||
}
|
||||
let V::Inst(i) = v else { return None };
|
||||
if self.is_wrlf_eq(b, def_block, i) {
|
||||
return Some(vec![i]);
|
||||
}
|
||||
if let Op::Bin(Bin::And, x, y) = self.insts[i as usize].op {
|
||||
let mut a = self.collect_wrlf_terms(b, def_block, x, depth - 1)?;
|
||||
let mut c = self.collect_wrlf_terms(b, def_block, y, depth - 1)?;
|
||||
a.append(&mut c);
|
||||
return Some(a);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn collect_negated_wrlf_terms(
|
||||
&self,
|
||||
b: usize,
|
||||
def_block: &[usize],
|
||||
v: V,
|
||||
depth: u32,
|
||||
) -> Option<Vec<u32>> {
|
||||
if depth == 0 {
|
||||
return None;
|
||||
}
|
||||
let V::Inst(i) = v else { return None };
|
||||
match self.insts[i as usize].op {
|
||||
Op::Bin(Bin::Xor, x, y) => {
|
||||
if self.int_k(y) == Some((1, 1)) {
|
||||
self.collect_wrlf_terms(b, def_block, x, depth - 1)
|
||||
} else if self.int_k(x) == Some((1, 1)) {
|
||||
self.collect_wrlf_terms(b, def_block, y, depth - 1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Op::Select(cond, tv, fv) if self.int_k(fv) == Some((1, 1)) => {
|
||||
let mut a = self.collect_wrlf_terms(b, def_block, cond, depth - 1)?;
|
||||
let mut c = self.collect_negated_wrlf_terms(b, def_block, tv, depth - 1)?;
|
||||
a.append(&mut c);
|
||||
Some(a)
|
||||
}
|
||||
Op::Bin(Bin::Or, x, y) => {
|
||||
let mut a = self.collect_negated_wrlf_terms(b, def_block, x, depth - 1)?;
|
||||
let mut c = self.collect_negated_wrlf_terms(b, def_block, y, depth - 1)?;
|
||||
a.append(&mut c);
|
||||
Some(a)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn split_waterfall_back(&self, b: usize, entry_pred: usize, cond: V) -> (V, Option<u32>) {
|
||||
let is_limit = |v: V| -> Option<u32> {
|
||||
let V::Inst(i) = v else { return None };
|
||||
let (next_v, lim_v) = match self.insts[i as usize].op {
|
||||
Op::Cmp(pred::IULT, x, y) => (x, y),
|
||||
Op::Cmp(pred::IUGT, y, x) => (x, y),
|
||||
_ => return None,
|
||||
};
|
||||
let (_, k) = self.int_k(lim_v)?;
|
||||
if k < 64 {
|
||||
return None;
|
||||
}
|
||||
let V::Inst(ni) = next_v else { return None };
|
||||
let Op::Bin(Bin::Add, a, c) = self.insts[ni as usize].op else {
|
||||
return None;
|
||||
};
|
||||
let phi_v = if self.int_k(c) == Some((32, 1)) {
|
||||
a
|
||||
} else if self.int_k(a) == Some((32, 1)) {
|
||||
c
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let V::Inst(p) = phi_v else { return None };
|
||||
if !self.blocks[b].phis.contains(&p) {
|
||||
return None;
|
||||
}
|
||||
let Op::Phi(inc) = &self.insts[p as usize].op else {
|
||||
return None;
|
||||
};
|
||||
if inc.len() == 2
|
||||
&& inc.iter().any(|&(val, from)| from == entry_pred && self.int_k(val) == Some((32, 0)))
|
||||
&& inc.iter().any(|&(val, from)| from == b && val == V::Inst(ni))
|
||||
{
|
||||
Some(p)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
if let V::Inst(i) = cond
|
||||
&& let Op::Bin(Bin::And, x, y) = self.insts[i as usize].op
|
||||
{
|
||||
if let Some(p) = is_limit(y) {
|
||||
return (x, Some(p));
|
||||
}
|
||||
if let Some(p) = is_limit(x) {
|
||||
return (y, Some(p));
|
||||
}
|
||||
}
|
||||
(cond, None)
|
||||
}
|
||||
|
||||
/// [`HOIST_HANDLES`]: hoists loop-invariant `createHandleFromHeap` (+
|
||||
/// `annotateHandle`) chains out of loops, and hoists constant or duplicated
|
||||
/// pure handle chains to their deepest dominating operand block so
|
||||
/// [`REUSE`] deduplicates them.
|
||||
fn hoist_handles(&mut self) -> bool {
|
||||
let effects = self.effects();
|
||||
let tree = self.dominator_tree();
|
||||
let n_blocks = self.blocks.len();
|
||||
let n_insts = self.insts.len();
|
||||
let mut def_block = vec![usize::MAX; n_insts];
|
||||
for &b in &tree.order {
|
||||
for &i in self.blocks[b].phis.iter().chain(&self.blocks[b].body) {
|
||||
def_block[i as usize] = b;
|
||||
}
|
||||
}
|
||||
|
||||
// Identify natural loops: for each back-edge `tail -> hdr` where `hdr`
|
||||
// dominates `tail`, collect all blocks in the loop.
|
||||
let mut enclosing: Vec<Vec<usize>> = vec![Vec::new(); n_blocks];
|
||||
for &tail in &tree.order {
|
||||
for &hdr in successors(self.blocks[tail].term).iter() {
|
||||
if !tree.dominates(hdr, tail) {
|
||||
continue;
|
||||
}
|
||||
let mut in_loop = vec![false; n_blocks];
|
||||
in_loop[hdr] = true;
|
||||
let mut stack = Vec::new();
|
||||
if tail != hdr {
|
||||
in_loop[tail] = true;
|
||||
stack.push(tail);
|
||||
}
|
||||
while let Some(cur) = stack.pop() {
|
||||
for &p in &tree.preds[cur] {
|
||||
if !in_loop[p] {
|
||||
in_loop[p] = true;
|
||||
stack.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (blk, &yes) in in_loop.iter().enumerate() {
|
||||
if yes && !enclosing[blk].contains(&hdr) {
|
||||
enclosing[blk].push(hdr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for hdrs in &mut enclosing {
|
||||
hdrs.sort_by_key(|&h| tree.depth[h]);
|
||||
}
|
||||
|
||||
let is_heap_handle = |f: u32| self.funcs[f as usize].name == "dx.op.createHandleFromHeap";
|
||||
let is_annotate = |f: u32| self.funcs[f as usize].name == "dx.op.annotateHandle";
|
||||
|
||||
// Build structural key for each `createHandleFromHeap` to detect
|
||||
// duplicates across sibling branches.
|
||||
let mut handle_counts: HashMap<String, u32> = HashMap::new();
|
||||
let mut handle_keys: HashMap<u32, (String, bool)> = HashMap::new();
|
||||
for &b in &tree.order {
|
||||
for &i in &self.blocks[b].body {
|
||||
if let Op::Call(f, args) = &self.insts[i as usize].op
|
||||
&& is_heap_handle(*f)
|
||||
&& args.len() >= 4
|
||||
{
|
||||
let idx_s = self.pure_expr_sig(args[1], &effects, 6);
|
||||
let is_const_idx = self.is_const_pure(args[1], &effects, 6);
|
||||
let k = format!("{}:{:?}:{:?}", idx_s, args[2], args[3]);
|
||||
*handle_counts.entry(k.clone()).or_default() += 1;
|
||||
handle_keys.insert(i, (k, is_const_idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Map `createHandleFromHeap` -> `annotateHandle`s in the same block.
|
||||
let mut annots: HashMap<u32, Vec<u32>> = HashMap::new();
|
||||
for &b in &tree.order {
|
||||
for &i in &self.blocks[b].body {
|
||||
if let Op::Call(f, args) = &self.insts[i as usize].op
|
||||
&& is_annotate(*f)
|
||||
&& let Some(&V::Inst(h)) = args.get(1)
|
||||
&& def_block[h as usize] == b
|
||||
{
|
||||
annots.entry(h).or_default().push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut moved = vec![false; n_insts];
|
||||
let mut to_append: Vec<Vec<u32>> = vec![Vec::new(); n_blocks];
|
||||
let mut changed = false;
|
||||
|
||||
for &b in &tree.order {
|
||||
if b == 0 {
|
||||
continue;
|
||||
}
|
||||
let body_snapshot = self.blocks[b].body.clone();
|
||||
for h in body_snapshot {
|
||||
if moved[h as usize] {
|
||||
continue;
|
||||
}
|
||||
let Some((key, is_const_idx)) = handle_keys.get(&h) else {
|
||||
continue;
|
||||
};
|
||||
// 1) Try hoisting out of enclosing loops (outermost first).
|
||||
let mut chosen: Option<(usize, Vec<u32>)> = None;
|
||||
for &hdr in &enclosing[b] {
|
||||
let pre = tree.idom[hdr];
|
||||
if pre == hdr || pre == usize::MAX || pre == b {
|
||||
continue;
|
||||
}
|
||||
if let Some(slice) = self.collect_hoist_slice(h, pre, &tree, &def_block, &effects) {
|
||||
chosen = Some((pre, slice));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 2) For constant indices (e.g. samplers) or handles used >=2
|
||||
// times, hoist to the deepest dominating leaf block.
|
||||
if chosen.is_none()
|
||||
&& (*is_const_idx || handle_counts.get(key).copied().unwrap_or(0) >= 2)
|
||||
&& let Some((target, slice)) = self.collect_hoist_deepest(h, b, &tree, &def_block, &effects)
|
||||
&& target != b
|
||||
{
|
||||
chosen = Some((target, slice));
|
||||
}
|
||||
|
||||
let Some((target, slice)) = chosen else {
|
||||
continue;
|
||||
};
|
||||
for inst_id in slice {
|
||||
if !moved[inst_id as usize] && def_block[inst_id as usize] != target {
|
||||
moved[inst_id as usize] = true;
|
||||
def_block[inst_id as usize] = target;
|
||||
to_append[target].push(inst_id);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if let Some(list) = annots.get(&h) {
|
||||
for &a in list {
|
||||
if !moved[a as usize] && def_block[a as usize] != target {
|
||||
moved[a as usize] = true;
|
||||
def_block[a as usize] = target;
|
||||
to_append[target].push(a);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !changed {
|
||||
return false;
|
||||
}
|
||||
for b in 0..n_blocks {
|
||||
self.blocks[b].body.retain(|&i| !moved[i as usize]);
|
||||
}
|
||||
for (b, extra) in to_append.into_iter().enumerate() {
|
||||
self.blocks[b].body.extend(extra);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn is_hoistable_pure(&self, i: u32, effects: &[Effect]) -> bool {
|
||||
matches!(
|
||||
self.insts[i as usize].op,
|
||||
Op::Bin(..) | Op::Cast(..) | Op::Cmp(..) | Op::Select(..) | Op::Extract(..) | Op::Call(..)
|
||||
) && self.class(effects, i) == Effect::Pure
|
||||
}
|
||||
|
||||
fn pure_expr_sig(&self, v: V, effects: &[Effect], depth: u32) -> String {
|
||||
let V::Inst(i) = v else {
|
||||
return format!("{v:?}");
|
||||
};
|
||||
if depth == 0 || !self.is_hoistable_pure(i, effects) {
|
||||
return format!("I{i}");
|
||||
}
|
||||
match &self.insts[i as usize].op {
|
||||
Op::Bin(op, a, b) => format!(
|
||||
"B({:?},{},{})",
|
||||
op,
|
||||
self.pure_expr_sig(*a, effects, depth - 1),
|
||||
self.pure_expr_sig(*b, effects, depth - 1)
|
||||
),
|
||||
Op::Cast(op, a) => format!("C({:?},{})", op, self.pure_expr_sig(*a, effects, depth - 1)),
|
||||
Op::Call(f, args) => {
|
||||
let parts: Vec<String> = args
|
||||
.iter()
|
||||
.map(|&a| self.pure_expr_sig(a, effects, depth - 1))
|
||||
.collect();
|
||||
format!("F({f},{})", parts.join(","))
|
||||
}
|
||||
_ => format!("I{i}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_const_pure(&self, v: V, effects: &[Effect], depth: u32) -> bool {
|
||||
match v {
|
||||
V::Const(_) => true,
|
||||
V::Inst(i) if depth > 0 && self.is_hoistable_pure(i, effects) => {
|
||||
let mut ok = true;
|
||||
for_each_operand(&self.insts[i as usize].op, |op| {
|
||||
if !self.is_const_pure(op, effects, depth - 1) {
|
||||
ok = false;
|
||||
}
|
||||
});
|
||||
ok
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Collects the pure DAG rooted at `root` whose instructions do not yet
|
||||
/// dominate `target`, returning them in topological order (operands first).
|
||||
fn collect_hoist_slice(
|
||||
&self,
|
||||
root: u32,
|
||||
target: usize,
|
||||
tree: &Tree,
|
||||
def_block: &[usize],
|
||||
effects: &[Effect],
|
||||
) -> Option<Vec<u32>> {
|
||||
let mut order = Vec::new();
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn dfs(
|
||||
m: &Module,
|
||||
i: u32,
|
||||
target: usize,
|
||||
tree: &Tree,
|
||||
def_block: &[usize],
|
||||
effects: &[Effect],
|
||||
seen: &mut std::collections::HashSet<u32>,
|
||||
order: &mut Vec<u32>,
|
||||
) -> bool {
|
||||
let db = def_block[i as usize];
|
||||
if db == usize::MAX {
|
||||
return false;
|
||||
}
|
||||
if tree.dominates(db, target) {
|
||||
return true;
|
||||
}
|
||||
if !seen.insert(i) {
|
||||
return true;
|
||||
}
|
||||
if order.len() >= 16 || !m.is_hoistable_pure(i, effects) {
|
||||
return false;
|
||||
}
|
||||
let mut ok = true;
|
||||
for_each_operand(&m.insts[i as usize].op, |v| {
|
||||
if let V::Inst(u) = v
|
||||
&& !dfs(m, u, target, tree, def_block, effects, seen, order)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
});
|
||||
if ok {
|
||||
order.push(i);
|
||||
}
|
||||
ok
|
||||
}
|
||||
dfs(self, root, target, tree, def_block, effects, &mut seen, &mut order).then_some(order)
|
||||
}
|
||||
|
||||
/// Walks the pure DAG rooted at `root` (up to 16 pure instructions in
|
||||
/// non-entry blocks) to find the deepest dominating leaf block `target`.
|
||||
fn collect_hoist_deepest(
|
||||
&self,
|
||||
root: u32,
|
||||
cur_block: usize,
|
||||
tree: &Tree,
|
||||
def_block: &[usize],
|
||||
effects: &[Effect],
|
||||
) -> Option<(usize, Vec<u32>)> {
|
||||
let mut order = Vec::new();
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut deepest = 0usize;
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn dfs(
|
||||
m: &Module,
|
||||
i: u32,
|
||||
tree: &Tree,
|
||||
def_block: &[usize],
|
||||
effects: &[Effect],
|
||||
seen: &mut std::collections::HashSet<u32>,
|
||||
order: &mut Vec<u32>,
|
||||
deepest: &mut usize,
|
||||
) -> bool {
|
||||
let db = def_block[i as usize];
|
||||
if db == usize::MAX {
|
||||
return false;
|
||||
}
|
||||
if db == 0 || !m.is_hoistable_pure(i, effects) || order.len() >= 16 {
|
||||
if tree.depth[db] > tree.depth[*deepest] {
|
||||
*deepest = db;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if !seen.insert(i) {
|
||||
return true;
|
||||
}
|
||||
let mut ok = true;
|
||||
for_each_operand(&m.insts[i as usize].op, |v| {
|
||||
if let V::Inst(u) = v
|
||||
&& !dfs(m, u, tree, def_block, effects, seen, order, deepest)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
});
|
||||
if ok {
|
||||
order.push(i);
|
||||
}
|
||||
ok
|
||||
}
|
||||
if !dfs(self, root, tree, def_block, effects, &mut seen, &mut order, &mut deepest) {
|
||||
return None;
|
||||
}
|
||||
if !tree.dominates(deepest, cur_block) {
|
||||
return None;
|
||||
}
|
||||
// Keep only instructions not already dominating `deepest`.
|
||||
order.retain(|&i| !tree.dominates(def_block[i as usize], deepest));
|
||||
Some((deepest, order))
|
||||
}
|
||||
|
||||
/// Whether instruction `i` must stay whatever reads it.
|
||||
fn has_effect(&self, effects: &[Effect], i: u32) -> bool {
|
||||
match &self.insts[i as usize].op {
|
||||
|
||||
@@ -142,6 +142,17 @@ const POPS_PACKER: u16 = 25;
|
||||
/// The operand `src_pops_exiting_wave_id`.
|
||||
const POPS_EXITING: u8 = 239;
|
||||
|
||||
/// Whether pixel float colour outputs are held to the console's HDR range
|
||||
/// `[-65024, 65024]` (`VICTORY_HDR_CLAMP=1`: on; off by default because
|
||||
/// clamping every MRT pixel output adds heavy GPU overhead on 6 GB laptops,
|
||||
/// while `VICTORY_COMPOSE_NAN` + `ambient.rs` already scrub NaNs at compose).
|
||||
fn hdr_clamp() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_HDR_CLAMP").is_some_and(|v| v == "1"))
|
||||
}
|
||||
|
||||
const HDR_MAX: f32 = 65024.0;
|
||||
|
||||
/// The instructions inside a pixel program's ordered section
|
||||
/// (primitive-ordered pixel shading, which the console compiler makes of
|
||||
/// rasterizer ordered views): from the write of `POPS_PACKER`, along every
|
||||
@@ -1466,7 +1477,24 @@ pub(super) fn host_rdna() -> u32 {
|
||||
if let Some(bits) = TEST_RDNA.get() {
|
||||
return bits;
|
||||
}
|
||||
if HOST_RDNA.load(std::sync::atomic::Ordering::Relaxed) { super::rdna_float() } else { 0 }
|
||||
static EXPLICIT: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
let explicit = *EXPLICIT.get_or_init(|| std::env::var_os("VICTORY_RDNA_FLOAT").is_some());
|
||||
if HOST_RDNA.load(std::sync::atomic::Ordering::Relaxed) || explicit {
|
||||
super::rdna_float()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
/// Optional override for `v_mul_legacy_f32` lowering (`VICTORY_LEGACY_MUL`):
|
||||
/// `plain` emits plain `fmul`; `isnan` emits `r = a * b; select(isnan(r), 0.0, r)`.
|
||||
fn legacy_mul_mode() -> u8 {
|
||||
static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new();
|
||||
*MODE.get_or_init(|| match std::env::var("VICTORY_LEGACY_MUL").as_deref() {
|
||||
Ok("plain") => 1,
|
||||
Ok("isnan") => 2,
|
||||
_ => 0,
|
||||
})
|
||||
}
|
||||
|
||||
/// The refusal of a first half of an interpolation whose result is read
|
||||
@@ -4248,6 +4276,21 @@ impl<'a> Lower<'a> {
|
||||
self.s.m.select(c, keep, r, t)
|
||||
}
|
||||
|
||||
/// Holds a pixel float colour output to `[-65024, 65024]` (`VICTORY_HDR_CLAMP`).
|
||||
/// Prevents >65504 values from becoming `+Inf` in 16-bit float host targets.
|
||||
fn clamp_hdr(&mut self, f: V) -> V {
|
||||
if !hdr_clamp() {
|
||||
return f;
|
||||
}
|
||||
let c = self.cur;
|
||||
let min = self.s.m.f32((-HDR_MAX).to_bits());
|
||||
let max = self.s.m.f32(HDR_MAX.to_bits());
|
||||
let lo = self.binary(35, f, min); // FMax
|
||||
let hi = self.binary(36, lo, max); // FMin
|
||||
let nan = self.is_nan_f32(f);
|
||||
self.s.m.select(c, nan, max, hi)
|
||||
}
|
||||
|
||||
/// Whether an f32 value is NaN, tested in integer arithmetic so host
|
||||
/// drivers (such as NVIDIA) do not fold `fcmp uno` away under fast-math.
|
||||
fn is_nan_f32(&mut self, f: V) -> V {
|
||||
@@ -4357,6 +4400,16 @@ impl<'a> Lower<'a> {
|
||||
/// `0 × anything = 0`, as in D3D9.
|
||||
fn legacy_mul(&mut self, a: V, b: V) -> V {
|
||||
let c = self.cur;
|
||||
match legacy_mul_mode() {
|
||||
1 => return self.s.m.bin(c, Bin::Mul, a, b),
|
||||
2 => {
|
||||
let m = self.s.m.bin(c, Bin::Mul, a, b);
|
||||
let nan = self.s.m.cmp(c, pred::UNO, m, m);
|
||||
let zero = self.s.m.f32(0);
|
||||
return self.s.m.select(c, nan, zero, m);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if host_rdna() & super::rdna::LEGACY != 0 {
|
||||
let m = self.s.m.bin(c, Bin::Mul, a, b);
|
||||
let zero = self.s.m.f32(0);
|
||||
@@ -10045,15 +10098,17 @@ impl<'a> Lower<'a> {
|
||||
return Err("a 16-bit result outside a VGPR");
|
||||
};
|
||||
let mut high = v.opsel >> 3 & 1 != 0;
|
||||
// SDWA: the word written, the other one kept (preserve) or zero
|
||||
// (pad; a sign extension above the high word adds nothing).
|
||||
// UNUSED_SEXT extends bit 15 only for WORD_0. WORD_1 has
|
||||
// nothing above it to extend, and its low word is zero-padded.
|
||||
let mut keep = true;
|
||||
let mut sext = false;
|
||||
if let Some(sd) = v.sdwa {
|
||||
match (sd.dst_sel, sd.dst_unused) {
|
||||
(4, 2) => {}
|
||||
(5, 2) => high = true,
|
||||
(4 | 6, _) => keep = false,
|
||||
(5, _) => (high, keep) = (true, false),
|
||||
(4, 1) => (keep, sext) = (false, true),
|
||||
(4, 0) | (6, 0..=2) => keep = false,
|
||||
(5, 0 | 1) => (high, keep) = (true, false),
|
||||
_ => return Err("an SDWA destination of a 16-bit operation"),
|
||||
}
|
||||
}
|
||||
@@ -10064,7 +10119,10 @@ impl<'a> Lower<'a> {
|
||||
};
|
||||
let (k16, low) = (self.s.m.i32(16), self.s.m.i32(0xFFFF));
|
||||
let x = self.s.m.bin(c, Bin::And, x, low);
|
||||
let r = if high {
|
||||
let r = if sext {
|
||||
let shifted = self.s.m.bin(c, Bin::Shl, x, k16);
|
||||
self.s.m.bin(c, Bin::AShr, shifted, k16)
|
||||
} else if high {
|
||||
let o = self.s.m.bin(c, Bin::And, old, low);
|
||||
let x = self.s.m.bin(c, Bin::Shl, x, k16);
|
||||
self.s.m.bin(c, Bin::Or, o, x)
|
||||
@@ -13202,16 +13260,21 @@ impl<'a> Lower<'a> {
|
||||
.op(c, "legacyF16ToF32", Attr::ReadNone, f32t, 131, &[x]);
|
||||
x = self.as_int(f);
|
||||
}
|
||||
let is_ps = !mesh && matches!(self.x.native.stage, HwStage::Ps);
|
||||
let el = &mut elements(self, primitive)[id];
|
||||
el.usage |= 1 << col;
|
||||
let hdr = is_ps && el.kind == 16;
|
||||
let (suffix, x) = match el.comp {
|
||||
9 if half.is_some() => (".f32", self.as_float(x)),
|
||||
9 if half.is_some() => {
|
||||
let f = self.as_float(x);
|
||||
(".f32", if hdr { self.clamp_hdr(f) } else { f })
|
||||
}
|
||||
9 => {
|
||||
let f = match self.floats.get(&value) {
|
||||
Some(&f) => f,
|
||||
None => self.as_float(x),
|
||||
};
|
||||
(".f32", f)
|
||||
(".f32", if hdr { self.clamp_hdr(f) } else { f })
|
||||
}
|
||||
_ => (".i32", x),
|
||||
};
|
||||
@@ -14314,4 +14377,31 @@ mod tests {
|
||||
// A 16-bit float is a half already, sign included.
|
||||
assert_eq!(half(0xBC00 << half_shift(16)), -1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sdwa_16bit_reserved_dst_unused_is_refused() {
|
||||
for dst_sel in [4u32, 5] {
|
||||
// v_cvt_i16_f16_sdwa v1, v0 dst_sel:{WORD_0,WORD_1} dst_unused:3 (reserved);
|
||||
// ds_write_b32 v0, v1 to keep v1 live.
|
||||
let sdwa_ext = (dst_sel << 8) | (3 << 11) | (4 << 16);
|
||||
let words = [
|
||||
0x7E02_A6F9, // v_cvt_i16_f16 v1, sdwa
|
||||
sdwa_ext,
|
||||
0xD834_0000,
|
||||
0x0000_0100, // ds_write_b32 v0, v1
|
||||
S_ENDPGM,
|
||||
];
|
||||
let err = lowers(&words, 1 << 15).expect_err("reserved dst_unused must fail");
|
||||
assert!(
|
||||
matches!(
|
||||
err,
|
||||
crate::ShaderError::Unsupported {
|
||||
what: "an SDWA destination of a 16-bit operation",
|
||||
..
|
||||
}
|
||||
),
|
||||
"unexpected error for dst_sel={dst_sel}: {err}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1421,7 +1421,7 @@ mod tests {
|
||||
assert_eq!(parse_shader_opt(Some("0")), 0);
|
||||
assert_eq!(parse_shader_opt(Some(" 1 ")), 1);
|
||||
assert_eq!(parse_shader_opt(Some("0x1")), 1);
|
||||
assert_eq!(parse_shader_opt(Some("127")), all);
|
||||
assert_eq!(parse_shader_opt(Some("511")), all);
|
||||
assert_eq!(parse_shader_opt(Some("0xffffffff")), all);
|
||||
assert_eq!(parse_shader_opt(Some("on")), usual);
|
||||
}
|
||||
@@ -2753,7 +2753,7 @@ mod tests {
|
||||
let res = crate::resource::track(&p, &native.layout, native.stage, None).unwrap();
|
||||
let io = crate::io::raise(&p, &native).unwrap();
|
||||
let st = crate::structure::structure(&p).unwrap();
|
||||
let l = super::lower::lower(&super::lower::Parts {
|
||||
super::lower::lower(&super::lower::Parts {
|
||||
native: &native,
|
||||
p: &p,
|
||||
st: &st,
|
||||
@@ -2764,8 +2764,7 @@ mod tests {
|
||||
prims: Vec::new(),
|
||||
mesh_stride: 0,
|
||||
})
|
||||
.unwrap();
|
||||
l
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -375,6 +375,7 @@ fn simulate(insts: &[Inst], wave: u32, saved: Value) -> Left {
|
||||
}
|
||||
continue;
|
||||
};
|
||||
let f16_inline = name == "v_add_f16";
|
||||
let lanes = |op: &Operand,
|
||||
vec: &HashMap<Value, Vec<Sym>>,
|
||||
uni: &HashMap<Value, Sym>|
|
||||
@@ -392,6 +393,12 @@ fn simulate(insts: &[Inst], wave: u32, saved: Value) -> Left {
|
||||
Some(x) => one(uni.get(&x).copied().unwrap_or(Sym::Uni(x))),
|
||||
None => one(Sym::Unknown),
|
||||
},
|
||||
Operand::Const(c @ 240..=248) if f16_inline => {
|
||||
let h = [
|
||||
0x3800, 0xB800, 0x3C00, 0xBC00, 0x4000, 0xC000, 0x4400, 0xC400, 0x3118,
|
||||
][usize::from(c - 240)];
|
||||
one(Sym::K(h))
|
||||
}
|
||||
Operand::Const(c) => one(crate::resource::inline(c).map_or(Sym::Unknown, Sym::K)),
|
||||
Operand::Literal(x) => one(Sym::K(x)),
|
||||
_ => one(Sym::Unknown),
|
||||
@@ -1289,4 +1296,39 @@ mod tests {
|
||||
assert_eq!(per_lane(&bad_ident, all), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v_add_f16_inline_float_constants_are_not_zero_identity() {
|
||||
let run = |src_const: u16| -> (Option<Shape>, Value, Value) {
|
||||
let mut w = vec![sop1(0, 0x3D, 193)]; // s_or_saveexec_b32 s0, -1
|
||||
w.extend(vop3(1, 0x101, 128, 256, 0)); // v_cndmask_b32 v1, 0, v0, s0
|
||||
w.push(vop2(1, 0x32, src_const, 1)); // v_add_f16 v1, <const>, v1
|
||||
for ctrl in [0x00B1u16, 0x004E, 0x0164, 0x0168] {
|
||||
w.push(vop2(1, 0x32, 0xFA, 1));
|
||||
w.push(dpp16(1, ctrl, 0xF, 0xF, false));
|
||||
}
|
||||
w.extend(vop3(2, 0x378, 257, 128, 128)); // v_permlanex16_b32 v2, v1, 0, 0
|
||||
w.push(vop2(1, 0x32, 258, 1)); // v_add_f16 v1, v2, v1
|
||||
w.extend(vop3(1, 0x360, 257, 128 + 31, 0)); // v_readlane_b32 s1, v1, 31
|
||||
w.push(sop1(EXEC, 0x03, 0)); // s_mov_b32 exec_lo, s0
|
||||
|
||||
let p = build(&w, false);
|
||||
let insts = &p.blocks[0].insts;
|
||||
let saved = insts[0].write(Reg::S(0)).unwrap();
|
||||
let v0_in = insts[1].read(Reg::V(0)).unwrap();
|
||||
let s1 = insts[insts.len() - 3].write(Reg::S(1)).unwrap();
|
||||
let sec = §ions(&p, 0)[&0];
|
||||
(sec.shapes.get(&s1).copied(), v0_in, saved)
|
||||
};
|
||||
|
||||
let (zero_shape, v0_in, saved) = run(128);
|
||||
assert_eq!(
|
||||
zero_shape,
|
||||
Some(Shape::Active(Op::AddH, v0_in, saved, 0))
|
||||
);
|
||||
for c in 240..=248u16 {
|
||||
let (shape, _, _) = run(c);
|
||||
assert_eq!(shape, None, "inline float const {c} was treated as identity");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user