173f96c51052bf5233191d852ef463462306bf1d5Brian/**************************************************************************
273f96c51052bf5233191d852ef463462306bf1d5Brian *
373f96c51052bf5233191d852ef463462306bf1d5Brian * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
473f96c51052bf5233191d852ef463462306bf1d5Brian * All Rights Reserved.
5eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer * Copyright 2009 VMware, Inc.  All Rights Reserved.
673f96c51052bf5233191d852ef463462306bf1d5Brian *
773f96c51052bf5233191d852ef463462306bf1d5Brian * Permission is hereby granted, free of charge, to any person obtaining a
873f96c51052bf5233191d852ef463462306bf1d5Brian * copy of this software and associated documentation files (the
973f96c51052bf5233191d852ef463462306bf1d5Brian * "Software"), to deal in the Software without restriction, including
1073f96c51052bf5233191d852ef463462306bf1d5Brian * without limitation the rights to use, copy, modify, merge, publish,
1173f96c51052bf5233191d852ef463462306bf1d5Brian * distribute, sub license, and/or sell copies of the Software, and to
1273f96c51052bf5233191d852ef463462306bf1d5Brian * permit persons to whom the Software is furnished to do so, subject to
1373f96c51052bf5233191d852ef463462306bf1d5Brian * the following conditions:
1473f96c51052bf5233191d852ef463462306bf1d5Brian *
1573f96c51052bf5233191d852ef463462306bf1d5Brian * The above copyright notice and this permission notice (including the
1673f96c51052bf5233191d852ef463462306bf1d5Brian * next paragraph) shall be included in all copies or substantial portions
1773f96c51052bf5233191d852ef463462306bf1d5Brian * of the Software.
1873f96c51052bf5233191d852ef463462306bf1d5Brian *
1973f96c51052bf5233191d852ef463462306bf1d5Brian * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2073f96c51052bf5233191d852ef463462306bf1d5Brian * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2173f96c51052bf5233191d852ef463462306bf1d5Brian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2273f96c51052bf5233191d852ef463462306bf1d5Brian * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2373f96c51052bf5233191d852ef463462306bf1d5Brian * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2473f96c51052bf5233191d852ef463462306bf1d5Brian * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2573f96c51052bf5233191d852ef463462306bf1d5Brian * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2673f96c51052bf5233191d852ef463462306bf1d5Brian *
2773f96c51052bf5233191d852ef463462306bf1d5Brian **************************************************************************/
2873f96c51052bf5233191d852ef463462306bf1d5Brian
2973f96c51052bf5233191d852ef463462306bf1d5Brian/* Author:
3073f96c51052bf5233191d852ef463462306bf1d5Brian *    Brian Paul
31eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer *    Michel Dänzer
3273f96c51052bf5233191d852ef463462306bf1d5Brian */
3373f96c51052bf5233191d852ef463462306bf1d5Brian
3473f96c51052bf5233191d852ef463462306bf1d5Brian
35fb206809ba2a131fd9034e10a00592f2d0d81fceBrian#include "pipe/p_defines.h"
36a1886d539158fcc692d0d45985465be8e4bbe077Brian Paul#include "util/u_pack_color.h"
3773f96c51052bf5233191d852ef463462306bf1d5Brian#include "sp_clear.h"
38837f2c18c477f0695150b69b69a3a921b08943ecBrian#include "sp_context.h"
3941450b03a8e8e0f94f8eefc6880d32e9b0ef6f6dBrian Paul#include "sp_query.h"
402b2f761e2b0dc160793be2f48e811d2d455e1e22Brian#include "sp_tile_cache.h"
4173f96c51052bf5233191d852ef463462306bf1d5Brian
4273f96c51052bf5233191d852ef463462306bf1d5Brian
4347fdaf0ed9ef2f89cdaa97d0d48b1f1194d710c6Brian/**
44eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer * Clear the given buffers to the specified values.
4547fdaf0ed9ef2f89cdaa97d0d48b1f1194d710c6Brian * No masking, no scissor (clear entire buffer).
4647fdaf0ed9ef2f89cdaa97d0d48b1f1194d710c6Brian */
4773f96c51052bf5233191d852ef463462306bf1d5Brianvoid
486dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airliesoftpipe_clear(struct pipe_context *pipe, unsigned buffers,
496dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie               const union pipe_color_union *color,
50eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer               double depth, unsigned stencil)
5173f96c51052bf5233191d852ef463462306bf1d5Brian{
524f442d9ef5db42867c99a7288b4114a0340f73e6Keith Whitwell   struct softpipe_context *softpipe = softpipe_context(pipe);
53e763b6e78825f11aa3e9e2368ba8fc47313a7848Morgan Armand   uint64_t cv;
545d4b53b3afcb6014200faad8712bbb13af30469eBrian   uint i;
5554135597b8a23a7349f5fa3193642758c229777eBrian
56a5b87f249ef79b1a8d8b9dbe72879b7ac9eb133cKeith Whitwell   if (softpipe->no_rast)
57a5b87f249ef79b1a8d8b9dbe72879b7ac9eb133cKeith Whitwell      return;
58a5b87f249ef79b1a8d8b9dbe72879b7ac9eb133cKeith Whitwell
5941450b03a8e8e0f94f8eefc6880d32e9b0ef6f6dBrian Paul   if (!softpipe_check_render_cond(softpipe))
6041450b03a8e8e0f94f8eefc6880d32e9b0ef6f6dBrian Paul      return;
6141450b03a8e8e0f94f8eefc6880d32e9b0ef6f6dBrian Paul
625d4b53b3afcb6014200faad8712bbb13af30469eBrian#if 0
6357aa597b3d5dac0fc59c05557dafec59e14e1019Brian Paul   softpipe_update_derived(softpipe, PIPE_PRIM_TRIANGLES); /* not needed?? */
645d4b53b3afcb6014200faad8712bbb13af30469eBrian#endif
6554135597b8a23a7349f5fa3193642758c229777eBrian
66eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer   if (buffers & PIPE_CLEAR_COLOR) {
67eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer      for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
68396ac41fc285f0d7c8545f2b32ba373693a7a326Dave Airlie         sp_tile_cache_clear(softpipe->cbuf_cache[i], color, 0);
695d4b53b3afcb6014200faad8712bbb13af30469eBrian      }
7076a4fd098f44ae4f226d4747b9fdaf9db5d40270Brian   }
7176a4fd098f44ae4f226d4747b9fdaf9db5d40270Brian
72eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer   if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
73396ac41fc285f0d7c8545f2b32ba373693a7a326Dave Airlie      static const union pipe_color_union zero;
74eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer      struct pipe_surface *ps = softpipe->framebuffer.zsbuf;
75eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer
76e763b6e78825f11aa3e9e2368ba8fc47313a7848Morgan Armand      cv = util_pack64_z_stencil(ps->format, depth, stencil);
77396ac41fc285f0d7c8545f2b32ba373693a7a326Dave Airlie      sp_tile_cache_clear(softpipe->zsbuf_cache, &zero, cv);
783f4d776199562f94edb99045e0dad3e26dfddac0Brian Paul   }
79988db641195819c948249a1bb2d59f13577a482fBrian Paul
80988db641195819c948249a1bb2d59f13577a482fBrian Paul   softpipe->dirty_render_cache = TRUE;
8173f96c51052bf5233191d852ef463462306bf1d5Brian}
82