All elements of pre-DRI_NEW_INTERFACE_ONLY are removed. This allows
[mesa.git] / src / mesa / drivers / dri / mga / mga_xmesa.c
index 6312997ce642676d45b0f06fbec2b532f5adfce7..aaa4e25c10382e2ce9093d8ae304a5d9c99a0493 100644 (file)
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file mga_xmesa.c
+ * MGA screen and context initialization / creation code.
  *
- * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
+ * \author Keith Whitwell <keith@tungstengraphics.com>
  */
 
 #include <stdlib.h>
+#include <stdint.h>
 #include "drm.h"
 #include "mga_drm.h"
 #include "mga_xmesa.h"
 
 #include "GL/internal/dri_interface.h"
 
+#define need_GL_ARB_multisample
+#define need_GL_ARB_texture_compression
+#define need_GL_ARB_vertex_program
+#define need_GL_EXT_fog_coord
+#define need_GL_EXT_multi_draw_arrays
+#define need_GL_EXT_secondary_color
+#if 0
+#define need_GL_EXT_paletted_texture
+#endif
+#define need_GL_NV_vertex_program
+#include "extension_helper.h"
+
 /* MGA configuration
  */
 #include "xmlpool.h"
@@ -81,12 +98,13 @@ DRI_CONF_BEGIN
         DRI_CONF_ARB_VERTEX_PROGRAM(true)
         DRI_CONF_NV_VERTEX_PROGRAM(true)
     DRI_CONF_SECTION_END
+    DRI_CONF_SECTION_DEBUG
+        DRI_CONF_NO_RAST(false)
+    DRI_CONF_SECTION_END
 DRI_CONF_END;
-static const GLuint __driNConfigOptions = 5;
+static const GLuint __driNConfigOptions = 6;
 
-#ifdef USE_NEW_INTERFACE
 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
-#endif /* USE_NEW_INTERFACE */
 
 #ifndef MGA_DEBUG
 int MGA_DEBUG = 0;
@@ -94,7 +112,6 @@ int MGA_DEBUG = 0;
 
 static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );
 
-#ifdef USE_NEW_INTERFACE
 static __GLcontextModes *
 mgaFillInModes( unsigned pixel_bits, unsigned depth_bits,
                unsigned stencil_bits, GLboolean have_back_buffer )
@@ -174,7 +191,6 @@ mgaFillInModes( unsigned pixel_bits, unsigned depth_bits,
 
     return modes;
 }
-#endif /* USE_NEW_INTERFACE */
 
 
 static GLboolean
@@ -182,8 +198,15 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
 {
    mgaScreenPrivate *mgaScreen;
    MGADRIPtr         serverInfo = (MGADRIPtr)sPriv->pDevPriv;
+   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
+       (PFNGLXSCRENABLEEXTENSIONPROC) glXGetProcAddress( (const GLubyte *) "__glXScrEnableExtension" );
+   void * const psc = sPriv->psc->screenConfigs;
 
 
+   if ( glx_enable_extension == NULL ) {
+      return GL_FALSE;
+   }
+
    /* Allocate the private area */
    mgaScreen = (mgaScreenPrivate *)MALLOC(sizeof(mgaScreenPrivate));
    if (!mgaScreen) {
@@ -211,31 +234,12 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
            return GL_FALSE;
       }
    }
