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
},
68 { "bufferobj" , DEBUG_BUFFEROBJ
},
72 #define need_GL_ARB_vertex_program
73 #include "extension_helper.h"
75 const struct dri_extension common_extensions
[] =
80 const struct dri_extension nv10_extensions
[] =
85 const struct dri_extension nv20_extensions
[] =
90 const struct dri_extension nv30_extensions
[] =
92 { "GL_ARB_fragment_program", NULL
},
96 const struct dri_extension nv40_extensions
[] =
98 /* ARB_vp can be moved to nv20/30 once the shader backend has been
99 * written for those cards.
101 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
105 const struct dri_extension nv50_extensions
[] =
110 /* Create the device specific context.
112 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
113 __DRIcontextPrivate
*driContextPriv
,
114 void *sharedContextPrivate
)
116 GLcontext
*ctx
, *shareCtx
;
117 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
118 struct dd_function_table functions
;
119 nouveauContextPtr nmesa
;
120 nouveauScreenPtr screen
;
122 /* Allocate the context */
123 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
127 nmesa
->driContext
= driContextPriv
;
128 nmesa
->driScreen
= sPriv
;
129 nmesa
->driDrawable
= NULL
;
130 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
131 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
132 nmesa
->driFd
= sPriv
->fd
;
134 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
135 screen
=nmesa
->screen
;
137 /* Create the hardware context */
138 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_FB_PHYSICAL
,
141 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_AGP_PHYSICAL
,
144 if (!nouveauFifoInit(nmesa
))
146 nouveauObjectInit(nmesa
);
149 /* Init default driver functions then plug in our nouveau-specific functions
150 * (the texture functions are especially important)
152 _mesa_init_driver_functions( &functions
);
153 nouveauDriverInitFunctions( &functions
);
154 nouveauTexInitFunctions( &functions
);
156 /* Allocate the Mesa context */
157 if (sharedContextPrivate
)
158 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
161 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
162 &functions
, (void *) nmesa
);
167 driContextPriv
->driverPrivate
= nmesa
;
170 /* Parse configuration files */
171 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
172 screen
->driScreen
->myNum
, "nouveau");
174 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
175 screen
->sarea_priv_offset
);
177 /* Enable any supported extensions */
178 driInitExtensions(ctx
, common_extensions
, GL_TRUE
);
179 if (nmesa
->screen
->card
->type
>= NV_10
)
180 driInitExtensions(ctx
, nv10_extensions
, GL_FALSE
);
181 if (nmesa
->screen
->card
->type
>= NV_20
)
182 driInitExtensions(ctx
, nv20_extensions
, GL_FALSE
);
183 if (nmesa
->screen
->card
->type
>= NV_30
)
184 driInitExtensions(ctx
, nv30_extensions
, GL_FALSE
);
185 if (nmesa
->screen
->card
->type
>= NV_40
)
186 driInitExtensions(ctx
, nv40_extensions
, GL_FALSE
);
187 if (nmesa
->screen
->card
->type
>= NV_50
)
188 driInitExtensions(ctx
, nv50_extensions
, GL_FALSE
);
190 nmesa
->current_primitive
= -1;
192 nouveauShaderInitFuncs(ctx
);
193 /* Install Mesa's fixed-function texenv shader support */
194 if (nmesa
->screen
->card
->type
>= NV_40
)
195 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
197 /* Initialize the swrast */
198 _swrast_CreateContext( ctx
);
199 _ac_CreateContext( ctx
);
200 _tnl_CreateContext( ctx
);
201 _swsetup_CreateContext( ctx
);
203 _math_matrix_ctr(&nmesa
->viewport
);
205 nouveauDDInitStateFuncs( ctx
);
206 nouveauSpanInitFunctions( ctx
);
207 nouveauDDInitState( nmesa
);
208 switch(nmesa
->screen
->card
->type
)
211 //nv03TriInitFunctions( ctx );
215 //nv04TriInitFunctions( ctx );
224 nv10TriInitFunctions( ctx
);
228 nouveauInitBufferObjects(ctx
);
229 if (!nouveauSyncInitFuncs(ctx
))
231 nmesa
->hw_func
.InitCard(nmesa
);
232 nouveauInitState(ctx
);
234 driContextPriv
->driverPrivate
= (void *)nmesa
;
236 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
239 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
240 fprintf(stderr
, "disabling 3D acceleration\n");
241 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
247 /* Destroy the device specific context. */
248 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
250 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
254 /* free the option cache */
255 driDestroyOptionCache (&nmesa
->optionCache
);
263 /* Force the context `c' to be the current context and associate with it
266 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
267 __DRIdrawablePrivate
*driDrawPriv
,
268 __DRIdrawablePrivate
*driReadPriv
)
270 if ( driContextPriv
) {
271 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
272 struct gl_framebuffer
*draw_fb
=
273 (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
274 struct gl_framebuffer
*read_fb
=
275 (struct gl_framebuffer
*)driReadPriv
->driverPrivate
;
277 driDrawableInitVBlank(driDrawPriv
, nmesa
->vblank_flags
, &nmesa
->vblank_seq
);
278 nmesa
->driDrawable
= driDrawPriv
;
280 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
281 driDrawPriv
->w
, driDrawPriv
->h
);
282 if (draw_fb
!= read_fb
) {
283 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
287 _mesa_make_current(nmesa
->glCtx
, draw_fb
, read_fb
);
289 nouveau_build_framebuffer(nmesa
->glCtx
,
290 driDrawPriv
->driverPrivate
);
292 _mesa_make_current( NULL
, NULL
, NULL
);
299 /* Force the context `c' to be unbound from its buffer.
301 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
306 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa
,
307 __DRIdrawablePrivate
*dPriv
)
309 struct gl_framebuffer
*fb
;
310 nouveau_renderbuffer
*src
, *dst
;
311 drm_clip_rect_t
*box
;
314 fb
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
315 dst
= (nouveau_renderbuffer
*)
316 fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
317 src
= (nouveau_renderbuffer
*)
318 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
320 #ifdef ALLOW_MULTI_SUBCHANNEL
321 LOCK_HARDWARE(nmesa
);
322 nbox
= dPriv
->numClipRects
;
323 box
= dPriv
->pClipRects
;
326 BEGIN_RING_SIZE(NvSubCtxSurf2D
,
327 NV10_CONTEXT_SURFACES_2D_FORMAT
, 4);
328 if (src
->mesa
._ActualFormat
== GL_RGBA8
)
329 OUT_RING (6); /* X8R8G8B8 */
331 OUT_RING (4); /* R5G6B5 */
332 OUT_RING ((dst
->pitch
<< 16) | src
->pitch
);
333 OUT_RING (src
->offset
);
334 OUT_RING (dst
->offset
);
337 for (i
=0; i
<nbox
; i
++, box
++) {
338 BEGIN_RING_SIZE(NvSubImageBlit
, NV10_IMAGE_BLIT_SET_POINT
, 3);
339 OUT_RING (((box
->y1
- dPriv
->y
) << 16) |
340 (box
->x1
- dPriv
->x
));
341 OUT_RING ((box
->y1
<< 16) | box
->x1
);
342 OUT_RING (((box
->y2
- box
->y1
) << 16) |
343 (box
->x2
- box
->x1
));
346 UNLOCK_HARDWARE(nmesa
);
350 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
352 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
353 nouveauContextPtr nmesa
= dPriv
->driContextPriv
->driverPrivate
;
355 if (nmesa
->glCtx
->Visual
.doubleBufferMode
) {
356 _mesa_notifySwapBuffers(nmesa
->glCtx
);
357 nouveauDoSwapBuffers(nmesa
, dPriv
);
363 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
364 int x
, int y
, int w
, int h
)