[Piglit] [PATCH 1/2] Add tests for YUV EGLImages with samplerExternalOES

Kristian Høgsberg hoegsberg at gmail.com
Wed May 11 20:38:56 UTC 2016


From: Kristian Høgsberg Kristensen <kristian.h.kristensen at intel.com>

---
 tests/all.py                                       |   6 +
 .../ext_image_dma_buf_import/CMakeLists.gles2.txt  |   1 +
 .../spec/ext_image_dma_buf_import/sample_common.c  |  67 ++++++++-
 tests/spec/ext_image_dma_buf_import/sample_yuv.c   | 154 +++++++++++++++++++++
 4 files changed, 223 insertions(+), 5 deletions(-)
 create mode 100644 tests/spec/ext_image_dma_buf_import/sample_yuv.c

diff --git a/tests/all.py b/tests/all.py
index 395f964..a02dc37 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3062,6 +3062,12 @@ with profile.group_manager(
       'ext_image_dma_buf_import-sample_argb8888', run_concurrent=False)
     g(['ext_image_dma_buf_import-sample_rgb', '-fmt=XR24', '-alpha-one'],
       'ext_image_dma_buf_import-sample_xrgb8888', run_concurrent=False)
+    g(['ext_image_dma_buf_import-sample_yuv', '-fmt=NV12', '-alpha-one'],
+      'ext_image_dma_buf_import-sample_nv12', run_concurrent=False)
+    g(['ext_image_dma_buf_import-sample_yuv', '-fmt=YU12', '-alpha-one'],
+      'ext_image_dma_buf_import-sample_yuv420', run_concurrent=False)
+    g(['ext_image_dma_buf_import-sample_yuv', '-fmt=YV12', '-alpha-one'],
+      'ext_image_dma_buf_import-sample_yvu420', run_concurrent=False)
     g(['ext_image_dma_buf_import-transcode-nv12-as-r8-gr88'],
       'ext_image_dma_buf_import-transcode-nv12-as-r8-gr88',
       run_concurrent=False)
diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
index a1e0042..fdf4359 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
@@ -16,6 +16,7 @@ if(PIGLIT_BUILD_DMA_BUF_TESTS)
 		${LIBDRM_INCLUDE_DIRS}
 	)
 
