[Mesa-dev] [PATCH 1/9] nir: Add some new helpers for working with const sources
Bas Nieuwenhuizen
bas at basnieuwenhuizen.nl
Sun Oct 21 19:26:21 UTC 2018
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
for patch 1-4. (Also, I don't see patch 7?)
On Sat, Oct 20, 2018 at 7:56 PM Jason Ekstrand <jason at jlekstrand.net> wrote:
>
> ---
> src/compiler/nir/nir.c | 92 ++++++++++++++++++++++++++++++++++++++++++
> src/compiler/nir/nir.h | 16 ++++++++
> 2 files changed, 108 insertions(+)
>
> diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
> index 402fd2c7725..0be40d257f5 100644
> --- a/src/compiler/nir/nir.c
> +++ b/src/compiler/nir/nir.c
> @@ -1198,6 +1198,98 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)
> return nir_foreach_dest(instr, visit_dest_indirect, &dest_state);
> }
>
> +int64_t
> +nir_src_comp_as_int(nir_src src, unsigned comp)
> +{
> + assert(nir_src_is_const(src));
> + nir_load_const_instr *load = nir_instr_as_load_const(src.ssa->parent_instr);
> +
> + assert(comp < load->def.num_components);
> + switch (load->def.bit_size) {
> + case 8: return load->value.i8[comp];
> + case 16: return load->value.i16[comp];
> + case 32: return load->value.i32[comp];
> + case 64: return load->value.i64[comp];
> + default:
> + unreachable("Invalid bit size");
> + }
> +}
> +
> +uint64_t
> +nir_src_comp_as_uint(nir_src src, unsigned comp)
> +{
> + assert(nir_src_is_const(src));
> + nir_load_const_instr *load = nir_instr_as_load_const(src.ssa->parent_instr);
> +
> + assert(comp < load->def.num_components);
> + switch (load->def.bit_size) {
> + case 8: return load->value.u8[comp];
> + case 16: return load->value.u16[comp];
> + case 32: return load->value.u32[comp];
> + case 64: return load->value.u64[comp];
> + default:
> + unreachable("Invalid bit size");
> + }
> +}
> +
> +bool
> +nir_src_comp_as_bool(nir_src src, unsigned comp)
> +{
> + assert(nir_src_is_const(src));
> + nir_load_const_instr *load = nir_instr_as_load_const(src.ssa->parent_instr);
> +
> + assert(comp < load->def.num_components);
> + assert(load->def.bit_size == 32);
> + assert(load->value.u32[comp] == NIR_TRUE ||
> + load->value.u32[comp] == NIR_FALSE);
> +
> + return load->value.u32[comp];
> +}
> +
> +double
> +nir_src_comp_as_float(nir_src src, unsigned comp)
> +{
> + assert(nir_src_is_const(src));
> + nir_load_const_instr *load = nir_instr_as_load_const(src.ssa->parent_instr);
> +
> + assert(comp < load->def.num_components);
> + switch (load->def.bit_size) {
> + case 16: return _mesa_half_to_float(load->value.u16[comp]);
> + case 32: return load->value.f32[comp];
> + case 64: return load->value.f64[comp];
> + default:
> + unreachable("Invalid bit size");
> + }
> +}
> +
> +int64_t
> +nir_src_as_int(nir_src src)
> +{
> + assert(nir_src_num_components(src) == 1);
> + return nir_src_comp_as_int(src, 0);
> +}
> +
> +uint64_t
> +nir_src_as_uint(nir_src src)
> +{
> + assert(nir_src_num_components(src) == 1);
> + return nir_src_comp_as_uint(src, 0);
> +}
> +
> +bool
> +nir_src_as_bool(nir_src src)
> +{
> + assert(nir_src_num_components(src) == 1);
> + return nir_src_comp_as_bool(src, 0);
> +}
> +
> +double
> +nir_src_as_float(nir_src src)
> +{
> + assert(nir_src_num_components(src) == 1);
> + return nir_src_comp_as_float(src, 0);
> +}
> +
> nir_const_value *
> nir_src_as_const_value(nir_src src)
> {
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index 5b871812d46..0ba19cbb25d 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -700,6 +700,22 @@ nir_src_num_components(nir_src src)
> return src.is_ssa ? src.ssa->num_components : src.reg.reg->num_components;
> }
>
> +static inline bool
> +nir_src_is_const(nir_src src)
> +{
> + return src.is_ssa &&
> + src.ssa->parent_instr->type == nir_instr_type_load_const;
> +}
> +
> +int64_t nir_src_as_int(nir_src src);
> +uint64_t nir_src_as_uint(nir_src src);
> +bool nir_src_as_bool(nir_src src);
> +double nir_src_as_float(nir_src src);
> +int64_t nir_src_comp_as_int(nir_src src, unsigned component);
> +uint64_t nir_src_comp_as_uint(nir_src src, unsigned component);
> +bool nir_src_comp_as_bool(nir_src src, unsigned component);
> +double nir_src_comp_as_float(nir_src src, unsigned component);
> +
> static inline unsigned
> nir_dest_bit_size(nir_dest dest)
> {
> --
> 2.19.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list