Convert depth_stencil state to the new semantics.

This commit is contained in:
Zack Rusin
2007-09-20 08:35:10 -04:00
parent daf5b0f41b
commit a6c0c5532f
14 changed files with 88 additions and 66 deletions

View File

@@ -53,6 +53,11 @@ struct cso_blend {
void *data; void *data;
}; };
struct cso_depth_stencil {
struct pipe_depth_stencil_state state;
void *data;
};
struct cso_rasterizer { struct cso_rasterizer {
struct pipe_rasterizer_state state; struct pipe_rasterizer_state state;
void *data; void *data;

View File

@@ -72,7 +72,7 @@ struct failover_context {
*/ */
const struct fo_state *blend; const struct fo_state *blend;
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_state *depth_stencil; const struct fo_state *depth_stencil;
const struct fo_state *rasterizer; const struct fo_state *rasterizer;
const struct fo_state *fragment_shader; const struct fo_state *fragment_shader;
const struct fo_state *vertex_shader; const struct fo_state *vertex_shader;

View File

@@ -128,17 +128,44 @@ failover_set_clear_color_state( struct pipe_context *pipe,
failover->hw->set_clear_color_state( failover->hw, clear_color ); failover->hw->set_clear_color_state( failover->hw, clear_color );
} }
static void *
failover_create_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *templ)
{
struct fo_state *state = malloc(sizeof(struct fo_state));
struct failover_context *failover = failover_context(pipe);
state->sw_state = failover->sw->create_depth_stencil_state(pipe, templ);
state->hw_state = failover->hw->create_depth_stencil_state(pipe, templ);
return state;
}
static void static void
failover_bind_depth_stencil_state(struct pipe_context *pipe, failover_bind_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil) void *depth_stencil)
{ {
struct failover_context *failover = failover_context(pipe); struct failover_context *failover = failover_context(pipe);
failover->depth_stencil = depth_stencil; failover->depth_stencil = (struct fo_state *)depth_stencil;
failover->dirty |= FO_NEW_DEPTH_STENCIL; failover->dirty |= FO_NEW_DEPTH_STENCIL;
failover->hw->bind_depth_stencil_state( failover->hw, depth_stencil ); failover->hw->bind_depth_stencil_state( failover->hw, depth_stencil );
} }
static void
failover_delete_depth_stencil_state(struct pipe_context *pipe,
void *ds)
{
struct fo_state *state = (struct fo_state*)ds;
struct failover_context *failover = failover_context(pipe);
failover->sw->delete_depth_stencil_state(pipe, state->sw_state);
failover->hw->delete_depth_stencil_state(pipe, state->hw_state);
state->sw_state = 0;
state->hw_state = 0;
free(state);
}
static void static void
failover_set_framebuffer_state(struct pipe_context *pipe, failover_set_framebuffer_state(struct pipe_context *pipe,
const struct pipe_framebuffer_state *framebuffer) const struct pipe_framebuffer_state *framebuffer)
@@ -363,7 +390,9 @@ failover_init_state_functions( struct failover_context *failover )
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.delete_blend_state = failover_delete_blend_state;
failover->pipe.bind_sampler_state = failover_bind_sampler_state; failover->pipe.bind_sampler_state = failover_bind_sampler_state;
failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state; failover->pipe.create_depth_stencil_state = failover_create_depth_stencil_state;
failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state;
failover->pipe.delete_depth_stencil_state = failover_delete_depth_stencil_state;
failover->pipe.create_rasterizer_state = failover_create_rasterizer_state; failover->pipe.create_rasterizer_state = failover_create_rasterizer_state;
failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state;
failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state; failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state;

View File

@@ -72,7 +72,8 @@ failover_state_emit( struct failover_context *failover )
failover->sw->set_clear_color_state( failover->sw, &failover->clear_color ); failover->sw->set_clear_color_state( failover->sw, &failover->clear_color );
if (failover->dirty & FO_NEW_DEPTH_STENCIL) if (failover->dirty & FO_NEW_DEPTH_STENCIL)
failover->sw->bind_depth_stencil_state( failover->sw, failover->depth_stencil ); failover->sw->bind_depth_stencil_state( failover->sw,
failover->depth_stencil->sw_state );
if (failover->dirty & FO_NEW_FRAMEBUFFER) if (failover->dirty & FO_NEW_FRAMEBUFFER)
failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer );

