[Mesa-dev] [PATCH 1/9] mesa: Use gl_shader_program::_LinkedShaders instead of VertexProgram

Ian Romanick idr at freedesktop.org
Tue Oct 4 13:44:04 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |    3 ++-
 src/mesa/drivers/dri/i965/brw_vs.c             |    8 +++++---
 src/mesa/main/context.c                        |    2 +-
 src/mesa/main/ff_fragment_shader.cpp           |   10 +++++-----
 src/mesa/main/mtypes.h                         |    1 -
 src/mesa/main/shaderapi.c                      |    9 +++++----
 src/mesa/main/shaderobj.c                      |    1 -
 src/mesa/main/state.c                          |    6 ++++--
 src/mesa/main/texstate.c                       |    8 ++++----
 src/mesa/main/uniforms.c                       |   12 +++++++-----
 src/mesa/program/ir_to_mesa.cpp                |    5 ++---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp     |    4 ++--
 src/mesa/state_tracker/st_program.c            |    4 ++--
 13 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index ad8b433..8fd1a54 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -2315,7 +2315,8 @@ vec4_visitor::vec4_visitor(struct brw_vs_compile *c,
    this->current_annotation = NULL;
 
    this->c = c;
-   this->vp = prog->VertexProgram;
+   this->vp = (struct gl_vertex_program *)
+     prog->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
    this->prog_data = &c->prog_data;
 
    this->variable_ht = hash_table_ctor(0,
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 93c6838..be7c8e4 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -309,15 +309,17 @@ brw_vs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 {
    struct brw_context *brw = brw_context(ctx);
    struct brw_vs_prog_key key;
-   struct gl_vertex_program *vp = prog->VertexProgram;
-   struct brw_vertex_program *bvp = brw_vertex_program(vp);
    uint32_t old_prog_offset = brw->vs.prog_offset;
    struct brw_vs_prog_data *old_prog_data = brw->vs.prog_data;
    bool success;
 
-   if (!vp)
+   if (!prog->_LinkedShaders[MESA_SHADER_VERTEX])
       return true;
 
+   struct gl_vertex_program *vp = (struct gl_vertex_program *)
+      prog->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
+   struct brw_vertex_program *bvp = brw_vertex_program(vp);
+
    memset(&key, 0, sizeof(key));
 
    key.program_string_id = bvp->id;
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 2532c47..b825a63 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1852,7 +1852,7 @@ _mesa_valid_to_render(struct gl_context *ctx, const char *where)
 	 sh = shProg[i]->_LinkedShaders[i];
 	 switch (sh->Type) {
 	 case GL_VERTEX_SHADER:
-	    _mesa_append_uniforms_to_file(sh, &shProg[i]->VertexProgram->Base);
+	    _mesa_append_uniforms_to_file(sh, sh->Program);
 	    break;
 
 	 case GL_GEOMETRY_SHADER_ARB:
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index 7cc1721..e6451c9 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -315,7 +315,7 @@ static GLbitfield get_fp_input_mask( struct gl_context *ctx )
    const GLboolean vertexShader =
       (ctx->Shader.CurrentVertexProgram &&
        ctx->Shader.CurrentVertexProgram->LinkStatus &&
-       ctx->Shader.CurrentVertexProgram->VertexProgram);
+       ctx->Shader.CurrentVertexProgram->_LinkedShaders[MESA_SHADER_VERTEX]);
    const GLboolean vertexProgram = ctx->VertexProgram._Enabled;
    GLbitfield fp_inputs = 0x0;
 
@@ -371,7 +371,7 @@ static GLbitfield get_fp_input_mask( struct gl_context *ctx )
    }
    else {
       /* calculate from vp->outputs */
-      struct gl_vertex_program *vprog;
+      struct gl_program *vprog;
       GLbitfield64 vp_outputs;
 
       /* Choose GLSL vertex shader over ARB vertex program.  Need this
@@ -379,11 +379,11 @@ static GLbitfield get_fp_input_mask( struct gl_context *ctx )
        * validation (see additional comments in state.c).
        */
       if (vertexShader)
-         vprog = ctx->Shader.CurrentVertexProgram->VertexProgram;
+         vprog = ctx->Shader.CurrentVertexProgram->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
       else
-         vprog = ctx->VertexProgram.Current;
+         vprog = &ctx->VertexProgram.Current->Base;
 
-      vp_outputs = vprog->Base.OutputsWritten;
+      vp_outputs = vprog->OutputsWritten;
 
       /* These get generated in the setup routine regardless of the
        * vertex program:
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 67db4df..8df77f1 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2173,7 +2173,6 @@ struct gl_shader_program
    } Vert;
 
    /* post-link info: */
-   struct gl_vertex_program *VertexProgram;     /**< Linked vertex program */
    struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
    struct gl_geometry_program *GeometryProgram; /**< Linked geometry prog */
    struct gl_uniform_list *Uniforms;
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 9e0ed9c..d9559ba 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -808,8 +808,9 @@ print_shader_info(const struct gl_shader_program *shProg)
 	     shProg->Shaders[i]->Name,
 	     shProg->Shaders[i]->SourceChecksum);
    }
-   if (shProg->VertexProgram)
-      printf("  vert prog %u\n", shProg->VertexProgram->Base.Id);
+   if (shProg->_LinkedShaders[MESA_SHADER_VERTEX])
+      printf("  vert prog %u\n",
+	     shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program->Id);
    if (shProg->FragmentProgram)
       printf("  frag prog %u\n", shProg->FragmentProgram->Base.Id);
    if (shProg->GeometryProgram)
@@ -963,7 +964,7 @@ static GLboolean
 validate_shader_program(const struct gl_shader_program *shProg,
                         char *errMsg)
 {
-   const struct gl_vertex_program *vp = shProg->VertexProgram;
+   const struct gl_shader *vs = shProg->_LinkedShaders[MESA_SHADER_VERTEX];
    const struct gl_geometry_program *gp = shProg->GeometryProgram;
    const struct gl_fragment_program *fp = shProg->FragmentProgram;
 
@@ -991,7 +992,7 @@ validate_shader_program(const struct gl_shader_program *shProg,
     * Check: any two active samplers in the current program object are of
     * different types, but refer to the same texture image unit,
     */
-   if (vp && !validate_samplers(&vp->Base, errMsg)) {
+   if (vs && !validate_samplers(vs->Program, errMsg)) {
       return GL_FALSE;
    }
    if (gp && !validate_samplers(&gp->Base, errMsg)) {
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 1eba756..f5f5e70 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -275,7 +275,6 @@ void
 _mesa_clear_shader_program_data(struct gl_context *ctx,
                                 struct gl_shader_program *shProg)
 {
-   _mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL);
    _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL);
    _mesa_reference_geomprog(ctx, &shProg->GeometryProgram, NULL);
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index fc25515..ab7250f 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -281,10 +281,12 @@ update_program(struct gl_context *ctx)
     * _mesa_get_fixed_func_vertex_program() needs to know active
     * fragprog inputs.
     */
-   if (vsProg && vsProg->LinkStatus && vsProg->VertexProgram) {
+   if (vsProg && vsProg->LinkStatus
+       && vsProg->_LinkedShaders[MESA_SHADER_VERTEX]) {
       /* Use GLSL vertex shader */
       _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
-                               vsProg->VertexProgram);
+			       (struct gl_vertex_program *)
+			       vsProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program);
    }
    else if (ctx->VertexProgram._Enabled) {
       /* Use user-defined vertex program */
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index e02f162..ee99e50 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -490,16 +490,16 @@ update_texture_state( struct gl_context *ctx )
 {
    GLuint unit;
    struct gl_fragment_program *fprog = NULL;
-   struct gl_vertex_program *vprog = NULL;
+   struct gl_program *vprog = NULL;
    GLbitfield enabledFragUnits = 0x0;
 
    if (ctx->Shader.CurrentVertexProgram &&
        ctx->Shader.CurrentVertexProgram->LinkStatus) {
-      vprog = ctx->Shader.CurrentVertexProgram->VertexProgram;
+      vprog = ctx->Shader.CurrentVertexProgram->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
    } else if (ctx->VertexProgram._Enabled) {
       /* XXX enable this if/when non-shader vertex programs get
        * texture fetches:
-       vprog = ctx->VertexProgram.Current;
+       vprog = &ctx->VertexProgram.Current->Base;
        */
    }
 
@@ -540,7 +540,7 @@ update_texture_state( struct gl_context *ctx )
        * settle on the one with highest priority (see below).
        */
       if (vprog) {
-         enabledVertTargets |= vprog->Base.TexturesUsed[unit];
+         enabledVertTargets |= vprog->TexturesUsed[unit];
       }
 
       if (fprog) {
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 2323819..28a3bee 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -180,7 +180,7 @@ find_uniform_parameter_pos(struct gl_shader_program *shProg, GLint index,
 
    pos = shProg->Uniforms->Uniforms[index].VertPos;
    if (pos >= 0) {
-      prog = &shProg->VertexProgram->Base;
+      prog = shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
    }
    else {
       pos = shProg->Uniforms->Uniforms[index].FragPos;
@@ -911,11 +911,12 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
    /* A uniform var may be used by both a vertex shader and a fragment
     * shader.  We may need to update one or both shader's uniform here:
     */
-   if (shProg->VertexProgram) {
+   if (shProg->_LinkedShaders[MESA_SHADER_VERTEX]) {
       /* convert uniform location to program parameter index */
       GLint index = uniform->VertPos;
       if (index >= 0) {
-         set_program_uniform(ctx, &shProg->VertexProgram->Base,
+         set_program_uniform(ctx,
+                             shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program,
                              index, offset, type, count, elems, values);
       }
    }
@@ -1056,11 +1057,12 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
 
    uniform = &shProg->Uniforms->Uniforms[location];
 
-   if (shProg->VertexProgram) {
+   if (shProg->_LinkedShaders[MESA_SHADER_VERTEX]) {
       /* convert uniform location to program parameter index */
       GLint index = uniform->VertPos;
       if (index >= 0) {
-         set_program_uniform_matrix(ctx, &shProg->VertexProgram->Base,
+         set_program_uniform_matrix(ctx,
+				    shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program,
                                     index, offset,
                                     count, rows, cols, transpose, values);
       }
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 2e1b8fb..652e706 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3294,8 +3294,8 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
          case GL_VERTEX_SHADER:
             ((struct gl_vertex_program *)linked_prog)->UsesClipDistance
                = prog->Vert.UsesClipDistance;
-            _mesa_reference_vertprog(ctx, &prog->VertexProgram,
-                                     (struct gl_vertex_program *)linked_prog);
+            _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
+				    linked_prog);
             ok = ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
                                                  linked_prog);
             break;
@@ -3427,7 +3427,6 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       }
    }
 
-   _mesa_reference_vertprog(ctx, &prog->VertexProgram, NULL);
    _mesa_reference_fragprog(ctx, &prog->FragmentProgram, NULL);
    _mesa_reference_geomprog(ctx, &prog->GeometryProgram, NULL);
 
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index d8ef8a3..01e4d88 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5184,8 +5184,8 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 
          switch (prog->_LinkedShaders[i]->Type) {
          case GL_VERTEX_SHADER:
-            _mesa_reference_vertprog(ctx, &prog->VertexProgram,
-                                     (struct gl_vertex_program *)linked_prog);
+            _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
+                                    linked_prog);
             ok = ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
                                                  linked_prog);
             if (!ok) {
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index a4f47ed..5211043 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1153,8 +1153,8 @@ destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
             destroy_program_variants(st, shProg->Shaders[i]->Program);
          }
 
-         destroy_program_variants(st, (struct gl_program *)
-                                  shProg->VertexProgram);
+         destroy_program_variants(st,
+                                  shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program);
          destroy_program_variants(st, (struct gl_program *)
                                   shProg->FragmentProgram);
          destroy_program_variants(st, (struct gl_program *)
-- 
1.7.6



More information about the mesa-dev mailing list