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"
38 #include "tnl/t_vp_build.h"
40 #include "drivers/common/driverfuncs.h"
42 #include "nouveau_context.h"
43 #include "nouveau_driver.h"
44 //#include "nouveau_state.h"
45 #include "nouveau_span.h"
46 #include "nouveau_object.h"
47 #include "nouveau_fifo.h"
48 #include "nouveau_tex.h"
49 #include "nouveau_msg.h"
50 #include "nv10_swtcl.h"
55 #include "xmlpool.h" /* for symbolic values of enum-type options */
58 int NOUVEAU_DEBUG
= 0;
61 static const struct dri_debug_control debug_control
[] =
66 const struct dri_extension common_extensions
[] =
71 /* Create the device specific context.
73 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
74 __DRIcontextPrivate
*driContextPriv
,
75 void *sharedContextPrivate
)
77 GLcontext
*ctx
, *shareCtx
;
78 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
79 struct dd_function_table functions
;
80 nouveauContextPtr nmesa
;
81 nouveauScreenPtr screen
;
83 /* Allocate the context */
84 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
88 nmesa
->driContext
= driContextPriv
;
89 nmesa
->driScreen
= sPriv
;
90 nmesa
->driDrawable
= NULL
;
91 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
92 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
93 nmesa
->driFd
= sPriv
->fd
;
95 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
98 /* Create the hardware context */
99 if (!nouveauFifoInit(nmesa
))
101 nouveauObjectInit(nmesa
);
103 /* Init default driver functions then plug in our nouveau-specific functions
104 * (the texture functions are especially important)
106 _mesa_init_driver_functions( &functions
);
107 nouveauDriverInitFunctions( &functions
);
108 nouveauTexInitFunctions( &functions
);
110 /* Allocate the Mesa context */
111 if (sharedContextPrivate
)
112 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
115 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
116 &functions
, (void *) nmesa
);
121 driContextPriv
->driverPrivate
= nmesa
;
124 /* Parse configuration files */
125 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
126 screen
->driScreen
->myNum
, "nouveau");
128 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
129 screen
->sarea_priv_offset
);
132 nmesa
->current_primitive
= -1;
134 nouveauShaderInitFuncs(ctx
);
135 /* Install Mesa's fixed-function shader support */
136 if (nmesa
->screen
->card
->type
>= NV_40
) {
137 ctx
->_MaintainTnlProgram
= GL_TRUE
;
138 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
141 /* Initialize the swrast */
142 _swrast_CreateContext( ctx
);
143 _ac_CreateContext( ctx
);
144 _tnl_CreateContext( ctx
);
145 _swsetup_CreateContext( ctx
);
147 _math_matrix_ctr(&nmesa
->viewport
);
149 nouveauDDInitStateFuncs( ctx
);
150 nouveauSpanInitFunctions( ctx
);
151 nouveauDDInitState( nmesa
);
152 switch(nmesa
->screen
->card
->type
)
155 //nv03TriInitFunctions( ctx );
159 //nv04TriInitFunctions( ctx );
167 nv10TriInitFunctions( ctx
);
171 nouveauInitState(ctx
);
173 driContextPriv
->driverPrivate
= (void *)nmesa
;
175 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
178 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
179 fprintf(stderr
, "disabling 3D acceleration\n");
180 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
186 /* Destroy the device specific context. */
187 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
189 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
193 /* free the option cache */
194 driDestroyOptionCache (&nmesa
->optionCache
);
202 /* Force the context `c' to be the current context and associate with it
205 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
206 __DRIdrawablePrivate
*driDrawPriv
,
207 __DRIdrawablePrivate
*driReadPriv
)
209 if ( driContextPriv
) {
210 GET_CURRENT_CONTEXT(ctx
);
211 nouveauContextPtr oldNOUVEAUCtx
= ctx
? NOUVEAU_CONTEXT(ctx
) : NULL
;
212 nouveauContextPtr newNOUVEAUCtx
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
214 driDrawableInitVBlank(driDrawPriv
, newNOUVEAUCtx
->vblank_flags
, &newNOUVEAUCtx
->vblank_seq
);
215 newNOUVEAUCtx
->driDrawable
= driDrawPriv
;
217 _mesa_make_current( newNOUVEAUCtx
->glCtx
,
218 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
219 (GLframebuffer
*) driReadPriv
->driverPrivate
);
222 _mesa_make_current( NULL
, NULL
, NULL
);
229 /* Force the context `c' to be unbound from its buffer.
231 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
236 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
240 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
241 int x
, int y
, int w
, int h
)