Merge branch '7.8'
[mesa.git] / src / mesa / state_tracker / st_cb_texture.c
index 61d3f0f98cc2591741afe34a0f697f8a7ed70e54..3457214ca4c24e8c384f392459c823d7784d43a7 100644 (file)
@@ -49,7 +49,6 @@
 #include "state_tracker/st_cb_fbo.h"
 #include "state_tracker/st_cb_texture.h"
 #include "state_tracker/st_format.h"
-#include "state_tracker/st_public.h"
 #include "state_tracker/st_texture.h"
 #include "state_tracker/st_gen_mipmap.h"
 #include "state_tracker/st_inlines.h"
@@ -63,6 +62,7 @@
 #include "util/u_blit.h"
 #include "util/u_format.h"
 #include "util/u_surface.h"
+#include "util/u_sampler.h"
 #include "util/u_math.h"
 
 
@@ -120,10 +120,21 @@ static void
 st_DeleteTextureObject(GLcontext *ctx,
                        struct gl_texture_object *texObj)
 {
+   struct st_context *st = st_context(ctx);
    struct st_texture_object *stObj = st_texture_object(texObj);
    if (stObj->pt)
-      pipe_texture_reference(&stObj->pt, NULL);
-
+      pipe_resource_reference(&stObj->pt, NULL);
+   if (stObj->sampler_view) {
+      if (stObj->sampler_view->context != st->pipe) {
+         /* Take "ownership" of this texture sampler view by setting
+          * its context pointer to this context.  This avoids potential
+          * crashes when the texture object is shared among contexts
+          * and the original/owner context has already been destroyed.
+          */
+         stObj->sampler_view->context = st->pipe;
+      }
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+   }
    _mesa_delete_texture_object(ctx, texObj);
 }
 
@@ -137,7 +148,7 @@ st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
    DBG("%s\n", __FUNCTION__);
 
    if (stImage->pt) {
-      pipe_texture_reference(&stImage->pt, NULL);
+      pipe_resource_reference(&stImage->pt, NULL);
    }
 
    if (texImage->Data) {
@@ -198,22 +209,30 @@ do_memcpy(void *dest, const void *src, size_t n)
 
 
 /**
- * Return default texture usage bitmask for the given texture format.
+ * Return default texture resource binding bitmask for the given format.
  */
 static GLuint
-default_usage(enum pipe_format fmt)
+default_bindings(struct st_context *st, enum pipe_format format)
 {
-   GLuint usage = PIPE_TEXTURE_USAGE_SAMPLER;
-   if (util_format_is_depth_or_stencil(fmt))
-      usage |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+   struct pipe_screen *screen = st->pipe->screen;
+   const unsigned target = PIPE_TEXTURE_2D;
+   const unsigned geom = 0x0;
+   unsigned bindings;
+
+   if (util_format_is_depth_or_stencil(format))
+      bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL;
+   else
+      bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
+
+   if (screen->is_format_supported(screen, format, target, bindings, geom))
+      return bindings;
    else
-      usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
-   return usage;
+      return PIPE_BIND_SAMPLER_VIEW;
 }
 
 
 /**
- * Allocate a pipe_texture object for the given st_texture_object using
+ * Allocate a pipe_resource object for the given st_texture_object using
  * the given st_texture_image to guess the mipmap size/levels.
  *
  * [comments...]
@@ -236,7 +255,7 @@ guess_and_alloc_texture(struct st_context *st,
    GLuint width = stImage->base.Width2;  /* size w/out border */
    GLuint height = stImage->base.Height2;
    GLuint depth = stImage->base.Depth2;
-   GLuint i, usage;
+   GLuint i, bindings;
    enum pipe_format fmt;
 
    DBG("%s\n", __FUNCTION__);
@@ -301,7 +320,7 @@ guess_and_alloc_texture(struct st_context *st,
 
    fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat);
 
-   usage = default_usage(fmt);
+   bindings = default_bindings(st, fmt);
 
    stObj->pt = st_texture_create(st,
                                  gl_target_to_pipe(stObj->base.Target),
@@ -310,7 +329,7 @@ guess_and_alloc_texture(struct st_context *st,
                                  width,
                                  height,
                                  depth,
-                                 usage);
+                                 bindings);
 
    DBG("%s - success\n", __FUNCTION__);
 }
