101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/**************************************************************************
201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2007 VMware, Inc.
401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * All Rights Reserved.
501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * copy of this software and associated documentation files (the
801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * "Software"), to deal in the Software without restriction, including
901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
1001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
1101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to
1201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * the following conditions:
1301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
1401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * The above copyright notice and this permission notice (including the
1501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * next paragraph) shall be included in all copies or substantial portions
1601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * of the Software.
1701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
1801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
2201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
2601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell **************************************************************************/
2701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
28eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer/* Authors:
2901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *    Brian Paul
3001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */
3101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
3201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
336358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "util/u_format.h"
346358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "util/u_pack_color.h"
3501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell#include "i915_context.h"
366358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "i915_screen.h"
376358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "i915_reg.h"
386358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "i915_batch.h"
396358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "i915_resource.h"
406358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter#include "i915_state.h"
4101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
42fb3b712b84528b192834d3ba3df557b25bbe6e6eDaniel Vettervoid
436dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airliei915_clear_emit(struct pipe_context *pipe, unsigned buffers,
446dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie                const union pipe_color_union *color,
456358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter                double depth, unsigned stencil,
466358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter                unsigned destx, unsigned desty, unsigned width, unsigned height)
476358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter{
486358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   struct i915_context *i915 = i915_context(pipe);
496358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   uint32_t clear_params, clear_color, clear_depth, clear_stencil,
506358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter            clear_color8888, packed_z_stencil;
516358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   union util_color u_color;
526358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   float f_depth = depth;
536358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   struct i915_texture *cbuf_tex, *depth_tex;
54661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter   int depth_clear_bbp, color_clear_bbp;
556358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
566358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   cbuf_tex = depth_tex = NULL;
576358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   clear_params = 0;
58661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter   depth_clear_bbp = color_clear_bbp = 0;
596358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
606358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   if (buffers & PIPE_CLEAR_COLOR) {
616358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      struct pipe_surface *cbuf = i915->framebuffer.cbufs[0];
626358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
636358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      clear_params |= CLEARPARAM_WRITE_COLOR;
646358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      cbuf_tex = i915_texture(cbuf->texture);
658dd523b2dfdcda27a0afc449b169f2c26bf73527Daniel Vetter
666dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie      util_pack_color(color->f, cbuf->format, &u_color);
67661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      if (util_format_get_blocksize(cbuf_tex->b.b.format) == 4) {
68fa4082320acaf0a1a22ae56144eef94b2997818dRoland Scheidegger         clear_color = u_color.ui[0];
69661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         color_clear_bbp = 32;
70661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      } else {
71fa4082320acaf0a1a22ae56144eef94b2997818dRoland Scheidegger         clear_color = (u_color.ui[0] & 0xffff) | (u_color.ui[0] << 16);
72661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         color_clear_bbp = 16;
73661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      }
746358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
758dd523b2dfdcda27a0afc449b169f2c26bf73527Daniel Vetter      /* correctly swizzle clear value */
7623d4a0569dcb70bdfd748bf7e1f5102289bfad6bStéphane Marchesin      if (i915->current.target_fixup_format)
778dd523b2dfdcda27a0afc449b169f2c26bf73527Daniel Vetter         util_pack_color(color->f, cbuf->format, &u_color);
788dd523b2dfdcda27a0afc449b169f2c26bf73527Daniel Vetter      else
798dd523b2dfdcda27a0afc449b169f2c26bf73527Daniel Vetter         util_pack_color(color->f, PIPE_FORMAT_B8G8R8A8_UNORM, &u_color);
80fa4082320acaf0a1a22ae56144eef94b2997818dRoland Scheidegger      clear_color8888 = u_color.ui[0];
816358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   } else
826358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      clear_color = clear_color8888 = 0;
836358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
846358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   clear_depth = clear_stencil = 0;
856358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   if (buffers & PIPE_CLEAR_DEPTH) {
866358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      struct pipe_surface *zbuf = i915->framebuffer.zsbuf;
876358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
886358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      clear_params |= CLEARPARAM_WRITE_DEPTH;
896358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      depth_tex = i915_texture(zbuf->texture);
906358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      packed_z_stencil = util_pack_z_stencil(depth_tex->b.b.format, depth, stencil);
916358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
926358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      if (util_format_get_blocksize(depth_tex->b.b.format) == 4) {
936358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter         /* Avoid read-modify-write if there's no stencil. */
946358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter         if (buffers & PIPE_CLEAR_STENCIL
95866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie               || depth_tex->b.b.format != PIPE_FORMAT_Z24_UNORM_S8_UINT) {
966358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter            clear_params |= CLEARPARAM_WRITE_STENCIL;
97e2c08e824b9698f911fb6c20da43ce7476de0b3fMichael Karcher            clear_stencil = packed_z_stencil >> 24;
98e2c08e824b9698f911fb6c20da43ce7476de0b3fMichael Karcher         }
99661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
100e2c08e824b9698f911fb6c20da43ce7476de0b3fMichael Karcher         clear_depth = packed_z_stencil & 0xffffff;
101661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         depth_clear_bbp = 32;
1026358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      } else {
103ce775dc1b6601bb7272054b87fcb574c19265c63Daniel Vetter         clear_depth = (packed_z_stencil & 0xffff) | (packed_z_stencil << 16);
104661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         depth_clear_bbp = 16;
1056358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      }
106e2c08e824b9698f911fb6c20da43ce7476de0b3fMichael Karcher   } else if (buffers & PIPE_CLEAR_STENCIL) {
107530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter      struct pipe_surface *zbuf = i915->framebuffer.zsbuf;
108530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter
109530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter      clear_params |= CLEARPARAM_WRITE_STENCIL;
110530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter      depth_tex = i915_texture(zbuf->texture);
111866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie      assert(depth_tex->b.b.format == PIPE_FORMAT_Z24_UNORM_S8_UINT);
112530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter
113530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter      packed_z_stencil = util_pack_z_stencil(depth_tex->b.b.format, depth, stencil);
114530728fb60fc4dd2aa1a2b6eb5de39ec9b17ea35Daniel Vetter      depth_clear_bbp = 32;
115e2c08e824b9698f911fb6c20da43ce7476de0b3fMichael Karcher      clear_stencil = packed_z_stencil >> 24;
1166358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   }
1176358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
118661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter   /* hw can't fastclear both depth and color if their bbp mismatch. */
119661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter   if (color_clear_bbp && depth_clear_bbp
120661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         && color_clear_bbp != depth_clear_bbp) {
121661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      if (i915->hardware_dirty)
122661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         i915_emit_hardware_state(i915);
1236358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
124661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      if (!BEGIN_BATCH(1 + 2*(7 + 7))) {
1251662178863d7b715530274148aa57e6494f935a8Stéphane Marchesin         FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
1266358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
127661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         i915_emit_hardware_state(i915);
128661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         i915->vbo_flushed = 1;
1296358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
130661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         assert(BEGIN_BATCH(1 + 2*(7 + 7)));
131661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      }
132661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
133661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
134661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
135661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DSTATE_CLEAR_PARAMETERS);
136661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(CLEARPARAM_WRITE_COLOR | CLEARPARAM_CLEAR_RECT);
137661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      /* Used for zone init prim */
138661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_color);
139661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_depth);
140661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      /* Used for clear rect prim */
141661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_color8888);
142661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(f_depth);
143661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_stencil);
144661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
145661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DPRIMITIVE | PRIM3D_CLEAR_RECT | 5);
146661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx + width);
147661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty + height);
148661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx);
149661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty + height);
150661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx);
151661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty);
152661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
153661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DSTATE_CLEAR_PARAMETERS);
154661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH((clear_params & ~CLEARPARAM_WRITE_COLOR) |
155661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter                CLEARPARAM_CLEAR_RECT);
156661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      /* Used for zone init prim */
157661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_color);
158661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_depth);
159661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      /* Used for clear rect prim */
160661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_color8888);
161661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(f_depth);
162661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_stencil);
163661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
164661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DPRIMITIVE | PRIM3D_CLEAR_RECT | 5);
165661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx + width);
166661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty + height);
167661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx);
168661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty + height);
169661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx);
170661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty);
171661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter   } else {
172661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      if (i915->hardware_dirty)
173661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         i915_emit_hardware_state(i915);
174661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
175661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      if (!BEGIN_BATCH(1 + 7 + 7)) {
1761662178863d7b715530274148aa57e6494f935a8Stéphane Marchesin         FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
177661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
178661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         i915_emit_hardware_state(i915);
179661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         i915->vbo_flushed = 1;
180661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
181661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter         assert(BEGIN_BATCH(1 + 7 + 7));
182661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      }
1836358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
184661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
185661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
186661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DSTATE_CLEAR_PARAMETERS);
187661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_params | CLEARPARAM_CLEAR_RECT);
188661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      /* Used for zone init prim */
189661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_color);
190661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_depth);
191661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      /* Used for clear rect prim */
192661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_color8888);
193661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(f_depth);
194661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(clear_stencil);
195661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter
196661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH(_3DPRIMITIVE | PRIM3D_CLEAR_RECT | 5);
197661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx + width);
198661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty + height);
199661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx);
200661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty + height);
201661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(destx);
202661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter      OUT_BATCH_F(desty);
203661b7ef9a89b8f5a10cb8ca8a23365bce1f1cbc5Daniel Vetter   }
204e53b41f2632af26c79c4f7ed5b0fdb86a1feb602Stéphane Marchesin
205e53b41f2632af26c79c4f7ed5b0fdb86a1feb602Stéphane Marchesin   /* Flush after clear, its expected to be a costly operation.
2060a6131b15c874c076781a8dc347b4e51be15801aDaniel Vetter    * This is not required, just a heuristic, but without the flush we'd need to
2070a6131b15c874c076781a8dc347b4e51be15801aDaniel Vetter    * clobber the SCISSOR_ENABLE dynamic state. */
2081662178863d7b715530274148aa57e6494f935a8Stéphane Marchesin   FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
209b97889f543085f516fc1c821c621790399d57fa5Stéphane Marchesin
210b97889f543085f516fc1c821c621790399d57fa5Stéphane Marchesin   i915->last_fired_vertices = i915->fired_vertices;
211b97889f543085f516fc1c821c621790399d57fa5Stéphane Marchesin   i915->fired_vertices = 0;
2126358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter}
21301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
21401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/**
215eb168e26aa63f11a47d70c4555cae30691a2cd57Michel Dänzer * Clear the given buffers to the specified values.
21601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * No masking, no scissor (clear entire buffer).
21701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */
21801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellvoid
2196dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airliei915_clear_blitter(struct pipe_context *pipe, unsigned buffers,
2206dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie                   const union pipe_color_union *color,
2216358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter                   double depth, unsigned stencil)
22201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
22322b8288b336d506997d69e3b026fcf16c996a973Brian Paul   struct pipe_framebuffer_state *framebuffer =
22422b8288b336d506997d69e3b026fcf16c996a973Brian Paul      &i915_context(pipe)->framebuffer;
22522b8288b336d506997d69e3b026fcf16c996a973Brian Paul   unsigned i;
22622b8288b336d506997d69e3b026fcf16c996a973Brian Paul
22722b8288b336d506997d69e3b026fcf16c996a973Brian Paul   for (i = 0; i < framebuffer->nr_cbufs; i++) {
22822b8288b336d506997d69e3b026fcf16c996a973Brian Paul      if (buffers & (PIPE_CLEAR_COLOR0 << i)) {
22922b8288b336d506997d69e3b026fcf16c996a973Brian Paul         struct pipe_surface *ps = framebuffer->cbufs[i];
23022b8288b336d506997d69e3b026fcf16c996a973Brian Paul
23122b8288b336d506997d69e3b026fcf16c996a973Brian Paul         if (ps) {
23222b8288b336d506997d69e3b026fcf16c996a973Brian Paul            pipe->clear_render_target(pipe, ps, color, 0, 0, ps->width,
23322b8288b336d506997d69e3b026fcf16c996a973Brian Paul                                      ps->height, true);
23422b8288b336d506997d69e3b026fcf16c996a973Brian Paul         }
23522b8288b336d506997d69e3b026fcf16c996a973Brian Paul      }
23622b8288b336d506997d69e3b026fcf16c996a973Brian Paul   }
23722b8288b336d506997d69e3b026fcf16c996a973Brian Paul
23822b8288b336d506997d69e3b026fcf16c996a973Brian Paul   if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
23922b8288b336d506997d69e3b026fcf16c996a973Brian Paul      struct pipe_surface *ps = framebuffer->zsbuf;
24022b8288b336d506997d69e3b026fcf16c996a973Brian Paul      pipe->clear_depth_stencil(pipe, ps, buffers & PIPE_CLEAR_DEPTHSTENCIL,
24122b8288b336d506997d69e3b026fcf16c996a973Brian Paul                                depth, stencil,
24222b8288b336d506997d69e3b026fcf16c996a973Brian Paul                                0, 0, ps->width, ps->height, true);
24322b8288b336d506997d69e3b026fcf16c996a973Brian Paul   }
24401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
2456358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
2466358e6371b31671acbfa7c00336673f62ee928c5Daniel Vettervoid
2476dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airliei915_clear_render(struct pipe_context *pipe, unsigned buffers,
2486dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie                  const union pipe_color_union *color,
2496358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter                  double depth, unsigned stencil)
2506358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter{
2516358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   struct i915_context *i915 = i915_context(pipe);
2526358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
2536358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter   if (i915->dirty)
2546358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter      i915_update_derived(i915);
2556358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter
2566dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie   i915_clear_emit(pipe, buffers, color, depth, stencil,
257f6087955888ee089f986c19b576ef574c9e7bd06Daniel Vetter                   0, 0, i915->framebuffer.width, i915->framebuffer.height);
2586358e6371b31671acbfa7c00336673f62ee928c5Daniel Vetter}
259