[Mesa-dev] [PATCH 18/53] mesa: make _CurrentFragmentProgram a gl_program struct pointer

Timothy Arceri timothy.arceri at collabora.com
Tue Jan 3 02:43:22 UTC 2017


Making this point to a gl_program struct rather than a gl_shader_program
struct will allow use to later also make the CurrentProgram array hold
gl_program structs which in turn will allow for code simpilifcation.

Reviewed-by: Eric Anholt <eric at anholt.net>
---
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c |  8 ++------
 src/mesa/main/api_validate.c                     |  6 ++----
 src/mesa/main/mtypes.h                           |  2 +-
 src/mesa/main/pipelineobj.c                      |  2 +-
 src/mesa/main/shaderapi.c                        | 14 ++++++++------
 src/mesa/main/state.c                            | 20 ++++++++------------
 6 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index eff19de..4566696 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -1438,14 +1438,10 @@ brw_upload_wm_ubo_surfaces(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
    /* _NEW_PROGRAM */
-   struct gl_shader_program *prog = ctx->_Shader->_CurrentFragmentProgram;
-
-   if (!prog || !prog->_LinkedShaders[MESA_SHADER_FRAGMENT])
-      return;
+   struct gl_program *prog = ctx->_Shader->_CurrentFragmentProgram;
 
    /* BRW_NEW_FS_PROG_DATA */
-   brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program,
-                           &brw->wm.base, brw->wm.base.prog_data);
+   brw_upload_ubo_surfaces(brw, prog, &brw->wm.base, brw->wm.base.prog_data);
 }
 
 const struct brw_tracked_state brw_wm_ubo_surfaces = {
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index 42eeeba..5f051db 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -99,10 +99,8 @@ check_blend_func_error(struct gl_context *ctx)
        *     the blend equation or "blend_support_all_equations", the error
        *     INVALID_OPERATION is generated [...]"
        */
-      const struct gl_shader_program *sh_prog =
-         ctx->_Shader->_CurrentFragmentProgram;
-      const GLbitfield blend_support = !sh_prog ? 0 :
-         sh_prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->sh.fs.BlendSupport;
+      const struct gl_program *prog = ctx->_Shader->_CurrentFragmentProgram;
+      const GLbitfield blend_support = !prog ? 0 : prog->sh.fs.BlendSupport;
 
       if ((blend_support & ctx->Color._AdvancedBlendMode) == 0) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 31a11a8..2ce5d6b 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2921,7 +2921,7 @@ struct gl_pipeline_object
     */
    struct gl_shader_program *CurrentProgram[MESA_SHADER_STAGES];
 
-   struct gl_shader_program *_CurrentFragmentProgram;
+   struct gl_program *_CurrentFragmentProgram;
 
    /**
     * Program used by glUniform calls.
diff --git a/src/mesa/main/pipelineobj.c b/src/mesa/main/pipelineobj.c
index 5fc2808..9651a40 100644
--- a/src/mesa/main/pipelineobj.c
+++ b/src/mesa/main/pipelineobj.c
@@ -58,7 +58,7 @@ _mesa_delete_pipeline_object(struct gl_context *ctx,
 {
    unsigned i;
 
-   _mesa_reference_shader_program(ctx, &obj->_CurrentFragmentProgram, NULL);
+   _mesa_reference_program(ctx, &obj->_CurrentFragmentProgram, NULL);
 
    for (i = 0; i < MESA_SHADER_STAGES; i++)
       _mesa_reference_shader_program(ctx, &obj->CurrentProgram[i], NULL);
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index f910614..571b35b 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -161,8 +161,7 @@ _mesa_free_shader_state(struct gl_context *ctx)
       _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentProgram[i],
                                      NULL);
    }
-   _mesa_reference_shader_program(ctx, &ctx->Shader._CurrentFragmentProgram,
-				  NULL);
+   _mesa_reference_program(ctx, &ctx->Shader._CurrentFragmentProgram, NULL);
    _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, NULL);
 
    /* Extended for ARB_separate_shader_objects */
@@ -1230,10 +1229,13 @@ use_shader_program(struct gl_context *ctx, gl_shader_stage stage,
          /* Empty for now. */
          break;
       case MESA_SHADER_FRAGMENT:
-         if (*target == ctx->_Shader->_CurrentFragmentProgram) {
-	    _mesa_reference_shader_program(ctx,
-                                           &ctx->_Shader->_CurrentFragmentProgram,
-					   NULL);
+         if (*target != NULL &&
+             ((*target)->_LinkedShaders[MESA_SHADER_FRAGMENT] &&
+              (*target)->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program ==
+              ctx->_Shader->_CurrentFragmentProgram)) {
+	    _mesa_reference_program(ctx,
+                                    &ctx->_Shader->_CurrentFragmentProgram,
+                                    NULL);
 	 }
 	 break;
       }
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index e56f6e1..2a926a1 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -135,9 +135,8 @@ update_program(struct gl_context *ctx)
    if (fsProg && fsProg->data->LinkStatus
        && fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
       /* Use GLSL fragment shader */
-      _mesa_reference_shader_program(ctx,
-                                     &ctx->_Shader->_CurrentFragmentProgram,
-				     fsProg);
+      _mesa_reference_program(ctx, &ctx->_Shader->_CurrentFragmentProgram,
+                              fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
                               fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
@@ -145,9 +144,8 @@ update_program(struct gl_context *ctx)
    }
    else if (ctx->FragmentProgram._Enabled) {
       /* Use user-defined fragment program */
-      _mesa_reference_shader_program(ctx,
-                                     &ctx->_Shader->_CurrentFragmentProgram,
-				     NULL);
+      _mesa_reference_program(ctx, &ctx->_Shader->_CurrentFragmentProgram,
+                              NULL);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
                               ctx->FragmentProgram.Current);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
@@ -156,9 +154,8 @@ update_program(struct gl_context *ctx)
    else if (ctx->ATIFragmentShader._Enabled &&
             ctx->ATIFragmentShader.Current->Program) {
        /* Use the enabled ATI fragment shader's associated program */
-      _mesa_reference_shader_program(ctx,
-                                     &ctx->_Shader->_CurrentFragmentProgram,
-                                     NULL);
+      _mesa_reference_program(ctx, &ctx->_Shader->_CurrentFragmentProgram,
+                              NULL);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
                               ctx->ATIFragmentShader.Current->Program);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
@@ -168,9 +165,8 @@ update_program(struct gl_context *ctx)
       /* Use fragment program generated from fixed-function state */
       struct gl_shader_program *f = _mesa_get_fixed_func_fragment_program(ctx);
 
-      _mesa_reference_shader_program(ctx,
-                                     &ctx->_Shader->_CurrentFragmentProgram,
-				     f);
+      _mesa_reference_program(ctx, &ctx->_Shader->_CurrentFragmentProgram,
+                              f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
 			      f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
       _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
-- 
2.9.3



More information about the mesa-dev mailing list