[Mesa-dev] [PATCH 02/11] mesa: Remove extension checking from ChooseTexFormat.
Ian Romanick
idr at freedesktop.org
Wed Apr 17 15:06:25 PDT 2013
On 04/16/2013 05:21 PM, Eric Anholt wrote:
> This should already be handled by _mesa_base_tex_format() calls in
> TexImage*.
> ---
>
> NOTE!
>
> I've replaced the actual patch full of unindentation of code described by:
> src/mesa/main/texformat.c | 1184 ++++++++++++++++++++-------------------------
> 1 file changed, 533 insertions(+), 651 deletions(-)
>
> with the git show -b output so that someone can actually review it.
> If you want to apply the series, please just use the "formats" branch
> of my tree.
Now it's your turn to get, "I've got a branch for that!" I had started
working on some of this earlier this year, but I wandered off when Marek
was doing some renaming. You can check the choose-format2 branch of my
tree. I haven't rebased it since February, so, yeah.
I was working towards simplifying this code and making it testable by
unit tests. I wanted to verify that if a driver exposes some extension
or core version that it also supports the necessary MESA_FORMATs.
> diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
> index ecf8fec..45497c1 100644
> --- a/src/mesa/main/texformat.c
> +++ b/src/mesa/main/texformat.c
> @@ -207,12 +207,6 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
> break;
>
> - default:
> - ; /* fallthrough */
> - }
> -
> - if (ctx->Extensions.ARB_depth_texture) {
> - switch (internalFormat) {
> case GL_DEPTH_COMPONENT:
> case GL_DEPTH_COMPONENT24:
> case GL_DEPTH_COMPONENT32:
> @@ -224,12 +218,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_Z16);
> RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24);
> RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - switch (internalFormat) {
> case GL_COMPRESSED_ALPHA_ARB:
> RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
> break;
> @@ -273,28 +262,17 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
> RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
> break;
> - default:
> - ; /* fallthrough */
> - }
>
> - if (ctx->Extensions.ARB_ES2_compatibility) {
> - switch (internalFormat) {
> case GL_RGB565:
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
> break;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.MESA_ycbcr_texture) {
> - if (internalFormat == GL_YCBCR_MESA) {
> + case GL_YCBCR_MESA:
> if (type == GL_UNSIGNED_SHORT_8_8_MESA)
> RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR);
> else
> RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV);
> - }
> - }
> + break;
>
> /* For non-generic compressed format we assert two things:
> *
> @@ -304,7 +282,6 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> * 2. The driver only enables the extension if it supports all of the
> * formats that are part of that extension.
> */
> - switch (internalFormat) {
> case GL_COMPRESSED_RGB_FXT1_3DFX:
> return MESA_FORMAT_RGB_FXT1;
> case GL_COMPRESSED_RGBA_FXT1_3DFX:
> @@ -369,12 +346,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> return MESA_FORMAT_SRGBA_DXT3;
> case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
> return MESA_FORMAT_SRGBA_DXT5;
> - default:
> - ; /* fallthrough */
> - }
>
> - if (ctx->Extensions.ARB_texture_float) {
> - switch (internalFormat) {
> case GL_ALPHA16F_ARB:
> RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
> RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
> @@ -445,69 +417,35 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
> break;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.EXT_texture_shared_exponent) {
> - switch (internalFormat) {
> case GL_RGB9_E5:
> + /* GL_EXT_texture_shared_exponent -- just one format to support */
> ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_RGB9_E5_FLOAT]);
> return MESA_FORMAT_RGB9_E5_FLOAT;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.EXT_packed_float) {
> - switch (internalFormat) {
> case GL_R11F_G11F_B10F:
> + /* GL_EXT_texture_packed_float -- just one format to support */
> ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_R11_G11_B10_FLOAT]);
> return MESA_FORMAT_R11_G11_B10_FLOAT;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.EXT_packed_depth_stencil) {
> - switch (internalFormat) {
> case GL_DEPTH_STENCIL_EXT:
> case GL_DEPTH24_STENCIL8_EXT:
> RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_S8);
> RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
> break;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.ARB_depth_buffer_float) {
> - switch (internalFormat) {
> case GL_DEPTH_COMPONENT32F:
> ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT]);
> return MESA_FORMAT_Z32_FLOAT;
> case GL_DEPTH32F_STENCIL8:
> ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT_X24S8]);
> return MESA_FORMAT_Z32_FLOAT_X24S8;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.ATI_envmap_bumpmap) {
> - switch (internalFormat) {
> case GL_DUDV_ATI:
> case GL_DU8DV8_ATI:
> RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8);
> break;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.EXT_texture_snorm) {
> - switch (internalFormat) {
> case GL_RED_SNORM:
> case GL_R8_SNORM:
> RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8);
> @@ -586,13 +524,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
> RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
> break;
> - default:
> - ; /* fall-through */
> - }
> - }
>
> - if (ctx->Extensions.EXT_texture_sRGB) {
> - switch (internalFormat) {
> case GL_SRGB_EXT:
> case GL_SRGB8_EXT:
> RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
> @@ -622,24 +554,16 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
> break;
> case GL_COMPRESSED_SRGB_EXT:
> - if (ctx->Extensions.EXT_texture_compression_s3tc)
> RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
> RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
> RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
> break;
> case GL_COMPRESSED_SRGB_ALPHA_EXT:
> - if (ctx->Extensions.EXT_texture_compression_s3tc)
> RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
> RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
> RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
> break;
> - default:
> - ; /* fallthrough */
> - }
> - }
>
> - if (ctx->Extensions.EXT_texture_integer) {
> - switch (internalFormat) {
> case GL_ALPHA8UI_EXT:
> RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT8);
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
> @@ -736,12 +660,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT32);
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
> break;
> - }
> - }
>
> - if (ctx->Version >= 30 ||
> - ctx->Extensions.EXT_texture_integer) {
> - switch (internalFormat) {
> case GL_RGB8UI_EXT:
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT8);
> RETURN_IF_SUPPORTED(MESA_FORMAT_XBGR8888_UINT);
> @@ -790,11 +709,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> case GL_RGBA32I_EXT:
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
> break;
> - }
> - }
>
> - if (ctx->Extensions.ARB_texture_rg) {
> - switch (internalFormat) {
> case GL_R8:
> case GL_RED:
> RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
> @@ -825,13 +740,6 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_GR1616);
> break;
>
> - default:
> - ; /* fallthrough */
> - }
> - }
> -
> - if (ctx->Extensions.ARB_texture_rg && ctx->Extensions.ARB_texture_float) {
> - switch (internalFormat) {
> case GL_R16F:
> RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
> RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
> @@ -861,15 +769,6 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
> break;
>
> - default:
> - ; /* fallthrough */
> - }
> - }
> -
> - if (ctx->Version >= 30 ||
> - (ctx->Extensions.ARB_texture_rg &&
> - ctx->Extensions.EXT_texture_integer)) {
> - switch (internalFormat) {
> case GL_R8UI:
> RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT8);
> break;
> @@ -906,32 +805,15 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
> case GL_RG32I:
> RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT32);
> break;
> - default:
> - break;
> - }
> - }
>
> - if (ctx->Extensions.ARB_texture_rgb10_a2ui) {
> - switch (internalFormat) {
> case GL_RGB10_A2UI:
> RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010_UINT);
> RETURN_IF_SUPPORTED(MESA_FORMAT_ABGR2101010_UINT);
> break;
> - default:
> - break;
> - }
> - }
> - /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
> - */
> - if (_mesa_is_gles(ctx)) {
> - switch (internalFormat) {
> +
> case GL_BGRA:
> RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
> break;
> -
> - default:
> - ; /* fallthrough */
> - }
> }
>
> _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()",
> _______________________________________________
> 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