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"
37 #include "tnl/t_pipeline.h"
39 #include "drivers/common/driverfuncs.h"
41 #include "nouveau_context.h"
42 #include "nouveau_ioctl.h"
43 #include "nouveau_driver.h"
44 //#include "nouveau_state.h"
45 #include "nouveau_span.h"
46 #include "nouveau_tex.h"
47 #include "nv10_swtcl.h"
52 #include "xmlpool.h" /* for symbolic values of enum-type options */
55 int NOUVEAU_DEBUG
= 0;
58 #define NOUVEAU_FALLBACK_DISABLE 1
60 static const struct dri_debug_control debug_control
[] =
65 /* Create the device specific context.
67 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
68 __DRIcontextPrivate
*driContextPriv
,
69 void *sharedContextPrivate
)
71 GLcontext
*ctx
, *shareCtx
;
72 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
73 struct dd_function_table functions
;
74 nouveauContextPtr nmesa
;
75 nouveauScreenPtr screen
;
78 /* Allocate the context */
79 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
83 /* Init default driver functions then plug in our Radeon-specific functions
84 * (the texture functions are especially important)
86 _mesa_init_driver_functions( &functions
);
87 nouveauDriverInitFunctions( &functions
);
88 nouveauIoctlInitFunctions( &functions
);
89 nouveauTexInitFunctions( &functions
);
91 /* Allocate the Mesa context */
92 if (sharedContextPrivate
)
93 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
96 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
97 &functions
, (void *) nmesa
);
102 driContextPriv
->driverPrivate
= nmesa
;
105 nmesa
->driContext
= driContextPriv
;
106 nmesa
->driScreen
= sPriv
;
107 nmesa
->driDrawable
= NULL
;
108 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
109 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
110 nmesa
->driFd
= sPriv
->fd
;
112 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
113 screen
=nmesa
->screen
;
115 /* Parse configuration files */
116 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
117 screen
->driScreen
->myNum
, "nouveau");
119 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
120 screen
->sarea_priv_offset
);
123 nmesa
->current_primitive
= -1;
125 /* Initialize the swrast */
126 _swrast_CreateContext( ctx
);
127 _ac_CreateContext( ctx
);
128 _tnl_CreateContext( ctx
);
129 _swsetup_CreateContext( ctx
);
131 switch(nmesa
->screen
->card_type
)
137 //nv03TriInitFunctions( ctx );
144 nv10TriInitFunctions( ctx
);
147 nouveauDDInitStateFuncs( ctx
);
148 nouveauSpanInitFunctions( ctx
);
149 nouveauDDInitState( nmesa
);
151 driContextPriv
->driverPrivate
= (void *)nmesa
;
153 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
156 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
157 fprintf(stderr
, "disabling 3D acceleration\n");
158 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
164 /* Destroy the device specific context. */
165 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
167 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
171 /* free the option cache */
172 driDestroyOptionCache (&nmesa
->optionCache
);
180 /* Force the context `c' to be the current context and associate with it
183 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
184 __DRIdrawablePrivate
*driDrawPriv
,
185 __DRIdrawablePrivate
*driReadPriv
)
187 if ( driContextPriv
) {
188 GET_CURRENT_CONTEXT(ctx
);
189 nouveauContextPtr oldNOUVEAUCtx
= ctx
? NOUVEAU_CONTEXT(ctx
) : NULL
;
190 nouveauContextPtr newNOUVEAUCtx
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
192 driDrawableInitVBlank( driDrawPriv
, newNOUVEAUCtx
->vblank_flags
);
193 newNOUVEAUCtx
->driDrawable
= driDrawPriv
;
195 _mesa_make_current( newNOUVEAUCtx
->glCtx
,
196 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
197 (GLframebuffer
*) driReadPriv
->driverPrivate
);
200 _mesa_make_current( NULL
, NULL
, NULL
);
207 /* Force the context `c' to be unbound from its buffer.
209 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)