[Mesa-dev] [PATCH 7/9] softpipe: Add functions for computing mipmap level

Krzesimir Nowak krzesimir at kinvolk.io
Thu Sep 10 04:30:25 PDT 2015


On Wed, Sep 9, 2015 at 8:19 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:

> On Wed, Sep 9, 2015 at 2:17 PM, Roland Scheidegger <sroland at vmware.com>
> wrote:
> > Am 09.09.2015 um 12:35 schrieb Krzesimir Nowak:
> >> These functions will be used by textureQueryLod.
> >> ---
> >>  src/gallium/drivers/softpipe/sp_tex_sample.c | 100
> +++++++++++++++++++++++++--
> >>  src/gallium/drivers/softpipe/sp_tex_sample.h |   7 ++
> >>  2 files changed, 101 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c
> b/src/gallium/drivers/softpipe/sp_tex_sample.c
> >> index cdec984..6e639e0 100644
> >> --- a/src/gallium/drivers/softpipe/sp_tex_sample.c
> >> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
> >> @@ -1937,6 +1937,38 @@ get_gather_component(const float
> lod_in[TGSI_QUAD_SIZE])
> >>  }
> >>
> >>  static void
> >> +clamp_lod(const struct sp_sampler_view *sp_sview,
> >> +          const struct sp_sampler *sp_samp,
> >> +          const float lod[TGSI_QUAD_SIZE],
> >> +          float clamped[TGSI_QUAD_SIZE])
> >> +{
> >> +   const float min_lod = sp_samp->base.min_lod;
> >> +   const float max_lod = sp_samp->base.max_lod;
> >> +   const float min_level = sp_sview->base.u.tex.first_level;
> >> +   const float max_level = sp_sview->base.u.tex.last_level;
> >> +   int i;
> >> +
> >> +   for (i = 0; i < TGSI_QUAD_SIZE; i++) {
> >> +      float cl = lod[i];
> >> +
> >> +      cl = CLAMP(cl, min_lod, max_lod);
> >> +      /* XXX: Is min_level ever different from 0?
> > I think the comment is bogus. min_level can easily be different from 0,
> > at least when using ARB_texture_view afaik (playing around with base
> > level might also cause this to be non-zero, though I'm not too familiar
> > with what the state tracker does for those legacy GL weirdness things).
>
> Either setting the base level or a texture view (or both!) can cause
> the min level to be 0.
>

I believe you wanted to say that setting base level or a texture view can
cause min level to be different from 0?

Anyway, I scrapped the comment.


>
> >
> >> +       */
> >> +      cl = CLAMP(cl, 0, max_level - min_level);
> >> +      clamped[i] = cl;
> >> +   }
> >> +}
> >> +
> >> +static void
> >> +mip_level_linear(struct sp_sampler_view *sp_sview,
> >> +                 struct sp_sampler *sp_samp,
> >> +                 const float lod[TGSI_QUAD_SIZE],
> >> +                 float level[TGSI_QUAD_SIZE])
> >> +{
> >> +   clamp_lod(sp_sview, sp_samp, lod, level);
> >> +}
> >> +
> >> +static void
> >>  mip_filter_linear(struct sp_sampler_view *sp_sview,
> >>                    struct sp_sampler *sp_samp,
> >>                    img_filter_func min_filter,
> >> @@ -1998,6 +2030,23 @@ mip_filter_linear(struct sp_sampler_view
> *sp_sview,
> >>  }
> >>
> >>
> >> +static void
> >> +mip_level_nearest(struct sp_sampler_view *sp_sview,
> >> +                  struct sp_sampler *sp_samp,
> >> +                  const float lod[TGSI_QUAD_SIZE],
> >> +                  float level[TGSI_QUAD_SIZE])
> >> +{
> >> +   const int first_level = sp_sview->base.u.tex.first_level;
> >> +   int j;
> >> +
> >> +   clamp_lod(sp_sview, sp_samp, lod, level);
> >> +   for (j = 0; j < TGSI_QUAD_SIZE; j++)
> >> +      /* TODO: It should rather be:
> >> +       * level[j] = first_level + ceil(level[j] + 0.5F) - 1.0F;
> >> +       */
> >> +      level[j] = first_level + (int)(level[j] + 0.5F);
> >> +}
> >> +
> >>  /**
> >>   * Compute nearest mipmap level from texcoords.
> >>   * Then sample the texture level for four elements of a quad.
> >> @@ -2050,6 +2099,19 @@ mip_filter_nearest(struct sp_sampler_view
> *sp_sview,
> >>
> >>
> >>  static void
> >> +mip_level_none(struct sp_sampler_view *sp_sview,
> >> +               struct sp_sampler *sp_samp,
> >> +               const float lod[TGSI_QUAD_SIZE],
> >> +               float level[TGSI_QUAD_SIZE])
> >> +{
> >> +   int j;
> >> +
> >> +   for (j = 0; j < TGSI_QUAD_SIZE; j++) {
> >> +      level[j] = sp_sview->base.u.tex.first_level;
> >> +   }
> >> +}
> >> +
> >> +static void
> >>  mip_filter_none(struct sp_sampler_view *sp_sview,
> >>                  struct sp_sampler *sp_samp,
> >>                  img_filter_func min_filter,
> >> @@ -2088,6 +2150,15 @@ mip_filter_none(struct sp_sampler_view *sp_sview,
> >>
> >>
> >>  static void
> >> +mip_level_none_no_filter_select(struct sp_sampler_view *sp_sview,
> >> +                                struct sp_sampler *sp_samp,
> >> +                                const float lod[TGSI_QUAD_SIZE],
> >> +                                float level[TGSI_QUAD_SIZE])
> >> +{
> >> +   mip_level_none(sp_sview, sp_samp, lod, level);
> >> +}
> >> +
> >> +static void
> >>  mip_filter_none_no_filter_select(struct sp_sampler_view *sp_sview,
> >>                                   struct sp_sampler *sp_samp,
> >>                                   img_filter_func min_filter,
> >> @@ -2339,6 +2410,15 @@ img_filter_2d_ewa(struct sp_sampler_view
> *sp_sview,
> >>  }
> >>
> >>
> >> +static void
> >> +mip_level_linear_aniso(struct sp_sampler_view *sp_sview,
> >> +                       struct sp_sampler *sp_samp,
> >> +                       const float lod[TGSI_QUAD_SIZE],
> >> +                       float level[TGSI_QUAD_SIZE])
> >> +{
> >> +   mip_level_linear(sp_sview, sp_samp, lod, level);
> >> +}
> >> +
> >>  /**
> >>   * Sample 2D texture using an anisotropic filter.
> >>   */
> >> @@ -2450,6 +2530,14 @@ mip_filter_linear_aniso(struct sp_sampler_view
> *sp_sview,
> >>     }
> >>  }
> >>
> >> +static void
> >> +mip_level_linear_2d_linear_repeat_POT(struct sp_sampler_view *sp_sview,
> >> +                                      struct sp_sampler *sp_samp,
> >> +                                      const float lod[TGSI_QUAD_SIZE],
> >> +                                      float level[TGSI_QUAD_SIZE])
> >> +{
> >> +   mip_level_linear(sp_sview, sp_samp, lod, level);
> >> +}
> >>
> >>  /**
> >>   * Specialized version of mip_filter_linear with hard-wired calls to
> >> @@ -2515,12 +2603,12 @@ mip_filter_linear_2d_linear_repeat_POT(
> >>     }
> >>  }
> >>
> >> -static struct sp_mip mip_linear = {mip_filter_linear};
> >> -static struct sp_mip mip_nearest = {mip_filter_nearest};
> >> -static struct sp_mip mip_none = {mip_filter_none};
> >> -static struct sp_mip mip_none_no_filter_select =
> {mip_filter_none_no_filter_select};
> >> -static struct sp_mip mip_linear_aniso = {mip_filter_linear_aniso};
> >> -static struct sp_mip mip_linear_2d_linear_repeat_POT =
> {mip_filter_linear_2d_linear_repeat_POT};
> >> +static struct sp_mip mip_linear = {mip_level_linear,
> mip_filter_linear};
> >> +static struct sp_mip mip_nearest = {mip_level_nearest,
> mip_filter_nearest};
> >> +static struct sp_mip mip_none = {mip_level_none, mip_filter_none};
> >> +static struct sp_mip mip_none_no_filter_select =
> {mip_level_none_no_filter_select, mip_filter_none_no_filter_select};
> >> +static struct sp_mip mip_linear_aniso = {mip_level_linear_aniso,
> mip_filter_linear_aniso};
> >> +static struct sp_mip mip_linear_2d_linear_repeat_POT =
> {mip_level_linear_2d_linear_repeat_POT,
> mip_filter_linear_2d_linear_repeat_POT};
> >>
> >>  /**
> >>   * Do shadow/depth comparisons.
> >> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.h
> b/src/gallium/drivers/softpipe/sp_tex_sample.h
> >> index 7739f59..89cf9d1 100644
> >> --- a/src/gallium/drivers/softpipe/sp_tex_sample.h
> >> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.h
> >> @@ -87,6 +87,12 @@ typedef void (*mip_filter_func)(struct
> sp_sampler_view *sp_sview,
> >>                                  float
> rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
> >>
> >>
> >> +typedef void (*mip_level_func)(struct sp_sampler_view *sp_sview,
> >> +                               struct sp_sampler *sp_samp,
> >> +                               const float lod[TGSI_QUAD_SIZE],
> >> +                               float level[TGSI_QUAD_SIZE]);
> >> +
> >> +
> >>  typedef void (*convert_func)(struct sp_sampler_view *sp_sview,
> >>                               struct sp_sampler *sp_samp,
> >>                               const float s[TGSI_QUAD_SIZE],
> >> @@ -129,6 +135,7 @@ struct sp_sampler_view
> >>  };
> >>
> >>  struct sp_mip {
> >> +   mip_level_func level;
> >>     mip_filter_func filter;
> >>  };
> >>
> >>
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150910/4611d38e/attachment.html>


More information about the mesa-dev mailing list