From d172fa825b21ce3ff4f5cd83d0de7ef7f3a8d865 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 22 Nov 2012 22:40:06 +0100 Subject: [PATCH] r600g: fix ARB_map_buffer_alignment with unaligned offsets and staging buffers --- src/gallium/drivers/r600/r600_buffer.c | 7 +++++-- src/gallium/drivers/r600/r600_pipe.c | 2 +- src/gallium/drivers/r600/r600_pipe.h | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c index 968824e..3b8d227 100644 --- a/src/gallium/drivers/r600/r600_buffer.c +++ b/src/gallium/drivers/r600/r600_buffer.c @@ -149,11 +149,14 @@ static void *r600_buffer_transfer_map(struct pipe_context *ctx, /* Do a wait-free write-only transfer using a temporary buffer. */ struct r600_resource *staging = (struct r600_resource*) pipe_buffer_create(ctx->screen, PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STAGING, box->width); + PIPE_USAGE_STAGING, + box->width + (box->x % R600_MAP_BUFFER_ALIGNMENT)); data = rctx->ws->buffer_map(staging->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE); if (!data) return NULL; + + data += box->x % R600_MAP_BUFFER_ALIGNMENT; return r600_buffer_get_transfer(ctx, resource, level, usage, box, ptransfer, data, staging); } @@ -177,7 +180,7 @@ static void r600_buffer_transfer_unmap(struct pipe_context *pipe, if (rtransfer->staging) { struct pipe_box box; - u_box_1d(0, transfer->box.width, &box); + u_box_1d(transfer->box.x % R600_MAP_BUFFER_ALIGNMENT, transfer->box.width, &box); /* Copy the staging buffer into the original one. */ r600_copy_buffer(pipe, transfer->resource, transfer->box.x, diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c index 296f812..04ddbea 100644 --- a/src/gallium/drivers/r600/r600_pipe.c +++ b/src/gallium/drivers/r600/r600_pipe.c @@ -401,7 +401,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) return 1; case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT: - return 64; + return R600_MAP_BUFFER_ALIGNMENT; case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: return 256; diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h index 33ccefa..219bd54 100644 --- a/src/gallium/drivers/r600/r600_pipe.h +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -52,6 +52,8 @@ #define R600_BIG_ENDIAN 0 #endif +#define R600_MAP_BUFFER_ALIGNMENT 64 + struct r600_bytecode; struct r600_shader_key; -- 2.7.4