piglit_drm_dma_buf: fix NV12, YUV420, and YVU420 import tests for radeonsi

Submitted by Marek Olšák on May 13, 2019, 9:52 p.m.

Details

Message ID 20190513215229.14255-1-maraeo@gmail.com
State New
Headers show
Series "piglit_drm_dma_buf: fix NV12, YUV420, and YVU420 import tests for radeonsi" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Marek Olšák May 13, 2019, 9:52 p.m.
From: Marek Olšák <marek.olsak@amd.com>

- We have to use the linear layout, otherwise the offsets can't be modified.
- The GBM image has only 1 plane, so the gbm functions can't be used
  for other planes.
- Don't manipulate with the stride. It has to be the same.
---
 .../piglit-framework-gl/piglit_drm_dma_buf.c  | 21 ++++++++++---------
 1 file changed, 11 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

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 d2182c48c..c8adc35a4 100644
--- a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
+++ b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
@@ -323,21 +323,22 @@  piglit_gbm_buf_create(unsigned w, unsigned h, unsigned fourcc,
 		buf_w = w / 2;
 		buf_h = h * 2;    /* U/V not interleaved */
 		src_stride = w;
 		cpp = 1;
 		break;
 	default:
 		fprintf(stderr, "invalid fourcc: %.4s\n", (char *)&fourcc);
 		return false;
 	}
 
-	bo = gbm_bo_create(gbm, buf_w, buf_h, format, GBM_BO_USE_RENDERING);
+	bo = gbm_bo_create(gbm, buf_w, buf_h, format,
+			   GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
 	if (!bo)
 		return false;
 
 	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;
 	}
@@ -354,38 +355,38 @@  piglit_gbm_buf_create(unsigned w, unsigned h, unsigned fourcc,
 		       src_data + i * src_stride,
 		       w * cpp);
 	}
 
 	switch (fourcc) {
 	case DRM_FORMAT_NV12:
 		for (i = 0; i < h/2; ++i) {
 			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);
+		buf->offset[1] = buf->stride[0] * h;
+		buf->stride[1] = buf->stride[0];
 		break;
 	case DRM_FORMAT_YUV420:
 	case DRM_FORMAT_YVU420:
 		for (i = 0; i < h/2; ++i) {
-			memcpy(((char *)dst_data + dst_stride * h) + i * dst_stride / 2,
+			memcpy(((char *)dst_data + dst_stride * h) + i * dst_stride,
 				(src_data + (w*h)) + i * src_stride / 2, w / 2);
 		}
-		unsigned cpu_offset2 = dst_stride * h + (dst_stride * h / 2 / 2);
+		unsigned cpu_offset2 = dst_stride * h + dst_stride * h / 2;
 		for (i = 0; i < h/2; ++i) {
-			memcpy(((char *)dst_data + cpu_offset2) + i * dst_stride / 2,
+			memcpy(((char *)dst_data + cpu_offset2) + i * dst_stride,
 				(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);
+		buf->offset[1] = buf->stride[0] * h;
+		buf->stride[1] = buf->stride[0];
+		buf->offset[2] = buf->stride[0] * h + buf->stride[0] * h / 2;
+		buf->stride[2] = buf->stride[1];
 		break;
 	default:
 		break;
 	}
 
 	gbm_bo_unmap(bo, map_data);
 
 
 	return true;
 }