Change default of driconf "allow_large_textures" to announce hardware limits.
[mesa.git] / src / mesa / drivers / dri / intel / intel_screen.c
index 247fc4c5bc9955446f1d7d995ee2742b79989981..52e062eececbfea1f23082da5a4e6da059abfac5 100644 (file)
 #include "i830_dri.h"
 #include "intel_regions.h"
 #include "intel_batchbuffer.h"
+#include "intel_bufmgr_ttm.h"
 
 PUBLIC const char __driConfigOptions[] =
    DRI_CONF_BEGIN
    DRI_CONF_SECTION_PERFORMANCE
       DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
       DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
+      /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
+       * DRI_CONF_BO_REUSE_ALL
+       */
+      DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 0, "0:1")
+        DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
+           DRI_CONF_ENUM(0, "Disable buffer object reuse")
+           DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
+        DRI_CONF_DESC_END
+      DRI_CONF_OPT_END
    DRI_CONF_SECTION_END
    DRI_CONF_SECTION_QUALITY
       DRI_CONF_FORCE_S3TC_ENABLE(false)
-      DRI_CONF_ALLOW_LARGE_TEXTURES(1)
+      DRI_CONF_ALLOW_LARGE_TEXTURES(2)
    DRI_CONF_SECTION_END
    DRI_CONF_SECTION_DEBUG
      DRI_CONF_NO_RAST(false)
    DRI_CONF_SECTION_END
 DRI_CONF_END;
 
-const GLuint __driNConfigOptions = 5;
+const GLuint __driNConfigOptions = 6;
 
 #ifdef USE_NEW_INTERFACE
-     static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
+static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
 #endif /*USE_NEW_INTERFACE */
 
-     extern const struct dri_extension card_extensions[];
-     extern const struct dri_extension ttm_extensions[];
-
 /**
  * Map all the memory regions described by the screen.
  * \return GL_TRUE if success, GL_FALSE if error.
@@ -208,7 +215,7 @@ intelPrintDRIInfo(intelScreenPrivate * intelScreen,
 
 
 static void
-intelPrintSAREA(const drmI830Sarea * sarea)
+intelPrintSAREA(const struct drm_i915_sarea * sarea)
 {
    fprintf(stderr, "SAREA: sarea width %d  height %d\n", sarea->width,
            sarea->height);
@@ -235,7 +242,7 @@ intelPrintSAREA(const drmI830Sarea * sarea)
  */
 void
 intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
-                           drmI830Sarea * sarea)
+                           struct drm_i915_sarea * sarea)
 {
    intelScreen->width = sarea->width;
    intelScreen->height = sarea->height;
@@ -284,18 +291,117 @@ intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
       intelPrintSAREA(sarea);
 }
 
