[Mesa-dev] [PATCH 20/37] mesa: Convert GetCompressedTexImage to using MapTextureImage().
Eric Anholt
eric at anholt.net
Mon Aug 15 11:53:50 PDT 2011
From: Brian Paul <brianp at vmware.com>
This changes drivers to not map the texture on their own before
calling _mesa_get_compressed_teximage().
---
src/mesa/drivers/dri/intel/intel_tex_image.c | 47 +++------------------
src/mesa/drivers/dri/radeon/radeon_tex_getimage.c | 45 ++++----------------
src/mesa/drivers/dri/radeon/radeon_texture.c | 1 -
src/mesa/drivers/dri/radeon/radeon_texture.h | 4 --
src/mesa/main/texgetimage.c | 21 ++++++---
src/mesa/state_tracker/st_cb_texture.c | 47 ++++-----------------
6 files changed, 37 insertions(+), 128 deletions(-)
diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index 29a6d3b..b061680 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -653,16 +653,11 @@ intelCompressedTexImage2D( struct gl_context *ctx, GLenum target, GLint level,
0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
}
-
-/**
- * Need to map texture image into memory before copying image data,
- * then unmap it.
- */
static void
-intel_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage, GLboolean compressed)
+intelGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid * pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
struct intel_context *intel = intel_context(ctx);
struct intel_texture_image *intelImage = intel_texture_image(texImage);
@@ -708,15 +703,8 @@ intel_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
intel_tex_image_s8z24_gather(intel, intelImage);
}
- if (compressed) {
- _mesa_get_compressed_teximage(ctx, target, level, pixels,
- texObj, texImage);
- }
- else {
- _mesa_get_teximage(ctx, target, level, format, type, pixels,
- texObj, texImage);
- }
-
+ _mesa_get_teximage(ctx, target, level, format, type, pixels,
+ texObj, texImage);
/* Unmap */
if (intelImage->mt) {
@@ -725,28 +713,6 @@ intel_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
}
}
-
-static void
-intelGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- intel_get_tex_image(ctx, target, level, format, type, pixels,
- texObj, texImage, GL_FALSE);
-}
-
-
-static void
-intelGetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
- GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- intel_get_tex_image(ctx, target, level, 0, 0, pixels,
- texObj, texImage, GL_TRUE);
-}
-
void
intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
GLint texture_format,
@@ -886,7 +852,6 @@ intelInitTextureImageFuncs(struct dd_function_table *functions)
functions->GetTexImage = intelGetTexImage;
functions->CompressedTexImage2D = intelCompressedTexImage2D;
- functions->GetCompressedTexImage = intelGetCompressedTexImage;
#if FEATURE_OES_EGL_image
functions->EGLImageTargetTexture2D = intel_image_target_texture_2d;
diff --git a/src/mesa/drivers/dri/radeon/radeon_tex_getimage.c b/src/mesa/drivers/dri/radeon/radeon_tex_getimage.c
index 4a73089..97ae402 100644
--- a/src/mesa/drivers/dri/radeon/radeon_tex_getimage.c
+++ b/src/mesa/drivers/dri/radeon/radeon_tex_getimage.c
@@ -39,17 +39,17 @@
* Need to map texture image into memory before copying image data,
* then unmap it.
*/
-static void
-radeon_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage, int compressed)
+void
+radeonGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid * pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
radeon_texture_image *image = get_radeon_texture_image(texImage);
radeon_print(RADEON_TEXTURE, RADEON_NORMAL,
- "%s(%p, tex %p, image %p) compressed %d.\n",
- __func__, ctx, texObj, image, compressed);
+ "%s(%p, tex %p, image %p).\n",
+ __func__, ctx, texObj, image);
if (image->mt) {
radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
@@ -67,37 +67,10 @@ radeon_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
assert(image->base.Data);
}
- if (compressed) {
- /* FIXME: this can't work for small textures (mips) which
- use different hw stride */
- _mesa_get_compressed_teximage(ctx, target, level, pixels,
- texObj, texImage);
- } else {
- _mesa_get_teximage(ctx, target, level, format, type, pixels,
- texObj, texImage);
- }
+ _mesa_get_teximage(ctx, target, level, format, type, pixels,
+ texObj, texImage);
if (image->mt) {
radeon_teximage_unmap(image);
}
}
-
-void
-radeonGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- radeon_get_tex_image(ctx, target, level, format, type, pixels,
- texObj, texImage, 0);
-}
-
-void
-radeonGetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
- GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- radeon_get_tex_image(ctx, target, level, 0, 0, pixels,
- texObj, texImage, 1);
-}
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index 9964663..cb9a87e 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -1178,7 +1178,6 @@ radeon_init_common_texture_funcs(radeonContextPtr radeon,
functions->TexSubImage3D = radeonTexSubImage3D;
functions->CompressedTexImage2D = radeonCompressedTexImage2D;
functions->CompressedTexSubImage2D = radeonCompressedTexSubImage2D;
- functions->GetCompressedTexImage = radeonGetCompressedTexImage;
functions->GetTexImage = radeonGetTexImage;
functions->GenerateMipmap = radeonGenerateMipmap;
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.h b/src/mesa/drivers/dri/radeon/radeon_texture.h
index c02aa30..3d096b1 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.h
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.h
@@ -121,10 +121,6 @@ void radeonGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
GLenum format, GLenum type, GLvoid * pixels,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage);
-void radeonGetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
- GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage);
void radeonCopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
GLint xoffset, GLint yoffset,
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 26c2ff9..4c8a412 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -491,11 +491,11 @@ _mesa_get_compressed_teximage(struct gl_context *ctx, GLenum target, GLint level
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
- const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat,
- texImage->Width);
- const GLuint row_stride_stored = _mesa_format_row_stride(texImage->TexFormat,
- texImage->RowStride);
+ const GLuint row_stride =
+ _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
GLuint i;
+ GLubyte *src;
+ GLint srcRowStride;
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
/* pack texture image into a PBO */
@@ -511,25 +511,32 @@ _mesa_get_compressed_teximage(struct gl_context *ctx, GLenum target, GLint level
img = ADD_POINTERS(buf, img);
}
+ /* map src texture buffer */
+ ctx->Driver.MapTextureImage(ctx, texImage, 0,
+ 0, 0, texImage->Width, texImage->Height,
+ GL_MAP_READ_BIT, &src, &srcRowStride);
+
/* no pixelstore or pixel transfer, but respect stride */
- if (row_stride == row_stride_stored) {
+ if (row_stride == srcRowStride) {
const GLuint size = _mesa_format_image_size(texImage->TexFormat,
texImage->Width,
texImage->Height,
texImage->Depth);
- memcpy(img, texImage->Data, size);
+ memcpy(img, src, size);
}
else {
GLuint bw, bh;
_mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) {
memcpy((GLubyte *)img + i * row_stride,
- (GLubyte *)texImage->Data + i * row_stride_stored,
+ (GLubyte *)src + i * srcRowStride,
row_stride);
}
}
+ ctx->Driver.UnmapTextureImage(ctx, texImage, 0);
+
if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
ctx->Pack.BufferObj);
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index e4be7fb..ec81a89 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -919,10 +919,10 @@ decompress_with_blit(struct gl_context * ctx, GLenum target, GLint level,
* then unmap it.
*/
static void
-st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage, GLboolean compressed_dst)
+st_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)
{
struct st_context *st = st_context(ctx);
struct st_texture_image *stImage = st_texture_image(texImage);
@@ -932,9 +932,7 @@ st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
GLuint depth, i;
GLubyte *dest;
- if (stImage->pt &&
- util_format_is_s3tc(stImage->pt->format) &&
- !compressed_dst) {
+ if (stImage->pt && util_format_is_s3tc(stImage->pt->format)) {
/* Need to decompress the texture.
* We'll do this by rendering a textured quad.
* Note that we only expect RGBA formats (no Z/depth formats).
@@ -978,14 +976,8 @@ st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
_mesa_set_fetch_functions(texImage, get_texture_dims(target));
for (i = 0; i < depth; i++) {
- if (compressed_dst) {
- _mesa_get_compressed_teximage(ctx, target, level, dest,
- texObj, texImage);
- }
- else {
- _mesa_get_teximage(ctx, target, level, format, type, dest,
- texObj, texImage);
- }
+ _mesa_get_teximage(ctx, target, level, format, type, dest,
+ texObj, texImage);
if (stImage->pt && i + 1 < depth) {
/* unmap this slice */
@@ -1010,29 +1002,6 @@ st_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
static void
-st_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)
-{
- st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
- GL_FALSE);
-}
-
-
-static void
-st_GetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
- GLvoid *pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
-{
- st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
- GL_TRUE);
-}
-
-
-
-static void
st_TexSubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
GLint xoffset, GLint yoffset, GLint zoffset,
GLint width, GLint height, GLint depth,
@@ -1918,7 +1887,7 @@ st_init_texture_functions(struct dd_function_table *functions)
/* compressed texture functions */
functions->CompressedTexImage2D = st_CompressedTexImage2D;
- functions->GetCompressedTexImage = st_GetCompressedTexImage;
+ functions->GetCompressedTexImage = _mesa_get_compressed_teximage;
functions->NewTextureObject = st_NewTextureObject;
functions->NewTextureImage = st_NewTextureImage;
--
1.7.5.4
More information about the mesa-dev
mailing list