nv50: use 3D engine clears, 2D engine doesn't understand zeta formats
[mesa.git] / src / gallium / drivers / nv50 / nv50_clear.c
index 552b92f72e233b352e1aaaf73437cad6d7636f4b..a31a42d6b54879ca0d5f20883a8b3c032456cf20 100644 (file)
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2008 Ben Skeggs
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
@@ -8,5 +30,61 @@ void
 nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps,
           unsigned clearValue)
 {
-       pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue);
+       struct nv50_context *nv50 = nv50_context(pipe);
+       struct pipe_framebuffer_state fb, s_fb = nv50->framebuffer;
+       struct pipe_scissor_state sc, s_sc = nv50->scissor;
+       unsigned dirty = nv50->dirty;
+
+       nv50->dirty = 0;
+
+       if (ps->format == PIPE_FORMAT_Z24S8_UNORM ||
+           ps->format == PIPE_FORMAT_Z16_UNORM) {
+               fb.num_cbufs = 0;
+               fb.zsbuf = ps;
+       } else {
+               fb.num_cbufs = 1;
+               fb.cbufs[0] = ps;
+               fb.zsbuf = NULL;
+       }
+       fb.width = ps->width;
+       fb.height = ps->height;
+       pipe->set_framebuffer_state(pipe, &fb);
+
+       sc.minx = sc.miny = 0;
+       sc.maxx = fb.width;
+       sc.maxy = fb.height;
+       pipe->set_scissor_state(pipe, &sc);
+
+       nv50_state_validate(nv50);
+
+       switch (ps->format) {
+       case PIPE_FORMAT_A8R8G8B8_UNORM:
+               BEGIN_RING(tesla, 0x0d80, 4);
+               OUT_RINGf (ubyte_to_float((clearValue >> 16) & 0xff));
+               OUT_RINGf (ubyte_to_float((clearValue >>  8) & 0xff));
+               OUT_RINGf (ubyte_to_float((clearValue >>  0) & 0xff));
+               OUT_RINGf (ubyte_to_float((clearValue >> 24) & 0xff));
+               BEGIN_RING(tesla, 0x19d0, 1);
+               OUT_RING  (0x3c);
+               break;
+       case PIPE_FORMAT_Z24S8_UNORM:
+               BEGIN_RING(tesla, 0x0d90, 1);
+               OUT_RINGf ((float)(clearValue >> 8) * (1.0 / 16777215.0));
+               BEGIN_RING(tesla, 0x0da0, 1);
+               OUT_RING  (clearValue & 0xff);
+               BEGIN_RING(tesla, 0x19d0, 1);
+               OUT_RING  (0x03);
+               break;
+       default:
+               pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height,
+                                  clearValue);
+               break;
+       }
+
+       pipe->set_framebuffer_state(pipe, &s_fb);
+       pipe->set_scissor_state(pipe, &s_sc);
+       nv50->dirty |= dirty;
+
+       ps->status = PIPE_SURFACE_STATUS_CLEAR;
 }
+