Skip to content

Commit

Permalink
refactor configgen invocation of batocera-vulkan into module
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanforbes committed Dec 13, 2024
1 parent ae41ce0 commit 0461a55
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ... import Command
from ...batoceraPaths import CACHE, CONFIGS, SAVES, mkdir_if_not_exists
from ...controller import generate_sdl_game_controller_config
from ...utils import vulkan
from ..Generator import Generator
from . import cemuControllers
from .cemuPaths import CEMU_BIOS, CEMU_CONFIG, CEMU_CONTROLLER_PROFILES, CEMU_ROMDIR, CEMU_SAVES
Expand Down Expand Up @@ -148,33 +149,21 @@ def CemuConfig(configFile: Path, system: Emulator) -> None:
# Only set the graphics `device` if Vulkan
if api_value == "1":
# Check if we have a discrete GPU & if so, set the UUID
try:
have_vulkan = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasVulkan"], text=True).strip()
if have_vulkan == "true":
eslog.debug("Vulkan driver is available on the system.")
try:
have_discrete = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasDiscrete"], text=True).strip()
if have_discrete == "true":
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
try:
discrete_uuid = subprocess.check_output(["/usr/bin/batocera-vulkan", "discreteUUID"], text=True).strip()
if discrete_uuid != "":
discrete_uuid_num = discrete_uuid.replace("-", "")
eslog.debug("Using Discrete GPU UUID: {} for Cemu".format(discrete_uuid_num))
CemuGenerator.setSectionConfig(config, graphic_root, "device", discrete_uuid_num)
else:
eslog.debug("Couldn't get discrete GPU UUID!")
except subprocess.CalledProcessError:
eslog.debug("Error getting discrete GPU UUID!")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
except subprocess.CalledProcessError:
eslog.debug("Error checking for discrete GPU.")
if vulkan.is_available():
eslog.debug("Vulkan driver is available on the system.")
if vulkan.has_discrete_gpu():
discrete_uuid = vulkan.get_discrete_gpu_uuid()
if discrete_uuid:
discrete_uuid_num = discrete_uuid.replace("-", "")
eslog.debug("Using Discrete GPU UUID: {} for Cemu".format(discrete_uuid_num))
CemuGenerator.setSectionConfig(config, graphic_root, "device", discrete_uuid_num)
else:
eslog.debug("Couldn't get discrete GPU UUID!")
else:
eslog.debug("Vulkan driver is not available on the system. Falling back to OpenGL")
CemuGenerator.setSectionConfig(config, graphic_root, "api", "0")
except subprocess.CalledProcessError:
eslog.debug("Error executing batocera-vulkan script.")
eslog.debug("Discrete GPU is not available on the system. Using default.")
else:
eslog.debug("Vulkan driver is not available on the system. Falling back to OpenGL")
CemuGenerator.setSectionConfig(config, graphic_root, "api", "0")

# Async VULKAN Shader compilation
if system.isOptSet("cemu_async") and system.config["cemu_async"] == "False":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import logging
import subprocess
from os import environ
from pathlib import Path
from typing import TYPE_CHECKING

from ... import Command
from ...batoceraPaths import CACHE, CONFIGS, SAVES, ensure_parents_and_open
from ...controller import generate_sdl_game_controller_config
from ...utils import vulkan
from ...utils.configparser import CaseSensitiveRawConfigParser
from ..Generator import Generator

