[Mesa-dev] [PATCH 1/2] gallium/sw: allow for negative strides in some places

Jose Fonseca jfonseca at vmware.com
Tue Mar 19 03:54:00 PDT 2013


I think this is fine in principle, but I believe it's better to be exhaustive now than to waste time debugging unsigned/signed stride mismatches later.

Especially all src/gallium/auxiliary/util modules should be updated:

- src/gallium/auxiliary/util/u_format_*
- src/gallium/auxiliary/util/u_surface.*

among others. Here is the full list:

$ git grep -l '\<\(unsigned\(\s\+int\)\?\|uint\)\s\+\w\+\(stride\|pitch\)\>' src/gallium/auxiliary/util/
src/gallium/auxiliary/util/u_format.c
src/gallium/auxiliary/util/u_format.h
src/gallium/auxiliary/util/u_format_etc.c
src/gallium/auxiliary/util/u_format_etc.h
src/gallium/auxiliary/util/u_format_latc.c
src/gallium/auxiliary/util/u_format_latc.h
src/gallium/auxiliary/util/u_format_other.c
src/gallium/auxiliary/util/u_format_other.h
src/gallium/auxiliary/util/u_format_pack.py
src/gallium/auxiliary/util/u_format_rgtc.c
src/gallium/auxiliary/util/u_format_rgtc.h
src/gallium/auxiliary/util/u_format_s3tc.c
src/gallium/auxiliary/util/u_format_s3tc.h
src/gallium/auxiliary/util/u_format_yuv.c
src/gallium/auxiliary/util/u_format_yuv.h
src/gallium/auxiliary/util/u_format_zs.c
src/gallium/auxiliary/util/u_format_zs.h
src/gallium/auxiliary/util/u_resource.c
src/gallium/auxiliary/util/u_surface.c
src/gallium/auxiliary/util/u_surface.h
src/gallium/auxiliary/util/u_texture.c
src/gallium/auxiliary/util/u_texture.h
src/gallium/auxiliary/util/u_tile.c
src/gallium/auxiliary/util/u_tile.h
src/gallium/auxiliary/util/u_transfer.c
src/gallium/auxiliary/util/u_transfer.h

Jose


