[Piglit] [v5 03/12] framework: support for creating dma buffers through libdrm

Chad Versace chad.versace at linux.intel.com
Tue May 7 14:29:10 PDT 2013


On 05/03/2013 04:26 AM, Topi Pohjolainen wrote:
> In order to test EXT_image_dma_buf_import one needs the capability
> of creating driver specific buffers. By probing the environment for
> drm libraries one can decide for which drivers the support is to
> be built.
>
> v2 (first five according to Chad's advice):
>     - replace manual search for drm with 'pkg_check_modules()'
>     - move BATCH_SZ into intel specific part
>     - use ARRAY_SIZE
>     - fix faulty check for mem-allocation (drm_buf vs. buf)
>     - define the opaque type piglit_dma_buf declared in platform
>       independent interface instead of introducing new local type
>       (piglit_drm_dma_buf)
>     - use 'drm_intel_bo_subdata()' instead of mapping the buffers
>       for CPU
>     - also set the support for GBM in addition to X11
>
> v3:
>     - fix a type (does -> doesn't)
>     - exclude intel driver entry points when the driver is not
>       present
>
> Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
> ---
>   tests/util/CMakeLists.txt                          |  29 +++
>   .../util/piglit-framework-gl/piglit_drm_dma_buf.c  | 222 +++++++++++++++++++++
>   .../util/piglit-framework-gl/piglit_drm_dma_buf.h  |  37 ++++
>   .../piglit-framework-gl/piglit_gbm_framework.c     |   5 +
>   .../piglit-framework-gl/piglit_x11_framework.c     |   5 +
>   5 files changed, 298 insertions(+)
>   create mode 100644 tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
>   create mode 100644 tests/util/piglit-framework-gl/piglit_drm_dma_buf.h

[snip]

> +static int
> +piglit_intel_buf_create(unsigned w, unsigned h, unsigned cpp,
> +			const unsigned char *src_data, unsigned src_stride,
> +			struct piglit_dma_buf *buf)
> +{
> +	unsigned i;
> +	drm_intel_bo *bo;
> +	unsigned stride = ALIGN(w * cpp, 4);
> +	drm_intel_bufmgr *mgr = piglit_intel_bufmgr_get();
> +
> +	if (!mgr || src_stride > stride || h % 2)
> +		return -1;
> +
> +	bo = drm_intel_bo_alloc(mgr, "piglit_dma_buf", h * stride, 4096);
> +	if (!bo)
> +		return -1;
> +
> +	for (i = 0; i < h; ++i) {
> +		if (drm_intel_bo_subdata(bo, i * stride, src_stride,
> +			src_data + i * src_stride)) {
> +			drm_intel_bo_unreference(bo);
> +			return -1;
> +		}
> +	}
> +
> +	buf->w = w;
> +	buf->h = h;
> +	buf->stride = stride;

For safety, buf->fd = 0.

> +	buf->priv = bo;
> +
> +	return 0;
> +}

[snip]

> +void
> +piglit_drm_destroy_dma_buf(struct piglit_dma_buf *buf)

Just a reminder: whatever behavior you choose and document for
piglit_destroy_dma_buf() in patch 2 needs to be honored here.

> +{
> +	const struct piglit_drm_driver *drv = piglit_drm_get_driver();
> +
> +	if (!drv)
> +		return;
> +
> +	drv->destroy(buf);
> +	free(buf);
> +}

> diff --git a/tests/util/piglit-framework-gl/piglit_gbm_framework.c b/tests/util/piglit-framework-gl/piglit_gbm_framework.c
> index 4df3861..67ca21f 100644
> --- a/tests/util/piglit-framework-gl/piglit_gbm_framework.c
> +++ b/tests/util/piglit-framework-gl/piglit_gbm_framework.c
> @@ -27,6 +27,7 @@
>
>   #include "piglit-util-gl-common.h"
>   #include "piglit_gbm_framework.h"
> +#include "piglit_drm_dma_buf.h"
>
>   static void
>   enter_event_loop(struct piglit_winsys_framework *winsys_fw)
> @@ -69,6 +70,10 @@ piglit_gbm_framework_create(const struct piglit_gl_test_config *test_config)
>   	winsys_fw->show_window = show_window;
>   	winsys_fw->enter_event_loop = enter_event_loop;
>   	gl_fw->destroy = destroy;
> +#ifdef HAVE_LIBDRM
> +	gl_fw->create_dma_buf = piglit_drm_create_dma_buf;
> +	gl_fw->destroy_dma_buf = piglit_drm_destroy_dma_buf;
> +#endif
>
>   	return gl_fw;

It's not sufficient to enable the dma_buf functions for only X11
and GBM. If someone runs a Piglit test under fbo mode on any window
system [1], or under Wayland [2], then the function pointers won't get set.
The function pointer assignment should be moved up to
piglit_gl_framework.c:piglit_gl_framework_init() so that all Piglit tests
and platforms benefit.

[1] See piglit_fbo_framework.c:piglit_fbo_framework_create
[2] See piglit_wl_framework.c:piglit_wl_framework_create


More information about the Piglit mailing list