Expand Down Expand Up @@ -152,29 +152,18 @@ def writeCITRAConfig(
citraConfig.set("Renderer", "graphics_api", "1")
# Set Vulkan as necessary
if system.isOptSet("citra_graphics_api") and system.config["citra_graphics_api"] == "2":
try:
have_vulkan = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasVulkan"], text=True).strip()
if have_vulkan == "true":
eslog.debug("Vulkan driver is available on the system.")
try:
have_discrete = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasDiscrete"], text=True).strip()
if have_discrete == "true":
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
try:
discrete_index = subprocess.check_output(["/usr/bin/batocera-vulkan", "discreteIndex"], text=True).strip()
if discrete_index != "":
eslog.debug("Using Discrete GPU Index: {} for Citra".format(discrete_index))
citraConfig.set("Renderer", "physical_device", discrete_index)
else:
eslog.debug("Couldn't get discrete GPU index")
except subprocess.CalledProcessError:
eslog.debug("Error getting discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
except subprocess.CalledProcessError:
eslog.debug("Error checking for discrete GPU.")
except subprocess.CalledProcessError:
eslog.debug("Error executing batocera-vulkan script.")
if vulkan.is_available():
eslog.debug("Vulkan driver is available on the system.")
if vulkan.has_discrete_gpu():
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
discrete_index = vulkan.get_discrete_gpu_index()
if discrete_index:
eslog.debug("Using Discrete GPU Index: {} for Citra".format(discrete_index))
citraConfig.set("Renderer", "physical_device", discrete_index)
else:
eslog.debug("Couldn't get discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
# Use VSYNC
if system.isOptSet('citra_use_vsync_new') and system.config["citra_use_vsync_new"] == '0':
citraConfig.set("Renderer", "use_vsync_new", "false")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

import logging
import subprocess
from os import environ
from pathlib import Path
from typing import TYPE_CHECKING

from ... import Command, controllersConfig
from ...batoceraPaths import CONFIGS, SAVES, CACHE, mkdir_if_not_exists
from ...batoceraPaths import CACHE, CONFIGS, SAVES, mkdir_if_not_exists
from ...utils import vulkan
from ...utils.configparser import CaseSensitiveConfigParser
from ..Generator import Generator
from . import dolphinControllers, dolphinSYSCONF
Expand Down Expand Up @@ -148,13 +148,9 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
if system.isOptSet("gfxbackend") and system.config["gfxbackend"] == "Vulkan":
dolphinSettings.set("Core", "GFXBackend", "Vulkan")
# Check Vulkan
try:
have_vulkan = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasVulkan"], text=True).strip()
if have_vulkan != "true":
eslog.debug("Vulkan driver is not available on the system. Using OpenGL instead.")
dolphinSettings.set("Core", "GFXBackend", "OGL")
except subprocess.CalledProcessError:
eslog.debug("Error checking for discrete GPU.")
if not vulkan.is_available():
eslog.debug("Vulkan driver is not available on the system. Using OpenGL instead.")
dolphinSettings.set("Core", "GFXBackend", "OGL")
else:
dolphinSettings.set("Core", "GFXBackend", "OGL")

Expand Down Expand Up @@ -235,29 +231,18 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
dolphinGFXSettings.add_section("Hardware")

# Set Vulkan adapter
try:
have_vulkan = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasVulkan"], text=True).strip()
if have_vulkan == "true":
eslog.debug("Vulkan driver is available on the system.")
try:
have_discrete = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasDiscrete"], text=True).strip()
if have_discrete == "true":
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
try:
discrete_index = subprocess.check_output(["/usr/bin/batocera-vulkan", "discreteIndex"], text=True).strip()
if discrete_index != "":
eslog.debug("Using Discrete GPU Index: {} for Dolphin".format(discrete_index))
dolphinGFXSettings.set("Hardware", "Adapter", discrete_index)
else:
eslog.debug("Couldn't get discrete GPU index")
except subprocess.CalledProcessError:
eslog.debug("Error getting discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
except subprocess.CalledProcessError:
eslog.debug("Error checking for discrete GPU.")
except subprocess.CalledProcessError:
eslog.debug("Error executing batocera-vulkan script.")
if vulkan.is_available():
eslog.debug("Vulkan driver is available on the system.")
if vulkan.has_discrete_gpu():
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
discrete_index = vulkan.get_discrete_gpu_index()
if discrete_index:
eslog.debug("Using Discrete GPU Index: {} for Dolphin".format(discrete_index))
dolphinGFXSettings.set("Hardware", "Adapter", discrete_index)
else:
eslog.debug("Couldn't get discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")

# Graphics setting Aspect Ratio
if system.isOptSet('dolphin_aspect_ratio'):
Expand Down Expand Up @@ -489,8 +474,8 @@ def generate(self, system, rom, playersControllers, metadata, guns, wheels, game
commandArray.extend(["--save_state", system.config['state_filename']])

return Command.Command(
array=commandArray,
env={
array=commandArray,
env={
"XDG_CONFIG_HOME": CONFIGS,
"XDG_DATA_HOME": SAVES,
"XDG_CACHE_HOME": CACHE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import logging
import subprocess
from os import environ
from pathlib import Path
from typing import TYPE_CHECKING

from ... import Command
from ...batoceraPaths import CACHE, CONFIGS, SAVES, ensure_parents_and_open
from ...controller import generate_sdl_game_controller_config
from ...utils import vulkan
from ...utils.configparser import CaseSensitiveRawConfigParser
from ..Generator import Generator

Expand Down Expand Up @@ -154,29 +154,18 @@ def writeLEMONADEConfig(lemonadeConfigFile: Path, system: Emulator, playersContr
lemonadeConfig.set("Renderer", "graphics_api", "1")
# Set Vulkan as necessary
if system.isOptSet("lemonade_graphics_api") and system.config["lemonade_graphics_api"] == "2":
try:
have_vulkan = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasVulkan"], text=True).strip()
if have_vulkan == "true":
eslog.debug("Vulkan driver is available on the system.")
try:
have_discrete = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasDiscrete"], text=True).strip()
if have_discrete == "true":
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
try:
discrete_index = subprocess.check_output(["/usr/bin/batocera-vulkan", "discreteIndex"], text=True).strip()
if discrete_index != "":
eslog.debug("Using Discrete GPU Index: {} for Lemonade".format(discrete_index))
lemonadeConfig.set("Renderer", "physical_device", discrete_index)
else:
eslog.debug("Couldn't get discrete GPU index")
except subprocess.CalledProcessError:
eslog.debug("Error getting discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
except subprocess.CalledProcessError:
eslog.debug("Error checking for discrete GPU.")
except subprocess.CalledProcessError:
eslog.debug("Error executing batocera-vulkan script.")
if vulkan.is_available():
eslog.debug("Vulkan driver is available on the system.")
if vulkan.has_discrete_gpu():
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
discrete_index = vulkan.get_discrete_gpu_index()
if discrete_index:
eslog.debug("Using Discrete GPU Index: {} for Lemonade".format(discrete_index))
lemonadeConfig.set("Renderer", "physical_device", discrete_index)
else:
eslog.debug("Couldn't get discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
# Use VSYNC
if system.isOptSet('lemonade_use_vsync_new') and system.config["lemonade_use_vsync_new"] == '0':
lemonadeConfig.set("Renderer", "use_vsync_new", "false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ... import controllersConfig
from ...batoceraPaths import DEFAULTS_DIR, ES_SETTINGS, SAVES, mkdir_if_not_exists
from ...settings.unixSettings import UnixSettings
from ...utils import bezels as bezelsUtil, videoMode as videoMode
from ...utils import bezels as bezelsUtil, videoMode as videoMode, vulkan
from ..hatari.hatariGenerator import HATARI_CONFIG
from . import libretroMAMEConfig, libretroOptions
from .libretroPaths import (
Expand Down Expand Up @@ -144,29 +144,18 @@ def createLibretroConfig(generator: Generator, system: Emulator, controllers: Co
retroarchConfig['video_driver'] = '"' + gfxBackend + '"' # needed for the ozone menu
# Set Vulkan
if system.isOptSet("gfxbackend") and system.config["gfxbackend"] == "vulkan":
try:
have_vulkan = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasVulkan"], text=True).strip()
if have_vulkan == "true":
eslog.debug("Vulkan driver is available on the system.")
try:
have_discrete = subprocess.check_output(["/usr/bin/batocera-vulkan", "hasDiscrete"], text=True).strip()
if have_discrete == "true":
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
try:
discrete_index = subprocess.check_output(["/usr/bin/batocera-vulkan", "discreteIndex"], text=True).strip()
if discrete_index != "":
eslog.debug("Using Discrete GPU Index: {} for RetroArch".format(discrete_index))
retroarchConfig["vulkan_gpu_index"] = '"' + discrete_index + '"'
else:
eslog.debug("Couldn't get discrete GPU index")
except subprocess.CalledProcessError:
eslog.debug("Error getting discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")
except subprocess.CalledProcessError:
eslog.debug("Error checking for discrete GPU.")
except subprocess.CalledProcessError:
eslog.debug("Error executing batocera-vulkan script.")
if vulkan.is_available():
eslog.debug("Vulkan driver is available on the system.")
if vulkan.has_discrete_gpu():
eslog.debug("A discrete GPU is available on the system. We will use that for performance")
discrete_index = vulkan.get_discrete_gpu_index()
if discrete_index:
eslog.debug("Using Discrete GPU Index: {} for RetroArch".format(discrete_index))
retroarchConfig["vulkan_gpu_index"] = f'"{discrete_index}"'
else:
eslog.debug("Couldn't get discrete GPU index")
else:
eslog.debug("Discrete GPU is not available on the system. Using default.")

retroarchConfig['audio_driver'] = '"pulse"'
if (system.isOptSet("audio_driver")):
Expand Down
Loading

0 comments on commit 0461a55

Please sign in to comment.