-   
-   mgaScreen->linecomp_sane = (sPriv->ddxMajor > 1) || (sPriv->ddxMinor > 1)
-       || ((sPriv->ddxMinor == 1) && (sPriv->ddxPatch > 0));
-
-   if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
-      PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
-          (PFNGLXSCRENABLEEXTENSIONPROC) glXGetProcAddress( (const GLubyte *) "__glXScrEnableExtension" );
-      void * const psc = sPriv->psc->screenConfigs;
-
-      if ( glx_enable_extension != NULL ) {
-        if ( mgaScreen->linecomp_sane ) {
-           (*glx_enable_extension)( psc, "GLX_SGI_swap_control" );
-           (*glx_enable_extension)( psc, "GLX_SGI_video_sync" );
-           (*glx_enable_extension)( psc, "GLX_MESA_swap_control" );
-        }
-
-        (*glx_enable_extension)( psc, "GLX_SGI_make_current_read" );
-        (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" );
-
-        if ( driCompareGLXAPIVersion( 20030915 ) >= 0 ) {
-           (*glx_enable_extension)( psc, "GLX_SGIX_fbconfig" );
-           (*glx_enable_extension)( psc, "GLX_OML_swap_method" );
-        }
-      }
-   }
+
+   (*glx_enable_extension)( psc, "GLX_MESA_swap_control" );
+   (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" );
+   (*glx_enable_extension)( psc, "GLX_SGI_make_current_read" );
+   (*glx_enable_extension)( psc, "GLX_SGI_swap_control" );
+   (*glx_enable_extension)( psc, "GLX_SGI_video_sync" );
 
    if (serverInfo->chipset != MGA_CARD_TYPE_G200 &&
        serverInfo->chipset != MGA_CARD_TYPE_G400) {
@@ -247,9 +251,6 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
 
 
    mgaScreen->chipset = serverInfo->chipset;
-   mgaScreen->width = serverInfo->width;
-   mgaScreen->height = serverInfo->height;
-   mgaScreen->mem = serverInfo->mem;
    mgaScreen->cpp = serverInfo->cpp;
 
    mgaScreen->agpMode = serverInfo->agpMode;
@@ -261,37 +262,35 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
    mgaScreen->depthOffset = serverInfo->depthOffset;
    mgaScreen->depthPitch  =  serverInfo->depthPitch;
 
-   mgaScreen->mmio.handle = serverInfo->registers.handle;
-   mgaScreen->mmio.size = serverInfo->registers.size;
-   if ( drmMap( sPriv->fd,
-               mgaScreen->mmio.handle, mgaScreen->mmio.size,
-               &mgaScreen->mmio.map ) < 0 ) {
-      FREE( mgaScreen );
-      sPriv->private = NULL;
-      __driUtilMessage( "Couldn't map MMIO registers" );
-      return GL_FALSE;
-   }
 
-   mgaScreen->primary.handle = serverInfo->primary.handle;
-   mgaScreen->primary.size = serverInfo->primary.size;
-   mgaScreen->buffers.handle = serverInfo->buffers.handle;
-   mgaScreen->buffers.size = serverInfo->buffers.size;
+   /* The only reason that the MMIO region needs to be accessable and the
+    * primary DMA region base address needs to be known is so that the driver
+    * can busy wait for certain DMA operations to complete (see
+    * mgaWaitForFrameCompletion in mgaioctl.c).
+    *
+    * Starting with MGA DRM version 3.2, these are completely unneeded as
+    * there is a new, in-kernel mechanism for handling the wait.
+    */
 
-#if 0
-   mgaScreen->agp.handle = serverInfo->agp;
-   mgaScreen->agp.size = serverInfo->agpSize;
-
-   if (drmMap(sPriv->fd,
-             mgaScreen->agp.handle,
-             mgaScreen->agp.size,
-             (drmAddress *)&mgaScreen->agp.map) != 0)
-   {
-      Xfree(mgaScreen);
-      sPriv->private = NULL;
-      __driUtilMessage("Couldn't map agp region");
-      return GL_FALSE;
+   if (mgaScreen->sPriv->drmMinor < 2) {
+      mgaScreen->mmio.handle = serverInfo->registers.handle;
+      mgaScreen->mmio.size = serverInfo->registers.size;
+      if ( drmMap( sPriv->fd,
+                  mgaScreen->mmio.handle, mgaScreen->mmio.size,
+                  &mgaScreen->mmio.map ) < 0 ) {
+        FREE( mgaScreen );
+        sPriv->private = NULL;
+        __driUtilMessage( "Couldn't map MMIO registers" );
+        return GL_FALSE;
+      }
+
+      mgaScreen->primary.handle = serverInfo->primary.handle;
+      mgaScreen->primary.size = serverInfo->primary.size;
+   }
+   else {
+      (void) memset( & mgaScreen->primary, 0, sizeof( mgaScreen->primary ) );
+      (void) memset( & mgaScreen->mmio, 0, sizeof( mgaScreen->mmio ) );
    }
-#endif
 
    mgaScreen->textureOffset[MGA_CARD_HEAP] = serverInfo->textureOffset;
    mgaScreen->textureOffset[MGA_AGP_HEAP] = (serverInfo->agpTextureOffset |
@@ -300,38 +299,34 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
    mgaScreen->textureSize[MGA_CARD_HEAP] = serverInfo->textureSize;
    mgaScreen->textureSize[MGA_AGP_HEAP] = serverInfo->agpTextureSize;
 
-   mgaScreen->logTextureGranularity[MGA_CARD_HEAP] =
-      serverInfo->logTextureGranularity;
-   mgaScreen->logTextureGranularity[MGA_AGP_HEAP] =
-      serverInfo->logAgpTextureGranularity;
+   
+   /* The texVirtual array stores the base addresses in the CPU's address
+    * space of the texture memory pools.  The base address of the on-card
+    * memory pool is calculated as an offset of the base of video memory.  The
+    * AGP texture pool has to be mapped into the processes address space by
+    * the DRM. 
+    */
 
    mgaScreen->texVirtual[MGA_CARD_HEAP] = (char *)(mgaScreen->sPriv->pFB +
                                           serverInfo->textureOffset);
-   if (drmMap(sPriv->fd,
-              serverInfo->agpTextureOffset,
-              serverInfo->agpTextureSize,
-              (drmAddress *)&mgaScreen->texVirtual[MGA_AGP_HEAP]) != 0)
-   {
-      FREE(mgaScreen);
-      sPriv->private = NULL;
-      __driUtilMessage("Couldn't map agptexture region");
-      return GL_FALSE;
-   }
 
-#if 0
-   mgaScreen->texVirtual[MGA_AGP_HEAP] = (mgaScreen->agp.map +
-                                         serverInfo->agpTextureOffset);
-#endif
+   if ( serverInfo->agpTextureSize > 0 ) {
+      if (drmMap(sPriv->fd, serverInfo->agpTextureOffset,
+                serverInfo->agpTextureSize,
+                (drmAddress *)&mgaScreen->texVirtual[MGA_AGP_HEAP]) != 0) {
+        FREE(mgaScreen);
+        sPriv->private = NULL;
+        __driUtilMessage("Couldn't map agptexture region");
+        return GL_FALSE;
+      }
+   }
 
-   mgaScreen->mAccess = serverInfo->mAccess;
 
    /* For calculating setupdma addresses.
     */
-   mgaScreen->dmaOffset = serverInfo->buffers.handle;
 
    mgaScreen->bufs = drmMapBufs(sPriv->fd);
    if (!mgaScreen->bufs) {
-      /*drmUnmap(mgaScreen->agp_tex.map, mgaScreen->agp_tex.size);*/
       FREE(mgaScreen);
       sPriv->private = NULL;
       __driUtilMessage("Couldn't map dma buffers");
@@ -357,7 +352,6 @@ mgaDestroyScreen(__DRIscreenPrivate *sPriv)
 
    drmUnmapBufs(mgaScreen->bufs);
 
-   /*drmUnmap(mgaScreen->agp_tex.map, mgaScreen->agp_tex.size);*/
 
    /* free all option information */
    driDestroyOptionInfo (&mgaScreen->optionCache);
@@ -388,39 +382,47 @@ static const struct tnl_pipeline_stage *mga_pipeline[] = {
 };
 
 
-static const char * const g400_extensions[] =
+static const struct dri_extension g400_extensions[] =
 {
-   "GL_ARB_multitexture",
-   "GL_ARB_texture_env_add",
-   "GL_ARB_texture_env_combine",
-   "GL_ARB_texture_env_crossbar",
-   "GL_EXT_texture_env_combine",
-   "GL_EXT_texture_edge_clamp",
-   "GL_ATI_texture_env_combine3",
-#if defined (MESA_packed_depth_stencil)
-   "GL_MESA_packed_depth_stencil",
-#endif
-   NULL
+   { "GL_ARB_multitexture",           NULL },
+   { "GL_ARB_texture_env_add",        NULL },
+   { "GL_ARB_texture_env_combine",    NULL },
+   { "GL_ARB_texture_env_crossbar",   NULL },
+   { "GL_EXT_texture_env_combine",    NULL },
+   { "GL_EXT_texture_edge_clamp",     NULL },
+   { "GL_ATI_texture_env_combine3",   NULL },
+   { NULL,                            NULL }
 };
 
-static const char * const card_extensions[] =
+static const struct dri_extension card_extensions[] =
 {
-   "GL_ARB_multisample",
-   "GL_ARB_texture_compression",
-   "GL_ARB_texture_rectangle",
-   "GL_EXT_blend_logic_op",
-   "GL_EXT_fog_coord",
-   "GL_EXT_multi_draw_arrays",
+   { "GL_ARB_multisample",            GL_ARB_multisample_functions },
+   { "GL_ARB_texture_compression",    GL_ARB_texture_compression_functions },
+   { "GL_ARB_texture_rectangle",      NULL },
+   { "GL_EXT_blend_logic_op",         NULL },
+   { "GL_EXT_fog_coord",              GL_EXT_fog_coord_functions },
+   { "GL_EXT_multi_draw_arrays",      GL_EXT_multi_draw_arrays_functions },
    /* paletted_textures currently doesn't work, but we could fix them later */
-#if 0
-   "GL_EXT_shared_texture_palette",
-   "GL_EXT_paletted_texture",
+#if defined( need_GL_EXT_paletted_texture )
+   { "GL_EXT_shared_texture_palette", NULL },
+   { "GL_EXT_paletted_texture",       GL_EXT_paletted_texture_functions },
 #endif
-   "GL_EXT_secondary_color",
-   "GL_EXT_stencil_wrap",
-   "GL_MESA_ycbcr_texture",
-   "GL_SGIS_generate_mipmap",
-   NULL
+   { "GL_EXT_secondary_color",        GL_EXT_secondary_color_functions },
+   { "GL_EXT_stencil_wrap",           NULL },
+   { "GL_MESA_ycbcr_texture",         NULL },
+   { "GL_SGIS_generate_mipmap",       NULL },
+   { NULL,                            NULL }
+};
+
+static const struct dri_extension ARB_vp_extension[] = {
+   { "GL_ARB_vertex_program",         GL_ARB_vertex_program_functions },
+   { NULL,                            NULL }
+};
+
+static const struct dri_extension NV_vp_extensions[] = {
+   { "GL_NV_vertex_program",          GL_NV_vertex_program_functions },
+   { "GL_NV_vertex_program1_1",       NULL },
+   { NULL,                            NULL }
 };
 
 static const struct dri_debug_control debug_control[] =
@@ -625,12 +627,11 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
    }
 
    if ( driQueryOptionb( &mmesa->optionCache, "arb_vertex_program" ) ) {
-      _mesa_enable_extension( ctx, "GL_ARB_vertex_program" );
+      driInitSingleExtension( ctx, ARB_vp_extension );
    }
    
    if ( driQueryOptionb( &mmesa->optionCache, "nv_vertex_program" ) ) {
-      _mesa_enable_extension( ctx, "GL_NV_vertex_program" );
-      _mesa_enable_extension( ctx, "GL_NV_vertex_program1_1" );
+      driInitExtensions( ctx, NV_vp_extensions, GL_FALSE );
    }
 
        
@@ -650,8 +651,7 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
                                    debug_control );
 #endif
 
-   mmesa->vblank_flags = ((mmesa->mgaScreen->irq == 0) 
-                         || !mmesa->mgaScreen->linecomp_sane)
+   mmesa->vblank_flags = (mmesa->mgaScreen->irq == 0)
        ? VBLANK_FLAG_NO_IRQ : driGetDefaultVBlankFlags(&mmesa->optionCache);
 
    mmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" );
@@ -661,6 +661,11 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
 
    (*mmesa->get_ust)( & mmesa->swap_ust );
 
+   if (driQueryOptionb(&mmesa->optionCache, "no_rast")) {
+      fprintf(stderr, "disabling 3D acceleration\n");
+      FALLBACK(mmesa->glCtx, MGA_FALLBACK_DISABLE, 1);
+   }
+
    return GL_TRUE;
 }
 
@@ -912,8 +917,6 @@ void mgaGetLock( mgaContextPtr mmesa, GLuint flags )
    for ( i = 0 ; i < mmesa->nr_heaps ; i++ ) {
       DRI_AGE_TEXTURES( mmesa->texture_heaps[ i ] );
    }
-
-   sarea->last_quiescent = -1; /* just kill it for now */
 }
 
 
@@ -935,22 +938,6 @@ static const struct __DriverAPIRec mgaAPI = {
 };
 
 
-/*
- * This is the bootstrap function for the driver.
- * The __driCreateScreen name is the symbol that libGL.so fetches.
- * Return:  pointer to a __DRIscreenPrivate.
- */
-#if !defined(DRI_NEW_INTERFACE_ONLY)
-void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
-                        int numConfigs, __GLXvisualConfig *config)
-{
-   __DRIscreenPrivate *psp;
-   psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &mgaAPI);
-   return (void *) psp;
-}
-#endif /* !defined(DRI_NEW_INTERFACE_ONLY) */
-
-
 /**
  * This is the bootstrap function for the driver.  libGL supplies all of the
  * requisite information about the system, and the driver initializes itself.
@@ -961,9 +948,8 @@ void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
  * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on 
  *         failure.
  */
-#ifdef USE_NEW_INTERFACE
 PUBLIC
-void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
+void * __driCreateNewScreen_20050722( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
                             const __GLcontextModes * modes,
                             const __DRIversion * ddx_version,
                             const __DRIversion * dri_version,
@@ -975,7 +961,7 @@ void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc
                             
 {
    __DRIscreenPrivate *psp;
-   static const __DRIversion ddx_expected = { 1, 0, 0 };
+   static const __DRIversion ddx_expected = { 1, 1, 1 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 3, 0, 0 };
 
@@ -1004,7 +990,6 @@ void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc
 
    return (void *) psp;
 }
-#endif /* USE_NEW_INTERFACE */
 
 
 /**