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 "nouveau_class.h"
31 #include "nouveau_util.h"
32 #include "nv10_driver.h"
34 static inline unsigned
35 get_rt_format(gl_format format
)
38 case MESA_FORMAT_XRGB8888
:
40 case MESA_FORMAT_ARGB8888
:
42 case MESA_FORMAT_RGB565
:
46 case MESA_FORMAT_Z24_S8
:
54 setup_lma_buffer(GLcontext
*ctx
)
56 struct nouveau_channel
*chan
= context_chan(ctx
);
57 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
58 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, LMA_DEPTH
);
59 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
60 struct nouveau_framebuffer
*nfb
= to_nouveau_framebuffer(fb
);
61 unsigned pitch
= align(fb
->Width
, 128),
62 height
= align(fb
->Height
, 2),
63 size
= pitch
* height
;
65 if (!nfb
->lma_bo
|| nfb
->lma_bo
->size
!= size
) {
66 nouveau_bo_ref(NULL
, &nfb
->lma_bo
);
67 nouveau_bo_new(context_dev(ctx
), NOUVEAU_BO_VRAM
, 0, size
,
71 nouveau_bo_markl(bctx
, celsius
, NV17TCL_LMA_DEPTH_BUFFER_OFFSET
,
72 nfb
->lma_bo
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
);
75 BEGIN_RING(chan
, celsius
, NV17TCL_LMA_DEPTH_WINDOW_X
, 4);
76 OUT_RINGf(chan
, - 1792);
77 OUT_RINGf(chan
, - 2304 + fb
->Height
);
78 OUT_RINGf(chan
, fb
->_DepthMaxF
/ 2);
81 BEGIN_RING(chan
, celsius
, NV17TCL_LMA_DEPTH_BUFFER_PITCH
, 1);
82 OUT_RING(chan
, pitch
);
84 BEGIN_RING(chan
, celsius
, NV17TCL_LMA_DEPTH_ENABLE
, 1);
89 nv10_emit_framebuffer(GLcontext
*ctx
, int emit
)
91 struct nouveau_channel
*chan
= context_chan(ctx
);
92 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
93 struct nouveau_bo_context
*bctx
= context_bctx(ctx
, FRAMEBUFFER
);
94 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
95 struct nouveau_surface
*s
;
96 unsigned rt_format
= NV10TCL_RT_FORMAT_TYPE_LINEAR
;
97 unsigned rt_pitch
= 0, zeta_pitch
= 0;
98 unsigned bo_flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_RDWR
;
100 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
)
103 /* At least nv11 seems to get sad if we don't do this before
105 if (context_chipset(ctx
) < 0x17) {
108 for (i
= 0; i
< 6; i
++) {
109 BEGIN_RING(chan
, celsius
, NV10TCL_NOP
, 1);
115 if (fb
->_ColorDrawBuffers
[0]) {
116 s
= &to_nouveau_renderbuffer(
117 fb
->_ColorDrawBuffers
[0])->surface
;
119 rt_format
|= get_rt_format(s
->format
);
120 zeta_pitch
= rt_pitch
= s
->pitch
;
122 nouveau_bo_markl(bctx
, celsius
, NV10TCL_COLOR_OFFSET
,
127 if (fb
->_DepthBuffer
) {
128 s
= &to_nouveau_renderbuffer(
129 fb
->_DepthBuffer
->Wrapped
)->surface
;
131 rt_format
|= get_rt_format(s
->format
);
132 zeta_pitch
= s
->pitch
;
134 nouveau_bo_markl(bctx
, celsius
, NV10TCL_ZETA_OFFSET
,
137 if (context_chipset(ctx
) >= 0x17)
138 setup_lma_buffer(ctx
);
141 BEGIN_RING(chan
, celsius
, NV10TCL_RT_FORMAT
, 2);
142 OUT_RING(chan
, rt_format
);
143 OUT_RING(chan
, zeta_pitch
<< 16 | rt_pitch
);
145 context_dirty(ctx
, VIEWPORT
);
146 context_dirty(ctx
, SCISSOR
);
150 nv10_emit_render_mode(GLcontext
*ctx
, int emit
)
155 nv10_emit_scissor(GLcontext
*ctx
, int emit
)
157 struct nouveau_channel
*chan
= context_chan(ctx
);
158 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
161 get_scissors(ctx
->DrawBuffer
, &x
, &y
, &w
, &h
);
163 BEGIN_RING(chan
, celsius
, NV10TCL_RT_HORIZ
, 2);
164 OUT_RING(chan
, w
<< 16 | x
);
165 OUT_RING(chan
, h
<< 16 | y
);
169 nv10_emit_viewport(GLcontext
*ctx
, int emit
)
171 struct nouveau_channel
*chan
= context_chan(ctx
);
172 struct nouveau_grobj
*celsius
= context_eng3d(ctx
);
173 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
176 get_viewport_translate(ctx
, a
);
180 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_TRANSLATE_X
, 4);
181 OUT_RINGp(chan
, a
, 4);
183 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 1);
184 OUT_RING(chan
, (fb
->Width
- 1) << 16 | 0x08000800);
185 BEGIN_RING(chan
, celsius
, NV10TCL_VIEWPORT_CLIP_VERT(0), 1);
186 OUT_RING(chan
, (fb
->Height
- 1) << 16 | 0x08000800);
188 context_dirty(ctx
, PROJECTION
);