Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for nvenc and accel_assist #3320

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ xrdp/xrdp.ini
xrdp_configure_options.h
xrdpapi/xrdp-xrdpapi-simple
.vscode/*
xrdp_accel_assist/xrdp-accel-assist
9 changes: 8 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ else
ULALACADIR =
endif

if XRDP_ACCEL
ACCELDIR = xrdp_accel_assist
else
ACCELDIR =
endif

# This should not be dictionary order but build order
SUBDIRS = \
third_party \
Expand All @@ -70,7 +76,8 @@ SUBDIRS = \
$(XRDPVRDIR) \
$(ULALACADIR) \
tests \
tools
tools \
$(ACCELDIR)

distclean-local:
-rm -f xrdp_configure_options.h
4 changes: 4 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ AM_CPPFLAGS = \
-DXRDP_PID_PATH=\"${localstatedir}/run\" \
-DXRDP_LOG_PATH=\"${localstatedir}/log\"

if XRDP_NVENC
AM_CPPFLAGS += -DXRDP_NVENC
endif

# -no-suppress is an automake-specific flag which is needed
# to prevent us missing compiler errors in some circumstances
# (see https://github.com/neutrinolabs/xrdp/pull/1843 )
Expand Down
63 changes: 63 additions & 0 deletions common/os_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ g_init(const char *app_name)

WSAStartup(2, &wsadata);
#endif
#if defined(XRDP_NVENC)
if (g_strcmp(app_name, "xrdp-sesman") == 0)
{
/* call cuInit() to initalize the nvidia drivers */
/* TODO create an issue on nvidia forums to figure out why we need to
* do this */
if (g_fork() == 0)
{
typedef int (*cu_init_proc)(int flags);
cu_init_proc cu_init;
long lib;
char cuda_lib_name[] = "libcuda.so";
char cuda_func_name[] = "cuInit";

lib = g_load_library(cuda_lib_name);
if (lib != 0)
{
cu_init = (cu_init_proc)
g_get_proc_address(lib, cuda_func_name);
if (cu_init != NULL)
{
cu_init(0);
}
}
log_end();
g_deinit();
g_exit(0);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding error logging if this doesn't work, for triaging user issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't t think the log ing system is initialized at this point. Can we still log?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're quite right. Calling LOG() won't work.

Two possible solutions:-

  1. Log errors to stderr in this function. This isn't ideal, but it will at least get picked up by the journal on systemd-based systems.
  2. Use a separate function for this purpose (g_cu_init()?) called explicitly from sesman after logging has started. We can remove it if you ever get a better answer as to why this function is required.

#endif
}

/*****************************************************************************/
Expand Down Expand Up @@ -1530,6 +1560,39 @@ g_sck_send_fd_set(int sck, const void *ptr, unsigned int len,
return rv;
}

/******************************************************************************/
int
g_alloc_shm_map_fd(void **addr, int *fd, size_t size)
{
int lfd = -1;
void *laddr;
char name[128];
static unsigned int autoinc;

snprintf(name, 128, "/%8.8X%8.8X", getpid(), autoinc++);
lfd = shm_open(name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (lfd == -1)
{
return 1;
}
shm_unlink(name);
if (ftruncate(lfd, size) == -1)
{
close(lfd);
return 2;
}
/* map fd to address space */
laddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, lfd, 0);
if (laddr == MAP_FAILED)
{
close(lfd);
return 3;
}
*addr = laddr;
*fd = lfd;
return 0;
}