+	piglit_add_executable(ext_image_dma_buf_import-sample_yuv sample_yuv.c sample_common.c image_common.c)
 	piglit_add_executable(ext_image_dma_buf_import-sample_rgb sample_rgb.c sample_common.c image_common.c)
 	piglit_add_executable(ext_image_dma_buf_import-intel_external_sampler_with_dma_only intel_external_sampler_with_dma_only.c image_common.c)
 	piglit_add_executable(ext_image_dma_buf_import-transcode-nv12-as-r8-gr88 transcode-nv12-as-r8-gr88.c image_common.c)
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.c b/tests/spec/ext_image_dma_buf_import/sample_common.c
index 95f1098..7373cd4 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.c
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.c
@@ -116,7 +116,7 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
 {
 	EGLint error;
 	EGLImageKHR img;
-	EGLint attr[] = {
+	EGLint attr_packed[] = {
 		EGL_WIDTH, w,
 		EGL_HEIGHT, h,
 		EGL_LINUX_DRM_FOURCC_EXT, fourcc,
@@ -126,8 +126,51 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
 		EGL_NONE
 	};
 
+	EGLint attr_nv12[] = {
+		EGL_WIDTH, w,
+		EGL_HEIGHT, h,
+		EGL_LINUX_DRM_FOURCC_EXT, fourcc,
+		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+		EGL_DMA_BUF_PLANE1_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE1_OFFSET_EXT, offset + h * stride,
+		EGL_DMA_BUF_PLANE1_PITCH_EXT, stride,
+		EGL_NONE
+	};
+
+	EGLint attr_yuv420[] = {
+		EGL_WIDTH, w,
+		EGL_HEIGHT, h,
+		EGL_LINUX_DRM_FOURCC_EXT, fourcc,
+		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+		EGL_DMA_BUF_PLANE1_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE1_OFFSET_EXT, offset + h * stride,
+		EGL_DMA_BUF_PLANE1_PITCH_EXT, stride,
+		EGL_DMA_BUF_PLANE2_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE2_OFFSET_EXT, offset + h * stride + w / 2,
+		EGL_DMA_BUF_PLANE2_PITCH_EXT, stride,
+		EGL_NONE
+	};
+
+	EGLint *attr;
+	switch (fourcc) {
+	case DRM_FORMAT_NV12:
+		attr = attr_nv12;
+		break;
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+		attr = attr_yuv420;
+		break;
+	default:
+		attr = attr_packed;
+		break;
+	}
+
 	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
-			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
+				EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
 
 	/* Release the creator side of the buffer. */
 	piglit_destroy_dma_buf(buf);
@@ -158,15 +201,29 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
 
 enum piglit_result
 dma_buf_create_and_sample_32bpp(unsigned w, unsigned h, unsigned cpp,
-			int fourcc, const unsigned char *src)
+				int fourcc, const unsigned char *src)
 {
 	struct piglit_dma_buf *buf;
 	unsigned stride, offset;
 	int fd;
 	enum piglit_result res;
 
-	res = piglit_create_dma_buf(w, h, cpp, src, w * cpp, &buf, &fd, &stride,
-				&offset);
+	unsigned buffer_height;
+
+	switch (fourcc) {
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+		buffer_height = h * 3 / 2;
+		break;
+	default:
+		buffer_height = h;
+		break;
+	}
+
+	res = piglit_create_dma_buf(w, buffer_height,
+				    cpp, src, w * cpp, &buf, &fd, &stride,
+				    &offset);
 	if (res != PIGLIT_PASS)
 		return res;
 
diff --git a/tests/spec/ext_image_dma_buf_import/sample_yuv.c b/tests/spec/ext_image_dma_buf_import/sample_yuv.c
new file mode 100644
index 0000000..9605534
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/sample_yuv.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "sample_common.h"
+#include "image_common.h"
+
+/**
+ * @file sample_rgb.c
+ *
+ * Create EGL images out of various YUV formatted dma buffers, set
+ * them as external textures, set texture filters for avoiding need
+ * for other mipmap-levels and sample the textures using a shader
+ * program.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static int fourcc = -1;
+
+enum piglit_result
+piglit_display(void)
+{
+	static const unsigned char nv12[] = {
+		10, 20, 30, 40,
+		30, 40, 10, 10,
+		10, 10, 10, 10,
+		10, 10, 10, 10,
+		20, 30, 20, 30,
+		20, 30, 20, 30
+	}, yuv420[] = {
+		10, 20, 30, 40,
+		30, 40, 10, 10,
+		10, 10, 10, 10,
+		10, 10, 10, 10,
+		20, 20, 30, 30,
+		20, 20, 30, 30
+	}, yvu420[] = {
+		10, 20, 30, 40,
+		30, 40, 10, 10,
+		10, 10, 10, 10,
+		10, 10, 10, 10,
+		30, 30, 20, 20,
+		30, 30, 20, 20,
+	};
+
+	static const unsigned char expected[4 * 4 * 4] = {
+		58,  0, 50, 255,
+		68,  0, 60, 255,
+		78,  0, 70, 255,
+		88,  8, 80, 255,
+
+		78,  0, 70, 255,
+		88,  8, 80, 255,
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+		58,  0, 50, 255,
+	};
+
+	const unsigned char *t;
+
+	enum piglit_result res;
+	switch (fourcc) {
+	case DRM_FORMAT_NV12:
+		t = nv12;
+		break;
+	case DRM_FORMAT_YUV420:
+		t = yuv420;
+		break;
+	case DRM_FORMAT_YVU420:
+		t = yvu420;
+		break;
+	default:
+		return PIGLIT_SKIP;
+	}
+
+	res = dma_buf_create_and_sample_32bpp(4, 4, 1, fourcc, t);
+	if (res != PIGLIT_PASS)
+		return res;
+
+	return piglit_probe_image_ubyte(0, 0, 4, 4, GL_RGBA, expected) ?
+			PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+static int
+parse_format(const char *s)
+{
+	if (strlen(s) != 4)
+		return -1;
+
+	return (int)fourcc_code(s[0], s[1], s[2], s[3]);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	unsigned i;
+	EGLDisplay egl_dpy = eglGetCurrentDisplay();
+
+	piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");
+	piglit_require_extension("GL_OES_EGL_image_external");
+
+	for (i = 1; i < argc; i++) {
+                static const char fmt[] = "-fmt=";
+
+                if (strncmp(argv[i], fmt, sizeof(fmt) - 1)) {
+			fprintf(stderr, "unknown argument %s\n", argv[i]);
+                        continue;
+		}
+
+		fourcc = parse_format(argv[i] + sizeof(fmt) - 1);
+		if (fourcc == -1) {
+			fprintf(stderr, "invalid format: %s\n", argv[i]);
+			piglit_report_result(PIGLIT_SKIP);
+		}
+        }
+
+	if (fourcc == -1) {
+		fprintf(stderr, "format not specified\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+}
-- 
2.5.0



More information about the Piglit mailing list