Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / xorg / xorg_exa.c
index a22f15f64a7b05e4cac0c3e058faa9143590dbc3..d5a1be81747a4c78da8f20b8b6a40250ed40931b 100644 (file)
 #include "pipe/p_format.h"
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
 
 #include "util/u_rect.h"
 #include "util/u_math.h"
 #include "util/u_debug.h"
+#include "util/u_format.h"
 
 #define DEBUG_PRINT 0
+#define ROUND_UP_TEXTURES 1
 
 /*
  * Helper functions
@@ -117,22 +118,22 @@ exa_get_pipe_format(int depth, enum pipe_format *format, int *bbp, int *picture_
 {
     switch (depth) {
     case 32:
-       *format = PIPE_FORMAT_A8R8G8B8_UNORM;
+       *format = PIPE_FORMAT_B8G8R8A8_UNORM;
        *picture_format = PICT_a8r8g8b8;
        assert(*bbp == 32);
        break;
     case 24:
-       *format = PIPE_FORMAT_X8R8G8B8_UNORM;
+       *format = PIPE_FORMAT_B8G8R8X8_UNORM;
        *picture_format = PICT_x8r8g8b8;
        assert(*bbp == 32);
        break;
     case 16:
-       *format = PIPE_FORMAT_R5G6B5_UNORM;
+       *format = PIPE_FORMAT_B5G6R5_UNORM;
        *picture_format = PICT_r5g6b5;
        assert(*bbp == 16);
        break;
     case 15:
-       *format = PIPE_FORMAT_A1R5G5B5_UNORM;
+       *format = PIPE_FORMAT_B5G5R5A1_UNORM;
        *picture_format = PICT_x1r5g5b5;
        assert(*bbp == 16);
        break;
@@ -143,7 +144,7 @@ exa_get_pipe_format(int depth, enum pipe_format *format, int *bbp, int *picture_
        break;
     case 4:
     case 1:
-       *format = PIPE_FORMAT_A8R8G8B8_UNORM; /* bad bad bad */
+       *format = PIPE_FORMAT_B8G8R8A8_UNORM; /* bad bad bad */
        break;
     default:
        assert(0);
@@ -187,11 +188,7 @@ ExaDownloadFromScreen(PixmapPtr pPix, int x,  int y, int w,  int h, char *dst,
     if (!priv || !priv->tex)
        return FALSE;
 
-    if (exa->pipe->is_texture_referenced(exa->pipe, priv->tex, 0, 0) &
-       PIPE_REFERENCED_FOR_WRITE)
-       exa->pipe->flush(exa->pipe, 0, NULL);
-
-    transfer = exa->scrn->get_tex_transfer(exa->scrn, priv->tex, 0, 0, 0,
+    transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0,
                                           PIPE_TRANSFER_READ, x, y, w, h);
     if (!transfer)
        return FALSE;
@@ -201,12 +198,12 @@ ExaDownloadFromScreen(PixmapPtr pPix, int x,  int y, int w,  int h, char *dst,
                  x, y, w, h, dst_pitch);
 #endif
 
-    util_copy_rect((unsigned char*)dst, &priv->tex->block, dst_pitch, 0, 0,
-                  w, h, exa->scrn->transfer_map(exa->scrn, transfer),
+    util_copy_rect((unsigned char*)dst, priv->tex->format, dst_pitch, 0, 0,
+                  w, h, exa->pipe->transfer_map(exa->pipe, transfer),
                   transfer->stride, 0, 0);
 
-    exa->scrn->transfer_unmap(exa->scrn, transfer);
-    exa->scrn->tex_transfer_destroy(transfer);
+    exa->pipe->transfer_unmap(exa->pipe, transfer);
+    exa->pipe->transfer_destroy(exa->pipe, transfer);
 
     return TRUE;
 }
@@ -225,12 +222,7 @@ ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src,
     if (!priv || !priv->tex)
        return FALSE;
 
-    /* make sure that any pending operations are flushed to hardware */
-    if (exa->pipe->is_texture_referenced(exa->pipe, priv->tex, 0, 0) &
-       (PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE))
-       xorg_exa_flush(exa, 0, NULL);
-
-    transfer = exa->scrn->get_tex_transfer(exa->scrn, priv->tex, 0, 0, 0,
+    transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0,
                                           PIPE_TRANSFER_WRITE, x, y, w, h);
     if (!transfer)
        return FALSE;
@@ -240,12 +232,12 @@ ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src,
                  x, y, w, h, src_pitch);
 #endif
 
