Fix problems with vertex shaders and the private draw module.
authorBrian <brian.paul@tungstengraphics.com>
Tue, 15 Jan 2008 02:12:46 +0000 (19:12 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 15 Jan 2008 02:13:34 +0000 (19:13 -0700)
The CSO returned by pipe->create_vs_state() can't be passed to the
private draw module.  That was causing glRasterPos to blow up.
Add a 'draw_shader' field to st_vertex_program for use with the private
draw module.
Change st_context->state.vs type from cso_vertex_shader to st_vertex_program.

src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_program.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_debug.c
src/mesa/state_tracker/st_draw.c
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h

index 2a182c7..1ed9333 100644 (file)
@@ -43,6 +43,8 @@
 #include "pipe/p_context.h"
 #include "pipe/p_shader_tokens.h"
 
+#include "pipe/cso_cache/cso_cache.h"
+
 #include "st_context.h"
 #include "st_cache.h"
 #include "st_atom.h"
@@ -71,8 +73,8 @@ struct translated_vertex_program
    /** The program in TGSI format */
    struct tgsi_token tokens[ST_MAX_SHADER_TOKENS];
 
-   /** Pointer to the translated, cached vertex shader */
-   const struct cso_vertex_shader *vs;
+   /** Pointer to the translated vertex program */
+   struct st_vertex_program *vp;
 
    struct translated_vertex_program *next;  /**< next in linked list */
 };
@@ -257,12 +259,13 @@ find_translated_vp(struct st_context *st,
 
       assert(stvp->Base.Base.NumInstructions > 1);
 
-      xvp->vs = st_translate_vertex_program(st, stvp,
-                                            xvp->output_to_slot,
-                                            xvp->tokens,
-                                            ST_MAX_SHADER_TOKENS);
-      assert(xvp->vs);
-      stvp->vs = NULL; /* don't want to use this */
+      st_translate_vertex_program(st, stvp,
+                                  xvp->output_to_slot,
+                                  xvp->tokens,
+                                  ST_MAX_SHADER_TOKENS);
+
+      assert(stvp->cso);
+      xvp->vp = stvp;
 
       /* translated VP is up to date now */
       xvp->serialNo = stvp->serialNo;
@@ -291,8 +294,8 @@ update_linkage( struct st_context *st )
    xvp = find_translated_vp(st, stvp, stfp);
 
    st->vp = stvp;
-   st->state.vs = xvp->vs;
-   st->pipe->bind_vs_state(st->pipe, st->state.vs->data);
+   st->state.vs = xvp->vp;
+   st->pipe->bind_vs_state(st->pipe, st->state.vs->cso->data);
 
    st->fp = stfp;
    st->state.fs = stfp->fs;
index 40319f4..758d4a4 100644 (file)
@@ -208,7 +208,7 @@ make_vertex_shader(struct st_context *st)
    stvp = (struct st_vertex_program *) p;
    st_translate_vertex_program(st, stvp, NULL,
                                stvp->tokens, ST_MAX_SHADER_TOKENS);
-   assert(stvp->vs);
+   assert(stvp->cso);
 
    return stvp;
 }
@@ -350,7 +350,7 @@ clear_with_quad(GLcontext *ctx,
       if (!stvp) {
          stvp = make_vertex_shader(st);
       }
-      pipe->bind_vs_state(pipe, stvp->vs->data);
+      pipe->bind_vs_state(pipe, stvp->cso->data);
    }
 
    /* viewport state: viewport matching window dims */
@@ -376,7 +376,7 @@ clear_with_quad(GLcontext *ctx,
    pipe->bind_blend_state(pipe, st->state.blend->data);
    pipe->bind_depth_stencil_alpha_state(pipe, st->state.depth_stencil->data);
    pipe->bind_fs_state(pipe, st->state.fs->data);
-   pipe->bind_vs_state(pipe, st->state.vs->data);
+   pipe->bind_vs_state(pipe, st->state.vs->cso->data);
    pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data);
    pipe->set_viewport_state(pipe, &st->state.viewport);
    /* OR:
index be5434f..f4d6b93 100644 (file)
@@ -662,7 +662,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
    pipe->bind_fs_state(pipe, stfp->fs->data);
 
    /* vertex shader state: position + texcoord pass-through */
-   pipe->bind_vs_state(pipe, stvp->vs->data);
+   pipe->bind_vs_state(pipe, stvp->cso->data);
 
    /* texture sampling state: */
    {
@@ -719,7 +719,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
    /* restore GL state */
    pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data);
    pipe->bind_fs_state(pipe, ctx->st->state.fs->data);
-   pipe->bind_vs_state(pipe, ctx->st->state.vs->data);
+   pipe->bind_vs_state(pipe, ctx->st->state.vs->cso->data);
    pipe->set_sampler_texture(pipe, unit, ctx->st->state.sampler_texture[unit]);
    pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]->data);
    pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
index aed6b1e..63a9542 100644 (file)
@@ -39,6 +39,8 @@
 #include "shader/programopt.h"
 #include "shader/shader_api.h"
 
+#include "pipe/cso_cache/cso_cache.h"
+
 #include "st_context.h"
 #include "st_program.h"
 #include "st_atom_shader.h"
