gallium: use the utility pasthrough shaders
authorBrian <brian.paul@tungstengraphics.com>
Thu, 20 Mar 2008 15:13:51 +0000 (09:13 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 20 Mar 2008 15:13:51 +0000 (09:13 -0600)
This avoids the Mesa->TGSI translation step.

src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_clear.h
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h

index c23938dc6814b6f85e69a7d1c800cd16dc1fb07f..8cc02f63bbfd6b3fbd6571bf97c2aae033fbccf2 100644 (file)
@@ -49,6 +49,7 @@
 #include "pipe/p_defines.h"
 #include "pipe/p_winsys.h"
 #include "util/u_pack_color.h"
+#include "util/u_simple_shaders.h"
 
 #include "cso_cache/cso_context.h"
 
 #define TEST_DRAW_PASSTHROUGH 0
 
 
+void
+st_destroy_clear(struct st_context *st)
+{
+   if (st->clear.fs) {
+      st->pipe->delete_fs_state(st->pipe, st->clear.fs);
+      st->clear.fs = NULL;
+   }
+   if (st->clear.vs) {
+      st->pipe->delete_vs_state(st->pipe, st->clear.vs);
+      st->clear.vs = NULL;
+   }
+}
+
+
 static GLboolean
 is_depth_stencil_format(enum pipe_format pipeFormat)
 {
@@ -71,104 +86,6 @@ is_depth_stencil_format(enum pipe_format pipeFormat)
 
 
 
-/**
- * Create a simple fragment shader that just passes through the fragment color.
- */
-static struct st_fragment_program *
-make_frag_shader(struct st_context *st)
-{
-   GLcontext *ctx = st->ctx;
-   struct st_fragment_program *stfp;
-   struct gl_program *p;
-   GLuint interpMode[16];
-   GLuint i;
-
-   /* XXX temporary */
-   for (i = 0; i < 16; i++)
-      interpMode[i] = TGSI_INTERPOLATE_LINEAR;
-
-   p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
-   if (!p)
-      return NULL;
-
-   p->NumInstructions = 2;
-   p->Instructions = _mesa_alloc_instructions(2);
-   if (!p->Instructions) {
-      ctx->Driver.DeleteProgram(ctx, p);
-      return NULL;
-   }
-   _mesa_init_instructions(p->Instructions, 2);
-   /* MOV result.color, fragment.color; */
-   p->Instructions[0].Opcode = OPCODE_MOV;
-   p->Instructions[0].DstReg.File = PROGRAM_OUTPUT;
-   p->Instructions[0].DstReg.Index = FRAG_RESULT_COLR;
-   p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT;
-   p->Instructions[0].SrcReg[0].Index = FRAG_ATTRIB_COL0;
-   /* END; */
-   p->Instructions[1].Opcode = OPCODE_END;
-
-   p->InputsRead = FRAG_BIT_COL0;
-   p->OutputsWritten = (1 << FRAG_RESULT_COLR);
-
-   stfp = (struct st_fragment_program *) p;
-   st_translate_fragment_program(st, stfp, NULL);
-
-   return stfp;
-}
-
-
-/**
- * Create a simple vertex shader that just passes through the
- * vertex position and color.
- */
-static struct st_vertex_program *
-make_vertex_shader(struct st_context *st)
-{
-   GLcontext *ctx = st->ctx;
-   struct st_vertex_program *stvp;
-   struct gl_program *p;
-
-   p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
-   if (!p)
-      return NULL;
-
-   p->NumInstructions = 3;
-   p->Instructions = _mesa_alloc_instructions(3);
-   if (!p->Instructions) {
-      ctx->Driver.DeleteProgram(ctx, p);
-      return NULL;
-   }
-   _mesa_init_instructions(p->Instructions, 3);
-   /* MOV result.pos, vertex.pos; */
-   p->Instructions[0].Opcode = OPCODE_MOV;
-   p->Instructions[0].DstReg.File = PROGRAM_OUTPUT;
-   p->Instructions[0].DstReg.Index = VERT_RESULT_HPOS;
-   p->Instructions[0].SrcReg[0].File = PROGRAM_INPUT;
-   p->Instructions[0].SrcReg[0].Index = VERT_ATTRIB_POS;
-   /* MOV result.color, vertex.color; */
-   p->Instructions[1].Opcode = OPCODE_MOV;
-   p->Instructions[1].DstReg.File = PROGRAM_OUTPUT;
-   p->Instructions[1].DstReg.Index = VERT_RESULT_COL0;
-   p->Instructions[1].SrcReg[0].File = PROGRAM_INPUT;
-   p->Instructions[1].SrcReg[0].Index = VERT_ATTRIB_COLOR0;
-   /* END; */
-   p->Instructions[2].Opcode = OPCODE_END;
-
-   p->InputsRead = VERT_BIT_POS | VERT_BIT_COLOR0;
-   p->OutputsWritten = ((1 << VERT_RESULT_COL0) |
-                        (1 << VERT_RESULT_HPOS));
-
-   stvp = (struct st_vertex_program *) p;
-   st_translate_vertex_program(st, stvp, NULL);
-#if 0
-   assert(stvp->cso);
-#endif
-
-   return stvp;
-}
-
-
-
 /**
  * Draw a screen-aligned quadrilateral.
  * Coords are window coords with y=0=bottom.  These coords will be transformed
@@ -311,23 +228,23 @@ clear_with_quad(GLcontext *ctx,
    }
 
    /* fragment shader state: color pass-through program */
-   {
-      static struct st_fragment_program *stfp = NULL;
-      if (!stfp) {
-         stfp = make_frag_shader(st);
-      }
-      pipe->bind_fs_state(pipe, stfp->driver_shader);
+   if (!st->clear.fs) {
+      st->clear.fs = util_make_fragment_passthrough_shader(pipe);
    }
+   pipe->bind_fs_state(pipe, st->clear.fs);
+
 
 #if !TEST_DRAW_PASSTHROUGH
    /* vertex shader state: color/position pass-through */
-   {
-      static struct st_vertex_program *stvp = NULL;
-      if (!stvp) {
-         stvp = make_vertex_shader(st);
-      }
-      pipe->bind_vs_state(pipe, stvp->driver_shader);
+   if (!st->clear.vs) {
+      const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
+                                      TGSI_SEMANTIC_COLOR };
+      const uint semantic_indexes[] = { 0, 0 };
+      st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2,
+                                                         semantic_names,
+                                                         semantic_indexes);
    }
+   pipe->bind_vs_state(pipe, st->clear.vs);
 #endif
 
 #if !TEST_DRAW_PASSTHROUGH
index c715e56bd56c7be90c232652527ca5587d27d76a..dfa4033faa6efccfa5e0129cd3b3b9a4b805480f 100644 (file)
 #define ST_CB_CLEAR_H
 
 
+extern void
+st_destroy_clear(struct st_context *st);
+
+
 extern void
 st_init_clear_functions(struct dd_function_table *functions);
 
index e1fc885e0e7b55fecb458e72000c02860bf3a963..b1681be2eb5fa7ce16286118575d518bc98e03b1 100644 (file)
@@ -155,6 +155,7 @@ static void st_destroy_context_priv( struct st_context *st )
    st_destroy_draw( st );
    st_destroy_generate_mipmap(st);
    st_destroy_blit(st);
+   st_destroy_clear(st);
 
    _vbo_DestroyContext(st->ctx);
 
index ca8307c4ba0224f06d4395abae95ed414c5893bd..8058086d8753fb9c1b94880ba2e1b1b092816910 100644 (file)
@@ -142,12 +142,19 @@ struct st_context
       GLuint combined_prog_sn;
    } pixel_xfer;
 
+   /** for glBitmap */
    struct {
       struct st_fragment_program *program;  /**< bitmap tex/kil program */
       GLuint user_prog_sn;  /**< user fragment program serial no. */
       struct st_fragment_program *combined_prog;
    } bitmap;
 
+   /** for glClear */
+   struct {
+      void *vs;
+      void *fs;
+   } clear;
+
    struct gen_mipmap_state *gen_mipmap;
    struct blit_state *blit;