nouveau_context.c revision 6464787bfd1888ea93ebfe53528ceac3c27c993f
1/************************************************************************** 2 3Copyright 2006 Stephane Marchesin 4All Rights Reserved. 5 6Permission is hereby granted, free of charge, to any person obtaining a 7copy of this software and associated documentation files (the "Software"), 8to deal in the Software without restriction, including without limitation 9on the rights to use, copy, modify, merge, publish, distribute, sub 10license, and/or sell copies of the Software, and to permit persons to whom 11the Software is furnished to do so, subject to the following conditions: 12 13The above copyright notice and this permission notice (including the next 14paragraph) shall be included in all copies or substantial portions of the 15Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM, 21DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 23USE 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 39#include "drivers/common/driverfuncs.h" 40 41#include "nouveau_context.h" 42#include "nouveau_driver.h" 43//#include "nouveau_state.h" 44#include "nouveau_span.h" 45#include "nouveau_object.h" 46#include "nouveau_fifo.h" 47#include "nouveau_tex.h" 48#include "nv10_swtcl.h" 49 50#include "vblank.h" 51#include "utils.h" 52#include "texmem.h" 53#include "xmlpool.h" /* for symbolic values of enum-type options */ 54 55#ifndef NOUVEAU_DEBUG 56int NOUVEAU_DEBUG = 0; 57#endif 58 59static const struct dri_debug_control debug_control[] = 60{ 61 { NULL, 0 } 62}; 63 64/* Create the device specific context. 65 */ 66GLboolean nouveauCreateContext( const __GLcontextModes *glVisual, 67 __DRIcontextPrivate *driContextPriv, 68 void *sharedContextPrivate ) 69{ 70 GLcontext *ctx, *shareCtx; 71 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; 72 struct dd_function_table functions; 73 nouveauContextPtr nmesa; 74 nouveauScreenPtr screen; 75 76 /* Allocate the context */ 77 nmesa = (nouveauContextPtr) CALLOC( sizeof(*nmesa) ); 78 if ( !nmesa ) 79 return GL_FALSE; 80 81 /* Create the hardware context */ 82 if (!nouveauFifoInit(nmesa)) 83 return GL_FALSE; 84 nouveauObjectInit(nmesa); 85 86 /* Init default driver functions then plug in our nouveau-specific functions 87 * (the texture functions are especially important) 88 */ 89 _mesa_init_driver_functions( &functions ); 90 nouveauDriverInitFunctions( &functions ); 91 nouveauTexInitFunctions( &functions ); 92 93 /* Allocate the Mesa context */ 94 if (sharedContextPrivate) 95 shareCtx = ((nouveauContextPtr) sharedContextPrivate)->glCtx; 96 else 97 shareCtx = NULL; 98 nmesa->glCtx = _mesa_create_context(glVisual, shareCtx, 99 &functions, (void *) nmesa); 100 if (!nmesa->glCtx) { 101 FREE(nmesa); 102 return GL_FALSE; 103 } 104 driContextPriv->driverPrivate = nmesa; 105 ctx = nmesa->glCtx; 106 107 nmesa->driContext = driContextPriv; 108 nmesa->driScreen = sPriv; 109 nmesa->driDrawable = NULL; 110 nmesa->hHWContext = driContextPriv->hHWContext; 111 nmesa->driHwLock = &sPriv->pSAREA->lock; 112 nmesa->driFd = sPriv->fd; 113 114 nmesa->screen = (nouveauScreenPtr)(sPriv->private); 115 screen=nmesa->screen; 116 117 /* Parse configuration files */ 118 driParseConfigFiles (&nmesa->optionCache, &screen->optionCache, 119 screen->driScreen->myNum, "nouveau"); 120 121 nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA + 122 screen->sarea_priv_offset); 123 124 125 nmesa->current_primitive = -1; 126 127 /* Initialize the swrast */ 128 _swrast_CreateContext( ctx ); 129 _ac_CreateContext( ctx ); 130 _tnl_CreateContext( ctx ); 131 _swsetup_CreateContext( ctx ); 132 133 switch(nmesa->screen->card->type) 134 { 135 case NV_03: 136 //nv03TriInitFunctions( ctx ); 137 break; 138 case NV_04: 139 case NV_05: 140 //nv04TriInitFunctions( ctx ); 141 break; 142 case NV_10: 143 case NV_20: 144 case NV_30: 145 case NV_40: 146 case G_70: 147 default: 148 nv10TriInitFunctions( ctx ); 149 break; 150 } 151 nouveauDDInitStateFuncs( ctx ); 152 nouveauSpanInitFunctions( ctx ); 153 nouveauDDInitState( nmesa ); 154 155 driContextPriv->driverPrivate = (void *)nmesa; 156 157 NOUVEAU_DEBUG = driParseDebugString( getenv( "NOUVEAU_DEBUG" ), 158 debug_control ); 159 160 if (driQueryOptionb(&nmesa->optionCache, "no_rast")) { 161 fprintf(stderr, "disabling 3D acceleration\n"); 162 FALLBACK(nmesa, NOUVEAU_FALLBACK_DISABLE, 1); 163 } 164 165 return GL_TRUE; 166} 167 168/* Destroy the device specific context. */ 169void nouveauDestroyContext( __DRIcontextPrivate *driContextPriv ) 170{ 171 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate; 172 173 assert(nmesa); 174 if ( nmesa ) { 175 /* free the option cache */ 176 driDestroyOptionCache (&nmesa->optionCache); 177 178 FREE( nmesa ); 179 } 180 181} 182 183 184/* Force the context `c' to be the current context and associate with it 185 * buffer `b'. 186 */ 187GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv, 188 __DRIdrawablePrivate *driDrawPriv, 189 __DRIdrawablePrivate *driReadPriv ) 190{ 191 if ( driContextPriv ) { 192 GET_CURRENT_CONTEXT(ctx); 193 nouveauContextPtr oldNOUVEAUCtx = ctx ? NOUVEAU_CONTEXT(ctx) : NULL; 194 nouveauContextPtr newNOUVEAUCtx = (nouveauContextPtr) driContextPriv->driverPrivate; 195 196 driDrawableInitVBlank(driDrawPriv, newNOUVEAUCtx->vblank_flags, &newNOUVEAUCtx->vblank_seq ); 197 newNOUVEAUCtx->driDrawable = driDrawPriv; 198 199 _mesa_make_current( newNOUVEAUCtx->glCtx, 200 (GLframebuffer *) driDrawPriv->driverPrivate, 201 (GLframebuffer *) driReadPriv->driverPrivate ); 202 203 } else { 204 _mesa_make_current( NULL, NULL, NULL ); 205 } 206 207 return GL_TRUE; 208} 209 210 211/* Force the context `c' to be unbound from its buffer. 212 */ 213GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv ) 214{ 215 return GL_TRUE; 216} 217