From bfe79babf99e6b9435195178d1ea64687c60d161 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 17 Dec 2007 16:14:29 +0000 Subject: gallium: incorporate alpha state into depth_stencil state object. --- src/mesa/state_tracker/st_atom.c | 3 +- src/mesa/state_tracker/st_atom.h | 3 +- src/mesa/state_tracker/st_atom_alphatest.c | 92 ------------------------------ src/mesa/state_tracker/st_atom_depth.c | 55 ++++++++++-------- src/mesa/state_tracker/st_cache.c | 40 ++++--------- src/mesa/state_tracker/st_cache.h | 9 +-- src/mesa/state_tracker/st_cb_clear.c | 35 +++++------- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_context.h | 2 +- 9 files changed, 62 insertions(+), 179 deletions(-) delete mode 100644 src/mesa/state_tracker/st_atom_alphatest.c (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index bde81edd8c..0e22a2fa6e 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -45,7 +45,7 @@ static const struct st_tracked_state *atoms[] = { &st_update_framebuffer, - &st_update_depth_stencil, + &st_update_depth_stencil_alpha, &st_update_clip, &st_update_shader, @@ -59,7 +59,6 @@ static const struct st_tracked_state *atoms[] = &st_update_texture, &st_update_vs_constants, &st_update_fs_constants, - &st_update_alpha_test, &st_update_pixel_transfer }; diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 0114f42ba5..3a63e2dec0 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -46,7 +46,7 @@ void st_validate_state( struct st_context *st ); const struct st_tracked_state st_update_framebuffer; const struct st_tracked_state st_update_clip; -const struct st_tracked_state st_update_depth_stencil; +const struct st_tracked_state st_update_depth_stencil_alpha; const struct st_tracked_state st_update_shader; const struct st_tracked_state st_update_rasterizer; const struct st_tracked_state st_update_polygon_stipple; @@ -57,7 +57,6 @@ 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; const struct st_tracked_state st_update_pixel_transfer; diff --git a/src/mesa/state_tracker/st_atom_alphatest.c b/src/mesa/state_tracker/st_atom_alphatest.c deleted file mode 100644 index 873520ab02..0000000000 --- a/src/mesa/state_tracker/st_atom_alphatest.c +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - /* - * Authors: - * Keith Whitwell - * Brian Paul - */ - - -#include "st_context.h" -#include "st_cache.h" -#include "st_atom.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" - - -/** - * Convert GLenum stencil func tokens to pipe tokens. - */ -static GLuint -gl_alpha_func_to_sp(GLenum func) -{ - /* Same values, just biased */ - assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER); - assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER); - assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER); - assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER); - assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER); - assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER); - assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER); - assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER); - assert(func >= GL_NEVER); - assert(func <= GL_ALWAYS); - return func - GL_NEVER; -} - - -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)); - - if (st->ctx->Color.AlphaEnabled) { - alpha.enabled = 1; - alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc); - alpha.ref = st->ctx->Color.AlphaRef; - } - cso = st_cached_alpha_test_state(st, &alpha); - if (st->state.alpha_test != cso) { - /* state has changed */ - st->state.alpha_test = cso; - st->pipe->bind_alpha_test_state(st->pipe, cso->data); /* bind new state */ - } -} - - -const struct st_tracked_state st_update_alpha_test = { - .name = "st_update_alpha_test", - .dirty = { - .mesa = (_NEW_COLOR), - .st = 0, - }, - .update = update_alpha_test -}; diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index e785434cec..7aecdbfbcc 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -91,10 +91,10 @@ gl_stencil_op_to_pipe(GLenum func) } static void -update_depth_stencil(struct st_context *st) +update_depth_stencil_alpha(struct st_context *st) { - struct pipe_depth_stencil_state depth_stencil; - const struct cso_depth_stencil *cso; + struct pipe_depth_stencil_alpha_state depth_stencil; + const struct cso_depth_stencil_alpha *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); @@ -107,40 +107,47 @@ update_depth_stencil(struct st_context *st) depth_stencil.depth.occlusion_count = 1; if (st->ctx->Stencil.Enabled) { - depth_stencil.stencil.front_enabled = 1; - depth_stencil.stencil.front_func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); - depth_stencil.stencil.front_fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); - depth_stencil.stencil.front_zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); - depth_stencil.stencil.front_zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); - depth_stencil.stencil.ref_value[0] = st->ctx->Stencil.Ref[0] & 0xff; - depth_stencil.stencil.value_mask[0] = st->ctx->Stencil.ValueMask[0] & 0xff; - depth_stencil.stencil.write_mask[0] = st->ctx->Stencil.WriteMask[0] & 0xff; + depth_stencil.stencil[0].enabled = 1; + depth_stencil.stencil[0].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); + depth_stencil.stencil[0].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); + depth_stencil.stencil[0].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[0]); + depth_stencil.stencil[0].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[0]); + depth_stencil.stencil[0].ref_value = st->ctx->Stencil.Ref[0] & 0xff; + depth_stencil.stencil[0].value_mask = st->ctx->Stencil.ValueMask[0] & 0xff; + depth_stencil.stencil[0].write_mask = st->ctx->Stencil.WriteMask[0] & 0xff; + if (st->ctx->Stencil.TestTwoSide) { - depth_stencil.stencil.back_enabled = 1; - depth_stencil.stencil.back_func = st_compare_func_to_pipe(st->ctx->Stencil.Function[1]); - depth_stencil.stencil.back_fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[1]); - depth_stencil.stencil.back_zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); - depth_stencil.stencil.back_zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); - depth_stencil.stencil.ref_value[1] = st->ctx->Stencil.Ref[1] & 0xff; - depth_stencil.stencil.value_mask[1] = st->ctx->Stencil.ValueMask[1] & 0xff; - depth_stencil.stencil.write_mask[1] = st->ctx->Stencil.WriteMask[1] & 0xff; + depth_stencil.stencil[1].enabled = 1; + depth_stencil.stencil[1].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[1]); + depth_stencil.stencil[1].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[1]); + depth_stencil.stencil[1].zfail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZFailFunc[1]); + depth_stencil.stencil[1].zpass_op = gl_stencil_op_to_pipe(st->ctx->Stencil.ZPassFunc[1]); + depth_stencil.stencil[1].ref_value = st->ctx->Stencil.Ref[1] & 0xff; + depth_stencil.stencil[1].value_mask = st->ctx->Stencil.ValueMask[1] & 0xff; + depth_stencil.stencil[1].write_mask = st->ctx->Stencil.WriteMask[1] & 0xff; } } - cso = st_cached_depth_stencil_state(st, &depth_stencil); + if (st->ctx->Color.AlphaEnabled) { + depth_stencil.alpha.enabled = 1; + depth_stencil.alpha.func = st_compare_func_to_pipe(st->ctx->Color.AlphaFunc); + depth_stencil.alpha.ref = st->ctx->Color.AlphaRef; + } + + cso = st_cached_depth_stencil_alpha_state(st, &depth_stencil); if (st->state.depth_stencil != cso) { /* state has changed */ st->state.depth_stencil = cso; - st->pipe->bind_depth_stencil_state(st->pipe, cso->data); /* bind new state */ + st->pipe->bind_depth_stencil_alpha_state(st->pipe, cso->data); /* bind new state */ } } -const struct st_tracked_state st_update_depth_stencil = { +const struct st_tracked_state st_update_depth_stencil_alpha = { .name = "st_update_depth_stencil", .dirty = { - .mesa = (_NEW_DEPTH|_NEW_STENCIL), + .mesa = (_NEW_DEPTH|_NEW_STENCIL|_NEW_COLOR), .st = 0, }, - .update = update_depth_stencil + .update = update_depth_stencil_alpha }; diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index c0f712ba1d..e0965b217a 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -87,24 +87,25 @@ st_cached_sampler_state(struct st_context *st, return (struct cso_sampler*)(cso_hash_iter_data(iter)); } -const struct cso_depth_stencil * -st_cached_depth_stencil_state(struct st_context *st, - const struct pipe_depth_stencil_state *templ) +const struct cso_depth_stencil_alpha * +st_cached_depth_stencil_alpha_state(struct st_context *st, + const struct pipe_depth_stencil_alpha_state *templ) { unsigned hash_key = cso_construct_key((void*)templ, - sizeof(struct pipe_depth_stencil_state)); + sizeof(struct pipe_depth_stencil_alpha_state)); struct cso_hash_iter iter = cso_find_state_template(st->cache, - hash_key, CSO_DEPTH_STENCIL, + hash_key, + CSO_DEPTH_STENCIL_ALPHA, (void*)templ); if (cso_hash_iter_is_null(iter)) { - struct cso_depth_stencil *cso = malloc(sizeof(struct cso_depth_stencil)); - memcpy(&cso->state, templ, sizeof(struct pipe_depth_stencil_state)); - cso->data = st->pipe->create_depth_stencil_state(st->pipe, &cso->state); + struct cso_depth_stencil_alpha *cso = malloc(sizeof(struct cso_depth_stencil_alpha)); + memcpy(&cso->state, templ, sizeof(struct pipe_depth_stencil_alpha_state)); + cso->data = st->pipe->create_depth_stencil_alpha_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL, cso); + iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso); } - return (struct cso_depth_stencil*)(cso_hash_iter_data(iter)); + return (struct cso_depth_stencil_alpha*)(cso_hash_iter_data(iter)); } const struct cso_rasterizer* st_cached_rasterizer_state( @@ -167,22 +168,3 @@ 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)); -} diff --git a/src/mesa/state_tracker/st_cache.h b/src/mesa/state_tracker/st_cache.h index 422f668c56..e0c176b0ff 100644 --- a/src/mesa/state_tracker/st_cache.h +++ b/src/mesa/state_tracker/st_cache.h @@ -39,9 +39,6 @@ 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, @@ -51,9 +48,9 @@ const struct cso_sampler * st_cached_sampler_state(struct st_context *st, const struct pipe_sampler_state *sampler); -const struct cso_depth_stencil * -st_cached_depth_stencil_state(struct st_context *st, - const struct pipe_depth_stencil_state *depth_stencil); +const struct cso_depth_stencil_alpha * +st_cached_depth_stencil_alpha_state(struct st_context *st, + const struct pipe_depth_stencil_alpha_state *depth_stencil); const struct cso_rasterizer * st_cached_rasterizer_state(struct st_context *st, diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index b4b2429a2a..40319f4b4b 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -272,14 +272,6 @@ clear_with_quad(GLcontext *ctx, const GLfloat x1 = ctx->DrawBuffer->_Xmax; const GLfloat y1 = ctx->DrawBuffer->_Ymax; - /* alpha state: disabled */ - { - struct pipe_alpha_test_state alpha_test; - const struct cso_alpha_test *cso; - memset(&alpha_test, 0, sizeof(alpha_test)); - cso = st_cached_alpha_test_state(st, &alpha_test); - pipe->bind_alpha_test_state(pipe, cso->data); - } /* blend state: RGBA masking */ { @@ -304,8 +296,8 @@ clear_with_quad(GLcontext *ctx, /* depth_stencil state: always pass/set to ref value */ { - struct pipe_depth_stencil_state depth_stencil; - const struct cso_depth_stencil *cso; + struct pipe_depth_stencil_alpha_state depth_stencil; + const struct cso_depth_stencil_alpha *cso; memset(&depth_stencil, 0, sizeof(depth_stencil)); if (depth) { depth_stencil.depth.enabled = 1; @@ -314,17 +306,17 @@ clear_with_quad(GLcontext *ctx, } if (stencil) { - depth_stencil.stencil.front_enabled = 1; - depth_stencil.stencil.front_func = PIPE_FUNC_ALWAYS; - depth_stencil.stencil.front_fail_op = PIPE_STENCIL_OP_REPLACE; - depth_stencil.stencil.front_zpass_op = PIPE_STENCIL_OP_REPLACE; - depth_stencil.stencil.front_zfail_op = PIPE_STENCIL_OP_REPLACE; - depth_stencil.stencil.ref_value[0] = ctx->Stencil.Clear; - depth_stencil.stencil.value_mask[0] = 0xff; - depth_stencil.stencil.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff; + depth_stencil.stencil[0].enabled = 1; + depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS; + depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; + depth_stencil.stencil[0].ref_value = ctx->Stencil.Clear; + depth_stencil.stencil[0].value_mask = 0xff; + depth_stencil.stencil[0].write_mask = ctx->Stencil.WriteMask[0] & 0xff; } - cso = st_cached_depth_stencil_state(st, &depth_stencil); - pipe->bind_depth_stencil_state(pipe, cso->data); + cso = st_cached_depth_stencil_alpha_state(st, &depth_stencil); + pipe->bind_depth_stencil_alpha_state(pipe, cso->data); } /* rasterizer state: nothing */ @@ -381,9 +373,8 @@ clear_with_quad(GLcontext *ctx, draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore pipe state */ - 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_depth_stencil_alpha_state(pipe, st->state.depth_stencil->data); pipe->bind_fs_state(pipe, st->state.fs->data); pipe->bind_vs_state(pipe, st->state.vs->data); pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0bc48b7039..e70a5b49e1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -789,7 +789,7 @@ compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat) static GLboolean any_fragment_ops(const struct st_context *st) { - if (st->state.alpha_test->state.enabled || + if (st->state.depth_stencil->state.alpha.enabled || st->state.blend->state.blend_enable || st->state.blend->state.logicop_enable || st->state.depth_stencil->state.depth.enabled) diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 87646b3c71..c3919d474c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -97,7 +97,7 @@ struct st_context 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_depth_stencil_alpha *depth_stencil; const struct cso_rasterizer *rasterizer; const struct cso_fragment_shader *fs; const struct cso_vertex_shader *vs; -- cgit v1.2.3