Skip to content

Commit 6b1b987

Browse files
larsonerPragnyaKhandelwal
authored andcommitted
Speed up 3D window creation and sizing, simplify class inheritance (#14087)
1 parent 9b5f72a commit 6b1b987

4 files changed

Lines changed: 142 additions & 102 deletions

File tree

mne/viz/backends/_pyvista.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# License: BSD-3-Clause
99
# Copyright the MNE-Python contributors.
1010

11+
import functools
1112
import os
1213
import platform
1314
import re
@@ -1402,6 +1403,9 @@ def _disabled_depth_peeling():
14021403
depth_peeling["enabled"] = depth_peeling_enabled
14031404

14041405

1406+
_GPU_REPORT = None
1407+
1408+
14051409
def _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,

0 commit comments

Comments
 (0)