From cd9ab2584f5e2a5eb0e96a948e6aedc9a33c886d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 5 Jun 2012 16:32:23 -0600 Subject: [PATCH] mesa: consolidate internal glCopyTexSubImage1/2/3D code Reviewed-by: Kenneth Graunke --- src/mesa/drivers/common/driverfuncs.c | 4 +- src/mesa/drivers/common/meta.c | 55 +++--------------- src/mesa/drivers/common/meta.h | 27 ++------- src/mesa/drivers/dri/intel/intel_tex_copy.c | 40 ++++--------- src/mesa/drivers/dri/radeon/radeon_tex_copy.c | 18 +++--- src/mesa/drivers/dri/radeon/radeon_texture.c | 2 +- src/mesa/drivers/dri/radeon/radeon_texture.h | 12 ++-- src/mesa/main/dd.h | 35 +++-------- src/mesa/main/teximage.c | 31 ++-------- src/mesa/state_tracker/st_cb_texture.c | 58 ++----------------- 10 files changed, 62 insertions(+), 220 deletions(-) diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c index a9ccbd565da..118fc4ab06b 100644 --- a/src/mesa/drivers/common/driverfuncs.c +++ b/src/mesa/drivers/common/driverfuncs.c @@ -94,9 +94,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver) driver->TexImage = _mesa_store_teximage; driver->TexSubImage = _mesa_store_texsubimage; driver->GetTexImage = _mesa_meta_GetTexImage; - driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D; - driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D; - driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D; + driver->CopyTexSubImage = _mesa_meta_CopyTexSubImage; driver->GenerateMipmap = _mesa_meta_GenerateMipmap; driver->TestProxyTexImage = _mesa_test_proxy_teximage; driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d; diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index af21d3b0697..8d7e90126fd 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -3117,14 +3117,13 @@ get_temp_image_type(struct gl_context *ctx, GLenum baseFormat) * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions. * Have to be careful with locking and meta state for pixel transfer. */ -static void -copy_tex_sub_image(struct gl_context *ctx, - GLuint dims, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, GLint zoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height) +void +_mesa_meta_CopyTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, GLint zoffset, + struct gl_renderbuffer *rb, + GLint x, GLint y, + GLsizei width, GLsizei height) { struct gl_texture_object *texObj = texImage->TexObject; GLenum format, type; @@ -3151,7 +3150,7 @@ copy_tex_sub_image(struct gl_context *ctx, type = get_temp_image_type(ctx, format); bpp = _mesa_bytes_per_pixel(format, type); if (bpp <= 0) { - _mesa_problem(ctx, "Bad bpp in meta copy_tex_sub_image()"); + _mesa_problem(ctx, "Bad bpp in _mesa_meta_CopyTexSubImage()"); return; } @@ -3193,44 +3192,6 @@ copy_tex_sub_image(struct gl_context *ctx, } -void -_mesa_meta_CopyTexSubImage1D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width) -{ - copy_tex_sub_image(ctx, 1, texImage, xoffset, 0, 0, - rb, x, y, width, 1); -} - - -void -_mesa_meta_CopyTexSubImage2D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height) -{ - copy_tex_sub_image(ctx, 2, texImage, xoffset, yoffset, 0, - rb, x, y, width, height); -} - - -void -_mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, GLint zoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height) -{ - copy_tex_sub_image(ctx, 3, texImage, xoffset, yoffset, zoffset, - rb, x, y, width, height); -} - - /** * Decompress a texture image by drawing a quad with the compressed * texture and reading the pixels out of the color buffer. diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h index de039b575e5..7a80b1dde4d 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -111,27 +111,12 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, struct gl_texture_object *texObj); extern void -_mesa_meta_CopyTexSubImage1D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width); - -extern void -_mesa_meta_CopyTexSubImage2D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height); - -extern void -_mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, GLint zoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height); +_mesa_meta_CopyTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, GLint zoffset, + struct gl_renderbuffer *rb, + GLint x, GLint y, + GLsizei width, GLsizei height); extern void _mesa_meta_GetTexImage(struct gl_context *ctx, diff --git a/src/mesa/drivers/dri/intel/intel_tex_copy.c b/src/mesa/drivers/dri/intel/intel_tex_copy.c index 8617302856d..0798cec8f3c 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_copy.c +++ b/src/mesa/drivers/dri/intel/intel_tex_copy.c @@ -144,38 +144,21 @@ intel_copy_texsubimage(struct intel_context *intel, static void -intelCopyTexSubImage1D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width) +intelCopyTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, GLint zoffset, + struct gl_renderbuffer *rb, + GLint x, GLint y, + GLsizei width, GLsizei height) { - if (!intel_copy_texsubimage(intel_context(ctx), - intel_texture_image(texImage), - xoffset, 0, - intel_renderbuffer(rb), x, y, width, 1)) { - fallback_debug("%s - fallback to swrast\n", __FUNCTION__); - _mesa_meta_CopyTexSubImage1D(ctx, texImage, xoffset, - rb, x, y, width); - } -} - - -static void -intelCopyTexSubImage2D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width, GLsizei height) -{ - if (!intel_copy_texsubimage(intel_context(ctx), + if (dims == 3 || !intel_copy_texsubimage(intel_context(ctx), intel_texture_image(texImage), xoffset, yoffset, intel_renderbuffer(rb), x, y, width, height)) { fallback_debug("%s - fallback to swrast\n", __FUNCTION__); - _mesa_meta_CopyTexSubImage2D(ctx, texImage, - xoffset, yoffset, - rb, x, y, width, height); + _mesa_meta_CopyTexSubImage(ctx, dims, texImage, + xoffset, yoffset, zoffset, + rb, x, y, width, height); } } @@ -183,6 +166,5 @@ intelCopyTexSubImage2D(struct gl_context *ctx, void intelInitTextureCopyImageFuncs(struct dd_function_table *functions) { - functions->CopyTexSubImage1D = intelCopyTexSubImage1D; - functions->CopyTexSubImage2D = intelCopyTexSubImage2D; + functions->CopyTexSubImage = intelCopyTexSubImage; } diff --git a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c index a26acbfdd04..1faf9c81db9 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c @@ -134,17 +134,17 @@ do_copy_texsubimage(struct gl_context *ctx, } void -radeonCopyTexSubImage2D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height) +radeonCopyTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, GLint zoffset, + struct gl_renderbuffer *rb, + GLint x, GLint y, + GLsizei width, GLsizei height) { radeonContextPtr radeon = RADEON_CONTEXT(ctx); radeon_prepare_render(radeon); - if (!do_copy_texsubimage(ctx, + if (dims != 2 || !do_copy_texsubimage(ctx, radeon_tex_obj(texImage->TexObject), (radeon_texture_image *)texImage, xoffset, yoffset, @@ -153,8 +153,8 @@ radeonCopyTexSubImage2D(struct gl_context *ctx, radeon_print(RADEON_FALLBACKS, RADEON_NORMAL, "Falling back to sw for glCopyTexSubImage2D\n"); - _mesa_meta_CopyTexSubImage2D(ctx, texImage, - xoffset, yoffset, + _mesa_meta_CopyTexSubImage(ctx, dims, texImage, + xoffset, yoffset, zoffset, rb, x, y, width, height); } } diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c index 8df5484f557..6c7171953bb 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.c +++ b/src/mesa/drivers/dri/radeon/radeon_texture.c @@ -727,7 +727,7 @@ radeon_init_common_texture_funcs(radeonContextPtr radeon, functions->TexImage = radeonTexImage; - functions->CopyTexSubImage2D = radeonCopyTexSubImage2D; + functions->CopyTexSubImage = radeonCopyTexSubImage; functions->Bitmap = _mesa_meta_Bitmap; #if FEATURE_OES_EGL_image diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.h b/src/mesa/drivers/dri/radeon/radeon_texture.h index 6cca011bf2f..8f9f5bd128e 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.h +++ b/src/mesa/drivers/dri/radeon/radeon_texture.h @@ -65,12 +65,12 @@ gl_format radeonChooseTextureFormat(struct gl_context * ctx, GLenum format, GLenum type, GLboolean fbo); -void radeonCopyTexSubImage2D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height); +void radeonCopyTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, GLint zoffset, + struct gl_renderbuffer *rb, + GLint x, GLint y, + GLsizei width, GLsizei height); unsigned radeonIsFormatRenderable(gl_format mesa_format); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index c7984177d7f..f66e754baea 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -234,33 +234,14 @@ struct dd_function_table { struct gl_texture_image *texImage ); /** - * Called by glCopyTexSubImage1D() and glCopyTexImage1D(). - */ - void (*CopyTexSubImage1D)(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width); - - /** - * Called by glCopyTexSubImage2D() and glCopyTexImage2D(). - */ - void (*CopyTexSubImage2D)(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height); - - /** - * Called by glCopyTexSubImage3D() and glCopyTexImage3D(). - */ - void (*CopyTexSubImage3D)(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, GLint zoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, - GLsizei width, GLsizei height); + * Called by glCopyTex[Sub]Image[123]D(). + */ + void (*CopyTexSubImage)(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, GLint zoffset, + struct gl_renderbuffer *rb, + GLint x, GLint y, + GLsizei width, GLsizei height); /** * Called by glGenerateMipmap() or when GL_GENERATE_MIPMAP_SGIS is enabled. diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index e8353463758..ce42246317f 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -2926,7 +2926,7 @@ copyteximage(struct gl_context *ctx, GLuint dims, GL_NONE, GL_NONE); if (legal_texture_size(ctx, texFormat, width, height, 1)) { - GLint srcX = x, srcY = y, dstX = 0, dstY = 0; + GLint srcX = x, srcY = y, dstX = 0, dstY = 0, dstZ = 0; /* Free old texture image */ ctx->Driver.FreeTextureImageBuffer(ctx, texImage); @@ -2944,13 +2944,8 @@ copyteximage(struct gl_context *ctx, GLuint dims, struct gl_renderbuffer *srcRb = get_copy_tex_image_source(ctx, texImage->TexFormat); - if (dims == 1) - ctx->Driver.CopyTexSubImage1D(ctx, texImage, dstX, - srcRb, srcX, srcY, width); - - else - ctx->Driver.CopyTexSubImage2D(ctx, texImage, dstX, dstY, - srcRb, srcX, srcY, width, height); + ctx->Driver.CopyTexSubImage(ctx, dims, texImage, dstX, dstY, dstZ, + srcRb, srcX, srcY, width, height); } check_gen_mipmap(ctx, target, texObj, level); @@ -3049,23 +3044,9 @@ copytexsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, struct gl_renderbuffer *srcRb = get_copy_tex_image_source(ctx, texImage->TexFormat); - switch (dims) { - case 1: - ctx->Driver.CopyTexSubImage1D(ctx, texImage, xoffset, - srcRb, x, y, width); - break; - case 2: - ctx->Driver.CopyTexSubImage2D(ctx, texImage, xoffset, yoffset, - srcRb, x, y, width, height); - break; - case 3: - ctx->Driver.CopyTexSubImage3D(ctx, texImage, - xoffset, yoffset, zoffset, - srcRb, x, y, width, height); - break; - default: - _mesa_problem(ctx, "bad dims in copytexsubimage()"); - } + ctx->Driver.CopyTexSubImage(ctx, dims, texImage, + xoffset, yoffset, zoffset, + srcRb, x, y, width, height); check_gen_mipmap(ctx, target, texObj, level); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index eb861586c4a..593dc95cde4 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -928,12 +928,11 @@ compatible_src_dst_formats(struct gl_context *ctx, * Note: srcY=0=Bottom of renderbuffer (GL convention) */ static void -st_copy_texsubimage(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint destX, GLint destY, GLint destZ, - struct gl_renderbuffer *rb, - GLint srcX, GLint srcY, - GLsizei width, GLsizei height) +st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, + struct gl_texture_image *texImage, + GLint destX, GLint destY, GLint destZ, + struct gl_renderbuffer *rb, + GLint srcX, GLint srcY, GLsizei width, GLsizei height) { struct st_texture_image *stImage = st_texture_image(texImage); const GLenum texBaseFormat = texImage->_BaseFormat; @@ -1096,49 +1095,6 @@ fallback: } - -static void -st_CopyTexSubImage1D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width) -{ - const GLint yoffset = 0, zoffset = 0; - const GLsizei height = 1; - st_copy_texsubimage(ctx, texImage, - xoffset, yoffset, zoffset, /* destX,Y,Z */ - rb, x, y, width, height); /* src X, Y, size */ -} - - -static void -st_CopyTexSubImage2D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width, GLsizei height) -{ - const GLint zoffset = 0; - st_copy_texsubimage(ctx, texImage, - xoffset, yoffset, zoffset, /* destX,Y,Z */ - rb, x, y, width, height); /* src X, Y, size */ -} - - -static void -st_CopyTexSubImage3D(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, GLint zoffset, - struct gl_renderbuffer *rb, - GLint x, GLint y, GLsizei width, GLsizei height) -{ - st_copy_texsubimage(ctx, texImage, - xoffset, yoffset, zoffset, /* destX,Y,Z */ - rb, x, y, width, height); /* src X, Y, size */ -} - - /** * Copy image data from stImage into the texture object 'stObj' at level * 'dstLevel'. @@ -1401,9 +1357,7 @@ st_init_texture_functions(struct dd_function_table *functions) functions->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; functions->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; functions->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; - functions->CopyTexSubImage1D = st_CopyTexSubImage1D; - functions->CopyTexSubImage2D = st_CopyTexSubImage2D; - functions->CopyTexSubImage3D = st_CopyTexSubImage3D; + functions->CopyTexSubImage = st_CopyTexSubImage; functions->GenerateMipmap = st_generate_mipmap; functions->GetTexImage = st_GetTexImage; -- 2.30.2