mesa: Introduce a compiler enum for tessellation spacing.
authorKenneth Graunke <kenneth@whitecape.org>
Sun, 25 Sep 2016 00:59:55 +0000 (17:59 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Sun, 8 Jan 2017 06:22:28 +0000 (22:22 -0800)
It feels weird using GL_* enums in a Vulkan driver.

v2: Fix the TESS_SPACING -> PIPE_TESS_SPACING conversion.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Timothy Arceri <timothy.arceri@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/glsl/ast.h
src/compiler/glsl/glsl_parser.yy
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/linker.cpp
src/compiler/shader_enums.h
src/compiler/shader_info.h
src/mesa/drivers/dri/i965/brw_tcs.c
src/mesa/drivers/dri/i965/brw_tes.c
src/mesa/main/mtypes.h
src/mesa/main/shaderapi.c
src/mesa/state_tracker/st_program.c

index 0e32c36528e1439fe9e28db293527a671a6ba526..e3f629e3419395aad9651d4ea8585bdb8cd71ea3 100644 (file)
@@ -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;
index e3893d5ec3b259d61475ea688ded7916e9dbd845..519e35b6d532e700a2a03849d6788ae2b091cea8 100644 (file)
@@ -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) {
index e97cbf4b8260d943a3396dff98d2d7698e1568f9..1b84876079d682ae20b7a41659ce7cb7e61bc726 100644 (file)
@@ -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;
 
index d4a484fdea05bb8c13fd3a8e357df3bf9a5a9ae2..bf902bd862a3c8404608c13b8e8d00e28cda8422 100644 (file)
@@ -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;
index bb9f53d2e170a588b09b4abe5139dfb504a79857..98565c80cb8a547a9be963033c645587242ff51c 100644 (file)
@@ -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
index 24b1291f2f5fab2b836d6f42789afb0ba32a4de3..1dd687e9b890bc5b77de50ccf2a7cdaa51d9a847 100644 (file)
@@ -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;
index b6251d52f60971f1f96e0c49c1c7062c1f3566db..9e9d9eb00d2af5fe8c7e5202a75c4aa608d3b1d2 100644 (file)
@@ -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;
index 2dae1e57f416f16877e2fe05b70041017db44529..2729d29239b62cf9c25e701514430ff6fc4a2bb7 100644 (file)
@@ -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:
index dadedb145adda219780022ff5848f8ca2c71ae07..691323d8f3c0728d0173bd58f2910fbf991d9c6b 100644 (file)
@@ -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.
        */
index f198a3c6302cd1b88d275f9029bf0360a7afeb96..7771b7ce7da2f3ec674621b70307940895eba461 100644 (file)
@@ -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:
index 7d548d51c13385f339ab1f10638e4578dacbe8e4..96c6bb3fcf8ff8eca426c1c7c2aa2d6a13195ccf 100644 (file)
@@ -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 + 1) % 3 == PIPE_TESS_SPACING_EQUAL);
+   STATIC_ASSERT((TESS_SPACING_FRACTIONAL_ODD + 1) % 3 ==
+                 PIPE_TESS_SPACING_FRACTIONAL_ODD);
+   STATIC_ASSERT((TESS_SPACING_FRACTIONAL_EVEN + 1) % 3 ==
+                 PIPE_TESS_SPACING_FRACTIONAL_EVEN);
+
+   ureg_property(ureg, TGSI_PROPERTY_TES_SPACING,
+                 (sttep->Base.info.tes.spacing + 1) % 3);
 
    ureg_property(ureg, TGSI_PROPERTY_TES_VERTEX_ORDER_CW,
                  !sttep->Base.info.tes.ccw);