View File

@@ -175,31 +175,27 @@ static void i915_delete_sampler_state(struct pipe_context *pipe,
* into one file. * into one file.
*/ */
static const struct pipe_depth_stencil_state * static void *
i915_create_depth_stencil_state(struct pipe_context *pipe, i915_create_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil) const struct pipe_depth_stencil_state *depth_stencil)
{ {
struct pipe_depth_stencil_state *new_ds = return 0;
malloc(sizeof(struct pipe_depth_stencil_state));
memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state));
return new_ds;
} }
static void i915_bind_depth_stencil_state(struct pipe_context *pipe, static void i915_bind_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil) void *depth_stencil)
{ {
struct i915_context *i915 = i915_context(pipe); struct i915_context *i915 = i915_context(pipe);
i915->depth_stencil = depth_stencil; i915->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil;
i915->dirty |= I915_NEW_DEPTH_STENCIL; i915->dirty |= I915_NEW_DEPTH_STENCIL;
} }
static void i915_delete_depth_stencil_state(struct pipe_context *pipe, static void i915_delete_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil) void *depth_stencil)
{ {
free((struct pipe_depth_stencil_state *)depth_stencil); /* do nothing */
} }
static void i915_set_alpha_test_state(struct pipe_context *pipe, static void i915_set_alpha_test_state(struct pipe_context *pipe,

View File

@@ -105,13 +105,10 @@ struct pipe_context {
void (*bind_rasterizer_state)(struct pipe_context *, void *); void (*bind_rasterizer_state)(struct pipe_context *, void *);
void (*delete_rasterizer_state)(struct pipe_context *, void *); void (*delete_rasterizer_state)(struct pipe_context *, void *);
const struct pipe_depth_stencil_state * (*create_depth_stencil_state)( void * (*create_depth_stencil_state)(struct pipe_context *,
struct pipe_context *, const struct pipe_depth_stencil_state *);
const struct pipe_depth_stencil_state *); void (*bind_depth_stencil_state)(struct pipe_context *, void *);
void (*bind_depth_stencil_state)(struct pipe_context *, void (*delete_depth_stencil_state)(struct pipe_context *, void *);
const struct pipe_depth_stencil_state *);
void (*delete_depth_stencil_state)(struct pipe_context *,
const struct pipe_depth_stencil_state *);
void * (*create_fs_state)(struct pipe_context *, void * (*create_fs_state)(struct pipe_context *,
const struct pipe_shader_state *); const struct pipe_shader_state *);

View File

@@ -50,21 +50,17 @@ void softpipe_bind_sampler_state(struct pipe_context *,
void softpipe_delete_sampler_state(struct pipe_context *, void softpipe_delete_sampler_state(struct pipe_context *,
const struct pipe_sampler_state *); const struct pipe_sampler_state *);
const struct pipe_depth_stencil_state * void *
softpipe_create_depth_stencil_state(struct pipe_context *, softpipe_create_depth_stencil_state(struct pipe_context *,
const struct pipe_depth_stencil_state *); const struct pipe_depth_stencil_state *);
void softpipe_bind_depth_stencil_state(struct pipe_context *, void softpipe_bind_depth_stencil_state(struct pipe_context *, void *);
const struct pipe_depth_stencil_state *); void softpipe_delete_depth_stencil_state(struct pipe_context *, void *);
void softpipe_delete_depth_stencil_state(struct pipe_context *,
const struct pipe_depth_stencil_state *);
void * void *
softpipe_create_rasterizer_state(struct pipe_context *, softpipe_create_rasterizer_state(struct pipe_context *,
const struct pipe_rasterizer_state *); const struct pipe_rasterizer_state *);
void softpipe_bind_rasterizer_state(struct pipe_context *, void softpipe_bind_rasterizer_state(struct pipe_context *, void *);
void *); void softpipe_delete_rasterizer_state(struct pipe_context *, void *);
void softpipe_delete_rasterizer_state(struct pipe_context *,
void *);
void softpipe_set_framebuffer_state( struct pipe_context *, void softpipe_set_framebuffer_state( struct pipe_context *,
const struct pipe_framebuffer_state * ); const struct pipe_framebuffer_state * );

View File

@@ -82,30 +82,26 @@ softpipe_set_alpha_test_state(struct pipe_context *pipe,
softpipe->dirty |= SP_NEW_ALPHA_TEST; softpipe->dirty |= SP_NEW_ALPHA_TEST;
} }
const struct pipe_depth_stencil_state * void *
softpipe_create_depth_stencil_state(struct pipe_context *pipe, softpipe_create_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil) const struct pipe_depth_stencil_state *depth_stencil)
{ {
struct pipe_depth_stencil_state *new_ds = malloc(sizeof(struct pipe_depth_stencil_state)); return 0;
memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state));
return new_ds;
} }
void void
softpipe_bind_depth_stencil_state(struct pipe_context *pipe, softpipe_bind_depth_stencil_state(struct pipe_context *pipe,
const struct pipe_depth_stencil_state *depth_stencil) void *depth_stencil)
{ {
struct softpipe_context *softpipe = softpipe_context(pipe); struct softpipe_context *softpipe = softpipe_context(pipe);
softpipe->depth_stencil = depth_stencil; softpipe->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil;
softpipe->dirty |= SP_NEW_DEPTH_STENCIL; softpipe->dirty |= SP_NEW_DEPTH_STENCIL;
} }
void void
softpipe_delete_depth_stencil_state(struct pipe_context *pipe, softpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth)
const struct pipe_depth_stencil_state *depth)
{ {
free((struct pipe_depth_stencil_state*)depth); /* do nothing */
} }