@@ -181,10 +183,11 @@ static void st_program_string_notify( GLcontext *ctx,
 
       stvp->serialNo++;
 
-      if (stvp->vs) {
-         /* free the TGSI code */
-         // cso_delete(stfp->vs);
-         stvp->vs = NULL;
+      if (stvp->cso) {
+         /* free the CSO data */
+         st->pipe->delete_vs_state(st->pipe, stvp->cso->data);
+         FREE((void *) stvp->cso);
+         stvp->cso = NULL;
       }
 
       stvp->param_state = stvp->Base.Base.Parameters->StateFlags;
index 0f40f3c..5ae21c9 100644 (file)
@@ -100,7 +100,7 @@ struct st_context
       const struct cso_depth_stencil_alpha   *depth_stencil;
       const struct cso_rasterizer      *rasterizer;
       const struct cso_fragment_shader *fs;
-      const struct cso_vertex_shader   *vs;
+      struct st_vertex_program   *vs;
 
       struct pipe_blend_color  blend_color;
       struct pipe_clip_state clip;
index cffd667..57450e5 100644 (file)
@@ -53,11 +53,11 @@ st_print_current(void)
    int i;
 
    printf("Vertex Transform Inputs:\n");
-   for (i = 0; i < st->state.vs->state.num_inputs; i++) {
+   for (i = 0; i < st->state.vs->cso->state.num_inputs; i++) {
       printf("  Slot %d:  VERT_ATTRIB_%d\n", i, st->vp->index_to_input[i]);
    }
 
-   tgsi_dump( st->state.vs->state.tokens, 0 );
+   tgsi_dump( st->state.vs->cso->state.tokens, 0 );
    if (st->vp->Base.Base.Parameters)
       _mesa_print_parameter_list(st->vp->Base.Base.Parameters);
 
index 96db9e3..94b3a95 100644 (file)
@@ -241,7 +241,7 @@ st_draw_vbo(GLcontext *ctx,
 
    /* must get these after state validation! */
    vp = ctx->st->vp;
-   vs = &ctx->st->state.vs->state;
+   vs = &ctx->st->state.vs->cso->state;
 
    /* loop over TGSI shader inputs to determine vertex buffer
     * and attribute info
@@ -447,7 +447,7 @@ set_feedback_vertex_format(GLcontext *ctx)
    else {
       /* GL_FEEDBACK, or glRasterPos */
       /* emit all attribs (pos, color, texcoord) as GLfloat[4] */
-      vinfo.num_attribs = st->state.vs->state.num_outputs;
+      vinfo.num_attribs = st->state.vs->cso->state.num_outputs;
       for (i = 0; i < vinfo.num_attribs; i++) {
          vinfo.format[i] = FORMAT_4F;
          vinfo.interp_mode[i] = INTERP_LINEAR;
@@ -491,7 +491,11 @@ st_feedback_draw_vbo(GLcontext *ctx,
 
    /* must get these after state validation! */
    vp = ctx->st->vp;
-   vs = &ctx->st->state.vs->state;
+   vs = &ctx->st->state.vs->cso->state;
+
+   if (!st->state.vs->draw_shader) {
+      st->state.vs->draw_shader = draw_create_vertex_shader(draw, vs);
+   }
 
    /*
     * Set up the draw module's state.
@@ -503,7 +507,7 @@ st_feedback_draw_vbo(GLcontext *ctx,
    draw_set_viewport_state(draw, &st->state.viewport);
    draw_set_clip_state(draw, &st->state.clip);
    draw_set_rasterizer_state(draw, &st->state.rasterizer->state);
-   draw_bind_vertex_shader(draw, st->state.vs->data);
+   draw_bind_vertex_shader(draw, st->state.vs->draw_shader);
    set_feedback_vertex_format(ctx);
 
    /* loop over TGSI shader inputs to determine vertex buffer
index 1852228..1f1e650 100644 (file)
@@ -57,7 +57,7 @@
  * \param tokensOut  destination for TGSI tokens
  * \return  pointer to cached pipe_shader object.
  */
-const struct cso_vertex_shader *
+void
 st_translate_vertex_program(struct st_context *st,
                             struct st_vertex_program *stvp,
                             const GLuint outputMapping[],
@@ -256,12 +256,10 @@ st_translate_vertex_program(struct st_context *st,
    vs.tokens = tokensOut;
 
    cso = st_cached_vs_state(st, &vs);
-   stvp->vs = cso;
+   stvp->cso = cso;
 
    if (TGSI_DEBUG)
       tgsi_dump( tokensOut, 0 );
-
-   return cso;
 }
 
 
index 049f9f6..de02c31 100644 (file)
@@ -90,7 +90,10 @@ struct st_vertex_program
    struct tgsi_token tokens[ST_MAX_SHADER_TOKENS];
 
    /** Pointer to the corresponding cached shader */
-   const struct cso_vertex_shader *vs;
+   const struct cso_vertex_shader *cso;
+
+   /** For using our private draw module (glRasterPos) */
+   struct draw_vertex_shader *draw_shader;
 
    GLuint param_state;
 };
@@ -122,7 +125,7 @@ st_translate_fragment_program(struct st_context *st,
                               GLuint maxTokens);
 
 
-extern const struct cso_vertex_shader *
+extern void
 st_translate_vertex_program(struct st_context *st,
                             struct st_vertex_program *vp,
                             const GLuint vert_output_to_slot[],