14a49301eSmrg/**************************************************************************
24a49301eSmrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg * Copyright 2009 VMware, Inc.  All Rights Reserved.
64a49301eSmrg *
74a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
84a49301eSmrg * copy of this software and associated documentation files (the
94a49301eSmrg * "Software"), to deal in the Software without restriction, including
104a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
114a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
124a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
134a49301eSmrg * the following conditions:
144a49301eSmrg *
154a49301eSmrg * The above copyright notice and this permission notice (including the
164a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
174a49301eSmrg * of the Software.
184a49301eSmrg *
194a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
204a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
214a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
234a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
244a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
254a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
264a49301eSmrg *
274a49301eSmrg **************************************************************************/
284a49301eSmrg
294a49301eSmrg/* Author:
304a49301eSmrg *    Brian Paul
314a49301eSmrg *    Michel Dänzer
324a49301eSmrg */
334a49301eSmrg
344a49301eSmrg
354a49301eSmrg#include "pipe/p_defines.h"
364a49301eSmrg#include "util/u_pack_color.h"
37af69d88dSmrg#include "util/u_surface.h"
384a49301eSmrg#include "sp_clear.h"
394a49301eSmrg#include "sp_context.h"
407ec681f3Smrg#include "sp_screen.h"
41cdc920a0Smrg#include "sp_query.h"
424a49301eSmrg#include "sp_tile_cache.h"
434a49301eSmrg
444a49301eSmrg
454a49301eSmrg/**
464a49301eSmrg * Clear the given buffers to the specified values.
474a49301eSmrg * No masking, no scissor (clear entire buffer).
484a49301eSmrg */
494a49301eSmrgvoid
50af69d88dSmrgsoftpipe_clear(struct pipe_context *pipe, unsigned buffers,
517ec681f3Smrg               const struct pipe_scissor_state *scissor_state,
52af69d88dSmrg               const union pipe_color_union *color,
534a49301eSmrg               double depth, unsigned stencil)
544a49301eSmrg{
554a49301eSmrg   struct softpipe_context *softpipe = softpipe_context(pipe);
56af69d88dSmrg   struct pipe_surface *zsbuf = softpipe->framebuffer.zsbuf;
57af69d88dSmrg   unsigned zs_buffers = buffers & PIPE_CLEAR_DEPTHSTENCIL;
58af69d88dSmrg   uint64_t cv;
594a49301eSmrg   uint i;
604a49301eSmrg
617ec681f3Smrg   if (unlikely(sp_debug & SP_DBG_NO_RAST))
624a49301eSmrg      return;
634a49301eSmrg
64cdc920a0Smrg   if (!softpipe_check_render_cond(softpipe))
65cdc920a0Smrg      return;
66cdc920a0Smrg
674a49301eSmrg#if 0
68af69d88dSmrg   softpipe_update_derived(softpipe, PIPE_PRIM_TRIANGLES); /* not needed?? */
694a49301eSmrg#endif
704a49301eSmrg
714a49301eSmrg   if (buffers & PIPE_CLEAR_COLOR) {
724a49301eSmrg      for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
739f464c52Smaya         if (buffers & (PIPE_CLEAR_COLOR0 << i))
749f464c52Smaya            sp_tile_cache_clear(softpipe->cbuf_cache[i], color, 0);
754a49301eSmrg      }
764a49301eSmrg   }
774a49301eSmrg
78af69d88dSmrg   if (zs_buffers &&
79af69d88dSmrg       util_format_is_depth_and_stencil(zsbuf->texture->format) &&
80af69d88dSmrg       zs_buffers != PIPE_CLEAR_DEPTHSTENCIL) {
81af69d88dSmrg      /* Clearing only depth or stencil in a combined depth-stencil buffer. */
82af69d88dSmrg      util_clear_depth_stencil(pipe, zsbuf, zs_buffers, depth, stencil,
83af69d88dSmrg                               0, 0, zsbuf->width, zsbuf->height);
84af69d88dSmrg   }
85af69d88dSmrg   else if (zs_buffers) {
86af69d88dSmrg      static const union pipe_color_union zero;
874a49301eSmrg
88af69d88dSmrg      cv = util_pack64_z_stencil(zsbuf->format, depth, stencil);
89af69d88dSmrg      sp_tile_cache_clear(softpipe->zsbuf_cache, &zero, cv);
904a49301eSmrg   }
914a49301eSmrg
924a49301eSmrg   softpipe->dirty_render_cache = TRUE;
934a49301eSmrg}
94