-    util_copy_rect(exa->scrn->transfer_map(exa->scrn, transfer),
-                  &priv->tex->block, transfer->stride, 0, 0, w, h,
+    util_copy_rect(exa->pipe->transfer_map(exa->pipe, transfer),
+                  priv->tex->format, transfer->stride, 0, 0, w, h,
                   (unsigned char*)src, src_pitch, 0, 0);
 
-    exa->scrn->transfer_unmap(exa->scrn, transfer);
-    exa->scrn->tex_transfer_destroy(transfer);
+    exa->pipe->transfer_unmap(exa->pipe, transfer);
+    exa->pipe->transfer_destroy(exa->pipe, transfer);
 
     return TRUE;
 }
@@ -269,17 +261,18 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
 
     if (priv->map_count == 0)
     {
-       if (exa->pipe->is_texture_referenced(exa->pipe, priv->tex, 0, 0) &
-           PIPE_REFERENCED_FOR_WRITE)
-           exa->pipe->flush(exa->pipe, 0, NULL);
+        assert(pPix->drawable.width <= priv->tex->width0);
+        assert(pPix->drawable.height <= priv->tex->height0);
 
        priv->map_transfer =
-           exa->scrn->get_tex_transfer(exa->scrn, priv->tex, 0, 0, 0,
+          pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0,
 #ifdef EXA_MIXED_PIXMAPS
                                        PIPE_TRANSFER_MAP_DIRECTLY |
 #endif
                                        PIPE_TRANSFER_READ_WRITE,
-                                       0, 0, priv->tex->width[0], priv->tex->height[0]);
+                                       0, 0, 
+                                        pPix->drawable.width,
+                                        pPix->drawable.height );
        if (!priv->map_transfer)
 #ifdef EXA_MIXED_PIXMAPS
            return FALSE;
@@ -288,7 +281,7 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
 #endif
 
        pPix->devPrivate.ptr =
-           exa->scrn->transfer_map(exa->scrn, priv->map_transfer);
+           exa->pipe->transfer_map(exa->pipe, priv->map_transfer);
        pPix->devKind = priv->map_transfer->stride;
     }
 
@@ -315,8 +308,8 @@ ExaFinishAccess(PixmapPtr pPix, int index)
 
     if (--priv->map_count == 0) {
        assert(priv->map_transfer);
-       exa->scrn->transfer_unmap(exa->scrn, priv->map_transfer);
-       exa->scrn->tex_transfer_destroy(priv->map_transfer);
+       exa->pipe->transfer_unmap(exa->pipe, priv->map_transfer);
+       exa->pipe->transfer_destroy(exa->pipe, priv->map_transfer);
        priv->map_transfer = NULL;
        pPix->devPrivate.ptr = NULL;
     }
@@ -337,6 +330,9 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
 #if DEBUG_PRINT
     debug_printf("ExaPrepareSolid(0x%x)\n", fg);
 #endif
+    if (!exa->accel)
+       return FALSE;
+
     if (!exa->pipe)
        XORG_FALLBACK("accle not enabled");
 
@@ -351,11 +347,11 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
 
     if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
                                         priv->tex->target,
-                                        PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
-       XORG_FALLBACK("format %s", pf_name(priv->tex->format));
+                                        PIPE_BIND_RENDER_TARGET, 0)) {
+       XORG_FALLBACK("format %s", util_format_name(priv->tex->format));
     }
 
-    return exa->accel && xorg_solid_bind_state(exa, priv, fg);
+    return xorg_solid_bind_state(exa, priv, fg);
 }
 
 static void
@@ -411,6 +407,10 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 #if DEBUG_PRINT
     debug_printf("ExaPrepareCopy\n");
 #endif