+static void
+intelHandleDrawableConfig(__DRIdrawablePrivate *dPriv,
+                         __DRIcontextPrivate *pcp,
+                         __DRIDrawableConfigEvent *event)
+{
+   struct intel_framebuffer *intel_fb = dPriv->driverPrivate;
+   struct intel_region *region = NULL;
+   struct intel_renderbuffer *rb, *depth_rb, *stencil_rb;
+   struct intel_context *intel = pcp->driverPrivate;
+   int cpp, pitch;
+
+   cpp = intel->ctx.Visual.rgbBits / 8;
+   pitch = ((cpp * dPriv->w + 63) & ~63) / cpp;
+
+   rb = intel_fb->color_rb[1];
+   if (rb) {
+      region = intel_region_alloc(intel, cpp, pitch, dPriv->h);
+      intel_renderbuffer_set_region(rb, region);
+   }
+
+   rb = intel_fb->color_rb[2];
+   if (rb) {
+      region = intel_region_alloc(intel, cpp, pitch, dPriv->h);
+      intel_renderbuffer_set_region(rb, region);
+   }
+
+   depth_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
+   stencil_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
+   if (depth_rb || stencil_rb)
+      region = intel_region_alloc(intel, cpp, pitch, dPriv->h);
+   if (depth_rb)
+      intel_renderbuffer_set_region(depth_rb, region);
+   if (stencil_rb)
+      intel_renderbuffer_set_region(stencil_rb, region);
+
+   /* FIXME: Tell the X server about the regions we just allocated and
+    * attached. */
+}
+
+#define BUFFER_FLAG_TILED 0x0100
+
+static void
+intelHandleBufferAttach(__DRIdrawablePrivate *dPriv,
+                       __DRIcontextPrivate *pcp,
+                       __DRIBufferAttachEvent *ba)
+{
+   struct intel_framebuffer *intel_fb = dPriv->driverPrivate;
+   struct intel_renderbuffer *rb;
+   struct intel_region *region;
+   struct intel_context *intel = pcp->driverPrivate;
+   GLuint tiled;
+
+   switch (ba->buffer.attachment) {
+   case DRI_DRAWABLE_BUFFER_FRONT_LEFT:
+      rb = intel_fb->color_rb[0];
+      break;
+
+   case DRI_DRAWABLE_BUFFER_BACK_LEFT:
+      rb = intel_fb->color_rb[0];
+      break;
+
+   case DRI_DRAWABLE_BUFFER_DEPTH:
+     rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
+     break;
+
+   case DRI_DRAWABLE_BUFFER_STENCIL:
+     rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
+     break;
+
+   case DRI_DRAWABLE_BUFFER_ACCUM:
+   default:
+      fprintf(stderr, "unhandled buffer attach event, attacment type %d\n",
+             ba->buffer.attachment);
+      return;
+   }
+
+#if 0
+   /* FIXME: Add this so we can filter out when the X server sends us
+    * attachment events for the buffers we just allocated.  Need to
+    * get the BO handle for a render buffer. */
+   if (intel_renderbuffer_get_region_handle(rb) == ba->buffer.handle)
+      return;
+#endif
+
+   tiled = (ba->buffer.flags & BUFFER_FLAG_TILED) > 0;
+   region = intel_region_alloc_for_handle(intel, ba->buffer.cpp,
+                                         ba->buffer.pitch / ba->buffer.cpp,
+                                         dPriv->h, tiled,
+                                         ba->buffer.handle);
+
+   intel_renderbuffer_set_region(rb, region);
+}
+
 static const __DRItexOffsetExtension intelTexOffsetExtension = {
    { __DRI_TEX_OFFSET },
    intelSetTexOffset,
 };
 
