[Mesa-dev] [PATCH 03/31] mesa: replace ctx->VertexProgram._TwoSideEnabled with a helper function

Marek Olšák maraeo at gmail.com
Mon Jun 12 16:55:28 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/drivers/dri/i965/brw_sf.c            |  4 ++--
 src/mesa/drivers/dri/i965/genX_state_upload.c |  3 ++-
 src/mesa/main/mtypes.h                        |  2 --
 src/mesa/main/state.c                         | 19 -------------------
 src/mesa/main/state.h                         | 11 +++++++++++
 src/mesa/state_tracker/st_atom_rasterizer.c   |  3 ++-
 6 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c
index 0739306..d92b519 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -27,20 +27,21 @@
  /*
   * Authors:
   *   Keith Whitwell <keithw at vmware.com>
   */
 
 #include "compiler/nir/nir.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/enums.h"
 #include "main/fbobject.h"
+#include "main/state.h"
 
 #include "intel_batchbuffer.h"
 
 #include "brw_defines.h"
 #include "brw_context.h"
 #include "brw_util.h"
 #include "brw_state.h"
 #include "compiler/brw_eu.h"
 
 #include "util/ralloc.h"
@@ -145,22 +146,21 @@ brw_upload_sf_prog(struct brw_context *brw)
    if (wm_prog_data) {
       key.contains_flat_varying = wm_prog_data->contains_flat_varying;
 
       STATIC_ASSERT(sizeof(key.interp_mode) ==
                     sizeof(wm_prog_data->interp_mode));
       memcpy(key.interp_mode, wm_prog_data->interp_mode,
              sizeof(key.interp_mode));
    }
 
    /* _NEW_LIGHT | _NEW_PROGRAM */
-   key.do_twoside_color = ((ctx->Light.Enabled && ctx->Light.Model.TwoSide) ||
-                           ctx->VertexProgram._TwoSideEnabled);
+   key.do_twoside_color = _mesa_vertex_program_two_side_enabled(ctx);
 
    /* _NEW_POLYGON */
    if (key.do_twoside_color) {
       /* If we're rendering to a FBO, we have to invert the polygon
        * face orientation, just as we invert the viewport in
        * sf_unit_create_from_key().
        */
       key.frontface_ccw = ctx->Polygon._FrontBit == render_to_fbo;
    }
 
diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index 6598f1f..a6e02e3 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -24,20 +24,21 @@
 #include <assert.h>
 
 #include "common/gen_device_info.h"
 #include "common/gen_sample_positions.h"
 #include "genxml/gen_macros.h"
 
 #include "main/bufferobj.h"
 #include "main/context.h"
 #include "main/enums.h"
 #include "main/macros.h"
+#include "main/state.h"
 
 #include "brw_context.h"
 #if GEN_GEN == 6
 #include "brw_defines.h"
 #endif
 #include "brw_draw.h"
 #include "brw_multisample_state.h"
 #include "brw_state.h"
 #include "brw_wm.h"
 #include "brw_util.h"
