Mesa (main): intel/compiler: Use a struct for brw_compile_gs parameters

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Dec 13 01:29:01 UTC 2021


Module: Mesa
Branch: main
Commit: 58c4a95320003cb733dec1084801406cf15f04ec
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=58c4a95320003cb733dec1084801406cf15f04ec

Author: Caio Oliveira <caio.oliveira at intel.com>
Date:   Tue Mar 23 15:19:05 2021 -0700

intel/compiler: Use a struct for brw_compile_gs parameters

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14139>

---

 src/gallium/drivers/crocus/crocus_program.c | 14 +++++++----
 src/gallium/drivers/iris/iris_program.c     | 14 +++++++----
 src/intel/compiler/brw_compiler.h           | 30 +++++++++++++++++------
 src/intel/compiler/brw_vec4_gs_visitor.cpp  | 38 ++++++++++++++---------------
 src/intel/vulkan/anv_pipeline.c             | 15 ++++++++----
 5 files changed, 68 insertions(+), 43 deletions(-)

diff --git a/src/gallium/drivers/crocus/crocus_program.c b/src/gallium/drivers/crocus/crocus_program.c
index 165feb3d678..91958295d31 100644
--- a/src/gallium/drivers/crocus/crocus_program.c
+++ b/src/gallium/drivers/crocus/crocus_program.c
@@ -1739,12 +1739,16 @@ crocus_compile_gs(struct crocus_context *ice,
    struct brw_gs_prog_key key_clean = *key;
    crocus_sanitize_tex_key(&key_clean.base.tex);
 
-   char *error_str = NULL;
-   const unsigned *program =
-      brw_compile_gs(compiler, &ice->dbg, mem_ctx, &key_clean, gs_prog_data, nir,
-                     NULL, &error_str);
+   struct brw_compile_gs_params params = {
+      .nir = nir,
+      .key = &key_clean,
+      .prog_data = gs_prog_data,
+      .log_data = &ice->dbg,
+   };
+
+   const unsigned *program = brw_compile_gs(compiler, mem_ctx, &params);
    if (program == NULL) {
-      dbg_printf("Failed to compile geometry shader: %s\n", error_str);
+      dbg_printf("Failed to compile geometry shader: %s\n", params.error_str);
       ralloc_free(mem_ctx);
       return false;
    }
diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c
index c9ddd028733..7e773661c62 100644
--- a/src/gallium/drivers/iris/iris_program.c
+++ b/src/gallium/drivers/iris/iris_program.c
@@ -1850,12 +1850,16 @@ iris_compile_gs(struct iris_screen *screen,
 
    struct brw_gs_prog_key brw_key = iris_to_brw_gs_key(devinfo, key);
 
-   char *error_str = NULL;
-   const unsigned *program =
-      brw_compile_gs(compiler, dbg, mem_ctx, &brw_key, gs_prog_data,
-                     nir, NULL, &error_str);
+   struct brw_compile_gs_params params = {
+      .nir = nir,
+      .key = &brw_key,
+      .prog_data = gs_prog_data,
+      .log_data = dbg,
+   };
+
+   const unsigned *program = brw_compile_gs(compiler, mem_ctx, &params);
    if (program == NULL) {
-      dbg_printf("Failed to compile geometry shader: %s\n", error_str);
+      dbg_printf("Failed to compile geometry shader: %s\n", params.error_str);
       ralloc_free(mem_ctx);
 
       shader->compilation_failed = true;
diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h
index 7cb2eaf0d0d..b2e49a7d1cf 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -1624,18 +1624,32 @@ brw_compile_tes(const struct brw_compiler *compiler,
                 struct brw_compile_tes_params *params);
 
 /**
- * Compile a vertex shader.
+ * Parameters for compiling a geometry shader.
  *
- * Returns the final assembly and the program's size.
+ * Some of these will be modified during the shader compilation.
+ */
+struct brw_compile_gs_params {
+   nir_shader *nir;
+
+   const struct brw_gs_prog_key *key;
+   struct brw_gs_prog_data *prog_data;
+
+   struct brw_compile_stats *stats;
+
+   void *log_data;
+
+   char *error_str;
+};
+
+/**
+ * Compile a geometry shader.
+ *
+ * Returns the final assembly and updates the parameters structure.
  */
 const unsigned *
-brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
+brw_compile_gs(const struct brw_compiler *compiler,
                void *mem_ctx,
-               const struct brw_gs_prog_key *key,
-               struct brw_gs_prog_data *prog_data,
-               nir_shader *nir,
-               struct brw_compile_stats *stats,
-               char **error_str);
+               struct brw_compile_gs_params *params);
 
 /**
  * Compile a strips and fans shader.
diff --git a/src/intel/compiler/brw_vec4_gs_visitor.cpp b/src/intel/compiler/brw_vec4_gs_visitor.cpp
index 37a98397f1b..1b1cddc8fae 100644
--- a/src/intel/compiler/brw_vec4_gs_visitor.cpp
+++ b/src/intel/compiler/brw_vec4_gs_visitor.cpp
@@ -580,14 +580,14 @@ static const GLuint gl_prim_to_hw_prim[GL_TRIANGLE_STRIP_ADJACENCY+1] = {
 } /* namespace brw */
 
 extern "C" const unsigned *
-brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
+brw_compile_gs(const struct brw_compiler *compiler,
                void *mem_ctx,
-               const struct brw_gs_prog_key *key,
-               struct brw_gs_prog_data *prog_data,
-               nir_shader *nir,
-               struct brw_compile_stats *stats,
-               char **error_str)
+               struct brw_compile_gs_params *params)
 {
+   nir_shader *nir = params->nir;
+   const struct brw_gs_prog_key *key = params->key;
+   struct brw_gs_prog_data *prog_data = params->prog_data;
+
    struct brw_gs_compile c;
    memset(&c, 0, sizeof(c));
    c.key = *key;
@@ -816,13 +816,13 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
    }
 
    if (is_scalar) {
-      fs_visitor v(compiler, log_data, mem_ctx, &c, prog_data, nir,
+      fs_visitor v(compiler, params->log_data, mem_ctx, &c, prog_data, nir,
                    debug_enabled);
       if (v.run_gs()) {
          prog_data->base.dispatch_mode = DISPATCH_MODE_SIMD8;
          prog_data->base.base.dispatch_grf_start_reg = v.payload.num_regs;
 
-         fs_generator g(compiler, log_data, mem_ctx,
+         fs_generator g(compiler, params->log_data, mem_ctx,
                         &prog_data->base.base, false, MESA_SHADER_GEOMETRY);
          if (unlikely(debug_enabled)) {
             const char *label =
@@ -832,13 +832,12 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
             g.enable_debug(name);
          }
          g.generate_code(v.cfg, 8, v.shader_stats,
-                         v.performance_analysis.require(), stats);
+                         v.performance_analysis.require(), params->stats);
          g.add_const_data(nir->constant_data, nir->constant_data_size);
          return g.get_assembly();
       }
 
-      if (error_str)
-         *error_str = ralloc_strdup(mem_ctx, v.fail_msg);
+      params->error_str = ralloc_strdup(mem_ctx, v.fail_msg);
 
       return NULL;
    }
@@ -852,7 +851,7 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
           !INTEL_DEBUG(DEBUG_NO_DUAL_OBJECT_GS)) {
          prog_data->base.dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
 
-         brw::vec4_gs_visitor v(compiler, log_data, &c, prog_data, nir,
+         brw::vec4_gs_visitor v(compiler, params->log_data, &c, prog_data, nir,
                                 mem_ctx, true /* no_spills */,
                                 debug_enabled);
 
@@ -869,11 +868,11 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
          if (v.run()) {
             /* Success! Backup is not needed */
             ralloc_free(param);
-            return brw_vec4_generate_assembly(compiler, log_data, mem_ctx,
+            return brw_vec4_generate_assembly(compiler, params->log_data, mem_ctx,
                                               nir, &prog_data->base,
                                               v.cfg,
                                               v.performance_analysis.require(),
-                                              stats, debug_enabled);
+                                              params->stats, debug_enabled);
          } else {
             /* These variables could be modified by the execution of the GS
              * visitor if it packed the uniforms in the push constant buffer.
@@ -922,22 +921,21 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
    const unsigned *ret = NULL;
 
    if (compiler->devinfo->ver >= 7)
-      gs = new brw::vec4_gs_visitor(compiler, log_data, &c, prog_data,
+      gs = new brw::vec4_gs_visitor(compiler, params->log_data, &c, prog_data,
                                     nir, mem_ctx, false /* no_spills */,
                                     debug_enabled);
    else
-      gs = new brw::gfx6_gs_visitor(compiler, log_data, &c, prog_data,
+      gs = new brw::gfx6_gs_visitor(compiler, params->log_data, &c, prog_data,
                                     nir, mem_ctx, false /* no_spills */,
                                     debug_enabled);
 
    if (!gs->run()) {
-      if (error_str)
-         *error_str = ralloc_strdup(mem_ctx, gs->fail_msg);
+      params->error_str = ralloc_strdup(mem_ctx, gs->fail_msg);
    } else {
-      ret = brw_vec4_generate_assembly(compiler, log_data, mem_ctx, nir,
+      ret = brw_vec4_generate_assembly(compiler, params->log_data, mem_ctx, nir,
                                        &prog_data->base, gs->cfg,
                                        gs->performance_analysis.require(),
-                                       stats, debug_enabled);
+                                       params->stats, debug_enabled);
    }
 
    delete gs;
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 2c315f99cfb..dd57a31a906 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -1079,11 +1079,16 @@ anv_pipeline_compile_gs(const struct brw_compiler *compiler,
                        gs_stage->nir->info.separate_shader, 1);
 
    gs_stage->num_stats = 1;
-   gs_stage->code = brw_compile_gs(compiler, device, mem_ctx,
-                                   &gs_stage->key.gs,
-                                   &gs_stage->prog_data.gs,
-                                   gs_stage->nir,
-                                   gs_stage->stats, NULL);
+
+   struct brw_compile_gs_params params = {
+      .nir = gs_stage->nir,
+      .key = &gs_stage->key.gs,
+      .prog_data = &gs_stage->prog_data.gs,
+      .stats = gs_stage->stats,
+      .log_data = device,
+   };
+
+   gs_stage->code = brw_compile_gs(compiler, mem_ctx, &params);
 }
 
 static void



More information about the mesa-commit mailing list