+
+    if (!exa->accel)
+       return FALSE;
+
     if (!exa->pipe)
        XORG_FALLBACK("accle not enabled");
 
@@ -428,13 +428,13 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 
     if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
                                         priv->tex->target,
-                                        PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))
-       XORG_FALLBACK("pDst format %s", pf_name(priv->tex->format));
+                                        PIPE_BIND_RENDER_TARGET, 0))
+       XORG_FALLBACK("pDst format %s", util_format_name(priv->tex->format));
 
     if (!exa->scrn->is_format_supported(exa->scrn, src_priv->tex->format,
                                         src_priv->tex->target,
-                                        PIPE_TEXTURE_USAGE_SAMPLER, 0))
-       XORG_FALLBACK("pSrc format %s", pf_name(src_priv->tex->format));
+                                        PIPE_BIND_SAMPLER_VIEW, 0))
+       XORG_FALLBACK("pSrc format %s", util_format_name(src_priv->tex->format));
 
     exa->copy.src = src_priv;
     exa->copy.dst = priv;
@@ -453,13 +453,13 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
           exa->scrn->get_tex_surface( exa->scrn,
                                       exa->copy.src->tex,
                                       0, 0, 0,
-                                      PIPE_BUFFER_USAGE_GPU_READ);
+                                      PIPE_BIND_BLIT_SOURCE);
 
        exa->copy.dst_surface =
           exa->scrn->get_tex_surface( exa->scrn, 
                                       exa->copy.dst->tex,
                                       0, 0, 0, 
-                                      PIPE_BUFFER_USAGE_GPU_WRITE );
+                                      PIPE_BIND_BLIT_DESTINATION );
     }
     else {
        exa->copy.use_surface_copy = FALSE;
@@ -468,14 +468,14 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
           exa->copy.src_texture = renderer_clone_texture( exa->renderer,
                                                           exa->copy.src->tex );
        else
-          pipe_texture_reference(&exa->copy.src_texture,
+          pipe_resource_reference(&exa->copy.src_texture,
                                  exa->copy.src->tex);
 
        exa->copy.dst_surface =
           exa->scrn->get_tex_surface(exa->scrn,
                                      exa->copy.dst->tex,
                                      0, 0, 0,
-                                     PIPE_BUFFER_USAGE_GPU_WRITE);
+                                     PIPE_BIND_BLIT_DESTINATION);
 
 
        renderer_copy_prepare(exa->renderer, 
@@ -484,7 +484,7 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     }
 
 
-    return exa->accel;
+    return TRUE;
 }
 
 static void
@@ -502,6 +502,7 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
 #endif
 
    debug_assert(priv == exa->copy.dst);
