gallium: add EXT_texture_snorm support
authorMarek Olšák <maraeo@gmail.com>
Mon, 14 Mar 2011 09:04:36 +0000 (10:04 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 29 Mar 2011 10:04:55 +0000 (12:04 +0200)
src/gallium/auxiliary/util/u_format.csv
src/gallium/include/pipe/p_format.h
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c

index 6f5cc618ffc19e9be965e7a3b17d6c97c7b8cc46..771bd49412d4b9d6c2a5eb35c1a95806ea289a1e 100644 (file)
@@ -88,6 +88,14 @@ PIPE_FORMAT_L16_UNORM             , plain, 1, 1, un16,     ,     ,     , xxx1, r
 PIPE_FORMAT_A16_UNORM             , plain, 1, 1, un16,     ,     ,     , 000x, rgb
 PIPE_FORMAT_I16_UNORM             , plain, 1, 1, un16,     ,     ,     , xxxx, rgb
 PIPE_FORMAT_L16A16_UNORM          , plain, 1, 1, un16, un16,     ,     , xxxy, rgb
+PIPE_FORMAT_A8_SNORM              , plain, 1, 1, sn8 ,     ,     ,     , 000x, rgb
+PIPE_FORMAT_L8_SNORM              , plain, 1, 1, sn8 ,     ,     ,     , xxx1, rgb
+PIPE_FORMAT_L8A8_SNORM            , plain, 1, 1, sn8 , sn8 ,     ,     , xxxy, rgb
+PIPE_FORMAT_I8_SNORM              , plain, 1, 1, sn8 ,     ,     ,     , xxxx, rgb
+PIPE_FORMAT_A16_SNORM             , plain, 1, 1, sn16,     ,     ,     , 000x, rgb
+PIPE_FORMAT_L16_SNORM             , plain, 1, 1, sn16,     ,     ,     , xxx1, rgb
+PIPE_FORMAT_L16A16_SNORM          , plain, 1, 1, sn16, sn16,     ,     , xxxy, rgb
+PIPE_FORMAT_I16_SNORM             , plain, 1, 1, sn16,     ,     ,     , xxxx, rgb
 
 # SRGB formats
 PIPE_FORMAT_L8_SRGB               , plain, 1, 1, un8 ,     ,     ,     , xxx1, srgb 
index d53af598e7501e5ba1d52084eb40402156a58fb4..3ea9a3999d1bee5cbbad040dd9fa7793034799f7 100644 (file)
@@ -211,6 +211,15 @@ enum pipe_format {
    PIPE_FORMAT_LATC2_UNORM             = 145,
    PIPE_FORMAT_LATC2_SNORM             = 146,
 
+   PIPE_FORMAT_A8_SNORM                = 147,
+   PIPE_FORMAT_L8_SNORM                = 148,
+   PIPE_FORMAT_L8A8_SNORM              = 149,
+   PIPE_FORMAT_I8_SNORM                = 150,
+   PIPE_FORMAT_A16_SNORM               = 151,
+   PIPE_FORMAT_L16_SNORM               = 152,
+   PIPE_FORMAT_L16A16_SNORM            = 153,
+   PIPE_FORMAT_I16_SNORM               = 154,
+
    PIPE_FORMAT_COUNT
 };
 
index 89bb03046c1a856e023df629282d17e1f0529db2..ba1a0af0628d7a33850629de927b0ffa94ed42a1 100644 (file)
@@ -453,6 +453,12 @@ void st_init_extensions(struct st_context *st)
       ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
    }
 
+   if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
+                                   PIPE_TEXTURE_2D, 0,
+                                   PIPE_BIND_SAMPLER_VIEW)) {
+      ctx->Extensions.EXT_texture_snorm = GL_TRUE;
+   }
+
    /* ycbcr support */
    if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, 
                                    PIPE_TEXTURE_2D, 0,
index 03655ee048394aa40ffbd5bb43cadc13a86185a5..957a06c0880e2d647667a7faca31219dcbe953ea 100644 (file)
@@ -259,6 +259,39 @@ st_mesa_format_to_pipe_format(gl_format mesaFormat)
    case MESA_FORMAT_SIGNED_LA_LATC2:
       return PIPE_FORMAT_LATC2_SNORM;
 
+   /* signed normalized formats */
+   case MESA_FORMAT_SIGNED_R8:
+      return PIPE_FORMAT_R8_SNORM;
+   case MESA_FORMAT_SIGNED_RG88_REV:
+      return PIPE_FORMAT_R8G8_SNORM;
+   case MESA_FORMAT_SIGNED_RGBA8888_REV:
+      return PIPE_FORMAT_R8G8B8A8_SNORM;
+
+   case MESA_FORMAT_SIGNED_A8:
+      return PIPE_FORMAT_A8_SNORM;
+   case MESA_FORMAT_SIGNED_L8:
+      return PIPE_FORMAT_L8_SNORM;
+   case MESA_FORMAT_SIGNED_AL88:
+      return PIPE_FORMAT_L8A8_SNORM;
+   case MESA_FORMAT_SIGNED_I8:
+      return PIPE_FORMAT_I8_SNORM;
+
+   case MESA_FORMAT_SIGNED_R16:
+      return PIPE_FORMAT_R16_SNORM;
+   case MESA_FORMAT_SIGNED_GR1616:
+      return PIPE_FORMAT_R16G16_SNORM;
+   case MESA_FORMAT_SIGNED_RGBA_16:
+      return PIPE_FORMAT_R16G16B16A16_SNORM;
+
+   case MESA_FORMAT_SIGNED_A16:
+      return PIPE_FORMAT_A16_SNORM;
+   case MESA_FORMAT_SIGNED_L16:
+      return PIPE_FORMAT_L16_SNORM;
+   case MESA_FORMAT_SIGNED_AL1616:
+      return PIPE_FORMAT_L16A16_SNORM;
+   case MESA_FORMAT_SIGNED_I16:
+      return PIPE_FORMAT_I16_SNORM;
+
    default:
       assert(0);
       return PIPE_FORMAT_NONE;