@@ -371,10 +390,14 @@ compress_with_blit(GLcontext * ctx,
 {
    const GLuint dstImageOffsets[1] = {0};
    struct st_texture_image *stImage = st_texture_image(texImage);
-   struct pipe_screen *screen = ctx->st->pipe->screen;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_screen *screen = pipe->screen;
    gl_format mesa_format;
-   struct pipe_texture templ;
-   struct pipe_texture *src_tex;
+   struct pipe_resource templ;
+   struct pipe_resource *src_tex;
+   struct pipe_sampler_view view_templ;
+   struct pipe_sampler_view *src_view;
    struct pipe_surface *dst_surface;
    struct pipe_transfer *tex_xfer;
    void *map;
@@ -387,7 +410,7 @@ compress_with_blit(GLcontext * ctx,
    /* get destination surface (in the compressed texture) */
    dst_surface = screen->get_tex_surface(screen, stImage->pt,
                                          stImage->face, stImage->level, 0,
-                                         PIPE_BUFFER_USAGE_GPU_WRITE);
+                                         PIPE_BIND_BLIT_DESTINATION);
    if (!dst_surface) {
       /* can't render into this format (or other problem) */
       return GL_FALSE;
@@ -409,8 +432,9 @@ compress_with_blit(GLcontext * ctx,
    templ.height0 = height;
    templ.depth0 = 1;
    templ.last_level = 0;
-   templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
-   src_tex = screen->texture_create(screen, &templ);
+   templ.usage = PIPE_USAGE_DEFAULT;
+   templ.bind = PIPE_BIND_SAMPLER_VIEW;
+   src_tex = screen->resource_create(screen, &templ);
 
    if (!src_tex)
       return GL_FALSE;
@@ -421,7 +445,7 @@ compress_with_blit(GLcontext * ctx,
                                             0, 0, 0, /* face, level are zero */
                                             PIPE_TRANSFER_WRITE,
                                             0, 0, width, height); /* x, y, w, h */
-   map = screen->transfer_map(screen, tex_xfer);
+   map = pipe_transfer_map(pipe, tex_xfer);
 
    _mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
                   map,              /* dest ptr */
@@ -433,12 +457,19 @@ compress_with_blit(GLcontext * ctx,
                   pixels,           /* source data */
                   unpack);          /* source data packing */
 
-   screen->transfer_unmap(screen, tex_xfer);
-   screen->tex_transfer_destroy(tex_xfer);
+   pipe_transfer_unmap(pipe, tex_xfer);
+   pipe->transfer_destroy(pipe, tex_xfer);
+
+   /* Create temporary sampler view */
+   u_sampler_view_default_template(&view_templ,
+                                   src_tex,
+                                   src_tex->format);
+   src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ);
+
 
    /* copy / compress image */
-   util_blit_pixels_tex(ctx->st->blit,
-                        src_tex,          /* pipe_texture (src) */
+   util_blit_pixels_tex(st->blit,
+                        src_view,         /* sampler view (src) */
                         0, 0,             /* src x0, y0 */
                         width, height,    /* src x1, y1 */
                         dst_surface,      /* pipe_surface (dst) */
@@ -449,7 +480,8 @@ compress_with_blit(GLcontext * ctx,
                         PIPE_TEX_MIPFILTER_NEAREST);
 
    pipe_surface_reference(&dst_surface, NULL);
-   pipe_texture_reference(&src_tex, NULL);
+   pipe_resource_reference(&src_tex, NULL);
+   pipe_sampler_view_reference(&src_view, NULL);
 
    return GL_TRUE;
 }
@@ -471,7 +503,8 @@ st_TexImage(GLcontext * ctx,
             struct gl_texture_image *texImage,
             GLsizei imageSize, GLboolean compressed_src)
 {
-   struct pipe_screen *screen = ctx->st->pipe->screen;
+   struct st_context *st = st_context(ctx);
+   struct pipe_screen *screen = st->pipe->screen;
    struct st_texture_object *stObj = st_texture_object(texObj);
    struct st_texture_image *stImage = st_texture_image(texImage);
    GLint postConvWidth, postConvHeight;
@@ -536,7 +569,7 @@ st_TexImage(GLcontext * ctx,
     * Release any old malloced memory.
     */
    if (stImage->pt) {
-      pipe_texture_reference(&stImage->pt, NULL);
+      pipe_resource_reference(&stImage->pt, NULL);
       assert(!texImage->Data);
    }
    else if (texImage->Data) {
@@ -553,8 +586,9 @@ st_TexImage(GLcontext * ctx,
           !st_texture_match_image(stObj->pt, &stImage->base,
                                   stImage->face, stImage->level)) {
          DBG("release it\n");
-         pipe_texture_reference(&stObj->pt, NULL);
+         pipe_resource_reference(&stObj->pt, NULL);
          assert(!stObj->pt);
+         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
          stObj->teximage_realloc = FALSE;
       }
    }
@@ -565,13 +599,13 @@ st_TexImage(GLcontext * ctx,
    }
 
    if (!stObj->pt) {
-      guess_and_alloc_texture(ctx->st, stObj, stImage);
+      guess_and_alloc_texture(st, stObj, stImage);
       if (!stObj->pt) {
          /* Probably out of memory.
           * Try flushing any pending rendering, then retry.
           */
-         st_finish(ctx->st);
-         guess_and_alloc_texture(ctx->st, stObj, stImage);
+         st_finish(st);
+         guess_and_alloc_texture(st, stObj, stImage);
          if (!stObj->pt) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
             return;
@@ -585,7 +619,7 @@ st_TexImage(GLcontext * ctx,
        st_texture_match_image(stObj->pt, &stImage->base,
                                  stImage->face, stImage->level)) {
 
-      pipe_texture_reference(&stImage->pt, stObj->pt);
+      pipe_resource_reference(&stImage->pt, stObj->pt);
       assert(stImage->pt);
    }
 
@@ -619,7 +653,7 @@ st_TexImage(GLcontext * ctx,
        screen->is_format_supported(screen,
                                    stImage->pt->format,
                                    stImage->pt->target,
-                                   PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+                                   PIPE_BIND_RENDER_TARGET, 0)) {
       if (!pixels)
          goto done;
 
@@ -636,7 +670,7 @@ st_TexImage(GLcontext * ctx,
       else
          transfer_usage = PIPE_TRANSFER_WRITE;
 
-      texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
+      texImage->Data = st_texture_image_map(st, stImage, 0,
                                             transfer_usage, 0, 0,
                                             stImage->base.Width,
                                             stImage->base.Height);
@@ -717,9 +751,9 @@ st_TexImage(GLcontext * ctx,
 
         if (stImage->pt && i + 1 < depth) {
             /* unmap this slice */
-           st_texture_image_unmap(ctx->st, stImage);
+           st_texture_image_unmap(st, stImage);
             /* map next slice of 3D texture */
-           texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
+           texImage->Data = st_texture_image_map(st, stImage, i + 1,
                                                   transfer_usage, 0, 0,
                                                   stImage->base.Width,
                                                   stImage->base.Height);
@@ -732,7 +766,7 @@ done:
    _mesa_unmap_teximage_pbo(ctx, unpack);
 
    if (stImage->pt && texImage->Data) {
-      st_texture_image_unmap(ctx->st, stImage);
+      st_texture_image_unmap(st, stImage);
       texImage->Data = NULL;
    }
 }
@@ -809,16 +843,24 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
                      struct gl_texture_object *texObj,
                      struct gl_texture_image *texImage)
 {
-   struct pipe_screen *screen = ctx->st->pipe->screen;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_screen *screen = pipe->screen;
    struct st_texture_image *stImage = st_texture_image(texImage);
+   struct st_texture_object *stObj = st_texture_object(texObj);
+   struct pipe_sampler_view *src_view =
+      st_get_texture_sampler_view(stObj, pipe);
    const GLuint width = texImage->Width;
    const GLuint height = texImage->Height;
    struct pipe_surface *dst_surface;
-   struct pipe_texture *dst_texture;
+   struct pipe_resource *dst_texture;
    struct pipe_transfer *tex_xfer;
+   unsigned bind = (PIPE_BIND_BLIT_DESTINATION |
+                   PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
+                   PIPE_BIND_TRANSFER_READ);
 
    /* create temp / dest surface */
-   if (!util_create_rgba_surface(screen, width, height,
+   if (!util_create_rgba_surface(screen, width, height, bind,
                                  &dst_texture, &dst_surface)) {
       _mesa_problem(ctx, "util_create_rgba_surface() failed "
                     "in decompress_with_blit()");
@@ -826,8 +868,8 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
    }
 
    /* blit/render/decompress */
-   util_blit_pixels_tex(ctx->st->blit,
-                        stImage->pt,      /* pipe_texture (src) */
+   util_blit_pixels_tex(st->blit,
+                        src_view,      /* pipe_resource (src) */
                         0, 0,             /* src x0, y0 */
                         width, height,    /* src x1, y1 */
                         dst_surface,      /* pipe_surface (dst) */
@@ -848,7 +890,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
    if (st_equal_formats(stImage->pt->format, format, type)) {
       /* memcpy */
       const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
-      ubyte *map = screen->transfer_map(screen, tex_xfer);
+      ubyte *map = pipe_transfer_map(pipe, tex_xfer);
       GLuint row;
       for (row = 0; row < height; row++) {
          GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
@@ -856,7 +898,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
          memcpy(dest, map, bytesPerRow);
          map += tex_xfer->stride;
       }
-      screen->transfer_unmap(screen, tex_xfer);
+      pipe_transfer_unmap(pipe, tex_xfer);
    }
    else {
       /* format translation via floats */
@@ -871,7 +913,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
             debug_printf("%s: fallback format translation\n", __FUNCTION__);
 
          /* get float[4] rgba row from surface */
-         pipe_get_tile_rgba(tex_xfer, 0, row, width, 1, rgba);
+         pipe_get_tile_rgba(pipe, tex_xfer, 0, row, width, 1, rgba);
 
          _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
                                     type, dest, &ctx->Pack, transferOps);
@@ -880,7 +922,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
 
    _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
 
-   screen->tex_transfer_destroy(tex_xfer);
+   pipe->transfer_destroy(pipe, tex_xfer);
 
    /* destroy the temp / dest surface */
    util_destroy_rgba_surface(dst_texture, dst_surface);
@@ -898,6 +940,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
                  struct gl_texture_object *texObj,
                  struct gl_texture_image *texImage, GLboolean compressed_dst)
 {
+   struct st_context *st = st_context(ctx);
    struct st_texture_image *stImage = st_texture_image(texImage);
    const GLuint dstImageStride =
       _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
@@ -906,7 +949,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
    GLubyte *dest;
 
    if (stImage->pt &&
-       util_format_is_compressed(stImage->pt->format) &&
+       util_format_is_s3tc(stImage->pt->format) &&
        !compressed_dst) {
       /* Need to decompress the texture.
        * We'll do this by rendering a textured quad.
@@ -924,10 +967,10 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
        */
       unsigned face = _mesa_tex_target_to_face(target);
 
-      st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
+      st_teximage_flush_before_map(st, stImage->pt, face, level,
                                   PIPE_TRANSFER_READ);
 
-      texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
+      texImage->Data = st_texture_image_map(st, stImage, 0,
                                             PIPE_TRANSFER_READ, 0, 0,
                                             stImage->base.Width,
                                             stImage->base.Height);
@@ -965,9 +1008,9 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
 
       if (stImage->pt && i + 1 < depth) {
          /* unmap this slice */
-        st_texture_image_unmap(ctx->st, stImage);
+        st_texture_image_unmap(st, stImage);
          /* map next slice of 3D texture */
-        texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
+        texImage->Data = st_texture_image_map(st, stImage, i + 1,
                                                PIPE_TRANSFER_READ, 0, 0,
                                                stImage->base.Width,
                                                stImage->base.Height);
@@ -979,7 +1022,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
 
    /* Unmap */
    if (stImage->pt) {
-      st_texture_image_unmap(ctx->st, stImage);
+      st_texture_image_unmap(st, stImage);
       texImage->Data = NULL;
    }
 }
@@ -1017,7 +1060,8 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
                struct gl_texture_object *texObj,
                struct gl_texture_image *texImage)
 {
-   struct pipe_screen *screen = ctx->st->pipe->screen;
+   struct st_context *st = st_context(ctx);
+   struct pipe_screen *screen = st->pipe->screen;
    struct st_texture_image *stImage = st_texture_image(texImage);
    GLuint dstRowStride;
    const GLuint srcImageStride =
@@ -1044,7 +1088,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
        screen->is_format_supported(screen,
                                    stImage->pt->format,
                                    stImage->pt->target,
-                                   PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+                                   PIPE_BIND_RENDER_TARGET, 0)) {
       if (compress_with_blit(ctx, target, level,
                              xoffset, yoffset, zoffset,
                              width, height, depth,
@@ -1065,9 +1109,9 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
       else
          transfer_usage = PIPE_TRANSFER_WRITE;
 
-      st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
+      st_teximage_flush_before_map(st, stImage->pt, face, level,
                                   transfer_usage);
-      texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, 
+      texImage->Data = st_texture_image_map(st, stImage, zoffset, 
                                             transfer_usage,
                                             xoffset, yoffset,
                                             width, height);
@@ -1095,9 +1139,9 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
 
       if (stImage->pt && i + 1 < depth) {
          /* unmap this slice */
-        st_texture_image_unmap(ctx->st, stImage);
+        st_texture_image_unmap(st, stImage);
          /* map next slice of 3D texture */
-        texImage->Data = st_texture_image_map(ctx->st, stImage,
+        texImage->Data = st_texture_image_map(st, stImage,
                                                zoffset + i + 1,
                                                transfer_usage,
                                                xoffset, yoffset,
@@ -1110,7 +1154,7 @@ done:
    _mesa_unmap_teximage_pbo(ctx, packing);
 
    if (stImage->pt && texImage->Data) {
-      st_texture_image_unmap(ctx->st, stImage);
+      st_texture_image_unmap(st, stImage);
       texImage->Data = NULL;
    }
 }
@@ -1181,18 +1225,20 @@ st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
                            struct gl_texture_object *texObj,
                            struct gl_texture_image *texImage)
 {
+   struct st_context *st = st_context(ctx);
    struct st_texture_image *stImage = st_texture_image(texImage);
    int srcBlockStride;
    int dstBlockStride;
    int y;
-   enum pipe_format pformat= stImage->pt->format;
+   enum pipe_format pformat;
 
    if (stImage->pt) {
       unsigned face = _mesa_tex_target_to_face(target);
+      pformat = stImage->pt->format;
 
-      st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
+      st_teximage_flush_before_map(st, stImage->pt, face, level,
                                   PIPE_TRANSFER_WRITE);
-      texImage->Data = st_texture_image_map(ctx->st, stImage, 0, 
+      texImage->Data = st_texture_image_map(st, stImage, 0, 
                                             PIPE_TRANSFER_WRITE,
                                             xoffset, yoffset,
                                             width, height);
@@ -1224,7 +1270,7 @@ st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
    }
 
    if (stImage->pt) {
-      st_texture_image_unmap(ctx->st, stImage);
+      st_texture_image_unmap(st, stImage);
       texImage->Data = NULL;
    }
 }
@@ -1260,8 +1306,8 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
                           GLint srcX, GLint srcY,
                           GLsizei width, GLsizei height)
 {
-   struct pipe_context *pipe = ctx->st->pipe;
-   struct pipe_screen *screen = pipe->screen;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
    struct pipe_transfer *src_trans;
    GLvoid *texDest;
    enum pipe_transfer_usage transfer_usage;
@@ -1289,10 +1335,10 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
    else
       transfer_usage = PIPE_TRANSFER_WRITE;
 
-   st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0,
+   st_teximage_flush_before_map(st, stImage->pt, 0, 0,
                                transfer_usage);
 
-   texDest = st_texture_image_map(ctx->st, stImage, 0, transfer_usage,
+   texDest = st_texture_image_map(st, stImage, 0, transfer_usage,
                                   destX, destY, width, height);
 
    if (baseFormat == GL_DEPTH_COMPONENT ||
@@ -1314,11 +1360,11 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
       /* To avoid a large temp memory allocation, do copy row by row */
       for (row = 0; row < height; row++, srcY += yStep) {
          uint data[MAX_WIDTH];
-         pipe_get_tile_z(src_trans, 0, srcY, width, 1, data);
+         pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
          if (scaleOrBias) {
             _mesa_scale_and_bias_depth_uint(ctx, width, data);
          }
-         pipe_put_tile_z(stImage->transfer, 0, row, width, 1, data);
+         pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
       }
    }
    else {
@@ -1340,7 +1386,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
          /* XXX this usually involves a lot of int/float conversion.
           * try to avoid that someday.
           */
-         pipe_get_tile_rgba(src_trans, 0, 0, width, height, tempSrc);
+         pipe_get_tile_rgba(pipe, src_trans, 0, 0, width, height, tempSrc);
 
          /* Store into texture memory.
           * Note that this does some special things such as pixel transfer
@@ -1367,8 +1413,8 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
          free(tempSrc);
    }
 
-   st_texture_image_unmap(ctx->st, stImage);
-   screen->tex_transfer_destroy(src_trans);
+   st_texture_image_unmap(st, stImage);
+   pipe->transfer_destroy(pipe, src_trans);
 }
 
 
@@ -1463,7 +1509,8 @@ st_copy_texsubimage(GLcontext *ctx,
    const GLenum texBaseFormat = texImage->_BaseFormat;
    struct gl_framebuffer *fb = ctx->ReadBuffer;
    struct st_renderbuffer *strb;
-   struct pipe_context *pipe = ctx->st->pipe;
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
    struct pipe_screen *screen = pipe->screen;
    enum pipe_format dest_format, src_format;
    GLboolean use_fallback = GL_TRUE;
@@ -1473,11 +1520,11 @@ st_copy_texsubimage(GLcontext *ctx,
    GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
 
    /* any rendering in progress must flushed before we grab the fb image */
-   st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
+   st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
 
    /* make sure finalize_textures has been called? 
     */
-   if (0) st_validate_state(ctx->st);
+   if (0) st_validate_state(st);
 
    /* determine if copying depth or color data */
    if (texBaseFormat == GL_DEPTH_COMPONENT ||
@@ -1544,8 +1591,7 @@ st_copy_texsubimage(GLcontext *ctx,
 
    if (ctx->_ImageTransferState == 0x0) {
 
-      if (pipe->surface_copy &&
-          matching_base_formats &&
+      if (matching_base_formats &&
           src_format == dest_format &&
           !do_flip) 
       {
@@ -1554,7 +1600,7 @@ st_copy_texsubimage(GLcontext *ctx,
          dest_surface = screen->get_tex_surface(screen, stImage->pt,
                                                 stImage->face, stImage->level,
                                                 destZ,
-                                                PIPE_BUFFER_USAGE_GPU_WRITE);
+                                                PIPE_BIND_BLIT_DESTINATION);
 
          /* for surface_copy(), y=0=top, always */
          pipe->surface_copy(pipe,
@@ -1573,11 +1619,11 @@ st_copy_texsubimage(GLcontext *ctx,
                texBaseFormat != GL_DEPTH_STENCIL &&
                screen->is_format_supported(screen, src_format,
                                            PIPE_TEXTURE_2D, 
-                                           PIPE_TEXTURE_USAGE_SAMPLER,
+                                           PIPE_BIND_SAMPLER_VIEW,
                                            0) &&
                screen->is_format_supported(screen, dest_format,
                                            PIPE_TEXTURE_2D, 
-                                           PIPE_TEXTURE_USAGE_RENDER_TARGET,
+                                           PIPE_BIND_RENDER_TARGET,
                                            0)) {
          /* draw textured quad to do the copy */
          GLint srcY0, srcY1;
@@ -1585,7 +1631,7 @@ st_copy_texsubimage(GLcontext *ctx,
          dest_surface = screen->get_tex_surface(screen, stImage->pt,
                                                 stImage->face, stImage->level,
                                                 destZ,
-                                                PIPE_BUFFER_USAGE_GPU_WRITE);
+                                                PIPE_BIND_BLIT_DESTINATION);
 
          if (do_flip) {
             srcY1 = strb->Base.Height - srcY - height;
@@ -1595,8 +1641,9 @@ st_copy_texsubimage(GLcontext *ctx,
             srcY0 = srcY;
             srcY1 = srcY0 + height;
          }
-         util_blit_pixels_writemask(ctx->st->blit,
+         util_blit_pixels_writemask(st->blit,
                                     strb->surface,
+                                    st_get_renderbuffer_sampler_view(strb, pipe),
                                     srcX, srcY0,
                                     srcX + width, srcY1,
                                     dest_surface,
@@ -1724,7 +1771,7 @@ copy_image_data_to_texture(struct st_context *st,
                             stImage->pt, /* src texture */
                             stImage->face);
 
-      pipe_texture_reference(&stImage->pt, NULL);
+      pipe_resource_reference(&stImage->pt, NULL);
    }
    else if (stImage->base.Data) {
       /* More straightforward upload.  
@@ -1746,7 +1793,7 @@ copy_image_data_to_texture(struct st_context *st,
       stImage->base.Data = NULL;
    }
 
-   pipe_texture_reference(&stImage->pt, stObj->pt);
+   pipe_resource_reference(&stImage->pt, stObj->pt);
 }
 
 
@@ -1761,6 +1808,7 @@ st_finalize_texture(GLcontext *ctx,
                    struct gl_texture_object *tObj,
                    GLboolean *needFlush)
 {
+   struct st_context *st = st_context(ctx);
    struct st_texture_object *stObj = st_texture_object(tObj);
    const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
    GLuint blockSize, face;
@@ -1792,7 +1840,8 @@ st_finalize_texture(GLcontext *ctx,
    if (firstImage->pt &&
        firstImage->pt != stObj->pt &&
        firstImage->pt->last_level >= stObj->lastLevel) {
-      pipe_texture_reference(&stObj->pt, firstImage->pt);
+      pipe_resource_reference(&stObj->pt, firstImage->pt);
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
    }
 
    /* bytes per pixel block (blocks are usually 1x1) */
@@ -1811,8 +1860,9 @@ st_finalize_texture(GLcontext *ctx,
           stObj->pt->height0 != firstImage->base.Height2 ||
           stObj->pt->depth0 != firstImage->base.Depth2)
       {
-         pipe_texture_reference(&stObj->pt, NULL);
-         ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
+         pipe_resource_reference(&stObj->pt, NULL);
+         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+         st->dirty.st |= ST_NEW_FRAMEBUFFER;
       }
    }
 
@@ -1821,16 +1871,16 @@ st_finalize_texture(GLcontext *ctx,
    if (!stObj->pt) {
       const enum pipe_format fmt =
          st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
-      GLuint usage = default_usage(fmt);
+      GLuint bindings = default_bindings(st, fmt);
 
-      stObj->pt = st_texture_create(ctx->st,
+      stObj->pt = st_texture_create(st,
                                     gl_target_to_pipe(stObj->base.Target),
                                     fmt,
                                     stObj->lastLevel,
                                     firstImage->base.Width2,
                                     firstImage->base.Height2,
                                     firstImage->base.Depth2,
-                                    usage);
+                                    bindings);
 
       if (!stObj->pt) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
@@ -1849,7 +1899,7 @@ st_finalize_texture(GLcontext *ctx,
          /* Need to import images in main memory or held in other textures.
           */
          if (stImage && stObj->pt != stImage->pt) {
-            copy_image_data_to_texture(ctx->st, stObj, level, stImage);
+            copy_image_data_to_texture(st, stObj, level, stImage);
            *needFlush = GL_TRUE;
          }
       }