From: Zack Rusin Date: Thu, 20 Sep 2007 14:28:20 +0000 (-0400) Subject: Rewrite the depth_stencil state handling in i915. X-Git-Tag: 062012170305~17580^2~390^2~4076 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d8c31b47bd34a43e1f78a9f21a0c02c57c58479;p=profile%2Fivi%2Fmesa.git Rewrite the depth_stencil state handling in i915. Done to match the new cso semantics. translate in create, use in bind and later delete. --- diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index ea6d1ce..1a7df65 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -120,6 +120,13 @@ struct i915_blend_state { unsigned LIS6; }; +struct i915_depth_stencil_state { + unsigned stencil_modes4; + unsigned bfo[2]; + unsigned stencil_LIS5; + unsigned depth_LIS6; +}; + struct i915_context { struct pipe_context pipe; @@ -128,9 +135,9 @@ struct i915_context /* The most recent drawing state as set by the driver: */ - const struct i915_blend_state *blend; + const struct i915_blend_state *blend; const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - const struct pipe_depth_stencil_state *depth_stencil; + const struct i915_depth_stencil_state *depth_stencil; const struct pipe_rasterizer_state *rasterizer; const struct pipe_shader_state *fs; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 0fb41e1..9611288 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -174,7 +174,84 @@ static void * i915_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_state *depth_stencil) { - return 0; + struct i915_depth_stencil_state *cso = calloc(1, sizeof(struct i915_depth_stencil_state)); + + { + int testmask = depth_stencil->stencil.value_mask[0] & 0xff; + int writemask = depth_stencil->stencil.write_mask[0] & 0xff; + + cso->stencil_modes4 |= (_3DSTATE_MODES_4_CMD | + ENABLE_STENCIL_TEST_MASK | + STENCIL_TEST_MASK(testmask) | + ENABLE_STENCIL_WRITE_MASK | + STENCIL_WRITE_MASK(writemask)); + } + + if (depth_stencil->stencil.front_enabled) { + int test = i915_translate_compare_func(depth_stencil->stencil.front_func); + int fop = i915_translate_stencil_op(depth_stencil->stencil.front_fail_op); + int dfop = i915_translate_stencil_op(depth_stencil->stencil.front_zfail_op); + int dpop = i915_translate_stencil_op(depth_stencil->stencil.front_zpass_op); + int ref = depth_stencil->stencil.ref_value[0] & 0xff; + + cso->stencil_LIS5 |= (S5_STENCIL_TEST_ENABLE | + S5_STENCIL_WRITE_ENABLE | + (ref << S5_STENCIL_REF_SHIFT) | + (test << S5_STENCIL_TEST_FUNC_SHIFT) | + (fop << S5_STENCIL_FAIL_SHIFT) | + (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) | + (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT)); + } + + if (depth_stencil->stencil.back_enabled) { + int test = i915_translate_compare_func(depth_stencil->stencil.back_func); + int fop = i915_translate_stencil_op(depth_stencil->stencil.back_fail_op); + int dfop = i915_translate_stencil_op(depth_stencil->stencil.back_zfail_op); + int dpop = i915_translate_stencil_op(depth_stencil->stencil.back_zpass_op); + int ref = depth_stencil->stencil.ref_value[1] & 0xff; + int tmask = depth_stencil->stencil.value_mask[1] & 0xff; + int wmask = depth_stencil->stencil.write_mask[1] & 0xff; + + cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | + BFO_ENABLE_STENCIL_FUNCS | + BFO_ENABLE_STENCIL_TWO_SIDE | + BFO_ENABLE_STENCIL_REF | + BFO_STENCIL_TWO_SIDE | + (ref << BFO_STENCIL_REF_SHIFT) | + (test << BFO_STENCIL_TEST_SHIFT) | + (fop << BFO_STENCIL_FAIL_SHIFT) | + (dfop << BFO_STENCIL_PASS_Z_FAIL_SHIFT) | + (dpop << BFO_STENCIL_PASS_Z_PASS_SHIFT)); + + cso->bfo[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS | + BFM_ENABLE_STENCIL_TEST_MASK | + BFM_ENABLE_STENCIL_WRITE_MASK | + (tmask << BFM_STENCIL_TEST_MASK_SHIFT) | + (wmask << BFM_STENCIL_WRITE_MASK_SHIFT)); + } + else { + /* This actually disables two-side stencil: The bit set is a + * modify-enable bit to indicate we are changing the two-side + * setting. Then there is a symbolic zero to show that we are + * setting the flag to zero/off. + */ + cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | + BFO_ENABLE_STENCIL_TWO_SIDE | + 0); + cso->bfo[1] = 0; + } + + if (depth_stencil->depth.enabled) { + int func = i915_translate_compare_func(depth_stencil->depth.func); + + cso->depth_LIS6 |= (S6_DEPTH_TEST_ENABLE | + (func << S6_DEPTH_TEST_FUNC_SHIFT)); + + if (depth_stencil->depth.writemask) + cso->depth_LIS6 |= S6_DEPTH_WRITE_ENABLE; + } + + return cso; } static void i915_bind_depth_stencil_state(struct pipe_context *pipe, @@ -182,7 +259,7 @@ static void i915_bind_depth_stencil_state(struct pipe_context *pipe, { struct i915_context *i915 = i915_context(pipe); - i915->depth_stencil = (const struct pipe_depth_stencil_state *)depth_stencil; + i915->depth_stencil = (const struct i915_depth_stencil_state *)depth_stencil; i915->dirty |= I915_NEW_DEPTH_STENCIL; } @@ -190,7 +267,7 @@ static void i915_bind_depth_stencil_state(struct pipe_context *pipe, static void i915_delete_depth_stencil_state(struct pipe_context *pipe, void *depth_stencil) { - /* do nothing */ + free(depth_stencil); } static void i915_set_alpha_test_state(struct pipe_context *pipe, diff --git a/src/mesa/pipe/i915simple/i915_state_dynamic.c b/src/mesa/pipe/i915simple/i915_state_dynamic.c index 262ac94..d97aeb8 100644 --- a/src/mesa/pipe/i915simple/i915_state_dynamic.c +++ b/src/mesa/pipe/i915simple/i915_state_dynamic.c @@ -67,17 +67,7 @@ static void upload_MODES4( struct i915_context *i915 ) unsigned modes4 = 0; /* I915_NEW_STENCIL */ - { - int testmask = i915->depth_stencil->stencil.value_mask[0] & 0xff; - int writemask = i915->depth_stencil->stencil.write_mask[0] & 0xff; - - modes4 |= (_3DSTATE_MODES_4_CMD | - ENABLE_STENCIL_TEST_MASK | - STENCIL_TEST_MASK(testmask) | - ENABLE_STENCIL_WRITE_MASK | - STENCIL_WRITE_MASK(writemask)); - } - + modes4 |= i915->depth_stencil->stencil_modes4; /* I915_NEW_BLEND */ modes4 |= i915->blend->modes4; @@ -102,53 +92,9 @@ const struct i915_tracked_state i915_upload_MODES4 = { static void upload_BFO( struct i915_context *i915 ) { - unsigned bf[2]; - - memset( bf, 0, sizeof(bf) ); - - /* _NEW_STENCIL - */ - if (i915->depth_stencil->stencil.back_enabled) { - int test = i915_translate_compare_func(i915->depth_stencil->stencil.back_func); - int fop = i915_translate_stencil_op(i915->depth_stencil->stencil.back_fail_op); - int dfop = i915_translate_stencil_op(i915->depth_stencil->stencil.back_zfail_op); - int dpop = i915_translate_stencil_op(i915->depth_stencil->stencil.back_zpass_op); - int ref = i915->depth_stencil->stencil.ref_value[1] & 0xff; - int tmask = i915->depth_stencil->stencil.value_mask[1] & 0xff; - int wmask = i915->depth_stencil->stencil.write_mask[1] & 0xff; - - bf[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | - BFO_ENABLE_STENCIL_FUNCS | - BFO_ENABLE_STENCIL_TWO_SIDE | - BFO_ENABLE_STENCIL_REF | - BFO_STENCIL_TWO_SIDE | - (ref << BFO_STENCIL_REF_SHIFT) | - (test << BFO_STENCIL_TEST_SHIFT) | - (fop << BFO_STENCIL_FAIL_SHIFT) | - (dfop << BFO_STENCIL_PASS_Z_FAIL_SHIFT) | - (dpop << BFO_STENCIL_PASS_Z_PASS_SHIFT)); - - bf[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS | - BFM_ENABLE_STENCIL_TEST_MASK | - BFM_ENABLE_STENCIL_WRITE_MASK | - (tmask << BFM_STENCIL_TEST_MASK_SHIFT) | - (wmask << BFM_STENCIL_WRITE_MASK_SHIFT)); - } - else { - /* This actually disables two-side stencil: The bit set is a - * modify-enable bit to indicate we are changing the two-side - * setting. Then there is a symbolic zero to show that we are - * setting the flag to zero/off. - */ - bf[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | - BFO_ENABLE_STENCIL_TWO_SIDE | - 0); - bf[1] = 0; - } - - set_dynamic_indirect( i915, + set_dynamic_indirect( i915, I915_DYNAMIC_BFO_0, - &bf[0], + &(i915->depth_stencil->bfo[0]), 2 ); } diff --git a/src/mesa/pipe/i915simple/i915_state_immediate.c b/src/mesa/pipe/i915simple/i915_state_immediate.c index 38cf2ad..7de7f53 100644 --- a/src/mesa/pipe/i915simple/i915_state_immediate.c +++ b/src/mesa/pipe/i915simple/i915_state_immediate.c @@ -127,22 +127,7 @@ static void upload_S5( struct i915_context *i915 ) { unsigned LIS5 = 0; - /* I915_NEW_STENCIL */ - if (i915->depth_stencil->stencil.front_enabled) { - int test = i915_translate_compare_func(i915->depth_stencil->stencil.front_func); - int fop = i915_translate_stencil_op(i915->depth_stencil->stencil.front_fail_op); - int dfop = i915_translate_stencil_op(i915->depth_stencil->stencil.front_zfail_op); - int dpop = i915_translate_stencil_op(i915->depth_stencil->stencil.front_zpass_op); - int ref = i915->depth_stencil->stencil.ref_value[0] & 0xff; - - LIS5 |= (S5_STENCIL_TEST_ENABLE | - S5_STENCIL_WRITE_ENABLE | - (ref << S5_STENCIL_REF_SHIFT) | - (test << S5_STENCIL_TEST_FUNC_SHIFT) | - (fop << S5_STENCIL_FAIL_SHIFT) | - (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) | - (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT)); - } + LIS5 |= i915->depth_stencil->stencil_LIS5; LIS5 |= i915->blend->LIS5; @@ -189,17 +174,9 @@ static void upload_S6( struct i915_context *i915 ) */ LIS6 |= i915->blend->LIS6; - /* I915_NEW_DEPTH + /* I915_NEW_DEPTH */ - if (i915->depth_stencil->depth.enabled) { - int func = i915_translate_compare_func(i915->depth_stencil->depth.func); - - LIS6 |= (S6_DEPTH_TEST_ENABLE | - (func << S6_DEPTH_TEST_FUNC_SHIFT)); - - if (i915->depth_stencil->depth.writemask) - LIS6 |= S6_DEPTH_WRITE_ENABLE; - } + LIS6 |= i915->depth_stencil->depth_LIS6; if (LIS6 != i915->current.immediate[I915_IMMEDIATE_S6]) { i915->current.immediate[I915_IMMEDIATE_S6] = LIS6;