summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorZack Rusin <[email protected]>2007-09-18 13:24:44 -0400
committerZack Rusin <[email protected]>2007-09-18 13:24:44 -0400
commitccd63b54cfbb6bb241d55f7ac95afcd14819f469 (patch)
tree3ea07838de79877e6d441506cdd6f805fcb9d308 /src/mesa/state_tracker
parent498a1b5dc4ca431bb1de45d04140bfb2ac319ab2 (diff)
Convert shader to an immutable state object.
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom_fs.c16
-rw-r--r--src/mesa/state_tracker/st_atom_vs.c16
-rw-r--r--src/mesa/state_tracker/st_cache.c18
-rw-r--r--src/mesa/state_tracker/st_cache.h4
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c12
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c12
-rw-r--r--src/mesa/state_tracker/st_cb_rasterpos.c6
-rw-r--r--src/mesa/state_tracker/st_context.h4
-rw-r--r--src/mesa/state_tracker/st_draw.c6
-rw-r--r--src/mesa/state_tracker/st_program.h6
10 files changed, 71 insertions, 29 deletions
diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c
index d0665476168..dc3e5258d82 100644
--- a/src/mesa/state_tracker/st_atom_fs.c
+++ b/src/mesa/state_tracker/st_atom_fs.c
@@ -38,6 +38,7 @@
#include "pipe/tgsi/exec/tgsi_dump.h"
#include "st_context.h"
+#include "st_cache.h"
#include "st_atom.h"
#include "st_program.h"
@@ -46,16 +47,21 @@
static void compile_fs( struct st_context *st )
{
struct st_fragment_program *fp = st->fp;
+ struct pipe_shader_state fs;
+ struct pipe_shader_state *cached;
/* XXX: fix static allocation of tokens:
*/
tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS );
- fp->fs.inputs_read
+ memset(&fs, 0, sizeof(fs));
+ fs.inputs_read
= tgsi_mesa_translate_fragment_input_mask(fp->Base.Base.InputsRead);
- fp->fs.outputs_written
+ fs.outputs_written
= tgsi_mesa_translate_fragment_output_mask(fp->Base.Base.OutputsWritten);
- fp->fs.tokens = &fp->tokens[0];
+ fs.tokens = &fp->tokens[0];
+ cached = st_cached_shader_state(st, &fs);
+ fp->fsx = cached;
if (TGSI_DEBUG)
tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE );
@@ -92,8 +98,8 @@ static void update_fs( struct st_context *st )
if (fp->dirty)
compile_fs( st );
- st->state.fs = fp->fs;
- st->pipe->set_fs_state(st->pipe, &st->state.fs);
+ st->state.fs = fp->fsx;
+ st->pipe->bind_fs_state(st->pipe, st->state.fs);
}
}
diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c
index 289a3e4f46c..18be71367a2 100644
--- a/src/mesa/state_tracker/st_atom_vs.c
+++ b/src/mesa/state_tracker/st_atom_vs.c
@@ -41,6 +41,7 @@
#include "pipe/tgsi/exec/tgsi_core.h"
#include "st_context.h"
+#include "st_cache.h"
#include "st_atom.h"
#include "st_program.h"
@@ -55,16 +56,21 @@
static void compile_vs( struct st_context *st )
{
struct st_vertex_program *vp = st->vp;
-
+ struct pipe_shader_state vs;
+ struct pipe_shader_state *cached;
/* XXX: fix static allocation of tokens:
*/
tgsi_mesa_compile_vp_program( &vp->Base, vp->tokens, ST_FP_MAX_TOKENS );
- vp->vs.inputs_read
+ memset(&vs, 0, sizeof(vs));
+ vs.inputs_read
= tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead);
- vp->vs.outputs_written
+ vs.outputs_written
= tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten);
- vp->vs.tokens = &vp->tokens[0];
+ vs.tokens = &vp->tokens[0];
+
+ cached = st_cached_shader_state(st, &vs);
+ vp->vs = cached;
if (TGSI_DEBUG)
tgsi_dump( vp->tokens, 0 );
@@ -110,7 +116,7 @@ static void update_vs( struct st_context *st )
#endif
st->state.vs = st->vp->vs;
- st->pipe->set_vs_state(st->pipe, &st->state.vs);
+ st->pipe->bind_vs_state(st->pipe, st->state.vs);
}
}
diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c
index e9c79634bd7..7b851e3901b 100644
--- a/src/mesa/state_tracker/st_cache.c
+++ b/src/mesa/state_tracker/st_cache.c
@@ -111,3 +111,21 @@ struct pipe_rasterizer_state * st_cached_rasterizer_state(
}
return (struct pipe_rasterizer_state*)(cso_hash_iter_data(iter));
}
+
+struct pipe_shader_state * st_cached_shader_state(
+ struct st_context *st,
+ const struct pipe_shader_state *templ)
+{
+ unsigned hash_key = cso_construct_key((void*)templ,
+ sizeof(struct pipe_shader_state));
+ struct cso_hash_iter iter = cso_find_state_template(st->cache,
+ hash_key, CSO_SHADER,
+ (void*)templ);
+ if (cso_hash_iter_is_null(iter)) {
+ const struct pipe_shader_state *created_state =
+ st->pipe->create_shader_state(st->pipe, templ);
+ iter = cso_insert_state(st->cache, hash_key, CSO_SHADER,
+ (void*)created_state);
+ }
+ return (struct pipe_shader_state*)(cso_hash_iter_data(iter));
+}
diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h
index a06af311237..6a897a99933 100644
--- a/src/mesa/state_tracker/st_cache.h
+++ b/src/mesa/state_tracker/st_cache.h
@@ -53,4 +53,8 @@ struct pipe_rasterizer_state *st_cached_rasterizer_state(
struct st_context *st,
const struct pipe_rasterizer_state *raster);
+struct pipe_shader_state *st_cached_shader_state(
+ struct st_context *st,
+ const struct pipe_shader_state *templ);
+
#endif
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 584bc1cc2ae..2ea498663b1 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -347,6 +347,7 @@ clear_with_quad(GLcontext *ctx,
{
static struct st_fragment_program *stfp = NULL;
struct pipe_shader_state fs;
+ const struct pipe_shader_state *cached;
if (!stfp) {
stfp = make_color_shader(st);
}
@@ -354,13 +355,15 @@ clear_with_quad(GLcontext *ctx,
fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten);
fs.tokens = &stfp->tokens[0];
- pipe->set_fs_state(pipe, &fs);
+ cached = st_cached_shader_state(st, &fs);
+ pipe->bind_fs_state(pipe, cached);
}
/* vertex shader state: color/position pass-through */
{
static struct st_vertex_program *stvp = NULL;
struct pipe_shader_state vs;
+ const struct pipe_shader_state *cached;
if (!stvp) {
stvp = make_vertex_shader(st);
}
@@ -368,7 +371,8 @@ clear_with_quad(GLcontext *ctx,
vs.inputs_read = stvp->Base.Base.InputsRead;
vs.outputs_written = stvp->Base.Base.OutputsWritten;
vs.tokens = &stvp->tokens[0];
- pipe->set_vs_state(pipe, &vs);
+ cached = st_cached_shader_state(st, &vs);
+ pipe->bind_vs_state(pipe, cached);
}
/* viewport state: viewport matching window dims */
@@ -394,8 +398,8 @@ clear_with_quad(GLcontext *ctx,
pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
pipe->bind_blend_state(pipe, st->state.blend);
pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil);
- pipe->set_fs_state(pipe, &st->state.fs);
- pipe->set_vs_state(pipe, &st->state.vs);
+ pipe->bind_fs_state(pipe, st->state.fs);
+ pipe->bind_vs_state(pipe, st->state.vs);
pipe->bind_rasterizer_state(pipe, st->state.rasterizer);
pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
/* OR:
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 78ede8e2250..37e40636f61 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -329,19 +329,22 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
{
static struct st_fragment_program *stfp = NULL;
struct pipe_shader_state fs;
+ struct pipe_shader_state *cached;
if (!stfp) {
stfp = make_fragment_shader(ctx->st);
}
memset(&fs, 0, sizeof(fs));
fs.inputs_read = stfp->Base.Base.InputsRead;
fs.tokens = &stfp->tokens[0];
- pipe->set_fs_state(pipe, &fs);
+ cached = st_cached_shader_state(ctx->st, &fs);
+ pipe->bind_fs_state(pipe, cached);
}
/* vertex shader state: position + texcoord pass-through */
{
static struct st_vertex_program *stvp = NULL;
struct pipe_shader_state vs;
+ struct pipe_shader_state *cached;
if (!stvp) {
stvp = make_vertex_shader(ctx->st);
}
@@ -349,7 +352,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
vs.inputs_read = stvp->Base.Base.InputsRead;
vs.outputs_written = stvp->Base.Base.OutputsWritten;
vs.tokens = &stvp->tokens[0];
- pipe->set_vs_state(pipe, &vs);
+ cached = st_cached_shader_state(ctx->st, &vs);
+ pipe->bind_vs_state(pipe, cached);
}
/* texture sampling state: */
@@ -403,8 +407,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
/* restore GL state */
pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer);
- pipe->set_fs_state(pipe, &ctx->st->state.fs);
- pipe->set_vs_state(pipe, &ctx->st->state.vs);
+ pipe->bind_fs_state(pipe, ctx->st->state.fs);
+ pipe->bind_vs_state(pipe, ctx->st->state.vs);
pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]);
pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]);
pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index 7bedf3f89f1..98efe1a10bb 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -53,7 +53,7 @@ static void
setup_vertex_attribs(GLcontext *ctx)
{
struct pipe_context *pipe = ctx->st->pipe;
- const uint inputAttrs = ctx->st->state.vs.inputs_read;
+ const uint inputAttrs = ctx->st->state.vs->inputs_read;
uint attr;
/* all attributes come from the default attribute buffer */
@@ -84,7 +84,7 @@ static void
setup_feedback(GLcontext *ctx)
{
struct pipe_context *pipe = ctx->st->pipe;
- const uint outputAttrs = ctx->st->state.vs.outputs_written;
+ const uint outputAttrs = ctx->st->state.vs->outputs_written;
struct pipe_feedback_state feedback;
uint i;
@@ -307,7 +307,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
/* extract values and update rasterpos state */
{
- const uint outputAttrs = ctx->st->state.vs.outputs_written;
+ const uint outputAttrs = ctx->st->state.vs->outputs_written;
const float *pos, *color0, *color1, *tex0;
float *buf = buf_map;
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 516d319a6ee..a8ae5d9c562 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -78,6 +78,8 @@ struct st_context
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_state *depth_stencil;
const struct pipe_rasterizer_state *rasterizer;
+ const struct pipe_shader_state *fs;
+ const struct pipe_shader_state *vs;
struct pipe_alpha_test_state alpha_test;
struct pipe_blend_color blend_color;
@@ -89,8 +91,6 @@ struct st_context
struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS];
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
- struct pipe_shader_state fs;
- struct pipe_shader_state vs;
struct pipe_viewport_state viewport;
} state;
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index f68e449f079..ac63a387205 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -193,7 +193,7 @@ st_draw_vbo(GLcontext *ctx,
update_default_attribs_buffer(ctx);
/* this must be after state validation */
- attrsNeeded = ctx->st->state.vs.inputs_read;
+ attrsNeeded = ctx->st->state.vs->inputs_read;
/* tell pipe about the vertex array element/attributes */
for (attr = 0; attr < 16; attr++) {
@@ -395,14 +395,14 @@ 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);
- draw_set_vertex_shader(draw, &st->state.vs);
+ draw_set_vertex_shader(draw, st->state.vs);
/* XXX need to set vertex info too */
update_default_attribs_buffer(ctx);
/* this must be after state validation */
- attrsNeeded = ctx->st->state.vs.inputs_read;
+ attrsNeeded = ctx->st->state.vs->inputs_read;
/* tell draw module about the vertex array element/attributes */
for (attr = 0; attr < 16; attr++) {
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 7a91983ce9e..a2f114b1bab 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -53,8 +53,8 @@ struct st_fragment_program
struct tgsi_token tokens[ST_FP_MAX_TOKENS];
GLboolean dirty;
-
- struct pipe_shader_state fs;
+
+ const struct pipe_shader_state *fsx;
GLuint param_state;
};
@@ -75,7 +75,7 @@ struct st_vertex_program
struct x86_function sse2_program;
#endif
- struct pipe_shader_state vs;
+ const struct pipe_shader_state *vs;
GLuint param_state;
};