st/mesa: simplify code due to unification to st_common_program
authorMarek Olšák <marek.olsak@amd.com>
Sun, 30 Apr 2017 14:31:07 +0000 (16:31 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 8 May 2017 16:32:00 +0000 (18:32 +0200)
v2: use the st_common_program() helper

Tested-by: Edmondo Tommasina <edmondo.tommasina@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_cb_program.c
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_shader_cache.c

index 531d20d20ff7737a94e6782a43709dc529507a74..555fc5d5ad9bc3c7c4f55a5d7b91d4c7448d0a8d 100644 (file)
@@ -68,19 +68,11 @@ st_new_program(struct gl_context *ctx, GLenum target, GLuint id,
                                                  struct st_fragment_program);
       return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
+   case GL_TESS_CONTROL_PROGRAM_NV:
+   case GL_TESS_EVALUATION_PROGRAM_NV:
    case GL_GEOMETRY_PROGRAM_NV: {
       struct st_common_program *prog = rzalloc(NULL,
-                                                 struct st_common_program);
-      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
-   }
-   case GL_TESS_CONTROL_PROGRAM_NV: {
-      struct st_common_program *prog = rzalloc(NULL,
-                                                 struct st_common_program);
-      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
-   }
-   case GL_TESS_EVALUATION_PROGRAM_NV: {
-      struct st_common_program *prog = rzalloc(NULL,
-                                                 struct st_common_program);
+                                               struct st_common_program);
       return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    case GL_COMPUTE_PROGRAM_NV: {
@@ -113,16 +105,17 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
             free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi);
       }
       break;
+   case GL_TESS_CONTROL_PROGRAM_NV:
+   case GL_TESS_EVALUATION_PROGRAM_NV:
    case GL_GEOMETRY_PROGRAM_NV:
       {
-         struct st_common_program *stgp =
-            (struct st_common_program *) prog;
+         struct st_common_program *p = st_common_program(prog);
 
-         st_release_basic_variants(st, stgp->Base.Target, &stgp->variants,
-                                   &stgp->tgsi);
+         st_release_basic_variants(st, p->Base.Target, &p->variants,
+                                   &p->tgsi);
          
-         if (stgp->glsl_to_tgsi)
-            free_glsl_to_tgsi_visitor(stgp->glsl_to_tgsi);
+         if (p->glsl_to_tgsi)
+            free_glsl_to_tgsi_visitor(p->glsl_to_tgsi);
       }
       break;
    case GL_FRAGMENT_PROGRAM_ARB:
@@ -136,30 +129,6 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
             free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
       }
       break;
