[Mesa-dev] [PATCH 1/3] mesa: Fold gallium's texture border stripping into a core Mesa option.
Brian Paul
brian.e.paul at gmail.com
Mon Oct 24 18:23:53 PDT 2011
On Mon, Oct 24, 2011 at 5:15 PM, Eric Anholt <eric at anholt.net> wrote:
> We wanted to reuse this in the Intel driver.
> ---
> src/mesa/main/mtypes.h | 14 ++++++++
> src/mesa/main/teximage.c | 57 +++++++++++++++++++++++++++++--
> src/mesa/state_tracker/st_cb_texture.c | 58 ++------------------------------
> src/mesa/state_tracker/st_extensions.c | 2 +
> 4 files changed, 73 insertions(+), 58 deletions(-)
>
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 719dff3..3309119 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1457,6 +1457,20 @@ struct gl_texture_attrib
> /** GL_ARB_seamless_cubemap */
> GLboolean CubeMapSeamless;
>
> + /**
> + * Whether the implementation strips out and ignores texture borders.
> + *
> + * Many GPU hardware implementations don't support rendering with texture
> + * borders and mipmapped textures. (Note: not static border color, but the
> + * old 1-pixel border around each edge). Implementations then have to do
> + * slow fallbacks to be correct, or just ignore the border and be fast but
> + * wrong. Setting the flag stripts the border off of TexImage calls,
> + * providing "fast but wrong" at significantly reduced driver complexity.
> + *
> + * Texture borders are deprecated in GL 3.0.
> + **/
> + GLboolean StripTextureBorder;
I think I'd like to see this put into the gl_constants state to make
it obvious that this is driver-specified constant state and not some
kind of settable texture state.
> +
> /** Texture units/samplers used by vertex or fragment texturing */
> GLbitfield _EnabledUnits;
>
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 798201a..f1d1a7c 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -2246,6 +2246,45 @@ _mesa_choose_texture_format(struct gl_context *ctx,
> return f;
> }
>
> +/**
> + * Adjust pixel unpack params and image dimensions to strip off the
> + * texture border.
> + *
> + * Gallium and intel don't support texture borders. They've seldem been used
> + * and seldom been implemented correctly anyway.
> + *
> + * \param unpackNew returns the new pixel unpack parameters
> + */
> +static void
> +strip_texture_border(GLint *border,
> + GLint *width, GLint *height, GLint *depth,
> + const struct gl_pixelstore_attrib *unpack,
> + struct gl_pixelstore_attrib *unpackNew)
> +{
> + assert(*border > 0); /* sanity check */
> +
> + *unpackNew = *unpack;
> +
> + if (unpackNew->RowLength == 0)
> + unpackNew->RowLength = *width;
> +
> + if (depth && unpackNew->ImageHeight == 0)
> + unpackNew->ImageHeight = *height;
> +
> + unpackNew->SkipPixels += *border;
> + if (height)
> + unpackNew->SkipRows += *border;
> + if (depth)
> + unpackNew->SkipImages += *border;
> +
> + assert(*width >= 3);
> + *width = *width - 2 * *border;
> + if (height && *height >= 3)
> + *height = *height - 2 * *border;
> + if (depth && *depth >= 3)
> + *depth = *depth - 2 * *border;
> + *border = 0;
> +}
>
> /**
> * Common code to implement all the glTexImage1D/2D/3D functions.
> @@ -2258,6 +2297,8 @@ teximage(struct gl_context *ctx, GLuint dims,
> const GLvoid *pixels)
> {
> GLboolean error;
> + struct gl_pixelstore_attrib unpack_no_border;
> + const struct gl_pixelstore_attrib *unpack = &ctx->Unpack;
>
> ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
>
> @@ -2322,6 +2363,16 @@ teximage(struct gl_context *ctx, GLuint dims,
> return; /* error was recorded */
> }
>
> + /* Allow a hardware driver to just strip out the border, to provide
> + * reliable but slightly incorrect hardware rendering instead of
> + * rarely-tested software fallback rendering.
> + */
> + if (border && ctx->Texture.StripTextureBorder) {
> + strip_texture_border(&border, &width, &height, &depth, unpack,
> + &unpack_no_border);
> + unpack = &unpack_no_border;
> + }
> +
I think we also need this code in the glCopyTexImage() path.
-Brian
More information about the mesa-dev
mailing list