Merge branch '7.8' into master
[mesa.git] / src / mesa / state_tracker / st_cb_texture.c
index 0c518a7e031e0e53d2f5186918243f7a948594ec..84b78181a972d4bbed104f23c2fba449985eed5e 100644 (file)
@@ -63,6 +63,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"
 
 
@@ -380,6 +381,8 @@ compress_with_blit(GLcontext * ctx,
    gl_format mesa_format;
    struct pipe_texture templ;
    struct pipe_texture *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;
@@ -441,9 +444,16 @@ compress_with_blit(GLcontext * ctx,
    pipe->transfer_unmap(pipe, tex_xfer);
    pipe->tex_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) */
+                        src_view,         /* sampler view (src) */
                         0, 0,             /* src x0, y0 */
                         width, height,    /* src x1, y1 */
                         dst_surface,      /* pipe_surface (dst) */
@@ -455,6 +465,7 @@ compress_with_blit(GLcontext * ctx,
 
    pipe_surface_reference(&dst_surface, NULL);
    pipe_texture_reference(&src_tex, NULL);
+   pipe_sampler_view_reference(&src_view, NULL);
 
    return GL_TRUE;
 }
@@ -560,6 +571,7 @@ st_TexImage(GLcontext * ctx,
          DBG("release it\n");
          pipe_texture_reference(&stObj->pt, NULL);
          assert(!stObj->pt);
+         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
          stObj->teximage_realloc = FALSE;
       }
    }
@@ -817,6 +829,8 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
    struct pipe_context *pipe = ctx->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_stobj_sampler_view(stObj);
    const GLuint width = texImage->Width;
    const GLuint height = texImage->Height;
    struct pipe_surface *dst_surface;
@@ -833,7 +847,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
 
    /* blit/render/decompress */
    util_blit_pixels_tex(ctx->st->blit,
-                        stImage->pt,      /* pipe_texture (src) */
+                        src_view,      /* pipe_texture (src) */
                         0, 0,             /* src x0, y0 */
                         width, height,    /* src x1, y1 */
                         dst_surface,      /* pipe_surface (dst) */
@@ -886,6 +900,8 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
 
    _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
 
+   screen->tex_transfer_destroy(tex_xfer);
+
    /* destroy the temp / dest surface */
    util_destroy_rgba_surface(dst_texture, dst_surface);
 }
@@ -1457,7 +1473,6 @@ st_copy_texsubimage(GLcontext *ctx,
       &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
    struct gl_texture_object *texObj =
       _mesa_select_tex_object(ctx, texUnit, target);
-   struct st_texture_object *stObj = st_texture_object(texObj);
    struct gl_texture_image *texImage =
       _mesa_select_tex_image(ctx, texObj, target, level);
    struct st_texture_image *stImage = st_texture_image(texImage);
@@ -1795,6 +1810,7 @@ st_finalize_texture(GLcontext *ctx,
        firstImage->pt != stObj->pt &&
        firstImage->pt->last_level >= stObj->lastLevel) {
       pipe_texture_reference(&stObj->pt, firstImage->pt);
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
    }
 
    /* bytes per pixel block (blocks are usually 1x1) */
@@ -1814,6 +1830,7 @@ st_finalize_texture(GLcontext *ctx,
           stObj->pt->depth0 != firstImage->base.Depth2)
       {
          pipe_texture_reference(&stObj->pt, NULL);
+         pipe_sampler_view_reference(&stObj->sampler_view, NULL);
          ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
       }
    }