[Mesa-dev] [PATCH 2/6] mesa: Introduce a compiler enum for tessellation spacing.

Kenneth Graunke kenneth at whitecape.org
Sat Jan 7 08:02:55 UTC 2017


It feels weird using GL_* enums in a Vulkan driver.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/compiler/glsl/ast.h                  |  2 +-
 src/compiler/glsl/glsl_parser.yy         |  8 ++++----
 src/compiler/glsl/glsl_parser_extras.cpp |  2 +-
 src/compiler/glsl/linker.cpp             |  6 +++---
 src/compiler/shader_enums.h              |  8 ++++++++
 src/compiler/shader_info.h               |  2 +-
 src/mesa/drivers/dri/i965/brw_tcs.c      |  4 ++--
 src/mesa/drivers/dri/i965/brw_tes.c      | 20 +++++++-------------
 src/mesa/main/mtypes.h                   |  8 +++-----
 src/mesa/main/shaderapi.c                | 18 ++++++++++++++++--
 src/mesa/state_tracker/st_program.c      | 23 ++++++++---------------
 11 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h
index 0e32c36528e..e3f629e3419 100644
--- a/src/compiler/glsl/ast.h
+++ b/src/compiler/glsl/ast.h
@@ -704,7 +704,7 @@ struct ast_type_qualifier {
    ast_layout_expression *local_size[3];
 
    /** Tessellation evaluation shader: vertex spacing (equal, fractional even/odd) */
-   GLenum vertex_spacing;
+   enum gl_tess_spacing vertex_spacing;
 
    /** Tessellation evaluation shader: vertex ordering (CW or CCW) */
    GLenum ordering;
diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy
index e3893d5ec3b..519e35b6d53 100644
--- a/src/compiler/glsl/glsl_parser.yy
+++ b/src/compiler/glsl/glsl_parser.yy
@@ -1463,11 +1463,11 @@ layout_qualifier_id:
       if (!$$.flags.i) {
          static const struct {
             const char *s;
-            GLenum e;
+            enum gl_tess_spacing e;
          } map[] = {
-                 { "equal_spacing", GL_EQUAL },
-                 { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
-                 { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
+                 { "equal_spacing", TESS_SPACING_EQUAL },
+                 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
+                 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
          };
          for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
             if (match_layout_qualifier($1, map[i].s, state) == 0) {
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index e97cbf4b826..1b84876079d 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1732,7 +1732,7 @@ set_shader_inout_layout(struct gl_shader *shader,
       if (state->in_qualifier->flags.q.prim_type)
          shader->info.TessEval.PrimitiveMode = state->in_qualifier->prim_type;
 
-      shader->info.TessEval.Spacing = 0;
+      shader->info.TessEval.Spacing = TESS_SPACING_UNSPECIFIED;
       if (state->in_qualifier->flags.q.vertex_spacing)
          shader->info.TessEval.Spacing = state->in_qualifier->vertex_spacing;
 
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index ef2b01e17d7..fa6de5a3150 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -1721,7 +1721,7 @@ link_tes_in_layout_qualifiers(struct gl_shader_program *prog,
                               unsigned num_shaders)
 {
    linked_shader->info.TessEval.PrimitiveMode = PRIM_UNKNOWN;
-   linked_shader->info.TessEval.Spacing = 0;
+   linked_shader->info.TessEval.Spacing = TESS_SPACING_UNSPECIFIED;
    linked_shader->info.TessEval.VertexOrder = 0;
    linked_shader->info.TessEval.PointMode = -1;
 
@@ -1804,8 +1804,8 @@ link_tes_in_layout_qualifiers(struct gl_shader_program *prog,
       return;
    }
 
-   if (linked_shader->info.TessEval.Spacing == 0)
-      linked_shader->info.TessEval.Spacing = GL_EQUAL;
+   if (linked_shader->info.TessEval.Spacing == TESS_SPACING_UNSPECIFIED)
+      linked_shader->info.TessEval.Spacing = TESS_SPACING_EQUAL;
 
    if (linked_shader->info.TessEval.VertexOrder == 0)
       linked_shader->info.TessEval.VertexOrder = GL_CCW;
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index bb9f53d2e17..98565c80cb8 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -591,6 +591,14 @@ enum gl_advanced_blend_mode
    BLEND_ALL            = 0x7fff,
 };
 
+enum gl_tess_spacing
+{
+   TESS_SPACING_UNSPECIFIED,
+   TESS_SPACING_EQUAL,
+   TESS_SPACING_FRACTIONAL_ODD,
+   TESS_SPACING_FRACTIONAL_EVEN,
+};
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index 24b1291f2f5..1dd687e9b89 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -149,7 +149,7 @@ typedef struct shader_info {
 
       struct {
          uint32_t primitive_mode; /* GL_TRIANGLES, GL_QUADS or GL_ISOLINES */
-         uint32_t spacing;        /* GL_EQUAL, GL_FRACTIONAL_EVEN, GL_FRACTIONAL_ODD */
+         enum gl_tess_spacing spacing;
          /** Is the vertex order counterclockwise? */
          bool ccw;
          bool point_mode;
diff --git a/src/mesa/drivers/dri/i965/brw_tcs.c b/src/mesa/drivers/dri/i965/brw_tcs.c
index b6251d52f60..9e9d9eb00d2 100644
--- a/src/mesa/drivers/dri/i965/brw_tcs.c
+++ b/src/mesa/drivers/dri/i965/brw_tcs.c
@@ -331,7 +331,7 @@ brw_tcs_populate_key(struct brw_context *brw,
    key->tes_primitive_mode = tep->program.info.tes.primitive_mode;
    key->quads_workaround = brw->gen < 9 &&
                            tep->program.info.tes.primitive_mode == GL_QUADS &&
-                           tep->program.info.tes.spacing == GL_EQUAL;
+                           tep->program.info.tes.spacing == TESS_SPACING_EQUAL;
 
    if (tcp) {
       key->program_string_id = tcp->id;
@@ -403,7 +403,7 @@ brw_tcs_precompile(struct gl_context *ctx,
       key.tes_primitive_mode = tes->info.TessEval.PrimitiveMode;
       key.quads_workaround = brw->gen < 9 &&
                              tes->info.TessEval.PrimitiveMode == GL_QUADS &&
-                             tes->info.TessEval.Spacing == GL_EQUAL;
+                             tes->info.TessEval.Spacing == TESS_SPACING_EQUAL;
    } else {
       btep = NULL;
       key.tes_primitive_mode = GL_TRIANGLES;
diff --git a/src/mesa/drivers/dri/i965/brw_tes.c b/src/mesa/drivers/dri/i965/brw_tes.c
index 2dae1e57f41..2729d29239b 100644
--- a/src/mesa/drivers/dri/i965/brw_tes.c
+++ b/src/mesa/drivers/dri/i965/brw_tes.c
@@ -93,19 +93,13 @@ brw_codegen_tes_prog(struct brw_context *brw,
    brw_assign_common_binding_table_offsets(devinfo, &tep->program,
                                            &prog_data.base.base, 0);
 
-   switch (tep->program.info.tes.spacing) {
-   case GL_EQUAL:
-      prog_data.partitioning = BRW_TESS_PARTITIONING_INTEGER;
-      break;
-   case GL_FRACTIONAL_ODD:
-      prog_data.partitioning = BRW_TESS_PARTITIONING_ODD_FRACTIONAL;
-      break;
-   case GL_FRACTIONAL_EVEN:
-      prog_data.partitioning = BRW_TESS_PARTITIONING_EVEN_FRACTIONAL;
-      break;
-   default:
-      unreachable("invalid domain shader spacing");
-   }
+   STATIC_ASSERT(BRW_TESS_PARTITIONING_INTEGER == TESS_SPACING_EQUAL - 1);
+   STATIC_ASSERT(BRW_TESS_PARTITIONING_ODD_FRACTIONAL ==
+                 TESS_SPACING_FRACTIONAL_ODD - 1);
+   STATIC_ASSERT(BRW_TESS_PARTITIONING_EVEN_FRACTIONAL ==
+                 TESS_SPACING_FRACTIONAL_EVEN - 1);
+
+   prog_data.partitioning = tep->program.info.tes.spacing - 1;
 
    switch (tep->program.info.tes.primitive_mode) {
    case GL_QUADS:
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index dadedb145ad..691323d8f3c 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2279,11 +2279,9 @@ struct gl_shader_info
        * in this shader.
        */
       GLenum PrimitiveMode;
-      /**
-       * GL_EQUAL, GL_FRACTIONAL_ODD, GL_FRACTIONAL_EVEN, or 0 if it's not set
-       * in this shader.
-       */
-      GLenum Spacing;
+
+      enum gl_tess_spacing Spacing;
+
       /**
        * GL_CW, GL_CCW, or 0 if it's not set in this shader.
        */
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index f198a3c6302..7771b7ce7da 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -838,8 +838,22 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
       if (!has_tess)
          break;
       if (check_tes_query(ctx, shProg)) {
-         *params = shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL]->
-            info.TessEval.Spacing;
+         const struct gl_linked_shader *tes =
+            shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL];
+         switch (tes->info.TessEval.Spacing) {
+         case TESS_SPACING_EQUAL:
+            *params = GL_EQUAL;
+            break;
+         case TESS_SPACING_FRACTIONAL_ODD:
+            *params = GL_FRACTIONAL_ODD;
+            break;
+         case TESS_SPACING_FRACTIONAL_EVEN:
+            *params = GL_FRACTIONAL_EVEN;
+            break;
+         case TESS_SPACING_UNSPECIFIED:
+            *params = 0;
+            break;
+         }
       }
       return;
    case GL_TESS_GEN_VERTEX_ORDER:
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 7d548d51c13..544cbb0bbd5 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1607,21 +1607,14 @@ st_translate_tesseval_program(struct st_context *st,
       ureg_property(ureg, TGSI_PROPERTY_TES_PRIM_MODE,
                     sttep->Base.info.tes.primitive_mode);
 
-   switch (sttep->Base.info.tes.spacing) {
-   case GL_EQUAL:
-      ureg_property(ureg, TGSI_PROPERTY_TES_SPACING, PIPE_TESS_SPACING_EQUAL);
-      break;
-   case GL_FRACTIONAL_EVEN:
-      ureg_property(ureg, TGSI_PROPERTY_TES_SPACING,
-                    PIPE_TESS_SPACING_FRACTIONAL_EVEN);
-      break;
-   case GL_FRACTIONAL_ODD:
-      ureg_property(ureg, TGSI_PROPERTY_TES_SPACING,
-                    PIPE_TESS_SPACING_FRACTIONAL_ODD);
-      break;
-   default:
-      assert(0);
-   }
+   STATIC_ASSERT((TESS_SPACING_EQUAL - 2) % 3 == PIPE_TESS_SPACING_EQUAL);
+   STATIC_ASSERT((TESS_SPACING_FRACTIONAL_ODD - 2) % 3 ==
+                 PIPE_TESS_SPACING_FRACTIONAL_ODD);
+   STATIC_ASSERT((TESS_SPACING_FRACTIONAL_EVEN - 2) % 3 ==
+                 PIPE_TESS_SPACING_FRACTIONAL_EVEN);
+
+   ureg_property(ureg, TGSI_PROPERTY_TES_SPACING,
+                 (sttep->Base.info.tes.spacing - 2) % 3);
 
    ureg_property(ureg, TGSI_PROPERTY_TES_VERTEX_ORDER_CW,
                  !sttep->Base.info.tes.ccw);
-- 
2.11.0



More information about the mesa-dev mailing list