1 /**************************************************************************
3 Copyright 2006 Stephane Marchesin
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
29 #include "simple_list.h"
32 #include "swrast/swrast.h"
33 #include "swrast_setup/swrast_setup.h"
34 #include "array_cache/acache.h"
35 #include "framebuffer.h"
38 #include "tnl/t_pipeline.h"
39 #include "tnl/t_vp_build.h"
41 #include "drivers/common/driverfuncs.h"
43 #include "nouveau_context.h"
44 #include "nouveau_driver.h"
45 //#include "nouveau_state.h"
46 #include "nouveau_span.h"
47 #include "nouveau_object.h"
48 #include "nouveau_fifo.h"
49 #include "nouveau_tex.h"
50 #include "nouveau_msg.h"
51 #include "nouveau_reg.h"
52 #include "nouveau_lock.h"
53 #include "nv10_swtcl.h"
58 #include "xmlpool.h" /* for symbolic values of enum-type options */
61 int NOUVEAU_DEBUG
= 0;
64 static const struct dri_debug_control debug_control
[] =
66 { "shaders" , DEBUG_SHADERS
},
67 { "mem" , DEBUG_MEM
},
71 #define need_GL_ARB_vertex_program
72 #include "extension_helper.h"
74 const struct dri_extension common_extensions
[] =
79 const struct dri_extension nv10_extensions
[] =
84 const struct dri_extension nv20_extensions
[] =
89 const struct dri_extension nv30_extensions
[] =
91 { "GL_ARB_fragment_program", NULL
},
95 const struct dri_extension nv40_extensions
[] =
97 /* ARB_vp can be moved to nv20/30 once the shader backend has been
98 * written for those cards.
100 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
104 const struct dri_extension nv50_extensions
[] =
109 /* Create the device specific context.
111 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
112 __DRIcontextPrivate
*driContextPriv
,
113 void *sharedContextPrivate
)
115 GLcontext
*ctx
, *shareCtx
;
116 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
117 struct dd_function_table functions
;
118 nouveauContextPtr nmesa
;
119 nouveauScreenPtr screen
;
121 /* Allocate the context */
122 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
126 nmesa
->driContext
= driContextPriv
;
127 nmesa
->driScreen
= sPriv
;
128 nmesa
->driDrawable
= NULL
;
129 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
130 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
131 nmesa
->driFd
= sPriv
->fd
;
133 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
134 screen
=nmesa
->screen
;
136 /* Create the hardware context */
137 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_FB_PHYSICAL
,
140 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_AGP_PHYSICAL
,
143 if (!nouveauFifoInit(nmesa
))
145 nouveauObjectInit(nmesa
);
148 /* Init default driver functions then plug in our nouveau-specific functions
149 * (the texture functions are especially important)
151 _mesa_init_driver_functions( &functions
);
152 nouveauDriverInitFunctions( &functions
);
153 nouveauTexInitFunctions( &functions
);
155 /* Allocate the Mesa context */
156 if (sharedContextPrivate
)
157 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
160 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
161 &functions
, (void *) nmesa
);
166 driContextPriv
->driverPrivate
= nmesa
;
169 /* Parse configuration files */
170 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
171 screen
->driScreen
->myNum
, "nouveau");
173 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
174 screen
->sarea_priv_offset
);
176 /* Enable any supported extensions */
177 driInitExtensions(ctx
, common_extensions
, GL_TRUE
);
178 if (nmesa
->screen
->card
->type
>= NV_10
)
179 driInitExtensions(ctx
, nv10_extensions
, GL_FALSE
);
180 if (nmesa
->screen
->card
->type
>= NV_20
)
181 driInitExtensions(ctx
, nv20_extensions
, GL_FALSE
);
182 if (nmesa
->screen
->card
->type
>= NV_30
)
183 driInitExtensions(ctx
, nv30_extensions
, GL_FALSE
);
184 if (nmesa
->screen
->card
->type
>= NV_40
)
185 driInitExtensions(ctx
, nv40_extensions
, GL_FALSE
);
186 if (nmesa
->screen
->card
->type
>= NV_50
)
187 driInitExtensions(ctx
, nv50_extensions
, GL_FALSE
);
189 nmesa
->current_primitive
= -1;
191 nouveauShaderInitFuncs(ctx
);
192 /* Install Mesa's fixed-function texenv shader support */
193 if (nmesa
->screen
->card
->type
>= NV_40
)
194 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
196 /* Initialize the swrast */
197 _swrast_CreateContext( ctx
);
198 _ac_CreateContext( ctx
);
199 _tnl_CreateContext( ctx
);
200 _swsetup_CreateContext( ctx
);
202 _math_matrix_ctr(&nmesa
->viewport
);
204 nouveauDDInitStateFuncs( ctx
);
205 nouveauSpanInitFunctions( ctx
);
206 nouveauDDInitState( nmesa
);
207 switch(nmesa
->screen
->card
->type
)
210 //nv03TriInitFunctions( ctx );
214 //nv04TriInitFunctions( ctx );
223 nv10TriInitFunctions( ctx
);
227 if (!nouveauSyncInitFuncs(ctx
))
229 nmesa
->hw_func
.InitCard(nmesa
);
230 nouveauInitState(ctx
);
232 driContextPriv
->driverPrivate
= (void *)nmesa
;
234 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
237 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
238 fprintf(stderr
, "disabling 3D acceleration\n");
239 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
245 /* Destroy the device specific context. */
246 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
248 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
252 /* free the option cache */
253 driDestroyOptionCache (&nmesa
->optionCache
);
261 /* Force the context `c' to be the current context and associate with it
264 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
265 __DRIdrawablePrivate
*driDrawPriv
,
266 __DRIdrawablePrivate
*driReadPriv
)
268 if ( driContextPriv
) {
269 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
270 struct gl_framebuffer
*draw_fb
=
271 (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
272 struct gl_framebuffer
*read_fb
=
273 (struct gl_framebuffer
*)driReadPriv
->driverPrivate
;
275 driDrawableInitVBlank(driDrawPriv
, nmesa
->vblank_flags
, &nmesa
->vblank_seq
);
276 nmesa
->driDrawable
= driDrawPriv
;
278 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
279 driDrawPriv
->w
, driDrawPriv
->h
);
280 if (draw_fb
!= read_fb
) {
281 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
285 _mesa_make_current(nmesa
->glCtx
, draw_fb
, read_fb
);
287 nouveau_build_framebuffer(nmesa
->glCtx
,
288 driDrawPriv
->driverPrivate
);
290 _mesa_make_current( NULL
, NULL
, NULL
);
297 /* Force the context `c' to be unbound from its buffer.
299 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
304 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa
,
305 __DRIdrawablePrivate
*dPriv
)
307 struct gl_framebuffer
*fb
;
308 nouveau_renderbuffer
*src
, *dst
;
309 drm_clip_rect_t
*box
;
312 fb
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
313 dst
= (nouveau_renderbuffer
*)
314 fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
315 src
= (nouveau_renderbuffer
*)
316 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
318 #ifdef ALLOW_MULTI_SUBCHANNEL
319 LOCK_HARDWARE(nmesa
);
320 nbox
= dPriv
->numClipRects
;
321 box
= dPriv
->pClipRects
;
324 BEGIN_RING_SIZE(NvSubCtxSurf2D
,
325 NV10_CONTEXT_SURFACES_2D_FORMAT
, 4);
326 if (src
->mesa
._ActualFormat
== GL_RGBA8
)
327 OUT_RING (6); /* X8R8G8B8 */
329 OUT_RING (4); /* R5G6B5 */
330 OUT_RING ((dst
->pitch
<< 16) | src
->pitch
);
331 OUT_RING (src
->offset
);
332 OUT_RING (dst
->offset
);
335 for (i
=0; i
<nbox
; i
++, box
++) {
336 BEGIN_RING_SIZE(NvSubImageBlit
, NV10_IMAGE_BLIT_SET_POINT
, 3);
337 OUT_RING (((box
->y1
- dPriv
->y
) << 16) |
338 (box
->x1
- dPriv
->x
));
339 OUT_RING ((box
->y1
<< 16) | box
->x1
);
340 OUT_RING (((box
->y2
- box
->y1
) << 16) |
341 (box
->x2
- box
->x1
));
344 UNLOCK_HARDWARE(nmesa
);
348 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
350 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
351 nouveauContextPtr nmesa
= dPriv
->driContextPriv
->driverPrivate
;
353 if (nmesa
->glCtx
->Visual
.doubleBufferMode
) {
354 _mesa_notifySwapBuffers(nmesa
->glCtx
);
355 nouveauDoSwapBuffers(nmesa
, dPriv
);
361 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
362 int x
, int y
, int w
, int h
)