From 2f4b0cc5db14299505119201eadcae685f2f27f0 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Tue, 23 Dec 2025 00:11:01 +0100 Subject: [PATCH] refactor(cleanup): make configuration a common objet --- lsfg-vk-common/CMakeLists.txt | 5 +++++ .../lsfg-vk-common}/configuration/config.hpp | 2 +- .../lsfg-vk-common}/configuration/detection.hpp | 2 +- .../src/configuration/config.cpp | 6 +++--- .../src/configuration/detection.cpp | 11 +++++------ .../thirdparty/include/toml.hpp | 0 lsfg-vk-layer/CMakeLists.txt | 11 +++-------- lsfg-vk-layer/src/entrypoint.cpp | 8 ++++---- lsfg-vk-layer/src/{context => }/instance.cpp | 13 ++++++------- lsfg-vk-layer/src/{context => }/instance.hpp | 6 +++--- lsfg-vk-layer/src/{context => }/swapchain.cpp | 10 +++++----- lsfg-vk-layer/src/{context => }/swapchain.hpp | 8 ++++---- lsfg-vk-ui/src/backend.cpp | 9 +++++++++ lsfg-vk-ui/src/backend.hpp | 16 ++++++++++++++++ 14 files changed, 65 insertions(+), 42 deletions(-) rename {lsfg-vk-layer/src => lsfg-vk-common/include/lsfg-vk-common}/configuration/config.hpp (98%) rename {lsfg-vk-layer/src => lsfg-vk-common/include/lsfg-vk-common}/configuration/detection.hpp (97%) rename {lsfg-vk-layer => lsfg-vk-common}/src/configuration/config.cpp (98%) rename {lsfg-vk-layer => lsfg-vk-common}/src/configuration/detection.cpp (94%) rename {lsfg-vk-layer => lsfg-vk-common}/thirdparty/include/toml.hpp (100%) rename lsfg-vk-layer/src/{context => }/instance.cpp (96%) rename lsfg-vk-layer/src/{context => }/instance.hpp (95%) rename lsfg-vk-layer/src/{context => }/swapchain.cpp (97%) rename lsfg-vk-layer/src/{context => }/swapchain.hpp (92%) create mode 100644 lsfg-vk-ui/src/backend.cpp create mode 100644 lsfg-vk-ui/src/backend.hpp diff --git a/lsfg-vk-common/CMakeLists.txt b/lsfg-vk-common/CMakeLists.txt index 4048b19..6a05960 100644 --- a/lsfg-vk-common/CMakeLists.txt +++ b/lsfg-vk-common/CMakeLists.txt @@ -1,4 +1,6 @@ set(COMMON_SOURCES + "src/configuration/config.cpp" + "src/configuration/detection.cpp" "src/helpers/errors.cpp" "src/vulkan/buffer.cpp" "src/vulkan/command_buffer.cpp" @@ -16,3 +18,6 @@ add_library(lsfg-vk-common STATIC ${COMMON_SOURCES}) target_include_directories(lsfg-vk-common PUBLIC include) + +target_include_directories(lsfg-vk-common SYSTEM + PRIVATE thirdparty/include) diff --git a/lsfg-vk-layer/src/configuration/config.hpp b/lsfg-vk-common/include/lsfg-vk-common/configuration/config.hpp similarity index 98% rename from lsfg-vk-layer/src/configuration/config.hpp rename to lsfg-vk-common/include/lsfg-vk-common/configuration/config.hpp index 9507b48..7b5f333 100644 --- a/lsfg-vk-layer/src/configuration/config.hpp +++ b/lsfg-vk-common/include/lsfg-vk-common/configuration/config.hpp @@ -6,7 +6,7 @@ #include #include -namespace lsfgvk::layer { +namespace ls { /// global configuration struct GlobalConf { diff --git a/lsfg-vk-layer/src/configuration/detection.hpp b/lsfg-vk-common/include/lsfg-vk-common/configuration/detection.hpp similarity index 97% rename from lsfg-vk-layer/src/configuration/detection.hpp rename to lsfg-vk-common/include/lsfg-vk-common/configuration/detection.hpp index 5ef9f32..48045ed 100644 --- a/lsfg-vk-layer/src/configuration/detection.hpp +++ b/lsfg-vk-common/include/lsfg-vk-common/configuration/detection.hpp @@ -6,7 +6,7 @@ #include #include -namespace lsfgvk::layer { +namespace ls { /// identification data for a process struct Identification { diff --git a/lsfg-vk-layer/src/configuration/config.cpp b/lsfg-vk-common/src/configuration/config.cpp similarity index 98% rename from lsfg-vk-layer/src/configuration/config.cpp rename to lsfg-vk-common/src/configuration/config.cpp index 7adff53..cec9a06 100644 --- a/lsfg-vk-layer/src/configuration/config.cpp +++ b/lsfg-vk-common/src/configuration/config.cpp @@ -1,4 +1,4 @@ -#include "config.hpp" +#include "lsfg-vk-common/configuration/config.hpp" #include "lsfg-vk-common/helpers/errors.hpp" #include @@ -12,10 +12,10 @@ #define TOML_ENABLE_FORMATTERS 0 #include -using namespace lsfgvk::layer; +using namespace ls; namespace { - const char* DEFAULT_CONFIG = R"(version = 2 + constexpr char const* DEFAULT_CONFIG = R"(version = 2 [global] # dll = '/media/games/Lossless Scaling/Lossless.dll' # if you don't have LS in the default location diff --git a/lsfg-vk-layer/src/configuration/detection.cpp b/lsfg-vk-common/src/configuration/detection.cpp similarity index 94% rename from lsfg-vk-layer/src/configuration/detection.cpp rename to lsfg-vk-common/src/configuration/detection.cpp index beaccfd..35cf2d5 100644 --- a/lsfg-vk-layer/src/configuration/detection.cpp +++ b/lsfg-vk-common/src/configuration/detection.cpp @@ -1,5 +1,5 @@ -#include "detection.hpp" -#include "config.hpp" +#include "lsfg-vk-common/configuration/detection.hpp" +#include "lsfg-vk-common/configuration/config.hpp" #include #include @@ -12,8 +12,7 @@ #include -using namespace lsfgvk; -using namespace lsfgvk::layer; +using namespace ls; namespace { // try to match a profile by id @@ -26,7 +25,7 @@ namespace { } } -Identification layer::identify() { +Identification ls::identify() { Identification id{}; // fetch LSFGVK_PROFILE @@ -83,7 +82,7 @@ Identification layer::identify() { return id; } -std::optional> layer::findProfile( +std::optional> ls::findProfile( const Configuration& config, const Identification& id) { const auto& profiles = config.getProfiles(); diff --git a/lsfg-vk-layer/thirdparty/include/toml.hpp b/lsfg-vk-common/thirdparty/include/toml.hpp similarity index 100% rename from lsfg-vk-layer/thirdparty/include/toml.hpp rename to lsfg-vk-common/thirdparty/include/toml.hpp diff --git a/lsfg-vk-layer/CMakeLists.txt b/lsfg-vk-layer/CMakeLists.txt index 630216b..b19efb4 100644 --- a/lsfg-vk-layer/CMakeLists.txt +++ b/lsfg-vk-layer/CMakeLists.txt @@ -1,9 +1,7 @@ set(LAYER_SOURCES - "src/configuration/config.cpp" - "src/configuration/detection.cpp" - "src/context/instance.cpp" - "src/context/swapchain.cpp" - "src/entrypoint.cpp") + "src/entrypoint.cpp" + "src/instance.cpp" + "src/swapchain.cpp") add_library(lsfg-vk-layer SHARED ${LAYER_SOURCES}) @@ -11,8 +9,5 @@ target_link_libraries(lsfg-vk-layer PUBLIC lsfg-vk-common PUBLIC lsfg-vk-backend) -target_include_directories(lsfg-vk-layer SYSTEM - PRIVATE thirdparty/include) - set_target_properties(lsfg-vk-layer PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/lsfg-vk-layer/src/entrypoint.cpp b/lsfg-vk-layer/src/entrypoint.cpp index a82ab4e..abc852a 100644 --- a/lsfg-vk-layer/src/entrypoint.cpp +++ b/lsfg-vk-layer/src/entrypoint.cpp @@ -1,4 +1,4 @@ -#include "context/instance.hpp" +#include "instance.hpp" #include "lsfg-vk-common/helpers/errors.hpp" #include "lsfg-vk-common/helpers/pointers.hpp" #include "lsfg-vk-common/vulkan/vulkan.hpp" @@ -15,7 +15,7 @@ #include #include -using namespace lsfgvk; +using namespace lsfgvk::layer; namespace { // global layer info initialized at layer negotiation @@ -23,7 +23,7 @@ namespace { std::unordered_map map; //!< function pointer override map PFN_vkGetInstanceProcAddr GetInstanceProcAddr; - layer::Root root; + Root root; }* layer_info; // instance-wide info initialized at instance creation @@ -428,7 +428,7 @@ VkResult vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface* pVers { "vkDestroySwapchainKHR", VKPTR(myvkDestroySwapchainKHR) } #undef VKPTR }, - .root = layer::Root() + .root = Root() }; if (!layer_info->root.active()) { // skip inactive diff --git a/lsfg-vk-layer/src/context/instance.cpp b/lsfg-vk-layer/src/instance.cpp similarity index 96% rename from lsfg-vk-layer/src/context/instance.cpp rename to lsfg-vk-layer/src/instance.cpp index 8ddfc28..ad2d987 100644 --- a/lsfg-vk-layer/src/context/instance.cpp +++ b/lsfg-vk-layer/src/instance.cpp @@ -1,7 +1,6 @@ #include "instance.hpp" -#include "../configuration/config.hpp" -#include "../configuration/detection.hpp" #include "swapchain.hpp" +#include "lsfg-vk-common/configuration/detection.hpp" #include "lsfg-vk-common/helpers/errors.hpp" #include "lsfg-vk-common/vulkan/vulkan.hpp" @@ -86,7 +85,7 @@ namespace { Root::Root() { // find active profile this->config.reload(); - const auto& profile = findProfile(this->config, identify()); + const auto& profile = findProfile(this->config, ls::identify()); if (!profile.has_value()) return; @@ -94,16 +93,16 @@ Root::Root() { std::cerr << "lsfg-vk: using profile with name '" << this->active_profile->name << "' "; switch (profile->first) { - case IdentType::OVERRIDE: + case ls::IdentType::OVERRIDE: std::cerr << "(identified via override)\n"; break; - case IdentType::EXECUTABLE: + case ls::IdentType::EXECUTABLE: std::cerr << "(identified via executable)\n"; break; - case IdentType::WINE_EXECUTABLE: + case ls::IdentType::WINE_EXECUTABLE: std::cerr << "(identified via wine executable)\n"; break; - case IdentType::PROCESS_NAME: + case ls::IdentType::PROCESS_NAME: std::cerr << "(identified via process name)\n"; break; } diff --git a/lsfg-vk-layer/src/context/instance.hpp b/lsfg-vk-layer/src/instance.hpp similarity index 95% rename from lsfg-vk-layer/src/context/instance.hpp rename to lsfg-vk-layer/src/instance.hpp index 353146d..ad40272 100644 --- a/lsfg-vk-layer/src/context/instance.hpp +++ b/lsfg-vk-layer/src/instance.hpp @@ -1,7 +1,7 @@ #pragma once -#include "../configuration/config.hpp" #include "lsfg-vk-backend/lsfgvk.hpp" +#include "lsfg-vk-common/configuration/config.hpp" #include "lsfg-vk-common/helpers/errors.hpp" #include "lsfg-vk-common/helpers/pointers.hpp" #include "lsfg-vk-common/vulkan/vulkan.hpp" @@ -67,8 +67,8 @@ namespace lsfgvk::layer { /// @param swapchain swapchain handle void removeSwapchainContext(VkSwapchainKHR swapchain); private: - Configuration config; - std::optional active_profile; + ls::Configuration config; + std::optional active_profile; ls::lazy backend; std::unordered_map swapchains; diff --git a/lsfg-vk-layer/src/context/swapchain.cpp b/lsfg-vk-layer/src/swapchain.cpp similarity index 97% rename from lsfg-vk-layer/src/context/swapchain.cpp rename to lsfg-vk-layer/src/swapchain.cpp index 85015c4..76e8d92 100644 --- a/lsfg-vk-layer/src/context/swapchain.cpp +++ b/lsfg-vk-layer/src/swapchain.cpp @@ -1,6 +1,6 @@ #include "swapchain.hpp" -#include "../configuration/config.hpp" #include "lsfg-vk-backend/lsfgvk.hpp" +#include "lsfg-vk-common/configuration/config.hpp" #include "lsfg-vk-common/helpers/errors.hpp" #include "lsfg-vk-common/helpers/pointers.hpp" #include "lsfg-vk-common/vulkan/command_buffer.hpp" @@ -48,13 +48,13 @@ namespace { } } -void layer::context_ModifySwapchainCreateInfo(const GameConf& profile, uint32_t maxImages, +void layer::context_ModifySwapchainCreateInfo(const ls::GameConf& profile, uint32_t maxImages, VkSwapchainCreateInfoKHR& createInfo) { createInfo.imageUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; switch (profile.pacing) { - case Pacing::None: + case ls::Pacing::None: createInfo.minImageCount += profile.multiplier; if (maxImages && createInfo.minImageCount > maxImages) createInfo.minImageCount = maxImages; @@ -65,7 +65,7 @@ void layer::context_ModifySwapchainCreateInfo(const GameConf& profile, uint32_t } Swapchain::Swapchain(const vk::Vulkan& vk, lsfgvk::backend::Instance& backend, - GameConf profile, SwapchainInfo info) : + ls::GameConf profile, SwapchainInfo info) : instance(backend), profile(std::move(profile)), info(std::move(info)) { const VkExtent2D extent = this->info.extent; @@ -139,7 +139,7 @@ VkResult Swapchain::present(const vk::Vulkan& vk, } // update present mode when not using pacing - if (this->profile.pacing == Pacing::None) { + if (this->profile.pacing == ls::Pacing::None) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" auto* info = reinterpret_cast(next_chain); diff --git a/lsfg-vk-layer/src/context/swapchain.hpp b/lsfg-vk-layer/src/swapchain.hpp similarity index 92% rename from lsfg-vk-layer/src/context/swapchain.hpp rename to lsfg-vk-layer/src/swapchain.hpp index e6885e8..75de2a3 100644 --- a/lsfg-vk-layer/src/context/swapchain.hpp +++ b/lsfg-vk-layer/src/swapchain.hpp @@ -1,7 +1,7 @@ #pragma once -#include "../configuration/config.hpp" #include "lsfg-vk-backend/lsfgvk.hpp" +#include "lsfg-vk-common/configuration/config.hpp" #include "lsfg-vk-common/helpers/pointers.hpp" #include "lsfg-vk-common/vulkan/command_buffer.hpp" #include "lsfg-vk-common/vulkan/fence.hpp" @@ -31,7 +31,7 @@ namespace lsfgvk::layer { /// @param profile active game profile /// @param maxImages maximum number of images supported by the surface /// @param createInfo swapchain create info to modify - void context_ModifySwapchainCreateInfo(const GameConf& profile, uint32_t maxImages, + void context_ModifySwapchainCreateInfo(const ls::GameConf& profile, uint32_t maxImages, VkSwapchainCreateInfoKHR& createInfo); /// swapchain context for a layer instance @@ -43,7 +43,7 @@ namespace lsfgvk::layer { /// @param profile active game profile /// @param info swapchain info Swapchain(const vk::Vulkan& vk, lsfgvk::backend::Instance& backend, - GameConf profile, SwapchainInfo info); + ls::GameConf profile, SwapchainInfo info); /// present a frame /// @param vk vulkan instance @@ -75,7 +75,7 @@ namespace lsfgvk::layer { size_t idx{1}; size_t fidx{0}; // real frame index - GameConf profile; + ls::GameConf profile; SwapchainInfo info; }; diff --git a/lsfg-vk-ui/src/backend.cpp b/lsfg-vk-ui/src/backend.cpp new file mode 100644 index 0000000..036c579 --- /dev/null +++ b/lsfg-vk-ui/src/backend.cpp @@ -0,0 +1,9 @@ +#include "backend.hpp" + +#include + +using namespace lsfgvk::ui; + +Backend::Backend(QObject* parent) : QObject(parent) { + +} diff --git a/lsfg-vk-ui/src/backend.hpp b/lsfg-vk-ui/src/backend.hpp new file mode 100644 index 0000000..19abf41 --- /dev/null +++ b/lsfg-vk-ui/src/backend.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace lsfgvk::ui { + + class Backend : public QObject { + Q_OBJECT + + public: + explicit Backend(QObject* parent = nullptr); + private: + + }; + +}