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 "nv10_swtcl.h"
57 #include "xmlpool.h" /* for symbolic values of enum-type options */
60 int NOUVEAU_DEBUG = 0;
63 static const struct dri_debug_control debug_control[] =
68 #define need_GL_ARB_vertex_program
69 #include "extension_helper.h"
71 const struct dri_extension common_extensions[] =
76 const struct dri_extension nv10_extensions[] =
81 const struct dri_extension nv20_extensions[] =
86 const struct dri_extension nv30_extensions[] =
88 { "GL_ARB_fragment_program", NULL },
92 const struct dri_extension nv40_extensions[] =
94 /* ARB_vp can be moved to nv20/30 once the shader backend has been
95 * written for those cards.
97 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
101 const struct dri_extension nv50_extensions[] =
106 /* Create the device specific context.
108 GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
109 __DRIcontextPrivate *driContextPriv,
110 void *sharedContextPrivate )
112 GLcontext *ctx, *shareCtx;
113 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
114 struct dd_function_table functions;
115 nouveauContextPtr nmesa;
116 nouveauScreenPtr screen;
118 /* Allocate the context */
119 nmesa = (nouveauContextPtr) CALLOC( sizeof(*nmesa) );
123 nmesa->driContext = driContextPriv;
124 nmesa->driScreen = sPriv;
125 nmesa->driDrawable = NULL;
126 nmesa->hHWContext = driContextPriv->hHWContext;
127 nmesa->driHwLock = &sPriv->pSAREA->lock;
128 nmesa->driFd = sPriv->fd;
130 nmesa->screen = (nouveauScreenPtr)(sPriv->private);
131 screen=nmesa->screen;
133 /* Create the hardware context */
134 if (!nouveauDRMGetParam(nmesa, NOUVEAU_GETPARAM_FB_PHYSICAL,
137 if (!nouveauDRMGetParam(nmesa, NOUVEAU_GETPARAM_AGP_PHYSICAL,
140 if (!nouveauFifoInit(nmesa))
142 nouveauObjectInit(nmesa);
145 /* Init default driver functions then plug in our nouveau-specific functions
146 * (the texture functions are especially important)
148 _mesa_init_driver_functions( &functions );
149 nouveauDriverInitFunctions( &functions );
150 nouveauTexInitFunctions( &functions );
152 /* Allocate the Mesa context */
153 if (sharedContextPrivate)
154 shareCtx = ((nouveauContextPtr) sharedContextPrivate)->glCtx;
157 nmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
158 &functions, (void *) nmesa);
163 driContextPriv->driverPrivate = nmesa;
166 /* Parse configuration files */
167 driParseConfigFiles (&nmesa->optionCache, &screen->optionCache,
168 screen->driScreen->myNum, "nouveau");
170 nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA +
171 screen->sarea_priv_offset);
173 /* Enable any supported extensions */
174 driInitExtensions(ctx, common_extensions, GL_TRUE);
175 if (nmesa->screen->card->type >= NV_10)
176 driInitExtensions(ctx, nv10_extensions, GL_FALSE);
177 if (nmesa->screen->card->type >= NV_20)
178 driInitExtensions(ctx, nv20_extensions, GL_FALSE);
179 if (nmesa->screen->card->type >= NV_30)
180 driInitExtensions(ctx, nv30_extensions, GL_FALSE);
181 if (nmesa->screen->card->type >= NV_40)
182 driInitExtensions(ctx, nv40_extensions, GL_FALSE);
183 if (nmesa->screen->card->type >= NV_50)
184 driInitExtensions(ctx, nv50_extensions, GL_FALSE);
186 nmesa->current_primitive = -1;
188 nouveauShaderInitFuncs(ctx);
189 /* Install Mesa's fixed-function shader support */
190 if (nmesa->screen->card->type >= NV_40) {
191 ctx->_MaintainTnlProgram = GL_TRUE;
192 ctx->_MaintainTexEnvProgram = GL_TRUE;
195 /* Initialize the swrast */
196 _swrast_CreateContext( ctx );
197 _ac_CreateContext( ctx );
198 _tnl_CreateContext( ctx );
199 _swsetup_CreateContext( ctx );
201 _math_matrix_ctr(&nmesa->viewport);
203 nouveauDDInitStateFuncs( ctx );
204 nouveauSpanInitFunctions( ctx );
205 nouveauDDInitState( nmesa );
206 switch(nmesa->screen->card->type)
209 //nv03TriInitFunctions( ctx );
213 //nv04TriInitFunctions( ctx );
222 nv10TriInitFunctions( ctx );
226 nmesa->hw_func.InitCard(nmesa);
227 nouveauInitState(ctx);
229 driContextPriv->driverPrivate = (void *)nmesa;
231 NOUVEAU_DEBUG = driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
234 if (driQueryOptionb(&nmesa->optionCache, "no_rast")) {
235 fprintf(stderr, "disabling 3D acceleration\n");
236 FALLBACK(nmesa, NOUVEAU_FALLBACK_DISABLE, 1);
242 /* Destroy the device specific context. */
243 void nouveauDestroyContext( __DRIcontextPrivate *driContextPriv )
245 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
249 /* free the option cache */
250 driDestroyOptionCache (&nmesa->optionCache);
258 /* Force the context `c' to be the current context and associate with it
261 GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
262 __DRIdrawablePrivate *driDrawPriv,
263 __DRIdrawablePrivate *driReadPriv )
265 if ( driContextPriv ) {
266 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
267 struct gl_framebuffer *draw_fb =
268 (struct gl_framebuffer*)driDrawPriv->driverPrivate;
269 struct gl_framebuffer *read_fb =
270 (struct gl_framebuffer*)driReadPriv->driverPrivate;
272 driDrawableInitVBlank(driDrawPriv, nmesa->vblank_flags, &nmesa->vblank_seq );
273 nmesa->driDrawable = driDrawPriv;
275 _mesa_resize_framebuffer(nmesa->glCtx, draw_fb,
276 driDrawPriv->w, driDrawPriv->h);
277 if (draw_fb != read_fb) {
278 _mesa_resize_framebuffer(nmesa->glCtx, draw_fb,
282 _mesa_make_current(nmesa->glCtx, draw_fb, read_fb);
284 nouveau_build_framebuffer(nmesa->glCtx,
285 driDrawPriv->driverPrivate);
287 _mesa_make_current( NULL, NULL, NULL );
294 /* Force the context `c' to be unbound from its buffer.
296 GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv )
301 static void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
302 __DRIdrawablePrivate *dPriv)
304 struct gl_framebuffer *fb;
305 nouveau_renderbuffer *src, *dst;
307 fb = (struct gl_framebuffer *)dPriv->driverPrivate;
308 dst = (nouveau_renderbuffer*)
309 fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
310 src = (nouveau_renderbuffer*)
311 fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
313 #ifdef ALLOW_MULTI_SUBCHANNEL
314 /* Ignore this.. it's a hack to test double-buffering, and not how
315 * SwapBuffers should look :)
317 BEGIN_RING_SIZE(NvSubCtxSurf2D, NV10_CONTEXT_SURFACES_2D_FORMAT, 4);
318 OUT_RING (6); /* X8R8G8B8 */
319 OUT_RING ((dst->pitch << 16) | src->pitch);
320 OUT_RING (src->offset);
321 OUT_RING (dst->offset);
323 BEGIN_RING_SIZE(NvSubImageBlit, NV10_IMAGE_BLIT_SET_POINT, 3);
324 OUT_RING ((0 << 16) | 0); /* src point */
325 OUT_RING ((0 << 16) | 0); /* dst point */
326 OUT_RING ((fb->Height << 16) | fb->Width); /* width/height */
330 void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv)
332 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
333 nouveauContextPtr nmesa = dPriv->driContextPriv->driverPrivate;
335 if (nmesa->glCtx->Visual.doubleBufferMode) {
336 _mesa_notifySwapBuffers(nmesa->glCtx);
337 nouveauDoSwapBuffers(nmesa, dPriv);
343 void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
344 int x, int y, int w, int h)