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
[] =
69 #define need_GL_ARB_vertex_program
70 #include "extension_helper.h"
72 const struct dri_extension common_extensions
[] =
77 const struct dri_extension nv10_extensions
[] =
82 const struct dri_extension nv20_extensions
[] =
87 const struct dri_extension nv30_extensions
[] =
89 { "GL_ARB_fragment_program", NULL
},
93 const struct dri_extension nv40_extensions
[] =
95 /* ARB_vp can be moved to nv20/30 once the shader backend has been
96 * written for those cards.
98 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
102 const struct dri_extension nv50_extensions
[] =
107 /* Create the device specific context.
109 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
110 __DRIcontextPrivate
*driContextPriv
,
111 void *sharedContextPrivate
)
113 GLcontext
*ctx
, *shareCtx
;
114 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
115 struct dd_function_table functions
;
116 nouveauContextPtr nmesa
;
117 nouveauScreenPtr screen
;
119 /* Allocate the context */
120 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
124 nmesa
->driContext
= driContextPriv
;
125 nmesa
->driScreen
= sPriv
;
126 nmesa
->driDrawable
= NULL
;
127 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
128 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
129 nmesa
->driFd
= sPriv
->fd
;
131 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
132 screen
=nmesa
->screen
;
134 /* Create the hardware context */
135 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_FB_PHYSICAL
,
138 if (!nouveauDRMGetParam(nmesa
, NOUVEAU_GETPARAM_AGP_PHYSICAL
,
141 if (!nouveauFifoInit(nmesa
))
143 nouveauObjectInit(nmesa
);
146 /* Init default driver functions then plug in our nouveau-specific functions
147 * (the texture functions are especially important)
149 _mesa_init_driver_functions( &functions
);
150 nouveauDriverInitFunctions( &functions
);
151 nouveauTexInitFunctions( &functions
);
153 /* Allocate the Mesa context */
154 if (sharedContextPrivate
)
155 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
158 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
159 &functions
, (void *) nmesa
);
164 driContextPriv
->driverPrivate
= nmesa
;
167 /* Parse configuration files */
168 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
169 screen
->driScreen
->myNum
, "nouveau");
171 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
172 screen
->sarea_priv_offset
);
174 /* Enable any supported extensions */
175 driInitExtensions(ctx
, common_extensions
, GL_TRUE
);
176 if (nmesa
->screen
->card
->type
>= NV_10
)
177 driInitExtensions(ctx
, nv10_extensions
, GL_FALSE
);
178 if (nmesa
->screen
->card
->type
>= NV_20
)
179 driInitExtensions(ctx
, nv20_extensions
, GL_FALSE
);
180 if (nmesa
->screen
->card
->type
>= NV_30
)
181 driInitExtensions(ctx
, nv30_extensions
, GL_FALSE
);
182 if (nmesa
->screen
->card
->type
>= NV_40
)
183 driInitExtensions(ctx
, nv40_extensions
, GL_FALSE
);
184 if (nmesa
->screen
->card
->type
>= NV_50
)
185 driInitExtensions(ctx
, nv50_extensions
, GL_FALSE
);
187 nmesa
->current_primitive
= -1;
189 nouveauShaderInitFuncs(ctx
);
190 /* Install Mesa's fixed-function shader support */
191 if (nmesa
->screen
->card
->type
>= NV_40
) {
192 ctx
->_MaintainTnlProgram
= GL_TRUE
;
193 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
196 /* Initialize the swrast */
197 _swrast_CreateContext( ctx
);
198 _ac_CreateContext( ctx
);
199 _tnl_CreateContext( ctx
);
200 _swsetup_CreateContext( ctx
);
202 _math_matrix_ctr(&nmesa
->viewport
);
204 nouveauDDInitStateFuncs( ctx
);
205 nouveauSpanInitFunctions( ctx
);
206 nouveauDDInitState( nmesa
);
207 switch(nmesa
->screen
->card
->type
)
210 //nv03TriInitFunctions( ctx );
214 //nv04TriInitFunctions( ctx );
223 nv10TriInitFunctions( ctx
);
227 nmesa
->hw_func
.InitCard(nmesa
);
228 nouveauInitState(ctx
);
230 driContextPriv
->driverPrivate
= (void *)nmesa
;
232 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
235 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
236 fprintf(stderr
, "disabling 3D acceleration\n");
237 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
243 /* Destroy the device specific context. */
244 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
246 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
250 /* free the option cache */
251 driDestroyOptionCache (&nmesa
->optionCache
);
259 /* Force the context `c' to be the current context and associate with it
262 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
263 __DRIdrawablePrivate
*driDrawPriv
,
264 __DRIdrawablePrivate
*driReadPriv
)
266 if ( driContextPriv
) {
267 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
268 struct gl_framebuffer
*draw_fb
=
269 (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
270 struct gl_framebuffer
*read_fb
=
271 (struct gl_framebuffer
*)driReadPriv
->driverPrivate
;
273 driDrawableInitVBlank(driDrawPriv
, nmesa
->vblank_flags
, &nmesa
->vblank_seq
);
274 nmesa
->driDrawable
= driDrawPriv
;
276 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
277 driDrawPriv
->w
, driDrawPriv
->h
);
278 if (draw_fb
!= read_fb
) {
279 _mesa_resize_framebuffer(nmesa
->glCtx
, draw_fb
,
283 _mesa_make_current(nmesa
->glCtx
, draw_fb
, read_fb
);
285 nouveau_build_framebuffer(nmesa
->glCtx
,
286 driDrawPriv
->driverPrivate
);
288 _mesa_make_current( NULL
, NULL
, NULL
);
295 /* Force the context `c' to be unbound from its buffer.
297 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
302 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa
,
303 __DRIdrawablePrivate
*dPriv
)
305 struct gl_framebuffer
*fb
;
306 nouveau_renderbuffer
*src
, *dst
;
307 drm_clip_rect_t
*box
;
310 fb
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
311 dst
= (nouveau_renderbuffer
*)
312 fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
313 src
= (nouveau_renderbuffer
*)
314 fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
316 #ifdef ALLOW_MULTI_SUBCHANNEL
317 LOCK_HARDWARE(nmesa
);
318 nbox
= dPriv
->numClipRects
;
319 box
= dPriv
->pClipRects
;
322 BEGIN_RING_SIZE(NvSubCtxSurf2D
,
323 NV10_CONTEXT_SURFACES_2D_FORMAT
, 4);
324 OUT_RING (6); /* X8R8G8B8 */
325 OUT_RING ((dst
->pitch
<< 16) | src
->pitch
);
326 OUT_RING (src
->offset
);
327 OUT_RING (dst
->offset
);
330 for (i
=0; i
<nbox
; i
++, box
++) {
331 BEGIN_RING_SIZE(NvSubImageBlit
, NV10_IMAGE_BLIT_SET_POINT
, 3);
332 OUT_RING (((box
->y1
- dPriv
->y
) << 16) |
333 (box
->x1
- dPriv
->x
));
334 OUT_RING ((box
->y1
<< 16) | box
->x1
);
335 OUT_RING (((box
->y2
- box
->y1
) << 16) |
336 (box
->x2
- box
->x1
));
339 UNLOCK_HARDWARE(nmesa
);
343 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
345 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
346 nouveauContextPtr nmesa
= dPriv
->driContextPriv
->driverPrivate
;
348 if (nmesa
->glCtx
->Visual
.doubleBufferMode
) {
349 _mesa_notifySwapBuffers(nmesa
->glCtx
);
350 nouveauDoSwapBuffers(nmesa
, dPriv
);
356 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
357 int x
, int y
, int w
, int h
)