[Mesa-dev] [PATCH v3 000/104] nir: Move to using instructions for derefs

Jason Ekstrand jason at jlekstrand.net
Tue Apr 3 18:32:27 UTC 2018


This is something that Connor and I have been talking about for some time
now.  The basic idea is to replace the current singly linked nir_deref list
with deref instructions.  This is similar to what LLVM does and it offers
quite a bit more freedom when we start getting more realistic pointers from
compute applications.

This series implements a complete conversion for both i965 and anv.  As can
be seen in the penultimate patch, there are three core NIR passes remaining
to be converted.  None of those three passes is used by any of the Intel
drivers so I have no ability to test them.  The final patch deletes support
for old-school deref chains from NIR entirely.  The only NIR-using drivers
which build with that patch are i965 and anv but it shows that the
conversion for those two is complete and has also been very useful in
finding things I missed the first time around.

Somehow, this series manages to shave off 700 lines of code but I wouldn't
take that to mean much.  Some of that is whole-sale deleting lower_io_types
(170 lines).  Some of it is that deref instructions and the new function
call mechanism are more efficient from a data structure perspective because
you don't have deref chains attached to texture ops and intrinsics.  I've
also been modernizing as I go and converting some things to use nir_builder
instead of building instructions manually.  The ammount that deref
instructions make things easier over deref chains is totally a wash.

Clearly, this can't really proceed until other drivers have added the bits
(which should be small at this point) to do the conversion.  Someone also
needs to add "Support deref instructions in..." and "Remove deref chain
support from..." patches for the three remaining core NIR passes.

My next plan is to try and start experimenting with more advanced
load/store elimination on shared variables and maybe even SSBOs.  This will
require properly handling barriers and, thanks to Vulkan's pointer support,
cast derefs where the source may have come from a phi node or variable.

This series can be found as a branch on gitlab:

https://gitlab.freedesktop.org/jekstrand/mesa/commits/review/nir-deref-instr-v3

Cc: Rob Clark <robdclark at gmail.com>
Cc: Timothy Arceri <tarceri at itsqueeze.com>
Cc: Eric Anholt <eric at anholt.net>
Cc: Connor Abbott <cwabbott0 at gmail.com>
Cc: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Cc: Karol Herbst <kherbst at redhat.com>

