@@ -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
886910def 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