mesa: Prefer non-swizzled formats for most sized internalformats
authorChris Forbes <chrisf@ijw.co.nz>
Mon, 10 Mar 2014 08:36:22 +0000 (21:36 +1300)
committerChris Forbes <chrisf@ijw.co.nz>
Thu, 10 Apr 2014 06:27:40 +0000 (18:27 +1200)
These formats can be cast to others (with different component types or
sizes) via ARB_texture_view or ARB_shader_image_load_store. We want
them to be laid out consistently so that we can just reinterpret the
memory with a different format.

In V1, this was done conditionally on a 'prefer_no_swizzle' flag which
was set in TexStorage/TextureView paths, but we need the same behavior
for ARB_shader_image_load_store (which also works with images created
via TexImage, so we don't want it to be conditional.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Eric Anholt <eric@anholt.net>
src/mesa/main/texformat.c

index 004e7ebac823440938d865d540f5c81461cf77cf..d43480482476110f415950b6d80860fd6656ab0d 100644 (file)
@@ -76,11 +76,10 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
       } else if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
          RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM);
       }
-      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM);
-      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
-      break;
+      /* fallthrough */
 
    case GL_RGBA8:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_UNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
       break;
@@ -97,6 +96,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
 
    /* deep RGBA formats */
    case GL_RGB10_A2:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R10G10B10A2_UNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
       break;
@@ -116,6 +116,10 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
       }
       /* fallthrough */
    case GL_RGB8:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UNORM8);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_UNORM);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_UNORM);
+
       RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
@@ -451,10 +455,14 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
       break;
    case GL_RGB_SNORM:
    case GL_RGB8_SNORM:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_SNORM);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SNORM);
-      /* FALLTHROUGH */
+      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
+      break;
    case GL_RGBA_SNORM:
    case GL_RGBA8_SNORM:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
       break;
@@ -522,11 +530,17 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
 
    case GL_SRGB_EXT:
    case GL_SRGB8_EXT:
+      /* there is no MESA_FORMAT_RGB_SRGB8 */
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_SRGB);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SRGB);
+
       RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_SRGB8);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
       break;
    case GL_SRGB_ALPHA_EXT:
    case GL_SRGB8_ALPHA8_EXT:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SRGB);
+
       RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SRGB);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
       break;