/*****************************************************************************/
/* returns boolean */
int
Expand Down
1 change: 1 addition & 0 deletions common/os_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int g_sck_recv_fd_set(int sck, void *ptr, unsigned int len,
*/
int g_sck_send_fd_set(int sck, const void *ptr, unsigned int len,
int fds[], unsigned int fdcount);
int g_alloc_shm_map_fd(void **addr, int *fd, size_t size);
int g_sck_last_error_would_block(int sck);
int g_sck_socket_ok(int sck);
/**
Expand Down
2 changes: 2 additions & 0 deletions common/trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ enum xrdp_source
XRDP_SOURCE_SESMAN,
XRDP_SOURCE_CHANSRV,
XRDP_SOURCE_MOD,
XORGXRDP_SOURCE_XORG,
XORGXRDP_SOURCE_XRDP,

XRDP_SOURCE_MAX_COUNT
};
Expand Down
31 changes: 31 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ AC_ARG_ENABLE(openh264, AS_HELP_STRING([--enable-openh264],
[Use Cisco OpenH264 library (default: no)]),
[], [enable_openh264=no])
AM_CONDITIONAL(XRDP_OPENH264, [test x$enable_openh264 = xyes])
AC_ARG_ENABLE(nvenc, AS_HELP_STRING([--enable-nvenc],
[Use nvenc library (default: no), env vars XRDP_NVENC_CFLAGS and
XRDP_NVENC_LIBS should be set if used]),
[], [enable_nvenc=no])
AM_CONDITIONAL(XRDP_NVENC, [test x$enable_nvenc = xyes])
AC_ARG_ENABLE(accel, AS_HELP_STRING([--enable-accel],
[Build xrdp_accel_assist (default: no, auto set if --enable-nvenc)]),
[], [enable_accel=no])
# AM_CONDITIONAL(XRDP_ACCEL, [test x$enable_accel = xyes]) later in this file
AC_ARG_ENABLE(painter, AS_HELP_STRING([--disable-painter],
[Do not use included painter library (default: no)]),
[], [enable_painter=yes])
Expand Down Expand Up @@ -263,6 +272,9 @@ AC_CHECK_HEADER([security/_pam_types.h],
AC_CHECK_HEADER([security/pam_constants.h],
[AC_DEFINE([HAVE_PAM_CONSTANTS_H], 1, [Using OpenPAM], [])])

# shm_open may not be in the C library
AC_SEARCH_LIBS([shm_open], [rt])

# Find imlib2
case "$with_imlib2" in
'' | no) AC_MSG_NOTICE([imlib2 will not be supported])
Expand Down Expand Up @@ -499,6 +511,21 @@ AS_IF( [test "x$enable_x264" = "xyes"] , [PKG_CHECK_MODULES(XRDP_X264, x264 >= 0

AS_IF( [test "x$enable_openh264" = "xyes"] , [PKG_CHECK_MODULES(XRDP_OPENH264, openh264 >= 2.0.0)] )

if test "x$enable_nvenc" = "xyes"
then
enable_accel=$enable_nvenc
if test ! -z "$XRDP_NVENC_CFLAGS"
then
AC_SUBST(XRDP_NVENC_CFLAGS, ["$XRDP_NVENC_CFLAGS"])
fi
if test ! -z "$XRDP_NVENC_LIBS"
then
AC_SUBST(XRDP_NVENC_LIBS, ["$XRDP_NVENC_LIBS"])
fi
fi

AM_CONDITIONAL(XRDP_ACCEL, [test x$enable_accel = xyes])

# checking for TurboJPEG
if test "x$enable_tjpeg" = "xyes"
then
Expand Down Expand Up @@ -665,6 +692,8 @@ AC_CONFIG_FILES([
xup/Makefile
third_party/Makefile
third_party/tomlc99/Makefile
xrdp_accel_assist/Makefile

])

AC_REQUIRE_AUX_FILE([tap-driver.sh])
Expand All @@ -681,6 +710,8 @@ echo " turbo jpeg $enable_tjpeg"
echo " rfxcodec $enable_rfxcodec"
echo " x264 $enable_x264"
echo " openh264 $enable_openh264"
echo " nvenc $enable_nvenc"
echo " accel $enable_accel"
echo " painter $enable_painter"
echo " pixman $enable_pixman"
echo " fuse $enable_fuse"
Expand Down
4 changes: 4 additions & 0 deletions sesman/sesman.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ param=Xorg
; Leave the rest parameters as-is unless you understand what will happen.
param=-config
param=xrdp/xorg.conf
;param=xrdp/xorg_nvidia.conf
;param=xrdp/xorg_nvidia_grid.conf
param=-noreset
param=-nolisten
param=tcp
Expand Down Expand Up @@ -218,3 +220,5 @@ EnableSyslog=true

[SessionVariables]
PULSE_SCRIPT=@sesmansysconfdir@/pulse/default.pa
;XRDP_USE_ACCEL_ASSIST=1
;XRDP_NVIDIA_GRID=1
34 changes: 34 additions & 0 deletions xrdp_accel_assist/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/common

EXTRA_DIST = xrdp_accel_assist_shaders.c

XRDP_EXTRA_LIBS =
XRDP_EXTRA_SOURCES =

if XRDP_NVENC
AM_CPPFLAGS += -DXRDP_NVENC
AM_CPPFLAGS += $(XRDP_NVENC_CFLAGS)
XRDP_EXTRA_LIBS += $(XRDP_NVENC_LIBS)
XRDP_EXTRA_SOURCES += xrdp_accel_assist_nvenc.c xrdp_accel_assist_nvenc.h encoder_headers/nvEncodeAPI_11_1.h
endif

pkglibexec_PROGRAMS = \
xrdp-accel-assist

xrdp_accel_assist_SOURCES = \
xrdp_accel_assist.c \
xrdp_accel_assist.h \
xrdp_accel_assist_x11.c \
xrdp_accel_assist_x11.h \
xrdp_accel_assist_egl.c \
xrdp_accel_assist_egl.h \
xrdp_accel_assist_glx.c \
xrdp_accel_assist_glx.h \
$(XRDP_EXTRA_SOURCES)

xrdp_accel_assist_LDADD = \
$(top_builddir)/common/libcommon.la \
$(XRDP_EXTRA_LIBS) \
-lX11 -lepoxy

Loading
Loading