[Mesa-dev] [RFC PATCH 00/17] An other look at nir

Christian Gmeiner christian.gmeiner at gmail.com
Fri May 10 09:08:58 UTC 2019

There has been interest in NIR support for etnaviv for a while, for the
obvious reasons: gaining access to common optimizations, better support
for non-trivial code transformations, better register allocation, and
the promise of OpenCL and SPIR-V support in the future.

This time I give it a try with a completly different architecture compared
to the one pengutronix has choosen.
  - https://patchwork.freedesktop.org/series/44282/

My main goal was to have all the needed tools like assembler, disasm,
linker and ofc the compiler living outside of the gallium driver. This
opens the door for easier testing of the different components and - if
somebody dreams loud - vulkan.

I have choosen to go with an own backend ir called:  *drumroll*  eir
It is a basic block based one with some nice to haves. I have studied
every backend-compiler mesa have and have choosen the (best) parts from

eir provides stuff like:
 - legalization
 - optimizations
 - register allocator
 - unit tests

Why I have not choosen to do it directly in nir?

Not that easy to answer but nir is a really fast moving target and nobody
can tell where the road goes. nir might translate well enought to hw ISA now
but maybe in the situation gets harder with newer GPUs and some core nir
changes. For instance, at the moment on thing that might need worked around
is the fact that nir can't represent (jump_if x CND y).

ISA wise there are some improvements possible like on GC3000 it is possible
to provide immediate values inline for source arguments for other instructions
than control flow instructions.

Oh before I forget it - this RFC is based on top of:
"etnaviv: add low level ISA library"
 - https://gitlab.freedesktop.org/mesa/mesa/merge_requests/848

I am sending out this RFC to get feedback on the design I have choosen. I am not
sure how the future nir based compiler infrastrucutre will look like but I am
hoping for the best.

Keep in mind that the nir compiler does something but most of the time the wrong
thing. I only target GC2000 for the moment as it is still my main dev gpu. Weeks
ago I have started to track deqp and piglit problems and to address them - so dont
even try to use it.

The last thing I want to say - lot of you might know that I am working on this thing
for a while now and never had any ready-to-send patches, but I have a good explanation.

 - nir is moving really fast and it takes time to sync my downstream with upstream.
 - I only hack/work on etnaviv one day a week.
 - Cleaning up the git history after a long hack day (with refactorings etc.) takes time.
 - It takes time to upstream nir changes if you need to respin it.
 - I spend some of my etnaviv time with other topic like linear texturing support,
   etc2 texture patching, some other RE stuff and ofc I try my best to review other
   patches in the area of etnaviv.

So it comes down to my limted time and the big architectural changes I have done with
unit tests and real shader compiles on the targets.

At the moment I am not sure how to move on form this point.


PS: You can find this changes here too

