Make the alpha test state a cso.

This commit is contained in:
Zack Rusin 2007-09-21 07:00:20 -04:00
parent b0fa489eba
commit 6cb87cf26f
23 changed files with 177 additions and 64 deletions

View file

@ -90,6 +90,9 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_
case CSO_VERTEX_SHADER:
hash = sc->vs_hash;
break;
case CSO_ALPHA_TEST:
hash = sc->alpha_hash;
break;
}
return hash;
@ -110,6 +113,8 @@ static int _cso_size_for_type(enum cso_cache_type type)
return sizeof(struct pipe_shader_state);
case CSO_VERTEX_SHADER:
return sizeof(struct pipe_shader_state);
case CSO_ALPHA_TEST:
return sizeof(struct pipe_alpha_test_state);
}
return 0;
}
@ -164,6 +169,7 @@ struct cso_cache *cso_cache_create(void)
sc->rasterizer_hash = cso_hash_create();
sc->fs_hash = cso_hash_create();
sc->vs_hash = cso_hash_create();
sc->alpha_hash = cso_hash_create();
return sc;
}
@ -177,5 +183,6 @@ void cso_cache_delete(struct cso_cache *sc)
cso_hash_delete(sc->rasterizer_hash);
cso_hash_delete(sc->fs_hash);
cso_hash_delete(sc->vs_hash);
cso_hash_delete(sc->alpha_hash);
free(sc);
}

View file

