Mesa (arb_geometry_shader4): gs: add the relevant state to the geometry shader token

Zack Rusin zack at kemper.freedesktop.org
Wed May 20 21:17:19 UTC 2009


Module: Mesa
Branch: arb_geometry_shader4
Commit: 96a4de1db7f83ed0e4b86e8d8d70fa84a20b0609
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=96a4de1db7f83ed0e4b86e8d8d70fa84a20b0609

Author: Zack Rusin <zackr at vmware.com>
Date:   Wed May 20 17:16:35 2009 -0400

gs: add the relevant state to the geometry shader token

it looks that to compile it we'll actually need to piggy back the state
that was set at link time. otherwise there's not enough informations to bind it

---

 src/gallium/include/pipe/p_context.h    |    2 +-
 src/gallium/include/pipe/p_defines.h    |   24 +++++++++++++-----------
 src/gallium/include/pipe/p_state.h      |    7 +++++++
 src/mesa/shader/slang/slang_link.c      |   11 +++++++++++
 src/mesa/state_tracker/st_atom_shader.c |    2 +-
 src/mesa/state_tracker/st_cb_program.c  |   12 ++++++------
 src/mesa/state_tracker/st_program.c     |   17 ++++++++++-------
 src/mesa/state_tracker/st_program.h     |    2 +-
 8 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index 4ee0807..4576999 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -147,7 +147,7 @@ struct pipe_context {
    void   (*delete_vs_state)(struct pipe_context *, void *);
 
    void * (*create_gs_state)(struct pipe_context *,
-                             const struct pipe_shader_state *);
+                             const struct pipe_geometry_shader_state *);
    void   (*bind_gs_state)(struct pipe_context *, void *);
    void   (*delete_gs_state)(struct pipe_context *, void *);
 
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index f5ab83a..8881bec 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -243,17 +243,19 @@ enum pipe_transfer_usage {
 /**
  * Primitive types:
  */
-#define PIPE_PRIM_POINTS          0
-#define PIPE_PRIM_LINES           1
-#define PIPE_PRIM_LINE_LOOP       2
-#define PIPE_PRIM_LINE_STRIP      3
-#define PIPE_PRIM_TRIANGLES       4
-#define PIPE_PRIM_TRIANGLE_STRIP  5
-#define PIPE_PRIM_TRIANGLE_FAN    6
-#define PIPE_PRIM_QUADS           7
-#define PIPE_PRIM_QUAD_STRIP      8
-#define PIPE_PRIM_POLYGON         9
-#define PIPE_PRIM_MAX             10
+#define PIPE_PRIM_POINTS               0
+#define PIPE_PRIM_LINES                1
+#define PIPE_PRIM_LINE_LOOP            2
+#define PIPE_PRIM_LINE_STRIP           3
+#define PIPE_PRIM_TRIANGLES            4
+#define PIPE_PRIM_TRIANGLE_STRIP       5
+#define PIPE_PRIM_TRIANGLE_FAN         6
+#define PIPE_PRIM_QUADS                7
+#define PIPE_PRIM_QUAD_STRIP           8
+#define PIPE_PRIM_POLYGON              9
+#define PIPE_PRIM_LINES_ADJACENCY     10
+#define PIPE_PRIM_TRIANGLES_ADJACENCY 11
+#define PIPE_PRIM_MAX                 12
 
 
 /**
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index 4b590bd..602042c 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -172,6 +172,13 @@ struct pipe_shader_state
 {
    const struct tgsi_token *tokens;
 };
+struct pipe_geometry_shader_state
+{
+   struct pipe_shader_state shader;
+   unsigned vertices_out : 16;
+   unsigned input_type   : 8;
+   unsigned output_type  : 8;
+};
 
 
 struct pipe_depth_state 
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 624cbba..590e0e2 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -814,6 +814,17 @@ _slang_link(GLcontext *ctx,
       }
    }
    if (shProg->GeometryProgram) {
+      if (!shProg->VertexProgram) {
+         link_error(shProg,
+                    "Geometry shader without a vertex shader is illegal!\n");
+         return;
+      }
+      if (shProg->GeometryProgram->VerticesOut == 0) {
+         link_error(shProg,
+                    "GEOMETRY_VERTICES_OUT is zero\n");
+         return;
+      }
+
       _slang_count_temporaries(&shProg->GeometryProgram->Base);
       _slang_update_inputs_outputs(&shProg->GeometryProgram->Base);
    }
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 173566b..ae9caf1 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -154,7 +154,7 @@ find_translated_vp(struct st_context *st,
       st_translate_fragment_program(st, stfp, stfp->input_to_slot);
    }
 
-   if (!stgp->state.tokens) {
+   if (!stgp->state.shader.tokens) {
       GLuint inAttr, numIn = 0;
 
       for (inAttr = 0; inAttr < GEOM_ATTRIB_MAX; inAttr++) {
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 5fb9ada..b71894d 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -201,9 +201,9 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog)
             stgp->driver_shader = NULL;
          }
 
-         if (stgp->state.tokens) {
-            FREE((void *)stgp->state.tokens);
-            stgp->state.tokens = NULL;
+         if (stgp->state.shader.tokens) {
+            FREE((void *)stgp->state.shader.tokens);
+            stgp->state.shader.tokens = NULL;
          }
       }
       break;
@@ -288,9 +288,9 @@ static void st_program_string_notify( GLcontext *ctx,
          stgp->driver_shader = NULL;
       }
 
-      if (stgp->state.tokens) {
-         _mesa_free((void *) stgp->state.tokens);
-         stgp->state.tokens = NULL;
+      if (stgp->state.shader.tokens) {
+         _mesa_free((void *) stgp->state.shader.tokens);
+         stgp->state.shader.tokens = NULL;
       }
 
       stgp->param_state = stgp->Base.Base.Parameters->StateFlags;
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 88311f6..54fc691 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -557,7 +557,7 @@ st_translate_geometry_program(struct st_context *st,
    GLuint *outputMapping;
    GLuint defaultInputMapping[GEOM_ATTRIB_MAX];
    GLuint defaultOutputMapping[GEOM_RESULT_MAX];
-   struct pipe_shader_state gs;
+   struct pipe_geometry_shader_state gs;
    GLuint interpMode[16];  /* XXX size? */
    GLuint attr;
    const GLbitfield inputsRead = stgp->Base.Base.InputsRead;
@@ -719,9 +719,9 @@ st_translate_geometry_program(struct st_context *st,
    outputMapping = defaultOutputMapping;
 
    /* free old shader state, if any */
-   if (stgp->state.tokens) {
-      _mesa_free((void *) stgp->state.tokens);
-      stgp->state.tokens = NULL;
+   if (stgp->state.shader.tokens) {
+      _mesa_free((void *) stgp->state.shader.tokens);
+      stgp->state.shader.tokens = NULL;
    }
    if (stgp->driver_shader) {
       cso_delete_vertex_shader(st->cso_context, stgp->driver_shader);
@@ -751,8 +751,11 @@ st_translate_geometry_program(struct st_context *st,
 
    assert(num_tokens < ST_MAX_SHADER_TOKENS);
 
-   gs.tokens = (struct tgsi_token *)
-               mem_dup(tokens, num_tokens * sizeof(tokens[0]));
+   gs.shader.tokens = (struct tgsi_token *)
+                      mem_dup(tokens, num_tokens * sizeof(tokens[0]));
+   gs.vertices_out = stgp->Base.VerticesOut;
+   gs.input_type = stgp->Base.InputType;
+   gs.output_type = stgp->Base.OutputType;
 
    stgp->num_inputs = gs_num_inputs;
    stgp->state = gs; /* struct copy */
@@ -762,7 +765,7 @@ st_translate_geometry_program(struct st_context *st,
       _mesa_print_program(&stgp->Base.Base);
 
    if (TGSI_DEBUG)
-      tgsi_dump(gs.tokens, 0);
+      tgsi_dump(gs.shader.tokens, 0);
 }
 
 /**
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 06221b6..2f986ea 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -127,7 +127,7 @@ struct st_geometry_program
    ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
 
 
-   struct pipe_shader_state state;
+   struct pipe_geometry_shader_state state;
    void *driver_shader;
 
    struct draw_geometry_shader *draw_shader;




More information about the mesa-commit mailing list