mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Expose video driver options for Qt6 (#2643)
* Expose video driver options for Qt6 * Default to d3d11/metal/vulkan on Qt6 * Remove `pass` * Add missing word to existing translation * Default to OpenGL on Linux * Exclude Vulkan from macOS * Label default drivers
This commit is contained in:
parent
6cf38b0326
commit
ba7140ddec
6 changed files with 65 additions and 37 deletions
|
@ -6,3 +6,4 @@ preferences-video-driver-software-mac = Software (not recommended)
|
||||||
preferences-video-driver-opengl-other = OpenGL (faster, may cause issues)
|
preferences-video-driver-opengl-other = OpenGL (faster, may cause issues)
|
||||||
preferences-video-driver-software-other = Software (slower)
|
preferences-video-driver-software-other = Software (slower)
|
||||||
preferences-video-driver-angle = ANGLE (may work better than OpenGL)
|
preferences-video-driver-angle = ANGLE (may work better than OpenGL)
|
||||||
|
preferences-video-driver-default = default
|
||||||
|
|
|
@ -61,7 +61,7 @@ qt-misc-your-firewall-or-antivirus-program-is = Your firewall or antivirus progr
|
||||||
qt-misc-error = Error
|
qt-misc-error = Error
|
||||||
qt-misc-no-temp-folder = No usable temporary folder found. Make sure C:\\temp exists or TEMP in your environment points to a valid, writable folder.
|
qt-misc-no-temp-folder = No usable temporary folder found. Make sure C:\\temp exists or TEMP in your environment points to a valid, writable folder.
|
||||||
qt-misc-incompatible-video-driver = Your video driver is incompatible. Please start Anki again, and Anki will switch to a slower, more compatible mode.
|
qt-misc-incompatible-video-driver = Your video driver is incompatible. Please start Anki again, and Anki will switch to a slower, more compatible mode.
|
||||||
qt-misc-error-loading-graphics-driver = Error loading '{ $mode }' graphics driver. Please start Anki again to try next driver. { $context }
|
qt-misc-error-loading-graphics-driver = Error loading '{ $mode }' graphics driver. Please start Anki again to try the next driver. { $context }
|
||||||
qt-misc-anki-is-running = Anki Already Running
|
qt-misc-anki-is-running = Anki Already Running
|
||||||
qt-misc-if-instance-is-not-responding = If the existing instance of Anki is not responding, please close it using your task manager, or restart your computer.
|
qt-misc-if-instance-is-not-responding = If the existing instance of Anki is not responding, please close it using your task manager, or restart your computer.
|
||||||
qt-misc-second =
|
qt-misc-second =
|
||||||
|
|
|
@ -399,6 +399,8 @@ def parseArgs(argv: list[str]) -> tuple[argparse.Namespace, list[str]]:
|
||||||
|
|
||||||
def setupGL(pm: aqt.profiles.ProfileManager) -> None:
|
def setupGL(pm: aqt.profiles.ProfileManager) -> None:
|
||||||
driver = pm.video_driver()
|
driver = pm.video_driver()
|
||||||
|
# RHI errors are emitted multiple times so make sure we only handle them once
|
||||||
|
driver_failed = False
|
||||||
|
|
||||||
# work around pyqt loading wrong GL library
|
# work around pyqt loading wrong GL library
|
||||||
if is_lin:
|
if is_lin:
|
||||||
|
@ -431,11 +433,16 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None:
|
||||||
context += f"{ctx.function}"
|
context += f"{ctx.function}"
|
||||||
if context:
|
if context:
|
||||||
context = f"'{context}'"
|
context = f"'{context}'"
|
||||||
if (
|
|
||||||
|
nonlocal driver_failed
|
||||||
|
if not driver_failed and (
|
||||||
"Failed to create OpenGL context" in msg
|
"Failed to create OpenGL context" in msg
|
||||||
# Based on the message Qt6 shows to the user; have not tested whether
|
# Based on the message Qt6 shows to the user; have not tested whether
|
||||||
# we can actually capture this or not.
|
# we can actually capture this or not.
|
||||||
or "Failed to initialize graphics backend" in msg
|
or "Failed to initialize graphics backend" in msg
|
||||||
|
# RHI backend
|
||||||
|
or "Failed to create QRhi" in msg
|
||||||
|
or "Failed to get a QRhi" in msg
|
||||||
):
|
):
|
||||||
QMessageBox.critical(
|
QMessageBox.critical(
|
||||||
None,
|
None,
|
||||||
|
@ -446,6 +453,7 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None:
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
pm.set_video_driver(driver.next())
|
pm.set_video_driver(driver.next())
|
||||||
|
driver_failed = True
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print(f"Qt {category}: {msg} {context}")
|
print(f"Qt {category}: {msg} {context}")
|
||||||
|
@ -455,8 +463,9 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None:
|
||||||
if driver == VideoDriver.OpenGL:
|
if driver == VideoDriver.OpenGL:
|
||||||
# Leaving QT_OPENGL unset appears to sometimes produce different results
|
# Leaving QT_OPENGL unset appears to sometimes produce different results
|
||||||
# to explicitly setting it to 'auto'; the former seems to be more compatible.
|
# to explicitly setting it to 'auto'; the former seems to be more compatible.
|
||||||
pass
|
if qtmajor > 5:
|
||||||
else:
|
QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.OpenGL)
|
||||||
|
elif driver in (VideoDriver.Software, VideoDriver.ANGLE):
|
||||||
if is_win:
|
if is_win:
|
||||||
# on Windows, this appears to be sufficient on Qt5/Qt6.
|
# on Windows, this appears to be sufficient on Qt5/Qt6.
|
||||||
# On Qt6, ANGLE is excluded by the enum.
|
# On Qt6, ANGLE is excluded by the enum.
|
||||||
|
@ -469,6 +478,14 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None:
|
||||||
# Required on Qt6
|
# Required on Qt6
|
||||||
if "QTWEBENGINE_CHROMIUM_FLAGS" not in os.environ:
|
if "QTWEBENGINE_CHROMIUM_FLAGS" not in os.environ:
|
||||||
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-gpu"
|
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-gpu"
|
||||||
|
if qtmajor > 5:
|
||||||
|
QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.Software)
|
||||||
|
elif driver == VideoDriver.Metal:
|
||||||
|
QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.Metal)
|
||||||
|
elif driver == VideoDriver.Vulkan:
|
||||||
|
QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.Vulkan)
|
||||||
|
elif driver == VideoDriver.Direct3D:
|
||||||
|
QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.Direct3D11)
|
||||||
|
|
||||||
|
|
||||||
PROFILE_CODE = os.environ.get("ANKI_PROFILE_CODE")
|
PROFILE_CODE = os.environ.get("ANKI_PROFILE_CODE")
|
||||||
|
|
|
@ -392,9 +392,6 @@ class Preferences(QDialog):
|
||||||
self.form.video_driver.setCurrentIndex(
|
self.form.video_driver.setCurrentIndex(
|
||||||
self.video_drivers.index(self.mw.pm.video_driver())
|
self.video_drivers.index(self.mw.pm.video_driver())
|
||||||
)
|
)
|
||||||
if qtmajor > 5:
|
|
||||||
self.form.video_driver_label.setVisible(False)
|
|
||||||
self.form.video_driver.setVisible(False)
|
|
||||||
|
|
||||||
def update_video_driver(self) -> None:
|
def update_video_driver(self) -> None:
|
||||||
new_driver = self.video_drivers[self.form.video_driver.currentIndex()]
|
new_driver = self.video_drivers[self.form.video_driver.currentIndex()]
|
||||||
|
@ -404,15 +401,22 @@ class Preferences(QDialog):
|
||||||
|
|
||||||
|
|
||||||
def video_driver_name_for_platform(driver: VideoDriver) -> str:
|
def video_driver_name_for_platform(driver: VideoDriver) -> str:
|
||||||
if driver == VideoDriver.ANGLE:
|
if qtmajor < 6:
|
||||||
return tr.preferences_video_driver_angle()
|
if driver == VideoDriver.ANGLE:
|
||||||
elif driver == VideoDriver.Software:
|
return tr.preferences_video_driver_angle()
|
||||||
if is_mac:
|
elif driver == VideoDriver.Software:
|
||||||
return tr.preferences_video_driver_software_mac()
|
if is_mac:
|
||||||
else:
|
return tr.preferences_video_driver_software_mac()
|
||||||
return tr.preferences_video_driver_software_other()
|
else:
|
||||||
else:
|
return tr.preferences_video_driver_software_other()
|
||||||
if is_mac:
|
elif driver == VideoDriver.OpenGL:
|
||||||
return tr.preferences_video_driver_opengl_mac()
|
if is_mac:
|
||||||
else:
|
return tr.preferences_video_driver_opengl_mac()
|
||||||
return tr.preferences_video_driver_opengl_other()
|
else:
|
||||||
|
return tr.preferences_video_driver_opengl_other()
|
||||||
|
|
||||||
|
label = driver.name
|
||||||
|
if driver == VideoDriver.default_for_platform():
|
||||||
|
label += f" ({tr.preferences_video_driver_default()})"
|
||||||
|
|
||||||
|
return label
|
||||||
|
|
|
@ -42,37 +42,42 @@ class VideoDriver(Enum):
|
||||||
OpenGL = "auto"
|
OpenGL = "auto"
|
||||||
ANGLE = "angle"
|
ANGLE = "angle"
|
||||||
Software = "software"
|
Software = "software"
|
||||||
|
Metal = "metal"
|
||||||
|
Vulkan = "vulkan"
|
||||||
|
Direct3D = "d3d11"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_for_platform() -> VideoDriver:
|
def default_for_platform() -> VideoDriver:
|
||||||
if is_mac or qtmajor > 5:
|
return VideoDriver.all_for_platform()[0]
|
||||||
return VideoDriver.OpenGL
|
|
||||||
else:
|
|
||||||
return VideoDriver.Software
|
|
||||||
|
|
||||||
def constrained_to_platform(self) -> VideoDriver:
|
def constrained_to_platform(self) -> VideoDriver:
|
||||||
if self == VideoDriver.ANGLE and not VideoDriver.supports_angle():
|
if self not in VideoDriver.all_for_platform():
|
||||||
return VideoDriver.Software
|
return VideoDriver.default_for_platform()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self) -> VideoDriver:
|
def next(self) -> VideoDriver:
|
||||||
if self == VideoDriver.Software:
|
all = VideoDriver.all_for_platform()
|
||||||
return VideoDriver.OpenGL
|
try:
|
||||||
elif self == VideoDriver.OpenGL and VideoDriver.supports_angle():
|
idx = (all.index(self) + 1) % len(all)
|
||||||
return VideoDriver.ANGLE
|
except ValueError:
|
||||||
else:
|
idx = 0
|
||||||
return VideoDriver.Software
|
return all[idx]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def supports_angle() -> bool:
|
|
||||||
return is_win and qtmajor < 6
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def all_for_platform() -> list[VideoDriver]:
|
def all_for_platform() -> list[VideoDriver]:
|
||||||
all = [VideoDriver.OpenGL]
|
all = []
|
||||||
if VideoDriver.supports_angle():
|
if qtmajor > 5:
|
||||||
|
if is_win:
|
||||||
|
all.append(VideoDriver.Direct3D)
|
||||||
|
if is_mac:
|
||||||
|
all.append(VideoDriver.Metal)
|
||||||
|
all.append(VideoDriver.OpenGL)
|
||||||
|
if qtmajor > 5 and not is_mac:
|
||||||
|
all.append(VideoDriver.Vulkan)
|
||||||
|
if is_win and qtmajor < 6:
|
||||||
all.append(VideoDriver.ANGLE)
|
all.append(VideoDriver.ANGLE)
|
||||||
all.append(VideoDriver.Software)
|
all.append(VideoDriver.Software)
|
||||||
|
|
||||||
return all
|
return all
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from PyQt6.QtCore import *
|
||||||
# conflicting Qt and qFuzzyCompare definitions require an ignore
|
# conflicting Qt and qFuzzyCompare definitions require an ignore
|
||||||
from PyQt6.QtGui import * # type: ignore[misc,assignment]
|
from PyQt6.QtGui import * # type: ignore[misc,assignment]
|
||||||
from PyQt6.QtNetwork import QLocalServer, QLocalSocket, QNetworkProxy
|
from PyQt6.QtNetwork import QLocalServer, QLocalSocket, QNetworkProxy
|
||||||
|
from PyQt6.QtQuick import *
|
||||||
from PyQt6.QtWebChannel import QWebChannel
|
from PyQt6.QtWebChannel import QWebChannel
|
||||||
from PyQt6.QtWebEngineCore import *
|
from PyQt6.QtWebEngineCore import *
|
||||||
from PyQt6.QtWebEngineWidgets import *
|
from PyQt6.QtWebEngineWidgets import *
|
||||||
|
|
Loading…
Reference in a new issue