[Mesa-dev] [PATCH v3 1/3] nir: add glsl_replace_vector_type()
Jason Ekstrand
jason at jlekstrand.net
Mon Feb 4 20:25:33 UTC 2019
On Mon, Nov 5, 2018 at 8:58 PM Timothy Arceri <tarceri at itsqueeze.com> wrote:
> This creates a new glsl_type with the specified number on components.
>
> We will use this in the following patch when vectorising io.
> ---
> src/compiler/nir_types.cpp | 24 ++++++++++++++++++++++++
> src/compiler/nir_types.h | 2 ++
> 2 files changed, 26 insertions(+)
>
> diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
> index d24f0941519..45a06e0214b 100644
> --- a/src/compiler/nir_types.cpp
> +++ b/src/compiler/nir_types.cpp
> @@ -432,6 +432,30 @@ glsl_array_type(const glsl_type *base, unsigned
> elements)
> return glsl_type::get_array_instance(base, elements);
> }
>
> +const glsl_type *
> +glsl_replace_vector_type(const glsl_type *t, unsigned components)
>
On the one hand, this doesn't seem incredibly generic. On the other hand,
I seem to recall having written this function before....
> +{
> + switch (glsl_get_base_type(t)) {
> + case GLSL_TYPE_ARRAY: {
> + const glsl_type *base = glsl_replace_vector_type(t->fields.array,
> components);
> + return glsl_array_type(base, glsl_get_length(t));
> + }
> + case GLSL_TYPE_UINT:
> + case GLSL_TYPE_INT:
> + case GLSL_TYPE_FLOAT:
> + case GLSL_TYPE_BOOL:
> + case GLSL_TYPE_DOUBLE:
> + case GLSL_TYPE_UINT64:
> + case GLSL_TYPE_INT64:
> + case GLSL_TYPE_FLOAT16:
> + case GLSL_TYPE_UINT16:
> + case GLSL_TYPE_INT16:
> + return glsl_vector_type(glsl_get_base_type(t), components);
>
Would it be better to just do:
if (glsl_type_is_array(t)) {
return glsl_array_type(glsl_replace_vector_type(t->fields.array),
t->length);
} else if (glsl_type_is_vector_or_scalar(t)) {
return glsl_vector_type(t->base_type, components);
} else {
unreachable();
}
That way we don't accidentally forget to add new scalar cases (INT8 is
coming!) and we ensure that the matrix case (currently unhandled) hits the
unreachable?
--Jason
> + default:
> + unreachable("Unhandled base type glsl_replace_vector_type()");
> + }
> +}
> +
> const glsl_type *
> glsl_struct_type(const glsl_struct_field *fields,
> unsigned num_fields, const char *name)
> diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
> index 77454fa9fab..deb7ead8dd2 100644
> --- a/src/compiler/nir_types.h
> +++ b/src/compiler/nir_types.h
> @@ -167,6 +167,8 @@ const struct glsl_type *glsl_bool_type(void);
> const struct glsl_type *glsl_scalar_type(enum glsl_base_type base_type);
> const struct glsl_type *glsl_vector_type(enum glsl_base_type base_type,
> unsigned components);
> +const struct glsl_type * glsl_replace_vector_type(const struct glsl_type
> *t,
> + unsigned components);
> const struct glsl_type *glsl_matrix_type(enum glsl_base_type base_type,
> unsigned rows, unsigned columns);
> const struct glsl_type *glsl_array_type(const struct glsl_type *base,
> --
> 2.19.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190204/dc5d3e3e/attachment.html>
More information about the mesa-dev
mailing list