----- Original Message -----
> From: Dave Airlie <airlied at redhat.com>
> 
> This is for a specific use-case for the QXL driver (which wraps
> llvmpipe/softpipe). Texture it get via TFP are inverted, so
> we need to use a negative stride to sample from them. So
> this converts a bunch of cases where we use unsigned stride
> to a signed value. I can't see the single bit less limiting
> us anytime soon, and so far the underlying llvm code has
> just worked properly and my texture samples end the right way up.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/gallium/auxiliary/draw/draw_context.c         | 2 +-
>  src/gallium/auxiliary/draw/draw_context.h         | 2 +-
>  src/gallium/auxiliary/draw/draw_llvm.c            | 2 +-
>  src/gallium/auxiliary/draw/draw_llvm.h            | 4 ++--
>  src/gallium/drivers/llvmpipe/lp_jit.h             | 2 +-
>  src/gallium/drivers/llvmpipe/lp_scene.h           | 2 +-
>  src/gallium/drivers/llvmpipe/lp_state_sampler.c   | 2 +-
>  src/gallium/drivers/llvmpipe/lp_texture.h         | 2 +-
>  src/gallium/include/pipe/p_state.h                | 2 +-
>  src/gallium/include/state_tracker/sw_winsys.h     | 4 ++--
>  src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c | 8 ++++----
>  src/gallium/winsys/sw/xlib/xlib_sw_winsys.c       | 6 +++---
>  12 files changed, 19 insertions(+), 19 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/draw/draw_context.c
> b/src/gallium/auxiliary/draw/draw_context.c
> index 045bb6b..0903cfb 100644
> --- a/src/gallium/auxiliary/draw/draw_context.c
> +++ b/src/gallium/auxiliary/draw/draw_context.c
> @@ -807,7 +807,7 @@ draw_set_mapped_texture(struct draw_context *draw,
>                          uint32_t width, uint32_t height, uint32_t depth,
>                          uint32_t first_level, uint32_t last_level,
>                          const void *base_ptr,
> -                        uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
> +                        int32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
>                          uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
>                          uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
>  {
> diff --git a/src/gallium/auxiliary/draw/draw_context.h
> b/src/gallium/auxiliary/draw/draw_context.h
> index e8e2d94..4927ca4 100644
> --- a/src/gallium/auxiliary/draw/draw_context.h
> +++ b/src/gallium/auxiliary/draw/draw_context.h
> @@ -155,7 +155,7 @@ draw_set_mapped_texture(struct draw_context *draw,
>                          uint32_t width, uint32_t height, uint32_t depth,
>                          uint32_t first_level, uint32_t last_level,
>                          const void *base,
> -                        uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
> +                        int32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
>                          uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
>                          uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
>  
> diff --git a/src/gallium/auxiliary/draw/draw_llvm.c
> b/src/gallium/auxiliary/draw/draw_llvm.c
> index 8e46687..3e7d497 100644
> --- a/src/gallium/auxiliary/draw/draw_llvm.c
> +++ b/src/gallium/auxiliary/draw/draw_llvm.c
> @@ -1501,7 +1501,7 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
>                               uint32_t width, uint32_t height, uint32_t
>                               depth,
>                               uint32_t first_level, uint32_t last_level,
>                               const void *base_ptr,
> -                             uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
> +                             int32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
>                               uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
>                               uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS])
>  {
> diff --git a/src/gallium/auxiliary/draw/draw_llvm.h
> b/src/gallium/auxiliary/draw/draw_llvm.h
> index c9f125b..748a01b 100644
> --- a/src/gallium/auxiliary/draw/draw_llvm.h
> +++ b/src/gallium/auxiliary/draw/draw_llvm.h
> @@ -49,7 +49,7 @@ struct draw_jit_texture
>     uint32_t first_level;
>     uint32_t last_level;
>     const void *base;
> -   uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
> +   int32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
>     uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
>     uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
>  };
> @@ -337,7 +337,7 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
>                               uint32_t width, uint32_t height, uint32_t
>                               depth,
>                               uint32_t first_level, uint32_t last_level,
>                               const void *base_ptr,
> -                             uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
> +                             int32_t row_stride[PIPE_MAX_TEXTURE_LEVELS],
>                               uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
>                               uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
>  
> diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h
> b/src/gallium/drivers/llvmpipe/lp_jit.h
> index 4eddb2a..ea89124 100644
> --- a/src/gallium/drivers/llvmpipe/lp_jit.h
> +++ b/src/gallium/drivers/llvmpipe/lp_jit.h
> @@ -55,7 +55,7 @@ struct lp_jit_texture
>     uint32_t first_level;
>     uint32_t last_level;
>     const void *base;
> -   uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
> +   int32_t row_stride[LP_MAX_TEXTURE_LEVELS];
>     uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
>     uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
>  };
> diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h
> b/src/gallium/drivers/llvmpipe/lp_scene.h
> index b1db61b..2ff8b5b 100644
> --- a/src/gallium/drivers/llvmpipe/lp_scene.h
> +++ b/src/gallium/drivers/llvmpipe/lp_scene.h
> @@ -134,7 +134,7 @@ struct lp_scene {
>      */
>     struct {
>        uint8_t *map;
> -      unsigned stride;
> +      int32_t stride;
>        unsigned blocksize;
>     } zsbuf, cbufs[PIPE_MAX_COLOR_BUFS];
>     
> diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
> b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
> index 30547a6..658d7cd 100644
> --- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
> +++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
> @@ -253,7 +253,7 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context
> *lp,
>                                   struct pipe_sampler_view **views)
>  {
>     unsigned i;
> -   uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
> +   int32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
>     uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
>     uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
>     const void *addr;
> diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h
> b/src/gallium/drivers/llvmpipe/lp_texture.h
> index c046902..1bdccce 100644
> --- a/src/gallium/drivers/llvmpipe/lp_texture.h
> +++ b/src/gallium/drivers/llvmpipe/lp_texture.h
> @@ -87,7 +87,7 @@ struct llvmpipe_resource
>     struct pipe_resource base;
>  
>     /** Row stride in bytes */
> -   unsigned row_stride[LP_MAX_TEXTURE_LEVELS];
> +   int row_stride[LP_MAX_TEXTURE_LEVELS];
>     /** Image stride (for cube maps, array or 3D textures) in bytes */
>     unsigned img_stride[LP_MAX_TEXTURE_LEVELS];
>     unsigned tiles_per_row[LP_MAX_TEXTURE_LEVELS];
> diff --git a/src/gallium/include/pipe/p_state.h
> b/src/gallium/include/pipe/p_state.h
> index ab49cab..9201cfe 100644
> --- a/src/gallium/include/pipe/p_state.h
> +++ b/src/gallium/include/pipe/p_state.h
> @@ -426,7 +426,7 @@ struct pipe_transfer
>     unsigned level;                 /**< texture mipmap level */
>     enum pipe_transfer_usage usage;
>     struct pipe_box box;            /**< region of the resource to access */
> -   unsigned stride;                /**< row stride in bytes */
> +   int stride;                /**< row stride in bytes */
>     unsigned layer_stride;          /**< image/layer stride in bytes */
>  };
>  
> diff --git a/src/gallium/include/state_tracker/sw_winsys.h
> b/src/gallium/include/state_tracker/sw_winsys.h
> index 0b11fe3..71d2943 100644
> --- a/src/gallium/include/state_tracker/sw_winsys.h
> +++ b/src/gallium/include/state_tracker/sw_winsys.h
> @@ -90,7 +90,7 @@ struct sw_winsys
>                              enum pipe_format format,
>                              unsigned width, unsigned height,
>                              unsigned alignment,
> -                            unsigned *stride );
> +                            int *stride );
>  
>     /**
>      * Used to implement texture_from_handle.
> @@ -99,7 +99,7 @@ struct sw_winsys
>     (*displaytarget_from_handle)( struct sw_winsys *ws,
>                                   const struct pipe_resource *templat,
>                                   struct winsys_handle *whandle,
> -                                 unsigned *stride );
> +                                 int *stride );
>  
>     /**
>      * Used to implement texture_get_handle.
> diff --git a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c
> b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c
> index e552ac2..3761ae0 100644
> --- a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c
> +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c
> @@ -85,7 +85,7 @@ wrapper_sw_displaytarget(struct sw_displaytarget *dt)
>  
>  
>  static boolean
> -wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride)
> +wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, int *stride)
>  {
>     struct pipe_context *pipe = wdt->winsys->pipe;
>     struct pipe_resource *tex = wdt->tex;
> @@ -108,7 +108,7 @@ wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt,
> unsigned *stride)
>  
>  static struct sw_displaytarget *
>  wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw,
> -                    struct pipe_resource *tex, unsigned *stride)
> +                    struct pipe_resource *tex, int *stride)
>  {
>     struct wrapper_sw_displaytarget *wdt =
>     CALLOC_STRUCT(wrapper_sw_displaytarget);
>     if (!wdt)
> @@ -135,7 +135,7 @@ wsw_dt_create(struct sw_winsys *ws,
>                enum pipe_format format,
>                unsigned width, unsigned height,
>                unsigned alignment,
> -              unsigned *stride)
> +              int *stride)
>  {
>     struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws);
>     struct pipe_resource templ;
> @@ -166,7 +166,7 @@ static struct sw_displaytarget *
>  wsw_dt_from_handle(struct sw_winsys *ws,
>                     const struct pipe_resource *templ,
>                     struct winsys_handle *whandle,
> -                   unsigned *stride)
> +                   int *stride)
>  {
>     struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws);
>     struct pipe_resource *tex;
> diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
> b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
> index 3aef8da..de6816f 100644
> --- a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
> +++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
> @@ -59,7 +59,7 @@ struct xlib_displaytarget
>     enum pipe_format format;
>     unsigned width;
>     unsigned height;
> -   unsigned stride;
> +   int stride;
>  
>     void *data;
>     void *mapped;
> @@ -383,7 +383,7 @@ xlib_displaytarget_create(struct sw_winsys *winsys,
>                            enum pipe_format format,
>                            unsigned width, unsigned height,
>                            unsigned alignment,
> -                          unsigned *stride)
> +                          int *stride)
>  {
>     struct xlib_displaytarget *xlib_dt;
>     unsigned nblocksy, size;
> @@ -428,7 +428,7 @@ static struct sw_displaytarget *
>  xlib_displaytarget_from_handle(struct sw_winsys *winsys,
>                                 const struct pipe_resource *templet,
>                                 struct winsys_handle *whandle,
> -                               unsigned *stride)
> +                               int *stride)
>  {
>     assert(0);
>     return NULL;
> --
> 1.8.1.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 


More information about the mesa-dev mailing list