st/mesa: convert Mesa float formats to Gallium
authorMarek Olšák <maraeo@gmail.com>
Tue, 15 Feb 2011 23:40:37 +0000 (00:40 +0100)
committerMarek Olšák <maraeo@gmail.com>
Fri, 15 Apr 2011 03:08:00 +0000 (05:08 +0200)
Squashed commit of the following:

Author: Marek Olšák <maraeo@gmail.com>

    st/mesa: require RGBA16F and RGBA32F to be renderable
    st/mesa: fix L32F and L16F format translation
    st/mesa: also convert the R/RG float formats

commit 49a9948b6a81b7d813304d081139d98e95ba5d1a
Author: Luca Barbieri <luca@luca-barbieri.com>
Date:   Fri Aug 20 10:36:17 2010 +0200

    mesa/st: enable ARB_texture_float if supported formats allow it

commit 7383632f7b6f9021b65f4973b7e7c99f0e8ce9b2
Author: Luca Barbieri <luca@luca-barbieri.com>
Date:   Tue Aug 24 21:00:46 2010 +0200

    mesa/st: support ARB_texture_float internal formats

commit 7c362cc06982586c2d29fac55f6bcc4bcd1550b5
Author: Luca Barbieri <luca@luca-barbieri.com>
Date:   Tue Aug 24 21:00:33 2010 +0200

    mesa/st: convert L/A/I floating point formats

src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c

index 9bc9d7a10f565296c776b6609e91393f697640e0..bdc08949dd418570d96ad2ca36ffb86ff4ca06e6 100644 (file)
@@ -382,6 +382,18 @@ void st_init_extensions(struct st_context *st)
       ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
    }
 
+   /* float support - assume nothing exclusively supports 64-bit floats */
+   if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_FLOAT,
+                                   PIPE_TEXTURE_2D, 0,
+                                   PIPE_BIND_SAMPLER_VIEW |
+                                   PIPE_BIND_RENDER_TARGET) &&
+      screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_FLOAT,
+                                   PIPE_TEXTURE_2D, 0,
+                                   PIPE_BIND_SAMPLER_VIEW |
+                                   PIPE_BIND_RENDER_TARGET)) {
+      ctx->Extensions.ARB_texture_float = GL_TRUE;
+   }
+
    /* sRGB support */
    if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
                                    PIPE_TEXTURE_2D, 0,
index 957a06c0880e2d647667a7faca31219dcbe953ea..8e50dbda68504f184465d212ab68635a58c9de2a 100644 (file)
@@ -214,6 +214,39 @@ st_mesa_format_to_pipe_format(gl_format mesaFormat)
    case MESA_FORMAT_SARGB8:
       return PIPE_FORMAT_B8G8R8A8_SRGB;
 #endif
+   case MESA_FORMAT_RGBA_FLOAT32:
+      return PIPE_FORMAT_R32G32B32A32_FLOAT;
+   case MESA_FORMAT_RGBA_FLOAT16:
+      return PIPE_FORMAT_R16G16B16A16_FLOAT;
+   case MESA_FORMAT_RGB_FLOAT32:
+      return PIPE_FORMAT_R32G32B32_FLOAT;
+   case MESA_FORMAT_RGB_FLOAT16:
+      return PIPE_FORMAT_R16G16B16_FLOAT;
+   case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+      return PIPE_FORMAT_L32A32_FLOAT;
+   case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+      return PIPE_FORMAT_L16A16_FLOAT;
+   case MESA_FORMAT_LUMINANCE_FLOAT32:
+      return PIPE_FORMAT_L32_FLOAT;
+   case MESA_FORMAT_LUMINANCE_FLOAT16:
+      return PIPE_FORMAT_L16_FLOAT;
+   case MESA_FORMAT_ALPHA_FLOAT32:
+      return PIPE_FORMAT_A32_FLOAT;
+   case MESA_FORMAT_ALPHA_FLOAT16:
+      return PIPE_FORMAT_A16_FLOAT;
+   case MESA_FORMAT_INTENSITY_FLOAT32:
+      return PIPE_FORMAT_I32_FLOAT;
+   case MESA_FORMAT_INTENSITY_FLOAT16:
+      return PIPE_FORMAT_I16_FLOAT;
+   case MESA_FORMAT_R_FLOAT32:
+      return PIPE_FORMAT_R32_FLOAT;
+   case MESA_FORMAT_R_FLOAT16:
+      return PIPE_FORMAT_R16_FLOAT;
+   case MESA_FORMAT_RG_FLOAT32:
+      return PIPE_FORMAT_R32G32_FLOAT;
+   case MESA_FORMAT_RG_FLOAT16:
+      return PIPE_FORMAT_R16G16_FLOAT;
+
    case MESA_FORMAT_R8:
       return PIPE_FORMAT_R8_UNORM;
    case MESA_FORMAT_R16:
