Michal,

Is the intention to have >1 sampler view active in the Mesa state
tracker, specifically in the cases where min_lod varies?

In other words, you seem to have two ways of specifying the same state: 

  pipe_sampler_view::first_level

and

  pipe_sampler::min_lod

Is there a case to keep both of these?  Or is one enough?

Keith

On Fri, 2010-03-12 at 05:39 -0800, Micha?? Kr??l wrote:
> Module: Mesa
> Branch: gallium-sampler-view
> Commit: b8030c6561e019e079b5be2fe64ec804df4bfa03
> URL:    
> http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8030c6561e019e079b5be2fe64ec804df4bfa03
> 
> Author: Michal Krol <mic...@vmware.com>
> Date:   Fri Mar 12 14:37:36 2010 +0100
> 
> st/mesa: Associate a sampler view with an st texture object.
> 
> Lazily create a sampler view when the texture is being bound
> for the first time.
> 
> ---
> 
>  src/mesa/state_tracker/st_atom_pixeltransfer.c |    2 +
>  src/mesa/state_tracker/st_atom_texture.c       |   20 +++++-----
>  src/mesa/state_tracker/st_cb_bitmap.c          |   48 +++++++++++++++--------
>  src/mesa/state_tracker/st_cb_drawpixels.c      |   46 ++++++++++++++--------
>  src/mesa/state_tracker/st_cb_texture.c         |    4 ++
>  src/mesa/state_tracker/st_context.c            |    4 +-
>  src/mesa/state_tracker/st_context.h            |    3 +-
>  src/mesa/state_tracker/st_texture.h            |   39 +++++++++++++++++++
>  8 files changed, 119 insertions(+), 47 deletions(-)
> 
> diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c 
> b/src/mesa/state_tracker/st_atom_pixeltransfer.c
> index 0b2e3f5..e766b3a 100644
> --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c
> +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c
> @@ -257,6 +257,8 @@ get_pixel_transfer_program(GLcontext *ctx, const struct 
> state_key *key)
>        /* create the colormap/texture now if not already done */
>        if (!st->pixel_xfer.pixelmap_texture) {
>           st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
> +         st->pixel_xfer.pixelmap_sampler_view = 
> st_sampler_view_from_texture(ctx->st->pipe,
> +                                                                             
> st->pixel_xfer.pixelmap_texture);
>        }
> 
>        /* with a little effort, we can do four pixel map look-ups with
> diff --git a/src/mesa/state_tracker/st_atom_texture.c 
> b/src/mesa/state_tracker/st_atom_texture.c
> index 57b71c1..241c001 100644
> --- a/src/mesa/state_tracker/st_atom_texture.c
> +++ b/src/mesa/state_tracker/st_atom_texture.c
> @@ -56,7 +56,7 @@ update_textures(struct st_context *st)
> 
>     /* loop over sampler units (aka tex image units) */
>     for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) {
> -      struct pipe_texture *pt = NULL;
> +      struct pipe_sampler_view *sampler_view = NULL;
> 
>        if (samplersUsed & (1 << su)) {
>           struct gl_texture_object *texObj;
> @@ -84,7 +84,7 @@ update_textures(struct st_context *st)
> 
>           st->state.num_textures = su + 1;
> 
> -         pt = st_get_stobj_texture(stObj);
> +         sampler_view = st_get_stobj_sampler_view(stObj);
>        }
> 
>        /*
> @@ -96,17 +96,17 @@ update_textures(struct st_context *st)
>        }
>        */
> 
> -      pipe_texture_reference(&st->state.sampler_texture[su], pt);
> +      pipe_sampler_view_reference(&st->state.sampler_views[su], 
> sampler_view);
>     }
> 
> -   cso_set_sampler_textures(st->cso_context,
> -                            st->state.num_textures,
> -                            st->state.sampler_texture);
> +   cso_set_fragment_sampler_views(st->cso_context,
> +                                  st->state.num_textures,
> +                                  st->state.sampler_views);
>     if (st->ctx->Const.MaxVertexTextureImageUnits > 0) {
> -      cso_set_vertex_sampler_textures(st->cso_context,
> -                                      MIN2(st->state.num_textures,
> -                                           
> st->ctx->Const.MaxVertexTextureImageUnits),
> -                                      st->state.sampler_texture);
> +      cso_set_vertex_sampler_views(st->cso_context,
> +                                   MIN2(st->state.num_textures,
> +                                        
> st->ctx->Const.MaxVertexTextureImageUnits),
> +                                   st->state.sampler_views);
>     }
>  }
> 
> diff --git a/src/mesa/state_tracker/st_cb_bitmap.c 
> b/src/mesa/state_tracker/st_cb_bitmap.c
> index f326601..25d33b9 100644
> --- a/src/mesa/state_tracker/st_cb_bitmap.c
> +++ b/src/mesa/state_tracker/st_cb_bitmap.c
> @@ -398,7 +398,7 @@ setup_bitmap_vertex_data(struct st_context *st,
>  static void
>  draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
>                   GLsizei width, GLsizei height,
> -                 struct pipe_texture *pt,
> +                 struct pipe_sampler_view *sv,
>                   const GLfloat *color)
>  {
>     struct st_context *st = ctx->st;
> @@ -436,7 +436,7 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, 
> GLfloat z,
> 
>     cso_save_rasterizer(cso);
>     cso_save_samplers(cso);
> -   cso_save_sampler_textures(cso);
> +   cso_save_fragment_sampler_views(cso);
>     cso_save_viewport(cso);
>     cso_save_fragment_shader(cso);
>     cso_save_vertex_shader(cso);
> @@ -466,11 +466,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, 
> GLfloat z,
> 
>     /* user textures, plus the bitmap texture */
>     {
> -      struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
> +      struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
>        uint num = MAX2(stfp->bitmap_sampler + 1, st->state.num_textures);
> -      memcpy(textures, st->state.sampler_texture, sizeof(textures));
> -      textures[stfp->bitmap_sampler] = pt;
> -      cso_set_sampler_textures(cso, num, textures);
> +      memcpy(sampler_views, st->state.sampler_views, sizeof(sampler_views));
> +      sampler_views[stfp->bitmap_sampler] = sv;
> +      cso_set_fragment_sampler_views(cso, num, sampler_views);
>     }
> 
>     /* viewport state: viewport matching window dims */
> @@ -508,7 +508,7 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, 
> GLfloat z,
>     /* restore state */
>     cso_restore_rasterizer(cso);
>     cso_restore_samplers(cso);
> -   cso_restore_sampler_textures(cso);
> +   cso_restore_fragment_sampler_views(cso);
>     cso_restore_viewport(cso);
>     cso_restore_fragment_shader(cso);
>     cso_restore_vertex_shader(cso);
> @@ -602,6 +602,7 @@ st_flush_bitmap_cache(struct st_context *st)
>        if (st->ctx->DrawBuffer) {
>           struct pipe_context *pipe = st->pipe;
>           struct pipe_screen *screen = pipe->screen;
> +         struct pipe_sampler_view *sv;
> 
>           assert(cache->xmin <= cache->xmax);
> 
> @@ -624,13 +625,18 @@ st_flush_bitmap_cache(struct st_context *st)
>              cache->trans = NULL;
>           }
> 
> -         draw_bitmap_quad(st->ctx,
> -                          cache->xpos,
> -                          cache->ypos,
> -                          cache->zpos,
> -                          BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
> -                          cache->texture,
> -                          cache->color);
> +         sv = st_sampler_view_from_texture(st->pipe, cache->texture);
> +         if (sv) {
> +            draw_bitmap_quad(st->ctx,
> +                             cache->xpos,
> +                             cache->ypos,
> +                             cache->zpos,
> +                             BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
> +                             sv,
> +                             cache->color);
> +
> +            pipe_sampler_view_reference(&sv, NULL);
> +         }
>        }
> 
>        /* release/free the texture */
> @@ -753,10 +759,18 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei 
> width, GLsizei height,
> 
>     pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
>     if (pt) {
> +      struct pipe_sampler_view *sv = st_sampler_view_from_texture(st->pipe, 
> pt);
> +
>        assert(pt->target == PIPE_TEXTURE_2D);
> -      draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
> -                       width, height, pt,
> -                       st->ctx->Current.RasterColor);
> +
> +      if (sv) {
> +         draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
> +                          width, height, sv,
> +                          st->ctx->Current.RasterColor);
> +
> +         pipe_sampler_view_reference(&sv, NULL);
> +      }
> +
>        /* release/free the texture */
>        pipe_texture_reference(&pt, NULL);
>     }
> diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c 
> b/src/mesa/state_tracker/st_cb_drawpixels.c
> index d542c99..236010c 100644
> --- a/src/mesa/state_tracker/st_cb_drawpixels.c
> +++ b/src/mesa/state_tracker/st_cb_drawpixels.c
> @@ -503,7 +503,7 @@ static void
>  draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
>                     GLsizei width, GLsizei height,
>                     GLfloat zoomX, GLfloat zoomY,
> -                   struct pipe_texture *pt,
> +                   struct pipe_sampler_view *sv,
>                     void *driver_vp,
>                     void *driver_fp,
>                     const GLfloat *color,
> @@ -526,7 +526,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, 
> GLfloat z,
>     cso_save_rasterizer(cso);
>     cso_save_viewport(cso);
>     cso_save_samplers(cso);
> -   cso_save_sampler_textures(cso);
> +   cso_save_fragment_sampler_views(cso);
>     cso_save_fragment_shader(cso);
>     cso_save_vertex_shader(cso);
>     cso_save_vertex_elements(cso);
> @@ -586,13 +586,13 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, 
> GLfloat z,
> 
>     /* texture state: */
>     if (st->pixel_xfer.pixelmap_enabled) {
> -      struct pipe_texture *textures[2];
> -      textures[0] = pt;
> -      textures[1] = st->pixel_xfer.pixelmap_texture;
> -      cso_set_sampler_textures(cso, 2, textures);
> +      struct pipe_sampler_view *sampler_views[2];
> +      sampler_views[0] = sv;
> +      sampler_views[1] = st->pixel_xfer.pixelmap_sampler_view;
> +      cso_set_fragment_sampler_views(cso, 2, sampler_views);
>     }
>     else {
> -      cso_set_sampler_textures(cso, 1, &pt);
> +      cso_set_fragment_sampler_views(cso, 1, &sv);
>     }
> 
>     /* Compute window coords (y=0=bottom) with pixel zoom.
> @@ -608,14 +608,14 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, 
> GLfloat z,
>     z = z * 2.0 - 1.0;
> 
>     draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex,
> -            (GLfloat) width / pt->width0,
> -            (GLfloat) height / pt->height0);
> +             (GLfloat) width / sv->texture->width0,
> +             (GLfloat) height / sv->texture->height0);
> 
>     /* restore state */
>     cso_restore_rasterizer(cso);
>     cso_restore_viewport(cso);
>     cso_restore_samplers(cso);
> -   cso_restore_sampler_textures(cso);
> +   cso_restore_fragment_sampler_views(cso);
>     cso_restore_fragment_shader(cso);
>     cso_restore_vertex_shader(cso);
>     cso_restore_vertex_elements(cso);
> @@ -809,12 +809,17 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei 
> width, GLsizei height,
>        struct pipe_texture *pt
>           = make_texture(st, width, height, format, type, unpack, pixels);
>        if (pt) {
> -         draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
> -                            width, height, ctx->Pixel.ZoomX, 
> ctx->Pixel.ZoomY,
> -                            pt,
> -                            driver_vp,
> -                            driver_fp,
> -                            color, GL_FALSE);
> +         struct pipe_sampler_view *sv = 
> st_sampler_view_from_texture(st->pipe, pt);
> +
> +         if (sv) {
> +            draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2],
> +                               width, height, ctx->Pixel.ZoomX, 
> ctx->Pixel.ZoomY,
> +                               sv,
> +                               driver_vp,
> +                               driver_fp,
> +                               color, GL_FALSE);
> +            pipe_sampler_view_reference(&sv, NULL);
> +         }
>           pipe_texture_reference(&pt, NULL);
>        }
>     }
> @@ -933,6 +938,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
>     struct st_renderbuffer *rbRead;
>     void *driver_vp, *driver_fp;
>     struct pipe_texture *pt;
> +   struct pipe_sampler_view *sv;
>     GLfloat *color;
>     enum pipe_format srcFormat, texFormat;
>     int ptw, pth;
> @@ -1050,6 +1056,11 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
>     if (!pt)
>        return;
> 
> +   sv = st_sampler_view_from_texture(st->pipe, pt);
> +   if (!sv) {
> +      pipe_texture_reference(&pt, NULL);
> +      return;
> +   }
> 
>     if (srcFormat == texFormat) {
>        /* copy source framebuffer surface into mipmap/texture */
> @@ -1118,12 +1129,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
>     /* draw textured quad */
>     draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2],
>                        width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY,
> -                      pt,
> +                      sv,
>                        driver_vp,
>                        driver_fp,
>                        color, GL_TRUE);
> 
>     pipe_texture_reference(&pt, NULL);
> +   pipe_sampler_view_reference(&sv, NULL);
>  }
> 
> 
> diff --git a/src/mesa/state_tracker/st_cb_texture.c 
> b/src/mesa/state_tracker/st_cb_texture.c
> index c849132..7684656 100644
> --- a/src/mesa/state_tracker/st_cb_texture.c
> +++ b/src/mesa/state_tracker/st_cb_texture.c
> @@ -123,6 +123,8 @@ st_DeleteTextureObject(GLcontext *ctx,
>     struct st_texture_object *stObj = st_texture_object(texObj);
>     if (stObj->pt)
>        pipe_texture_reference(&stObj->pt, NULL);
> +   if (stObj->sampler_view)
> +      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
> 
>     _mesa_delete_texture_object(ctx, texObj);
>  }
> @@ -312,6 +314,8 @@ guess_and_alloc_texture(struct st_context *st,
>                                   depth,
>                                   usage);
> 
> +   stObj->pipe = st->pipe;
> +
>     DBG("%s - success\n", __FUNCTION__);
>  }
> 
> diff --git a/src/mesa/state_tracker/st_context.c 
> b/src/mesa/state_tracker/st_context.c
> index 09f891d..e978415 100644
> --- a/src/mesa/state_tracker/st_context.c
> +++ b/src/mesa/state_tracker/st_context.c
> @@ -215,8 +215,8 @@ static void st_destroy_context_priv( struct st_context 
> *st )
>     st_destroy_drawtex(st);
>  #endif
> 
> -   for (i = 0; i < Elements(st->state.sampler_texture); i++) {
> -      pipe_texture_reference(&st->state.sampler_texture[i], NULL);
> +   for (i = 0; i < Elements(st->state.sampler_views); i++) {
> +      pipe_sampler_view_reference(&st->state.sampler_views[i], NULL);
>     }
> 
>     for (i = 0; i < Elements(st->state.constants); i++) {
> diff --git a/src/mesa/state_tracker/st_context.h 
> b/src/mesa/state_tracker/st_context.h
> index 6622361..ae73817 100644
> --- a/src/mesa/state_tracker/st_context.h
> +++ b/src/mesa/state_tracker/st_context.h
> @@ -94,7 +94,7 @@ struct st_context
>        struct pipe_clip_state clip;
>        struct pipe_buffer *constants[2];
>        struct pipe_framebuffer_state framebuffer;
> -      struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS];
> +      struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
>        struct pipe_scissor_state scissor;
>        struct pipe_viewport_state viewport;
> 
> @@ -141,6 +141,7 @@ struct st_context
>        struct st_fragment_program *combined_prog;
>        GLuint combined_prog_sn;
>        struct pipe_texture *pixelmap_texture;
> +      struct pipe_sampler_view *pixelmap_sampler_view;
>        boolean pixelmap_enabled;  /**< use the pixelmap texture? */
>     } pixel_xfer;
> 
> diff --git a/src/mesa/state_tracker/st_texture.h 
> b/src/mesa/state_tracker/st_texture.h
> index 60868ce..c62f7f2 100644
> --- a/src/mesa/state_tracker/st_texture.h
> +++ b/src/mesa/state_tracker/st_texture.h
> @@ -29,6 +29,9 @@
>  #define ST_TEXTURE_H
> 
> 
> +#include "pipe/p_context.h"
> +#include "util/u_sampler.h"
> +
>  #include "main/mtypes.h"
> 
>  struct pipe_context;
> @@ -68,6 +71,13 @@ struct st_texture_object
>      */
>     struct pipe_texture *pt;
> 
> +   /* Default sampler view attached to this texture object. Created lazily
> +    * on first binding.
> +    */
> +   struct pipe_sampler_view *sampler_view;
> +
> +   struct pipe_context *pipe;
> +
>     GLboolean teximage_realloc;
> 
>     /* True if there is/was a surface bound to this texture object.  It helps
> @@ -105,6 +115,35 @@ st_get_stobj_texture(struct st_texture_object *stObj)
>  }
> 
> 
> +static INLINE struct pipe_sampler_view *
> +st_sampler_view_from_texture(struct pipe_context *pipe,
> +                             struct pipe_texture *texture)
> +{
> +   struct pipe_sampler_view templ;
> +
> +   u_sampler_view_default_template(&templ,
> +                                   texture,
> +                                   texture->format);
> +
> +   return pipe->create_sampler_view(pipe, texture, &templ);
> +}
> +
> +
> +static INLINE struct pipe_sampler_view *
> +st_get_stobj_sampler_view(struct st_texture_object *stObj)
> +{
> +   if (!stObj || !stObj->pt) {
> +      return NULL;
> +   }
> +
> +   if (!stObj->sampler_view) {
> +      stObj->sampler_view = st_sampler_view_from_texture(stObj->pipe, 
> stObj->pt);
> +   }
> +
> +   return stObj->sampler_view;
> +}
> +
> +
>  extern struct pipe_texture *
>  st_texture_create(struct st_context *st,
>                    enum pipe_texture_target target,
> 
> _______________________________________________
> mesa-commit mailing list
> mesa-com...@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-commit



------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to