@ -40,12 +40,13 @@
struct cso_hash;
struct cso_cache {
struct cso_hash *alpha_hash;
struct cso_hash *blend_hash;
struct cso_hash *sampler_hash;
struct cso_hash *depth_stencil_hash;
struct cso_hash *rasterizer_hash;
struct cso_hash *fs_hash;
struct cso_hash *vs_hash;
struct cso_hash *rasterizer_hash;
struct cso_hash *sampler_hash;
};
struct cso_blend {
@ -78,13 +79,19 @@ struct cso_sampler {
void *data;
};
struct cso_alpha_test {
struct pipe_alpha_test_state state;
void *data;
};
enum cso_cache_type {
CSO_BLEND,
CSO_SAMPLER,
CSO_DEPTH_STENCIL,
CSO_RASTERIZER,
CSO_FRAGMENT_SHADER,
CSO_VERTEX_SHADER
CSO_VERTEX_SHADER,
CSO_ALPHA_TEST
};
unsigned cso_construct_key(void *item, int item_size);

View file

@ -64,12 +64,13 @@ struct fo_state {
void *sw_state;
void *hw_state;
};
struct failover_context {
struct failover_context {
struct pipe_context pipe; /**< base class */
/* The most recent drawing state as set by the driver:
*/
const struct fo_state *alpha_test;
const struct fo_state *blend;
const struct fo_state *sampler[PIPE_MAX_SAMPLERS];
const struct fo_state *depth_stencil;
@ -77,7 +78,6 @@ struct failover_context {
const struct fo_state *fragment_shader;
const struct fo_state *vertex_shader;
struct pipe_alpha_test_state alpha_test;
struct pipe_blend_color blend_color;
struct pipe_clear_color_state clear_color;
struct pipe_clip_state clip;

View file

@ -45,15 +45,44 @@
* lower overheads.
*/
static void
failover_set_alpha_test_state(struct pipe_context *pipe,
const struct pipe_alpha_test_state *alpha)
static void *
failover_create_alpha_test_state(struct pipe_context *pipe,
const struct pipe_alpha_test_state *templ)
{
struct fo_state *state = malloc(sizeof(struct fo_state));
struct failover_context *failover = failover_context(pipe);
failover->alpha_test = *alpha;
state->sw_state = failover->sw->create_alpha_test_state(pipe, templ);
state->hw_state = failover->hw->create_alpha_test_state(pipe, templ);
return state;
}
static void
failover_bind_alpha_test_state(struct pipe_context *pipe,
void *alpha)
{
struct failover_context *failover = failover_context(pipe);
struct fo_state *state = (struct fo_state *)alpha;
failover->alpha_test = state;
failover->dirty |= FO_NEW_ALPHA_TEST;
failover->hw->set_alpha_test_state( failover->hw, alpha );
failover->hw->bind_alpha_test_state(failover->hw,
state->hw_state);
}
static void
failover_delete_alpha_test_state(struct pipe_context *pipe,
void *alpha)
{
struct fo_state *state = (struct fo_state*)alpha;
struct failover_context *failover = failover_context(pipe);
failover->sw->delete_alpha_test_state(pipe, state->sw_state);
failover->hw->delete_alpha_test_state(pipe, state->hw_state);
state->sw_state = 0;
state->hw_state = 0;
free(state);
}
@ -95,7 +124,7 @@ failover_delete_blend_state( struct pipe_context *pipe,
free(state);
}
static void
static void
failover_set_blend_color( struct pipe_context *pipe,
const struct pipe_blend_color *blend_color )
{
@ -414,8 +443,11 @@ failover_set_vertex_element(struct pipe_context *pipe,
void
failover_init_state_functions( struct failover_context *failover )
{
failover->pipe.create_alpha_test_state = failover_create_alpha_test_state;
failover->pipe.bind_alpha_test_state = failover_bind_alpha_test_state;
failover->pipe.delete_alpha_test_state = failover_delete_alpha_test_state;
failover->pipe.create_blend_state = failover_create_blend_state;
failover->pipe.bind_blend_state = failover_bind_blend_state;
failover->pipe.bind_blend_state = failover_bind_blend_state;
failover->pipe.delete_blend_state = failover_delete_blend_state;
failover->pipe.create_sampler_state = failover_create_sampler_state;
failover->pipe.bind_sampler_state = failover_bind_sampler_state;
@ -433,7 +465,6 @@ failover_init_state_functions( struct failover_context *failover )
failover->pipe.bind_vs_state = failover_bind_vs_state;
failover->pipe.delete_vs_state = failover_delete_vs_state;
failover->pipe.set_alpha_test_state = failover_set_alpha_test_state;
failover->pipe.set_blend_color = failover_set_blend_color;
failover->pipe.set_clip_state = failover_set_clip_state;
failover->pipe.set_clear_color_state = failover_set_clear_color_state;

View file

@ -56,7 +56,8 @@ failover_state_emit( struct failover_context *failover )
unsigned i;
if (failover->dirty & FO_NEW_ALPHA_TEST)
failover->sw->set_alpha_test_state( failover->sw, &failover->alpha_test );
failover->sw->bind_alpha_test_state( failover->sw,
failover->alpha_test->sw_state );
if (failover->dirty & FO_NEW_BLEND)
failover->sw->bind_blend_state( failover->sw,

View file

@ -154,13 +154,13 @@ struct i915_context
/* The most recent drawing state as set by the driver:
*/
const struct pipe_alpha_test_state *alpha_test;
const struct i915_blend_state *blend;
const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct i915_depth_stencil_state *depth_stencil;
const struct i915_rasterizer_state *rasterizer;
const struct pipe_shader_state *fs;
struct pipe_alpha_test_state alpha_test;
struct pipe_blend_color blend_color;
struct pipe_clear_color_state clear_color;
struct pipe_clip_state clip;

View file

@ -394,16 +394,29 @@ static void i915_delete_depth_stencil_state(struct pipe_context *pipe,
free(depth_stencil);
}
static void i915_set_alpha_test_state(struct pipe_context *pipe,
const struct pipe_alpha_test_state *alpha)
static void *
i915_create_alpha_test_state(struct pipe_context *pipe,
const struct pipe_alpha_test_state *alpha)
{
return 0;
}
static void i915_bind_alpha_test_state(struct pipe_context *pipe,
void *alpha)
{
struct i915_context *i915 = i915_context(pipe);
i915->alpha_test = *alpha;
i915->alpha_test = (const struct pipe_alpha_test_state*)alpha;
i915->dirty |= I915_NEW_ALPHA_TEST;
}
static void i915_delete_alpha_test_state(struct pipe_context *pipe,
void *alpha)
{
}
static void i915_set_scissor_state( struct pipe_context *pipe,
const struct pipe_scissor_state *scissor )
{
@ -664,6 +677,10 @@ static void i915_set_vertex_element( struct pipe_context *pipe,
void
i915_init_state_functions( struct i915_context *i915 )
{
i915->pipe.create_alpha_test_state = i915_create_alpha_test_state;
i915->pipe.bind_alpha_test_state = i915_bind_alpha_test_state;
i915->pipe.delete_alpha_test_state = i915_delete_alpha_test_state;
i915->pipe.create_blend_state = i915_create_blend_state;
i915->pipe.bind_blend_state = i915_bind_blend_state;
i915->pipe.delete_blend_state = i915_delete_blend_state;
@ -686,7 +703,6 @@ i915_init_state_functions( struct i915_context *i915 )
i915->pipe.bind_vs_state = i915_bind_vs_state;
i915->pipe.delete_vs_state = i915_delete_shader_state;
i915->pipe.set_alpha_test_state = i915_set_alpha_test_state;
i915->pipe.set_blend_color = i915_set_blend_color;
i915->pipe.set_clip_state = i915_set_clip_state;
i915->pipe.set_clear_color_state = i915_set_clear_color_state;

View file

@ -121,9 +121,9 @@ static void upload_S6( struct i915_context *i915 )
/* I915_NEW_ALPHA_TEST
*/
if (i915->alpha_test.enabled) {
int test = i915_translate_compare_func(i915->alpha_test.func);
ubyte refByte = float_to_ubyte(i915->alpha_test.ref);
if (i915->alpha_test->enabled) {
int test = i915_translate_compare_func(i915->alpha_test->func);
ubyte refByte = float_to_ubyte(i915->alpha_test->ref);
LIS6 |= (S6_ALPHA_TEST_ENABLE |

View file

@ -86,26 +86,30 @@ struct pipe_context {
/*
* State functions
*/
void * (*create_alpha_test_state)(struct pipe_context *,
const struct pipe_alpha_test_state *);
void (*bind_alpha_test_state)(struct pipe_context *, void *);
void (*delete_alpha_test_state)(struct pipe_context *, void *);
void * (*create_blend_state)(struct pipe_context *,
const struct pipe_blend_state *);
void (*bind_blend_state)(struct pipe_context *, void *);
void (*delete_blend_state)(struct pipe_context *, void *);
void (*bind_blend_state)(struct pipe_context *, void *);
void (*delete_blend_state)(struct pipe_context *, void *);
void * (*create_sampler_state)(struct pipe_context *,
const struct pipe_sampler_state *);
void (*bind_sampler_state)(struct pipe_context *, unsigned unit,
void *);
void (*delete_sampler_state)(struct pipe_context *, void *);
void (*bind_sampler_state)(struct pipe_context *, unsigned unit, void *);
void (*delete_sampler_state)(struct pipe_context *, void *);
void *(*create_rasterizer_state)(struct pipe_context *,
const struct pipe_rasterizer_state *);
void (*bind_rasterizer_state)(struct pipe_context *, void *);
void (*delete_rasterizer_state)(struct pipe_context *, void *);
void * (*create_rasterizer_state)(struct pipe_context *,
const struct pipe_rasterizer_state *);
void (*bind_rasterizer_state)(struct pipe_context *, void *);
void (*delete_rasterizer_state)(struct pipe_context *, void *);
void * (*create_depth_stencil_state)(struct pipe_context *,
const struct pipe_depth_stencil_state *);
void (*bind_depth_stencil_state)(struct pipe_context *, void *);
void (*delete_depth_stencil_state)(struct pipe_context *, void *);
void (*bind_depth_stencil_state)(struct pipe_context *, void *);
void (*delete_depth_stencil_state)(struct pipe_context *, void *);
void * (*create_fs_state)(struct pipe_context *,
const struct pipe_shader_state *);
@ -117,9 +121,9 @@ struct pipe_context {
void (*bind_vs_state)(struct pipe_context *, void *);
void (*delete_vs_state)(struct pipe_context *, void *);
void (*set_alpha_test_state)( struct pipe_context *,
const struct pipe_alpha_test_state * );
/* The following look more properties than states.
* maybe combine a few of them into states or pass them
* in the bind calls to the state */
void (*set_blend_color)( struct pipe_context *,
const struct pipe_blend_color * );

View file

@ -260,6 +260,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
softpipe->pipe.get_param = softpipe_get_param;
/* state setters */
softpipe->pipe.create_alpha_test_state = softpipe_create_alpha_test_state;
softpipe->pipe.bind_alpha_test_state = softpipe_bind_alpha_test_state;
softpipe->pipe.delete_alpha_test_state = softpipe_delete_alpha_test_state;
softpipe->pipe.create_blend_state = softpipe_create_blend_state;
softpipe->pipe.bind_blend_state = softpipe_bind_blend_state;
softpipe->pipe.delete_blend_state = softpipe_delete_blend_state;
@ -279,7 +282,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
softpipe->pipe.bind_vs_state = softpipe_bind_vs_state;
softpipe->pipe.delete_vs_state = softpipe_delete_shader_state;
softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state;
softpipe->pipe.set_blend_color = softpipe_set_blend_color;
softpipe->pipe.set_clip_state = softpipe_set_clip_state;
softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;

View file

@ -70,6 +70,7 @@ struct softpipe_context {
/* The most recent drawing state as set by the driver:
*/
const struct pipe_alpha_test_state *alpha_test;
const struct pipe_blend_state *blend;
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_state *depth_stencil;
@ -77,7 +78,6 @@ struct softpipe_context {
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;
struct pipe_clear_color_state clear_color;
struct pipe_clip_state clip;

View file

@ -54,7 +54,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp)
sp->quad.first = sp->quad.depth_test;
}
if (sp->alpha_test.enabled) {
if (sp->alpha_test->enabled) {
sp->quad.alpha_test->next = sp->quad.first;
sp->quad.first = sp->quad.alpha_test;
}

View file

@ -14,10 +14,10 @@ static void
alpha_test_quad(struct quad_stage *qs, struct quad_header *quad)
{
struct softpipe_context *softpipe = qs->softpipe;
const float ref = softpipe->alpha_test.ref;
const float ref = softpipe->alpha_test->ref;
unsigned passMask = 0x0, j;
switch (softpipe->alpha_test.func) {
switch (softpipe->alpha_test->func) {
case PIPE_FUNC_NEVER:
quad->mask = 0x0;
break;

View file

@ -33,6 +33,15 @@
#include "pipe/p_state.h"
void *
softpipe_create_alpha_test_state(struct pipe_context *,
const struct pipe_alpha_test_state *);
void
softpipe_bind_alpha_test_state(struct pipe_context *, void *);
void
softpipe_delete_alpha_test_state(struct pipe_context *, void *);
void *
softpipe_create_blend_state(struct pipe_context *,
const struct pipe_blend_state *);
@ -62,9 +71,6 @@ void softpipe_delete_rasterizer_state(struct pipe_context *, void *);
void softpipe_set_framebuffer_state( struct pipe_context *,
const struct pipe_framebuffer_state * );
void softpipe_set_alpha_test_state( struct pipe_context *,
const struct pipe_alpha_test_state * );
void softpipe_set_blend_color( struct pipe_context *pipe,
const struct pipe_blend_color *blend_color );

View file

@ -71,17 +71,31 @@ void softpipe_set_blend_color( struct pipe_context *pipe,
* into one file.
*/
void *
softpipe_create_alpha_test_state(struct pipe_context *pipe,
const struct pipe_alpha_test_state *alpha)
{
return 0;
}
void
softpipe_set_alpha_test_state(struct pipe_context *pipe,
const struct pipe_alpha_test_state *alpha)
softpipe_bind_alpha_test_state(struct pipe_context *pipe,
void *alpha)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
softpipe->alpha_test = *alpha;
softpipe->alpha_test = (const struct pipe_alpha_test_state *)alpha;
softpipe->dirty |= SP_NEW_ALPHA_TEST;
}
void
softpipe_delete_alpha_test_state(struct pipe_context *pipe,
void *alpha)
{
/* do nothing */
}
void *
softpipe_create_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil)

View file

@ -62,6 +62,7 @@ static const struct st_tracked_state *atoms[] =
&st_update_texture,
&st_update_vs_constants,
&st_update_fs_constants,
&st_update_alpha_test
};

View file

@ -60,6 +60,7 @@ const struct st_tracked_state st_update_sampler;
const struct st_tracked_state st_update_texture;
const struct st_tracked_state st_update_fs_constants;
const struct st_tracked_state st_update_vs_constants;
const struct st_tracked_state st_update_alpha_test;
#endif

View file

@ -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"
@ -63,6 +64,7 @@ static void
update_alpha_test( struct st_context *st )
{
struct pipe_alpha_test_state alpha;
const struct cso_alpha_test *cso;
memset(&alpha, 0, sizeof(alpha));
@ -71,11 +73,11 @@ update_alpha_test( struct st_context *st )
alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc);
alpha.ref = st->ctx->Color.AlphaRef;
}
if (memcmp(&alpha, &st->state.alpha_test, sizeof(alpha)) != 0) {
cso = st_cached_alpha_test_state(st, &alpha);
if (st->state.alpha_test != cso) {
/* state has changed */
st->state.alpha_test = alpha; /* struct copy */
st->pipe->set_alpha_test_state(st->pipe, &alpha); /* set new state */
st->state.alpha_test = cso;
st->pipe->bind_alpha_test_state(st->pipe, cso->data); /* bind new state */
}
}
@ -88,8 +90,3 @@ const struct st_tracked_state st_update_alpha_test = {
},
.update = update_alpha_test
};

View file

@ -159,3 +159,23 @@ st_cached_vs_state(struct st_context *st,
}
return (struct cso_vertex_shader*)(cso_hash_iter_data(iter));
}
const struct cso_alpha_test *
st_cached_alpha_test_state(struct st_context *st,
const struct pipe_alpha_test_state *templ)
{
unsigned hash_key = cso_construct_key((void*)templ,
sizeof(struct pipe_alpha_test_state));
struct cso_hash_iter iter = cso_find_state_template(st->cache,
hash_key, CSO_ALPHA_TEST,
(void*)templ);
if (cso_hash_iter_is_null(iter)) {
struct cso_alpha_test *cso = malloc(sizeof(struct cso_alpha_test));
memcpy(&cso->state, templ, sizeof(struct pipe_alpha_test_state));
cso->data = st->pipe->create_alpha_test_state(st->pipe, &cso->state);
if (!cso->data)
cso->data = &cso->state;
iter = cso_insert_state(st->cache, hash_key, CSO_ALPHA_TEST, cso);
}
return ((struct cso_alpha_test *)cso_hash_iter_data(iter));
}

View file

@ -39,6 +39,10 @@ struct pipe_blend_state;
struct pipe_sampler_state;
struct st_context;
const struct cso_alpha_test *
st_cached_alpha_test_state(struct st_context *st,
const struct pipe_alpha_test_state *alpha);
const struct cso_blend *
st_cached_blend_state(struct st_context *st,
const struct pipe_blend_state *blend);

View file

@ -275,8 +275,10 @@ clear_with_quad(GLcontext *ctx,
/* alpha state: disabled */
{
struct pipe_alpha_test_state alpha_test;
const struct cso_alpha_test *cso;
memset(&alpha_test, 0, sizeof(alpha_test));
pipe->set_alpha_test_state(pipe, &alpha_test);
cso = st_cached_alpha_test_state(st, &alpha_test);
pipe->bind_alpha_test_state(pipe, cso->data);
}
/* blend state: RGBA masking */
@ -379,7 +381,7 @@ clear_with_quad(GLcontext *ctx,
draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor);
/* Restore pipe state */
pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
pipe->bind_alpha_test_state(pipe, st->state.alpha_test->data);
pipe->bind_blend_state(pipe, st->state.blend->data);
pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil->data);
pipe->bind_fs_state(pipe, st->state.fs->data);

View file

@ -468,7 +468,7 @@ compatible_formats(GLenum format, GLenum type, GLuint pipeFormat)
static GLboolean
any_fragment_ops(const struct st_context *st)
{
if (st->state.alpha_test.enabled ||
if (st->state.alpha_test->state.enabled ||
st->state.blend->state.blend_enable ||
st->state.blend->state.logicop_enable ||
st->state.depth_stencil->state.depth.enabled)

View file

@ -75,14 +75,14 @@ struct st_context
* though, we just shove random objects across the interface.
*/
struct {
const struct cso_blend *blend;
const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS];
const struct cso_depth_stencil *depth_stencil;
const struct cso_rasterizer *rasterizer;
const struct cso_alpha_test *alpha_test;
const struct cso_blend *blend;
const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS];
const struct cso_depth_stencil *depth_stencil;
const struct cso_rasterizer *rasterizer;
const struct cso_fragment_shader *fs;
const struct cso_vertex_shader *vs;
struct pipe_alpha_test_state alpha_test;
struct pipe_blend_color blend_color;
struct pipe_clear_color_state clear_color;
struct pipe_clip_state clip;