diff mbox

[6/6] ext_image_dma_buf_import: test sampling correctness with format modifiers

Message ID 1480066519-20283-7-git-send-email-varadgautam@gmail.com
State New
Headers show

Commit Message

Varad Gautam Nov. 25, 2016, 9:35 a.m. UTC
From: Varad Gautam <varad.gautam@collabora.com>

add a test that imports and samples DRM_FORMAT_NV12 and
DRM_FORMAT_NV12 + DRM_FORMAT_MOD_SAMSUNG_64_32_TILE patterns using
EGL_EXT_image_dma_buf_import_modifiers and compares them for equality.

Signed-off-by: Varad Gautam <varad.gautam@collabora.com>
---
 tests/all.py                                       |   2 +
 .../ext_image_dma_buf_import/CMakeLists.gles2.txt  |   1 +
 .../sample_yuv_modifiers.c                         | 197 +++++++++++++++++++++
 3 files changed, 200 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/sample_yuv_modifiers.c
diff mbox

Patch

diff --git a/tests/all.py b/tests/all.py
index da84d34..4999c7a 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3131,6 +3131,8 @@  with profile.test_list.group_manager(
       '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-sample_yuv_modifiers', '-fmt=NV12MT'],
+      'ext_image_dma_buf_import-sample_nv12mt', 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 a3729fb..8c03c77 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
@@ -18,6 +18,7 @@  if(PIGLIT_BUILD_DMA_BUF_TESTS)
 
 	piglit_add_executable(ext_image_dma_buf_import-refcount refcount.c sample_common.c image_common.c)
 	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_yuv_modifiers sample_yuv_modifiers.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_yuv_modifiers.c b/tests/spec/ext_image_dma_buf_import/sample_yuv_modifiers.c
new file mode 100644
index 0000000..8fce59a
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/sample_yuv_modifiers.c
@@ -0,0 +1,197 @@ 
+/*
+ * Copyright © 2016 Collabora, Ltd.
+ *
+ * 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"
+#include "nv12_frame_data.h"
+
+/* @file sample_yuv_modifiers.c
+ *
+ * Create EGL images from multi-planar dma bufs with and without using format
+ * modifiers and sample them as external textures.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+#define MAX_MODIFIERS 4
+
+static int fourcc = -1;
+static uint64_t modifiers[MAX_MODIFIERS];
+
+enum piglit_result
+piglit_display(void)
+{
+	extern const unsigned nv12[];
+	extern const unsigned nv12_64z32[];
+	EGLint *formats;
+	EGLuint64KHR supported_modifiers[MAX_MODIFIERS] = {0};
+	EGLint num_formats, num_modifiers;
+	unsigned char *expected;
+	const unsigned char *data;
+	const unsigned width = 128, height = 128;
+	EGLDisplay egl_dpy = eglGetCurrentDisplay();
+	int nr_planes;
+	enum piglit_result res;
+	bool pass = true;
+	unsigned i = 0, j = 0;
+
+	/* query format and modifier support before proceeding */
+	pass &= eglQueryDmaBufFormatsEXT(egl_dpy, 0, NULL, &num_formats);
+	if(!pass)
+		goto cleanup;
+
+	formats = calloc(1, num_formats * sizeof(EGLint));
+	pass &= eglQueryDmaBufFormatsEXT(egl_dpy, num_formats, formats,
+					 &num_formats);
+	if(!pass)
+		goto cleanup;
+
+	/* skip if the intended format is not supported on this platform */
+	for (i = 0; i < num_formats; i++) {
+		if (fourcc == formats[i])
+			break;
+	}
+	free(formats);
+	if (i == num_formats)
+		return PIGLIT_SKIP;
+
+	switch (fourcc) {
+	case DRM_FORMAT_NV12:
+		data = (unsigned char *) nv12;
+		nr_planes = 2;
+		break;
+	/* add more formats that support modifiers */
+	default:
+		return PIGLIT_SKIP;
+	}
+
+	pass &= eglQueryDmaBufModifiersEXT(egl_dpy, fourcc, 4,
+					   supported_modifiers, NULL,
+					   &num_modifiers);
+	if(!pass)
+		goto cleanup;
+
+	/* skip if the required modifiers are not supported on this platform */
+	for (i = 0; i < nr_planes; i++) {
+		for (j = 0; j < num_modifiers; j++) {
+			if (modifiers[i] == supported_modifiers[j])
+				break;
+		}
+		if (j == num_modifiers)
+			return PIGLIT_SKIP;
+	}
+
+	/* sample without modifiers to get reference image */
+	res = dma_buf_create_and_sample_32bpp(width, height,
+					      fourcc, NULL, 0, data);
+	if (res != PIGLIT_PASS)
+		return res;
+
+	expected = calloc(1, width * height * 4 * sizeof(GLubyte));
+
+	glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, expected);
+
+	switch (fourcc) {
+	case DRM_FORMAT_NV12:
+		if (modifiers[0] == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE &&
+		     modifiers[1] == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE)
+			data = (unsigned char *) nv12_64z32;
+		break;
+	default:
+		return PIGLIT_SKIP;
+	}
+
+	/* sample with modifiers to get test image */
+	res = dma_buf_create_and_sample_32bpp(width, height, fourcc,
+					      modifiers, 2, data);
+	if (res != PIGLIT_PASS) {
+		pass &= false;
+		goto cleanup;
+	}
+
+	/* Lower tolerance in case we're running against a 565 render
+	 * target (gbm).
+	 */
+	piglit_set_tolerance_for_bits(5, 6, 5, 8);
+
+	if (!piglit_probe_image_ubyte(0, 0, width, height, GL_RGBA, expected))
+		pass &= false;
+
+cleanup:
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+static void print_usage_and_exit(const char* progname)
+{
+	printf("Usage: %s -fmt=[NV12MT]\n", progname);
+	piglit_report_result(PIGLIT_FAIL);
+}
+
+static int parse_modifiers(const char *s)
+{
+	if (!strcmp(s, "MT")){
+		/* NV12MT is DRM_FORMAT_NV12 format with
+		 * DRM_FORMAT_MOD_SAMSUNG_64_32_TILE modifier */
+		modifiers[0] = DRM_FORMAT_MOD_SAMSUNG_64_32_TILE;
+		modifiers[1] = DRM_FORMAT_MOD_SAMSUNG_64_32_TILE;
+		return 1;
+	}
+
+	return 0;
+}
+
+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_modifiers");
+	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)) {
+			fourcc = parse_format(argv[i] + sizeof(fmt) - 1);
+			if (!parse_modifiers(argv[i] + sizeof(fmt) + 3))
+				print_usage_and_exit(argv[0]);
+		}
+		else
+			print_usage_and_exit(argv[0]);
+	}
+	if (fourcc == -1)
+		print_usage_and_exit(argv[0]);
+}
\ No newline at end of file