@@ -1087,21 +1088,21 @@ genX(calculate_attr_overrides)(const struct brw_context *brw,
             *point_sprite_enables |= (1 << input_index);
       }
 
       /* BRW_NEW_VUE_MAP_GEOM_OUT | _NEW_LIGHT | _NEW_PROGRAM */
       struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL) attribute = { 0 };
 
       if (!point_sprite) {
          genX(get_attr_override)(&attribute,
                                  &brw->vue_map_geom_out,
                                  *urb_entry_read_offset, attr,
-                                 brw->ctx.VertexProgram._TwoSideEnabled,
+                                 _mesa_vertex_program_two_side_enabled(ctx),
                                  &max_source_attr);
       }
 
       /* The hardware can only do the overrides on 16 overrides at a
        * time, and the other up to 16 have to be lined up so that the
        * input index = the output index.  We'll need to do some
        * tweaking to make sure that's the case.
        */
       if (input_index < 16)
          attr_overrides[input_index] = attribute;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 283215f..1a8ae28 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2181,22 +2181,20 @@ struct gl_program_state
 
 /**
  * Context state for vertex programs.
  */
 struct gl_vertex_program_state
 {
    GLboolean Enabled;            /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
    GLboolean _Enabled;           /**< Enabled and _valid_ user program? */
    GLboolean PointSizeEnabled;   /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
    GLboolean TwoSideEnabled;     /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
-   /** Computed two sided lighting for fixed function/programs. */
-   GLboolean _TwoSideEnabled;
    struct gl_program *Current;  /**< User-bound vertex program */
 
    /** Currently enabled and valid vertex program (including internal
     * programs, user-defined vertex programs and GLSL vertex shaders).
     * This is the program we must use when rendering.
     */
    struct gl_program *_Current;
 
    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index d1d0c2c..0772e6b 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -283,36 +283,20 @@ static void
 update_frontbit(struct gl_context *ctx)
 {
    if (ctx->Transform.ClipOrigin == GL_LOWER_LEFT)
       ctx->Polygon._FrontBit = (ctx->Polygon.FrontFace == GL_CW);
    else
       ctx->Polygon._FrontBit = (ctx->Polygon.FrontFace == GL_CCW);
 }
 
 
 /**
- * Update the ctx->VertexProgram._TwoSideEnabled flag.
- */
-static void
-update_twoside(struct gl_context *ctx)
-{
-   if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] ||
-       ctx->VertexProgram._Enabled) {
-      ctx->VertexProgram._TwoSideEnabled = ctx->VertexProgram.TwoSideEnabled;
-   } else {
-      ctx->VertexProgram._TwoSideEnabled = (ctx->Light.Enabled &&
-					    ctx->Light.Model.TwoSide);
-   }
-}
-
-
-/**
  * Compute derived GL state.
  * If __struct gl_contextRec::NewState is non-zero then this function \b must
  * be called before rendering anything.
  *
  * Calls dd_function_table::UpdateState to perform any internal state
  * management necessary.
  * 
  * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
  * _mesa_update_buffer_bounds(),
  * _mesa_update_lighting() and _mesa_update_tnl_spaces().
@@ -369,23 +353,20 @@ _mesa_update_state_locked( struct gl_context *ctx )
 
    if (new_state & _NEW_BUFFERS)
       _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer);
 
    if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
       _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
 
    if (new_state & _NEW_LIGHT)
       _mesa_update_lighting( ctx );
 
-   if (new_state & (_NEW_LIGHT | _NEW_PROGRAM))
-      update_twoside( ctx );
-
    if (new_state & _NEW_PIXEL)
       _mesa_update_pixel( ctx );
 
    /* ctx->_NeedEyeCoords is now up to date.
     *
     * If the truth value of this variable has changed, update for the
     * new lighting space and recompute the positions of lights and the
     * normal transform.
     *
     * If the lighting space hasn't changed, may still need to recompute
diff --git a/src/mesa/main/state.h b/src/mesa/main/state.h
index 7a6cdac..8817a47 100644
--- a/src/mesa/main/state.h
+++ b/src/mesa/main/state.h
@@ -65,11 +65,22 @@ _mesa_need_secondary_color(const struct gl_context *ctx)
       return GL_TRUE;
 
    if (ctx->FragmentProgram._Current &&
        (ctx->FragmentProgram._Current != ctx->FragmentProgram._TexEnvProgram) &&
        (ctx->FragmentProgram._Current->info.inputs_read & VARYING_BIT_COL1))
       return GL_TRUE;
 
    return GL_FALSE;
 }
 
+/** Compute two sided lighting state for fixed function or programs. */
+static inline bool
+_mesa_vertex_program_two_side_enabled(const struct gl_context *ctx)
+{
+   if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] ||
+       ctx->VertexProgram._Enabled)
+      return ctx->VertexProgram.TwoSideEnabled;
+
+   return ctx->Light.Enabled && ctx->Light.Model.TwoSide;
+}
+
 #endif
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c
index 42696b1..6e17562 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -25,20 +25,21 @@
  * 
  **************************************************************************/
 
  /*
   * Authors:
   *   Keith Whitwell <keithw at vmware.com>
   */
  
 #include "main/macros.h"
 #include "main/framebuffer.h"
+#include "main/state.h"
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_debug.h"
 #include "st_program.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "cso_cache/cso_context.h"
 
 
 static GLuint translate_fill( GLenum mode )
@@ -92,21 +93,21 @@ void st_update_rasterizer( struct st_context *st )
    }
 
    /* _NEW_LIGHT
     */
    raster->flatshade = ctx->Light.ShadeModel == GL_FLAT;
       
    raster->flatshade_first = ctx->Light.ProvokingVertex ==
                              GL_FIRST_VERTEX_CONVENTION_EXT;
 
    /* _NEW_LIGHT | _NEW_PROGRAM */
-   raster->light_twoside = ctx->VertexProgram._TwoSideEnabled;
+   raster->light_twoside = _mesa_vertex_program_two_side_enabled(ctx);
 
    /*_NEW_LIGHT | _NEW_BUFFERS */
    raster->clamp_vertex_color = !st->clamp_vert_color_in_shader &&
                                 ctx->Light._ClampVertexColor;
 
    /* _NEW_POLYGON
     */
    if (ctx->Polygon.CullFlag) {
       switch (ctx->Polygon.CullFaceMode) {
       case GL_FRONT:
-- 
2.7.4



More information about the mesa-dev mailing list