+   (void) priv;
 
    if (exa->copy.use_surface_copy) {
       /* XXX: consider exposing >1 box in surface_copy interface.
@@ -518,8 +519,8 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
                            dstX, dstY,
                            srcX, srcY,
                            width, height,
-                           exa->copy.src_texture->width[0],
-                           exa->copy.src_texture->height[0]);
+                           exa->copy.src_texture->width0,
+                           exa->copy.src_texture->height0);
    }
 }
 
@@ -540,7 +541,7 @@ ExaDoneCopy(PixmapPtr pPixmap)
    exa->copy.dst = NULL;
    pipe_surface_reference(&exa->copy.src_surface, NULL);
    pipe_surface_reference(&exa->copy.dst_surface, NULL);
-   pipe_texture_reference(&exa->copy.src_texture, NULL);
+   pipe_resource_reference(&exa->copy.src_texture, NULL);
 }
 
 
@@ -592,15 +593,19 @@ ExaCheckComposite(int op,
    ScrnInfoPtr pScrn = xf86Screens[pDstPicture->pDrawable->pScreen->myNum];
    modesettingPtr ms = modesettingPTR(pScrn);
    struct exa_context *exa = ms->exa;
-   boolean accelerated = xorg_composite_accelerated(op,
-                                                    pSrcPicture,
-                                                    pMaskPicture,
-                                                    pDstPicture);
+
 #if DEBUG_PRINT
    debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
                 op, pSrcPicture, pMaskPicture, pDstPicture, accelerated);
 #endif
-   return exa->accel && accelerated;
+
+   if (!exa->accel)
+       return FALSE;
+
+   return xorg_composite_accelerated(op,
+                                    pSrcPicture,
+                                    pMaskPicture,
+                                    pDstPicture);
 }
 
 
@@ -614,6 +619,9 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
    struct exa_context *exa = ms->exa;
    struct exa_pixmap_priv *priv;
 
+   if (!exa->accel)
+       return FALSE;
+
 #if DEBUG_PRINT
    debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
                 op, pSrcPicture, pMaskPicture, pDstPicture);
@@ -631,8 +639,8 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
 
    if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
                                        priv->tex->target,
-                                       PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))
-      XORG_FALLBACK("pDst format: %s", pf_name(priv->tex->format));
+                                       PIPE_BIND_RENDER_TARGET, 0))
+      XORG_FALLBACK("pDst format: %s", util_format_name(priv->tex->format));
 
    if (priv->picture_format != pDstPicture->format)
       XORG_FALLBACK("pDst pic_format: %s != %s",
@@ -646,8 +654,8 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
 
       if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
                                           priv->tex->target,
-                                          PIPE_TEXTURE_USAGE_SAMPLER, 0))
-         XORG_FALLBACK("pSrc format: %s", pf_name(priv->tex->format));
+                                          PIPE_BIND_SAMPLER_VIEW, 0))
+         XORG_FALLBACK("pSrc format: %s", util_format_name(priv->tex->format));
 
       if (!picture_check_formats(priv, pSrcPicture))
          XORG_FALLBACK("pSrc pic_format: %s != %s",
@@ -663,8 +671,8 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
 
       if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
                                           priv->tex->target,
-                                          PIPE_TEXTURE_USAGE_SAMPLER, 0))
-         XORG_FALLBACK("pMask format: %s", pf_name(priv->tex->format));
+                                          PIPE_BIND_SAMPLER_VIEW, 0))
+         XORG_FALLBACK("pMask format: %s", util_format_name(priv->tex->format));
 
       if (!picture_check_formats(priv, pMaskPicture))
          XORG_FALLBACK("pMask pic_format: %s != %s",
@@ -672,8 +680,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
                        render_format_name(pMaskPicture->format));
    }
 
-   return exa->accel &&
-          xorg_composite_bind_state(exa, op, pSrcPicture, pMaskPicture,
+   return xorg_composite_bind_state(exa, op, pSrcPicture, pMaskPicture,
                                     pDstPicture,
                                     pSrc ? exaGetPixmapDriverPrivate(pSrc) : NULL,
                                     pMask ? exaGetPixmapDriverPrivate(pMask) : NULL,
@@ -737,7 +744,7 @@ ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
     if (!priv)
        return;
 
-    pipe_texture_reference(&priv->tex, NULL);
+    pipe_resource_reference(&priv->tex, NULL);
 
     xfree(priv);
 }
@@ -769,7 +776,7 @@ xorg_exa_set_displayed_usage(PixmapPtr pPixmap)
        return 0;
     }
 
-    priv->flags |= PIPE_TEXTURE_USAGE_PRIMARY;
+    priv->flags |= PIPE_BIND_SCANOUT;
 
     return 0;
 }
@@ -785,38 +792,27 @@ xorg_exa_set_shared_usage(PixmapPtr pPixmap)
        return 0;
     }
 
-    priv->flags |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+    priv->flags |= PIPE_BIND_SHARED;
 
     return 0;
 }
 
-unsigned
-xorg_exa_get_pixmap_handle(PixmapPtr pPixmap, unsigned *stride_out)
-{
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_pixmap_priv *priv;
-    unsigned handle;
-    unsigned stride;
-
-    if (!ms->exa) {
-       FatalError("NO MS->EXA\n");
-       return 0;
-    }
 
-    priv = exaGetPixmapDriverPrivate(pPixmap);
 
-    if (!priv) {
-       FatalError("NO PIXMAP PRIVATE\n");
-       return 0;
-    }
+static Bool
+size_match( int width, int tex_width )
+{
+#if ROUND_UP_TEXTURES
+   if (width > tex_width)
+      return FALSE;
 
-    ms->api->local_handle_from_texture(ms->api, ms->screen, priv->tex, &stride, &handle);
-    if (stride_out)
-       *stride_out = stride;
+   if (width * 2 < tex_width)
+      return FALSE;
 
-    return handle;
+   return TRUE;
+#else
+   return width == tex_width;
+#endif
 }
 
 static Bool
@@ -839,8 +835,8 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
        
        if (priv->tex)
           debug_printf("  ==> old texture %dx%d\n",
-                       priv->tex->width[0]
-                       priv->tex->height[0]);
+                       priv->tex->width0
+                       priv->tex->height0);
     }
 
 
@@ -862,112 +858,115 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     miModifyPixmapHeader(pPixmap, width, height, depth,
                             bitsPerPixel, devKind, NULL);
 
+    priv->width = width;
+    priv->height = height;
+
     /* Deal with screen resize */
     if ((exa->accel || priv->flags) &&
         (!priv->tex ||
-         (priv->tex->width[0] != width ||
-          priv->tex->height[0] != height ||
-          priv->tex_flags != priv->flags))) {
-       struct pipe_texture *texture = NULL;
-       struct pipe_texture template;
+         !size_match(width, priv->tex->width0) ||
+         !size_match(height, priv->tex->height0) ||
+         priv->tex_flags != priv->flags)) {
+       struct pipe_resource *texture = NULL;
+       struct pipe_resource template;
 
        memset(&template, 0, sizeof(template));
        template.target = PIPE_TEXTURE_2D;
        exa_get_pipe_format(depth, &template.format, &bitsPerPixel, &priv->picture_format);
-       pf_get_block(template.format, &template.block);
-#if 1
-       template.width[0] = util_next_power_of_two(width);
-       template.height[0] = util_next_power_of_two(height);
-#else
-       template.width[0] = width;
-       template.height[0] = height;
-#endif
-       template.depth[0] = 1;
+        if (ROUND_UP_TEXTURES && priv->flags == 0) {
+           template.width0 = util_next_power_of_two(width);
+           template.height0 = util_next_power_of_two(height);
+        }
+        else {
+           template.width0 = width;
+           template.height0 = height;
+        }
+
+       template.depth0 = 1;
        template.last_level = 0;
-       template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET | priv->flags;
+       template.bind = PIPE_BIND_RENDER_TARGET | priv->flags;
        priv->tex_flags = priv->flags;
-       texture = exa->scrn->texture_create(exa->scrn, &template);
+       texture = exa->scrn->resource_create(exa->scrn, &template);
 
        if (priv->tex) {
            struct pipe_surface *dst_surf;
            struct pipe_surface *src_surf;
 
            dst_surf = exa->scrn->get_tex_surface(
-               exa->scrn, texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+               exa->scrn, texture, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION);
            src_surf = xorg_gpu_surface(exa->pipe->screen, priv);
             if (exa->pipe->surface_copy) {
                exa->pipe->surface_copy(exa->pipe, dst_surf, 0, 0, src_surf,
-                                       0, 0, min(width, texture->width[0]),
-                                       min(height, texture->height[0]));
+                                       0, 0, min(width, texture->width0),
+                                       min(height, texture->height0));
             } else {
                util_surface_copy(exa->pipe, FALSE, dst_surf, 0, 0, src_surf,
-                                 0, 0, min(width, texture->width[0]),
-                                 min(height, texture->height[0]));
+                                 0, 0, min(width, texture->width0),
+                                 min(height, texture->height0));
             }
            exa->scrn->tex_surface_destroy(dst_surf);
            exa->scrn->tex_surface_destroy(src_surf);
        }
 
