Incomplete shader stuff, should mostly work for NV40. Other cards, not so
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_context.c
1 /**************************************************************************
2
3 Copyright 2006 Stephane Marchesin
4 All Rights Reserved.
5
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:
12
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
15 Software.
16
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.
24
25 **************************************************************************/
26
27 #include "glheader.h"
28 #include "context.h"
29 #include "simple_list.h"
30 #include "imports.h"
31 #include "matrix.h"
32 #include "swrast/swrast.h"
33 #include "swrast_setup/swrast_setup.h"
34 #include "array_cache/acache.h"
35
36 #include "tnl/tnl.h"
37 #include "tnl/t_pipeline.h"
38 #include "tnl/t_vp_build.h"
39
40 #include "drivers/common/driverfuncs.h"
41
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"
51
52 #include "vblank.h"
53 #include "utils.h"
54 #include "texmem.h"
55 #include "xmlpool.h" /* for symbolic values of enum-type options */
56
57 #ifndef NOUVEAU_DEBUG
58 int NOUVEAU_DEBUG = 0;
59 #endif
60
61 static const struct dri_debug_control debug_control[] =
62 {
63 { NULL, 0 }
64 };
65
66 const struct dri_extension common_extensions[] =
67 {
68 { NULL, 0 }
69 };
70
71 /* Create the device specific context.
72 */
73 GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
74 __DRIcontextPrivate *driContextPriv,
75 void *sharedContextPrivate )
76 {
77 GLcontext *ctx, *shareCtx;
78 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
79 struct dd_function_table functions;
80 nouveauContextPtr nmesa;
81 nouveauScreenPtr screen;
82
83 /* Allocate the context */
84 nmesa = (nouveauContextPtr) CALLOC( sizeof(*nmesa) );
85 if ( !nmesa )
86 return GL_FALSE;
87
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;
94
95 nmesa->screen = (nouveauScreenPtr)(sPriv->private);
96 screen=nmesa->screen;
97
98 /* Create the hardware context */
99 if (!nouveauFifoInit(nmesa))
100 return GL_FALSE;
101 nouveauObjectInit(nmesa);
102
103 /* Init default driver functions then plug in our nouveau-specific functions
104 * (the texture functions are especially important)
105 */
106 _mesa_init_driver_functions( &functions );
107 nouveauDriverInitFunctions( &functions );
108 nouveauTexInitFunctions( &functions );
109
110 /* Allocate the Mesa context */
111 if (sharedContextPrivate)
112 shareCtx = ((nouveauContextPtr) sharedContextPrivate)->glCtx;
113 else
114 shareCtx = NULL;
115 nmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
116 &functions, (void *) nmesa);
117 if (!nmesa->glCtx) {
118 FREE(nmesa);
119 return GL_FALSE;
120 }
121 driContextPriv->driverPrivate = nmesa;
122 ctx = nmesa->glCtx;
123
124 /* Parse configuration files */
125 driParseConfigFiles (&nmesa->optionCache, &screen->optionCache,
126 screen->driScreen->myNum, "nouveau");
127
128 nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA +
129 screen->sarea_priv_offset);
130
131
132 nmesa->current_primitive = -1;
133
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;
139 }
140
141 /* Initialize the swrast */
142 _swrast_CreateContext( ctx );
143 _ac_CreateContext( ctx );
144 _tnl_CreateContext( ctx );
145 _swsetup_CreateContext( ctx );
146
147 _math_matrix_ctr(&nmesa->viewport);
148
149 nouveauDDInitStateFuncs( ctx );
150 nouveauSpanInitFunctions( ctx );
151 nouveauDDInitState( nmesa );
152 switch(nmesa->screen->card->type)
153 {
154 case NV_03:
155 //nv03TriInitFunctions( ctx );
156 break;
157 case NV_04:
158 case NV_05:
159 //nv04TriInitFunctions( ctx );
160 break;
161 case NV_10:
162 case NV_20:
163 case NV_30:
164 case NV_40:
165 case G_70:
166 default:
167 nv10TriInitFunctions( ctx );
168 break;
169 }
170
171 nouveauInitState(ctx);
172
173 driContextPriv->driverPrivate = (void *)nmesa;
174
175 NOUVEAU_DEBUG = driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
176 debug_control );
177
178 if (driQueryOptionb(&nmesa->optionCache, "no_rast")) {
179 fprintf(stderr, "disabling 3D acceleration\n");
180 FALLBACK(nmesa, NOUVEAU_FALLBACK_DISABLE, 1);
181 }
182
183 return GL_TRUE;
184 }
185
186 /* Destroy the device specific context. */
187 void nouveauDestroyContext( __DRIcontextPrivate *driContextPriv )
188 {
189 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
190
191 assert(nmesa);
192 if ( nmesa ) {
193 /* free the option cache */
194 driDestroyOptionCache (&nmesa->optionCache);
195
196 FREE( nmesa );
197 }
198
199 }
200
201
202 /* Force the context `c' to be the current context and associate with it
203 * buffer `b'.
204 */
205 GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
206 __DRIdrawablePrivate *driDrawPriv,
207 __DRIdrawablePrivate *driReadPriv )
208 {
209 if ( driContextPriv ) {
210 GET_CURRENT_CONTEXT(ctx);
211 nouveauContextPtr oldNOUVEAUCtx = ctx ? NOUVEAU_CONTEXT(ctx) : NULL;
212 nouveauContextPtr newNOUVEAUCtx = (nouveauContextPtr) driContextPriv->driverPrivate;
213
214 driDrawableInitVBlank(driDrawPriv, newNOUVEAUCtx->vblank_flags, &newNOUVEAUCtx->vblank_seq );
215 newNOUVEAUCtx->driDrawable = driDrawPriv;
216
217 _mesa_make_current( newNOUVEAUCtx->glCtx,
218 (GLframebuffer *) driDrawPriv->driverPrivate,
219 (GLframebuffer *) driReadPriv->driverPrivate );
220
221 } else {
222 _mesa_make_current( NULL, NULL, NULL );
223 }
224
225 return GL_TRUE;
226 }
227
228
229 /* Force the context `c' to be unbound from its buffer.
230 */
231 GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv )
232 {
233 return GL_TRUE;
234 }
235
236 void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv)
237 {
238 }
239
240 void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
241 int x, int y, int w, int h)
242 {
243 }
244