From 3c54d70ef9ddc3a6b03f6e3af4cf0329f7e2c8d4 Mon Sep 17 00:00:00 2001 From: Pavel Artsishevsky Date: Nov 15 2022 20:33:59 +0000 Subject: Initial commit --- diff --git a/0001-primus-needs-this-variable-workaround-for-libglvnd-e.patch b/0001-primus-needs-this-variable-workaround-for-libglvnd-e.patch new file mode 100644 index 0000000..1fba1e3 --- /dev/null +++ b/0001-primus-needs-this-variable-workaround-for-libglvnd-e.patch @@ -0,0 +1,26 @@ +From 0e378a469e25e6fe1cb4434ebd836c98cb3297b5 Mon Sep 17 00:00:00 2001 +From: Gary Gatling +Date: Thu, 2 Mar 2017 14:50:47 -0500 +Subject: [PATCH] primus needs this variable workaround for libglvnd enabled + mesa + +--- + primusrun | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/primusrun b/primusrun +index 81f40f0..d53572d 100755 +--- a/primusrun ++++ b/primusrun +@@ -1,5 +1,8 @@ + #!/bin/bash + ++# primus needs this variable workaround for libglvnd enabled mesa ++export __GLVND_DISALLOW_PATCHING=1 ++ + # Readback-display synchronization method + # 0: no sync, 1: D lags behind one frame, 2: fully synced + # export PRIMUS_SYNC=${PRIMUS_SYNC:-0} +-- +2.14.3 + diff --git a/0002-Use-Fedora-specific-library-paths.patch b/0002-Use-Fedora-specific-library-paths.patch new file mode 100644 index 0000000..e68cadd --- /dev/null +++ b/0002-Use-Fedora-specific-library-paths.patch @@ -0,0 +1,25 @@ +From a8b73cb281de09f4f6e5b1cef0d93b654c68614b Mon Sep 17 00:00:00 2001 +From: Xiao-Long Chen +Date: Tue, 11 Dec 2012 15:31:39 -0500 +Subject: [PATCH] Use Fedora-specific library paths + +--- + primusrun | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/primusrun b/primusrun +index 81e2dc0..81f40f0 100755 +--- a/primusrun ++++ b/primusrun +@@ -26,7 +26,7 @@ + # export PRIMUS_libGLd=${PRIMUS_libGLd:-'/usr/$LIB/libGL.so.1'} + + # Directory containing primus libGL +-PRIMUS_libGL=${PRIMUS_libGL:-$(dirname `readlink -ne $0`)/'$LIB'} ++PRIMUS_libGL=${PRIMUS_libGL:-/usr/'$LIB'/primus} + + # On some distributions, e.g. on Ubuntu, libnvidia-tls.so is not available + # in default search paths. Add its path manually after the primus library +-- +2.14.3 + diff --git a/primus-source.spec b/primus-source.spec new file mode 100644 index 0000000..3cebaef --- /dev/null +++ b/primus-source.spec @@ -0,0 +1,112 @@ +%global commit d1afbf6fce2778c0751eddf19db9882e04f18bfd +%global shortcommit %(c=%{commit}; echo ${c:0:7}) + +%global desc \ +Primus is a shared library that provides OpenGL and GLX APIs and implements\ +low-overhead local-only client-side OpenGL offloading via GLX forking, similar\ +to VirtualGL. It intercepts GLX calls and redirects GL rendering to a secondary\ +X display, presumably driven by a faster GPU. On swapping buffers, rendered\ +contents are read back using a PBO and copied onto the drawable it was supposed\ +to be rendered on in the first place. + + +Name: primus-source +Version: 0.2 +Release: 3.git%{shortcommit}%{?dist} +Summary: Faster OpenGL offloading for Bumblebee + +License: ISC +URL: https://github.com/amonakov/primus +Source0: https://github.com/amonakov/primus/archive/%{commit}/primus-%{shortcommit}.tar.gz +# From Arch Linux +Patch0: register_cleanup.patch +# https://github.com/amonakov/primus/pull/195 +Patch1: 0001-primus-needs-this-variable-workaround-for-libglvnd-e.patch +# Fix primusrun paths +Patch10: 0002-Use-Fedora-specific-library-paths.patch + +BuildRequires: gcc-c++ +BuildRequires: libX11-devel +BuildRequires: mesa-libGL-devel + +%description +%{desc} + + +# Hack to allow primus to be noarch and primus-libs to be multilib +%package -n primus +Summary: Faster OpenGL offloading for Bumblebee + +Requires: primus-libs = %{version}-%{release} +Requires: bumblebee + +BuildArch: noarch + +%description -n primus +%{desc} + + +%package -n primus-libs +Summary: Shared libraries for primus + +%description -n primus-libs +%{desc} + + +%prep +%autosetup -p1 -n primus-%{commit} + + +%build +export CXXFLAGS='%{optflags}' +export LIBDIR=%{_lib} +# Use glvnd libGL ($$ because this gets dereferenced by the Makefile) +export PRIMUS_libGLa='/usr/$$LIB/libGL.so.1' +%make_build + + +%install +# Install launcher +install -d -m 0755 %{buildroot}%{_bindir} +install -m 0755 primusrun \ + %{buildroot}%{_bindir}/ + +# Install library +install -d -m 0755 %{buildroot}%{_libdir}/primus +install -m 0755 %{_lib}/libGL.so.1 \ + %{buildroot}%{_libdir}/primus/ + +# Install bash-completion file +install -d -m 0755 %{buildroot}%{_datadir}/bash-completion/completions/ +install -m 0644 primus.bash-completion \ + %{buildroot}%{_datadir}/bash-completion/completions/primusrun + +# Install man page +install -d -m 0755 %{buildroot}%{_mandir}/man1/ +install -m 0644 primusrun.1 \ + %{buildroot}%{_mandir}/man1/ + + +%post -n primus-libs -p /sbin/ldconfig + + +%postun -n primus-libs -p /sbin/ldconfig + + +%files -n primus +%doc README.md technotes.md +%license LICENSE.txt +%{_bindir}/primusrun +%{_datadir}/bash-completion/completions/primusrun +%{_mandir}/man1/primusrun.1* + + +%files -n primus-libs +%dir %{_libdir}/primus/ +%{_libdir}/primus/libGL.so.1 + + +%changelog +* Mon Dec 25 2017 Andrew Gunnerson - 0.2.1.gitd1afbf6 +- Initial release +- Based on Arch Linux package diff --git a/register_cleanup.patch b/register_cleanup.patch new file mode 100644 index 0000000..6f58e87 --- /dev/null +++ b/register_cleanup.patch @@ -0,0 +1,47 @@ +diff --git a/libglfork.cpp b/libglfork.cpp +index 03f514f..bb42f0d 100644 +--- a/libglfork.cpp ++++ b/libglfork.cpp +@@ -259,6 +259,22 @@ static struct PrimusInfo { + } + } primus; + ++static void cleanup() ++{ ++ primus.drawables.clear(); ++} ++ ++static void register_cleanup_1() ++{ ++ atexit(cleanup); ++} ++ ++static void register_cleanup() ++{ ++ static pthread_once_t once = PTHREAD_ONCE_INIT; ++ pthread_once(&once, register_cleanup_1); ++} ++ + // Thread-specific data + static __thread struct { + Display *dpy; +@@ -622,11 +638,6 @@ GLXContext glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config, GLXConte + void glXDestroyContext(Display *dpy, GLXContext ctx) + { + primus.contexts.erase(ctx); +- // kludge: reap background tasks when deleting the last context +- // otherwise something will deadlock during unloading the library +- if (primus.contexts.empty()) +- for (DrawablesInfo::iterator i = primus.drawables.begin(); i != primus.drawables.end(); i++) +- i->second.reap_workers(); + primus.afns.glXDestroyContext(primus.adpy, ctx); + } + +@@ -720,6 +731,7 @@ void glXSwapBuffers(Display *dpy, GLXDrawable drawable) + di.actx = ctx; + di.d.spawn_worker(drawable, display_work); + di.r.spawn_worker(drawable, readback_work); ++ register_cleanup(); + } + // Readback thread needs a sync object to avoid reading an incomplete frame + di.sync = primus.afns.glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);