From cc34996684cf7bbd6d0bcb3be910af75effc2d2f Mon Sep 17 00:00:00 2001 From: Seungmin Kim <8457324+ehfd@users.noreply.github.com> Date: Fri, 10 May 2024 23:12:49 +0900 Subject: [PATCH 1/5] Inject additional libraries required for full X11 functionality and fix paths Signed-off-by: Seungmin Kim <8457324+ehfd@users.noreply.github.com> --- internal/discover/graphics.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 35b51982..2f408821 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -56,6 +56,9 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n driver.Root, []string{ "libnvidia-egl-gbm.so.*", + "gbm/nvidia-drm_gbm.so", + "libnvidia-egl-wayland.so.*", + "libnvidia-vulkan-producer.so*", }, ) @@ -271,13 +274,23 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa lookup.NewFileLocator( lookup.WithLogger(logger), lookup.WithRoot(driver.Root), - lookup.WithSearchPaths(libRoot, "/usr/lib/x86_64-linux-gnu"), + lookup.WithSearchPaths([]string{ + libRoot + "/nvidia/xorg", + libRoot + "/xorg/modules/extensions", + libRoot + "/xorg/modules/drivers", + "/usr/lib/xorg/modules/extensions", + "/usr/lib/xorg/modules/drivers", + "/usr/X11R6/modules/extensions", + "/usr/X11R6/modules/drivers", + "/usr/lib64/xorg/modules/extensions", + "/usr/lib64/xorg/modules/drivers", + }), lookup.WithCount(1), ), driver.Root, []string{ - "nvidia/xorg/nvidia_drv.so", - fmt.Sprintf("nvidia/xorg/libglxserver_nvidia.so.%s", version), + "nvidia_drv.so", + fmt.Sprintf("libglxserver_nvidia.so.%s", version), }, ) xorgHooks := xorgHooks{ @@ -290,7 +303,10 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa logger, driver.Configs(), driver.Root, - []string{"X11/xorg.conf.d/10-nvidia.conf"}, + []string{ + "X11/xorg.conf.d/10-nvidia.conf", + "X11/xorg.conf.d/nvidia-drm-outputclass.conf", + }, ) d := Merge( From 55440f40b32e56beeaafb3aade055927eb572c66 Mon Sep 17 00:00:00 2001 From: Seungmin Kim <8457324+ehfd@users.noreply.github.com> Date: Sat, 11 May 2024 04:31:11 +0900 Subject: [PATCH 2/5] Make X11 search paths accurate Signed-off-by: Seungmin Kim <8457324+ehfd@users.noreply.github.com> --- internal/discover/graphics.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 2f408821..fe0b2375 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -280,10 +280,20 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa libRoot + "/xorg/modules/drivers", "/usr/lib/xorg/modules/extensions", "/usr/lib/xorg/modules/drivers", - "/usr/X11R6/modules/extensions", - "/usr/X11R6/modules/drivers", "/usr/lib64/xorg/modules/extensions", "/usr/lib64/xorg/modules/drivers", + "/usr/lib/xorg/modules/updates/extensions", + "/usr/lib/xorg/modules/updates/drivers", + "/usr/lib64/xorg/modules/updates/extensions", + "/usr/lib64/xorg/modules/updates/drivers", + "/usr/X11R6/lib/modules/extensions", + "/usr/X11R6/lib/modules/drivers", + "/usr/X11R6/lib64/modules/extensions", + "/usr/X11R6/lib64/modules/drivers", + "/usr/X11R6/lib/modules/updates/extensions", + "/usr/X11R6/lib/modules/updates/drivers", + "/usr/X11R6/lib64/modules/updates/extensions", + "/usr/X11R6/lib64/modules/updates/drivers", }), lookup.WithCount(1), ), From cf388e7e63763ffb6213b7d365c59dceca8d1256 Mon Sep 17 00:00:00 2001 From: Seungmin Kim <8457324+ehfd@users.noreply.github.com> Date: Fri, 17 May 2024 23:53:06 +0900 Subject: [PATCH 3/5] Update internal/discover/graphics.go Co-authored-by: Evan Lezar Signed-off-by: Seungmin Kim <8457324+ehfd@users.noreply.github.com> --- internal/discover/graphics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index fe0b2375..30dcc4e3 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -58,7 +58,7 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n "libnvidia-egl-gbm.so.*", "gbm/nvidia-drm_gbm.so", "libnvidia-egl-wayland.so.*", - "libnvidia-vulkan-producer.so*", + "libnvidia-vulkan-producer.so.*", }, ) From c2411e644edc8d6a03facf8eb4eee1b5c0947803 Mon Sep 17 00:00:00 2001 From: tux-rampage Date: Tue, 4 Jun 2024 19:40:05 +0200 Subject: [PATCH 4/5] Build xorg lib search paths dynamically --- internal/discover/graphics.go | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 4cf85889..7b11caf8 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -254,6 +254,26 @@ func optionalXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidia return xorg } +func buildXOrgSearchPaths(libRoot string) []string { + paths := []string{ + libRoot + "/nvidia/xorg", + } + + directories := []string{"drivers", "extensions"} + pathOptions := []string{"modules", "modules/updates"} + prefixes := []string{libRoot + "/xorg", "/usr/lib/xorg", "/usr/lib64/xorg", "/usr/X11R6/lib", "/usr/X11R6/lib64"} + + for _, prefix := range prefixes { + for _, pathOption := range pathOptions { + for _, directory := range directories { + paths = append(paths, prefix+"/"+pathOption+"/"+directory) + } + } + } + + return paths +} + func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCDIHookPath string) (Discover, error) { libCudaPaths, err := cuda.New( driver.Libraries(), @@ -274,27 +294,7 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCDIHo lookup.NewFileLocator( lookup.WithLogger(logger), lookup.WithRoot(driver.Root), - lookup.WithSearchPaths([]string{ - libRoot + "/nvidia/xorg", - libRoot + "/xorg/modules/extensions", - libRoot + "/xorg/modules/drivers", - "/usr/lib/xorg/modules/extensions", - "/usr/lib/xorg/modules/drivers", - "/usr/lib64/xorg/modules/extensions", - "/usr/lib64/xorg/modules/drivers", - "/usr/lib/xorg/modules/updates/extensions", - "/usr/lib/xorg/modules/updates/drivers", - "/usr/lib64/xorg/modules/updates/extensions", - "/usr/lib64/xorg/modules/updates/drivers", - "/usr/X11R6/lib/modules/extensions", - "/usr/X11R6/lib/modules/drivers", - "/usr/X11R6/lib64/modules/extensions", - "/usr/X11R6/lib64/modules/drivers", - "/usr/X11R6/lib/modules/updates/extensions", - "/usr/X11R6/lib/modules/updates/drivers", - "/usr/X11R6/lib64/modules/updates/extensions", - "/usr/X11R6/lib64/modules/updates/drivers", - }), + lookup.WithSearchPaths(buildXOrgSearchPaths(libRoot)...), lookup.WithCount(1), ), driver.Root, From e841c6256aa4a696b536579ec6473b11be24426a Mon Sep 17 00:00:00 2001 From: tux-rampage Date: Wed, 5 Jun 2024 00:27:53 +0200 Subject: [PATCH 5/5] Add driver hooks --- internal/discover/graphics.go | 60 ++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 7b11caf8..c1768149 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -56,8 +56,8 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n driver.Root, []string{ "libnvidia-egl-gbm.so.*", - "gbm/nvidia-drm_gbm.so", "libnvidia-egl-wayland.so.*", + "libnvidia-allocator.so.*", "libnvidia-vulkan-producer.so.*", }, ) @@ -77,17 +77,75 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n }, ) + symlinks := newGraphicsDriverSymlinks(logger, libraries, nvidiaCDIHookPath) xorg := optionalXorgDiscoverer(logger, driver, nvidiaCDIHookPath) discover := Merge( libraries, jsonMounts, + symlinks, xorg, ) return discover, nil } +type graphicsDriverSymlinks struct { + None + logger logger.Interface + libraries Discover + nvidiaCDIHookPath string +} + +var _ Discover = (*graphicsDriverSymlinks)(nil) + +func newGraphicsDriverSymlinks(logger logger.Interface, libraries Discover, nvidiaCDIHookPath string) Discover { + return &graphicsDriverSymlinks{ + logger: logger, + libraries: libraries, + nvidiaCDIHookPath: nvidiaCDIHookPath, + } +} + +// Create necessary library symlinks for graphics drivers +func (d graphicsDriverSymlinks) Hooks() ([]Hook, error) { + mounts, err := d.libraries.Mounts() + + if err != nil { + return nil, fmt.Errorf("failed to get library mounts: %v", err) + } + + links := []string{} + + for _, mount := range mounts { + filename := filepath.Base(mount.HostPath) + + // nvidia-drm_gbm.so is a symlink to libnvidia-allocator.so + // Make sure this is actually available + if strings.HasPrefix(filename, "libnvidia-allocator.so.") { + linkDir := filepath.Dir(mount.Path) + linkPath := filepath.Join(linkDir, "gbm", "nvidia-drm_gbm.so") + target := filepath.Join("..", filename) + links = append(links, fmt.Sprintf("%s::%s", target, linkPath)) + } + + // Address the vulkan-producer lib for nvidia drivers prior driver version 545 + if strings.HasPrefix(filename, "libnvidia-vulkan-producer.so.") { + linkDir := filepath.Dir(mount.Path) + linkPath := filepath.Join(linkDir, "libnvidia-vulkan-producer.so") + links = append(links, fmt.Sprintf("%s::%s", filename, linkPath)) + } + } + + if len(links) == 0 { + return nil, nil + } + + hooks := CreateCreateSymlinkHook(d.nvidiaCDIHookPath, links) + + return hooks.Hooks() +} + type drmDevicesByPath struct { None logger logger.Interface