[Piglit] [PATCH] piglit_drm_dma_buf: fix GPU offsets and strides

Marek Olšák maraeo at gmail.com
Mon Jun 19 22:13:14 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

Most of the original code is simply wrong.

This patch makes sure that at least the returned GPU offsets and strides
are correct. This doesn't fix the incorrect CPU upload path for non-zero
planes. GBM doesn't seem to have the capability to map a specific plane
for CPU access.
---
 .../util/piglit-framework-gl/piglit_drm_dma_buf.c  | 23 +++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
index c3225c3..869d9db 100644
--- a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
+++ b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
@@ -322,54 +322,55 @@ piglit_gbm_buf_create(unsigned w, unsigned h, unsigned fourcc,
 	dst_data = gbm_bo_map(bo, 0, 0, buf_w, buf_h, GBM_BO_TRANSFER_WRITE,
 			      &dst_stride, &map_data);
 	if (!dst_data) {
 		fprintf(stderr, "Failed to map GBM bo\n");
 		gbm_bo_destroy(bo);
 		return NULL;
 	}
 
 	buf->w = w;
 	buf->h = h;
-	buf->offset[0] = 0;
-	buf->stride[0] = dst_stride;
+	buf->offset[0] = gbm_bo_get_offset(bo, 0);
+	buf->stride[0] = gbm_bo_get_stride_for_plane(bo, 0);
 	buf->fd = -1;
 	buf->priv = bo;
 
 	for (i = 0; i < h; ++i) {
 		memcpy((char *)dst_data + i * dst_stride,
 		       src_data + i * src_stride,
 		       w * cpp);
 	}
 
 	switch (fourcc) {
 	case DRM_FORMAT_NV12:
-		buf->offset[1] = dst_stride * h;
-		buf->stride[1] = dst_stride;
 		for (i = 0; i < h/2; ++i) {
-			memcpy(((char *)dst_data + buf->offset[1]) + i * buf->stride[1],
+			memcpy(((char *)dst_data + dst_stride * h) + i * dst_stride,
 				(src_data + (w*h)) + i * src_stride, w);
 		}
+		buf->offset[1] = gbm_bo_get_offset(bo, 1);
+		buf->stride[1] = gbm_bo_get_stride_for_plane(bo, 1);
 		break;
 	case DRM_FORMAT_YUV420:
 	case DRM_FORMAT_YVU420:
-		buf->offset[1] = dst_stride * h;
-		buf->stride[1] = dst_stride / 2;
 		for (i = 0; i < h/2; ++i) {
-			memcpy(((char *)dst_data + buf->offset[1]) + i * buf->stride[1],
+			memcpy(((char *)dst_data + dst_stride * h) + i * dst_stride / 2,
 				(src_data + (w*h)) + i * src_stride / 2, w / 2);
 		}
-		buf->offset[2] = buf->offset[1] + (dst_stride * h / 2 / 2);
-		buf->stride[2] = dst_stride / 2;
+		unsigned cpu_offset2 = dst_stride * h + (dst_stride * h / 2 / 2);
 		for (i = 0; i < h/2; ++i) {
-			memcpy(((char *)dst_data + buf->offset[2]) + i * buf->stride[2],
+			memcpy(((char *)dst_data + cpu_offset2) + i * dst_stride / 2,
 				(src_data + (w*h) + (w*h/4)) + i * src_stride / 2, w / 2);
 		}
+		buf->offset[1] = gbm_bo_get_offset(bo, 1);
+		buf->stride[1] = gbm_bo_get_stride_for_plane(bo, 1);
+		buf->offset[2] = gbm_bo_get_offset(bo, 2);
+		buf->stride[2] = gbm_bo_get_stride_for_plane(bo, 2);
 		break;
 	default:
 		break;
 	}
 
 	gbm_bo_unmap(bo, map_data);
 
 
 	return true;
 }
-- 
2.7.4



More information about the Piglit mailing list