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 "nv04_swtcl.h"
54 #include "nv10_swtcl.h"
59 #include "xmlpool.h" /* for symbolic values of enum-type options */
62 int NOUVEAU_DEBUG
= 0;
65 static const struct dri_debug_control debug_control
[] =
67 { "shaders" , DEBUG_SHADERS
},
68 { "mem" , DEBUG_MEM
},
69 { "bufferobj" , DEBUG_BUFFEROBJ
},
73 #define need_GL_ARB_vertex_program
74 #include "extension_helper.h"
76 const struct dri_extension common_extensions
[] =
81 const struct dri_extension nv10_extensions
[] =
86 const struct dri_extension nv20_extensions
[] =
91 const struct dri_extension nv30_extensions
[] =
93 { "GL_ARB_fragment_program", NULL
},
97 const struct dri_extension nv40_extensions
[] =
99 /* ARB_vp can be moved to nv20/30 once the shader backend has been
100 * written for those cards.
102 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
106 const struct dri_extension nv50_extensions
[] =
111 /* Create the device specific context.
113 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
114 __DRIcontextPrivate
*driContextPriv
,
115 void *sharedContextPrivate
)
117 GLcontext
*ctx
, *shareCtx
;
118 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
119 struct dd_function_table functions
;
120 nouveauContextPtr nmesa
;
121 nouveauScreenPtr screen
;
123 /* Allocate the context */
124 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
128 nmesa
->driContext
= driContextPriv
;
129 nmesa
->driScreen
= sPriv
;
130 nmesa
->driDrawable
= NULL
;
131 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
132 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
133 nmesa
->driFd
= sPriv
->fd
;
135 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
136 screen
=nmesa
->screen
;
138 /* Create the hardware context */
139 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_FB_PHYSICAL
,
142 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_AGP_PHYSICAL
,
145 if (!nouveauFifoInit(nmesa
))
147 nouveauObjectInit(nmesa
);
150 /* Init default driver functions then plug in our nouveau-specific functions
151 * (the texture functions are especially important)
153 _mesa_init_driver_functions( &functions
);
154 nouveauDriverInitFunctions( &functions
);
155 nouveauTexInitFunctions( &functions
);
157 /* Allocate the Mesa context */
158 if (sharedContextPrivate
)
159 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
162 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
163 &functions
, (void *) nmesa
);
168 driContextPriv
->driverPrivate
= nmesa
;
171 /* Parse configuration files */
172 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
173 screen
->driScreen
->myNum
, "nouveau");
175 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
176 screen
->sarea_priv_offset
);
178 /* Enable any supported extensions */
179 driInitExtensions(ctx
, common_extensions
, GL_TRUE
);
180 if (nmesa
->screen
->card
->type
>= NV_10
)
181 driInitExtensions(ctx
, nv10_extensions
, GL_FALSE
);
182 if (nmesa
->screen
->card
->type
>= NV_20
)
183 driInitExtensions(ctx
, nv20_extensions
, GL_FALSE
);
184 if (nmesa
->screen
->card
->type
>= NV_30
)
185 driInitExtensions(ctx
, nv30_extensions
, GL_FALSE
);
186 if (nmesa
->screen
->card
->type
>= NV_40
)
187 driInitExtensions(ctx
, nv40_extensions
, GL_FALSE
);
188 if (nmesa
->screen
->card
->type
>= NV_50
)
189 driInitExtensions(ctx
, nv50_extensions
, GL_FALSE
);
191 nmesa
->current_primitive
= -1;
193 nouveauShaderInitFuncs(ctx
);
194 /* Install Mesa's fixed-function texenv shader support */
195 if (nmesa
->screen
->card
->type
>= NV_40
)
196 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
198 /* Initialize the swrast */
199 _swrast_CreateContext( ctx
);
200 _ac_CreateContext( ctx
);
201 _tnl_CreateContext( ctx
);
202 _swsetup_CreateContext( ctx
);
204 _math_matrix_ctr(&nmesa
->viewport
);
206 nouveauDDInitStateFuncs( ctx
);
207 nouveauSpanInitFunctions( ctx
);
208 nouveauDDInitState( nmesa
);
209 switch(nmesa
->screen
->card
->type
)
212 //nv03TriInitFunctions( ctx );
216 nv04TriInitFunctions( ctx
);
225 nv10TriInitFunctions( ctx
);
229 nouveauInitBufferObjects(ctx
);
230 if (!nouveauSyncInitFuncs(ctx
))
232 nmesa
->hw_func
.InitCard(nmesa
);
233 nouveauInitState(ctx
);
235 driContextPriv
->driverPrivate
= (void *)nmesa
;
237 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
240 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
241 fprintf(stderr
, "disabling 3D acceleration\n");
242 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
248 /* Destroy the device specific context. */
249 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
251 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
255 /* free the option cache */
256 driDestroyOptionCache (&nmesa
->optionCache
);
264 /* Force the context `c' to be the current context and associate with it
267 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
268 __DRIdrawablePrivate
*driDrawPriv
,
269 __DRIdrawablePrivate
*driReadPriv
)
271 if ( driContextPriv
) {
272 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
273 struct gl_framebuffer
*draw_fb
=
274 (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
275 struct gl_framebuffer
*read_fb
=
276 (struct gl_framebuffer
*)driReadPriv
->driverPrivate
;
278 driDrawableInitVBlank(driDrawPriv
, nmesa
->vblank_flags
, &nmesa
->vblank_seq
);
279 nmesa
->driDrawable
= driDrawPriv
;
281 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
282 driDrawPriv
->w
, driDrawPriv
->h
);
283 if (draw_fb
!= read_fb
) {
284 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
288 _mesa_make_current(nmesa
->glCtx
, draw_fb
, read_fb
);
290 nouveau_build_framebuffer(nmesa
->glCtx
,
291 driDrawPriv
->driverPrivate
);
293 _mesa_make_current( NULL
, NULL
, NULL
);
300 /* Force the context `c' to be unbound from its buffer.
302 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
307 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa
,
308 __DRIdrawablePrivate
*dPriv
)
310 struct gl_framebuffer
*fb
;
311 nouveau_renderbuffer
*src
, *dst
;
312 drm_clip_rect_t
*box
;
315 fb
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
316 dst
= (nouveau_renderbuffer
*)
317 fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
318 src
= (nouveau_renderbuffer
*)
319 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
321 #ifdef ALLOW_MULTI_SUBCHANNEL
322 LOCK_HARDWARE(nmesa
);
323 nbox
= dPriv
->numClipRects
;
324 box
= dPriv
->pClipRects
;
327 BEGIN_RING_SIZE(NvSubCtxSurf2D
,
328 NV10_CONTEXT_SURFACES_2D_FORMAT
, 4);
329 if (src
->mesa
._ActualFormat
== GL_RGBA8
)
330 OUT_RING (6); /* X8R8G8B8 */
332 OUT_RING (4); /* R5G6B5 */
333 OUT_RING ((dst
->pitch
<< 16) | src
->pitch
);
334 OUT_RING (src
->offset
);
335 OUT_RING (dst
->offset
);
338 for (i
=0; i
<nbox
; i
++, box
++) {
339 BEGIN_RING_SIZE(NvSubImageBlit
, NV10_IMAGE_BLIT_SET_POINT
, 3);
340 OUT_RING (((box
->y1
- dPriv
->y
) << 16) |
341 (box
->x1
- dPriv
->x
));
342 OUT_RING ((box
->y1
<< 16) | box
->x1
);
343 OUT_RING (((box
->y2
- box
->y1
) << 16) |
344 (box
->x2
- box
->x1
));
347 UNLOCK_HARDWARE(nmesa
);
351 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
353 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
354 nouveauContextPtr nmesa
= dPriv
->driContextPriv
->driverPrivate
;
356 if (nmesa
->glCtx
->Visual
.doubleBufferMode
) {
357 _mesa_notifySwapBuffers(nmesa
->glCtx
);
358 nouveauDoSwapBuffers(nmesa
, dPriv
);
364 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
365 int x
, int y
, int w
, int h
)