Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / gallium / drivers / nv50 / nv50_clear.c
1 /*
2 * Copyright 2008 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "pipe/p_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/p_state.h"
26
27 #include "nv50_context.h"
28
29 void
30 nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps,
31 unsigned clearValue)
32 {
33 struct nv50_context *nv50 = nv50_context(pipe);
34 struct pipe_framebuffer_state fb, s_fb = nv50->framebuffer;
35 struct pipe_scissor_state sc, s_sc = nv50->scissor;
36 unsigned dirty = nv50->dirty;
37
38 nv50->dirty = 0;
39
40 if (ps->format == PIPE_FORMAT_Z24S8_UNORM ||
41 ps->format == PIPE_FORMAT_Z16_UNORM) {
42 fb.num_cbufs = 0;
43 fb.zsbuf = ps;
44 } else {
45 fb.num_cbufs = 1;
46 fb.cbufs[0] = ps;
47 fb.zsbuf = NULL;
48 }
49 fb.width = ps->width;
50 fb.height = ps->height;
51 pipe->set_framebuffer_state(pipe, &fb);
52
53 sc.minx = sc.miny = 0;
54 sc.maxx = fb.width;
55 sc.maxy = fb.height;
56 pipe->set_scissor_state(pipe, &sc);
57
58 nv50_state_validate(nv50);
59
60 switch (ps->format) {
61 case PIPE_FORMAT_A8R8G8B8_UNORM:
62 BEGIN_RING(tesla, 0x0d80, 4);
63 OUT_RINGf (ubyte_to_float((clearValue >> 16) & 0xff));
64 OUT_RINGf (ubyte_to_float((clearValue >> 8) & 0xff));
65 OUT_RINGf (ubyte_to_float((clearValue >> 0) & 0xff));
66 OUT_RINGf (ubyte_to_float((clearValue >> 24) & 0xff));
67 BEGIN_RING(tesla, 0x19d0, 1);
68 OUT_RING (0x3c);
69 break;
70 case PIPE_FORMAT_Z24S8_UNORM:
71 BEGIN_RING(tesla, 0x0d90, 1);
72 OUT_RINGf ((float)(clearValue >> 8) * (1.0 / 16777215.0));
73 BEGIN_RING(tesla, 0x0da0, 1);
74 OUT_RING (clearValue & 0xff);
75 BEGIN_RING(tesla, 0x19d0, 1);
76 OUT_RING (0x03);
77 break;
78 default:
79 pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height,
80 clearValue);
81 break;
82 }
83
84 pipe->set_framebuffer_state(pipe, &s_fb);
85 pipe->set_scissor_state(pipe, &s_sc);
86 nv50->dirty |= dirty;
87
88 ps->status = PIPE_SURFACE_STATUS_CLEAR;
89 }
90