Initial pull of code from r6xx-r7xx-support branch
[mesa.git] / src / mesa / drivers / dri / common / utils.c
index 431c26a19d8bcfd7b5c12f478b312cac39c32ea9..66f277c10b25f742e7d1ad2111c5c27565279b0f 100644 (file)
 
 #include <string.h>
 #include <stdlib.h>
-#include "mtypes.h"
-#include "extensions.h"
+#include "main/mtypes.h"
+#include "main/cpuinfo.h"
+#include "main/extensions.h"
+#include "glapi/dispatch.h"
 #include "utils.h"
-#include "dispatch.h"
 
-int driDispatchRemapTable[ driDispatchRemapTable_size ];
 
-#if defined(USE_X86_ASM)
-#include "x86/common_x86_asm.h"
-#endif
+int driDispatchRemapTable[ driDispatchRemapTable_size ];
 
-#if defined(USE_PPC_ASM)
-#include "ppc/common_ppc_features.h"
-#endif
 
 unsigned
 driParseDebugString( const char * debug, 
@@ -93,12 +88,8 @@ unsigned
 driGetRendererString( char * buffer, const char * hardware_name,
                      const char * driver_date, GLuint agp_mode )
 {
-#define MAX_INFO   4
-   const char * cpu[MAX_INFO];
-   unsigned   next = 0;
-   unsigned   i;
-   unsigned   offset;
-
+   unsigned offset;
+   char *cpu;
 
    offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date );
 
@@ -118,59 +109,10 @@ driGetRendererString( char * buffer, const char * hardware_name,
 
    /* Append any CPU-specific information.
     */
-#ifdef USE_X86_ASM
-   if ( _mesa_x86_cpu_features ) {
-      cpu[next] = " x86";
-      next++;
-   }
-# ifdef USE_MMX_ASM
-   if ( cpu_has_mmx ) {
-      cpu[next] = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
-      next++;
-   }
-# endif
-# ifdef USE_3DNOW_ASM
-   if ( cpu_has_3dnow ) {
-      cpu[next] = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
-      next++;
-   }
-# endif
-# ifdef USE_SSE_ASM
-   if ( cpu_has_xmm ) {
-      cpu[next] = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
-      next++;
-   }
-# endif
-
-#elif defined(USE_SPARC_ASM)
-
-   cpu[0] = " SPARC";
-   next = 1;
-
-#elif defined(USE_PPC_ASM)
-   if ( _mesa_ppc_cpu_features ) {
-      cpu[next] = (cpu_has_64) ? " PowerPC 64" : " PowerPC";
-      next++;
-   }
-
-# ifdef USE_VMX_ASM
-   if ( cpu_has_vmx ) {
-      cpu[next] = "/Altivec";
-      next++;
-   }
-# endif
-
-   if ( ! cpu_has_fpu ) {
-      cpu[next] = "/No FPU";
-      next++;
-   }
-#endif
-
-   for ( i = 0 ; i < next ; i++ ) {
-      const size_t len = strlen( cpu[i] );
-
-      strncpy( & buffer[ offset ], cpu[i], len );
-      offset += len;
+   cpu = _mesa_get_cpu_string();
+   if (cpu) {
+      offset += sprintf(buffer + offset, " %s", cpu);
+      _mesa_free(cpu);
    }
 
    return offset;
@@ -179,13 +121,18 @@ driGetRendererString( char * buffer, const char * hardware_name,
 
 
 
+#define need_GL_ARB_draw_buffers
 #define need_GL_ARB_multisample
+#define need_GL_ARB_texture_compression
 #define need_GL_ARB_transpose_matrix
+#define need_GL_ARB_vertex_buffer_object
 #define need_GL_ARB_window_pos
 #define need_GL_EXT_compiled_vertex_array
+#define need_GL_EXT_multi_draw_arrays
 #define need_GL_EXT_polygon_offset
 #define need_GL_EXT_texture_object
 #define need_GL_EXT_vertex_array
+#define need_GL_IBM_multimode_draw_arrays
 #define need_GL_MESA_window_pos
 
 /* These are needed in *all* drivers because Mesa internally implements
@@ -198,14 +145,19 @@ driGetRendererString( char * buffer, const char * hardware_name,
 #include "extension_helper.h"
 
 static const struct dri_extension all_mesa_extensions[] = {
+   { "GL_ARB_draw_buffers",          GL_ARB_draw_buffers_functions },
    { "GL_ARB_multisample",           GL_ARB_multisample_functions },
+   { "GL_ARB_texture_compression",   GL_ARB_texture_compression_functions },
    { "GL_ARB_transpose_matrix",      GL_ARB_transpose_matrix_functions },
+   { "GL_ARB_vertex_buffer_object",  GL_ARB_vertex_buffer_object_functions},
    { "GL_ARB_window_pos",            GL_ARB_window_pos_functions },
    { "GL_EXT_blend_func_separate",   GL_EXT_blend_func_separate_functions },
    { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions },
+   { "GL_EXT_multi_draw_arrays",     GL_EXT_multi_draw_arrays_functions },
    { "GL_EXT_polygon_offset",        GL_EXT_polygon_offset_functions },
    { "GL_EXT_texture_object",        GL_EXT_texture_object_functions },
    { "GL_EXT_vertex_array",          GL_EXT_vertex_array_functions },
+   { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions },
    { "GL_MESA_window_pos",           GL_MESA_window_pos_functions },
    { "GL_NV_vertex_program",         GL_NV_vertex_program_functions },
    { NULL,                           NULL }
@@ -524,17 +476,14 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
  * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, 
  * \c GL_4HALF_16_16_16_16, etc.  We can cross that bridge when we come to it.
  */
-
-/* XXX: need to re-add msaa support after gallium-0.1 merge
- */
-
 __DRIconfig **
 driCreateConfigs(GLenum fb_format, GLenum fb_type,
-                const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
+                const uint8_t * depth_bits, const uint8_t * stencil_bits,
                 unsigned num_depth_stencil_bits,
-                const GLenum * db_modes, unsigned num_db_modes)
+                const GLenum * db_modes, unsigned num_db_modes,
+                const uint8_t * msaa_samples, unsigned num_msaa_modes)
 {
-   static const u_int8_t bits_table[4][4] = {
+   static const uint8_t bits_table[4][4] = {
      /* R  G  B  A */
       { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
       { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
@@ -542,7 +491,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 8, 8, 8, 8 }  /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
    };
 
-   static const u_int32_t masks_table_rgb[6][4] = {
+   static const uint32_t masks_table_rgb[6][4] = {
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2       */
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
@@ -551,7 +500,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }  /* 8_8_8_8_REV */
    };
 
-   static const u_int32_t masks_table_rgba[6][4] = {
+   static const uint32_t masks_table_rgba[6][4] = {
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2       */
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
@@ -560,7 +509,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
    };
 
-   static const u_int32_t masks_table_bgr[6][4] = {
+   static const uint32_t masks_table_bgr[6][4] = {
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2       */
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
@@ -569,7 +518,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
    };
 
-   static const u_int32_t masks_table_bgra[6][4] = {
+   static const uint32_t masks_table_bgra[6][4] = {
       { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2       */
       { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV   */
       { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
@@ -578,7 +527,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
    };
 
-   static const u_int8_t bytes_per_pixel[6] = {
+   static const uint8_t bytes_per_pixel[6] = {
       1, /* 3_3_2       */
       1, /* 2_3_3_REV   */
       2, /* 5_6_5       */
@@ -587,14 +536,12 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
       4  /* 8_8_8_8_REV */
    };
 
-   const u_int8_t  * bits;
-   const u_int32_t * masks;
+   const uint8_t  * bits;
+   const uint32_t * masks;
    int index;
    __DRIconfig **configs, **c;
    __GLcontextModes *modes;
-   unsigned i;
-   unsigned j;
-   unsigned k;
+   unsigned i, j, k, h;
    unsigned num_modes;
    unsigned num_accum_bits = 2;
 
@@ -667,7 +614,7 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
         break;
    }
 
-   num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits;
+   num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes;
    configs = _mesa_calloc((num_modes + 1) * sizeof *configs);
    if (configs == NULL)
        return NULL;
@@ -675,66 +622,72 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
     c = configs;
     for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
        for ( i = 0 ; i < num_db_modes ; i++ ) {
-           for ( j = 0 ; j < num_accum_bits ; j++ ) {
-               *c = _mesa_malloc (sizeof **c);
-               modes = &(*c)->modes;
-               c++;
-
-               memset(modes, 0, sizeof *modes);
-               modes->redBits   = bits[0];
-               modes->greenBits = bits[1];
-               modes->blueBits  = bits[2];
-               modes->alphaBits = bits[3];
-               modes->redMask   = masks[0];
-               modes->greenMask = masks[1];
-               modes->blueMask  = masks[2];
-               modes->alphaMask = masks[3];
-               modes->rgbBits   = modes->redBits + modes->greenBits
-                   + modes->blueBits + modes->alphaBits;
-
-               modes->accumRedBits   = 16 * j;
-               modes->accumGreenBits = 16 * j;
-               modes->accumBlueBits  = 16 * j;
-               modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
-               modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
-
-               modes->stencilBits = stencil_bits[k];
-               modes->depthBits = depth_bits[k];
-
-               modes->transparentPixel = GLX_NONE;
-               modes->transparentRed = GLX_DONT_CARE;
-               modes->transparentGreen = GLX_DONT_CARE;
-               modes->transparentBlue = GLX_DONT_CARE;
-               modes->transparentAlpha = GLX_DONT_CARE;
-               modes->transparentIndex = GLX_DONT_CARE;
-               modes->visualType = GLX_DONT_CARE;
-               modes->renderType = GLX_RGBA_BIT;
-               modes->drawableType = GLX_WINDOW_BIT;
-               modes->rgbMode = GL_TRUE;
-
-               if ( db_modes[i] == GLX_NONE ) {
-                   modes->doubleBufferMode = GL_FALSE;
-               }
-               else {
-                   modes->doubleBufferMode = GL_TRUE;
-                   modes->swapMethod = db_modes[i];
-               }
-
-               modes->haveAccumBuffer = ((modes->accumRedBits +
+           for ( h = 0 ; h < num_msaa_modes; h++ ) {
+               for ( j = 0 ; j < num_accum_bits ; j++ ) {
+                   *c = _mesa_malloc (sizeof **c);
+                   modes = &(*c)->modes;
+                   c++;
+
+                   memset(modes, 0, sizeof *modes);
+                   modes->redBits   = bits[0];
+                   modes->greenBits = bits[1];
+                   modes->blueBits  = bits[2];
+                   modes->alphaBits = bits[3];
+                   modes->redMask   = masks[0];
+                   modes->greenMask = masks[1];
+                   modes->blueMask  = masks[2];
+                   modes->alphaMask = masks[3];
+                   modes->rgbBits   = modes->redBits + modes->greenBits
+                       + modes->blueBits + modes->alphaBits;
+
+                   modes->accumRedBits   = 16 * j;
+                   modes->accumGreenBits = 16 * j;
+                   modes->accumBlueBits  = 16 * j;
+                   modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
+                   modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
+
+                   modes->stencilBits = stencil_bits[k];
+                   modes->depthBits = depth_bits[k];
+
+                   modes->transparentPixel = GLX_NONE;
+                   modes->transparentRed = GLX_DONT_CARE;
+                   modes->transparentGreen = GLX_DONT_CARE;
+                   modes->transparentBlue = GLX_DONT_CARE;
+                   modes->transparentAlpha = GLX_DONT_CARE;
+                   modes->transparentIndex = GLX_DONT_CARE;
+                   modes->visualType = GLX_DONT_CARE;
+                   modes->renderType = GLX_RGBA_BIT;
+                   modes->drawableType = GLX_WINDOW_BIT;
+                   modes->rgbMode = GL_TRUE;
+
+                   if ( db_modes[i] == GLX_NONE ) {
+                       modes->doubleBufferMode = GL_FALSE;
+                   }
+                   else {
+                       modes->doubleBufferMode = GL_TRUE;
+                       modes->swapMethod = db_modes[i];
+                   }
+
+                   modes->samples = msaa_samples[h];
+                   modes->sampleBuffers = modes->samples ? 1 : 0;
+
+
+                   modes->haveAccumBuffer = ((modes->accumRedBits +
                                           modes->accumGreenBits +
                                           modes->accumBlueBits +
                                           modes->accumAlphaBits) > 0);
-               modes->haveDepthBuffer = (modes->depthBits > 0);
-               modes->haveStencilBuffer = (modes->stencilBits > 0);
-
-               modes->bindToTextureRgb = GL_TRUE;
-               modes->bindToTextureRgba = GL_TRUE;
-               modes->bindToMipmapTexture = GL_FALSE;
-               modes->bindToTextureTargets = modes->rgbMode ?
-                   __DRI_ATTRIB_TEXTURE_1D_BIT |
-                   __DRI_ATTRIB_TEXTURE_2D_BIT |
-                   __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT :
-                   0;
+                   modes->haveDepthBuffer = (modes->depthBits > 0);
+                   modes->haveStencilBuffer = (modes->stencilBits > 0);
+
+                   modes->bindToTextureRgb = GL_TRUE;
+                   modes->bindToTextureRgba = GL_TRUE;
+                   modes->bindToMipmapTexture = GL_FALSE;
+                   modes->bindToTextureTargets = modes->rgbMode ?
+                       __DRI_ATTRIB_TEXTURE_1D_BIT |
+                       __DRI_ATTRIB_TEXTURE_2D_BIT |
+                       __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT :
+                       0;
+               }
            }
        }
     }
@@ -743,9 +696,10 @@ driCreateConfigs(GLenum fb_format, GLenum fb_type,
     return configs;
 }
 
-const __DRIconfig **driConcatConfigs(__DRIconfig **a, __DRIconfig **b)
+__DRIconfig **driConcatConfigs(__DRIconfig **a,
+                              __DRIconfig **b)
 {
-    const __DRIconfig **all;
+    __DRIconfig **all;
     int i, j, index;
 
     i = 0;