Mesa (gallium-resources): gallium: change remaining util functions to use cso sampler views

Keith Whitwell keithw at kemper.freedesktop.org
Wed Mar 17 08:46:58 UTC 2010


Module: Mesa
Branch: gallium-resources
Commit: 8f55a95178069d5e8b18647e6b675fc403d68073
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8f55a95178069d5e8b18647e6b675fc403d68073

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Mon Mar 15 21:55:08 2010 +0100

gallium: change remaining util functions to use cso sampler views

changes arguments of util_blit_pixels_tex and util_gen_mipmap to
struct pipe_sampler_view * instead of struct pipe_texture *.

---

 src/gallium/auxiliary/util/u_blit.c       |   22 ++++++++++++----------
 src/gallium/auxiliary/util/u_blit.h       |    2 +-
 src/gallium/auxiliary/util/u_gen_mipmap.c |   13 +++++++------
 src/gallium/auxiliary/util/u_gen_mipmap.h |    2 +-
 src/mesa/state_tracker/st_cb_texture.c    |   18 +++++++++++++++---
 src/mesa/state_tracker/st_gen_mipmap.c    |   11 ++++++-----
 6 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index 4d9168f..cd95f85 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -555,21 +555,23 @@ void util_blit_flush( struct blit_state *ctx )
  */
 void
 util_blit_pixels_tex(struct blit_state *ctx,
-                 struct pipe_texture *tex,
-                 int srcX0, int srcY0,
-                 int srcX1, int srcY1,
-                 struct pipe_surface *dst,
-                 int dstX0, int dstY0,
-                 int dstX1, int dstY1,
-                 float z, uint filter)
+                     struct pipe_sampler_view *src_sampler_view,
+                     int srcX0, int srcY0,
+                     int srcX1, int srcY1,
+                     struct pipe_surface *dst,
+                     int dstX0, int dstY0,
+                     int dstX1, int dstY1,
+                     float z, uint filter)
 {
    struct pipe_framebuffer_state fb;
    float s0, t0, s1, t1;
    unsigned offset;
+   struct pipe_texture *tex = src_sampler_view->texture;
 
    assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
           filter == PIPE_TEX_MIPFILTER_LINEAR);
 
+   assert(tex);
    assert(tex->width0 != 0);
    assert(tex->height0 != 0);
 
@@ -588,7 +590,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
    cso_save_depth_stencil_alpha(ctx->cso);
    cso_save_rasterizer(ctx->cso);
    cso_save_samplers(ctx->cso);
-   cso_save_sampler_textures(ctx->cso);
+   cso_save_fragment_sampler_views(ctx->cso);
    cso_save_framebuffer(ctx->cso);
    cso_save_fragment_shader(ctx->cso);
    cso_save_vertex_shader(ctx->cso);
@@ -620,7 +622,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
    cso_set_viewport(ctx->cso, &ctx->viewport);
 
    /* texture */
-   cso_set_sampler_textures(ctx->cso, 1, &tex);
+   cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view);
 
    /* shaders */
    cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]);
@@ -654,7 +656,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
    cso_restore_depth_stencil_alpha(ctx->cso);
    cso_restore_rasterizer(ctx->cso);
    cso_restore_samplers(ctx->cso);
-   cso_restore_sampler_textures(ctx->cso);
+   cso_restore_fragment_sampler_views(ctx->cso);
    cso_restore_framebuffer(ctx->cso);
    cso_restore_fragment_shader(ctx->cso);
    cso_restore_vertex_shader(ctx->cso);
diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h
index 2d8cdd2..1ebe65b 100644
--- a/src/gallium/auxiliary/util/u_blit.h
+++ b/src/gallium/auxiliary/util/u_blit.h
@@ -75,7 +75,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
 
 extern void
 util_blit_pixels_tex(struct blit_state *ctx,
-                     struct pipe_texture *tex,
+                     struct pipe_sampler_view *src_sampler_view,
                      int srcX0, int srcY0,
                      int srcX1, int srcY1,
                      struct pipe_surface *dst,
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 5c51b53..61d64cf 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -1460,7 +1460,7 @@ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
  * Generate mipmap images.  It's assumed all needed texture memory is
  * already allocated.
  *
- * \param pt  the texture to generate mipmap levels for
+ * \param psv  the sampler view to the texture to generate mipmap levels for
  * \param face  which cube face to generate mipmaps for (0 for non-cube maps)
  * \param baseLevel  the first mipmap level to use as a src
  * \param lastLevel  the last mipmap level to generate
@@ -1469,12 +1469,13 @@ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
  */
 void
 util_gen_mipmap(struct gen_mipmap_state *ctx,
-                struct pipe_texture *pt,
+                struct pipe_sampler_view *psv,
                 uint face, uint baseLevel, uint lastLevel, uint filter)
 {
    struct pipe_context *pipe = ctx->pipe;
    struct pipe_screen *screen = pipe->screen;
    struct pipe_framebuffer_state fb;
+   struct pipe_texture *pt = psv->texture;
    void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d;
    uint dstLevel;
    uint zslice = 0;
@@ -1492,7 +1493,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
           filter == PIPE_TEX_FILTER_NEAREST);
 
    /* check if we can render in the texture's format */
-   if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D,
+   if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D,
                                     PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
       fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
       return;
@@ -1503,7 +1504,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_save_depth_stencil_alpha(ctx->cso);
    cso_save_rasterizer(ctx->cso);
    cso_save_samplers(ctx->cso);
-   cso_save_sampler_textures(ctx->cso);
+   cso_save_fragment_sampler_views(ctx->cso);
    cso_save_framebuffer(ctx->cso);
    cso_save_fragment_shader(ctx->cso);
    cso_save_vertex_shader(ctx->cso);
@@ -1572,7 +1573,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
       cso_single_sampler(ctx->cso, 0, &ctx->sampler);
       cso_single_sampler_done(ctx->cso);
 
-      cso_set_sampler_textures(ctx->cso, 1, &pt);
+      cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
 
       /* quad coords in clip coords */
       offset = set_vertex_data(ctx,
@@ -1597,7 +1598,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_restore_depth_stencil_alpha(ctx->cso);
    cso_restore_rasterizer(ctx->cso);
    cso_restore_samplers(ctx->cso);
-   cso_restore_sampler_textures(ctx->cso);
+   cso_restore_fragment_sampler_views(ctx->cso);
    cso_restore_framebuffer(ctx->cso);
    cso_restore_fragment_shader(ctx->cso);
    cso_restore_vertex_shader(ctx->cso);
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h
index 54608f9..35ac9da 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.h
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.h
@@ -59,7 +59,7 @@ util_gen_mipmap_flush( struct gen_mipmap_state *ctx );
 
 extern void
 util_gen_mipmap(struct gen_mipmap_state *ctx,
-                struct pipe_texture *pt,
+                struct pipe_sampler_view *psv,
                 uint face, uint baseLevel, uint lastLevel, uint filter);
 
 
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 0c518a7..6ed1c60 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -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;
 }
@@ -817,6 +828,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 +846,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) */
@@ -1457,7 +1470,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);
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index b252143..97f6903 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -79,22 +79,23 @@ st_destroy_generate_mipmap(struct st_context *st)
 static boolean
 st_render_mipmap(struct st_context *st,
                  GLenum target,
-                 struct pipe_texture *pt,
+                 struct st_texture_object *stObj,
                  uint baseLevel, uint lastLevel)
 {
    struct pipe_context *pipe = st->pipe;
    struct pipe_screen *screen = pipe->screen;
+   struct pipe_sampler_view *psv = st_get_stobj_sampler_view(stObj);
    const uint face = _mesa_tex_target_to_face(target);
 
    assert(target != GL_TEXTURE_3D); /* not done yet */
 
    /* check if we can render in the texture's format */
-   if (!screen->is_format_supported(screen, pt->format, pt->target,
+   if (!screen->is_format_supported(screen, psv->format, psv->texture->target,
                                     PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
       return FALSE;
    }
 
-   util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel,
+   util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel,
                    PIPE_TEX_FILTER_LINEAR);
 
    return TRUE;
@@ -211,6 +212,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
                    struct gl_texture_object *texObj)
 {
    struct st_context *st = ctx->st;
+   struct st_texture_object *stObj = st_texture_object(texObj);
    struct pipe_texture *pt = st_get_texobj_texture(texObj);
    const uint baseLevel = texObj->BaseLevel;
    uint lastLevel;
@@ -229,7 +231,6 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
       /* The current gallium texture doesn't have space for all the
        * mipmap levels we need to generate.  So allocate a new texture.
        */
-      struct st_texture_object *stObj = st_texture_object(texObj);
       struct pipe_texture *oldTex = stObj->pt;
       GLboolean needFlush;
 
@@ -264,7 +265,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target,
    /* Recall that the Mesa BaseLevel image is stored in the gallium
     * texture's level[0] position.  So pass baseLevel=0 here.
     */
-   if (!st_render_mipmap(st, target, pt, 0, lastLevel)) {
+   if (!st_render_mipmap(st, target, stObj, 0, lastLevel)) {
       fallback_generate_mipmap(ctx, target, texObj);
    }
 




More information about the mesa-commit mailing list