@@ -403,6 +436,38 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
    case PIPE_FORMAT_B8G8R8A8_SRGB:
       return MESA_FORMAT_SARGB8;
 #endif
+   case PIPE_FORMAT_R32G32B32A32_FLOAT:
+      return MESA_FORMAT_RGBA_FLOAT32;
+   case PIPE_FORMAT_R16G16B16A16_FLOAT:
+      return MESA_FORMAT_RGBA_FLOAT16;
+   case PIPE_FORMAT_R32G32B32_FLOAT:
+      return MESA_FORMAT_RGB_FLOAT32;
+   case PIPE_FORMAT_R16G16B16_FLOAT:
+      return MESA_FORMAT_RGB_FLOAT16;
+   case PIPE_FORMAT_L32A32_FLOAT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
+   case PIPE_FORMAT_L16A16_FLOAT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
+   case PIPE_FORMAT_L32_FLOAT:
+      return MESA_FORMAT_LUMINANCE_FLOAT32;
+   case PIPE_FORMAT_L16_FLOAT:
+      return MESA_FORMAT_LUMINANCE_FLOAT16;
+   case PIPE_FORMAT_A32_FLOAT:
+      return MESA_FORMAT_ALPHA_FLOAT32;
+   case PIPE_FORMAT_A16_FLOAT:
+      return MESA_FORMAT_ALPHA_FLOAT16;
+   case PIPE_FORMAT_I32_FLOAT:
+      return MESA_FORMAT_INTENSITY_FLOAT32;
+   case PIPE_FORMAT_I16_FLOAT:
+      return MESA_FORMAT_INTENSITY_FLOAT16;
+   case PIPE_FORMAT_R32_FLOAT:
+      return MESA_FORMAT_R_FLOAT32;
+   case PIPE_FORMAT_R16_FLOAT:
+      return MESA_FORMAT_R_FLOAT16;
+   case PIPE_FORMAT_R32G32_FLOAT:
+      return MESA_FORMAT_RG_FLOAT32;
+   case PIPE_FORMAT_R16G16_FLOAT:
+      return MESA_FORMAT_RG_FLOAT16;
 
    case PIPE_FORMAT_R8_UNORM:
       return MESA_FORMAT_R8;
@@ -887,6 +952,178 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
          return PIPE_FORMAT_L8_SRGB;
       return default_srgba_format( screen, target, sample_count, bindings);
 
+   /* prefer formats in order of data size, choosing 16-bit ones if equal sized */
+   case GL_RGBA16F_ARB:
+   case GL_RGB16F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_LUMINANCE_ALPHA16F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_ALPHA16F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_A16_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_A32_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_INTENSITY16F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_I16_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_I32_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_LUMINANCE16F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_L16_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_L32_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_R16F:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_R16_FLOAT,
+               PIPE_FORMAT_R16G16_FLOAT,
+               PIPE_FORMAT_R32_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_R32G32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_RG16F:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_R16G16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT,
+               PIPE_FORMAT_R32G32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
+   /* try a 32-bit format if available, otherwise fallback to a 16-bit one */
+   case GL_RGBA32F_ARB:
+   case GL_RGB32F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_LUMINANCE_ALPHA32F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_ALPHA32F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_A32_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_A16_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_INTENSITY32F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_I32_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_I16_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_LUMINANCE32F_ARB:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_L32_FLOAT,
+               PIPE_FORMAT_L32A32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_L16_FLOAT,
+               PIPE_FORMAT_L16A16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_R32F:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_R32_FLOAT,
+               PIPE_FORMAT_R32G32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_R16_FLOAT,
+               PIPE_FORMAT_R16G16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+   case GL_RG32F:
+      {
+         static const enum pipe_format formats[] = {
+               PIPE_FORMAT_R32G32_FLOAT,
+               PIPE_FORMAT_R32G32B32A32_FLOAT,
+               PIPE_FORMAT_R16G16_FLOAT,
+               PIPE_FORMAT_R16G16B16A16_FLOAT
+         };
+         return find_supported_format(screen, formats, Elements(formats),
+               target, sample_count, bindings);
+      }
+
    case GL_RED:
    case GL_R8:
       if (screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM, target,