File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88# License: BSD-3-Clause
99# Copyright the MNE-Python contributors.
1010
11+ import functools
1112import os
1213import platform
1314import re
@@ -1402,6 +1403,9 @@ def _disabled_depth_peeling():
14021403 depth_peeling ["enabled" ] = depth_peeling_enabled
14031404
14041405
1406+ _GPU_REPORT = None
1407+
1408+
14051409def _is_osmesa (plotter ):
14061410 # MESA (could use GPUInfo / _get_gpu_info here, but it takes
14071411 # > 700 ms to make a new window + report capabilities!)
@@ -1411,7 +1415,19 @@ def _is_osmesa(plotter):
14111415 return False
14121416 if os .getenv ("MNE_IS_OSMESA" , "" ).lower () == "true" :
14131417 return True
1414- gpu_info_full = plotter .ren_win .ReportCapabilities ()
1418+ global _GPU_REPORT
1419+ if _GPU_REPORT is None :
1420+ # Ask at most once per process: the GL driver cannot change while the
1421+ # process is alive, every report costs ~13 ms (and a GL context
1422+ # realization the first time), and asking VTK has segfaulted before.
1423+ # This cannot be a plotter-keyed cache: each figure is a new plotter,
1424+ # so it would miss every time and keep every plotter alive forever.
1425+ _GPU_REPORT = plotter .ren_win .ReportCapabilities ()
1426+ return _is_osmesa_from_report (_GPU_REPORT )
1427+
1428+
1429+ @functools .cache
1430+ def _is_osmesa_from_report (gpu_info_full ):
14151431 gpu_info = re .findall (
14161432 "OpenGL (?:version|renderer) string:(.+)\n " ,
14171433 gpu_info_full ,
You can’t perform that action at this time.
0 commit comments