[Mesa-dev] [PATCH] Add support for following Texture Float extensions: 1)GL_OES_texture_float, 2)GL_OES_texture_half_float, 3)GL_OES_texture_float_linear, 4)GL_OES_texture_half_float_linear.

kalyan kondapally kondapallykalyancontribute at gmail.com
Wed Nov 26 05:52:36 PST 2014


Hi,

Please ignore this patch. Will re-send with the commit message fixed.

Thanks,
Kalyan

On Wed, Nov 26, 2014 at 5:31 AM, Kalyan Kondapally
<kondapallykalyancontribute at gmail.com> wrote:
> Support for these extensions need to be explicitly enabled per driver
> and this patch enables support for i965 drivers.
>
> Signed-off-by: Kevin Rogovin <kevin.rogovin at intel.com>
> Signed-off-by: Kalyan Kondapally <kalyan.kondapally at intel.com>
> ---
>  src/mesa/drivers/dri/i965/intel_extensions.c |  6 +++
>  src/mesa/main/extensions.c                   |  4 ++
>  src/mesa/main/glformats.c                    | 48 +++++++++++++++++++---
>  src/mesa/main/glformats.h                    |  3 +-
>  src/mesa/main/mtypes.h                       |  6 +++
>  src/mesa/main/pack.c                         | 16 ++++++++
>  src/mesa/main/teximage.c                     | 60 +++++++++++++++++++++++++++-
>  src/mesa/main/texobj.c                       | 39 ++++++++++++++++++
>  8 files changed, 175 insertions(+), 7 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/intel_extensions.c b/src/mesa/drivers/dri/i965/intel_extensions.c
> index bbbb76f..e95eaef 100644
> --- a/src/mesa/drivers/dri/i965/intel_extensions.c
> +++ b/src/mesa/drivers/dri/i965/intel_extensions.c
> @@ -245,6 +245,12 @@ intelInitExtensions(struct gl_context *ctx)
>     ctx->Extensions.OES_standard_derivatives = true;
>     ctx->Extensions.OES_EGL_image_external = true;
>
> +   bool enable_opengles2_extensions = ctx->API == API_OPENGLES2;
> +   ctx->Extensions.OES_texture_float = enable_opengles2_extensions;
> +   ctx->Extensions.OES_texture_half_float = enable_opengles2_extensions;
> +   ctx->Extensions.OES_texture_float_linear = enable_opengles2_extensions;
> +   ctx->Extensions.OES_texture_half_float_linear = enable_opengles2_extensions;
> +
>     if (brw->gen >= 6)
>        ctx->Const.GLSLVersion = 330;
>     else
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index 0df04c2..6833fcf 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -314,6 +314,10 @@ static const struct extension extension_table[] = {
>     { "GL_OES_texture_3D",                          o(EXT_texture3D),                                      ES2, 2005 },
>     { "GL_OES_texture_cube_map",                    o(ARB_texture_cube_map),                         ES1,       2007 },
>     { "GL_OES_texture_env_crossbar",                o(ARB_texture_env_crossbar),                     ES1,       2005 },
> +   { "GL_OES_texture_float",                       o(OES_texture_float),                                  ES2, 2005 },
> +   { "GL_OES_texture_float_linear",                o(OES_texture_float_linear),                           ES2, 2005 },
> +   { "GL_OES_texture_half_float",                  o(OES_texture_half_float),                             ES2, 2005 },
> +   { "GL_OES_texture_half_float_linear",           o(OES_texture_half_float_linear),                      ES2, 2005 },
>     { "GL_OES_texture_mirrored_repeat",             o(dummy_true),                                   ES1,       2005 },
>     { "GL_OES_texture_npot",                        o(ARB_texture_non_power_of_two),                 ES1 | ES2, 2005 },
>     { "GL_OES_vertex_array_object",                 o(dummy_true),                                   ES1 | ES2, 2010 },
> diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
> index 00478f9..efb1e2e 100644
> --- a/src/mesa/main/glformats.c
> +++ b/src/mesa/main/glformats.c
> @@ -93,6 +93,7 @@ _mesa_sizeof_type(GLenum type)
>     case GL_DOUBLE:
>        return sizeof(GLdouble);
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        return sizeof(GLhalfARB);
>     case GL_FIXED:
>        return sizeof(GLfixed);
> @@ -125,6 +126,7 @@ _mesa_sizeof_packed_type(GLenum type)
>     case GL_INT:
>        return sizeof(GLint);
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        return sizeof(GLhalfARB);
>     case GL_FLOAT:
>        return sizeof(GLfloat);
> @@ -241,6 +243,7 @@ _mesa_bytes_per_pixel(GLenum format, GLenum type)
>     case GL_FLOAT:
>        return comps * sizeof(GLfloat);
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        return comps * sizeof(GLhalfARB);
>     case GL_UNSIGNED_BYTE_3_3_2:
>     case GL_UNSIGNED_BYTE_2_3_3_REV:
> @@ -1448,6 +1451,19 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
>        }
>        return GL_NO_ERROR;
>
> +   case GL_HALF_FLOAT_OES:
> +      switch (format) {
> +         case GL_RGBA:
> +         case GL_RGB:
> +         case GL_LUMINANCE_ALPHA:
> +         case GL_LUMINANCE:
> +         case GL_ALPHA:
> +           return GL_NO_ERROR;
> +         default:
> +           return GL_INVALID_OPERATION;
> +       }
> +
> +
>     default:
>        ; /* fall-through */
>     }
> @@ -1775,14 +1791,14 @@ _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
>     return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
>  }
>
> -
>  /**
>   * Do error checking of format/type combinations for OpenGL ES 3
>   * glTex[Sub]Image.
>   * \return error code, or GL_NO_ERROR.
>   */
>  GLenum
> -_mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
> +_mesa_es3_error_check_format_and_type(const struct gl_context *ctx,
> +                                      GLenum format, GLenum type,
>                                        GLenum internalFormat)
>  {
>     switch (format) {
> @@ -1847,11 +1863,17 @@ _mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
>           case GL_RGBA16F:
>           case GL_RGBA32F:
>              break;
> +         case GL_RGBA:
> +            if (ctx->Extensions.OES_texture_float && internalFormat == format)
> +               break;
>           default:
>              return GL_INVALID_OPERATION;
>           }
>           break;
>
> +      case GL_HALF_FLOAT_OES:
> +         if (ctx->Extensions.OES_texture_half_float && internalFormat == format)
> +            break;
>        default:
>           return GL_INVALID_OPERATION;
>        }
> @@ -1956,11 +1978,19 @@ _mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
>           case GL_R11F_G11F_B10F:
>           case GL_RGB9_E5:
>              break;
> +         case GL_RGB:
> +            if (ctx->Extensions.OES_texture_float && internalFormat == format)
> +               break;
>           default:
>              return GL_INVALID_OPERATION;
>           }
>           break;
>
> +      case GL_HALF_FLOAT_OES:
> +         if (!ctx->Extensions.OES_texture_half_float || internalFormat != format)
> +            return GL_INVALID_OPERATION;
> +         break;
> +
>        case GL_UNSIGNED_INT_2_10_10_10_REV:
>           switch (internalFormat) {
>           case GL_RGB: /* GL_EXT_texture_type_2_10_10_10_REV */
> @@ -2200,9 +2230,17 @@ _mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
>     case GL_ALPHA:
>     case GL_LUMINANCE:
>     case GL_LUMINANCE_ALPHA:
> -      if (type != GL_UNSIGNED_BYTE || format != internalFormat)
> -         return GL_INVALID_OPERATION;
> -      break;
> +      switch (type) {
> +      case GL_FLOAT:
> +         if (ctx->Extensions.OES_texture_float && internalFormat == format)
> +            break;
> +      case GL_HALF_FLOAT_OES:
> +         if (ctx->Extensions.OES_texture_half_float && internalFormat == format)
> +            break;
> +       default:
> +          if (type != GL_UNSIGNED_BYTE || format != internalFormat)
> +             return GL_INVALID_OPERATION;
> +       }
>     }
>
>     return GL_NO_ERROR;
> diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h
> index 7b03215..9b1674e 100644
> --- a/src/mesa/main/glformats.h
> +++ b/src/mesa/main/glformats.h
> @@ -122,7 +122,8 @@ _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
>                                       unsigned dimensions);
>
>  extern GLenum
> -_mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
> +_mesa_es3_error_check_format_and_type(const struct gl_context *ctx,
> +                                      GLenum format, GLenum type,
>                                        GLenum internalFormat);
>
>
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 7389baa..8670a16 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1220,6 +1220,8 @@ struct gl_texture_object
>     GLboolean Purgeable;        /**< Is the buffer purgeable under memory
>                                      pressure? */
>     GLboolean Immutable;        /**< GL_ARB_texture_storage */
> +   GLboolean Float_OES;        /**< GL_OES_float_texture */
> +   GLboolean HALF_Float_OES;   /**< GL_OES_half_float_texture */
>
>     GLuint MinLevel;            /**< GL_ARB_texture_view */
>     GLuint MinLayer;            /**< GL_ARB_texture_view */
> @@ -3842,6 +3844,10 @@ struct gl_extensions
>     GLboolean OES_draw_texture;
>     GLboolean OES_depth_texture_cube_map;
>     GLboolean OES_EGL_image_external;
> +   GLboolean OES_texture_float;
> +   GLboolean OES_texture_half_float;
> +   GLboolean OES_texture_float_linear;
> +   GLboolean OES_texture_half_float_linear;
>     GLboolean OES_compressed_ETC1_RGB8_texture;
>     GLboolean extension_sentinel;
>     /** The extension string */
> diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
> index 649a74c..daafb1e 100644
> --- a/src/mesa/main/pack.c
> +++ b/src/mesa/main/pack.c
> @@ -2301,6 +2301,7 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
>           }
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           {
>              GLhalfARB *dst = (GLhalfARB *) dstAddr;
>              switch (dstFormat) {
> @@ -2724,6 +2725,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
>            srcType == GL_INT ||
>            srcType == GL_UNSIGNED_INT_24_8_EXT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
>
> @@ -2863,6 +2865,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
>           }
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           {
>              GLuint i;
>              const GLhalfARB *s = (const GLhalfARB *) src;
> @@ -3102,6 +3105,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -3219,6 +3223,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
>           PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLfloat, (GLfloat));
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
>           PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
>           PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLhalfARB, _mesa_half_to_float);
> @@ -3717,6 +3722,7 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -3814,6 +3820,7 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
>           PROCESS(aSrc, ACOMP, 1, GLfloat, clamp_float_to_uint);
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           PROCESS(rSrc, RCOMP, 0, GLhalfARB, clamp_half_to_uint);
>           PROCESS(gSrc, GCOMP, 0, GLhalfARB, clamp_half_to_uint);
>           PROCESS(bSrc, BCOMP, 0, GLhalfARB, clamp_half_to_uint);
> @@ -4218,6 +4225,7 @@ _mesa_unpack_color_span_ubyte(struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -4471,6 +4479,7 @@ _mesa_unpack_color_span_float( struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -4675,6 +4684,7 @@ _mesa_unpack_color_span_uint(struct gl_context *ctx,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_UNSIGNED_BYTE_3_3_2 ||
>            srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
> @@ -4803,6 +4813,7 @@ _mesa_unpack_index_span( struct gl_context *ctx, GLuint n,
>            srcType == GL_UNSIGNED_INT ||
>            srcType == GL_INT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT);
>
>     ASSERT(dstType == GL_UNSIGNED_BYTE ||
> @@ -4974,6 +4985,7 @@ _mesa_pack_index_span( struct gl_context *ctx, GLuint n,
>        }
>        break;
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        {
>           GLhalfARB *dst = (GLhalfARB *) dest;
>           GLuint i;
> @@ -5023,6 +5035,7 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
>            srcType == GL_INT ||
>            srcType == GL_UNSIGNED_INT_24_8_EXT ||
>            srcType == GL_HALF_FLOAT_ARB ||
> +          srcType == GL_HALF_FLOAT_OES ||
>            srcType == GL_FLOAT ||
>            srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
>
> @@ -5213,6 +5226,7 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
>        }
>        break;
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        {
>           GLhalfARB *dst = (GLhalfARB *) dest;
>           GLuint i;
> @@ -5430,6 +5444,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
>           needClamp = GL_TRUE;
>           break;
>        case GL_HALF_FLOAT_ARB:
> +      case GL_HALF_FLOAT_OES:
>           {
>              GLuint i;
>              const GLhalfARB *src = (const GLhalfARB *) source;
> @@ -5619,6 +5634,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
>        }
>        break;
>     case GL_HALF_FLOAT_ARB:
> +   case GL_HALF_FLOAT_OES:
>        {
>           GLhalfARB *dst = (GLhalfARB *) dest;
>           GLuint i;
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 4f4bb11..ed28246 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -63,6 +63,50 @@
>  #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
>
>
> +/**
> + * Modify a texture format from as expected by GL_OES_texture_float
> + * and/or GL_OES_texture_half_float to as expected by GLES2.
> + */
> +static
> +GLint
> +adjust_for_oes_float_texture(GLenum format, GLenum type, GLint internalFormat)
> +{
> +   switch (type) {
> +   case GL_FLOAT:
> +      switch(format) {
> +      case GL_RGBA:
> +         return GL_RGBA32F_ARB;
> +      case GL_RGB:
> +         return GL_RGBA32F_ARB;
> +      case GL_ALPHA:
> +         return GL_ALPHA32F_ARB;
> +      case GL_LUMINANCE:
> +         return GL_LUMINANCE32F_ARB;
> +      case GL_LUMINANCE_ALPHA:
> +         return GL_LUMINANCE_ALPHA32F_ARB;
> +   }
> +   break;
> +
> +   case GL_HALF_FLOAT_OES:
> +      switch(format) {
> +      case GL_RGBA:
> +         return GL_RGBA16F_ARB;
> +      case GL_RGB:
> +         return GL_RGBA16F_ARB;
> +      case GL_ALPHA:
> +         return GL_ALPHA16F_ARB;
> +      case GL_LUMINANCE:
> +         return GL_LUMINANCE16F_ARB;
> +      case GL_LUMINANCE_ALPHA:
> +         return GL_LUMINANCE_ALPHA16F_ARB;
> +      }
> +      break;
> +   default:
> +       break;
> +   }
> +
> +   return internalFormat;
> +}
>
>  /**
>   * Return the simple base format for a given internal texture format.
> @@ -2137,7 +2181,7 @@ texture_error_check( struct gl_context *ctx,
>
>     if (_mesa_is_gles(ctx)) {
>        if (_mesa_is_gles3(ctx)) {
> -         err = _mesa_es3_error_check_format_and_type(format, type,
> +         err = _mesa_es3_error_check_format_and_type(ctx, format, type,
>                                                       internalFormat);
>        } else {
>           if (format != internalFormat) {
> @@ -3239,6 +3283,20 @@ teximage(struct gl_context *ctx, GLboolean compressed, GLuint dims,
>        texFormat = _mesa_glenum_to_compressed_format(internalFormat);
>     }
>     else {
> +      /* Change internalFormat and type to support GL_OES_texture_half_float
> +       * and GL_OES_texture_float as needed.
> +       */
> +      if (_mesa_is_gles(ctx) && format == internalFormat) {
> +         if (type == GL_HALF_FLOAT_OES && ctx->Extensions.OES_texture_half_float)
> +            texObj->HALF_Float_OES = GL_TRUE;
> +         else if (type == GL_FLOAT && ctx->Extensions.OES_texture_float)
> +            texObj->Float_OES =  GL_TRUE;
> +
> +         if (texObj->HALF_Float_OES || texObj->Float_OES)
> +            internalFormat = adjust_for_oes_float_texture(format, type,
> +                                                          internalFormat);
> +       }
> +
>        texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
>                                                internalFormat, format, type);
>     }
> diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
> index 923cf60..1415b95 100644
> --- a/src/mesa/main/texobj.c
> +++ b/src/mesa/main/texobj.c
> @@ -50,6 +50,40 @@
>  /*@{*/
>
>
> +static bool _mesa_valid_filter_for_float(const struct gl_context *ctx,
> +                                         const struct gl_texture_object *obj) {
> +   switch (obj->Sampler.MagFilter) {
> +      case GL_LINEAR:
> +         if (obj->HALF_Float_OES && !ctx->Extensions.OES_texture_half_float_linear)
> +            return false;
> +         else if (obj->Float_OES && !ctx->Extensions.OES_texture_float_linear)
> +            return false;
> +      case GL_NEAREST:
> +      case GL_NEAREST_MIPMAP_NEAREST:
> +         break;
> +      default:
> +         return false;
> +  }
> +
> +  switch (obj->Sampler.MinFilter) {
> +     case GL_NEAREST:
> +     case GL_NEAREST_MIPMAP_NEAREST:
> +        return true;
> +     case GL_LINEAR:
> +     case GL_NEAREST_MIPMAP_LINEAR:
> +     case GL_LINEAR_MIPMAP_NEAREST:
> +     case GL_LINEAR_MIPMAP_LINEAR:
> +        if (obj->HALF_Float_OES && ctx->Extensions.OES_texture_half_float_linear)
> +           return true;
> +        else if (obj->Float_OES && ctx->Extensions.OES_texture_float_linear)
> +           return true;
> +      default:
> +         return false;
> +  }
> +
> +  return false;
> +}
> +
>  /**
>   * Return the gl_texture_object for a given ID.
>   */
> @@ -542,6 +576,11 @@ _mesa_test_texobj_completeness( const struct gl_context *ctx,
>        t->_IsIntegerFormat = datatype == GL_INT || datatype == GL_UNSIGNED_INT;
>     }
>
> +   if ((t->Float_OES || t->HALF_Float_OES) && !_mesa_valid_filter_for_float(ctx, t)) {
> +     incomplete(t, BASE, "Filter is not supported with Float types.");
> +     return;
> +   }
> +
>     /* Compute _MaxLevel (the maximum mipmap level we'll sample from given the
>      * mipmap image sizes and GL_TEXTURE_MAX_LEVEL state).
>      */
> --
> 1.9.1
>


More information about the mesa-dev mailing list