brw_clear.c revision 877128505431adaf817dc8069172ebe4a1cdf5d8
14451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul/************************************************************************** 211892ea986b5fdad345ce7c09f97e0389e546509Eric Anholt * 3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2003 VMware, Inc. 43e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt * Copyright 2009, 2012 Intel Corporation. 54451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * All Rights Reserved. 611892ea986b5fdad345ce7c09f97e0389e546509Eric Anholt * 74451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a 84451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * copy of this software and associated documentation files (the 94451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * "Software"), to deal in the Software without restriction, including 104451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * without limitation the rights to use, copy, modify, merge, publish, 114451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * distribute, sub license, and/or sell copies of the Software, and to 124451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * permit persons to whom the Software is furnished to do so, subject to 134451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * the following conditions: 1411892ea986b5fdad345ce7c09f97e0389e546509Eric Anholt * 154451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * The above copyright notice and this permission notice (including the 164451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * next paragraph) shall be included in all copies or substantial portions 174451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * of the Software. 1811892ea986b5fdad345ce7c09f97e0389e546509Eric Anholt * 194451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 204451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 214451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 234451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 244451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 254451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2611892ea986b5fdad345ce7c09f97e0389e546509Eric Anholt * 274451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul **************************************************************************/ 284451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 29c96bac0950eda6e707455b0c1ee29c1d87daf727Eric Anholt#include "main/glheader.h" 30c96bac0950eda6e707455b0c1ee29c1d87daf727Eric Anholt#include "main/mtypes.h" 311df72402d99145425531297eef6772b88ce5225dEric Anholt#include "main/condrender.h" 32c96bac0950eda6e707455b0c1ee29c1d87daf727Eric Anholt#include "swrast/swrast.h" 3350d8b295f6c950da3b8783ff6e1803bdfbb5c7ccBrian Paul#include "drivers/common/meta.h" 34c96bac0950eda6e707455b0c1ee29c1d87daf727Eric Anholt 3568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt#include "intel_batchbuffer.h" 364451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul#include "intel_blit.h" 374451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul#include "intel_fbo.h" 3868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt#include "intel_mipmap_tree.h" 3913624848401679f7ee904aa731d520792a5e523eEric Anholt#include "intel_regions.h" 404451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 41c5d5827951fb321a58cc781b4e386551035ebf1aPaul Berry#include "brw_context.h" 42e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt#include "brw_blorp.h" 43c5d5827951fb321a58cc781b4e386551035ebf1aPaul Berry 444451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul#define FILE_DEBUG_FLAG DEBUG_BLIT 454451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 464451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paulstatic const char *buffer_names[] = { 474451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_FRONT_LEFT] = "front", 484451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_BACK_LEFT] = "back", 494451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_FRONT_RIGHT] = "front right", 504451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_BACK_RIGHT] = "back right", 514451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_DEPTH] = "depth", 524451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_STENCIL] = "stencil", 534451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_ACCUM] = "accum", 54555f0a88182e2b1af809b2d97abdac02814a2f28Brian Paul [BUFFER_AUX0] = "aux0", 554451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR0] = "color0", 564451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR1] = "color1", 574451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR2] = "color2", 584451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR3] = "color3", 594451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR4] = "color4", 604451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR5] = "color5", 614451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR6] = "color6", 624451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul [BUFFER_COLOR7] = "color7", 634451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul}; 644451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 65bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholtstatic void 66bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholtdebug_mask(const char *name, GLbitfield mask) 67bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt{ 68bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt GLuint i; 69bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt 70bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt if (unlikely(INTEL_DEBUG & DEBUG_BLIT)) { 71bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt DBG("%s clear:", name); 72bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt for (i = 0; i < BUFFER_COUNT; i++) { 73bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt if (mask & (1 << i)) 74bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt DBG(" %s", buffer_names[i]); 75bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt } 76bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt DBG("\n"); 77bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt } 78bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt} 79bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt 804451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul/** 81097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke * Returns true if the scissor is a noop (cuts out nothing). 82097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke */ 83097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunkestatic bool 84097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunkenoop_scissor(struct gl_context *ctx, struct gl_framebuffer *fb) 85097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke{ 86097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke return ctx->Scissor.X <= 0 && 87097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke ctx->Scissor.Y <= 0 && 88097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke ctx->Scissor.Width >= fb->Width && 89097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke ctx->Scissor.Height >= fb->Height; 90097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke} 91097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke 92097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke/** 9368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * Implements fast depth clears on gen6+. 9468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 9568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * Fast clears basically work by setting a flag in each of the subspans 9668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * represented in the HiZ buffer that says "When you need the depth values for 9768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * this subspan, it's the hardware's current clear value." Then later rendering 9868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * can just use the static clear value instead of referencing memory. 9968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 10068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * The tricky part of the implementation is that you have to have the clear 10168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * value that was used on the depth buffer in place for all further rendering, 10268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * at least until a resolve to the real depth buffer happens. 10368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 10468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholtstatic bool 10568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholtbrw_fast_clear_depth(struct gl_context *ctx) 10668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt{ 107ca437579b3974b91a5298707c459908a628c1098Kenneth Graunke struct brw_context *brw = brw_context(ctx); 10868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt struct gl_framebuffer *fb = ctx->DrawBuffer; 10968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt struct intel_renderbuffer *depth_irb = 11068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt intel_get_renderbuffer(fb, BUFFER_DEPTH); 11168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt struct intel_mipmap_tree *mt = depth_irb->mt; 1127b36137642f8946bbc85b45124fefda38ca5332eJordan Justen struct gl_renderbuffer_attachment *depth_att = &fb->Attachment[BUFFER_DEPTH]; 11368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 11436c3faf4bf41d6618a3b0fcd565f4907a1633a40Kenneth Graunke if (brw->gen < 6 || brw->gen >= 8) 11568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt return false; 11668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 1172d3bbc576c095f0942d131db886f5661dec5680cChad Versace if (!intel_renderbuffer_has_hiz(depth_irb)) 11868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt return false; 11968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 12068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* We only handle full buffer clears -- otherwise you'd have to track whether 12168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * a previous clear had happened at a different clear value and resolve it 12268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * first. 12368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 124097b4a3b28ecab81b356b86f04a939d24b94ae77Kenneth Graunke if (ctx->Scissor.Enabled && !noop_scissor(ctx, fb)) { 125b4da272a6ea58a7c81c71477d65d82651555709aEric Anholt perf_debug("Failed to fast clear depth due to scissor being enabled. " 126b4da272a6ea58a7c81c71477d65d82651555709aEric Anholt "Possible 5%% performance win if avoided.\n"); 12768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt return false; 128b4da272a6ea58a7c81c71477d65d82651555709aEric Anholt } 12968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 13068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt uint32_t depth_clear_value; 13168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt switch (mt->format) { 13268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt case MESA_FORMAT_Z32_FLOAT_X24S8: 13368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt case MESA_FORMAT_S8_Z24: 13468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* From the Sandy Bridge PRM, volume 2 part 1, page 314: 13568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 13668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * "[DevSNB+]: Several cases exist where Depth Buffer Clear cannot be 13768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * enabled (the legacy method of clearing must be performed): 13868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 13968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * - If the depth buffer format is D32_FLOAT_S8X24_UINT or 14068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * D24_UNORM_S8_UINT. 14168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 14268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt return false; 14368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 14468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt case MESA_FORMAT_Z32_FLOAT: 14568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt depth_clear_value = float_as_int(ctx->Depth.Clear); 14668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt break; 14768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 14868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt case MESA_FORMAT_Z16: 14968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* From the Sandy Bridge PRM, volume 2 part 1, page 314: 15068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 15168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * "[DevSNB+]: Several cases exist where Depth Buffer Clear cannot be 15268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * enabled (the legacy method of clearing must be performed): 15368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 15468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * - DevSNB{W/A}]: When depth buffer format is D16_UNORM and the 15568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * width of the map (LOD0) is not multiple of 16, fast clear 15668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * optimization must be disabled. 15768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 15853631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke if (brw->gen == 6 && (mt->level[depth_irb->mt_level].width % 16) != 0) 15968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt return false; 16068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* FALLTHROUGH */ 16168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 16268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt default: 16368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt depth_clear_value = fb->_DepthMax * ctx->Depth.Clear; 16468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt break; 16568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt } 16668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 16768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* If we're clearing to a new clear value, then we need to resolve any clear 16868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * flags out of the HiZ buffer into the real depth buffer. 16968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 17068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt if (mt->depth_clear_value != depth_clear_value) { 171ca437579b3974b91a5298707c459908a628c1098Kenneth Graunke intel_miptree_all_slices_resolve_depth(brw, mt); 17268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt mt->depth_clear_value = depth_clear_value; 17368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt } 17468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 17568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* From the Sandy Bridge PRM, volume 2 part 1, page 313: 17668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 17768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * "If other rendering operations have preceded this clear, a 17868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * PIPE_CONTROL with write cache flush enabled and Z-inhibit disabled 17968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * must be issued before the rectangle primitive used for the depth 18068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * buffer clear operation. 18168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 182ca437579b3974b91a5298707c459908a628c1098Kenneth Graunke intel_batchbuffer_emit_mi_flush(brw); 18368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 184532b1fecd93fd30d3b1b101b55fd2c6e074088adPaul Berry if (fb->MaxNumLayers > 0) { 185532b1fecd93fd30d3b1b101b55fd2c6e074088adPaul Berry unsigned num_layers = depth_irb->mt->level[depth_irb->mt_level].depth; 186532b1fecd93fd30d3b1b101b55fd2c6e074088adPaul Berry for (unsigned layer = 0; layer < num_layers; layer++) { 18708315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry intel_hiz_exec(brw, mt, depth_irb->mt_level, layer, 18808315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry GEN6_HIZ_OP_DEPTH_CLEAR); 18908315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry } 19008315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry } else { 19108315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry intel_hiz_exec(brw, mt, depth_irb->mt_level, depth_irb->mt_layer, 19208315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry GEN6_HIZ_OP_DEPTH_CLEAR); 19308315233509f1fa7dc1e877aed2a8517296cf86ePaul Berry } 19468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 19553631be4ebaa4fb13a7f129727c1cdd32fcc6f3dKenneth Graunke if (brw->gen == 6) { 19668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt /* From the Sandy Bridge PRM, volume 2 part 1, page 314: 19768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * 19868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * "DevSNB, DevSNB-B{W/A}]: Depth buffer clear pass must be followed 19968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * by a PIPE_CONTROL command with DEPTH_STALL bit set and Then 20068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt * followed by Depth FLUSH' 20168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 202ca437579b3974b91a5298707c459908a628c1098Kenneth Graunke intel_batchbuffer_emit_mi_flush(brw); 20368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt } 20468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 2055133bd6585552a5708b294180fa9a561bf7564a6Paul Berry /* Now, the HiZ buffer contains data that needs to be resolved to the depth 2065133bd6585552a5708b294180fa9a561bf7564a6Paul Berry * buffer. 20768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt */ 2087b36137642f8946bbc85b45124fefda38ca5332eJordan Justen intel_renderbuffer_att_set_needs_depth_resolve(depth_att); 20968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 21068216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt return true; 21168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt} 21268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 21368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt/** 2144451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul * Called by ctx->Driver.Clear. 2154451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul */ 2164451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paulstatic void 2177da9795070b1af746ab85692d4b65dbe8c4f2d76Eric Anholtbrw_clear(struct gl_context *ctx, GLbitfield mask) 2184451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul{ 219c5d5827951fb321a58cc781b4e386551035ebf1aPaul Berry struct brw_context *brw = brw_context(ctx); 2200af56c9d53a454477645f4537b8086120a638d3ePaul Berry struct gl_framebuffer *fb = ctx->DrawBuffer; 2210af56c9d53a454477645f4537b8086120a638d3ePaul Berry bool partial_clear = ctx->Scissor.Enabled && !noop_scissor(ctx, fb); 2224451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 2231df72402d99145425531297eef6772b88ce5225dEric Anholt if (!_mesa_check_conditional_render(ctx)) 2241df72402d99145425531297eef6772b88ce5225dEric Anholt return; 2251df72402d99145425531297eef6772b88ce5225dEric Anholt 2263105f3aa88e4b59eed3c7f175af77fbdb4af5924Brian Paul if (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_FRONT_RIGHT)) { 2279147b4049658fe2401c19e03d20220aeea0fafc6Kenneth Graunke brw->front_buffer_dirty = true; 2283105f3aa88e4b59eed3c7f175af77fbdb4af5924Brian Paul } 22938d3c156dc64679e5602816070a0bac4f1f39302Brian Paul 230ca437579b3974b91a5298707c459908a628c1098Kenneth Graunke intel_prepare_render(brw); 2310af56c9d53a454477645f4537b8086120a638d3ePaul Berry brw_workaround_depthstencil_alignment(brw, partial_clear ? 0 : mask); 23268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 23368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt if (mask & BUFFER_BIT_DEPTH) { 23468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt if (brw_fast_clear_depth(ctx)) { 23568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt DBG("fast clear: depth\n"); 23668216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt mask &= ~BUFFER_BIT_DEPTH; 23768216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt } 23868216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt } 23968216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt 240e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt /* BLORP is currently only supported on Gen6+. */ 24136c3faf4bf41d6618a3b0fcd565f4907a1633a40Kenneth Graunke if (brw->gen >= 6 && brw->gen < 8) { 242e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt if (mask & BUFFER_BITS_COLOR) { 243ca437579b3974b91a5298707c459908a628c1098Kenneth Graunke if (brw_blorp_clear_color(brw, fb, partial_clear)) { 244e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt debug_mask("blorp color", mask & BUFFER_BITS_COLOR); 245e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt mask &= ~BUFFER_BITS_COLOR; 246e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt } 247e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt } 248e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt } 249e56095dc2e40d6d1e37e123c694a609d16932b4aEric Anholt 2503e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt GLbitfield tri_mask = mask & (BUFFER_BITS_COLOR | 2513e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt BUFFER_BIT_STENCIL | 2523e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt BUFFER_BIT_DEPTH); 2534451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 2544451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul if (tri_mask) { 255bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt debug_mask("tri", tri_mask); 2563e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt mask &= ~tri_mask; 25794f22fbe787214580a1a13a774114d2650c166cbTapani Pälli 25894f22fbe787214580a1a13a774114d2650c166cbTapani Pälli if (ctx->API == API_OPENGLES) { 2598c9a54e7bcfc80295ad77097910d35958dfd3644Kenneth Graunke _mesa_meta_Clear(&brw->ctx, tri_mask); 26094f22fbe787214580a1a13a774114d2650c166cbTapani Pälli } else { 2618c9a54e7bcfc80295ad77097910d35958dfd3644Kenneth Graunke _mesa_meta_glsl_Clear(&brw->ctx, tri_mask); 26294f22fbe787214580a1a13a774114d2650c166cbTapani Pälli } 2634451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul } 2643e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt 2653e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt /* Any strange buffers get passed off to swrast */ 2663e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt if (mask) { 2673e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt debug_mask("swrast", mask); 2683e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt _swrast_Clear(ctx, mask); 2693e1656567c3d2abb91f8169806d6083e80c0a673Eric Anholt } 2704451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul} 2714451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 2724451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul 2734451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paulvoid 2744451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian PaulintelInitClearFuncs(struct dd_function_table *functions) 2754451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul{ 2767da9795070b1af746ab85692d4b65dbe8c4f2d76Eric Anholt functions->Clear = brw_clear; 2774451eb2e7533a41f67ed21d05a8d9ab5efec77e9Brian Paul} 278