Skip to content

intel: Split Gfx8- compiler into a separate module

Caio Oliveira requested to merge cmarcelo/mesa:intel-compiler-elk into main

This MR adds a separate module for Gfx8- compiler (based on the current compiler code), which will cover crocus, hasvk and iris (for Gfx8). This is a copy of the current code so there shouldn't be any functional change for those drivers.

Two separate MRs on top of this one clean up both sides: the existing compiler code can remove Gfx8- (!27691 (merged)) and the splitted off code can remove Gfx9+ code (!27629 (merged)). They can happen independently after this one lands.

The key goal here is allow us to make more aggressive changes for the compiler that target the anv and iris drivers without potentially breaking the older Gfx version drivers. Our test coverage for those is way more restricted. This is consistent with the original splitting of the drivers (crocus hasvk) themselves.

Picking Gfx9+ minimizes the combinations of drivers and compilers, and also synchronizes with anv. If we ever do another driver split, I think is a good idea to walk them all together.

Note we are not looking at the moment into creating a general compiler interface that would abstract drivers (and tools) from compiler changes -- in part because whatever happens to brw is still in flux, and in part because we may not really need it (due to the way split is done by versions). Client code that needs to handle both compilers will handle them explicitly.

I refer to the current compiler as brw, an historical name that is still present in most of its filenames and code. The Gfx8- compiler is called elk (after suggestion from Ken).

The overall plan is:

  • Find parts that can be shared between brw and elk (respecting our original goal).
  • Copy the existing compiler code into elk/ subdirectory.
  • Make it compile as a standalone library.
  • Handle elk in support libraries and tools.
  • Make the relevant drivers to use elk.

NOTE: At some point we'll move the brw code into a subdirectory as well, but punting on that to reduce conflicts with other efforts.

