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 "nouveau_query.h"
54 #include "nv04_swtcl.h"
55 #include "nv10_swtcl.h"
60 #include "xmlpool.h" /* for symbolic values of enum-type options */
63 int NOUVEAU_DEBUG
= 0;
66 static const struct dri_debug_control debug_control
[] =
68 { "shaders" , DEBUG_SHADERS
},
69 { "mem" , DEBUG_MEM
},
70 { "bufferobj" , DEBUG_BUFFEROBJ
},
74 #define need_GL_ARB_vertex_program
75 #define need_GL_ARB_occlusion_query
76 #include "extension_helper.h"
78 const struct dri_extension common_extensions
[] =
83 const struct dri_extension nv10_extensions
[] =
88 const struct dri_extension nv20_extensions
[] =
93 const struct dri_extension nv30_extensions
[] =
95 { "GL_ARB_fragment_program", NULL
},
99 const struct dri_extension nv40_extensions
[] =
101 /* ARB_vp can be moved to nv20/30 once the shader backend has been
102 * written for those cards.
104 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
105 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
},
109 const struct dri_extension nv50_extensions
[] =
114 /* Create the device specific context.
116 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
117 __DRIcontextPrivate
*driContextPriv
,
118 void *sharedContextPrivate
)
120 GLcontext
*ctx
, *shareCtx
;
121 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
122 struct dd_function_table functions
;
123 nouveauContextPtr nmesa
;
124 nouveauScreenPtr screen
;
126 /* Allocate the context */
127 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
131 nmesa
->driContext
= driContextPriv
;
132 nmesa
->driScreen
= sPriv
;
133 nmesa
->driDrawable
= NULL
;
134 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
135 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
136 nmesa
->driFd
= sPriv
->fd
;
138 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
139 screen
=nmesa
->screen
;
141 /* Create the hardware context */
142 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_FB_PHYSICAL
,
145 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_AGP_PHYSICAL
,
148 if (!nouveauFifoInit(nmesa
))
150 nouveauObjectInit(nmesa
);
153 /* Init default driver functions then plug in our nouveau-specific functions
154 * (the texture functions are especially important)
156 _mesa_init_driver_functions( &functions
);
157 nouveauDriverInitFunctions( &functions
);
158 nouveauTexInitFunctions( &functions
);
160 /* Allocate the Mesa context */
161 if (sharedContextPrivate
)
162 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
165 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
166 &functions
, (void *) nmesa
);
171 driContextPriv
->driverPrivate
= nmesa
;
174 /* Parse configuration files */
175 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
176 screen
->driScreen
->myNum
, "nouveau");
178 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
179 screen
->sarea_priv_offset
);
181 /* Enable any supported extensions */
182 driInitExtensions(ctx
, common_extensions
, GL_TRUE
);
183 if (nmesa
->screen
->card
->type
>= NV_10
)
184 driInitExtensions(ctx
, nv10_extensions
, GL_FALSE
);
185 if (nmesa
->screen
->card
->type
>= NV_20
)
186 driInitExtensions(ctx
, nv20_extensions
, GL_FALSE
);
187 if (nmesa
->screen
->card
->type
>= NV_30
)
188 driInitExtensions(ctx
, nv30_extensions
, GL_FALSE
);
189 if (nmesa
->screen
->card
->type
>= NV_40
)
190 driInitExtensions(ctx
, nv40_extensions
, GL_FALSE
);
191 if (nmesa
->screen
->card
->type
>= NV_50
)
192 driInitExtensions(ctx
, nv50_extensions
, GL_FALSE
);
194 nmesa
->current_primitive
= -1;
196 nouveauShaderInitFuncs(ctx
);
197 /* Install Mesa's fixed-function texenv shader support */
198 if (nmesa
->screen
->card
->type
>= NV_40
)
199 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
201 /* Initialize the swrast */
202 _swrast_CreateContext( ctx
);
203 _ac_CreateContext( ctx
);
204 _tnl_CreateContext( ctx
);
205 _swsetup_CreateContext( ctx
);
207 _math_matrix_ctr(&nmesa
->viewport
);
209 nouveauDDInitStateFuncs( ctx
);
210 nouveauSpanInitFunctions( ctx
);
211 nouveauDDInitState( nmesa
);
212 switch(nmesa
->screen
->card
->type
)
215 //nv03TriInitFunctions( ctx );
219 nv04TriInitFunctions( ctx
);
228 nv10TriInitFunctions( ctx
);
232 nouveauInitBufferObjects(ctx
);
233 if (!nouveauSyncInitFuncs(ctx
))
235 nouveauQueryInitFuncs(ctx
);
236 nmesa
->hw_func
.InitCard(nmesa
);
237 nouveauInitState(ctx
);
239 driContextPriv
->driverPrivate
= (void *)nmesa
;
241 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
244 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
245 fprintf(stderr
, "disabling 3D acceleration\n");
246 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
252 /* Destroy the device specific context. */
253 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
255 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
259 /* free the option cache */
260 driDestroyOptionCache (&nmesa
->optionCache
);
268 /* Force the context `c' to be the current context and associate with it
271 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
272 __DRIdrawablePrivate
*driDrawPriv
,
273 __DRIdrawablePrivate
*driReadPriv
)
275 if ( driContextPriv
) {
276 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
277 struct gl_framebuffer
*draw_fb
=
278 (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
279 struct gl_framebuffer
*read_fb
=
280 (struct gl_framebuffer
*)driReadPriv
->driverPrivate
;
282 driDrawableInitVBlank(driDrawPriv
, nmesa
->vblank_flags
, &nmesa
->vblank_seq
);
283 nmesa
->driDrawable
= driDrawPriv
;
285 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
286 driDrawPriv
->w
, driDrawPriv
->h
);
287 if (draw_fb
!= read_fb
) {
288 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
292 _mesa_make_current(nmesa
->glCtx
, draw_fb
, read_fb
);
294 nouveau_build_framebuffer(nmesa
->glCtx
,
295 driDrawPriv
->driverPrivate
);
297 _mesa_make_current( NULL
, NULL
, NULL
);
304 /* Force the context `c' to be unbound from its buffer.
306 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
311 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa
,
312 __DRIdrawablePrivate
*dPriv
)
314 struct gl_framebuffer
*fb
;
315 nouveau_renderbuffer
*src
, *dst
;
316 drm_clip_rect_t
*box
;
319 fb
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
320 dst
= (nouveau_renderbuffer
*)
321 fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
322 src
= (nouveau_renderbuffer
*)
323 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
325 #ifdef ALLOW_MULTI_SUBCHANNEL
326 LOCK_HARDWARE(nmesa
);
327 nbox
= dPriv
->numClipRects
;
328 box
= dPriv
->pClipRects
;
331 BEGIN_RING_SIZE(NvSubCtxSurf2D
,
332 NV10_CONTEXT_SURFACES_2D_FORMAT
, 4);
333 if (src
->mesa
._ActualFormat
== GL_RGBA8
)
334 OUT_RING (6); /* X8R8G8B8 */
336 OUT_RING (4); /* R5G6B5 */
337 OUT_RING ((dst
->pitch
<< 16) | src
->pitch
);
338 OUT_RING (src
->offset
);
339 OUT_RING (dst
->offset
);
342 for (i
=0; i
<nbox
; i
++, box
++) {
343 BEGIN_RING_SIZE(NvSubImageBlit
, NV10_IMAGE_BLIT_SET_POINT
, 3);
344 OUT_RING (((box
->y1
- dPriv
->y
) << 16) |
345 (box
->x1
- dPriv
->x
));
346 OUT_RING ((box
->y1
<< 16) | box
->x1
);
347 OUT_RING (((box
->y2
- box
->y1
) << 16) |
348 (box
->x2
- box
->x1
));
351 UNLOCK_HARDWARE(nmesa
);
355 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
357 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
358 nouveauContextPtr nmesa
= dPriv
->driContextPriv
->driverPrivate
;
360 if (nmesa
->glCtx
->Visual
.doubleBufferMode
) {
361 _mesa_notifySwapBuffers(nmesa
->glCtx
);
362 nouveauDoSwapBuffers(nmesa
, dPriv
);
368 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
369 int x
, int y
, int w
, int h
)