nir/builder: Add ubitfield_extract_imm helper

We have a ubfe_imm helper that creates ubfe ops. Not all drivers support ubfe,
however, as it requires SM5 semantics. A few drivers support oly
ubitfield_extract. They should still get the convenience of an _imm helper, so
add a symmetric helper.

It might be nice to unify these helpers into a single helper that asserts its
inputs do not overflow (such that the two ops become equivalent) and emits
either ubfe or ubitfield_extract depending on the underlying driver. That is
left for future work as it's unclear exactly what naming/semantics we want.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23351>
This commit is contained in:
Alyssa Rosenzweig 2023-05-20 23:01:45 -04:00
parent 7f8e172ecf
commit fc3bf53a65

View file

@ -937,6 +937,12 @@ nir_ubfe_imm(nir_builder *build, nir_ssa_def *x, uint32_t offset, uint32_t size)
return nir_ubfe(build, x, nir_imm_int(build, offset), nir_imm_int(build, size));
}
static inline nir_ssa_def *
nir_ubitfield_extract_imm(nir_builder *build, nir_ssa_def *x, uint32_t offset, uint32_t size)
{
return nir_ubitfield_extract(build, x, nir_imm_int(build, offset), nir_imm_int(build, size));
}
static inline nir_ssa_def *
nir_fclamp(nir_builder *b,
nir_ssa_def *x, nir_ssa_def *min_val, nir_ssa_def *max_val)