-       pipe_texture_reference(&priv->tex, texture);
+       pipe_resource_reference(&priv->tex, texture);
        /* the texture we create has one reference */
-       pipe_texture_reference(&texture, NULL);
+       pipe_resource_reference(&texture, NULL);
     }
 
     return TRUE;
 }
 
-struct pipe_texture *
+struct pipe_resource *
 xorg_exa_get_texture(PixmapPtr pPixmap)
 {
    struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
-   struct pipe_texture *tex = NULL;
-   pipe_texture_reference(&tex, priv->tex);
+   struct pipe_resource *tex = NULL;
+   pipe_resource_reference(&tex, priv->tex);
    return tex;
 }
 
 Bool
-xorg_exa_set_texture(PixmapPtr pPixmap, struct  pipe_texture *tex)
+xorg_exa_set_texture(PixmapPtr pPixmap, struct  pipe_resource *tex)
 {
     struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
 
-    int mask = PIPE_TEXTURE_USAGE_PRIMARY | PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+    int mask = PIPE_BIND_SHARED | PIPE_BIND_SCANOUT;
 
     if (!priv)
        return FALSE;
 
-    if (pPixmap->drawable.width != tex->width[0] ||
-       pPixmap->drawable.height != tex->height[0])
+    if (pPixmap->drawable.width != tex->width0 ||
+       pPixmap->drawable.height != tex->height0)
        return FALSE;
 
-    pipe_texture_reference(&priv->tex, tex);
-    priv->tex_flags = tex->tex_usage & mask;
+    pipe_resource_reference(&priv->tex, tex);
+    priv->tex_flags = tex->bind & mask;
 
     return TRUE;
 }
 
