s/params/pointer/ for glGetVertexAttribPointer
[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 #include "framebuffer.h"
36
37 #include "tnl/tnl.h"
38 #include "tnl/t_pipeline.h"
39 #include "tnl/t_vp_build.h"
40
41 #include "drivers/common/driverfuncs.h"
42
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 "nouveau_query.h"
54 #include "nv04_swtcl.h"
55 #include "nv10_swtcl.h"
56
57 #include "vblank.h"
58 #include "utils.h"
59 #include "texmem.h"
60 #include "xmlpool.h" /* for symbolic values of enum-type options */
61
62 #ifndef NOUVEAU_DEBUG
63 int NOUVEAU_DEBUG = 0;
64 #endif
65
66 static const struct dri_debug_control debug_control[] =
67 {
68 { "shaders" , DEBUG_SHADERS },
69 { "mem" , DEBUG_MEM },
70 { "bufferobj" , DEBUG_BUFFEROBJ },
71 { NULL , 0 }
72 };
73
74 #define need_GL_ARB_vertex_program
75 #define need_GL_ARB_occlusion_query
76 #include "extension_helper.h"
77
78 const struct dri_extension common_extensions[] =
79 {
80 { NULL, 0 }
81 };
82
83 const struct dri_extension nv10_extensions[] =
84 {
85 { NULL, 0 }
86 };
87
88 const struct dri_extension nv20_extensions[] =
89 {
90 { NULL, 0 }
91 };
92
93 const struct dri_extension nv30_extensions[] =
94 {
95 { "GL_ARB_fragment_program", NULL },
96 { NULL, 0 }
97 };
98
99 const struct dri_extension nv40_extensions[] =
100 {
101 /* ARB_vp can be moved to nv20/30 once the shader backend has been
102 * written for those cards.
103 */
104 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
105 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions},
106 { NULL, 0 }
107 };
108
109 const struct dri_extension nv50_extensions[] =
110 {
111 { NULL, 0 }
112 };
113
114 /* Create the device specific context.
115 */
116 GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
117 __DRIcontextPrivate *driContextPriv,
118 void *sharedContextPrivate )
119 {
120 GLcontext *ctx, *shareCtx;
121 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
122 struct dd_function_table functions;
123 nouveauContextPtr nmesa;
124 nouveauScreenPtr screen;
125
126 /* Allocate the context */
127 nmesa = (nouveauContextPtr) CALLOC( sizeof(*nmesa) );
128 if ( !nmesa )
129 return GL_FALSE;
130
131 nmesa->driContext = driContextPriv;
132 nmesa->driScreen = sPriv;
133 nmesa->driDrawable = NULL;
134 nmesa->hHWContext = driContextPriv->hHWContext;
135 nmesa->driHwLock = &sPriv->pSAREA->lock;
136 nmesa->driFd = sPriv->fd;
137
138 nmesa->screen = (nouveauScreenPtr)(sPriv->private);
139 screen=nmesa->screen;
140
141 /* Create the hardware context */
142 if (!nouveauDRMGetParam(nmesa, NOUVEAU_GETPARAM_FB_PHYSICAL,
143 &nmesa->vram_phys))
144 return GL_FALSE;
145 if (!nouveauDRMGetParam(nmesa, NOUVEAU_GETPARAM_AGP_PHYSICAL,
146 &nmesa->agp_phys))
147 return GL_FALSE;
148 if (!nouveauFifoInit(nmesa))
149 return GL_FALSE;
150 nouveauObjectInit(nmesa);
151
152
153 /* Init default driver functions then plug in our nouveau-specific functions
154 * (the texture functions are especially important)
155 */
156 _mesa_init_driver_functions( &functions );
157 nouveauDriverInitFunctions( &functions );
158 nouveauTexInitFunctions( &functions );
159
160 /* Allocate the Mesa context */
161 if (sharedContextPrivate)
162 shareCtx = ((nouveauContextPtr) sharedContextPrivate)->glCtx;
163 else
164 shareCtx = NULL;
165 nmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
166 &functions, (void *) nmesa);
167 if (!nmesa->glCtx) {
168 FREE(nmesa);
169 return GL_FALSE;
170 }
171 driContextPriv->driverPrivate = nmesa;
172 ctx = nmesa->glCtx;
173
174 /* Parse configuration files */
175 driParseConfigFiles (&nmesa->optionCache, &screen->optionCache,
176 screen->driScreen->myNum, "nouveau");
177
178 nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA +
179 screen->sarea_priv_offset);
180
181 /* Enable any supported extensions */
182 driInitExtensions(ctx, common_extensions, GL_TRUE);
183 if (nmesa->screen->card->type >= NV_10)
184 driInitExtensions(ctx, nv10_extensions, GL_FALSE);
185 if (nmesa->screen->card->type >= NV_20)
186 driInitExtensions(ctx, nv20_extensions, GL_FALSE);
187 if (nmesa->screen->card->type >= NV_30)
188 driInitExtensions(ctx, nv30_extensions, GL_FALSE);
189 if (nmesa->screen->card->type >= NV_40)
190 driInitExtensions(ctx, nv40_extensions, GL_FALSE);
191 if (nmesa->screen->card->type >= NV_50)
192 driInitExtensions(ctx, nv50_extensions, GL_FALSE);
193
194 nmesa->current_primitive = -1;
195
196 nouveauShaderInitFuncs(ctx);
197 /* Install Mesa's fixed-function texenv shader support */
198 if (nmesa->screen->card->type >= NV_40)
199 ctx->_MaintainTexEnvProgram = GL_TRUE;
200
201 /* Initialize the swrast */
202 _swrast_CreateContext( ctx );
203 _ac_CreateContext( ctx );
204 _tnl_CreateContext( ctx );
205 _swsetup_CreateContext( ctx );
206
207 _math_matrix_ctr(&nmesa->viewport);
208
209 nouveauDDInitStateFuncs( ctx );
210 nouveauSpanInitFunctions( ctx );
211 nouveauDDInitState( nmesa );
212 switch(nmesa->screen->card->type)
213 {
214 case NV_03:
215 //nv03TriInitFunctions( ctx );
216 break;
217 case NV_04:
218 case NV_05:
219 nv04TriInitFunctions( ctx );
220 break;
221 case NV_10:
222 case NV_20:
223 case NV_30:
224 case NV_40:
225 case NV_44:
226 case NV_50:
227 default:
228 nv10TriInitFunctions( ctx );
229 break;
230 }
231
232 nouveauInitBufferObjects(ctx);
233 if (!nouveauSyncInitFuncs(ctx))
234 return GL_FALSE;
235 nouveauQueryInitFuncs(ctx);
236 nmesa->hw_func.InitCard(nmesa);
237 nouveauInitState(ctx);
238
239 driContextPriv->driverPrivate = (void *)nmesa;
240
241 NOUVEAU_DEBUG = driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
242 debug_control );
243
244 if (driQueryOptionb(&nmesa->optionCache, "no_rast")) {
245 fprintf(stderr, "disabling 3D acceleration\n");
246 FALLBACK(nmesa, NOUVEAU_FALLBACK_DISABLE, 1);
247 }
248
249 return GL_TRUE;
250 }
251
252 /* Destroy the device specific context. */
253 void nouveauDestroyContext( __DRIcontextPrivate *driContextPriv )
254 {
255 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
256
257 assert(nmesa);
258 if ( nmesa ) {
259 /* free the option cache */
260 driDestroyOptionCache (&nmesa->optionCache);
261
262 FREE( nmesa );
263 }
264
265 }
266
267
268 /* Force the context `c' to be the current context and associate with it
269 * buffer `b'.
270 */
271 GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
272 __DRIdrawablePrivate *driDrawPriv,
273 __DRIdrawablePrivate *driReadPriv )
274 {
275 if ( driContextPriv ) {
276 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
277 struct gl_framebuffer *draw_fb =
278 (struct gl_framebuffer*)driDrawPriv->driverPrivate;
279 struct gl_framebuffer *read_fb =
280 (struct gl_framebuffer*)driReadPriv->driverPrivate;
281
282 driDrawableInitVBlank(driDrawPriv, nmesa->vblank_flags, &nmesa->vblank_seq );
283 nmesa->driDrawable = driDrawPriv;
284
285 _mesa_resize_framebuffer(nmesa->glCtx, draw_fb,
286 driDrawPriv->w, driDrawPriv->h);
287 if (draw_fb != read_fb) {
288 _mesa_resize_framebuffer(nmesa->glCtx, draw_fb,
289 driReadPriv->w,
290 driReadPriv->h);
291 }
292 _mesa_make_current(nmesa->glCtx, draw_fb, read_fb);
293
294 nouveau_build_framebuffer(nmesa->glCtx,
295 driDrawPriv->driverPrivate);
296 } else {
297 _mesa_make_current( NULL, NULL, NULL );
298 }
299
300 return GL_TRUE;
301 }
302
303
304 /* Force the context `c' to be unbound from its buffer.
305 */
306 GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv )
307 {
308 return GL_TRUE;
309 }
310
311 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
312 __DRIdrawablePrivate *dPriv)
313 {
314 struct gl_framebuffer *fb;
315 nouveau_renderbuffer *src, *dst;
316 drm_clip_rect_t *box;
317 int nbox, i;
318
319 fb = (struct gl_framebuffer *)dPriv->driverPrivate;
320 dst = (nouveau_renderbuffer*)
321 fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
322 src = (nouveau_renderbuffer*)
323 fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
324
325 #ifdef ALLOW_MULTI_SUBCHANNEL
326 LOCK_HARDWARE(nmesa);
327 nbox = dPriv->numClipRects;
328 box = dPriv->pClipRects;
329
330 if (nbox) {
331 BEGIN_RING_SIZE(NvSubCtxSurf2D,
332 NV10_CONTEXT_SURFACES_2D_FORMAT, 4);
333 if (src->mesa._ActualFormat == GL_RGBA8)
334 OUT_RING (6); /* X8R8G8B8 */
335 else
336 OUT_RING (4); /* R5G6B5 */
337 OUT_RING ((dst->pitch << 16) | src->pitch);
338 OUT_RING (src->offset);
339 OUT_RING (dst->offset);
340 }
341
342 for (i=0; i<nbox; i++, box++) {
343 BEGIN_RING_SIZE(NvSubImageBlit, NV10_IMAGE_BLIT_SET_POINT, 3);
344 OUT_RING (((box->y1 - dPriv->y) << 16) |
345 (box->x1 - dPriv->x));
346 OUT_RING ((box->y1 << 16) | box->x1);
347 OUT_RING (((box->y2 - box->y1) << 16) |
348 (box->x2 - box->x1));
349 }
350
351 UNLOCK_HARDWARE(nmesa);
352 #endif
353 }
354
355 void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv)
356 {
357 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
358 nouveauContextPtr nmesa = dPriv->driContextPriv->driverPrivate;
359
360 if (nmesa->glCtx->Visual.doubleBufferMode) {
361 _mesa_notifySwapBuffers(nmesa->glCtx);
362 nouveauDoSwapBuffers(nmesa, dPriv);
363 }
364
365 }
366 }
367
368 void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
369 int x, int y, int w, int h)
370 {
371 }
372