2 * Copyright 2008 Ben Skeggs
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #include "pipe/p_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/p_state.h"
27 #include "nv50_context.h"
30 nv50_clear(struct pipe_context
*pipe
, struct pipe_surface
*ps
,
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
;
42 if (ps
->format
== PIPE_FORMAT_Z24S8_UNORM
||
43 ps
->format
== PIPE_FORMAT_Z16_UNORM
) {
52 fb
.height
= ps
->height
;
53 pipe
->set_framebuffer_state(pipe
, &fb
);
55 sc
.minx
= sc
.miny
= 0;
58 pipe
->set_scissor_state(pipe
, &sc
);
60 nv50_state_validate(nv50
);
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);
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);
81 pipe
->surface_fill(pipe
, ps
, 0, 0, ps
->width
, ps
->height
,
86 pipe
->set_framebuffer_state(pipe
, &s_fb
);
87 pipe
->set_scissor_state(pipe
, &s_sc
);