[Piglit] [v10 03/13] framework: hardware independent interface for dma buffers

Topi Pohjolainen topi.pohjolainen at intel.com
Tue Aug 20 03:16:23 PDT 2013


In order to test the EXT_image_dma_buf_import, one needs a way for
creating dma buffers that can be imported to EGL and filling them
with data for the GL-stack to sample.
While dma buffer themselves are only defined for linux, the actual
writing of the buffers using CPU differs from hardware to another,
and possibly from window system to another. The intention here is
to push these details into the framework leaving the actual tests
environment independent.

v2 (Chad):
   - replace 'void*' buffer type by 'struct piglit_dma_buf *'

v3 (Chan, Ken):
   - document passing NULL pointers to buffer desctruction

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
Reviewed-by: Chad Versace <chad.versace at linux.intel.com> (v2)
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 tests/util/piglit-framework-gl.c                   | 24 +++++++++++++++++++++
 tests/util/piglit-framework-gl.h                   | 25 ++++++++++++++++++++++
 .../util/piglit-framework-gl/piglit_gl_framework.h |  9 ++++++++
 3 files changed, 58 insertions(+)

diff --git a/tests/util/piglit-framework-gl.c b/tests/util/piglit-framework-gl.c
index 85dcac0..2a315be 100644
--- a/tests/util/piglit-framework-gl.c
+++ b/tests/util/piglit-framework-gl.c
@@ -195,3 +195,27 @@ piglit_strip_arg(int *argc, char *argv[], const char *arg)
 	}
 	return false;
 }
+
+enum piglit_result
+piglit_create_dma_buf(unsigned w, unsigned h, unsigned cpp,
+		      const void *src_data, unsigned src_stride,
+		      struct piglit_dma_buf **buf, int *fd,
+		      unsigned *stride, unsigned *offset)
+{
+	*fd = 0;
+	*stride = 0;
+	*offset = 0;
+
+	if (!gl_fw->create_dma_buf)
+		return PIGLIT_SKIP;
+
+	return gl_fw->create_dma_buf(w, h, cpp, src_data, src_stride, buf, fd,
+				stride, offset);
+}
+
+void
+piglit_destroy_dma_buf(struct piglit_dma_buf *buf)
+{
+	if (gl_fw->destroy_dma_buf)
+		gl_fw->destroy_dma_buf(buf);
+}
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index 57b6325..7520f38 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -258,4 +258,29 @@ bool piglit_strip_arg(int *argc, char *argv[], const char *arg);
  */
 #define PIGLIT_STRIP_ARG(arg) piglit_strip_arg(&argc, argv, arg)
 
+struct piglit_dma_buf;
+
+/**
+ * Create buffer suitable for dma_buf importing and set its contents to the
+ * given data (src_data). Different hardware may have different alignment
+ * constraints and hence one can specify one stride for the source and get
+ * another for the final buffer to be given further to EGL.
+ * An opaque handle, file descriptor, stride and offset for the buffer are only
+ * returned upon success indicated by the return value PIGLIT_PASS, otherwise
+ * no buffer is created. In case the framework simply does not support dma
+ * buffers, the return value is PIGLIT_SKIP instead of PIGLIT_FAIL.
+ */
+enum piglit_result
+piglit_create_dma_buf(unsigned w, unsigned h, unsigned cpp,
+		      const void *src_data, unsigned src_stride,
+		      struct piglit_dma_buf **buf, int *fd,
+		      unsigned *stride, unsigned *offset);
+
+/**
+ * Release all the resources allocated for the designated buffer. If the given
+ * pointer (buf) is NULL no action is taken.
+ */
+void
+piglit_destroy_dma_buf(struct piglit_dma_buf *buf);
+
 #endif /* PIGLIT_FRAMEWORK_H */
diff --git a/tests/util/piglit-framework-gl/piglit_gl_framework.h b/tests/util/piglit-framework-gl/piglit_gl_framework.h
index 6dbdf94..97fecca 100644
--- a/tests/util/piglit-framework-gl/piglit_gl_framework.h
+++ b/tests/util/piglit-framework-gl/piglit_gl_framework.h
@@ -71,6 +71,15 @@ struct piglit_gl_framework {
 
 	void
 	(*destroy)(struct piglit_gl_framework *gl_fw);
+
+	enum piglit_result
+	(*create_dma_buf)(unsigned w, unsigned h, unsigned cpp,
+			  const void *src_data, unsigned src_stride,
+			  struct piglit_dma_buf **buf, int *fd,
+			  unsigned *stride, unsigned *offset);
+
+	void
+	(*destroy_dma_buf)(struct piglit_dma_buf *buf);
 };
 
 struct piglit_gl_framework*
-- 
1.8.3.1



More information about the Piglit mailing list