[Mesa-dev] [PATCH 06/12] nir: Add a structure splitting pass

Thomas Helland thomashelland90 at gmail.com
Thu Jul 26 18:54:07 UTC 2018


2018-07-26 18:00 GMT+02:00 Jason Ekstrand <jason at jlekstrand.net>:
> ---
>  src/compiler/Makefile.sources     |   1 +
>  src/compiler/nir/meson.build      |   1 +
>  src/compiler/nir/nir.h            |   1 +
>  src/compiler/nir/nir_split_vars.c | 271 ++++++++++++++++++++++++++++++
>  4 files changed, 274 insertions(+)
>  create mode 100644 src/compiler/nir/nir_split_vars.c
>
> diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
> index cc147218c4e..144ba94a8c6 100644
> --- a/src/compiler/Makefile.sources
> +++ b/src/compiler/Makefile.sources
> @@ -300,6 +300,7 @@ NIR_FILES = \
>         nir/nir_serialize.h \
>         nir/nir_split_per_member_structs.c \
>         nir/nir_split_var_copies.c \
> +       nir/nir_split_vars.c \
>         nir/nir_sweep.c \
>         nir/nir_to_lcssa.c \
>         nir/nir_validate.c \
> diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
> index a1bb19356ce..3fd5535ba52 100644
> --- a/src/compiler/nir/meson.build
> +++ b/src/compiler/nir/meson.build
> @@ -184,6 +184,7 @@ files_libnir = files(
>    'nir_serialize.h',
>    'nir_split_per_member_structs.c',
>    'nir_split_var_copies.c',
> +  'nir_split_vars.c',
>    'nir_sweep.c',
>    'nir_to_lcssa.c',
>    'nir_validate.c',
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index 3bfe7d7f7bf..4af7166f25b 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -2609,6 +2609,7 @@ int nir_gs_count_vertices(const nir_shader *shader);
>
>  bool nir_split_var_copies(nir_shader *shader);
>  bool nir_split_per_member_structs(nir_shader *shader);
> +bool nir_split_struct_vars(nir_shader *shader, nir_variable_mode modes);
>
>  bool nir_lower_returns_impl(nir_function_impl *impl);
>  bool nir_lower_returns(nir_shader *shader);
> diff --git a/src/compiler/nir/nir_split_vars.c b/src/compiler/nir/nir_split_vars.c
> new file mode 100644
> index 00000000000..1f59ac2f5e7
> --- /dev/null
> +++ b/src/compiler/nir/nir_split_vars.c
> @@ -0,0 +1,271 @@
> +/*
> + * Copyright © 2018 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +#include "nir.h"
> +#include "nir_builder.h"
> +#include "nir_deref.h"
> +
> +struct split_var_state {
> +   void *mem_ctx;
> +
> +   nir_shader *shader;
> +   nir_function_impl *impl;
> +
> +   nir_variable *base_var;
> +};
> +
> +struct field {
> +   struct field *parent;
> +
> +   const struct glsl_type *type;
> +
> +   unsigned num_fields;
> +   struct field *fields;
> +
> +   nir_variable *var;
> +};
> +
> +static const struct glsl_type *
> +wrap_type_in_array(const struct glsl_type *type,
> +                   const struct glsl_type *array_type)
> +{
> +   if (!glsl_type_is_array(array_type))
> +      return type;
> +
> +   const struct glsl_type *elem_type =
> +      wrap_type_in_array(type, glsl_get_array_element(array_type));
> +   return glsl_array_type(elem_type, glsl_get_length(array_type));
> +}
> +
> +static void
> +init_field_for_type(struct field *field, struct field *parent,
> +                    const struct glsl_type *type,
> +                    const char *name,
> +                    struct split_var_state *state)
> +{
> +   *field = (struct field) {
> +      .parent = parent,
> +      .type = type,
> +   };
> +
> +   const struct glsl_type *struct_type = glsl_without_array(type);
> +   if (glsl_type_is_struct(struct_type)) {
> +      field->num_fields = glsl_get_length(struct_type),

Should be semicolon at the end here?

> +      field->fields = ralloc_array(state->mem_ctx, struct field,
> +                                   field->num_fields);
> +      for (unsigned i = 0; i < field->num_fields; i++) {
> +         char *field_name = NULL;
> +         if (name) {
> +            ralloc_asprintf(state->mem_ctx, "%s_%s", name,
> +                            glsl_get_struct_elem_name(struct_type, i));
> +         }


More information about the mesa-dev mailing list