@@ -318,8 +351,6 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
 
    case PIPE_FORMAT_R16G16B16A16_UNORM:
       return MESA_FORMAT_RGBA_16;
-   case PIPE_FORMAT_R16G16B16A16_SNORM:
-      return MESA_FORMAT_SIGNED_RGBA_16;
 
    case PIPE_FORMAT_Z16_UNORM:
       return MESA_FORMAT_Z16;
@@ -416,6 +447,39 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
    case PIPE_FORMAT_LATC2_SNORM:
       return MESA_FORMAT_SIGNED_LA_LATC2;
 
+   /* signed normalized formats */
+   case PIPE_FORMAT_R8_SNORM:
+      return MESA_FORMAT_SIGNED_R8;
+   case PIPE_FORMAT_R8G8_SNORM:
+      return MESA_FORMAT_SIGNED_RG88_REV;
+   case PIPE_FORMAT_R8G8B8A8_SNORM:
+      return MESA_FORMAT_SIGNED_RGBA8888_REV;
+
+   case PIPE_FORMAT_A8_SNORM:
+      return MESA_FORMAT_SIGNED_A8;
+   case PIPE_FORMAT_L8_SNORM:
+      return MESA_FORMAT_SIGNED_L8;
+   case PIPE_FORMAT_L8A8_SNORM:
+      return MESA_FORMAT_SIGNED_AL88;
+   case PIPE_FORMAT_I8_SNORM:
+      return MESA_FORMAT_SIGNED_I8;
+
+   case PIPE_FORMAT_R16_SNORM:
+      return MESA_FORMAT_SIGNED_R16;
+   case PIPE_FORMAT_R16G16_SNORM:
+      return MESA_FORMAT_SIGNED_GR1616;
+   case PIPE_FORMAT_R16G16B16A16_SNORM:
+      return MESA_FORMAT_SIGNED_RGBA_16;
+
+   case PIPE_FORMAT_A16_SNORM:
+      return MESA_FORMAT_SIGNED_A16;
+   case PIPE_FORMAT_L16_SNORM:
+      return MESA_FORMAT_SIGNED_L16;
+   case PIPE_FORMAT_L16A16_SNORM:
+      return MESA_FORMAT_SIGNED_AL1616;
+   case PIPE_FORMAT_I16_SNORM:
+      return MESA_FORMAT_SIGNED_I16;
+
    default:
       assert(0);
       return MESA_FORMAT_NONE;
@@ -999,6 +1063,170 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
          return PIPE_FORMAT_R32G32B32A32_USCALED;
       return PIPE_FORMAT_NONE;
 
+   /* signed normalized formats */
+   case GL_RED_SNORM:
+   case GL_R8_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_R8_SNORM,
+            PIPE_FORMAT_R8G8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_R16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_R16_SNORM,
+            PIPE_FORMAT_R16G16_SNORM,
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_R8_SNORM,
+            PIPE_FORMAT_R8G8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_RG_SNORM:
+   case GL_RG8_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_R8G8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_RG16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_R16G16_SNORM,
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_R8G8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_RGB_SNORM:
+   case GL_RGB8_SNORM:
+   case GL_RGBA_SNORM:
+   case GL_RGBA8_SNORM:
+      if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SNORM,
+                                      target,
+                                      sample_count, bindings))
+         return PIPE_FORMAT_R8G8B8A8_SNORM;
+      return PIPE_FORMAT_NONE;
+
+   case GL_RGB16_SNORM:
+   case GL_RGBA16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+
+   case GL_ALPHA_SNORM:
+   case GL_ALPHA8_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_A8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_ALPHA16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_A16_SNORM,
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_A8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_LUMINANCE_SNORM:
+   case GL_LUMINANCE8_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_L8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_LUMINANCE16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_L16_SNORM,
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_L8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_LUMINANCE_ALPHA_SNORM:
+   case GL_LUMINANCE8_ALPHA8_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_L8A8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_LUMINANCE16_ALPHA16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_L16A16_SNORM,
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_L8A8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_INTENSITY_SNORM:
+   case GL_INTENSITY8_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_I8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   case GL_INTENSITY16_SNORM:
+      {
+         static const enum pipe_format formats[] = {
+            PIPE_FORMAT_I16_SNORM,
+            PIPE_FORMAT_R16G16B16A16_SNORM,
+            PIPE_FORMAT_I8_SNORM,
+            PIPE_FORMAT_R8G8B8A8_SNORM,
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
    default:
       return PIPE_FORMAT_NONE;
    }