[Mesa-dev] [PATCH] gallium: add Tegra renderonly support
Alexandre Courbot
acourbot at nvidia.com
Fri Jan 13 07:47:41 UTC 2017
From: Christian Gmeiner <christian.gmeiner at gmail.com>
Based on the same model as the IMX driver, opens a Nouveau render device
in order to transparently provide acceleration on Tegra.
Signed-off-by: Christian Gmeiner <christian.gmeiner at gmail.com>
[acourbot at nvidia.com: port to latest branch, minor improvements]
Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>
---
configure.ac | 9 ++-
src/gallium/Makefile.am | 4 ++
.../auxiliary/pipe-loader/pipe_loader_drm.c | 5 ++
src/gallium/auxiliary/target-helpers/drm_helper.h | 22 +++++++
.../auxiliary/target-helpers/drm_helper_public.h | 3 +
src/gallium/drivers/nouveau/nouveau_buffer.c | 3 +
src/gallium/drivers/nouveau/nouveau_buffer.h | 2 +
src/gallium/drivers/nouveau/nouveau_screen.h | 3 +
src/gallium/drivers/nouveau/nv50/nv50_miptree.c | 3 +
src/gallium/drivers/nouveau/nvc0/nvc0_resource.c | 18 +++++-
src/gallium/drivers/tegra/Automake.inc | 9 +++
src/gallium/drivers/tegra/Makefile.am | 9 +++
src/gallium/targets/dri/Makefile.am | 2 +
src/gallium/targets/dri/target.c | 11 ++++
.../winsys/nouveau/drm/nouveau_drm_public.h | 2 +
.../winsys/nouveau/drm/nouveau_drm_winsys.c | 10 +++
src/gallium/winsys/tegra/drm/Android.mk | 33 ++++++++++
src/gallium/winsys/tegra/drm/Makefile.am | 34 ++++++++++
src/gallium/winsys/tegra/drm/Makefile.sources | 3 +
src/gallium/winsys/tegra/drm/tegra_drm_public.h | 8 +++
src/gallium/winsys/tegra/drm/tegra_drm_winsys.c | 74 ++++++++++++++++++++++
src/mesa/drivers/dri/nouveau/nouveau_screen.h | 1 +
22 files changed, 265 insertions(+), 3 deletions(-)
create mode 100644 src/gallium/drivers/tegra/Automake.inc
create mode 100644 src/gallium/drivers/tegra/Makefile.am
create mode 100644 src/gallium/winsys/tegra/drm/Android.mk
create mode 100644 src/gallium/winsys/tegra/drm/Makefile.am
create mode 100644 src/gallium/winsys/tegra/drm/Makefile.sources
create mode 100644 src/gallium/winsys/tegra/drm/tegra_drm_public.h
create mode 100644 src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
diff --git a/configure.ac b/configure.ac
index bc92fb5535c1..4b90b65805e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1234,7 +1234,7 @@ GALLIUM_DRIVERS_DEFAULT="r300,r600,svga,swrast"
AC_ARG_WITH([gallium-drivers],
[AS_HELP_STRING([--with-gallium-drivers@<:@=DIRS...@:>@],
[comma delimited Gallium drivers list, e.g.
- "i915,ilo,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,etnaviv,imx"
+ "i915,ilo,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4,virgl,etnaviv,imx,tegra"
@<:@default=r300,r600,svga,swrast@:>@])],
[with_gallium_drivers="$withval"],
[with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
@@ -2559,6 +2559,10 @@ if test -n "$with_gallium_drivers"; then
require_libdrm "virgl"
require_basic_egl "virgl"
;;
+ xtegra)
+ HAVE_GALLIUM_TEGRA=yes
+ require_libdrm "tegra"
+ ;;
*)
AC_MSG_ERROR([Unknown Gallium driver: $driver])
;;
@@ -2643,6 +2647,7 @@ AM_CONDITIONAL(HAVE_GALLIUM_NOUVEAU, test "x$HAVE_GALLIUM_NOUVEAU" = xyes)
AM_CONDITIONAL(HAVE_GALLIUM_FREEDRENO, test "x$HAVE_GALLIUM_FREEDRENO" = xyes)
AM_CONDITIONAL(HAVE_GALLIUM_ETNAVIV, test "x$HAVE_GALLIUM_ETNAVIV" = xyes)
AM_CONDITIONAL(HAVE_GALLIUM_IMX, test "x$HAVE_GALLIUM_IMX" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_TEGRA, test "x$HAVE_GALLIUM_TEGRA" = xyes)
AM_CONDITIONAL(HAVE_GALLIUM_SOFTPIPE, test "x$HAVE_GALLIUM_SOFTPIPE" = xyes)
AM_CONDITIONAL(HAVE_GALLIUM_LLVMPIPE, test "x$HAVE_GALLIUM_LLVMPIPE" = xyes)
AM_CONDITIONAL(HAVE_GALLIUM_SWR, test "x$HAVE_GALLIUM_SWR" = xyes)
@@ -2800,6 +2805,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/drivers/imx/Makefile
src/gallium/drivers/vc4/Makefile
src/gallium/drivers/virgl/Makefile
+ src/gallium/drivers/tegra/Makefile
src/gallium/state_trackers/clover/Makefile
src/gallium/state_trackers/dri/Makefile
src/gallium/state_trackers/glx/xlib/Makefile
@@ -2844,6 +2850,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/winsys/vc4/drm/Makefile
src/gallium/winsys/virgl/drm/Makefile
src/gallium/winsys/virgl/vtest/Makefile
+ src/gallium/winsys/tegra/drm/Makefile
src/gbm/Makefile
src/gbm/main/gbm.pc
src/glx/Makefile
diff --git a/src/gallium/Makefile.am b/src/gallium/Makefile.am
index f910f3187eb4..0f887d220d5b 100644
--- a/src/gallium/Makefile.am
+++ b/src/gallium/Makefile.am
@@ -100,6 +100,10 @@ if HAVE_GALLIUM_VIRGL
SUBDIRS += drivers/virgl winsys/virgl/drm winsys/virgl/vtest
endif
+if HAVE_GALLIUM_TEGRA
+SUBDIRS += drivers/tegra winsys/tegra/drm
+endif
+
## the sw winsys'
SUBDIRS += winsys/sw/null
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index 6c89fe5ead1b..ff1166c2d0fc 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -163,6 +163,11 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
.driver_name = "imx-drm",
.create_screen = pipe_imx_drm_create_screen,
.configuration = configuration_query,
+ },
+ {
+ .driver_name = "tegra",
+ .create_screen = pipe_tegra_create_screen,
+ .configuration = configuration_query,
}
};
#endif
diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h b/src/gallium/auxiliary/target-helpers/drm_helper.h
index f847b17dd685..22932d3186f7 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
@@ -312,5 +312,27 @@ pipe_imx_drm_create_screen(int fd)
#endif
+#ifdef GALLIUM_TEGRA
+#include "tegra/drm/tegra_drm_public.h"
+
+struct pipe_screen *
+pipe_tegra_create_screen(int fd)
+{
+ struct pipe_screen *screen;
+
+ screen = tegra_drm_screen_create(fd);
+ return screen ? debug_screen_wrap(screen) : NULL;
+}
+
+#else
+
+struct pipe_screen *
+pipe_tegra_create_screen(int fd)
+{
+ fprintf(stderr, "tegra: driver missing\n");
+ return NULL;
+}
+
+#endif
#endif /* DRM_HELPER_H */
diff --git a/src/gallium/auxiliary/target-helpers/drm_helper_public.h b/src/gallium/auxiliary/target-helpers/drm_helper_public.h
index bc12b2155e45..5525bdf74973 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper_public.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper_public.h
@@ -40,4 +40,7 @@ pipe_etna_create_screen(int fd);
struct pipe_screen *
pipe_imx_drm_create_screen(int fd);
+struct pipe_screen *
+pipe_tegra_create_screen(int fd);
+
#endif /* _DRM_HELPER_PUBLIC_H */
diff --git a/src/gallium/drivers/nouveau/nouveau_buffer.c b/src/gallium/drivers/nouveau/nouveau_buffer.c
index 17052b26e9c8..95dcaad94396 100644
--- a/src/gallium/drivers/nouveau/nouveau_buffer.c
+++ b/src/gallium/drivers/nouveau/nouveau_buffer.c
@@ -128,6 +128,9 @@ nouveau_buffer_destroy(struct pipe_screen *pscreen,
util_range_destroy(&res->valid_buffer_range);
+ if (res->scanout)
+ renderonly_scanout_destroy(res->scanout);
+
FREE(res);
NOUVEAU_DRV_STAT(nouveau_screen(pscreen), buf_obj_current_count, -1);
diff --git a/src/gallium/drivers/nouveau/nouveau_buffer.h b/src/gallium/drivers/nouveau/nouveau_buffer.h
index 3a33fae9ce2f..c01fda4f3a78 100644
--- a/src/gallium/drivers/nouveau/nouveau_buffer.h
+++ b/src/gallium/drivers/nouveau/nouveau_buffer.h
@@ -50,6 +50,8 @@ struct nv04_resource {
/* buffer range that has been initialized */
struct util_range valid_buffer_range;
+
+ struct renderonly_scanout *scanout;
};
void
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h
index 28c4760af20c..f2c9ec14aa4f 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.h
+++ b/src/gallium/drivers/nouveau/nouveau_screen.h
@@ -2,6 +2,7 @@
#define __NOUVEAU_SCREEN_H__
#include "pipe/p_screen.h"
+#include "renderonly/renderonly.h"
#include "util/u_memory.h"
#ifdef DEBUG
@@ -59,6 +60,8 @@ struct nouveau_screen {
unsigned profiles_present;
} firmware_info;
+ struct renderonly ro;
+
#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
union {
uint64_t v[29];
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_miptree.c b/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
index f2e304fde621..29e95a6f9a89 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
@@ -189,6 +189,9 @@ nv50_miptree_get_handle(struct pipe_screen *pscreen,
if (!mt || !mt->base.bo)
return false;
+ if (renderonly_get_handle(mt->base.scanout, whandle))
+ return TRUE;
+
stride = mt->level[0].pitch;
return nouveau_screen_bo_get_handle(pscreen,
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
index 9bafe3d835db..ad2291be23dc 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c
@@ -8,12 +8,26 @@ static struct pipe_resource *
nvc0_resource_create(struct pipe_screen *screen,
const struct pipe_resource *templ)
{
+ struct nouveau_screen *scr = nouveau_screen(screen);
+ struct pipe_resource *pres;
+
switch (templ->target) {
case PIPE_BUFFER:
- return nouveau_buffer_create(screen, templ);
+ pres = nouveau_buffer_create(screen, templ);
+ break;
default:
- return nvc0_miptree_create(screen, templ);
+ pres = nvc0_miptree_create(screen, templ);
+ break;
}
+
+ if (pres) {
+ struct nv04_resource *res = nv04_resource(pres);
+
+ if (templ->bind & PIPE_BIND_SCANOUT)
+ res->scanout = renderonly_scanout_for_resource(pres, &scr->ro);
+ }
+
+ return pres;
}
static struct pipe_resource *
diff --git a/src/gallium/drivers/tegra/Automake.inc b/src/gallium/drivers/tegra/Automake.inc
new file mode 100644
index 000000000000..89e0441f169c
--- /dev/null
+++ b/src/gallium/drivers/tegra/Automake.inc
@@ -0,0 +1,9 @@
+if HAVE_GALLIUM_TEGRA
+
+TARGET_DRIVERS += tegra
+TARGET_CPPFLAGS += -DGALLIUM_TEGRA
+TARGET_LIB_DEPS += \
+ $(top_builddir)/src/gallium/winsys/tegra/drm/libtegradrm.la \
+ $(LIBDRM_LIBS)
+
+endif
diff --git a/src/gallium/drivers/tegra/Makefile.am b/src/gallium/drivers/tegra/Makefile.am
new file mode 100644
index 000000000000..30f46893f4a3
--- /dev/null
+++ b/src/gallium/drivers/tegra/Makefile.am
@@ -0,0 +1,9 @@
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CPPFLAGS = \
+ $(GALLIUM_CFLAGS) \
+ $(TEGRA_CFLAGS)
+
+noinst_LTLIBRARIES = libtegra.la
+
+libtegra_la_SOURCES =
diff --git a/src/gallium/targets/dri/Makefile.am b/src/gallium/targets/dri/Makefile.am
index bca747faa4ae..4236da107482 100644
--- a/src/gallium/targets/dri/Makefile.am
+++ b/src/gallium/targets/dri/Makefile.am
@@ -94,6 +94,8 @@ include $(top_srcdir)/src/gallium/drivers/virgl/Automake.inc
include $(top_srcdir)/src/gallium/drivers/etnaviv/Automake.inc
include $(top_srcdir)/src/gallium/drivers/imx/Automake.inc
+include $(top_srcdir)/src/gallium/drivers/tegra/Automake.inc
+
include $(top_srcdir)/src/gallium/drivers/softpipe/Automake.inc
include $(top_srcdir)/src/gallium/drivers/llvmpipe/Automake.inc
include $(top_srcdir)/src/gallium/drivers/swr/Automake.inc
diff --git a/src/gallium/targets/dri/target.c b/src/gallium/targets/dri/target.c
index 441a27ff6375..5e4db62a7d7d 100644
--- a/src/gallium/targets/dri/target.c
+++ b/src/gallium/targets/dri/target.c
@@ -181,3 +181,14 @@ PUBLIC const __DRIextension **__driDriverGetExtensions_etnaviv(void)
return galliumdrm_driver_extensions;
}
#endif
+
+#if defined(GALLIUM_TEGRA)
+
+const __DRIextension **__driDriverGetExtensions_tegra(void);
+
+PUBLIC const __DRIextension **__driDriverGetExtensions_tegra(void)
+{
+ globalDriverAPI = &galliumdrm_driver_api;
+ return galliumdrm_driver_extensions;
+}
+#endif
diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h b/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h
index 67b7c4429df6..455ea770c6b5 100644
--- a/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h
+++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h
@@ -3,7 +3,9 @@
#define __NOUVEAU_DRM_PUBLIC_H__
struct pipe_screen;
+struct renderonly;
struct pipe_screen *nouveau_drm_screen_create(int drmFD);
+struct pipe_screen *nouveau_drm_screen_create_renderonly(int fd, struct renderonly *ro);
#endif
diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
index cc9dfa7f7645..dd9c8f034c0a 100644
--- a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
+++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c
@@ -157,3 +157,13 @@ err:
pipe_mutex_unlock(nouveau_screen_mutex);
return NULL;
}
+
+struct pipe_screen *nouveau_drm_screen_create_renderonly(int fd, struct renderonly *ro)
+{
+ struct nouveau_screen *screen = nouveau_drm_screen_create(fd);
+
+ if (screen)
+ screen->ro = *ro;
+
+ return screen;
+}
diff --git a/src/gallium/winsys/tegra/drm/Android.mk b/src/gallium/winsys/tegra/drm/Android.mk
new file mode 100644
index 000000000000..a48dca48d52c
--- /dev/null
+++ b/src/gallium/winsys/tegra/drm/Android.mk
@@ -0,0 +1,33 @@
+# Copyright (C) 2014 Emil Velikov <emil.l.velikov at gmail.com>
+#
+# 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 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.
+
+LOCAL_PATH := $(call my-dir)
+
+# get C_SOURCES
+include $(LOCAL_PATH)/Makefile.sources
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(C_SOURCES)
+
+LOCAL_MODULE := libmesa_winsys_tegra
+
+include $(GALLIUM_COMMON_MK)
+include $(BUILD_STATIC_LIBRARY)
diff --git a/src/gallium/winsys/tegra/drm/Makefile.am b/src/gallium/winsys/tegra/drm/Makefile.am
new file mode 100644
index 000000000000..4223e8d686af
--- /dev/null
+++ b/src/gallium/winsys/tegra/drm/Makefile.am
@@ -0,0 +1,34 @@
+# Copyright © 2012 Intel Corporation
+#
+# 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 Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = \
+ -I$(top_srcdir)/src/gallium/drivers \
+ -I$(top_srcdir)/src/gallium/winsys \
+ $(GALLIUM_WINSYS_CFLAGS) \
+ $(LIBDRM_CFLAGS)
+
+noinst_LTLIBRARIES = libtegradrm.la
+
+libtegradrm_la_SOURCES = $(C_SOURCES)
diff --git a/src/gallium/winsys/tegra/drm/Makefile.sources b/src/gallium/winsys/tegra/drm/Makefile.sources
new file mode 100644
index 000000000000..29a0edc9c432
--- /dev/null
+++ b/src/gallium/winsys/tegra/drm/Makefile.sources
@@ -0,0 +1,3 @@
+C_SOURCES := \
+ tegra_drm_public.h \
+ tegra_drm_winsys.c
diff --git a/src/gallium/winsys/tegra/drm/tegra_drm_public.h b/src/gallium/winsys/tegra/drm/tegra_drm_public.h
new file mode 100644
index 000000000000..813268f9d8ba
--- /dev/null
+++ b/src/gallium/winsys/tegra/drm/tegra_drm_public.h
@@ -0,0 +1,8 @@
+#ifndef __TEGRA_DRM_PUBLIC_H__
+#define __TEGRA_DRM_PUBLIC_H__
+
+struct pipe_screen;
+
+struct pipe_screen *tegra_drm_screen_create(int drmFD);
+
+#endif /* __TEGRA_DRM_PUBLIC_H__ */
diff --git a/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
new file mode 100644
index 000000000000..af4171ace8db
--- /dev/null
+++ b/src/gallium/winsys/tegra/drm/tegra_drm_winsys.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner at gmail.com>
+ *
+ * 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.
+ *
+ * Authors:
+ * Christian Gmeiner <christian.gmeiner at gmail.com>
+ * Alexandre Courbot <acourbot at nvidia.com>
+ */
+
+#include "tegra_drm_public.h"
+#include "nouveau/drm/nouveau_drm_public.h"
+#include "renderonly/renderonly.h"
+
+#include <libdrm/tegra_drm.h>
+#include <xf86drm.h>
+
+static struct renderonly_scanout *
+tegra_create_with_tiling_for_resource(struct pipe_resource *rsc,
+ struct renderonly *ro)
+{
+ struct renderonly_scanout *scanout;
+
+ scanout = renderonly_create_gpu_import_for_resource(rsc, ro);
+ if (!scanout)
+ return NULL;
+
+ struct drm_tegra_gem_set_tiling args = {
+ .handle = scanout->handle,
+ .mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK,
+ .value = 4
+ };
+
+ int ret = drmIoctl(ro->kms_fd, DRM_IOCTL_TEGRA_GEM_SET_TILING, &args);
+ if (ret)
+ return NULL;
+
+ return scanout;
+}
+
+struct pipe_screen *tegra_drm_screen_create(int fd)
+{
+ struct renderonly ro = {
+ .create_for_resource = tegra_create_with_tiling_for_resource,
+ .kms_fd = fd,
+ .gpu_fd = drmOpenWithType("nouveau", NULL, DRM_NODE_RENDER),
+ };
+
+ if (ro.gpu_fd < 0)
+ return NULL;
+
+ struct pipe_screen *screen = nouveau_drm_screen_create_renderonly(ro.gpu_fd, &ro);
+ if (!screen)
+ drmClose(ro.gpu_fd);
+
+ return screen;
+};
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_screen.h b/src/mesa/drivers/dri/nouveau/nouveau_screen.h
index e3c192802d49..51ad4275dda5 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_screen.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_screen.h
@@ -36,6 +36,7 @@ struct nouveau_screen {
struct nouveau_drm *drm;
struct nouveau_device *device;
const struct nouveau_driver *driver;
+ struct renderonly *ro;
};
#endif
--
2.11.0
More information about the mesa-dev
mailing list