summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2016-07-25 11:25:20 -0700
committerEric Anholt <eric@anholt.net>2016-08-18 16:21:35 -0700
commita1efbfb94d591c8e5fc3293dfe84b8ee93c5332b (patch)
tree3abb858f15dd6ce0ea093f1aaf99a25455db54ec
parentad04e3c87d197faa06b7bf1fcfb325a5f1e51149 (diff)
piglit-framework-gl: Use GBM on non-intel for dmabuf creation.
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. Reviewed-by: Rob Clark <robdclark@gmail.com>
-rw-r--r--CMakeLists.txt7
-rw-r--r--tests/util/piglit-framework-gl/piglit_drm_dma_buf.c101
2 files changed, 107 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e2abbad6..55cfc4541 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 479592c3a..3d1dc2422 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);