Merge commit 'origin/gallium-master-merge'
[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 nouveau_channel *chan = nv50->screen->nvws->channel;
35 struct nouveau_grobj *tesla = nv50->screen->tesla;
36 struct pipe_framebuffer_state fb, s_fb = nv50->framebuffer;
37 struct pipe_scissor_state sc, s_sc = nv50->scissor;
38 unsigned dirty = nv50->dirty;
39
40 nv50->dirty = 0;
41
42 if (ps->format == PIPE_FORMAT_Z24S8_UNORM ||
43 ps->format == PIPE_FORMAT_Z16_UNORM) {
44 fb.nr_cbufs = 0;
45 fb.zsbuf = ps;
46 } else {
47 fb.nr_cbufs = 1;
48 fb.cbufs[0] = ps;
49 fb.zsbuf = NULL;
50 }
51 fb.width = ps->width;
52 fb.height = ps->height;
53 pipe->set_framebuffer_state(pipe, &fb);
54
55 sc.minx = sc.miny = 0;
56 sc.maxx = fb.width;
57 sc.maxy = fb.height;
58 pipe->set_scissor_state(pipe, &sc);
59
60 nv50_state_validate(nv50);
61
62 switch (ps->format) {
63 case PIPE_FORMAT_A8R8G8B8_UNORM:
64 BEGIN_RING(chan, tesla, 0x0d80, 4);
65 OUT_RINGf (chan, ubyte_to_float((clearValue >> 16) & 0xff));
66 OUT_RINGf (chan, ubyte_to_float((clearValue >> 8) & 0xff));
67 OUT_RINGf (chan, ubyte_to_float((clearValue >> 0) & 0xff));
68 OUT_RINGf (chan, ubyte_to_float((clearValue >> 24) & 0xff));
69 BEGIN_RING(chan, tesla, 0x19d0, 1);
70 OUT_RING (chan, 0x3c);
71 break;
72 case PIPE_FORMAT_Z24S8_UNORM:
73 BEGIN_RING(chan, tesla, 0x0d90, 1);
74 OUT_RINGf (chan, (float)(clearValue >> 8) * (1.0 / 16777215.0));
75 BEGIN_RING(chan, tesla, 0x0da0, 1);
76 OUT_RING (chan, clearValue & 0xff);
77 BEGIN_RING(chan, tesla, 0x19d0, 1);
78 OUT_RING (chan, 0x03);
79 break;
80 default:
81 pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height,
82 clearValue);
83 break;
84 }
85
86 pipe->set_framebuffer_state(pipe, &s_fb);
87 pipe->set_scissor_state(pipe, &s_sc);
88 nv50->dirty |= dirty;
89
90 ps->status = PIPE_SURFACE_STATUS_CLEAR;
91 }
92