View File

@@ -115,6 +115,7 @@ static void
update_depth_stencil(struct st_context *st) update_depth_stencil(struct st_context *st)
{ {
struct pipe_depth_stencil_state depth_stencil; struct pipe_depth_stencil_state depth_stencil;
const struct cso_depth_stencil *cso;
memset(&depth_stencil, 0, sizeof(depth_stencil)); memset(&depth_stencil, 0, sizeof(depth_stencil));
@@ -149,12 +150,11 @@ update_depth_stencil(struct st_context *st)
depth_stencil.stencil.clear_value = st->ctx->Stencil.Clear & 0xff; depth_stencil.stencil.clear_value = st->ctx->Stencil.Clear & 0xff;
} }
struct pipe_depth_stencil_state *cached_state = cso = st_cached_depth_stencil_state(st, &depth_stencil);
st_cached_depth_stencil_state(st, &depth_stencil); if (st->state.depth_stencil != cso) {
if (st->state.depth_stencil != cached_state) {
/* state has changed */ /* state has changed */
st->state.depth_stencil = cached_state; st->state.depth_stencil = cso;
st->pipe->bind_depth_stencil_state(st->pipe, cached_state); /* set new state */ st->pipe->bind_depth_stencil_state(st->pipe, cso->data); /* bind new state */
} }
} }

View File

@@ -78,21 +78,24 @@ struct pipe_sampler_state * st_cached_sampler_state(
return (struct pipe_sampler_state*)(cso_hash_iter_data(iter)); return (struct pipe_sampler_state*)(cso_hash_iter_data(iter));
} }
struct pipe_depth_stencil_state * st_cached_depth_stencil_state( const struct cso_depth_stencil *
struct st_context *st, st_cached_depth_stencil_state(struct st_context *st,
const struct pipe_depth_stencil_state *depth_stencil) const struct pipe_depth_stencil_state *templ)
{ {
unsigned hash_key = cso_construct_key((void*)depth_stencil, sizeof(struct pipe_depth_stencil_state)); unsigned hash_key = cso_construct_key((void*)templ,
sizeof(struct pipe_depth_stencil_state));
struct cso_hash_iter iter = cso_find_state_template(st->cache, struct cso_hash_iter iter = cso_find_state_template(st->cache,
hash_key, CSO_DEPTH_STENCIL, hash_key, CSO_DEPTH_STENCIL,
(void*)depth_stencil); (void*)templ);
if (cso_hash_iter_is_null(iter)) { if (cso_hash_iter_is_null(iter)) {
const struct pipe_depth_stencil_state *created_state = st->pipe->create_depth_stencil_state( struct cso_depth_stencil *cso = malloc(sizeof(struct cso_depth_stencil));
st->pipe, depth_stencil); memcpy(&cso->state, templ, sizeof(struct pipe_depth_stencil_state));
iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, cso->data = st->pipe->create_depth_stencil_state(st->pipe, templ);
(void*)created_state); if (!cso->data)
cso->data = &cso->state;
iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, cso);
} }
return (struct pipe_depth_stencil_state*)(cso_hash_iter_data(iter)); return (struct cso_depth_stencil*)(cso_hash_iter_data(iter));
} }
const struct cso_rasterizer* st_cached_rasterizer_state( const struct cso_rasterizer* st_cached_rasterizer_state(

View File

@@ -47,9 +47,9 @@ struct pipe_sampler_state *
st_cached_sampler_state(struct st_context *st, st_cached_sampler_state(struct st_context *st,
const struct pipe_sampler_state *sampler); const struct pipe_sampler_state *sampler);
struct pipe_depth_stencil_state *st_cached_depth_stencil_state( const struct cso_depth_stencil *
struct st_context *st, st_cached_depth_stencil_state(struct st_context *st,
const struct pipe_depth_stencil_state *depth_stencil); const struct pipe_depth_stencil_state *depth_stencil);
const struct cso_rasterizer * const struct cso_rasterizer *
st_cached_rasterizer_state(struct st_context *st, st_cached_rasterizer_state(struct st_context *st,

View File

@@ -303,7 +303,7 @@ clear_with_quad(GLcontext *ctx,
/* depth_stencil state: always pass/set to ref value */ /* depth_stencil state: always pass/set to ref value */
{ {
struct pipe_depth_stencil_state depth_stencil; struct pipe_depth_stencil_state depth_stencil;
struct pipe_depth_stencil_state *cached; const struct cso_depth_stencil *cso;
memset(&depth_stencil, 0, sizeof(depth_stencil)); memset(&depth_stencil, 0, sizeof(depth_stencil));
if (depth) { if (depth) {
depth_stencil.depth.enabled = 1; depth_stencil.depth.enabled = 1;
@@ -321,9 +321,8 @@ clear_with_quad(GLcontext *ctx,
depth_stencil.stencil.value_mask[0] = 0xff; depth_stencil.stencil.value_mask[0] = 0xff;
depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff;
} }
cached = cso = st_cached_depth_stencil_state(ctx->st, &depth_stencil);
st_cached_depth_stencil_state(ctx->st, &depth_stencil); pipe->bind_depth_stencil_state(pipe, cso->data);
pipe->bind_depth_stencil_state(pipe, cached);
} }
/* setup state: nothing */ /* setup state: nothing */
@@ -382,7 +381,7 @@ clear_with_quad(GLcontext *ctx,
/* Restore pipe state */ /* Restore pipe state */
pipe->set_alpha_test_state(pipe, &st->state.alpha_test); pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
pipe->bind_blend_state(pipe, st->state.blend->data); pipe->bind_blend_state(pipe, st->state.blend->data);
pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil); pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil->data);
pipe->bind_fs_state(pipe, st->state.fs->data); pipe->bind_fs_state(pipe, st->state.fs->data);
pipe->bind_vs_state(pipe, st->state.vs->data); pipe->bind_vs_state(pipe, st->state.vs->data);
pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data);

View File

@@ -470,7 +470,7 @@ any_fragment_ops(const struct st_context *st)
if (st->state.alpha_test.enabled || if (st->state.alpha_test.enabled ||
st->state.blend->state.blend_enable || st->state.blend->state.blend_enable ||
st->state.blend->state.logicop_enable || st->state.blend->state.logicop_enable ||
st->state.depth_stencil->depth.enabled) st->state.depth_stencil->state.depth.enabled)
/* XXX more checks */ /* XXX more checks */
return GL_TRUE; return GL_TRUE;
else else

View File

@@ -77,7 +77,7 @@ struct st_context
struct { struct {
const struct cso_blend *blend; const struct cso_blend *blend;
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_state *depth_stencil; const struct cso_depth_stencil *depth_stencil;
const struct cso_rasterizer *rasterizer; const struct cso_rasterizer *rasterizer;
const struct cso_fragment_shader *fs; const struct cso_fragment_shader *fs;
const struct cso_vertex_shader *vs; const struct cso_vertex_shader *vs;