[Piglit] [PATCH 1/8] piglit-framework-gl: Use GBM on non-intel for dmabuf creation.
Rob Clark
robdclark at gmail.com
Fri Aug 12 21:13:56 UTC 2016
On Mon, Jul 25, 2016 at 8:43 PM, Eric Anholt <eric at anholt.net> wrote:
> Previously the dmabuf tests only worked on the intel driver. However,
> thanks to the new GBM BO mapping interface by Rob Herring, we can make
> a generic framework for other drivers.
So big fan of this idea (beats my earlier plan to add libdrm_freedreno
support for piglit dmabuf stuff, which fortunately I never got around
to ;-))
Not a super big expert on this piglit code, but patch looks
reasonable. So I guess you can call that a r-b ;-)
BR,
-R
> ---
> CMakeLists.txt | 7 +-
> .../util/piglit-framework-gl/piglit_drm_dma_buf.c | 101 +++++++++++++++++++++
> 2 files changed, 107 insertions(+), 1 deletion(-)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index 8e2abbad6730..55cfc4541df0 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -141,6 +141,10 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
> if(GBM_FOUND)
> set(PIGLIT_HAS_GBM True)
> add_definitions(-DPIGLIT_HAS_GBM)
> + if (GBM_VERSION VERSION_GREATER "11.1")
> + set(PIGLIT_HAS_GBM_BO_MAP True)
> + add_definitions(-DPIGLIT_HAS_GBM_BO_MAP)
> + endif()
> endif(GBM_FOUND)
>
> pkg_check_modules(WAYLAND QUIET wayland-client wayland-egl)
> @@ -177,7 +181,8 @@ ENDIF()
> # drm-prime arrived in that version.
> #
> if(LIBDRM_FOUND AND XCB_DRI2_FOUND AND
> - (LIBDRM_INTEL_VERSION VERSION_GREATER "2.4.37"))
> + ((LIBDRM_INTEL_VERSION VERSION_GREATER "2.4.37") OR
> + PIGLIT_HAS_GBM_BO_MAP))
> set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID true)
> else()
> set(PIGLIT_BUILD_DMA_BUF_TESTS_IS_VALID false)
> 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 479592c3a4db..3d1dc2422b30 100644
> --- a/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
> +++ b/tests/util/piglit-framework-gl/piglit_drm_dma_buf.c
> @@ -26,6 +26,9 @@
> #ifdef HAVE_LIBDRM_INTEL
> #include <libdrm/intel_bufmgr.h>
> #endif
> +#ifdef PIGLIT_HAS_GBM_BO_MAP
> +#include <gbm.h>
> +#endif
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> @@ -182,6 +185,97 @@ piglit_intel_buf_destroy(struct piglit_dma_buf *buf)
> }
> #endif /* HAVE_LIBDRM_INTEL */
>
> +#ifdef PIGLIT_HAS_GBM_BO_MAP
> +static struct gbm_device *
> +piglit_gbm_get(void)
> +{
> + const struct piglit_drm_driver *drv = piglit_drm_get_driver();
> + static struct gbm_device *gbm = NULL;
> +
> + if (gbm)
> + return gbm;
> +
> + gbm = gbm_create_device(drv->fd);
> +
> + return gbm;
> +}
> +
> +static bool
> +piglit_gbm_buf_create(unsigned w, unsigned h, unsigned cpp,
> + const unsigned char *src_data, unsigned src_stride,
> + struct piglit_dma_buf *buf)
> +{
> + unsigned i;
> + struct gbm_bo *bo;
> + uint32_t dst_stride;
> + struct gbm_device *gbm = piglit_gbm_get();
> + void *dst_data;
> + void *map_data = NULL;
> + enum gbm_bo_format format;
> +
> + if (!gbm || h % 2)
> + return false;
> +
> + /* It would be nice if we took in a fourcc instead of a cpp */
> + switch (cpp) {
> + case 1:
> + format = GBM_FORMAT_C8;
> + break;
> + case 4:
> + format = GBM_BO_FORMAT_ARGB8888;
> + break;
> + default:
> + fprintf(stderr, "Unknown cpp %d\n", cpp);
> + return false;
> + }
> +
> + bo = gbm_bo_create(gbm, w, h, format, GBM_BO_USE_RENDERING);
> + if (!bo)
> + return false;
> +
> + dst_data = gbm_bo_map(bo, 0, 0, w, 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;
> + }
> +
> + for (i = 0; i < h; ++i) {
> + memcpy((char *)dst_data + i * dst_stride,
> + src_data + i * src_stride,
> + w * cpp);
> + }
> + gbm_bo_unmap(bo, map_data);
> +
> + buf->w = w;
> + buf->h = h;
> + buf->stride = dst_stride;
> + buf->fd = 0;
> + buf->priv = bo;
> +
> + return true;
> +}
> +
> +static bool
> +piglit_gbm_buf_export(struct piglit_dma_buf *buf)
> +{
> + struct gbm_bo *bo = buf->priv;
> +
> + buf->fd = gbm_bo_get_fd(bo);
> +
> + return buf->fd >= 0;
> +}
> +
> +static void
> +piglit_gbm_buf_destroy(struct piglit_dma_buf *buf)
> +{
> + struct gbm_bo *bo = buf->priv;
> +
> + gbm_bo_destroy(bo);
> +}
> +#endif /* PIGLIT_HAS_GBM_BO_MAP */
> +
> static const struct piglit_drm_driver *
> piglit_drm_get_driver(void)
> {
> @@ -228,6 +322,13 @@ piglit_drm_get_driver(void)
> drv.destroy = piglit_intel_buf_destroy;
> }
> #endif
> +#ifdef PIGLIT_HAS_GBM_BO_MAP
> + else if (true) {
> + drv.create = piglit_gbm_buf_create;
> + drv.export = piglit_gbm_buf_export;
> + drv.destroy = piglit_gbm_buf_destroy;
> + }
> +#endif
> else {
> fprintf(stderr, "error: unrecognized DRM driver name %s\n",
> version->name);
> --
> 2.8.1
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list