[Mesa-dev] [PATCH 2/6] softpipe: add get_dims callback for TXQ support.

Brian Paul brianp at vmware.com
Thu Aug 25 06:45:59 PDT 2011


On 08/25/2011 04:47 AM, Dave Airlie wrote:
> From: Dave Airlie<airlied at redhat.com>
>
> This adds the get_dims callback that is called from the tgsi exec_txq.
>
> It returns values as per EXT_gpu_program4.
>
> Signed-off-by: Dave Airlie<airlied at redhat.com>
> ---
>   src/gallium/drivers/softpipe/sp_tex_sample.c |   36 ++++++++++++++++++++++++++
>   1 files changed, 36 insertions(+), 0 deletions(-)
>
> diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c
> index f730948..4929f92 100644
> --- a/src/gallium/drivers/softpipe/sp_tex_sample.c
> +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
> @@ -2566,6 +2566,41 @@ sp_sampler_variant_destroy( struct sp_sampler_variant *samp )
>      FREE(samp);
>   }
>
> +static void
> +sample_get_dims(struct tgsi_sampler *tgsi_sampler, int level,
> +		int dims[4])
> +{
> +    struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
> +    const struct pipe_sampler_view *view = samp->view;
> +    const struct pipe_resource *texture = view->texture;
> +    const struct pipe_sampler_state *sampler = samp->sampler;
> +
> +    /* undefined according to EXT_gpu_program */
> +    level += view->u.tex.first_level;
> +    if (level>  view->u.tex.last_level)
> +	return;
> +
> +    dims[0] = u_minify(texture->width0, level);
> +    if (texture->target == PIPE_TEXTURE_1D)
> +	return;
> +
> +    if (texture->target == PIPE_TEXTURE_1D_ARRAY) {
> +	dims[1] = texture->array_size;
> +	return;
> +    }
> +
> +    dims[1] = u_minify(texture->height0, level);
> +
> +    if (texture->target == PIPE_TEXTURE_2D_ARRAY) {
> +	dims[2] = texture->array_size;
> +	return;
> +    }
> +
> +    if (texture->target != PIPE_TEXTURE_3D)
> +	return;
> +
> +    dims[2] = u_minify(texture->depth0, level);
> +}

I think it would be better to use a switch statement here:

     dims[0] = u_minify(texture->width0, level);

     switch (texture->target) {
     case PIPE_TEXTURE_1D:
        break;
     case PIPE_TEXTURE_2D:
     case PIPE_TEXTURE_CUBE:
     case PIPE_TEXTURE_RECT:
        dims[1] = u_minify(texture->height0, level);
        break;
     case PIPE_TEXTURE_3D:
        dims[1] = u_minify(texture->height0, level);
        dims[2] = u_minify(texture->depth0, level);
        break;
     case PIPE_TEXTURE_1D_ARRAY:
        dims[1] = texture->array_size;
        break;
     case PIPE_TEXTURE_2D_ARRAY:
        dims[1] = u_minify(texture->height0, level);
        dims[2] = texture->array_size;
        break;
     default:
        assert(!"unexpected texture target in sample_get_dims()");
     }

It's a bit easier read and see that all texture targets are handled. 
Also, when we add new texture targets (buffers, cube arrays) it'll be 
easier to catch unhandled cases.

-Brian


More information about the mesa-dev mailing list