Jason Ekstrand (104):
  nir/validate: Rework intrinsic type validation
  nir: Add a deref instruction type
  nir/builder: Add deref building helpers
  nir: Add _deref versions of all of the _var intrinsics
  nir: Add deref sources to texture instructions
  nir: Add helpers for working with deref instructions
  anv,i965,radv,st,ir3: Call nir_lower_deref_instrs
  glsl/nir: Only claim to handle intrinsic functions
  glsl/nir: Use deref instructions instead of dref chains
  prog/nir: Simplify some load/store operations
  prog/nir: Use deref instructions for params
  nir/lower_atomics: Rework the main walker loop a bit
  nir: Support deref instructions in remove_dead_variables
  nir: Add a pass for fixing deref modes
  nir: Support deref instructions in lower_global_vars_to_local
  nir: Use nir_builder in lower_io_to_temporaries
  nir: Support deref instructions in lower_io_to_temporaries
  nir: Add a deref path helper struct
  nir: Support deref instructions in lower_var_copies
  nir: Support deref instructions in split_var_copies
  nir: Support deref instructions in lower_vars_to_ssa
  nir: Support deref instructions in lower_indirect_derefs
  nir/deref: Add a deref cleanup function
  nir: Support deref instructions in lower_system_values
  nir: Support deref instructions in lower_clip_cull
  nir: Support deref instructions in propagate_invariant
  nir: Support deref instructions in gather_info
  nir: Support deref instructions in lower_io
  nir: Support deref instructions in lower_atomics
  nir: Support deref instructions in lower_wpos_ytransform
  nir: Support deref instructions in lower_pos_center
  nir: Support deref instructions in remove_unused_varyings
  nir: Support deref instructions in loop_analyze
  nir: Support deref instructions in lower_alpha_test
  nir: Support deref instructions in lower_clamp_color_outputs
  nir: Support deref instructions in lower_drawpixels
  nir: Consider deref instructions in lower_phis_to_scalar
  nir: Consider deref instructions in opt_peephole_select
  nir: Support deref instructions in opt_undef
  intel,ir3: Disable nir_opt_copy_prop_vars
  intel/nir: Fixup deref modes after lowering patch vertices
  i965: Move nir_lower_deref_instrs to right before locals_to_regs
  st/nir: Move lower_deref_instrs later
  spirv: Use deref instructions for most variables
  nir: Add a concept of per-member structs and a lowering pass
  nir/lower_system_values: Support SYSTEM_VALUE_LOCAL_GROUP_SIZE
  spirv: Use the LOCAL_GROUP_SIZE system value
  nir/spirv: Pass nir_variable_data into apply_var_decoration
  anv/pipeline: Lower more constant initializers earlier
  spirv: Use NIR per-member splitting
  spirv: Make push constants an offset-based pointer
  spirv: Clean up vtn_pointer_to_offset
  spirv: Allow pointers to have a deref at the base
  spirv: Update vtn_pointer_to/from_ssa to handle deref pointers
  spirv: Record the type of functions
  spirv/cfg: Make the builder fully capable for both walks
  nir,spirv: Rework function calls
  anv/pipeline: Do less deref instruction lowering
  anv/pipeline: Convert lower_input_attachments to deref instructions
  anv/pipeline: Convert YCbCr lowering to deref instructiosn
  anv/pipeline: Convert lower_multiview to deref instructions
  anv/apply_pipeline_layout: Simplify extract_tex_src_plane
  anv/pipeline: Convert apply_pipeline_layout to deref instructions
  intel/fs: Use image_deref intrinsics instead of image_var
  intel/nir: Only lower load/store derefs
  intel/blorp: Stop setting tex->texture/sampler
  nir/lower_samplers: Clean up function arguments
  nir: Use derefs in nir_lower_samplers
  nir/builder: Use deref instructions for load/store/copy_var
  nir: Use deref instructions in lower_constant_initializers
  nir/vars_to_ssa: Add an is_direct field to deref_node
  nir/vars_to_ssa: Rework to entirely use deref instructions
  nir: Remove deref chain support from analyze_loops
  nir: Rework gather_info to entirely use deref instructions
  nir: Remove deref chain support from lower_indirect_derefs
  nir: Remove deref chain support from lower_clip_cull_distance_arrays
  nir: Remove deref chain support from lower_atomics
  nir: Remove deref chain support from lower_alpha_test
  nir: Remove deref chain support from lower_clamp_color_outputs
  nir: Remove deref chain support from lower_global_vars_to_local
  nir/lower_io: Convert atomic lowering to deref instructions
  nir: Convert lower_io to deref instructions
  nir: Remove deref chain support from lower_phis_to_scalar
  nir: Delete lower_io_types
  nir: Remove deref chain support from remove_unused_varyings
  nir: Remove deref chain support from lower_system_values
  nir: Remove deref chain support from lower_wpos_center
  nir: Remove deref chain support from lower_wpos_ytransform
  nir/lower_tex: Always copy deref and offset sources
  nir: Remove deref chain support from lower_tex
  nir: Remove deref chain support from opt_peephole_select
  nir: Remove deref chain support from lower_drawpixels
  nir: Remove deref chain support from lower_var_copies
  nir: Remove deref chain support from propagate_invariant
  nir: Remove deref chain support from dead_variables
  nir: Remove deref chain support from split_var_copies
  nir: Remove deref chain support from opt_undef
  nir: Remove deref chain support from split_per_member_structs
  nir/copy_prop_vars: Re-order some logic in compare_derefs
  nir: Rework opt_copy_prop_vars to use deref instructions
  intel,ir3: Re-enable nir_opt_copy_prop_vars
  nir: Rework lower_locals_to_regs to use deref instructions
  HACK! nir: Disable building a couple passes
  nir: Remove old-school deref chain support

 src/amd/vulkan/radv_shader.c                       |  10 +
 src/compiler/Makefile.sources                      |   7 +-
 src/compiler/glsl/glsl_to_nir.cpp                  | 267 ++++------
 src/compiler/nir/meson.build                       |  10 +-
 src/compiler/nir/nir.c                             | 423 +++------------
 src/compiler/nir/nir.h                             | 211 ++++----
 src/compiler/nir/nir_builder.h                     | 254 +++++++--
 src/compiler/nir/nir_clone.c                       | 143 ++---
 src/compiler/nir/nir_deref.c                       | 117 +++++
 src/compiler/nir/nir_deref.h                       |  55 ++
 src/compiler/nir/nir_gather_info.c                 |  51 +-
 src/compiler/nir/nir_inline_functions.c            | 193 ++-----
 src/compiler/nir/nir_instr_set.c                   | 101 +++-
 src/compiler/nir/nir_intrinsics.py                 |  99 ++--
 src/compiler/nir/nir_intrinsics_c.py               |   1 -
 src/compiler/nir/nir_linking_helpers.c             |  47 +-
 src/compiler/nir/nir_loop_analyze.c                |  70 ++-
 src/compiler/nir/nir_lower_alpha_test.c            |   7 +-
 src/compiler/nir/nir_lower_atomics.c               | 154 +++---
 src/compiler/nir/nir_lower_clamp_color_outputs.c   |   9 +-
 .../nir/nir_lower_clip_cull_distance_arrays.c      |  85 +--
 src/compiler/nir/nir_lower_constant_initializers.c |  57 +-
 src/compiler/nir/nir_lower_drawpixels.c            |  10 +-
 src/compiler/nir/nir_lower_global_vars_to_local.c  |  45 +-
 src/compiler/nir/nir_lower_indirect_derefs.c       | 175 +++----
 src/compiler/nir/nir_lower_io.c                    | 186 +++----
 src/compiler/nir/nir_lower_io_to_temporaries.c     |  39 +-
 src/compiler/nir/nir_lower_io_types.c              | 176 -------
 src/compiler/nir/nir_lower_locals_to_regs.c        | 186 ++++---
 src/compiler/nir/nir_lower_phis_to_scalar.c        |  14 +-
 src/compiler/nir/nir_lower_samplers.c              | 162 +++---
 src/compiler/nir/nir_lower_system_values.c         |  27 +-
 src/compiler/nir/nir_lower_tex.c                   |  47 +-
 src/compiler/nir/nir_lower_var_copies.c            | 164 +++---
 src/compiler/nir/nir_lower_vars_to_ssa.c           | 350 +++++++------
 src/compiler/nir/nir_lower_wpos_center.c           |   8 +-
 src/compiler/nir/nir_lower_wpos_ytransform.c       |  33 +-
 src/compiler/nir/nir_opt_constant_folding.c        |  53 --
 src/compiler/nir/nir_opt_copy_prop_vars.c          | 316 ++++++-----
 src/compiler/nir/nir_opt_copy_propagate.c          |  95 ++--
 src/compiler/nir/nir_opt_dce.c                     |   7 +
 src/compiler/nir/nir_opt_peephole_select.c         |   4 +-
 src/compiler/nir/nir_opt_undef.c                   |   2 +-
 src/compiler/nir/nir_print.c                       | 192 ++-----
 src/compiler/nir/nir_propagate_invariant.c         |  23 +-
 src/compiler/nir/nir_remove_dead_variables.c       | 152 +++---
 src/compiler/nir/nir_serialize.c                   | 234 ++++-----
 src/compiler/nir/nir_split_per_member_structs.c    | 207 ++++++++
 src/compiler/nir/nir_split_var_copies.c            | 234 ++-------
 src/compiler/nir/nir_sweep.c                       |   4 -
 src/compiler/nir/nir_validate.c                    | 247 ++++-----
 src/compiler/spirv/spirv_to_nir.c                  | 184 ++++---
 src/compiler/spirv/vtn_cfg.c                       | 231 ++++----
 src/compiler/spirv/vtn_glsl450.c                   |  19 +-
 src/compiler/spirv/vtn_private.h                   |  26 +-
 src/compiler/spirv/vtn_variables.c                 | 580 +++++++--------------
 src/gallium/drivers/freedreno/ir3/ir3_cmdline.c    |   4 +-
 src/intel/blorp/blorp_blit.c                       |   2 -
 src/intel/compiler/brw_fs.h                        |   2 +-
 src/intel/compiler/brw_fs_nir.cpp                  | 157 +++---
 src/intel/vulkan/anv_nir_apply_pipeline_layout.c   | 187 +++----
 src/intel/vulkan/anv_nir_lower_input_attachments.c |  31 +-
 src/intel/vulkan/anv_nir_lower_multiview.c         |  17 +-
 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c    |  34 +-
 src/intel/vulkan/anv_pipeline.c                    |  19 +-
 src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp     |   2 +
 src/mesa/drivers/dri/i965/brw_program.c            |   5 +-
 src/mesa/program/prog_to_nir.c                     |  94 +---
 src/mesa/state_tracker/st_glsl_to_nir.cpp          |   2 +
 69 files changed, 3335 insertions(+), 4024 deletions(-)
 create mode 100644 src/compiler/nir/nir_deref.c
 create mode 100644 src/compiler/nir/nir_deref.h
 delete mode 100644 src/compiler/nir/nir_lower_io_types.c
 create mode 100644 src/compiler/nir/nir_split_per_member_structs.c

-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list