Mesa (master): intel: Add support for ARB_texture_float.

Eric Anholt anholt at kemper.freedesktop.org
Wed Apr 20 10:51:24 PDT 2011


Module: Mesa
Branch: master
Commit: 87478cd6e3e6349abc2688b390f8845d1e21af3d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=87478cd6e3e6349abc2688b390f8845d1e21af3d

Author: Eric Anholt <eric at anholt.net>
Date:   Fri Apr 15 11:00:00 2011 -0700

intel: Add support for ARB_texture_float.

For 1 and 2-channel formats the hardware only supports rendering to R
and RG.  To do I and L render targets we just call them R and
everything works out.  For A, we would need to rewrite the CC to do
the alpha channel's blending on color instead, and send the fragment
alpha down the red channel.  For LA, there doesn't seem to be any
hope, because we can't do independent color/alpha blending while
treating the LA surface as RG.

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/drivers/dri/i965/brw_wm_surface_state.c |   32 +++++++++++++++++++++-
 src/mesa/drivers/dri/intel/intel_blit.c          |    4 ++-
 src/mesa/drivers/dri/intel/intel_context.c       |   11 +++++++
 src/mesa/drivers/dri/intel/intel_extensions.c    |    3 ++
 src/mesa/drivers/dri/intel/intel_span.c          |    5 +++
 src/mesa/drivers/dri/intel/intel_tex_format.c    |    9 ++++++
 6 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index 5a478a7..e3396a3 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -105,17 +105,32 @@ static uint32_t brw_format_for_mesa_format[MESA_FORMAT_COUNT] =
    [MESA_FORMAT_SIGNED_RGBA8888_REV] = BRW_SURFACEFORMAT_R8G8B8A8_SNORM,
    [MESA_FORMAT_SIGNED_R16] = BRW_SURFACEFORMAT_R16_SNORM,
    [MESA_FORMAT_SIGNED_GR1616] = BRW_SURFACEFORMAT_R16G16_SNORM,
+   [MESA_FORMAT_RGBA_FLOAT32] = BRW_SURFACEFORMAT_R32G32B32A32_FLOAT,
+   [MESA_FORMAT_RG_FLOAT32] = BRW_SURFACEFORMAT_R32G32_FLOAT,
+   [MESA_FORMAT_R_FLOAT32] = BRW_SURFACEFORMAT_R32_FLOAT,
+   [MESA_FORMAT_INTENSITY_FLOAT32] = BRW_SURFACEFORMAT_I32_FLOAT,
+   [MESA_FORMAT_LUMINANCE_FLOAT32] = BRW_SURFACEFORMAT_L32_FLOAT,
+   [MESA_FORMAT_ALPHA_FLOAT32] = BRW_SURFACEFORMAT_A32_FLOAT,
+   [MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = BRW_SURFACEFORMAT_L32A32_FLOAT,
 };
 
 bool
 brw_render_target_supported(gl_format format)
 {
+   /* These are not color render targets like the table holds, but we
+    * ask the question for FBO completeness.
+    */
    if (format == MESA_FORMAT_S8_Z24 ||
        format == MESA_FORMAT_X8_Z24 ||
        format == MESA_FORMAT_Z16) {
       return true;
    }
 
+   /* The value of this BRW_SURFACEFORMAT is 0, so hardcode it.
+    */
+   if (format == MESA_FORMAT_RGBA_FLOAT32)
+      return true;
+
    /* Not exactly true, as some of those formats are not renderable.
     * But at least we know how to translate them.
     */
@@ -159,6 +174,13 @@ static GLuint translate_tex_format( gl_format mesa_format,
 	 return brw_format_for_mesa_format[mesa_format];
       else if (srgb_decode == GL_SKIP_DECODE_EXT)
 	 return brw_format_for_mesa_format[_mesa_get_srgb_format_linear(mesa_format)];
+
+   case MESA_FORMAT_RGBA_FLOAT32:
+      /* The value of this BRW_SURFACEFORMAT is 0, which tricks the
+       * assertion below.
+       */
+      return BRW_SURFACEFORMAT_R32G32B32A32_FLOAT;
+
    default:
       assert(brw_format_for_mesa_format[mesa_format] != 0);
       return brw_format_for_mesa_format[mesa_format];
@@ -430,6 +452,14 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
        */
       surf->ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
       break;
+   case MESA_FORMAT_INTENSITY_FLOAT32:
+   case MESA_FORMAT_LUMINANCE_FLOAT32:
+      /* For these formats, we just need to read/write the first
+       * channel into R, which is to say that we just treat them as
+       * GL_RED.
+       */
+      surf->ss0.surface_format = BRW_SURFACEFORMAT_R32_FLOAT;
+      break;
    case MESA_FORMAT_SARGB8:
       /* without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB
 	 surfaces to the blend/update as sRGB */
@@ -439,8 +469,8 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
 	 surf->ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
       break;
    default:
+      assert(brw_render_target_supported(irb->Base.Format));
       surf->ss0.surface_format = brw_format_for_mesa_format[irb->Base.Format];
-      assert(surf->ss0.surface_format != 0);
    }
 
    surf->ss0.surface_type = BRW_SURFACE_2D;
diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c
index 579a45b..5aac1f6 100644
--- a/src/mesa/drivers/dri/intel/intel_blit.c
+++ b/src/mesa/drivers/dri/intel/intel_blit.c
@@ -293,7 +293,7 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask)
 	  irb->region->buffer, (pitch * cpp),
 	  x1, y1, x2 - x1, y2 - y1);
 
-      BR13 = br13_for_cpp(cpp) | 0xf0 << 16;
+      BR13 = 0xf0 << 16;
       CMD = XY_COLOR_BLT_CMD;
 
       /* Setup the blit command */
@@ -354,6 +354,8 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask)
 	 }
       }
 
+      BR13 |= br13_for_cpp(cpp);
+
       assert(x1 < x2);
       assert(y1 < y2);
 
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 562fe86..02e7f77 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -743,8 +743,19 @@ intelInitContext(struct intel_context *intel,
       ctx->TextureFormatSupported[MESA_FORMAT_SL8] = GL_TRUE;
       ctx->TextureFormatSupported[MESA_FORMAT_SLA8] = GL_TRUE;
    }
+
+#ifdef TEXTURE_FLOAT_ENABLED
+   ctx->TextureFormatSupported[MESA_FORMAT_RGBA_FLOAT32] = GL_TRUE;
+   ctx->TextureFormatSupported[MESA_FORMAT_RG_FLOAT32] = GL_TRUE;
+   ctx->TextureFormatSupported[MESA_FORMAT_R_FLOAT32] = GL_TRUE;
+   ctx->TextureFormatSupported[MESA_FORMAT_INTENSITY_FLOAT32] = GL_TRUE;
+   ctx->TextureFormatSupported[MESA_FORMAT_LUMINANCE_FLOAT32] = GL_TRUE;
+   ctx->TextureFormatSupported[MESA_FORMAT_ALPHA_FLOAT32] = GL_TRUE;
+   ctx->TextureFormatSupported[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = GL_TRUE;
 #endif
 
+#endif /* !I915 */
+
    driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
                        sPriv->myNum, (intel->gen >= 4) ? "i965" : "i915");
    if (intel->gen < 4)
diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index febc1d4..ad37a98 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -171,6 +171,9 @@ static const struct dri_extension brw_extensions[] = {
    { "GL_ARB_point_sprite", 		  NULL },
    { "GL_ARB_seamless_cube_map",          NULL },
    { "GL_ARB_shadow",                     NULL },
+#ifdef TEXTURE_FLOAT_ENABLED
+   { "GL_ARB_texture_float",              NULL },
+#endif
    { "GL_MESA_texture_signed_rgba",       NULL },
    { "GL_ARB_texture_non_power_of_two",   NULL },
    { "GL_ARB_texture_rg",                 NULL },
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 6b840f3..16bce20 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -339,6 +339,11 @@ static span_init_func intel_span_init_funcs[MESA_FORMAT_COUNT] =
    [MESA_FORMAT_RG88] = _mesa_set_renderbuffer_accessors,
    [MESA_FORMAT_R16] = _mesa_set_renderbuffer_accessors,
    [MESA_FORMAT_RG1616] = _mesa_set_renderbuffer_accessors,
+   [MESA_FORMAT_RGBA_FLOAT32] = _mesa_set_renderbuffer_accessors,
+   [MESA_FORMAT_RG_FLOAT32] = _mesa_set_renderbuffer_accessors,
+   [MESA_FORMAT_R_FLOAT32] = _mesa_set_renderbuffer_accessors,
+   [MESA_FORMAT_INTENSITY_FLOAT32] = _mesa_set_renderbuffer_accessors,
+   [MESA_FORMAT_LUMINANCE_FLOAT32] = _mesa_set_renderbuffer_accessors,
 };
 
 bool
diff --git a/src/mesa/drivers/dri/intel/intel_tex_format.c b/src/mesa/drivers/dri/intel/intel_tex_format.c
index 9a6c24b..befa615 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_format.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_format.c
@@ -31,6 +31,15 @@ intel_mesa_format_to_rb_datatype(gl_format format)
       return GL_UNSIGNED_INT;
    case MESA_FORMAT_S8_Z24:
       return GL_UNSIGNED_INT_24_8_EXT;
+   case MESA_FORMAT_RGBA_FLOAT32:
+   case MESA_FORMAT_RG_FLOAT32:
+   case MESA_FORMAT_R_FLOAT32:
+   case MESA_FORMAT_INTENSITY_FLOAT32:
+   case MESA_FORMAT_LUMINANCE_FLOAT32:
+   case MESA_FORMAT_ALPHA_FLOAT32:
+   case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+      return GL_FLOAT;
+
    default:
       _mesa_problem(NULL, "unexpected MESA_FORMAT for renderbuffer");
       return GL_UNSIGNED_BYTE;



More information about the mesa-commit mailing list