[Mesa-dev] [PATCH] mesa: add GL_OES_copy_image support
Ian Romanick
idr at freedesktop.org
Thu Feb 18 18:14:28 UTC 2016
On 02/15/2016 05:41 PM, Ilia Mirkin wrote:
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
>
> I ran this with the dEQP tests, and other than the caveats below, they seem to
> mostly work.
>
> The biggest caveat is that this can't actually be enabled for any drivers that
> don't implement ETC2 in hardware. So really that's just freedreno and the
> super-new desktop hardware. The problem is that you can copy between ETC2 and
> non-compressed images, so you need to have the original data around. At least
> the way that st/mesa implements this, the original data is not kept around.
>
> In order to enable this more generally, st/mesa will have to be taught to keep
> track of the originally-uploaded data. And support copying (and re-decoding)
> of data from another image.
>
> There also appears to be some unrelated problem relating to copying non-0 levels
> but that could well be a nouveau issue, or something unrelated. I don't think
> it's a problem with this patch.
>
> docs/GL3.txt | 2 +-
> src/mapi/glapi/gen/es_EXT.xml | 22 +++++++++
> src/mesa/main/copyimage.c | 27 ++++++++++-
> src/mesa/main/extensions_table.h | 1 +
> src/mesa/main/mtypes.h | 1 +
> src/mesa/main/tests/dispatch_sanity.cpp | 3 ++
> src/mesa/main/textureview.c | 86 +++++++++++++++++++++++++++++++++
> src/mesa/state_tracker/st_extensions.c | 8 +++
> 8 files changed, 148 insertions(+), 2 deletions(-)
>
> diff --git a/docs/GL3.txt b/docs/GL3.txt
> index 0957247..3c4db06 100644
> --- a/docs/GL3.txt
> +++ b/docs/GL3.txt
> @@ -241,7 +241,7 @@ GLES3.2, GLSL ES 3.2
> GL_KHR_debug DONE (all drivers)
> GL_KHR_robustness 90% done (the ARB variant)
> GL_KHR_texture_compression_astc_ldr DONE (i965/gen9+)
> - GL_OES_copy_image not started (based on GL_ARB_copy_image, which is done for some drivers)
> + GL_OES_copy_image DONE (core only)
> GL_OES_draw_buffers_indexed not started
> GL_OES_draw_elements_base_vertex DONE (all drivers)
> GL_OES_geometry_shader started (Marta)
> diff --git a/src/mapi/glapi/gen/es_EXT.xml b/src/mapi/glapi/gen/es_EXT.xml
> index fb0ef05..91e118f 100644
> --- a/src/mapi/glapi/gen/es_EXT.xml
> +++ b/src/mapi/glapi/gen/es_EXT.xml
> @@ -941,6 +941,28 @@
>
> </category>
>
> +<category name="GL_OES_copy_image" number="208">
> +
> + <function name="CopyImageSubDataOES" alias="CopyImageSubData" es2="3.0">
> + <param name="srcName" type="GLuint"/>
> + <param name="srcTarget" type="GLenum"/>
> + <param name="srcLevel" type="GLint"/>
> + <param name="srcX" type="GLint"/>
> + <param name="srcY" type="GLint"/>
> + <param name="srcZ" type="GLint"/>
> + <param name="dstName" type="GLuint"/>
> + <param name="dstTarget" type="GLenum"/>
> + <param name="dstLevel" type="GLint"/>
> + <param name="dstX" type="GLint"/>
> + <param name="dstY" type="GLint"/>
> + <param name="dstZ" type="GLint"/>
> + <param name="srcWidth" type="GLsizei"/>
> + <param name="srcHeight" type="GLsizei"/>
> + <param name="srcDepth" type="GLsizei"/>
> + </function>
> +
> +</category>
> +
> <!-- 175. GL_OES_geometry_shader -->
> <category name="GL_OES_geometry_shader" number="210">
> <enum name="GEOMETRY_SHADER_OES" value="0x8DD9"/>
> diff --git a/src/mesa/main/copyimage.c b/src/mesa/main/copyimage.c
> index d571d22..a0f1c69 100644
> --- a/src/mesa/main/copyimage.c
> +++ b/src/mesa/main/copyimage.c
> @@ -25,6 +25,7 @@
> * Jason Ekstrand <jason.ekstrand at intel.com>
> */
>
> +#include "context.h"
> #include "glheader.h"
> #include "errors.h"
> #include "enums.h"
> @@ -360,8 +361,32 @@ compressed_format_compatible(const struct gl_context *ctx,
> case GL_COMPRESSED_SIGNED_RED_RGTC1:
> compressedClass = BLOCK_CLASS_64_BITS;
> break;
> + case GL_COMPRESSED_RGBA8_ETC2_EAC:
> + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
> + case GL_COMPRESSED_RG11_EAC:
> + case GL_COMPRESSED_SIGNED_RG11_EAC:
> + if (_mesa_is_gles(ctx))
> + compressedClass = BLOCK_CLASS_128_BITS;
> + else
> + return false;
> + break;
> + case GL_COMPRESSED_RGB8_ETC2:
> + case GL_COMPRESSED_SRGB8_ETC2:
> + case GL_COMPRESSED_R11_EAC:
> + case GL_COMPRESSED_SIGNED_R11_EAC:
> + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
> + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
> + if (_mesa_is_gles(ctx))
> + compressedClass = BLOCK_CLASS_64_BITS;
> + else
> + return false;
> + break;
> default:
> - return false;
> + if (_mesa_is_gles(ctx) && _mesa_is_astc_format(compressedFormat))
> + compressedClass = BLOCK_CLASS_128_BITS;
> + else
> + return false;
> + break;
I think we need to allow the ETC, ETC2, and ASTC formats on desktop when
the related extensions (GL_ARB_ES3_compatibility and
GL_KHR_texture_compression_astc_ldr) are supported. I think that's a
bug in the current implementation. It also leaks the "fake" ETC2
problem into desktop OpenGL. :(
But it would be a heaping helping of awesome sauce if either
GL_KHR_texture_compression_astc_ldr or GL_ARB_texture_view listed
interactions with the other spec. There are interactions lists in the
GL_OES_texture_view spec... do the changes here match that spec?
Either way, I submitted a bug on the ARB/KHR spec.
https://www.khronos.org/bugzilla/show_bug.cgi?id=1464
> }
>
> switch (otherFormat) {
> diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h
> index b07d635..d985ff0 100644
> --- a/src/mesa/main/extensions_table.h
> +++ b/src/mesa/main/extensions_table.h
> @@ -305,6 +305,7 @@ EXT(OES_blend_subtract , dummy_true
> EXT(OES_byte_coordinates , dummy_true , x , x , ES1, x , 2002)
> EXT(OES_compressed_ETC1_RGB8_texture , OES_compressed_ETC1_RGB8_texture , x , x , ES1, ES2, 2005)
> EXT(OES_compressed_paletted_texture , dummy_true , x , x , ES1, x , 2003)
> +EXT(OES_copy_image , OES_copy_image , x , x , x , 30, 2014)
> EXT(OES_depth24 , dummy_true , x , x , ES1, ES2, 2005)
> EXT(OES_depth32 , dummy_false , x , x , x , x , 2005)
> EXT(OES_depth_texture , ARB_depth_texture , x , x , x , ES2, 2006)
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index d50376b..50cbbd3 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -3890,6 +3890,7 @@ struct gl_extensions
> GLboolean EXT_transform_feedback;
> GLboolean EXT_timer_query;
> GLboolean EXT_vertex_array_bgra;
> + GLboolean OES_copy_image;
> GLboolean OES_standard_derivatives;
> /* vendor extensions */
> GLboolean AMD_performance_monitor;
> diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
> index 24e3d18..0cdb6e3 100644
> --- a/src/mesa/main/tests/dispatch_sanity.cpp
> +++ b/src/mesa/main/tests/dispatch_sanity.cpp
> @@ -2446,6 +2446,9 @@ const struct function gles3_functions_possible[] = {
> { "glGetSamplerParameterIivOES", 30, -1 },
> { "glGetSamplerParameterIuivOES", 30, -1 },
>
> + /* GL_OES_copy_image */
> + { "glCopyImageSubDataOES", 30, -1 },
> +
> { NULL, 0, -1 }
> };
>
> diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c
> index 316d828..56b271c 100644
> --- a/src/mesa/main/textureview.c
> +++ b/src/mesa/main/textureview.c
> @@ -82,6 +82,39 @@
> | | COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT |
> ---------------------------------------------------------------------------
> */
> +
> +#define VIEW_CLASS_GLES(x) (GL_VIEW_CLASS_BPTC_FLOAT + 1 + x)
> +#define VIEW_CLASS_EAC_R11 VIEW_CLASS_GLES(0)
> +#define VIEW_CLASS_EAC_RG11 VIEW_CLASS_GLES(1)
> +#define VIEW_CLASS_ETC2_RGB VIEW_CLASS_GLES(2)
> +#define VIEW_CLASS_ETC2_RGBA VIEW_CLASS_GLES(3)
> +#define VIEW_CLASS_ETC2_EAC_RGBA VIEW_CLASS_GLES(4)
> +#define VIEW_CLASS_ASTC_4x4_RGBA VIEW_CLASS_GLES(5)
> +#define VIEW_CLASS_ASTC_5x4_RGBA VIEW_CLASS_GLES(6)
> +#define VIEW_CLASS_ASTC_5x5_RGBA VIEW_CLASS_GLES(7)
> +#define VIEW_CLASS_ASTC_6x5_RGBA VIEW_CLASS_GLES(8)
> +#define VIEW_CLASS_ASTC_6x6_RGBA VIEW_CLASS_GLES(9)
> +#define VIEW_CLASS_ASTC_8x5_RGBA VIEW_CLASS_GLES(10)
> +#define VIEW_CLASS_ASTC_8x6_RGBA VIEW_CLASS_GLES(11)
> +#define VIEW_CLASS_ASTC_8x8_RGBA VIEW_CLASS_GLES(12)
> +#define VIEW_CLASS_ASTC_10x5_RGBA VIEW_CLASS_GLES(13)
> +#define VIEW_CLASS_ASTC_10x6_RGBA VIEW_CLASS_GLES(14)
> +#define VIEW_CLASS_ASTC_10x8_RGBA VIEW_CLASS_GLES(15)
> +#define VIEW_CLASS_ASTC_10x10_RGBA VIEW_CLASS_GLES(16)
> +#define VIEW_CLASS_ASTC_12x10_RGBA VIEW_CLASS_GLES(17)
> +#define VIEW_CLASS_ASTC_12x12_RGBA VIEW_CLASS_GLES(18)
> +#define VIEW_CLASS_ASTC_3x3x3_RGBA VIEW_CLASS_GLES(19)
> +#define VIEW_CLASS_ASTC_4x3x3_RGBA VIEW_CLASS_GLES(20)
> +#define VIEW_CLASS_ASTC_4x4x3_RGBA VIEW_CLASS_GLES(21)
> +#define VIEW_CLASS_ASTC_4x4x4_RGBA VIEW_CLASS_GLES(22)
> +#define VIEW_CLASS_ASTC_5x4x4_RGBA VIEW_CLASS_GLES(23)
> +#define VIEW_CLASS_ASTC_5x5x4_RGBA VIEW_CLASS_GLES(24)
> +#define VIEW_CLASS_ASTC_5x5x5_RGBA VIEW_CLASS_GLES(25)
> +#define VIEW_CLASS_ASTC_6x5x5_RGBA VIEW_CLASS_GLES(26)
> +#define VIEW_CLASS_ASTC_6x6x5_RGBA VIEW_CLASS_GLES(27)
> +#define VIEW_CLASS_ASTC_6x6x6_RGBA VIEW_CLASS_GLES(28)
> +
> +
> struct internal_format_class_info {
> GLenum view_class;
> GLenum internal_format;
> @@ -162,6 +195,41 @@ static const struct internal_format_class_info s3tc_compatible_internal_formats[
> {GL_VIEW_CLASS_S3TC_DXT5_RGBA, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT},
> };
>
> +static const struct internal_format_class_info gles_etc2_compatible_internal_formats[] = {
> + {VIEW_CLASS_EAC_R11, GL_COMPRESSED_R11_EAC},
> + {VIEW_CLASS_EAC_R11, GL_COMPRESSED_SIGNED_R11_EAC},
> + {VIEW_CLASS_EAC_RG11, GL_COMPRESSED_RG11_EAC},
> + {VIEW_CLASS_EAC_RG11, GL_COMPRESSED_SIGNED_RG11_EAC},
> + {VIEW_CLASS_ETC2_RGB, GL_COMPRESSED_RGB8_ETC2},
> + {VIEW_CLASS_ETC2_RGB, GL_COMPRESSED_SRGB8_ETC2},
> + {VIEW_CLASS_ETC2_RGBA, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2},
> + {VIEW_CLASS_ETC2_RGBA, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2},
> + {VIEW_CLASS_ETC2_EAC_RGBA, GL_COMPRESSED_RGBA8_ETC2_EAC},
> + {VIEW_CLASS_ETC2_EAC_RGBA, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC},
> +};
> +
> +static const struct internal_format_class_info gles_astc_compatible_internal_formats[] = {
> +#define ASTC_FMT(size) \
> + {VIEW_CLASS_ASTC_##size## _RGBA, GL_COMPRESSED_RGBA_ASTC_##size##_KHR}, \
> + {VIEW_CLASS_ASTC_##size##_RGBA, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_##size##_KHR}
> +
> + ASTC_FMT(4x4),
> + ASTC_FMT(5x4),
> + ASTC_FMT(5x5),
> + ASTC_FMT(6x5),
> + ASTC_FMT(6x6),
> + ASTC_FMT(8x5),
> + ASTC_FMT(8x6),
> + ASTC_FMT(8x8),
> + ASTC_FMT(10x5),
> + ASTC_FMT(10x6),
> + ASTC_FMT(10x8),
> + ASTC_FMT(10x10),
> + ASTC_FMT(12x10),
> + ASTC_FMT(12x12),
> +#undef ASTC_FMT
> +};
> +
> /**
> * Lookup format view class based on internalformat
> * \return VIEW_CLASS if internalformat found in table, false otherwise.
> @@ -184,6 +252,24 @@ lookup_view_class(const struct gl_context *ctx, GLenum internalformat)
> return s3tc_compatible_internal_formats[i].view_class;
> }
> }
> +
> + if (_mesa_is_gles3(ctx)) {
> + for (i = 0; i < ARRAY_SIZE(gles_etc2_compatible_internal_formats); i++) {
> + if (gles_etc2_compatible_internal_formats[i].internal_format
> + == internalformat)
> + return gles_etc2_compatible_internal_formats[i].view_class;
> + }
> +
> + if (ctx->Extensions.KHR_texture_compression_astc_ldr) {
> + for (i = 0; i < ARRAY_SIZE(gles_astc_compatible_internal_formats); i++) {
> + if (gles_astc_compatible_internal_formats[i].internal_format
> + == internalformat)
> + return gles_astc_compatible_internal_formats[i].view_class;
> + }
> + }
> +
> + /* FINISHME: Add 3D OES formats when supported */
> + }
> return GL_FALSE;
> }
>
> diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
> index bdfbded..95d5f95 100644
> --- a/src/mesa/state_tracker/st_extensions.c
> +++ b/src/mesa/state_tracker/st_extensions.c
> @@ -850,6 +850,14 @@ void st_init_extensions(struct pipe_screen *screen,
> extensions->ARB_sync = GL_TRUE;
> }
>
> + /* If we don't have native ETC2 support, we don't keep track of the
> + * original ETC2 data. This is necessary to be able to copy images between
> + * compatible view classes.
> + */
> + if (extensions->ARB_copy_image && st->has_etc2) {
> + extensions->OES_copy_image = GL_TRUE;
> + }
> +
> /* Maximum sample count. */
> {
> enum pipe_format color_formats[] = {
>
More information about the mesa-dev
mailing list