Mesa (main): compiler: Extract num_mesh_vertices_per_primitive function.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Feb 14 18:36:38 UTC 2022


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

Author: Timur Kristóf <timur.kristof at gmail.com>
Date:   Mon Feb 14 10:44:28 2022 +0100

compiler: Extract num_mesh_vertices_per_primitive function.

Prevent code duplication.

Signed-off-by: Timur Kristóf <timur.kristof at gmail.com>
Reviewed-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15005>

---

 src/amd/common/ac_nir_lower_ngg.c |  7 ++-----
 src/compiler/shader_enums.c       | 15 +++++++++++++++
 src/compiler/shader_enums.h       |  5 +++++
 src/intel/compiler/brw_mesh.cpp   | 16 ++--------------
 4 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/amd/common/ac_nir_lower_ngg.c b/src/amd/common/ac_nir_lower_ngg.c
index 5b805f072f4..34f8c115d2c 100644
--- a/src/amd/common/ac_nir_lower_ngg.c
+++ b/src/amd/common/ac_nir_lower_ngg.c
@@ -2412,11 +2412,8 @@ ac_nir_lower_ngg_ms(nir_shader *shader,
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
    assert(impl);
 
-   unsigned vertices_per_prim = 3;
-   if (shader->info.mesh.primitive_type == SHADER_PRIM_POINTS)
-      vertices_per_prim = 1;
-   else if (shader->info.mesh.primitive_type == SHADER_PRIM_LINES)
-      vertices_per_prim = 2;
+   unsigned vertices_per_prim =
+      num_mesh_vertices_per_primitive(shader->info.mesh.primitive_type);
 
    uint64_t per_vertex_outputs = shader->info.outputs_written & ~shader->info.per_primitive_outputs
                                  & ~BITFIELD64_BIT(VARYING_SLOT_PRIMITIVE_COUNT)
diff --git a/src/compiler/shader_enums.c b/src/compiler/shader_enums.c
index 93fb7728c78..fcd5fd5e956 100644
--- a/src/compiler/shader_enums.c
+++ b/src/compiler/shader_enums.c
@@ -375,3 +375,18 @@ gl_frag_result_name(gl_frag_result result)
    STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
    return NAME(result);
 }
+
+unsigned
+num_mesh_vertices_per_primitive(unsigned prim)
+{
+   switch (prim) {
+      case SHADER_PRIM_POINTS:
+         return 1;
+      case SHADER_PRIM_LINES:
+         return 2;
+      case SHADER_PRIM_TRIANGLES:
+         return 3;
+      default:
+         unreachable("invalid mesh shader primitive type");
+   }
+}
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index cd944193ac7..098f370ce97 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -1045,6 +1045,11 @@ enum shader_prim
    SHADER_PRIM_UNKNOWN = (SHADER_PRIM_MAX * 2),
 };
 
+/**
+ * Number of vertices per mesh shader primitive.
+ */
+unsigned num_mesh_vertices_per_primitive(unsigned prim);
+
 /**
  * A compare function enum for use in compiler lowering passes.  This is in
  * the same order as GL's compare functions (shifted down by GL_NEVER), and is
diff --git a/src/intel/compiler/brw_mesh.cpp b/src/intel/compiler/brw_mesh.cpp
index c47162c9b9c..2c65015fe3a 100644
--- a/src/intel/compiler/brw_mesh.cpp
+++ b/src/intel/compiler/brw_mesh.cpp
@@ -300,20 +300,8 @@ brw_compute_mue_map(struct nir_shader *nir, struct brw_mue_map *map)
    for (int i = 0; i < VARYING_SLOT_MAX; i++)
       map->start_dw[i] = -1;
 
-   unsigned vertices_per_primitive = 0;
-   switch (nir->info.mesh.primitive_type) {
-   case SHADER_PRIM_POINTS:
-      vertices_per_primitive = 1;
-      break;
-   case SHADER_PRIM_LINES:
-      vertices_per_primitive = 2;
-      break;
-   case SHADER_PRIM_TRIANGLES:
-      vertices_per_primitive = 3;
-      break;
-   default:
-      unreachable("invalid primitive type");
-   }
+   unsigned vertices_per_primitive =
+      num_mesh_vertices_per_primitive(nir->info.mesh.primitive_type);
 
    map->max_primitives = nir->info.mesh.max_primitives_out;
    map->max_vertices = nir->info.mesh.max_vertices_out;



More information about the mesa-commit mailing list