[Mesa-dev] [PATCH] mesa: use single memcpy when strides match
Bartosz Tomczyk
bartosz.tomczyk86 at gmail.com
Tue Apr 11 08:14:17 UTC 2017
Thank you very much, Brian.
On Mon, Apr 10, 2017 at 10:43 PM, Brian Paul <brianp at vmware.com> wrote:
> Pushed, with slightly more descriptive commit msg.
>
> -Brian
>
>
> On 04/10/2017 12:31 PM, Bartosz Tomczyk wrote:
>
>> v2: fix indentation
>> ---
>> src/mesa/main/readpix.c | 15 ++++++++++-----
>> src/mesa/main/texstore.c | 15 +++++++++++----
>> 2 files changed, 21 insertions(+), 9 deletions(-)
>>
>> diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
>> index 25823230d6..606d1e58e5 100644
>> --- a/src/mesa/main/readpix.c
>> +++ b/src/mesa/main/readpix.c
>> @@ -220,7 +220,7 @@ readpixels_memcpy(struct gl_context *ctx,
>> struct gl_renderbuffer *rb =
>> _mesa_get_read_renderbuffer_for_format(ctx, format);
>> GLubyte *dst, *map;
>> - int dstStride, stride, j, texelBytes;
>> + int dstStride, stride, j, texelBytes, bytesPerRow;
>>
>> /* Fail if memcpy cannot be used. */
>> if (!readpixels_can_use_memcpy(ctx, format, type, packing)) {
>> @@ -239,12 +239,17 @@ readpixels_memcpy(struct gl_context *ctx,
>> }
>>
>> texelBytes = _mesa_get_format_bytes(rb->Format);
>> + bytesPerRow = texelBytes * width;
>>
>> /* memcpy*/
>> - for (j = 0; j < height; j++) {
>> - memcpy(dst, map, width * texelBytes);
>> - dst += dstStride;
>> - map += stride;
>> + if (dstStride == stride && dstStride == bytesPerRow) {
>> + memcpy(dst, map, bytesPerRow * height);
>> + } else {
>> + for (j = 0; j < height; j++) {
>> + memcpy(dst, map, bytesPerRow);
>> + dst += dstStride;
>> + map += stride;
>> + }
>> }
>>
>> ctx->Driver.UnmapRenderbuffer(ctx, rb);
>> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
>> index 615ba63362..3314e557c0 100644
>> --- a/src/mesa/main/texstore.c
>> +++ b/src/mesa/main/texstore.c
>> @@ -1360,10 +1360,17 @@ _mesa_store_compressed_texsubimage(struct
>> gl_context *ctx, GLuint dims,
>> if (dstMap) {
>>
>> /* copy rows of blocks */
>> - for (i = 0; i < store.CopyRowsPerSlice; i++) {
>> - memcpy(dstMap, src, store.CopyBytesPerRow);
>> - dstMap += dstRowStride;
>> - src += store.TotalBytesPerRow;
>> + if (dstRowStride == store.TotalBytesPerRow &&
>> + dstRowStride == store.CopyBytesPerRow) {
>> + memcpy(dstMap, src, store.CopyBytesPerRow *
>> store.CopyRowsPerSlice);
>> + src += store.CopyBytesPerRow * store.CopyRowsPerSlice;
>> + }
>> + else {
>> + for (i = 0; i < store.CopyRowsPerSlice; i++) {
>> + memcpy(dstMap, src, store.CopyBytesPerRow);
>> + dstMap += dstRowStride;
>> + src += store.TotalBytesPerRow;
>> + }
>> }
>>
>> ctx->Driver.UnmapTextureImage(ctx, texImage, slice + zoffset);
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170411/db10c56b/attachment.html>
More information about the mesa-dev
mailing list