mesa: make _CurrentFragmentProgram a gl_program struct pointer
authorTimothy Arceri <timothy.arceri@collabora.com>
Thu, 3 Nov 2016 22:25:36 +0000 (09:25 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Fri, 6 Jan 2017 00:21:42 +0000 (11:21 +1100)
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@anholt.net>
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/main/api_validate.c
src/mesa/main/mtypes.h
src/mesa/main/pipelineobj.c
src/mesa/main/shaderapi.c
src/mesa/main/state.c

index eff19de06c0c689a1d66278b22b0233cf564f0bf..4566696fa98dafda8da740770422174476b03ad6 100644 (file)
@@ -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 = {
index 42eeeba1414e5d8ea397d65b089681c9bef4a984..5f051dbec6f127b4c0d215fb6560386daa1a422d 100644 (file)
@@ -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,
index 40a240c961c56923b089a6d3c87d7870f4a7ab22..ffd21ecea3bf4428927fd235719bf3308349f4e6 100644 (file)
@@ -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.
index 5fc2808a0c85a8d5bc6c79b78a450882a6802f2b..9651a40dbb8ed122e6d0d6b4b4b241d79672f713 100644 (file)
@@ -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);
index f9106140770dd7d0717bdfa72bc1c130c8917919..571b35be58b4d6cc95953343ebbba02ff3d15640 100644 (file)
@@ -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;
       }
index e56f6e136d3b0fb216470ba90c53756e105a524b..2a926a182b942dcd73f6d7e45ea52b563db11e4a 100644 (file)
@@ -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,