From f117327a3f246713abfd4dc4320d4a1a7f1b811a Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 17 Sep 2007 09:47:41 -0400 Subject: Make sampler an immutable state object. Switch the sample to be an immutable state object. --- src/mesa/state_tracker/st_atom_sampler.c | 10 +++++++--- src/mesa/state_tracker/st_cache.c | 17 +++++++++++++++++ src/mesa/state_tracker/st_cache.h | 6 ++++++ src/mesa/state_tracker/st_cb_drawpixels.c | 6 ++++-- src/mesa/state_tracker/st_context.h | 4 ++-- 5 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index d65565f991..9a728e2d79 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -33,6 +33,7 @@ #include "st_context.h" +#include "st_cache.h" #include "st_atom.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -142,10 +143,13 @@ update_samplers(struct st_context *st) /* XXX more sampler state here */ } - if (memcmp(&sampler, &st->state.sampler[u], sizeof(sampler)) != 0) { + const struct pipe_sampler_state *cached_sampler = + st_cached_sampler_state(st, &sampler); + + if (cached_sampler == st->state.sampler[u]) { /* state has changed */ - st->state.sampler[u] = sampler; - st->pipe->set_sampler_state(st->pipe, u, &sampler); + st->state.sampler[u] = cached_sampler; + st->pipe->bind_sampler_state(st->pipe, u, cached_sampler); } } } diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 0205b1cab3..99fb45f00a 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -59,3 +59,20 @@ struct pipe_blend_state * st_cached_blend_state( } return (struct pipe_blend_state*)(cso_hash_iter_data(iter)); } + +struct pipe_sampler_state * st_cached_sampler_state( + struct st_context *st, + const struct pipe_sampler_state *sampler) +{ + unsigned hash_key = cso_construct_key((void*)sampler, sizeof(struct pipe_sampler_state)); + struct cso_hash_iter iter = cso_find_state_template(st->cache, + hash_key, CSO_SAMPLER, + (void*)sampler); + if (cso_hash_iter_is_null(iter)) { + const struct pipe_sampler_state *created_state = st->pipe->create_sampler_state( + st->pipe, sampler); + iter = cso_insert_state(st->cache, hash_key, CSO_SAMPLER, + (void*)created_state); + } + return (struct pipe_sampler_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 29b1d00dca..927585141c 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -34,10 +34,16 @@ #define ST_CACHE_H struct pipe_blend_state; +struct pipe_sampler_state; struct st_context; struct pipe_blend_state * st_cached_blend_state( struct st_context *st, const struct pipe_blend_state *blend); +struct pipe_sampler_state * st_cached_sampler_state( + struct st_context *st, + const struct pipe_sampler_state *sampler); + + #endif diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c2d231cdb5..31a37e5cd4 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -34,6 +34,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_cache.h" #include "st_draw.h" #include "st_program.h" #include "st_cb_drawpixels.h" @@ -359,7 +360,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - pipe->set_sampler_state(pipe, unit, &sampler); + const struct pipe_sampler_state *state = st_cached_sampler_state(ctx->st, &sampler); + pipe->bind_sampler_state(pipe, unit, state); } /* viewport state: viewport matching window dims */ @@ -402,7 +404,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_fs_state(pipe, &ctx->st->state.fs); pipe->set_vs_state(pipe, &ctx->st->state.vs); pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]); - pipe->set_sampler_state(pipe, unit, &ctx->st->state.sampler[unit]); + pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); free_mipmap_tree(pipe, mt); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index bd2efdb960..13526ff9e7 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -74,7 +74,8 @@ struct st_context * though, we just shove random objects across the interface. */ struct { - const struct pipe_blend_state *blend; + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; struct pipe_alpha_test_state alpha_test; struct pipe_blend_color blend_color; @@ -86,7 +87,6 @@ struct st_context struct pipe_framebuffer_state framebuffer; struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; - struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; struct pipe_scissor_state scissor; struct pipe_setup_state setup; struct pipe_shader_state fs; -- cgit v1.2.3