We shouldn't directly call meta functions from core Mesa because that creates a dependency on swrast.
The new _mesa_meta_GetTexImage() function trivially calls the meta decompression routine for compressed textures vs. the core _mesa_get_teximage() fallback function for uncompressed textures. In the state tracker, use the existing code for glGetTexImage() that handles decompression via quad rendering already. --- src/mesa/drivers/common/driverfuncs.c | 2 +- src/mesa/drivers/common/meta.c | 39 +++++++++-- src/mesa/drivers/common/meta.h | 12 ++-- src/mesa/main/texgetimage.c | 125 ++++++++++++++++----------------- src/mesa/state_tracker/st_context.c | 4 - 5 files changed, 102 insertions(+), 80 deletions(-) diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c index 78caa05..bf4f5e4 100644 --- a/src/mesa/drivers/common/driverfuncs.c +++ b/src/mesa/drivers/common/driverfuncs.c @@ -94,7 +94,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver) driver->TexSubImage1D = _mesa_store_texsubimage1d; driver->TexSubImage2D = _mesa_store_texsubimage2d; driver->TexSubImage3D = _mesa_store_texsubimage3d; - driver->GetTexImage = _mesa_get_teximage; + driver->GetTexImage = _mesa_meta_GetTexImage; driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D; driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D; driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D; diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 751f3b6..537e894 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -59,6 +59,7 @@ #include "main/stencil.h" #include "main/texobj.h" #include "main/texenv.h" +#include "main/texgetimage.h" #include "main/teximage.h" #include "main/texparam.h" #include "main/texstate.h" @@ -3119,12 +3120,12 @@ _mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start * \param dest destination buffer * \param destRowLength dest image rowLength (ala GL_PACK_ROW_LENGTH) */ -void -_mesa_meta_decompress_texture_image(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLuint slice, - GLenum destFormat, GLenum destType, - GLvoid *dest, GLint destRowLength) +static void +decompress_texture_image(struct gl_context *ctx, + struct gl_texture_image *texImage, + GLuint slice, + GLenum destFormat, GLenum destType, + GLvoid *dest, GLint destRowLength) { struct decompress_state *decompress = &ctx->Meta->Decompress; struct gl_texture_object *texObj = texImage->TexObject; @@ -3294,3 +3295,29 @@ _mesa_meta_decompress_texture_image(struct gl_context *ctx, } } + +/** + * This is just a wrapper around _mesa_get_tex_image() and + * decompress_texture_image(). Meta functions should not be directly called + * from core Mesa. + */ +void +_mesa_meta_GetTexImage(struct gl_context *ctx, GLenum target, GLint level, + GLenum format, GLenum type, GLvoid *pixels, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) +{ + if (_mesa_is_format_compressed(texImage->TexFormat)) { + const GLuint slice = 0; /* only 2D compressed textures for now */ + /* Need to unlock the texture here to prevent deadlock... */ + _mesa_unlock_texture(ctx, texObj); + decompress_texture_image(ctx, texImage, slice, format, type, pixels, + ctx->Pack.RowLength); + /* ... and relock it */ + _mesa_lock_texture(ctx, texObj); + } + else { + _mesa_get_teximage(ctx, target, level, format, type, pixels, + texObj, texImage); + } +} diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h index 50389c9..b4cfe3e 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -107,11 +107,11 @@ _mesa_meta_CopyConvolutionFilter2D(struct gl_context *ctx, GLenum target, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height); -void -_mesa_meta_decompress_texture_image(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLuint slice, - GLenum destFormat, GLenum destType, - GLvoid *dest, GLint destRowLength); +extern void +_mesa_meta_GetTexImage(struct gl_context *ctx, GLenum target, GLint level, + GLenum format, GLenum type, GLvoid *pixels, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage); + #endif /* META_H */ diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 4d97c88..723f4b5 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -42,7 +42,6 @@ #include "pbo.h" #include "texgetimage.h" #include "teximage.h" -#include "drivers/common/meta.h" /** @@ -257,6 +256,7 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions, /** * glGetTexImage for (s)RGBA, Luminance, etc. pixels. * This is the slow way since we use texture sampling. + * NOTE: the texture cannot be compressed. */ static void get_tex_rgba(struct gl_context *ctx, GLuint dimensions, @@ -293,77 +293,68 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat); for (img = 0; img < depth; img++) { - if (_mesa_is_format_compressed(texImage->TexFormat)) { - _mesa_unlock_texture(ctx, texImage->TexObject); - _mesa_meta_decompress_texture_image(ctx, texImage, img, - format, type, pixels, - ctx->Pack.RowLength); - _mesa_lock_texture(ctx, texImage->TexObject); + GLfloat (*rgba)[4]; + GLubyte *srcMap; + GLint srcRowStride; + GLint row; + + rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat)); + if (!rgba) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); + return; } - else { - GLfloat (*rgba)[4]; - GLubyte *srcMap; - GLint srcRowStride; - GLint row; - - rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat)); - if (!rgba) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); - return; - } - /* map src texture buffer */ - ctx->Driver.MapTextureImage(ctx, texImage, img, - 0, 0, width, height, GL_MAP_READ_BIT, - &srcMap, &srcRowStride); - - for (row = 0; row < height; row++) { - void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, - width, height, format, type, - img, row, 0); - GLint i; - - _mesa_unpack_rgba_row(texFormat, width, srcMap, rgba); - srcMap += srcRowStride; - - if (texImage->_BaseFormat == GL_ALPHA) { - for (i = 0; i < width; i++) { - rgba[i][RCOMP] = 0.0F; - rgba[i][GCOMP] = 0.0F; - rgba[i][BCOMP] = 0.0F; - } + /* map src texture buffer */ + ctx->Driver.MapTextureImage(ctx, texImage, img, + 0, 0, width, height, GL_MAP_READ_BIT, + &srcMap, &srcRowStride); + + for (row = 0; row < height; row++) { + void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, + width, height, format, type, + img, row, 0); + GLint i; + + _mesa_unpack_rgba_row(texFormat, width, srcMap, rgba); + srcMap += srcRowStride; + + if (texImage->_BaseFormat == GL_ALPHA) { + for (i = 0; i < width; i++) { + rgba[i][RCOMP] = 0.0F; + rgba[i][GCOMP] = 0.0F; + rgba[i][BCOMP] = 0.0F; } - else if (texImage->_BaseFormat == GL_LUMINANCE) { - for (i = 0; i < width; i++) { - rgba[i][GCOMP] = 0.0F; - rgba[i][BCOMP] = 0.0F; - rgba[i][ACOMP] = 1.0F; - } + } + else if (texImage->_BaseFormat == GL_LUMINANCE) { + for (i = 0; i < width; i++) { + rgba[i][GCOMP] = 0.0F; + rgba[i][BCOMP] = 0.0F; + rgba[i][ACOMP] = 1.0F; } - else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) { - for (i = 0; i < width; i++) { - rgba[i][GCOMP] = 0.0F; - rgba[i][BCOMP] = 0.0F; - } + } + else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) { + for (i = 0; i < width; i++) { + rgba[i][GCOMP] = 0.0F; + rgba[i][BCOMP] = 0.0F; } - else if (texImage->_BaseFormat == GL_INTENSITY) { - for (i = 0; i < width; i++) { - rgba[i][GCOMP] = 0.0F; - rgba[i][BCOMP] = 0.0F; - rgba[i][ACOMP] = 1.0F; - } + } + else if (texImage->_BaseFormat == GL_INTENSITY) { + for (i = 0; i < width; i++) { + rgba[i][GCOMP] = 0.0F; + rgba[i][BCOMP] = 0.0F; + rgba[i][ACOMP] = 1.0F; } - - _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, - format, type, dest, - &ctx->Pack, transferOps); } - /* Unmap the src texture buffer */ - ctx->Driver.UnmapTextureImage(ctx, texImage, img); - - free(rgba); + _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, + format, type, dest, + &ctx->Pack, transferOps); } + + /* Unmap the src texture buffer */ + ctx->Driver.UnmapTextureImage(ctx, texImage, img); + + free(rgba); } } @@ -471,6 +462,12 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, * All error checking will have been done before this routine is called. * We'll call ctx->Driver.MapTextureImage() to access the data, then * unmap with ctx->Driver.UnmapTextureImage(). + * + * NOTE that compressed textures are not handled here. Decompression can + * be done in two ways: + * 1. Use software to decompress the blocks. + * 2. Render a textured quad with the compressed texture. + * The former is undesirable. The later can be done with a "meta" function. */ void _mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level, @@ -480,6 +477,8 @@ _mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level, { GLuint dimensions; + assert(!_mesa_is_format_compressed(texImage->TexFormat)); + switch (target) { case GL_TEXTURE_1D: dimensions = 1; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index e994e2e..6d4bc54 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -29,7 +29,6 @@ #include "main/context.h" #include "main/samplerobj.h" #include "main/shaderobj.h" -#include "drivers/common/meta.h" #include "program/prog_cache.h" #include "vbo/vbo.h" #include "glapi/glapi.h" @@ -184,8 +183,6 @@ struct st_context *st_create_context(gl_api api, struct pipe_context *pipe, return NULL; } - _mesa_meta_init(ctx); - /* XXX: need a capability bit in gallium to query if the pipe * driver prefers DP4 or MUL/MAD for vertex transformation. */ @@ -258,7 +255,6 @@ void st_destroy_context( struct st_context *st ) st_destroy_program_variants(st); - _mesa_meta_free(ctx); _mesa_free_context_data(ctx); st_destroy_context_priv(st); -- 1.7.3.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev