2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_fbo.h"
30 #include "nv_object.xml.h"
31 #include "nv10_3d.xml.h"
32 #include "nouveau_util.h"
33 #include "nv10_driver.h"
35 static inline unsigned
36 get_rt_format(gl_format format
)
39 case MESA_FORMAT_XRGB8888
:
41 case MESA_FORMAT_ARGB8888
:
43 case MESA_FORMAT_RGB565
:
47 case MESA_FORMAT_Z24_S8
:
55 setup_hierz_buffer(struct gl_context
*ctx
)
57 struct nouveau_channel
*chan
= context_chan(ctx
);
58 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
59 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, HIERZ
);
60 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
61 struct nouveau_framebuffer
*nfb
= to_nouveau_framebuffer(fb
);
62 unsigned pitch
= align(fb
->Width
, 128),
63 height
= align(fb
->Height
, 2),
64 size
= pitch
* height
;
66 if (!nfb
->hierz
.bo
|| nfb
->hierz
.bo
->size
!= size
) {
67 nouveau_bo_ref(NULL
, &nfb
->hierz
.bo
);
68 nouveau_bo_new_tile(context_dev(ctx
), NOUVEAU_BO_VRAM
, 0, size
,
69 0, NOUVEAU_BO_TILE_ZETA
, &nfb
->hierz
.bo
);
72 nouveau_bo_markl(bctx
, celsius
, NV17_3D_HIERZ_OFFSET
,
73 nfb
->hierz
.bo
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
);
76 BEGIN_RING(chan
, celsius
, NV17_3D_HIERZ_WINDOW_X
, 4);
77 OUT_RINGf(chan
, - 1792);
78 OUT_RINGf(chan
, - 2304 + fb
->Height
);
79 OUT_RINGf(chan
, fb
->_DepthMaxF
/ 2);
82 BEGIN_RING(chan
, celsius
, NV17_3D_HIERZ_PITCH
, 1);
83 OUT_RING(chan
, pitch
);
85 BEGIN_RING(chan
, celsius
, NV17_3D_HIERZ_ENABLE
, 1);
90 nv10_emit_framebuffer(struct gl_context
*ctx
, int emit
)
92 struct nouveau_channel
*chan
= context_chan(ctx
);
93 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
94 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, FRAMEBUFFER
);
95 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
96 struct nouveau_surface
*s
;
97 unsigned rt_format
= NV10_3D_RT_FORMAT_TYPE_LINEAR
;
98 unsigned rt_pitch
= 0, zeta_pitch
= 0;
99 unsigned bo_flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
;
101 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
)
104 /* At least nv11 seems to get sad if we don't do this before
106 if (context_chipset(ctx
) < 0x17) {
109 for (i
= 0; i
< 6; i
++) {
110 BEGIN_RING(chan
, celsius
, NV04_GRAPH_NOP
, 1);
116 if (fb
->_ColorDrawBuffers
[0]) {
117 s
= &to_nouveau_renderbuffer(
118 fb
->_ColorDrawBuffers
[0])->surface
;
120 rt_format
|= get_rt_format(s
->format
);
121 zeta_pitch
= rt_pitch
= s
->pitch
;
123 nouveau_bo_markl(bctx
, celsius
, NV10_3D_COLOR_OFFSET
,
128 if (fb
->_DepthBuffer
) {
129 s
= &to_nouveau_renderbuffer(
130 fb
->_DepthBuffer
->Wrapped
)->surface
;
132 rt_format
|= get_rt_format(s
->format
);
133 zeta_pitch
= s
->pitch
;
135 nouveau_bo_markl(bctx
, celsius
, NV10_3D_ZETA_OFFSET
,
138 if (context_chipset(ctx
) >= 0x17) {
139 setup_hierz_buffer(ctx
);
140 context_dirty(ctx
, ZCLEAR
);
144 BEGIN_RING(chan
, celsius
, NV10_3D_RT_FORMAT
, 2);
145 OUT_RING(chan
, rt_format
);
146 OUT_RING(chan
, zeta_pitch
<< 16 | rt_pitch
);
148 context_dirty(ctx
, VIEWPORT
);
149 context_dirty(ctx
, SCISSOR
);
153 nv10_emit_render_mode(struct gl_context
*ctx
, int emit
)
158 nv10_emit_scissor(struct gl_context
*ctx
, int emit
)
160 struct nouveau_channel
*chan
= context_chan(ctx
);
161 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
164 get_scissors(ctx
->DrawBuffer
, &x
, &y
, &w
, &h
);
166 BEGIN_RING(chan
, celsius
, NV10_3D_RT_HORIZ
, 2);
167 OUT_RING(chan
, w
<< 16 | x
);
168 OUT_RING(chan
, h
<< 16 | y
);
172 nv10_emit_viewport(struct gl_context
*ctx
, int emit
)
174 struct nouveau_channel
*chan
= context_chan(ctx
);
175 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
176 struct gl_viewport_attrib
*vp
= &ctx
->Viewport
;
177 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
180 get_viewport_translate(ctx
, a
);
183 if (nv10_use_viewport_zclear(ctx
))
184 a
[2] = nv10_transform_depth(ctx
, (vp
->Far
+ vp
->Near
) / 2);
186 BEGIN_RING(chan
, celsius
, NV10_3D_VIEWPORT_TRANSLATE_X
, 4);
187 OUT_RINGp(chan
, a
, 4);
189 BEGIN_RING(chan
, celsius
, NV10_3D_VIEWPORT_CLIP_HORIZ(0), 1);
190 OUT_RING(chan
, (fb
->Width
- 1) << 16 | 0x08000800);
191 BEGIN_RING(chan
, celsius
, NV10_3D_VIEWPORT_CLIP_VERT(0), 1);
192 OUT_RING(chan
, (fb
->Height
- 1) << 16 | 0x08000800);
194 context_dirty(ctx
, PROJECTION
);
198 nv10_emit_zclear(struct gl_context
*ctx
, int emit
)
200 struct nouveau_context
*nctx
= to_nouveau_context(ctx
);
201 struct nouveau_channel
*chan
= context_chan(ctx
);
202 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
203 struct nouveau_framebuffer
*nfb
=
204 to_nouveau_framebuffer(ctx
->DrawBuffer
);
207 BEGIN_RING(chan
, celsius
, NV17_3D_ZCLEAR_ENABLE
, 2);
208 OUT_RING(chan
, nctx
->hierz
.clear_blocked
? 0 : 1);
209 OUT_RING(chan
, nfb
->hierz
.clear_value
|
210 (nctx
->hierz
.clear_seq
& 0xff));
212 BEGIN_RING(chan
, celsius
, NV10_3D_DEPTH_RANGE_NEAR
, 2);
213 OUT_RINGf(chan
, nv10_transform_depth(ctx
, 0));
214 OUT_RINGf(chan
, nv10_transform_depth(ctx
, 1));
215 context_dirty(ctx
, VIEWPORT
);