-   case GL_TESS_CONTROL_PROGRAM_NV:
-      {
-         struct st_common_program *sttcp =
-            (struct st_common_program *) prog;
-
-         st_release_basic_variants(st, sttcp->Base.Target, &sttcp->variants,
-                                   &sttcp->tgsi);
-
-         if (sttcp->glsl_to_tgsi)
-            free_glsl_to_tgsi_visitor(sttcp->glsl_to_tgsi);
-      }
-      break;
-   case GL_TESS_EVALUATION_PROGRAM_NV:
-      {
-         struct st_common_program *sttep =
-            (struct st_common_program *) prog;
-
-         st_release_basic_variants(st, sttep->Base.Target,
-                                   &sttep->variants, &sttep->tgsi);
-
-         if (sttep->glsl_to_tgsi)
-            free_glsl_to_tgsi_visitor(sttep->glsl_to_tgsi);
-      }
-      break;
    case GL_COMPUTE_PROGRAM_NV:
       {
          struct st_compute_program *stcp =
@@ -204,7 +173,7 @@ st_program_string_notify( struct gl_context *ctx,
         st->dirty |= stfp->affected_states;
    }
    else if (target == GL_GEOMETRY_PROGRAM_NV) {
-      struct st_common_program *stgp = (struct st_common_program *) prog;
+      struct st_common_program *stgp = st_common_program(prog);
 
       st_release_basic_variants(st, stgp->Base.Target, &stgp->variants,
                                 &stgp->tgsi);
@@ -226,7 +195,7 @@ st_program_string_notify( struct gl_context *ctx,
    }
    else if (target == GL_TESS_CONTROL_PROGRAM_NV) {
       struct st_common_program *sttcp =
-         (struct st_common_program *) prog;
+         st_common_program(prog);
 
       st_release_basic_variants(st, sttcp->Base.Target, &sttcp->variants,
                                 &sttcp->tgsi);
@@ -238,7 +207,7 @@ st_program_string_notify( struct gl_context *ctx,
    }
    else if (target == GL_TESS_EVALUATION_PROGRAM_NV) {
       struct st_common_program *sttep =
-         (struct st_common_program *) prog;
+         st_common_program(prog);
 
       st_release_basic_variants(st, sttep->Base.Target, &sttep->variants,
                                 &sttep->tgsi);
index 0a8782ec364f0c7b230102269b5b69ff98646351..f3e8e337982551f41da3668a8986389b81df2d8c 100644 (file)
@@ -6830,9 +6830,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
 
    struct st_vertex_program *stvp;
    struct st_fragment_program *stfp;
-   struct st_common_program *stgp;
-   struct st_common_program *sttcp;
-   struct st_common_program *sttep;
+   struct st_common_program *stp;
    struct st_compute_program *stcp;
 
    switch (shader->Stage) {
@@ -6844,17 +6842,11 @@ get_mesa_program_tgsi(struct gl_context *ctx,
       stfp = (struct st_fragment_program *)prog;
       stfp->glsl_to_tgsi = v;
       break;
-   case MESA_SHADER_GEOMETRY:
-      stgp = (struct st_common_program *)prog;
-      stgp->glsl_to_tgsi = v;
-      break;
    case MESA_SHADER_TESS_CTRL:
-      sttcp = (struct st_common_program *)prog;
-      sttcp->glsl_to_tgsi = v;
-      break;
    case MESA_SHADER_TESS_EVAL:
-      sttep = (struct st_common_program *)prog;
-      sttep->glsl_to_tgsi = v;
+   case MESA_SHADER_GEOMETRY:
+      stp = st_common_program(prog);
+      stp->glsl_to_tgsi = v;
       break;
    case MESA_SHADER_COMPUTE:
       stcp = (struct st_compute_program *)prog;
index 09e6696782f9045e6f6315710b63ad47fd252404..6de61741dcf60a30a91d50818ae24b176b3f37e1 100644 (file)
@@ -120,7 +120,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       break;
 
    case MESA_SHADER_TESS_CTRL:
-      states = &((struct st_common_program*)prog)->affected_states;
+      states = &(st_common_program(prog))->affected_states;
 
       *states = ST_NEW_TCS_STATE;
 
@@ -135,7 +135,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       break;
 
    case MESA_SHADER_TESS_EVAL:
-      states = &((struct st_common_program*)prog)->affected_states;
+      states = &(st_common_program(prog))->affected_states;
 
       *states = ST_NEW_TES_STATE |
                 ST_NEW_RASTERIZER;
@@ -151,7 +151,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       break;
 
    case MESA_SHADER_GEOMETRY:
-      states = &((struct st_common_program*)prog)->affected_states;
+      states = &(st_common_program(prog))->affected_states;
 
       *states = ST_NEW_GS_STATE |
                 ST_NEW_RASTERIZER;
@@ -1918,16 +1918,11 @@ destroy_program_variants(struct st_context *st, struct gl_program *target)
    case GL_TESS_EVALUATION_PROGRAM_NV:
    case GL_COMPUTE_PROGRAM_NV:
       {
-         struct st_common_program *gp = (struct st_common_program*)target;
-         struct st_common_program *tcp = (struct st_common_program*)target;
-         struct st_common_program *tep = (struct st_common_program*)target;
+         struct st_common_program *p = st_common_program(target);
          struct st_compute_program *cp = (struct st_compute_program*)target;
          struct st_basic_variant **variants =
-            target->Target == GL_GEOMETRY_PROGRAM_NV ? &gp->variants :
-            target->Target == GL_TESS_CONTROL_PROGRAM_NV ? &tcp->variants :
-            target->Target == GL_TESS_EVALUATION_PROGRAM_NV ? &tep->variants :
             target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants :
-            NULL;
+                                                      &p->variants;
          struct st_basic_variant *v, **prevPtr = variants;
 
          for (v = *variants; v; ) {
@@ -2066,19 +2061,19 @@ st_precompile_shader_variant(struct st_context *st,
    }
 
    case GL_TESS_CONTROL_PROGRAM_NV: {
-      struct st_common_program *p = (struct st_common_program *)prog;
+      struct st_common_program *p = st_common_program(prog);
       st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, &p->tgsi, &p->variants);
       break;
    }
 
    case GL_TESS_EVALUATION_PROGRAM_NV: {
-      struct st_common_program *p = (struct st_common_program *)prog;
+      struct st_common_program *p = st_common_program(prog);
       st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, &p->tgsi, &p->variants);
       break;
    }
 
    case GL_GEOMETRY_PROGRAM_NV: {
-      struct st_common_program *p = (struct st_common_program *)prog;
+      struct st_common_program *p = st_common_program(prog);
       st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, &p->tgsi, &p->variants);
       break;
    }
index 0771ca660cfd29be4cde6d857328984cb0327873..23416c0c3fa8646cb2186b0260d269227b8991bd 100644 (file)
@@ -86,25 +86,11 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
       write_tgsi_to_cache(blob, &stvp->tgsi, st, sha1, num_tokens);
       break;
    }
-   case MESA_SHADER_TESS_CTRL: {
-      struct st_common_program *stcp = (struct st_common_program *) prog;
-      sha1 = stcp->sha1;
-
-      write_stream_out_to_cache(blob, out_state);
-      write_tgsi_to_cache(blob, out_state, st, sha1, num_tokens);
-      break;
-   }
-   case MESA_SHADER_TESS_EVAL: {
-      struct st_common_program *step = (struct st_common_program *) prog;
-      sha1 = step->sha1;
-
-      write_stream_out_to_cache(blob, out_state);
-      write_tgsi_to_cache(blob, out_state, st, sha1, num_tokens);
-      break;
-   }
+   case MESA_SHADER_TESS_CTRL:
+   case MESA_SHADER_TESS_EVAL:
    case MESA_SHADER_GEOMETRY: {
-      struct st_common_program *stgp = (struct st_common_program *) prog;
-      sha1 = stgp->sha1;
+      struct st_common_program *p = st_common_program(prog);
+      sha1 = p->sha1;
 
       write_stream_out_to_cache(blob, out_state);
       write_tgsi_to_cache(blob, out_state, st, sha1, num_tokens);
@@ -188,24 +174,21 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx,
          break;
       }
       case MESA_SHADER_TESS_CTRL: {
-         struct st_common_program *stcp =
-            (struct st_common_program *) glprog;
+         struct st_common_program *stcp = st_common_program(glprog);
          stage_sha1[i] = stcp->sha1;
          ralloc_strcat(&buf, " tcs");
          disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]);
          break;
       }
       case MESA_SHADER_TESS_EVAL: {
-         struct st_common_program *step =
-            (struct st_common_program *) glprog;
+         struct st_common_program *step = st_common_program(glprog);
          stage_sha1[i] = step->sha1;
          ralloc_strcat(&buf, " tes");
          disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]);
          break;
       }
       case MESA_SHADER_GEOMETRY: {
-         struct st_common_program *stgp =
-            (struct st_common_program *) glprog;
+         struct st_common_program *stgp = st_common_program(glprog);
          stage_sha1[i] = stgp->sha1;
          ralloc_strcat(&buf, " gs");
          disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]);
@@ -278,8 +261,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx,
             break;
          }
          case MESA_SHADER_TESS_CTRL: {
-            struct st_common_program *sttcp =
-               (struct st_common_program *) glprog;
+            struct st_common_program *sttcp = st_common_program(glprog);
 
             st_release_basic_variants(st, sttcp->Base.Target,
                                       &sttcp->variants, &sttcp->tgsi);
@@ -293,8 +275,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx,
             break;
          }
          case MESA_SHADER_TESS_EVAL: {
-            struct st_common_program *sttep =
-               (struct st_common_program *) glprog;
+            struct st_common_program *sttep = st_common_program(glprog);
 
             st_release_basic_variants(st, sttep->Base.Target,
                                       &sttep->variants, &sttep->tgsi);
@@ -308,8 +289,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx,
             break;
          }
          case MESA_SHADER_GEOMETRY: {
-            struct st_common_program *stgp =
-               (struct st_common_program *) glprog;
+            struct st_common_program *stgp = st_common_program(glprog);
 
             st_release_basic_variants(st, stgp->Base.Target, &stgp->variants,
                                       &stgp->tgsi);