st/mesa: use a single memcpy in st_ReadPixels when possible
This avoids costly address recomputations, function overhead, and may trigger large copy optimizations. Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
@@ -520,14 +520,21 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
|
||||
/* memcpy data into a user buffer */
|
||||
{
|
||||
const uint bytesPerRow = width * util_format_get_blocksize(dst_format);
|
||||
GLuint row;
|
||||
const uint destStride = _mesa_image_row_stride(pack, width, format, type);
|
||||
char *dest = _mesa_image_address2d(pack, pixels,
|
||||
width, height, format,
|
||||
type, 0, 0);
|
||||
|
||||
for (row = 0; row < (unsigned) height; row++) {
|
||||
void *dest = _mesa_image_address2d(pack, pixels,
|
||||
width, height, format,
|
||||
type, row, 0);
|
||||
memcpy(dest, map, bytesPerRow);
|
||||
map += tex_xfer->stride;
|
||||
if (tex_xfer->stride == bytesPerRow && destStride == bytesPerRow) {
|
||||
memcpy(dest, map, bytesPerRow * height);
|
||||
} else {
|
||||
GLuint row;
|
||||
|
||||
for (row = 0; row < (unsigned) height; row++) {
|
||||
memcpy(dest, map, bytesPerRow);
|
||||
map += tex_xfer->stride;
|
||||
dest += destStride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user