17ee590424c974cb10882e9c4664a6024595fc9deEric Anholt/* 27ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Copyright © 2009 Intel Corporation 37ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * 47ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a 57ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * copy of this software and associated documentation files (the "Software"), 67ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * to deal in the Software without restriction, including without limitation 77ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * and/or sell copies of the Software, and to permit persons to whom the 97ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Software is furnished to do so, subject to the following conditions: 107ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * 117ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * The above copyright notice and this permission notice (including the next 127ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * paragraph) shall be included in all copies or substantial portions of the 137ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Software. 147ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * 157ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * IN THE SOFTWARE. 227ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * 237ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Authors: 247ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Eric Anholt <eric@anholt.net> 257ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * 267ee590424c974cb10882e9c4664a6024595fc9deEric Anholt */ 277ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 2809e67706e9a74600e16fe012ecfd192b0d31960aEric Anholt#include "intel_fbo.h" 297ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "brw_context.h" 307ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "brw_state.h" 317ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 327ee590424c974cb10882e9c4664a6024595fc9deEric Anholtstatic void 33f84f3322b44e9828dcbee4791909025369c96f74Eric Anholtgen6_upload_depth_stencil_state(struct brw_context *brw) 347ee590424c974cb10882e9c4664a6024595fc9deEric Anholt{ 35f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &brw->intel.ctx; 36c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt struct gen6_depth_stencil_state *ds; 3709e67706e9a74600e16fe012ecfd192b0d31960aEric Anholt struct intel_renderbuffer *depth_irb; 3809e67706e9a74600e16fe012ecfd192b0d31960aEric Anholt 3909e67706e9a74600e16fe012ecfd192b0d31960aEric Anholt /* _NEW_BUFFERS */ 4009e67706e9a74600e16fe012ecfd192b0d31960aEric Anholt depth_irb = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_DEPTH); 417ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 42d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt ds = brw_state_batch(brw, AUB_TRACE_DEPTH_STENCIL_STATE, 43d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt sizeof(*ds), 64, 44c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt &brw->cc.depth_stencil_state_offset); 45c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt memset(ds, 0, sizeof(*ds)); 467ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 477ee590424c974cb10882e9c4664a6024595fc9deEric Anholt /* _NEW_STENCIL */ 48c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt if (ctx->Stencil._Enabled) { 49c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt int back = ctx->Stencil._BackFace; 50c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt 51c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.stencil_enable = 1; 52c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.stencil_func = 53c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_compare_func(ctx->Stencil.Function[0]); 54c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.stencil_fail_op = 55c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_stencil_op(ctx->Stencil.FailFunc[0]); 56c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.stencil_pass_depth_fail_op = 57c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_stencil_op(ctx->Stencil.ZFailFunc[0]); 58c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.stencil_pass_depth_pass_op = 59c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_stencil_op(ctx->Stencil.ZPassFunc[0]); 60c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds1.stencil_write_mask = ctx->Stencil.WriteMask[0]; 61c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds1.stencil_test_mask = ctx->Stencil.ValueMask[0]; 62c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt 63c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt if (ctx->Stencil._TestTwoSide) { 64c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.bf_stencil_enable = 1; 65c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.bf_stencil_func = 66c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_compare_func(ctx->Stencil.Function[back]); 67c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.bf_stencil_fail_op = 68c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_stencil_op(ctx->Stencil.FailFunc[back]); 69c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.bf_stencil_pass_depth_fail_op = 70c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_stencil_op(ctx->Stencil.ZFailFunc[back]); 71c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.bf_stencil_pass_depth_pass_op = 72c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt intel_translate_stencil_op(ctx->Stencil.ZPassFunc[back]); 73c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds1.bf_stencil_write_mask = ctx->Stencil.WriteMask[back]; 74c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds1.bf_stencil_test_mask = ctx->Stencil.ValueMask[back]; 757ee590424c974cb10882e9c4664a6024595fc9deEric Anholt } 767ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 777ee590424c974cb10882e9c4664a6024595fc9deEric Anholt /* Not really sure about this: 787ee590424c974cb10882e9c4664a6024595fc9deEric Anholt */ 79c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt if (ctx->Stencil.WriteMask[0] || 80c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[back])) 81c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds0.stencil_write_enable = 1; 827ee590424c974cb10882e9c4664a6024595fc9deEric Anholt } 837ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 847ee590424c974cb10882e9c4664a6024595fc9deEric Anholt /* _NEW_DEPTH */ 857b36c68ba6899c7f30fd56b7ef07a78b027771acChad Versace if (ctx->Depth.Test && depth_irb) { 8612498553462c7807034814cf843d86d52c407380Chad Versace ds->ds2.depth_test_enable = ctx->Depth.Test; 87c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds2.depth_test_func = intel_translate_compare_func(ctx->Depth.Func); 88c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt ds->ds2.depth_write_enable = ctx->Depth.Mask; 897ee590424c974cb10882e9c4664a6024595fc9deEric Anholt } 907ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 91c108a3f863c44b5e9760d4668148ef8ca7557b2fEric Anholt brw->state.dirty.cache |= CACHE_NEW_DEPTH_STENCIL_STATE; 927ee590424c974cb10882e9c4664a6024595fc9deEric Anholt} 937ee590424c974cb10882e9c4664a6024595fc9deEric Anholt 947ee590424c974cb10882e9c4664a6024595fc9deEric Anholtconst struct brw_tracked_state gen6_depth_stencil_state = { 957ee590424c974cb10882e9c4664a6024595fc9deEric Anholt .dirty = { 964874fcb028a8618b315b49081f9da5900ed7b69cKenneth Graunke .mesa = _NEW_DEPTH | _NEW_STENCIL | _NEW_BUFFERS, 977b36c68ba6899c7f30fd56b7ef07a78b027771acChad Versace .brw = BRW_NEW_BATCH, 987ee590424c974cb10882e9c4664a6024595fc9deEric Anholt .cache = 0, 997ee590424c974cb10882e9c4664a6024595fc9deEric Anholt }, 100f84f3322b44e9828dcbee4791909025369c96f74Eric Anholt .emit = gen6_upload_depth_stencil_state, 1017ee590424c974cb10882e9c4664a6024595fc9deEric Anholt}; 102