From 08e498ee47a63b2d3c23a592dcd1530685f18594 Mon Sep 17 00:00:00 2001 From: Rhys-T <108157737+Rhys-T@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:09:28 -0400 Subject: [PATCH] mame: use absolute path to bgfx data directory Currently if you try to use the `bgfx` renderer, MAME outputs an error: ``` Unable to find the BGFX path bgfx, please install it or fix the bgfx_path setting to use the BGFX renderer. Initializing video module bgfx failed, falling back to opengl ``` because it's looking for the `bgfx` directory inside the working directory. To fix this, you have to explicitly set `bgfx_path` to `/nix/store/whatever1234hash567890-mame-0.277/opt/mame/bgfx`. This commit changes the default `bgfx_path` to be an absolute path to the right place, similarly to what's already being done for `artpath`, `ctrlrpath`, etc. However, unlike those options, `bgfx_path` can only take a single directory - so this is technically a breaking change if you actually _wanted_ MAME to use `./bgfx`. --- .../emulators/mame/001-use-absolute-paths.diff | 17 +++++++++++++++-- pkgs/applications/emulators/mame/default.nix | 6 ++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/emulators/mame/001-use-absolute-paths.diff b/pkgs/applications/emulators/mame/001-use-absolute-paths.diff index e349cacb2d96..2acd6b78e21f 100644 --- a/pkgs/applications/emulators/mame/001-use-absolute-paths.diff +++ b/pkgs/applications/emulators/mame/001-use-absolute-paths.diff @@ -1,8 +1,8 @@ diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp -index 3defd33d0bb..33daacc4fc8 100644 +index 834710c9eb0..6394ad8a7bc 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp -@@ -39,16 +39,16 @@ const options_entry emu_options::s_option_entries[] = +@@ -42,16 +42,16 @@ const options_entry emu_options::s_option_entries[] = { nullptr, nullptr, core_options::option_type::HEADER, "CORE SEARCH PATH OPTIONS" }, { OPTION_PLUGINDATAPATH, ".", core_options::option_type::PATH, "path to base folder for plugin data (read/write)" }, { OPTION_MEDIAPATH ";rp;biospath;bp", "roms", core_options::option_type::MULTIPATH, "path to ROM sets and hard disk images" }, @@ -27,3 +27,16 @@ index 3defd33d0bb..33daacc4fc8 100644 { OPTION_SWPATH, "software", core_options::option_type::MULTIPATH, "path to loose software" }, // output directory options +diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp +index 82fabfdc0ba..eefdaba7fbe 100644 +--- a/src/osd/modules/lib/osdobj_common.cpp ++++ b/src/osd/modules/lib/osdobj_common.cpp +@@ -158,7 +158,7 @@ const options_entry osd_options::s_option_entries[] = + { OSDOPTION_NETWORK_PROVIDER, OSDOPTVAL_AUTO, core_options::option_type::STRING, "Emulated networking provider: " }, + + { nullptr, nullptr, core_options::option_type::HEADER, "BGFX POST-PROCESSING OPTIONS" }, +- { OSDOPTION_BGFX_PATH, "bgfx", core_options::option_type::PATH, "path to BGFX-related files" }, ++ { OSDOPTION_BGFX_PATH, "@mamePath@/bgfx", core_options::option_type::PATH, "path to BGFX-related files" }, + { OSDOPTION_BGFX_BACKEND, "auto", core_options::option_type::STRING, "BGFX backend to use (d3d9, d3d11, d3d12, metal, opengl, gles, vulkan)" }, + { OSDOPTION_BGFX_DEBUG, "0", core_options::option_type::BOOLEAN, "enable BGFX debugging statistics" }, + { OSDOPTION_BGFX_SCREEN_CHAINS, "", core_options::option_type::STRING, "comma-delimited list of screen chain JSON names, colon-delimited per-window" }, diff --git a/pkgs/applications/emulators/mame/default.nix b/pkgs/applications/emulators/mame/default.nix index 0db8ba1d4996..e4e6c97518a3 100644 --- a/pkgs/applications/emulators/mame/default.nix +++ b/pkgs/applications/emulators/mame/default.nix @@ -123,8 +123,10 @@ stdenv.mkDerivation rec { # it is not possible to use substituteAll postPatch = '' - substituteInPlace src/emu/emuopts.cpp \ - --subst-var-by mamePath "$out/opt/mame" + for file in src/emu/emuopts.cpp src/osd/modules/lib/osdobj_common.cpp; do + substituteInPlace "$file" \ + --subst-var-by mamePath "$out/opt/mame" + done '' # MAME's build system uses `sw_vers` to test whether it needs to link with # the Metal framework or not. However: