[Mesa-dev] [PATCH] mesa: implement GL_ARB_texture_buffer_range v6
Ian Romanick
idr at freedesktop.org
Mon Jan 28 18:53:59 PST 2013
On 01/28/2013 04:02 PM, Christoph Bumiller wrote:
> v2: Record texObj.BufferSize as -1 in TexBuffer(non-Range) instead
> of the buffer's current size so we know we always have to use the
> full size of the buffer object (i.e. even if it changes without the
> user calling TexBuffer again) for the texture.
>
> Clarify invalid offset alignment error message.
>
> v3: Use extra GL_CORE-only section in get_hash_params.py for
> TEXTURE_BUFFER_OFFSET_ALIGNMENT.
>
> v4: Remove unnecessary check for profile in _mesa_TexBufferRange.
> Add check for extension enable in get_tex_level_parameter_buffer.
>
> v5: Fix position in gl_API.xml.
> Add comment about meaning of BufferSize == -1.
>
> v6: Add back checks for core profile and add a note about it.
>
> And I hope this is the end of it.
It looks good to me!
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
> src/mapi/glapi/gen/ARB_texture_buffer_range.xml | 22 ++++++
> src/mapi/glapi/gen/Makefile.am | 1 +
> src/mapi/glapi/gen/gl_API.xml | 4 +
> src/mesa/main/context.c | 1 +
> src/mesa/main/extensions.c | 1 +
> src/mesa/main/get.c | 1 +
> src/mesa/main/get_hash_params.py | 6 ++
> src/mesa/main/mtypes.h | 6 ++
> src/mesa/main/teximage.c | 89 ++++++++++++++++++-----
> src/mesa/main/teximage.h | 4 +
> src/mesa/main/texparam.c | 12 +++
> 11 files changed, 130 insertions(+), 17 deletions(-)
> create mode 100644 src/mapi/glapi/gen/ARB_texture_buffer_range.xml
>
> diff --git a/src/mapi/glapi/gen/ARB_texture_buffer_range.xml b/src/mapi/glapi/gen/ARB_texture_buffer_range.xml
> new file mode 100644
> index 0000000..2176c08
> --- /dev/null
> +++ b/src/mapi/glapi/gen/ARB_texture_buffer_range.xml
> @@ -0,0 +1,22 @@
> +<?xml version="1.0"?>
> +<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
> +
> +<OpenGLAPI>
> +
> +<category name="GL_ARB_texture_buffer_range" number="139">
> +
> + <enum name="TEXTURE_BUFFER_OFFSET" value="0x919D"/>
> + <enum name="TEXTURE_BUFFER_SIZE" value="0x919E"/>
> + <enum name="TEXTURE_BUFFER_OFFSET_ALIGNMENT" value="0x919F"/>
> +
> + <function name="TexBufferRange" offset="assign">
> + <param name="target" type="GLenum"/>
> + <param name="internalformat" type="GLenum"/>
> + <param name="buffer" type="GLuint"/>
> + <param name="offset" type="GLintptr"/>
> + <param name="size" type="GLsizeiptr"/>
> + </function>
> +
> +</category>
> +
> +</OpenGLAPI>
> diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
> index f869d28..4d51bbc 100644
> --- a/src/mapi/glapi/gen/Makefile.am
> +++ b/src/mapi/glapi/gen/Makefile.am
> @@ -108,6 +108,7 @@ API_XML = \
> ARB_seamless_cube_map.xml \
> ARB_sync.xml \
> ARB_texture_buffer_object.xml \
> + ARB_texture_buffer_range.xml \
> ARB_texture_compression_rgtc.xml \
> ARB_texture_float.xml \
> ARB_texture_rg.xml \
> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
> index 404ccea..4cbd724 100644
> --- a/src/mapi/glapi/gen/gl_API.xml
> +++ b/src/mapi/glapi/gen/gl_API.xml
> @@ -8316,6 +8316,10 @@
>
> <xi:include href="ARB_invalidate_subdata.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
>
> +<!-- ARB extensions #133...#138 -->
> +
> +<xi:include href="ARB_texture_buffer_range.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
> +
> <!-- Non-ARB extensions sorted by extension number. -->
>
> <category name="GL_EXT_blend_color" number="2">
> diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
> index 5e9e539..5058c07 100644
> --- a/src/mesa/main/context.c
> +++ b/src/mesa/main/context.c
> @@ -564,6 +564,7 @@ _mesa_init_constants(struct gl_context *ctx)
> ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
> ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
> ctx->Const.MaxTextureBufferSize = 65536;
> + ctx->Const.TextureBufferOffsetAlignment = 1;
> ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
> ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
> ctx->Const.MinPointSize = MIN_POINT_SIZE;
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index 7ae07fb..27cf9c8 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -131,6 +131,7 @@ static const struct extension extension_table[] = {
> { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), GLL, 2000 },
> { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), GLC, 2008 },
> { "GL_ARB_texture_buffer_object_rgb32", o(ARB_texture_buffer_object_rgb32), GLC, 2009 },
> + { "GL_ARB_texture_buffer_range", o(ARB_texture_buffer_range), GLC, 2012 },
> { "GL_ARB_texture_compression", o(dummy_true), GLL, 2000 },
> { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), GL, 2004 },
> { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), GLL, 1999 },
> diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
> index 5f4e2fa..da1e01c 100644
> --- a/src/mesa/main/get.c
> +++ b/src/mesa/main/get.c
> @@ -353,6 +353,7 @@ EXTRA_EXT(ARB_uniform_buffer_object);
> EXTRA_EXT(ARB_timer_query);
> EXTRA_EXT(ARB_map_buffer_alignment);
> EXTRA_EXT(ARB_texture_cube_map_array);
> +EXTRA_EXT(ARB_texture_buffer_range);
>
> static const int
> extra_NV_primitive_restart[] = {
> diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
> index 26a722a..b6bed80 100644
> --- a/src/mesa/main/get_hash_params.py
> +++ b/src/mesa/main/get_hash_params.py
> @@ -701,6 +701,12 @@ descriptor=[
>
> # GL_ARB_texture_cube_map_array
> [ "TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB", "LOC_CUSTOM, TYPE_INT, TEXTURE_CUBE_ARRAY_INDEX, extra_ARB_texture_cube_map_array" ],
> +]},
> +
> +# Enums restricted to OpenGL Core profile
> +{ "apis": ["GL_CORE"], "params": [
> +# GL_ARB_texture_buffer_range
> + [ "TEXTURE_BUFFER_OFFSET_ALIGNMENT", "CONTEXT_INT(Const.TextureBufferOffsetAlignment), extra_ARB_texture_buffer_range" ],
> ]}
>
> ]
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 3369623..b92f98e 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1295,6 +1295,9 @@ struct gl_texture_object
> GLenum BufferObjectFormat;
> /** Equivalent Mesa format for BufferObjectFormat. */
> gl_format _BufferObjectFormat;
> + /** GL_ARB_texture_buffer_range */
> + GLintptr BufferOffset;
> + GLsizeiptr BufferSize; /**< if this is -1, use BufferObject->Size instead */
>
> /** GL_OES_EGL_image_external */
> GLint RequiredTextureImageUnits;
> @@ -2851,6 +2854,8 @@ struct gl_constants
> GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */
> GLuint MaxTextureBufferSize; /**< GL_ARB_texture_buffer_object */
>
> + GLuint TextureBufferOffsetAlignment; /**< GL_ARB_texture_buffer_range */
> +
> GLuint MaxArrayLockSize;
>
> GLint SubPixelBits;
> @@ -3075,6 +3080,7 @@ struct gl_extensions
> GLboolean ARB_texture_border_clamp;
> GLboolean ARB_texture_buffer_object;
> GLboolean ARB_texture_buffer_object_rgb32;
> + GLboolean ARB_texture_buffer_range;
> GLboolean ARB_texture_compression_rgtc;
> GLboolean ARB_texture_cube_map;
> GLboolean ARB_texture_cube_map_array;
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 31a559e..f03e84a 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -3994,23 +3994,16 @@ validate_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat)
> }
>
>
> -/** GL_ARB_texture_buffer_object */
> -void GLAPIENTRY
> -_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
> +static void
> +texbufferrange(struct gl_context *ctx, GLenum target, GLenum internalFormat,
> + struct gl_buffer_object *bufObj,
> + GLintptr offset, GLsizeiptr size)
> {
> struct gl_texture_object *texObj;
> - struct gl_buffer_object *bufObj;
> gl_format format;
>
> - GET_CURRENT_CONTEXT(ctx);
> FLUSH_VERTICES(ctx, 0);
>
> - if (!(ctx->API == API_OPENGL_CORE &&
> - ctx->Extensions.ARB_texture_buffer_object)) {
> - _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer");
> - return;
> - }
> -
> if (target != GL_TEXTURE_BUFFER_ARB) {
> _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)");
> return;
> @@ -4023,12 +4016,6 @@ _mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
> return;
> }
>
> - bufObj = _mesa_lookup_bufferobj(ctx, buffer);
> - if (buffer && !bufObj) {
> - _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer);
> - return;
> - }
> -
> texObj = _mesa_get_current_tex_object(ctx, target);
>
> _mesa_lock_texture(ctx, texObj);
> @@ -4036,6 +4023,74 @@ _mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
> _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj);
> texObj->BufferObjectFormat = internalFormat;
> texObj->_BufferObjectFormat = format;
> + texObj->BufferOffset = offset;
> + texObj->BufferSize = size;
> }
> _mesa_unlock_texture(ctx, texObj);
> }
> +
> +/** GL_ARB_texture_buffer_object */
> +void GLAPIENTRY
> +_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
> +{
> + struct gl_buffer_object *bufObj;
> +
> + GET_CURRENT_CONTEXT(ctx);
> +
> + /* NOTE: ARB_texture_buffer_object has interactions with
> + * the compatibility profile that are not implemented.
> + */
> + if (!(ctx->API == API_OPENGL_CORE &&
> + ctx->Extensions.ARB_texture_buffer_object)) {
> + _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer");
> + return;
> + }
> +
> + bufObj = _mesa_lookup_bufferobj(ctx, buffer);
> + if (!bufObj && buffer) {
> + _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer);
> + return;
> + }
> +
> + texbufferrange(ctx, target, internalFormat, bufObj, 0, buffer ? -1 : 0);
> +}
> +
> +/** GL_ARB_texture_buffer_range */
> +void GLAPIENTRY
> +_mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
> + GLintptr offset, GLsizeiptr size)
> +{
> + struct gl_buffer_object *bufObj;
> +
> + GET_CURRENT_CONTEXT(ctx);
> +
> + if (!(ctx->API == API_OPENGL_CORE &&
> + ctx->Extensions.ARB_texture_buffer_range)) {
> + _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBufferRange");
> + return;
> + }
> +
> + bufObj = _mesa_lookup_bufferobj(ctx, buffer);
> + if (bufObj) {
> + if (offset < 0 ||
> + size <= 0 ||
> + (offset + size) > bufObj->Size) {
> + _mesa_error(ctx, GL_INVALID_VALUE, "glTexBufferRange");
> + return;
> + }
> + if (offset % ctx->Const.TextureBufferOffsetAlignment) {
> + _mesa_error(ctx, GL_INVALID_VALUE,
> + "glTexBufferRange(invalid offset alignment)");
> + return;
> + }
> + } else if (buffer) {
> + _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBufferRange(buffer %u)",
> + buffer);
> + return;
> + } else {
> + offset = 0;
> + size = 0;
> + }
> +
> + texbufferrange(ctx, target, internalFormat, bufObj, offset, size);
> +}
> diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
> index 65e9333..7124cac 100644
> --- a/src/mesa/main/teximage.h
> +++ b/src/mesa/main/teximage.h
> @@ -289,6 +289,10 @@ _mesa_CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset,
> extern void GLAPIENTRY
> _mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer);
>
> +extern void GLAPIENTRY
> +_mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
> + GLintptr offset, GLsizeiptr size);
> +
>
> /*@}*/
>
> diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
> index 52ede13..b6afd35 100644
> --- a/src/mesa/main/texparam.c
> +++ b/src/mesa/main/texparam.c
> @@ -1181,6 +1181,18 @@ get_tex_level_parameter_buffer(struct gl_context *ctx,
> *params = _mesa_get_format_bits(texFormat, pname);
> break;
>
> + /* GL_ARB_texture_buffer_range */
> + case GL_TEXTURE_BUFFER_OFFSET:
> + if (!ctx->Extensions.ARB_texture_buffer_range)
> + goto invalid_pname;
> + *params = texObj->BufferOffset;
> + break;
> + case GL_TEXTURE_BUFFER_SIZE:
> + if (!ctx->Extensions.ARB_texture_buffer_range)
> + goto invalid_pname;
> + *params = (texObj->BufferSize == -1) ? bo->Size : texObj->BufferSize;
> + break;
> +
> /* GL_ARB_texture_compression */
> case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
> /* Always illegal for GL_TEXTURE_BUFFER */
>
More information about the mesa-dev
mailing list