Christian Gmeiner (17):
  etnaviv: add basic block based backend ir: eir
  eir: add legalization
  eir: add live ranges pass
  eir: add virtual register classes
  eir: implement actual register allocator
  eir: add nir optimization loop
  eir: add eir_print(..)
  eir: add nir compiler and all its infrastructure
  etnaviv: become independed of the used compiler backend
  etnaviv: hook-up eir into gallium driver
  etnaviv: add eir_compiler
  etnaviv: add debug option to report NIR as supported and preferred
    shader IR
  etnaviv: enable nir paths
  eir: add nir alu to scalar lowering pass
  eir: make use of eir_nir_lower_alu_to_scalar(..)
  eir: add optimization 'framework'
  eir: add peephole optimization

 src/etnaviv/compiler/eir.c                    |  239 ++++
 src/etnaviv/compiler/eir.h                    |  523 +++++++++
 src/etnaviv/compiler/eir_compiler.c           |   61 +
 src/etnaviv/compiler/eir_compiler.h           |   70 ++
 src/etnaviv/compiler/eir_compiler_nir.c       | 1041 +++++++++++++++++
 src/etnaviv/compiler/eir_legalize.c           |  177 +++
 src/etnaviv/compiler/eir_live_variables.c     |  258 ++++
 src/etnaviv/compiler/eir_nir.c                |  133 +++
 src/etnaviv/compiler/eir_nir.h                |   43 +
 .../compiler/eir_nir_lower_alu_to_scalar.c    |  131 +++
 src/etnaviv/compiler/eir_opt_peephole.c       |   63 +
 src/etnaviv/compiler/eir_optimize.c           |   50 +
 src/etnaviv/compiler/eir_optimize.h           |   36 +
 src/etnaviv/compiler/eir_print.c              |  222 ++++
 src/etnaviv/compiler/eir_register_allocate.c  |  353 ++++++
 src/etnaviv/compiler/eir_shader.c             |  312 +++++
 src/etnaviv/compiler/eir_shader.h             |  203 ++++
 src/etnaviv/compiler/eir_uniform.c            |  108 ++
 src/etnaviv/compiler/meson.build              |   52 +
 src/etnaviv/compiler/tests/eir_assemble.cpp   |  114 ++
 src/etnaviv/compiler/tests/eir_legalize.cpp   |  136 +++
 .../compiler/tests/eir_live_variables.cpp     |  162 +++
 src/etnaviv/compiler/tests/eir_uniform.cpp    |  324 +++++
 src/etnaviv/compiler/tests/meson.build        |   65 +
 src/etnaviv/meson.build                       |    1 +
 src/gallium/drivers/etnaviv/Makefile.sources  |    2 +
 src/gallium/drivers/etnaviv/eir_cmdline.c     |  189 +++
 src/gallium/drivers/etnaviv/etnaviv_context.c |   27 +-
 src/gallium/drivers/etnaviv/etnaviv_context.h |   18 +-
 src/gallium/drivers/etnaviv/etnaviv_debug.h   |    3 +
 src/gallium/drivers/etnaviv/etnaviv_eir.c     |  454 +++++++
 src/gallium/drivers/etnaviv/etnaviv_eir.h     |   71 ++
 src/gallium/drivers/etnaviv/etnaviv_emit.c    |   16 +-
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |   26 +-
 src/gallium/drivers/etnaviv/etnaviv_screen.h  |    2 +
 src/gallium/drivers/etnaviv/etnaviv_shader.c  |   60 +-
 src/gallium/drivers/etnaviv/etnaviv_shader.h  |    4 +-
 src/gallium/drivers/etnaviv/etnaviv_state.c   |   16 +-
 .../drivers/etnaviv/etnaviv_uniforms.c        |   19 +-
 .../drivers/etnaviv/etnaviv_uniforms.h        |    8 +-
 src/gallium/drivers/etnaviv/meson.build       |   28 +-
 41 files changed, 5790 insertions(+), 30 deletions(-)
 create mode 100644 src/etnaviv/compiler/eir.c
 create mode 100644 src/etnaviv/compiler/eir.h
 create mode 100644 src/etnaviv/compiler/eir_compiler.c
 create mode 100644 src/etnaviv/compiler/eir_compiler.h
 create mode 100644 src/etnaviv/compiler/eir_compiler_nir.c
 create mode 100644 src/etnaviv/compiler/eir_legalize.c
 create mode 100644 src/etnaviv/compiler/eir_live_variables.c
 create mode 100644 src/etnaviv/compiler/eir_nir.c
 create mode 100644 src/etnaviv/compiler/eir_nir.h
 create mode 100644 src/etnaviv/compiler/eir_nir_lower_alu_to_scalar.c
 create mode 100644 src/etnaviv/compiler/eir_opt_peephole.c
 create mode 100644 src/etnaviv/compiler/eir_optimize.c
 create mode 100644 src/etnaviv/compiler/eir_optimize.h
 create mode 100644 src/etnaviv/compiler/eir_print.c
 create mode 100644 src/etnaviv/compiler/eir_register_allocate.c
 create mode 100644 src/etnaviv/compiler/eir_shader.c
 create mode 100644 src/etnaviv/compiler/eir_shader.h
 create mode 100644 src/etnaviv/compiler/eir_uniform.c
 create mode 100644 src/etnaviv/compiler/meson.build
 create mode 100644 src/etnaviv/compiler/tests/eir_assemble.cpp
 create mode 100644 src/etnaviv/compiler/tests/eir_legalize.cpp
 create mode 100644 src/etnaviv/compiler/tests/eir_live_variables.cpp
 create mode 100644 src/etnaviv/compiler/tests/eir_uniform.cpp
 create mode 100644 src/etnaviv/compiler/tests/meson.build
 create mode 100644 src/gallium/drivers/etnaviv/eir_cmdline.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_eir.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_eir.h


More information about the mesa-dev mailing list