Skip to content

Commit 00aae32

Browse files
authored
Merge pull request #768 from fireshare-app/fix/vulkan-probe-logging
Ship the NVIDIA Vulkan manifest, and log what the tone map probe finds
2 parents 3a5d6dd + 6540ba1 commit 00aae32

2 files changed

Lines changed: 58 additions & 11 deletions

File tree

‎Dockerfile‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
170170
libass9 libfreetype6 libmp3lame0 libwebp7 libwebpmux3 \
171171
libzimg2 \
172172
liblcms2-2 libvulkan1 mesa-vulkan-drivers \
173-
libglvnd0 libx11-6 libxext6 \
173+
libglvnd0 libegl1 libx11-6 libxext6 \
174174
&& rm -rf /var/lib/apt/lists/*
175175

176176
COPY --from=python-source /opt/python3.14 /opt/python3.14
@@ -193,6 +193,21 @@ RUN ln -sf /usr/local/bin/ffmpeg /usr/bin/ffmpeg && \
193193
echo "Available encoders:" && \
194194
ffmpeg -hide_banner -encoders 2>/dev/null | grep -E "(nvenc|libaom|libvpx|libx264)" || true
195195

196+
# The NVIDIA Container Toolkit is meant to mount two manifests alongside the driver
197+
# libraries for the "graphics" capability: the Vulkan ICD manifest, without which the
198+
# Vulkan loader never looks at the driver, and libglvnd's EGL vendor manifest, without
199+
# which the driver aborts its own start-up while scanning for EGL vendors (it opens
200+
# neither /dev/nvidiactl nor the GPU and hands the loader no vkCreateInstance). Some
201+
# hosts, Unraid's driver plugin among them, mount the libraries and neither manifest,
202+
# so libplacebo silently ran bt.2390 on Mesa's software device. Shipping both covers
203+
# that: they only name libraries the toolkit mounts, and on a host without the GPU the
204+
# loader skips the Vulkan entry and carries on.
205+
RUN mkdir -p /etc/vulkan/icd.d /usr/share/glvnd/egl_vendor.d && printf '%s\n' \
206+
'{ "file_format_version": "1.0.0", "ICD": { "library_path": "libGLX_nvidia.so.0", "api_version": "1.3.204" } }' \
207+
> /etc/vulkan/icd.d/nvidia_icd.json && printf '%s\n' \
208+
'{ "file_format_version": "1.0.0", "ICD": { "library_path": "libEGL_nvidia.so.0" } }' \
209+
> /usr/share/glvnd/egl_vendor.d/10_nvidia.json
210+
196211
RUN adduser --disabled-password --gecos '' nginx
197212
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
198213
&& ln -sf /dev/stderr /var/log/nginx/error.log

‎app/server/fireshare/util.py‎

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,32 @@ def _probe_vulkan(index=None):
879879
return (match.group(1).strip() if match else 'unnamed'), errors
880880

881881

882-
def _nvidia_icd_mounted():
883-
return any(os.path.exists(os.path.join(d, 'nvidia_icd.json')) for d in _VULKAN_ICD_DIRS)
882+
def _vulkan_icd_manifests():
883+
"""The driver manifests the Vulkan loader will find, as 'dir/name' strings."""
884+
found = []
885+
for d in _VULKAN_ICD_DIRS:
886+
try:
887+
found.extend(os.path.join(d, n) for n in sorted(os.listdir(d)) if n.endswith('.json'))
888+
except OSError:
889+
continue
890+
return found
891+
892+
893+
_nvidia_driver_cache = None
894+
895+
896+
def _nvidia_driver_present():
897+
"""Whether the NVIDIA Vulkan driver library is in this container, i.e. the container
898+
toolkit mounted the driver for the graphics capability. The manifest that names it
899+
ships with the image, so it says nothing on its own."""
900+
global _nvidia_driver_cache
901+
if _nvidia_driver_cache is None:
902+
try:
903+
result = sp.run(['ldconfig', '-p'], capture_output=True, text=True, timeout=30)
904+
_nvidia_driver_cache = 'libGLX_nvidia.so.0' in result.stdout
905+
except (OSError, sp.SubprocessError):
906+
_nvidia_driver_cache = False
907+
return _nvidia_driver_cache
884908

885909

886910
def vulkan_device():
@@ -901,16 +925,24 @@ def vulkan_device():
901925
if not _is_software_vulkan(other):
902926
name, index = other, candidate
903927
break
928+
manifests = _vulkan_icd_manifests()
904929
if name:
905930
# Unknown names are treated as software: the only cost is that bt2390
906931
# is not picked automatically.
907932
kind = 'software' if _is_software_vulkan(name) else 'hardware'
908-
logger.info(f"Vulkan device for tone mapping: {name} ({kind}{f', device {index}' if index else ''})")
933+
logger.info(f"Vulkan device for tone mapping: {name} ({kind}{f', device {index}' if index else ''}); "
934+
f"driver manifests: {', '.join(manifests) or 'none'}")
909935
else:
910-
logger.info(f"No usable Vulkan device for tone mapping: {' | '.join(errors)[-300:]}")
911-
if kind != 'hardware' and _nvidia_icd_mounted():
912-
logger.warning("The NVIDIA Vulkan driver is mounted in this container but the GPU was not picked up; "
913-
"the loader said: " + (' | '.join(errors) or 'nothing'))
936+
logger.info(f"No usable Vulkan device for tone mapping: {' | '.join(errors)[-300:]}; "
937+
f"driver manifests: {', '.join(manifests) or 'none'}")
938+
if kind != 'hardware':
939+
if _nvidia_driver_present():
940+
logger.warning("The NVIDIA Vulkan driver is in this container but the GPU was not picked up; "
941+
"the loader said: " + (' | '.join(errors) or 'nothing'))
942+
elif any(c in os.environ.get('NVIDIA_DRIVER_CAPABILITIES', '') for c in ('graphics', 'all')):
943+
logger.warning("NVIDIA_DRIVER_CAPABILITIES asks for graphics, but no NVIDIA driver libraries were "
944+
"mounted into this container (libGLX_nvidia.so.0 is missing); is the GPU exposed "
945+
"with --gpus or the nvidia runtime?")
914946
_vulkan_device_cache = ('checked', kind, name, index)
915947
return _vulkan_device_cache[1]
916948

@@ -938,9 +970,9 @@ def tonemap_capabilities():
938970
available, note = False, 'no Vulkan device: install a Vulkan driver (mesa-vulkan-drivers) or expose the GPU'
939971
elif vulkan == 'hardware':
940972
available, note = True, 'runs on the GPU'
941-
elif _nvidia_icd_mounted():
942-
available, note = True, ('runs on the CPU through software Vulkan: the NVIDIA Vulkan driver is '
943-
'mounted but could not be loaded, see the server log')
973+
elif _nvidia_driver_present():
974+
available, note = True, ('runs on the CPU through software Vulkan: the NVIDIA driver is in the '
975+
'container but the GPU was not picked up, see the server log')
944976
else:
945977
caps_env = os.environ.get('NVIDIA_DRIVER_CAPABILITIES', '')
946978
hint = ('' if any(c in caps_env for c in ('graphics', 'all'))

0 commit comments

Comments
 (0)