[Mesa-dev] [PATCH] nir: move GL specific passes to src/compiler/glsl

Alejandro Piñeiro apinheiro at igalia.com
Mon Apr 30 11:13:49 UTC 2018


The patch looks good, and would make putting ARB_gl_spirv implementation
a better fit on src/compiler/glsl. Having said so, probably it would be
better to gather more opinions beyond mine, as it moves several pieces
around.

In any case, as it is ok to me:

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>


On 30/04/18 12:43, Timothy Arceri wrote:
> With this we should have no passes in src/compiler/nir with any
> dependencies on headers from core GL Mesa.
> ---
>  src/compiler/Makefile.sources                 |  7 +--
>  src/compiler/glsl/gl_nir.h                    | 47 +++++++++++++++++++
>  .../gl_nir_lower_atomics.c}                   | 12 +++--
>  .../gl_nir_lower_samplers.c}                  | 11 +++--
>  .../gl_nir_lower_samplers_as_deref.c}         | 11 +++--
>  src/compiler/glsl/meson.build                 |  4 ++
>  src/compiler/nir/meson.build                  |  3 --
>  src/compiler/nir/nir.h                        | 11 -----
>  .../drivers/freedreno/ir3/ir3_cmdline.c       |  2 +-
>  src/mesa/drivers/dri/i965/brw_link.cpp        |  5 +-
>  src/mesa/main/glspirv.h                       |  1 +
>  src/mesa/state_tracker/st_glsl_to_nir.cpp     |  7 +--
>  12 files changed, 83 insertions(+), 38 deletions(-)
>  create mode 100644 src/compiler/glsl/gl_nir.h
>  rename src/compiler/{nir/nir_lower_atomics.c => glsl/gl_nir_lower_atomics.c} (96%)
>  rename src/compiler/{nir/nir_lower_samplers.c => glsl/gl_nir_lower_samplers.c} (95%)
>  rename src/compiler/{nir/nir_lower_samplers_as_deref.c => glsl/gl_nir_lower_samplers_as_deref.c} (97%)
>
> diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
> index aca9dab476e..b98ea673705 100644
> --- a/src/compiler/Makefile.sources
> +++ b/src/compiler/Makefile.sources
> @@ -25,6 +25,10 @@ LIBGLSL_FILES = \
>  	glsl/builtin_types.cpp \
>  	glsl/builtin_variables.cpp \
>  	glsl/generate_ir.cpp \
> +	glsl/gl_nir_lower_atomics.c \
> +	glsl/gl_nir_lower_samplers.c \
> +	glsl/gl_nir_lower_samplers_as_deref.c \
> +	glsl/gl_nir.h \
>  	glsl/glsl_parser_extras.cpp \
>  	glsl/glsl_parser_extras.h \
>  	glsl/glsl_symbol_table.cpp \
> @@ -211,7 +215,6 @@ NIR_FILES = \
>  	nir/nir_lower_64bit_packing.c \
>  	nir/nir_lower_alpha_test.c \
>  	nir/nir_lower_alu_to_scalar.c \
> -	nir/nir_lower_atomics.c \
>  	nir/nir_lower_atomics_to_ssbo.c \
>  	nir/nir_lower_bitmap.c \
>  	nir/nir_lower_clamp_color_outputs.c \
> @@ -237,8 +240,6 @@ NIR_FILES = \
>  	nir/nir_lower_phis_to_scalar.c \
>  	nir/nir_lower_regs_to_ssa.c \
>  	nir/nir_lower_returns.c \
> -	nir/nir_lower_samplers.c \
> -	nir/nir_lower_samplers_as_deref.c \
>  	nir/nir_lower_subgroups.c \
>  	nir/nir_lower_system_values.c \
>  	nir/nir_lower_tex.c \
> diff --git a/src/compiler/glsl/gl_nir.h b/src/compiler/glsl/gl_nir.h
> new file mode 100644
> index 00000000000..59d5f65e659
> --- /dev/null
> +++ b/src/compiler/glsl/gl_nir.h
> @@ -0,0 +1,47 @@
> +/*
> + * Copyright © 2018 Timothy Arceri
> + *
> + * 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.
> + */
> +
> +#ifndef GL_NIR_H
> +#define GL_NIR_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +struct nir_shader;
> +struct gl_shader_program;
> +
> +bool gl_nir_lower_atomics(nir_shader *shader,
> +                          const struct gl_shader_program *shader_program,
> +                          bool use_binding_as_idx);
> +
> +bool gl_nir_lower_samplers(nir_shader *shader,
> +                           const struct gl_shader_program *shader_program);
> +bool gl_nir_lower_samplers_as_deref(nir_shader *shader,
> +                                    const struct gl_shader_program *shader_program);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* GL_NIR_H */
> diff --git a/src/compiler/nir/nir_lower_atomics.c b/src/compiler/glsl/gl_nir_lower_atomics.c
> similarity index 96%
> rename from src/compiler/nir/nir_lower_atomics.c
> rename to src/compiler/glsl/gl_nir_lower_atomics.c
> index 383e3236102..e203b390b48 100644
> --- a/src/compiler/nir/nir_lower_atomics.c
> +++ b/src/compiler/glsl/gl_nir_lower_atomics.c
> @@ -25,8 +25,10 @@
>   *
>   */
>  
> -#include "compiler/glsl/ir_uniform.h"
> -#include "nir.h"
> +#include "compiler/nir/nir.h"
> +#include "gl_nir.h"
> +#include "ir_uniform.h"
> +
>  #include "main/config.h"
>  #include "main/mtypes.h"
>  #include <assert.h>
> @@ -177,9 +179,9 @@ lower_instr(nir_intrinsic_instr *instr,
>  }
>  
>  bool
> -nir_lower_atomics(nir_shader *shader,
> -                  const struct gl_shader_program *shader_program,
> -                  bool use_binding_as_idx)
> +gl_nir_lower_atomics(nir_shader *shader,
> +                     const struct gl_shader_program *shader_program,
> +                     bool use_binding_as_idx)
>  {
>     bool progress = false;
>  
> diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/glsl/gl_nir_lower_samplers.c
> similarity index 95%
> rename from src/compiler/nir/nir_lower_samplers.c
> rename to src/compiler/glsl/gl_nir_lower_samplers.c
> index 7690665de30..a53fabb7e62 100644
> --- a/src/compiler/nir/nir_lower_samplers.c
> +++ b/src/compiler/glsl/gl_nir_lower_samplers.c
> @@ -23,9 +23,10 @@
>   * DEALINGS IN THE SOFTWARE.
>   */
>  
> -#include "nir.h"
> -#include "nir_builder.h"
> -#include "compiler/glsl/ir_uniform.h"
> +#include "compiler/nir/nir.h"
> +#include "compiler/nir/nir_builder.h"
> +#include "gl_nir.h"
> +#include "ir_uniform.h"
>  
>  #include "main/compiler.h"
>  #include "main/mtypes.h"
> @@ -148,8 +149,8 @@ lower_impl(nir_function_impl *impl, const struct gl_shader_program *shader_progr
>  }
>  
>  bool
> -nir_lower_samplers(nir_shader *shader,
> -                   const struct gl_shader_program *shader_program)
> +gl_nir_lower_samplers(nir_shader *shader,
> +                      const struct gl_shader_program *shader_program)
>  {
>     bool progress = false;
>  
> diff --git a/src/compiler/nir/nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
> similarity index 97%
> rename from src/compiler/nir/nir_lower_samplers_as_deref.c
> rename to src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
> index cb0c827182c..47115f943fe 100644
> --- a/src/compiler/nir/nir_lower_samplers_as_deref.c
> +++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
> @@ -55,9 +55,10 @@
>   * the opaque uniform mapping.
>   */
>  
> -#include "nir.h"
> -#include "nir_builder.h"
> -#include "compiler/glsl/ir_uniform.h"
> +#include "compiler/nir/nir.h"
> +#include "compiler/nir/nir_builder.h"
> +#include "gl_nir.h"
> +#include "ir_uniform.h"
>  
>  #include "main/compiler.h"
>  #include "main/mtypes.h"
> @@ -226,8 +227,8 @@ lower_impl(nir_function_impl *impl, struct lower_samplers_as_deref_state *state)
>  }
>  
>  bool
> -nir_lower_samplers_as_deref(nir_shader *shader,
> -                            const struct gl_shader_program *shader_program)
> +gl_nir_lower_samplers_as_deref(nir_shader *shader,
> +                               const struct gl_shader_program *shader_program)
>  {
>     bool progress = false;
>     struct lower_samplers_as_deref_state state;
> diff --git a/src/compiler/glsl/meson.build b/src/compiler/glsl/meson.build
> index 26ab4f1c8d3..055a84714c1 100644
> --- a/src/compiler/glsl/meson.build
> +++ b/src/compiler/glsl/meson.build
> @@ -66,6 +66,10 @@ files_libglsl = files(
>    'builtin_types.cpp',
>    'builtin_variables.cpp',
>    'generate_ir.cpp',
> +  'gl_nir_lower_atomics.c',
> +  'gl_nir_lower_samplers.c',
> +  'gl_nir_lower_samplers_as_deref.c',
> +  'gl_nir.h',
>    'glsl_parser_extras.cpp',
>    'glsl_parser_extras.h',
>    'glsl_symbol_table.cpp',
> diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
> index b28a565d0c6..84715a58912 100644
> --- a/src/compiler/nir/meson.build
> +++ b/src/compiler/nir/meson.build
> @@ -106,7 +106,6 @@ files_libnir = files(
>    'nir_lower_64bit_packing.c',
>    'nir_lower_alu_to_scalar.c',
>    'nir_lower_alpha_test.c',
> -  'nir_lower_atomics.c',
>    'nir_lower_atomics_to_ssbo.c',
>    'nir_lower_bitmap.c',
>    'nir_lower_clamp_color_outputs.c',
> @@ -132,8 +131,6 @@ files_libnir = files(
>    'nir_lower_phis_to_scalar.c',
>    'nir_lower_regs_to_ssa.c',
>    'nir_lower_returns.c',
> -  'nir_lower_samplers.c',
> -  'nir_lower_samplers_as_deref.c',
>    'nir_lower_subgroups.c',
>    'nir_lower_system_values.c',
>    'nir_lower_tex.c',
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index f3326e6df94..f8e71d54a50 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -55,9 +55,6 @@
>  extern "C" {
>  #endif
>  
> -struct gl_program;
> -struct gl_shader_program;
> -
>  #define NIR_FALSE 0u
>  #define NIR_TRUE (~0u)
>  
> @@ -2596,11 +2593,6 @@ void nir_lower_io_arrays_to_elements_no_indirects(nir_shader *shader,
>  void nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask);
>  void nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
>  
> -bool nir_lower_samplers(nir_shader *shader,
> -                        const struct gl_shader_program *shader_program);
> -bool nir_lower_samplers_as_deref(nir_shader *shader,
> -                                 const struct gl_shader_program *shader_program);
> -
>  typedef struct nir_lower_subgroups_options {
>     uint8_t subgroup_size;
>     uint8_t ballot_bit_size;
> @@ -2755,9 +2747,6 @@ typedef struct nir_lower_bitmap_options {
>  
>  void nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options *options);
>  
> -bool nir_lower_atomics(nir_shader *shader,
> -                       const struct gl_shader_program *shader_program,
> -                       bool use_binding_as_idx);
>  bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned ssbo_offset);
>  bool nir_lower_to_source_mods(nir_shader *shader);
>  
> diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c b/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
> index ff1d9d1377b..5631216ebd9 100644
> --- a/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
> +++ b/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
> @@ -162,7 +162,7 @@ load_glsl(unsigned num_files, char* const* files, gl_shader_stage stage)
>  
>  	NIR_PASS_V(nir, nir_lower_system_values);
>  	NIR_PASS_V(nir, nir_lower_io, nir_var_all, ir3_glsl_type_size, 0);
> -	NIR_PASS_V(nir, nir_lower_samplers, prog);
> +	NIR_PASS_V(nir, gl_nir_lower_samplers, prog);
>  
>  	return nir;
>  }
> diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
> index 7841626dc33..39fa94c0f8d 100644
> --- a/src/mesa/drivers/dri/i965/brw_link.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_link.cpp
> @@ -24,6 +24,7 @@
>  #include "brw_context.h"
>  #include "compiler/brw_nir.h"
>  #include "brw_program.h"
> +#include "compiler/glsl/gl_nir.h"
>  #include "compiler/glsl/ir.h"
>  #include "compiler/glsl/ir_optimization.h"
>  #include "compiler/glsl/program.h"
> @@ -299,8 +300,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
>        struct gl_program *prog = shader->Program;
>        brw_shader_gather_info(prog->nir, prog);
>  
> -      NIR_PASS_V(prog->nir, nir_lower_samplers, shProg);
> -      NIR_PASS_V(prog->nir, nir_lower_atomics, shProg, false);
> +      NIR_PASS_V(prog->nir, gl_nir_lower_samplers, shProg);
> +      NIR_PASS_V(prog->nir, gl_nir_lower_atomics, shProg, false);
>        NIR_PASS_V(prog->nir, nir_lower_atomics_to_ssbo,
>                   prog->nir->info.num_abos);
>  
> diff --git a/src/mesa/main/glspirv.h b/src/mesa/main/glspirv.h
> index cbcd3c0bcbc..8025c17c099 100644
> --- a/src/mesa/main/glspirv.h
> +++ b/src/mesa/main/glspirv.h
> @@ -30,6 +30,7 @@
>  extern "C" {
>  #endif
>  
> +struct gl_shader_program;
>  struct gl_context;
>  struct gl_shader;
>  
> diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
> index bcf6a7ceb6a..8d80c8cae22 100644
> --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
> @@ -43,6 +43,7 @@
>  #include "compiler/nir/nir.h"
>  #include "compiler/glsl_types.h"
>  #include "compiler/glsl/glsl_to_nir.h"
> +#include "compiler/glsl/gl_nir.h"
>  #include "compiler/glsl/ir.h"
>  #include "compiler/glsl/string_to_uint_map.h"
>  
> @@ -467,7 +468,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
>     st_set_prog_affected_state_flags(prog);
>  
>     NIR_PASS_V(nir, st_nir_lower_builtin);
> -   NIR_PASS_V(nir, nir_lower_atomics, shader_program, true);
> +   NIR_PASS_V(nir, gl_nir_lower_atomics, shader_program, true);
>  
>     if (st->ctx->_Shader->Flags & GLSL_DUMP) {
>        _mesa_log("\n");
> @@ -813,9 +814,9 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
>     }
>  
>     if (screen->get_param(screen, PIPE_CAP_NIR_SAMPLERS_AS_DEREF))
> -      NIR_PASS_V(nir, nir_lower_samplers_as_deref, shader_program);
> +      NIR_PASS_V(nir, gl_nir_lower_samplers_as_deref, shader_program);
>     else
> -      NIR_PASS_V(nir, nir_lower_samplers, shader_program);
> +      NIR_PASS_V(nir, gl_nir_lower_samplers, shader_program);
>  }
>  
>  } /* extern "C" */




More information about the mesa-dev mailing list