-static const __DRIextension *intelExtensions[] = {
+static const __DRItexBufferExtension intelTexBufferExtension = {
+    { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
+   intelSetTexBuffer,
+};
+
+static const __DRIextension *intelScreenExtensions[] = {
     &driReadDrawableExtension,
     &driCopySubBufferExtension.base,
     &driSwapControlExtension.base,
     &driFrameTrackingExtension.base,
     &driMediaStreamCounterExtension.base,
     &intelTexOffsetExtension.base,
+    &intelTexBufferExtension.base,
     NULL
 };
 
@@ -303,14 +409,14 @@ static GLboolean
 intel_get_param(__DRIscreenPrivate *psp, int param, int *value)
 {
    int ret;
-   drmI830GetParam gp;
+   struct drm_i915_getparam gp;
 
    gp.param = param;
    gp.value = value;
 
-   ret = drmCommandWriteRead(psp->fd, DRM_I830_GETPARAM, &gp, sizeof(gp));
+   ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
    if (ret) {
-      fprintf(stderr, "drmI830GetParam: %d\n", ret);
+      fprintf(stderr, "drm_i915_getparam: %d\n", ret);
       return GL_FALSE;
    }
 
@@ -321,7 +427,7 @@ static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
 {
    intelScreenPrivate *intelScreen;
    I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
-   drmI830Sarea *sarea;
+   struct drm_i915_sarea *sarea;
 
    if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
       fprintf(stderr,
@@ -342,7 +448,7 @@ static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
    intelScreen->driScrnPriv = sPriv;
    sPriv->private = (void *) intelScreen;
    intelScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
-   sarea = (drmI830Sarea *)
+   sarea = (struct drm_i915_sarea *)
       (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
 
    intelScreen->deviceID = gDRIPriv->deviceID;
@@ -364,16 +470,16 @@ static GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
    intelScreen->drmMinor = sPriv->drm_version.minor;
 
    /* Determine if IRQs are active? */
-   if (!intel_get_param(sPriv, I830_PARAM_IRQ_ACTIVE,
+   if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
                        &intelScreen->irq_active))
       return GL_FALSE;
 
    /* Determine if batchbuffers are allowed */
-   if (!intel_get_param(sPriv, I830_PARAM_ALLOW_BATCHBUFFER,
+   if (!intel_get_param(sPriv, I915_PARAM_ALLOW_BATCHBUFFER,
                        &intelScreen->allow_batchbuffer))
       return GL_FALSE;
 
-   sPriv->extensions = intelExtensions;
+   sPriv->extensions = intelScreenExtensions;
 
    return GL_TRUE;
 }
@@ -547,39 +653,18 @@ intelCreateContext(const __GLcontextModes * mesaVis,
 }
 
 
-static const struct __DriverAPIRec intelAPI = {
-   .DestroyScreen = intelDestroyScreen,
-   .CreateContext = intelCreateContext,
-   .DestroyContext = intelDestroyContext,
-   .CreateBuffer = intelCreateBuffer,
-   .DestroyBuffer = intelDestroyBuffer,
-   .SwapBuffers = intelSwapBuffers,
-   .MakeCurrent = intelMakeCurrent,
-   .UnbindContext = intelUnbindContext,
-   .GetSwapInfo = intelGetSwapInfo,
-   .GetMSC = driGetMSC32,
-   .GetDrawableMSC = driDrawableGetMSC32,
-   .WaitForMSC = driWaitForMSC32,
-   .WaitForSBC = NULL,
-   .SwapBuffersMSC = NULL,
-   .CopySubBuffer = intelCopySubBuffer,
-#ifdef I915
-   .setTexOffset = intelSetTexOffset,
-#endif
-};
-
-
-static __GLcontextModes *
-intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
+static __DRIconfig **
+intelFillInModes(__DRIscreenPrivate *psp,
+                unsigned pixel_bits, unsigned depth_bits,
                  unsigned stencil_bits, GLboolean have_back_buffer)
 {
-   __GLcontextModes *modes;
+   __DRIconfig **configs;
    __GLcontextModes *m;
-   unsigned num_modes;
    unsigned depth_buffer_factor;
    unsigned back_buffer_factor;
    GLenum fb_format;
    GLenum fb_type;
+   int i;
 
    /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
     * support pageflipping at all.
@@ -591,7 +676,6 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
    u_int8_t depth_bits_array[3];
    u_int8_t stencil_bits_array[3];
 
-
    depth_bits_array[0] = 0;
    depth_bits_array[1] = depth_bits;
    depth_bits_array[2] = depth_bits;
@@ -610,8 +694,6 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
    depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
    back_buffer_factor = (have_back_buffer) ? 3 : 1;
 
-   num_modes = depth_buffer_factor * back_buffer_factor * 4;
-
    if (pixel_bits == 16) {
       fb_format = GL_RGB;
       fb_type = GL_UNSIGNED_SHORT_5_6_5;
@@ -621,36 +703,26 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
       fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
    }
 
-   modes =
-      (*dri_interface->createContextModes) (num_modes,
-                                            sizeof(__GLcontextModes));
-   m = modes;
-   if (!driFillInModes(&m, fb_format, fb_type,
-                       depth_bits_array, stencil_bits_array,
-                       depth_buffer_factor, back_buffer_modes,
-                       back_buffer_factor, GLX_TRUE_COLOR)) {
-      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
-              __LINE__);
-      return NULL;
-   }
-   if (!driFillInModes(&m, fb_format, fb_type,
-                       depth_bits_array, stencil_bits_array,
-                       depth_buffer_factor, back_buffer_modes,
-                       back_buffer_factor, GLX_DIRECT_COLOR)) {
-      fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
+   configs = driCreateConfigs(fb_format, fb_type,
+                             depth_bits_array, stencil_bits_array,
+                             depth_buffer_factor, back_buffer_modes,
+                             back_buffer_factor);
+   if (configs == NULL) {
+    fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
               __LINE__);
       return NULL;
    }
 
    /* Mark the visual as slow if there are "fake" stencil bits.
     */
-   for (m = modes; m != NULL; m = m->next) {
+   for (i = 0; configs[i]; i++) {
+      m = &configs[i]->modes;
       if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
          m->visualRating = GLX_SLOW_CONFIG;
       }
    }
 
-   return modes;
+   return configs;
 }
 
 
@@ -661,7 +733,7 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
  *
  * \return the __GLcontextModes supported by this driver
  */
-PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
+static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
 {
 #ifdef I915
    static const __DRIversion ddx_expected = { 1, 5, 0 };
@@ -672,8 +744,6 @@ PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
    static const __DRIversion drm_expected = { 1, 5, 0 };
    I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
 
-   psp->DriverAPI = intelAPI;
-
    if (!driCheckDriDdxDrmVersions2("i915",
                                    &psp->dri_version, &dri_expected,
                                    &psp->ddx_version, &ddx_expected,
@@ -691,15 +761,17 @@ PUBLIC __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
     *
     * Hello chicken.  Hello egg.  How are you two today?
     */
-   driInitExtensions(NULL, card_extensions, GL_FALSE);
-   driInitExtensions(NULL, ttm_extensions, GL_FALSE);
-
+   intelInitExtensions(NULL, GL_TRUE);
+          
    if (!intelInitDriver(psp))
        return NULL;
 
-   return intelFillInModes(dri_priv->cpp * 8,
-                          (dri_priv->cpp == 2) ? 16 : 24,
-                          (dri_priv->cpp == 2) ? 0  : 8, 1);
+   psp->extensions = intelScreenExtensions;
+
+   return (const __DRIconfig **)
+       intelFillInModes(psp, dri_priv->cpp * 8,
+                       (dri_priv->cpp == 2) ? 16 : 24,
+                       (dri_priv->cpp == 2) ? 0  : 8, 1);
 }
 
 struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
@@ -717,3 +789,85 @@ struct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
   return intel_context(ctx);
 }
 
+/**
+ * This is the driver specific part of the createNewScreen entry point.
+ * 
+ * \return the __GLcontextModes supported by this driver
+ */
+static const
+__DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
+{
+   intelScreenPrivate *intelScreen;
+
+   /* Calling driInitExtensions here, with a NULL context pointer,
+    * does not actually enable the extensions.  It just makes sure
+    * that all the dispatch offsets for all the extensions that
+    * *might* be enables are known.  This is needed because the
+    * dispatch offsets need to be known when _mesa_context_create is
+    * called, but we can't enable the extensions until we have a
+    * context pointer.
+    *
+    * Hello chicken.  Hello egg.  How are you two today?
+    */
+   intelInitExtensions(NULL, GL_TRUE);
+
+   /* Allocate the private area */
+   intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
+   if (!intelScreen) {
+      fprintf(stderr, "\nERROR!  Allocating private area failed\n");
+      return GL_FALSE;
+   }
+   /* parse information in __driConfigOptions */
+   driParseOptionInfo(&intelScreen->optionCache,
+                      __driConfigOptions, __driNConfigOptions);
+
+   intelScreen->driScrnPriv = psp;
+   psp->private = (void *) intelScreen;
+
+   intelScreen->drmMinor = psp->drm_version.minor;
+
+   /* Determine chipset ID? */
+   if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
+                       &intelScreen->deviceID))
+      return GL_FALSE;
+
+   /* Determine if IRQs are active? */
+   if (!intel_get_param(psp, I915_PARAM_IRQ_ACTIVE,
+                       &intelScreen->irq_active))
+      return GL_FALSE;
+
+   /* Determine if batchbuffers are allowed */
+   if (!intel_get_param(psp, I915_PARAM_ALLOW_BATCHBUFFER,
+                       &intelScreen->allow_batchbuffer))
+      return GL_FALSE;
+
+   if (!intelScreen->allow_batchbuffer) {
+      fprintf(stderr, "batch buffer not allowed\n");
+      return GL_FALSE;
+   }
+
+   psp->extensions = intelScreenExtensions;
+
+   return driConcatConfigs(intelFillInModes(psp, 16, 16, 0, 1),
+                          intelFillInModes(psp, 32, 24, 8, 1));
+}
+
+const struct __DriverAPIRec driDriverAPI = {
+   .InitScreen          = intelInitScreen,
+   .DestroyScreen       = intelDestroyScreen,
+   .CreateContext       = intelCreateContext,
+   .DestroyContext      = intelDestroyContext,
+   .CreateBuffer        = intelCreateBuffer,
+   .DestroyBuffer       = intelDestroyBuffer,
+   .SwapBuffers                 = intelSwapBuffers,
+   .MakeCurrent                 = intelMakeCurrent,
+   .UnbindContext       = intelUnbindContext,
+   .GetSwapInfo                 = intelGetSwapInfo,
+   .GetDrawableMSC      = driDrawableGetMSC32,
+   .WaitForMSC          = driWaitForMSC32,
+   .CopySubBuffer       = intelCopySubBuffer,
+
+   .InitScreen2                 = intelInitScreen2,
+   .HandleDrawableConfig = intelHandleDrawableConfig,
+   .HandleBufferAttach  = intelHandleBufferAttach,
+};