nak: Add support for imad on Volta+ and enable it in simple cases

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27159>
This commit is contained in:
Faith Ekstrand
2024-01-18 16:49:01 -06:00
parent a747cd1bd5
commit 41722c6137
3 changed files with 32 additions and 1 deletions
+10
View File
@@ -1091,6 +1091,16 @@ impl<'a> ShaderFromNir<'a> {
b.isetp(cmp_type, cmp_op, x.into(), y.into())
}
}
nir_op_imad => {
assert!(alu.def.bit_size() == 32);
let dst = b.alloc_ssa(RegFile::GPR, 1);
b.push_op(OpIMad {
dst: dst.into(),
srcs: [srcs[0], srcs[1], srcs[2]],
signed: false,
});
dst
}
nir_op_imax | nir_op_imin | nir_op_umax | nir_op_umin => {
let (tp, min) = match alu.op {
nir_op_imax => (IntCmpType::I32, SrcRef::False),
+7 -1
View File
@@ -26,6 +26,7 @@ import sys
a = 'a'
b = 'b'
c = 'c'
# common conditions to improve readability
volta = 'nak->sm >= 70 && nak->sm < 75'
@@ -38,6 +39,11 @@ algebraic_lowering = [
(('umax', 'a', 'b'), ('bcsel', ('ult', a, b), b, a), volta),
]
late_optimizations = [
(('iadd@32', ('imul(nak_is_only_used_by_iadd)', a, b), c),
('imad', a, b, c), 'nak->sm >= 70'),
]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--out', required=True, help='Output file.')
@@ -52,7 +58,7 @@ def main():
f.write('#include "nak_private.h"')
f.write(nir_algebraic.AlgebraicPass(
"nak_nir_lower_algebraic_late",
algebraic_lowering,
algebraic_lowering + late_optimizations,
[
("const struct nak_compiler *", "nak"),
]).render())
+15
View File
@@ -205,6 +205,21 @@ enum nak_fs_out {
bool nak_nir_add_barriers(nir_shader *nir, const struct nak_compiler *nak);
static inline bool
nak_is_only_used_by_iadd(const nir_alu_instr *instr)
{
nir_foreach_use(src, &instr->def) {
nir_instr *use = nir_src_parent_instr(src);
if (use->type != nir_instr_type_alu)
return false;
if (nir_instr_as_alu(use)->op != nir_op_iadd)
return false;
}
return true;
}
struct nak_memstream {
FILE *stream;
char *buffer;