[Mesa-dev] [PATCH 03/11] mesa: replace Driver.GetTexImage with GetTexSubImage()
Brian Paul
brianp at vmware.com
Sat Dec 13 06:42:46 PST 2014
The new driver hook has x/y/zoffset and width/height/depth parameters
for the new glGetTextureSubImage() function.
The meta code and gallium state tracker are updated to handle the
new parameters.
Callers to Driver.GetTexSubImage() pass in offsets=0 and sizes equal
to the whole texture size.
---
src/mesa/drivers/common/driverfuncs.c | 2 +-
src/mesa/drivers/common/meta.c | 23 +++++++++++++----------
src/mesa/drivers/common/meta.h | 8 +++++---
src/mesa/main/dd.h | 10 ++++++----
src/mesa/main/debug.c | 4 +++-
src/mesa/main/mipmap.c | 9 ++++++---
src/mesa/main/texgetimage.c | 15 ++++++++++-----
src/mesa/main/texgetimage.h | 8 +++++---
src/mesa/state_tracker/st_cb_texture.c | 33 ++++++++++++++++++++-------------
9 files changed, 69 insertions(+), 43 deletions(-)
diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
index 4f0f7a6..27b3e6f 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->QuerySamplesForFormat = _mesa_query_samples_for_format;
driver->TexImage = _mesa_store_teximage;
driver->TexSubImage = _mesa_store_texsubimage;
- driver->GetTexImage = _mesa_meta_GetTexImage;
+ driver->GetTexSubImage = _mesa_meta_GetTexSubImage;
driver->ClearTexSubImage = _mesa_meta_ClearTexSubImage;
driver->CopyTexSubImage = _mesa_meta_CopyTexSubImage;
driver->GenerateMipmap = _mesa_meta_GenerateMipmap;
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index c2057e5..31cfde5 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -3196,15 +3196,17 @@ decompress_texture_image(struct gl_context *ctx,
* from core Mesa.
*/
void
-_mesa_meta_GetTexImage(struct gl_context *ctx,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_image *texImage)
+_mesa_meta_GetTexSubImage(struct gl_context *ctx,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_image *texImage)
{
if (_mesa_is_format_compressed(texImage->TexFormat)) {
GLuint slice;
bool result;
- for (slice = 0; slice < texImage->Depth; slice++) {
+ for (slice = 0; slice < depth; slice++) {
void *dst;
if (texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY
|| texImage->TexObject->Target == GL_TEXTURE_CUBE_MAP_ARRAY) {
@@ -3216,15 +3218,14 @@ _mesa_meta_GetTexImage(struct gl_context *ctx,
struct gl_pixelstore_attrib packing = ctx->Pack;
packing.SkipPixels = 0;
packing.SkipRows = 0;
- dst = _mesa_image_address3d(&packing, pixels, texImage->Width,
- texImage->Height, format, type,
- slice, 0, 0);
+ dst = _mesa_image_address3d(&packing, pixels, width, height,
+ format, type, slice, 0, 0);
}
else {
dst = pixels;
}
- result = decompress_texture_image(ctx, texImage, slice, 0, 0,
- texImage->Width, texImage->Height,
+ result = decompress_texture_image(ctx, texImage, slice,
+ xoffset, yoffset, width, height,
format, type, dst);
if (!result)
break;
@@ -3234,7 +3235,9 @@ _mesa_meta_GetTexImage(struct gl_context *ctx,
return;
}
- _mesa_get_teximage(ctx, format, type, pixels, texImage);
+ _mesa_get_texsubimage(ctx, xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, pixels, texImage);
}
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 03e5191..2f4740c 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -535,9 +535,11 @@ _mesa_meta_ClearTexSubImage(struct gl_context *ctx,
const GLvoid *clearValue);
extern void
-_mesa_meta_GetTexImage(struct gl_context *ctx,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_image *texImage);
+_mesa_meta_GetTexSubImage(struct gl_context *ctx,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_image *texImage);
extern void
_mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 2f40915..34f8d86 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -232,11 +232,13 @@ struct dd_function_table {
/**
- * Called by glGetTexImage().
+ * Called by glGetTexImage(), glGetTextureSubImage().
*/
- void (*GetTexImage)( struct gl_context *ctx,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_image *texImage );
+ void (*GetTexSubImage)(struct gl_context *ctx,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLint depth,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_image *texImage);
/**
* Called by glClearTex[Sub]Image
diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index 089ce89..e421bc1 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -276,7 +276,9 @@ write_texture_image(struct gl_texture_object *texObj,
store = ctx->Pack; /* save */
ctx->Pack = ctx->DefaultPacking;
- ctx->Driver.GetTexImage(ctx, GL_RGBA, GL_UNSIGNED_BYTE, buffer, img);
+ ctx->Driver.GetTexSubImage(ctx,
+ 0, 0, 0, img->Width, img->Height, img->Depth,
+ GL_RGBA, GL_UNSIGNED_BYTE, buffer, img);
/* make filename */
_mesa_snprintf(s, sizeof(s), "/tmp/tex%u.l%u.f%u.ppm", texObj->Name, level, face);
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index fdaa682..1415748 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -2077,9 +2077,12 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
/* Get the uncompressed image */
assert(srcImage->Level == texObj->BaseLevel);
- ctx->Driver.GetTexImage(ctx,
- temp_base_format, temp_datatype,
- temp_src, srcImage);
+ ctx->Driver.GetTexSubImage(ctx,
+ 0, 0, 0,
+ srcImage->Width, srcImage->Height,
+ srcImage->Depth,
+ temp_base_format, temp_datatype,
+ temp_src, srcImage);
/* restore packing mode */
ctx->Pack = save;
}
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index cb5f793..03ad5f4 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -625,15 +625,17 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type,
/**
- * This is the software fallback for Driver.GetTexImage().
+ * This is the software fallback for Driver.GetTexSubImage().
* 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().
*/
void
-_mesa_get_teximage(struct gl_context *ctx,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_image *texImage)
+_mesa_get_texsubimage(struct gl_context *ctx,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLint depth,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_image *texImage)
{
const GLuint dimensions =
_mesa_get_texture_dimensions(texImage->TexObject->Target);
@@ -946,7 +948,10 @@ _mesa_GetnTexImageARB( GLenum target, GLint level, GLenum format,
_mesa_lock_texture(ctx, texObj);
{
- ctx->Driver.GetTexImage(ctx, format, type, pixels, texImage);
+ ctx->Driver.GetTexSubImage(ctx, 0, 0, 0,
+ texImage->Width, texImage->Height,
+ texImage->Depth,
+ format, type, pixels, texImage);
}
_mesa_unlock_texture(ctx, texObj);
}
diff --git a/src/mesa/main/texgetimage.h b/src/mesa/main/texgetimage.h
index a292fab..c9af5b9 100644
--- a/src/mesa/main/texgetimage.h
+++ b/src/mesa/main/texgetimage.h
@@ -37,9 +37,11 @@ extern GLenum
_mesa_base_pack_format(GLenum format);
extern void
-_mesa_get_teximage(struct gl_context *ctx,
- GLenum format, GLenum type, GLvoid *pixels,
- struct gl_texture_image *texImage);
+_mesa_get_texsubimage(struct gl_context *ctx,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLint depth,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_image *texImage);
extern void
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index a8dbb78..8c5cbf1 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -892,7 +892,7 @@ st_CompressedTexImage(struct gl_context *ctx, GLuint dims,
/**
- * Called via ctx->Driver.GetTexImage()
+ * Called via ctx->Driver.GetTexSubImage()
*
* This uses a blit to copy the texture to a texture format which matches
* the format and type combo and then a fast read-back is done using memcpy.
@@ -906,16 +906,15 @@ st_CompressedTexImage(struct gl_context *ctx, GLuint dims,
* we do here should be free in such cases.
*/
static void
-st_GetTexImage(struct gl_context * ctx,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_image *texImage)
+st_GetTexSubImage(struct gl_context * ctx,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLint depth,
+ GLenum format, GLenum type, GLvoid * pixels,
+ struct gl_texture_image *texImage)
{
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
- GLuint width = texImage->Width;
- GLuint height = texImage->Height;
- GLuint depth = texImage->Depth;
struct st_texture_image *stImage = st_texture_image(texImage);
struct st_texture_object *stObj = st_texture_object(texImage->TexObject);
struct pipe_resource *src = stObj->pt;
@@ -1050,7 +1049,7 @@ st_GetTexImage(struct gl_context * ctx,
}
}
- /* create the destination texture */
+ /* create the destination texture of size (width X height X depth) */
memset(&dst_templ, 0, sizeof(dst_templ));
dst_templ.target = pipe_target;
dst_templ.format = dst_format;
@@ -1072,6 +1071,10 @@ st_GetTexImage(struct gl_context * ctx,
height = 1;
}
+ assert(texImage->Face == 0 ||
+ texImage->TexObject->MinLayer == 0 ||
+ zoffset == 0);
+
memset(&blit, 0, sizeof(blit));
blit.src.resource = src;
blit.src.level = texImage->Level + texImage->TexObject->MinLevel;
@@ -1079,9 +1082,11 @@ st_GetTexImage(struct gl_context * ctx,
blit.dst.resource = dst;
blit.dst.level = 0;
blit.dst.format = dst->format;
- blit.src.box.x = blit.dst.box.x = 0;
- blit.src.box.y = blit.dst.box.y = 0;
- blit.src.box.z = texImage->Face + texImage->TexObject->MinLayer;
+ blit.src.box.x = xoffset;
+ blit.dst.box.x = 0;
+ blit.src.box.y = yoffset;
+ blit.dst.box.y = 0;
+ blit.src.box.z = texImage->Face + texImage->TexObject->MinLayer + zoffset;
blit.dst.box.z = 0;
blit.src.box.width = blit.dst.box.width = width;
blit.src.box.height = blit.dst.box.height = height;
@@ -1195,7 +1200,9 @@ end:
fallback:
if (!done) {
- _mesa_get_teximage(ctx, format, type, pixels, texImage);
+ _mesa_get_texsubimage(ctx, xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, pixels, texImage);
}
}
@@ -1882,7 +1889,7 @@ st_init_texture_functions(struct dd_function_table *functions)
functions->CopyTexSubImage = st_CopyTexSubImage;
functions->GenerateMipmap = st_generate_mipmap;
- functions->GetTexImage = st_GetTexImage;
+ functions->GetTexSubImage = st_GetTexSubImage;
/* compressed texture functions */
functions->CompressedTexImage = st_CompressedTexImage;
--
1.9.1
More information about the mesa-dev
mailing list