summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorRoland Scheidegger <sroland@vmware.com>2010-02-12 21:39:29 +0100
committerRoland Scheidegger <sroland@vmware.com>2010-02-12 21:39:29 +0100
commit6602889d82d1402338f5d23e37a9f46db99e86c6 (patch)
treede80ae0d9607b02252043852fe385418e4c5379a /src/gallium/auxiliary
parentaf1052e2804ee5fbcde3c8f8618feeb2c17b51fd (diff)
parent0087f9dc0690e5de139f89ea4577b1824b918757 (diff)
Merge branch 'gallium-dynamicstencilref'
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.c27
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.h6
-rw-r--r--src/gallium/auxiliary/util/u_blitter.c77
-rw-r--r--src/gallium/auxiliary/util/u_blitter.h8
4 files changed, 69 insertions, 49 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index c638239e80..b5241fa64c 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -93,6 +93,7 @@ struct cso_context {
struct pipe_framebuffer_state fb, fb_saved;
struct pipe_viewport_state vp, vp_saved;
struct pipe_blend_color blend_color;
+ struct pipe_stencil_ref stencil_ref, stencil_ref_saved;
};
@@ -1057,8 +1058,6 @@ void cso_restore_viewport(struct cso_context *ctx)
}
-
-
enum pipe_error cso_set_blend_color(struct cso_context *ctx,
const struct pipe_blend_color *bc)
{
@@ -1069,6 +1068,30 @@ enum pipe_error cso_set_blend_color(struct cso_context *ctx,
return PIPE_OK;
}
+enum pipe_error cso_set_stencil_ref(struct cso_context *ctx,
+ const struct pipe_stencil_ref *sr)
+{
+ if (memcmp(&ctx->stencil_ref, sr, sizeof(ctx->stencil_ref))) {
+ ctx->stencil_ref = *sr;
+ ctx->pipe->set_stencil_ref(ctx->pipe, sr);
+ }
+ return PIPE_OK;
+}
+
+void cso_save_stencil_ref(struct cso_context *ctx)
+{
+ ctx->stencil_ref_saved = ctx->stencil_ref;
+}
+
+
+void cso_restore_stencil_ref(struct cso_context *ctx)
+{
+ if (memcmp(&ctx->stencil_ref, &ctx->stencil_ref_saved, sizeof(ctx->stencil_ref))) {
+ ctx->stencil_ref = ctx->stencil_ref_saved;
+ ctx->pipe->set_stencil_ref(ctx->pipe, &ctx->stencil_ref);
+ }
+}
+
enum pipe_error cso_set_geometry_shader_handle(struct cso_context *ctx,
void *handle)
{
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
index d2089b1c88..707b3c2cee 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.h
+++ b/src/gallium/auxiliary/cso_cache/cso_context.h
@@ -174,6 +174,12 @@ enum pipe_error cso_set_blend_color(struct cso_context *cso,
const struct pipe_blend_color *bc);
+enum pipe_error cso_set_stencil_ref(struct cso_context *cso,
+ const struct pipe_stencil_ref *sr);
+void cso_save_stencil_ref(struct cso_context *cso);
+void cso_restore_stencil_ref(struct cso_context *cso);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index f3b4491d17..1f7e25b84f 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -60,13 +60,12 @@ struct blitter_context_priv
float vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */
/* Templates for various state objects. */
- struct pipe_depth_stencil_alpha_state template_dsa;
struct pipe_sampler_state template_sampler_state;
/* Constant state objects. */
/* Vertex shaders. */
void *vs_col; /**< Vertex shader which passes {pos, color} to the output */
- void *vs_tex; /**<Vertex shader which passes {pos, texcoord} to the output.*/
+ void *vs_tex; /**< Vertex shader which passes {pos, texcoord} to the output.*/
/* Fragment shaders. */
/* FS which outputs a color to multiple color buffers. */
@@ -85,7 +84,7 @@ struct blitter_context_priv
void *blend_keep_color; /**< blend state with writemask of 0 */
/* Depth stencil alpha state. */
- void *dsa_write_depth_stencil[0xff]; /**< indices are stencil clear values */
+ void *dsa_write_depth_stencil;
void *dsa_write_depth_keep_stencil;
void *dsa_keep_depth_stencil;
@@ -100,7 +99,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
{
struct blitter_context_priv *ctx;
struct pipe_blend_state blend;
- struct pipe_depth_stencil_alpha_state *dsa;
+ struct pipe_depth_stencil_alpha_state dsa;
struct pipe_rasterizer_state rs_state;
struct pipe_sampler_state *sampler_state;
unsigned i;
@@ -129,23 +128,24 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
ctx->blend_write_color = pipe->create_blend_state(pipe, &blend);
/* depth stencil alpha state objects */
- dsa = &ctx->template_dsa;
ctx->dsa_keep_depth_stencil =
- pipe->create_depth_stencil_alpha_state(pipe, dsa);
+ pipe->create_depth_stencil_alpha_state(pipe, &dsa);
- dsa->depth.enabled = 1;
- dsa->depth.writemask = 1;
- dsa->depth.func = PIPE_FUNC_ALWAYS;
+ dsa.depth.enabled = 1;
+ dsa.depth.writemask = 1;
+ dsa.depth.func = PIPE_FUNC_ALWAYS;
ctx->dsa_write_depth_keep_stencil =
- pipe->create_depth_stencil_alpha_state(pipe, dsa);
-
- dsa->stencil[0].enabled = 1;
- dsa->stencil[0].func = PIPE_FUNC_ALWAYS;
- dsa->stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
- dsa->stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
- dsa->stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
- dsa->stencil[0].valuemask = 0xff;
- dsa->stencil[0].writemask = 0xff;
+ pipe->create_depth_stencil_alpha_state(pipe, &dsa);
+
+ dsa.stencil[0].enabled = 1;
+ dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
+ dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
+ dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
+ dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
+ dsa.stencil[0].valuemask = 0xff;
+ dsa.stencil[0].writemask = 0xff;
+ ctx->dsa_write_depth_stencil =
+ pipe->create_depth_stencil_alpha_state(pipe, &dsa);
/* The DSA state objects which write depth and stencil are created
* on-demand. */
@@ -210,12 +210,8 @@ void util_blitter_destroy(struct blitter_context *blitter)
pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
pipe->delete_depth_stencil_alpha_state(pipe,
ctx->dsa_write_depth_keep_stencil);
-
- for (i = 0; i < 0xff; i++)
- if (ctx->dsa_write_depth_stencil[i])
- pipe->delete_depth_stencil_alpha_state(pipe,
- ctx->dsa_write_depth_stencil[i]);
-
+ pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil);
+
pipe->delete_rasterizer_state(pipe, ctx->rs_state);
pipe->delete_vs_state(pipe, ctx->vs_col);
pipe->delete_vs_state(pipe, ctx->vs_tex);
@@ -266,6 +262,8 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx)
ctx->blitter.saved_fs = INVALID_PTR;
ctx->blitter.saved_vs = INVALID_PTR;
+ pipe->set_stencil_ref(pipe, &ctx->blitter.saved_stencil_ref);
+
/* restore the state objects which are required to be saved before copy/fill
*/
if (ctx->blitter.saved_fb_state.nr_cbufs != ~0) {
@@ -413,26 +411,6 @@ static void blitter_draw_quad(struct blitter_context_priv *ctx)
}
static INLINE
-void *blitter_get_state_write_depth_stencil(
- struct blitter_context_priv *ctx,
- unsigned stencil)
-{
- struct pipe_context *pipe = ctx->pipe;
-
- stencil &= 0xff;
-
- /* Create the DSA state on-demand. */
- if (!ctx->dsa_write_depth_stencil[stencil]) {
- ctx->template_dsa.stencil[0].ref_value = stencil;
-
- ctx->dsa_write_depth_stencil[stencil] =
- pipe->create_depth_stencil_alpha_state(pipe, &ctx->template_dsa);
- }
-
- return ctx->dsa_write_depth_stencil[stencil];
-}
-
-static INLINE
void **blitter_get_sampler_state(struct blitter_context_priv *ctx,
int miplevel)
{
@@ -559,9 +537,13 @@ void util_blitter_clear(struct blitter_context *blitter,
else
pipe->bind_blend_state(pipe, ctx->blend_keep_color);
- if (clear_buffers & PIPE_CLEAR_DEPTHSTENCIL)
- pipe->bind_depth_stencil_alpha_state(pipe,
- blitter_get_state_write_depth_stencil(ctx, stencil));
+ if (clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) {
+ struct pipe_stencil_ref sr;
+ memset (&sr, 0, sizeof(sr));
+ sr.ref_value[0] = stencil & 0xff;
+ pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil);
+ pipe->set_stencil_ref(pipe, &sr);
+ }
else
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
@@ -573,6 +555,7 @@ void util_blitter_clear(struct blitter_context *blitter,
blitter_set_rectangle(ctx, 0, 0, width, height, depth);
blitter_draw_quad(ctx);
blitter_restore_CSOs(ctx);
+ /* XXX driver's responsibility to restore stencil refs? */
}
static boolean
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index 3da5a6ca52..a2f17073ac 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -47,6 +47,7 @@ struct blitter_context
void *saved_fs, *saved_vs; /**< fragment shader, vertex shader */
struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */
+ struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */
int saved_num_sampler_states;
void *saved_sampler_states[32];
@@ -170,6 +171,13 @@ void util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter,
}
static INLINE
+void util_blitter_save_stencil_ref(struct blitter_context *blitter,
+ const struct pipe_stencil_ref *state)
+{
+ blitter->saved_stencil_ref = *state;
+}
+
+static INLINE
void util_blitter_save_rasterizer(struct blitter_context *blitter,
void *state)
{