-struct pipe_texture *
+struct pipe_resource *
 xorg_exa_create_root_texture(ScrnInfoPtr pScrn,
                             int width, int height,
                             int depth, int bitsPerPixel)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     struct exa_context *exa = ms->exa;
-    struct pipe_texture template;
+    struct pipe_resource template;
     int dummy;
 
     memset(&template, 0, sizeof(template));
     template.target = PIPE_TEXTURE_2D;
     exa_get_pipe_format(depth, &template.format, &bitsPerPixel, &dummy);
-    pf_get_block(template.format, &template.block);
-    template.width[0] = width;
-    template.height[0] = height;
-    template.depth[0] = 1;
+    template.width0 = width;
+    template.height0 = height;
+    template.depth0 = 1;
     template.last_level = 0;
-    template.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
-    template.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY;
-    template.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+    template.bind |= PIPE_BIND_RENDER_TARGET;
+    template.bind |= PIPE_BIND_SCANOUT;
+    template.bind |= PIPE_BIND_SHARED;
 
-    return exa->scrn->texture_create(exa->scrn, &template);
+    return exa->scrn->resource_create(exa->scrn, &template);
 }
 
 void
@@ -976,10 +975,16 @@ xorg_exa_close(ScrnInfoPtr pScrn)
    modesettingPtr ms = modesettingPTR(pScrn);
    struct exa_context *exa = ms->exa;
 
+   pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL);
+   pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL);
+
    renderer_destroy(exa->renderer);
 
    if (exa->pipe)
       exa->pipe->destroy(exa->pipe);
+   exa->pipe = NULL;
+   /* Since this was shared be proper with the pointer */
+   ms->ctx = NULL;
 
    exaDriverFini(pScrn->pScreen);
    xfree(exa);
@@ -1047,7 +1052,10 @@ xorg_exa_init(ScrnInfoPtr pScrn, Bool accel)
    }
 
    exa->scrn = ms->screen;
-   exa->pipe = ms->api->create_context(ms->api, exa->scrn);
+   exa->pipe = exa->scrn->context_create(exa->scrn, NULL);
+   if (exa->pipe == NULL)
+      goto out_err;
+
    /* Share context with DRI */
    ms->ctx = exa->pipe;
 
@@ -1065,9 +1073,12 @@ out_err:
 struct pipe_surface *
 xorg_gpu_surface(struct pipe_screen *scrn, struct exa_pixmap_priv *priv)
 {
+   
+   /* seems to get called both for blits and render target usage */
    return scrn->get_tex_surface(scrn, priv->tex, 0, 0, 0,
-                                PIPE_BUFFER_USAGE_GPU_READ |
-                                PIPE_BUFFER_USAGE_GPU_WRITE);
+                                PIPE_BIND_BLIT_SOURCE |
+                                PIPE_BIND_BLIT_DESTINATION |
+                                PIPE_BIND_RENDER_TARGET);
 
 }