A more detailed breakdown follows below, note the commentary refers to patches from the time this MR is posted.

  1. LANDED: Use intel_ prefix for common code. Move certain structures to intel_shader_enums.h file.

    Most of these are in MR !27475 (merged), and the remaining are in MR !27644 (merged).

    • intel/compiler: Rename brw_image_param to isl_image_param
    • intel/compiler: Rename BRW_WM_MSAA_* enums to INTEL_MSAA_*
    • intel/compiler: Rename BRW_TESS_* enums to INTEL_TESS_*
    • intel/compiler: Rename DISPATCH_MODE_* enums to INTEL_DISPATCH_MODE_*
    • intel/compiler: Rename brw_vue_map to intel_vue_map
    • intel/compiler: Rename brw_cs_dispatch_info to intel_cs_dispatch_info
    • intel/compiler: Collect NIR-only passes in intel_nir.h
    • intel/compiler: Rename the passes and files related to intel_nir.h
    • intel/compiler: Rename brw_gfx_ver_enum.h to intel_gfx_ver_enum.h
    • intel: Remove brw_ prefix from process debug function
    • intel/isl: Include compiler generic header
  2. LANDED: Move disassembler details and the asm/disasm tools into together with the compiler code. As part of this, extract a separate module for batch decoding.

    Most of these are in MR !27579 (merged), and the decoder MR is in !27647 (merged).

    • intel/compiler: Move disassemble functions to own header file
    • intel/compiler: Include brw_disasm_info.h where its used
    • intel/compiler: Merge intel_disasm.[ch] into corresponding brw files
    • intel/decoder: Move decoder to a separate module
    • intel: Rename i965_{asm,disasm} tools to brw_{asm,disasm}
  3. LANDED: Prepare blorp by minimizing reducing the explicit usage of brw in its interfaces.

    They are still present but now is constrained.

    There's enough compiler independent code in blorp that we decide to still try to keep it as a single module that can be used with both compilers.

    Most of these are in MR !27581 (merged), and the blorp ones are in MR !27643 (merged).

    • intel/blorp: Don't require specific prog_data type in callback
    • intel/blorp: Remove brw_ prefix when not applicable
    • intel/blorp: Simplify blorp_compile_fs() interface
    • intel/blorp: Simplify blorp_compile_cs() interface
    • intel/blorp: Use a struct to return blorp_compile_*() results
    • intel/blorp: Remove outdated reference in comment
    • intel/blorp: Move brw_blorp_get_urb_length helper
    • intel/blorp: Avoid brw types in blorp_priv.h
    • intel/blorp: Move brw_compiler.h include to where is needed
    • intel/blorp: Use a Meson dependency for blorp
    • intel: Add missing dependencies on blorp
  4. Copy and bootstrap the elk module. Some of the Gfx9+ support was removed to make it easier. Note a separate MR will do a proper clean up.

    Symbols were renamed to use or include the ELK prefix. This will avoid name conflicts (for the cases where a module use both compilers) and also make it easier to distinguish which parts of the code are being hacked on.

    The bulk of the work is done by a sed script (in one of the commit messages). I haven't attempted to make the script minimal, so there's a few special cases -- which is fine since this is used only for this MR.

  • intel/elk: Fork Gfx8- compiler by copying existing code
  • intel/elk: Compile ELK library, tests and tools
  • intel/elk: Remove a bunch of files that don't apply for Gfx8-
  • intel/elk: Use common code in intel/compiler
  • intel/elk: Remove stages not used in Gfx8-
  • intel/elk: Remove DPAS lowering
  • intel/elk: Rename files to use elk prefix
  • intel/elk: Rename header guards
  • intel/elk: Update doxygen-like file comments
  • intel/elk: Rename C++ namespace
  • intel/elk: Rename symbols
  • intel/elk: Don't include elk_eu_defines.h in elk_nir.h
  • intel/elk: Create separate header for opcodes
  1. Add ELK support to blorp. The general idea is that drivers can link to blorp backed by brw, elk or both. Which compiler is support are decided at blorp initialization time. Each one has its own genX header to be used.
  • intel/blorp: Move brw specific code to a separate file
  • intel/blorp: Explicitly include brw_compiler.h header
  • intel/blorp: Add ELK support
  • intel/blorp: Remove Gfx9+ references in elk code
  1. Similar strategy as was done with blorp is used for the batch decoder module.
  • intel/decoder: Add ELK support
  1. Change crocus and hasvk to use ELK. This is mostly linking to the right dependencies and renaming symbols.
  • crocus: Use ELK compiler
  • hasvk: Use ELK compiler
  1. For Iris, there's some extra work since we want to support both compilers, Gfx8 will use ELK and the other versions keep using BRW. As stated before we are not providing a "generic compiler interface", so Iris module gets to do some of this work. This ended up working mostly fine since iris already have a "iris_compiled_shader" type that ends up acting as this common layer.

    Almost all patches are in the MR !27646 (merged).

  • iris: Add stage to iris_compiled_shader
  • iris: Reduce dependency on brw_*_prog_data structs
  • iris: Take ownership of prog_data when applying it
  • iris: Use uint32_t instead of brw_param_builtin
  • iris: Move compiler creation to iris_program.c
  • iris: Add IRIS_MAX_* constants to replace BRW_MAX_* usage
  • iris: Add helper to access use_tcs_multi_patch
  • iris: Add helper for indirect_ubos_use_sampler
  • iris: Move iris_get_compiler_options to iris_program.c
  • iris: Include brw_compiler.h only when needed
  • iris: Rename screen->compiler to screen->brw
  • iris: Use ELK compiler for Gfx8
  1. Add support for ELK to the remaining Intel tools. These tools continue to work across versions (i.e. the link both compilers).

    Note command line assembler and disassembler where moved to the compiler, so they are not in this group anymore. There's a brw_asm and an elk_asm tools.

  • intel/tools: Add ELK support for aubinator
  • intel/tools: Add ELK support for aubinator_error_decode
  • intel/tools: Add ELK support for intel_hang_replay
  • intel/tools: Add ELK support for aubinator_viewer
  • intel/tools: Add ELK support for intel_hang_viewer
  1. Initially I wanted to keep the idea of a "current" compiler to avoid churn in the meson and the filenames, but ended up prefering being clear about which compiler is being used. These patches fix that.
  • intel: Use _brw prefix for genX headers that rely on brw
  • intel/meson: Rename libintel_compiler to libintel_compiler_brw
Edited by Caio Oliveira

Merge request reports