[Mesa-dev] [PATCH 6/9] softpipe: Split 3D to 2D coords conversion into separate function.

Roland Scheidegger sroland at vmware.com
Wed Sep 9 11:12:48 PDT 2015


Am 09.09.2015 um 12:35 schrieb Krzesimir Nowak:
> This is to avoid tying the conversion to sampling - textureQueryLod
> will need to do the conversion too, but it does not do any sampling.
> 
> So instead of a "sample" vfunc, there is a "convert" vfunc. The
> drawback of this approach is that a "noop" convert copies 3 arrays of
> floats. Would be nice to avoid it in some clean way.

Well yes I'm not sure it's such a great idea. These functions were there
initially to make things faster (by skipping work not necessary without
conditions basically), but it looks to me like that's not really
happening here (because the common case, non cube map, does extra work
for nothing - surely a perfectly predictable condition would be faster
than copying stuff around).
So, one idea to avoid this would be to just forget about those function
pointers there. Instead of get_samples (or now convert_coords) in sview,
just set needs_cube_convert or something like that in sview, then use a
condition based on needs_cube_convert to either invoke sample_mip
directly or cube coord conversion + sample mip in the appropriate place(s).
Either way though looks acceptable to me.

Roland

> ---
>  src/gallium/drivers/softpipe/sp_tex_sample.c | 73 +++++++++++++++++-----------
>  src/gallium/drivers/softpipe/sp_tex_sample.h | 20 ++++----
>  2 files changed, 54 insertions(+), 39 deletions(-)
> 
> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c
> index 0a3fc20..cdec984 100644
> --- a/src/gallium/drivers/softpipe/sp_tex_sample.c
> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
> @@ -2981,29 +2981,36 @@ sample_mip(struct sp_sampler_view *sp_sview,
>  
>  }
>  
> +static void
> +convert_noop(struct sp_sampler_view *sp_sview,
> +             struct sp_sampler *sp_samp,
> +             const float s[TGSI_QUAD_SIZE],
> +             const float t[TGSI_QUAD_SIZE],
> +             const float p[TGSI_QUAD_SIZE],
> +             const float c0[TGSI_QUAD_SIZE],
> +             float ssss[TGSI_QUAD_SIZE],
> +             float tttt[TGSI_QUAD_SIZE],
> +             float pppp[TGSI_QUAD_SIZE])
> +{
> +   const size_t len = sizeof(float) * TGSI_QUAD_SIZE;
> +
> +   memcpy(ssss, s, len);
> +   memcpy(tttt, t, len);
> +   memcpy(pppp, p, len);
> +}
>  
> -/**
> - * Use 3D texcoords to choose a cube face, then sample the 2D cube faces.
> - * Put face info into the sampler faces[] array.
> - */
>  static void
> -sample_cube(struct sp_sampler_view *sp_sview,
> -            struct sp_sampler *sp_samp,
> -            const float s[TGSI_QUAD_SIZE],
> -            const float t[TGSI_QUAD_SIZE],
> -            const float p[TGSI_QUAD_SIZE],
> -            const float c0[TGSI_QUAD_SIZE],
> -            const float c1[TGSI_QUAD_SIZE],
> -            const struct filter_args *filt_args,
> -            float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE])
> +convert_cube(struct sp_sampler_view *sp_sview,
> +             struct sp_sampler *sp_samp,
> +             const float s[TGSI_QUAD_SIZE],
> +             const float t[TGSI_QUAD_SIZE],
> +             const float p[TGSI_QUAD_SIZE],
> +             const float c0[TGSI_QUAD_SIZE],
> +             float ssss[TGSI_QUAD_SIZE],
> +             float tttt[TGSI_QUAD_SIZE],
> +             float pppp[TGSI_QUAD_SIZE])
>  {
>     unsigned j;
> -   float ssss[4], tttt[4];
> -
> -   /* Not actually used, but the intermediate steps that do the
> -    * dereferencing don't know it.
> -    */
> -   static float pppp[4] = { 0, 0, 0, 0 };
>  
>     pppp[0] = c0[0];
>     pppp[1] = c0[1];
> @@ -3071,8 +3078,6 @@ sample_cube(struct sp_sampler_view *sp_sview,
>           }
>        }
>     }
> -
> -   sample_mip(sp_sview, sp_samp, ssss, tttt, pppp, c0, c1, filt_args, rgba);
>  }
>  
>  
> @@ -3393,9 +3398,9 @@ softpipe_create_sampler_view(struct pipe_context *pipe,
>  
>        if (view->target == PIPE_TEXTURE_CUBE ||
>            view->target == PIPE_TEXTURE_CUBE_ARRAY)
> -         sview->get_samples = sample_cube;
> +         sview->convert_coords = convert_cube;
>        else {
> -         sview->get_samples = sample_mip;
> +         sview->convert_coords = convert_noop;
>        }
>        sview->pot2d = spr->pot &&
>                       (view->target == PIPE_TEXTURE_2D ||
> @@ -3440,13 +3445,22 @@ sp_tgsi_get_samples(struct tgsi_sampler *tgsi_sampler,
>                      enum tgsi_sampler_control control,
>                      float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE])
>  {
> -   struct sp_tgsi_sampler *sp_samp = (struct sp_tgsi_sampler *)tgsi_sampler;
> +   struct sp_tgsi_sampler *sp_tgsi_samp = (struct sp_tgsi_sampler *)tgsi_sampler;
> +   struct sp_sampler_view *sp_sview;
> +   struct sp_sampler *sp_samp;
>     struct filter_args filt_args;
> +   float cs[TGSI_QUAD_SIZE];
> +   float ct[TGSI_QUAD_SIZE];
> +   float cp[TGSI_QUAD_SIZE];
> +
>     assert(sview_index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
>     assert(sampler_index < PIPE_MAX_SAMPLERS);
> -   assert(sp_samp->sp_sampler[sampler_index]);
> +   assert(sp_tgsi_samp->sp_sampler[sampler_index]);
> +
> +   sp_sview = &sp_tgsi_samp->sp_sview[sview_index];
> +   sp_samp = sp_tgsi_samp->sp_sampler[sampler_index];
>     /* always have a view here but texture is NULL if no sampler view was set. */
> -   if (!sp_samp->sp_sview[sview_index].base.texture) {
> +   if (!sp_sview->base.texture) {
>        int i, j;
>        for (j = 0; j < TGSI_NUM_CHANNELS; j++) {
>           for (i = 0; i < TGSI_QUAD_SIZE; i++) {
> @@ -3456,11 +3470,12 @@ sp_tgsi_get_samples(struct tgsi_sampler *tgsi_sampler,
>        return;
>     }
>  
> +   sp_sview->convert_coords(sp_sview, sp_samp, s, t, p, c0, cs, ct, cp);
> +
>     filt_args.control = control;
>     filt_args.offset = offset;
> -   sp_samp->sp_sview[sview_index].get_samples(&sp_samp->sp_sview[sview_index],
> -                                              sp_samp->sp_sampler[sampler_index],
> -                                              s, t, p, c0, lod, &filt_args, rgba);
> +
> +   sample_mip(sp_sview, sp_samp, cs, ct, cp, c0, lod, &filt_args, rgba);
>  }
>  
>  
> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.h b/src/gallium/drivers/softpipe/sp_tex_sample.h
> index 78541e1..7739f59 100644
> --- a/src/gallium/drivers/softpipe/sp_tex_sample.h
> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.h
> @@ -87,15 +87,15 @@ typedef void (*mip_filter_func)(struct sp_sampler_view *sp_sview,
>                                  float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
>  
>  
> -typedef void (*filter_func)(struct sp_sampler_view *sp_sview,
> -                            struct sp_sampler *sp_samp,
> -                            const float s[TGSI_QUAD_SIZE],
> -                            const float t[TGSI_QUAD_SIZE],
> -                            const float p[TGSI_QUAD_SIZE],
> -                            const float c0[TGSI_QUAD_SIZE],
> -                            const float lod[TGSI_QUAD_SIZE],
> -                            const struct filter_args *args,
> -                            float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
> +typedef void (*convert_func)(struct sp_sampler_view *sp_sview,
> +                             struct sp_sampler *sp_samp,
> +                             const float s[TGSI_QUAD_SIZE],
> +                             const float t[TGSI_QUAD_SIZE],
> +                             const float p[TGSI_QUAD_SIZE],
> +                             const float c0[TGSI_QUAD_SIZE],
> +                             float ssss[TGSI_QUAD_SIZE],
> +                             float tttt[TGSI_QUAD_SIZE],
> +                             float pppp[TGSI_QUAD_SIZE]);
>  
>  
>  typedef void (*fetch_func)(struct sp_sampler_view *sp_sview,
> @@ -117,7 +117,7 @@ struct sp_sampler_view
>     boolean need_swizzle;
>     boolean pot2d;
>  
> -   filter_func get_samples;
> +   convert_func convert_coords;
>  
>     /* this is just abusing the sampler_view object as local storage */
>     unsigned faces[TGSI_QUAD_SIZE];
> 



More information about the mesa-dev mailing list