refactor(cleanup): make configuration a common objet

This commit is contained in:
PancakeTAS 2025-12-23 00:11:01 +01:00
parent e7bfccd7c1
commit 2f4b0cc5db
14 changed files with 65 additions and 42 deletions

View file

@ -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)

View file

@ -6,7 +6,7 @@
#include <string>
#include <vector>
namespace lsfgvk::layer {
namespace ls {
/// global configuration
struct GlobalConf {

View file

@ -6,7 +6,7 @@
#include <string>
#include <utility>
namespace lsfgvk::layer {
namespace ls {
/// identification data for a process
struct Identification {

View file

@ -1,4 +1,4 @@
#include "config.hpp"
#include "lsfg-vk-common/configuration/config.hpp"
#include "lsfg-vk-common/helpers/errors.hpp"
#include <cstdlib>
@ -12,10 +12,10 @@
#define TOML_ENABLE_FORMATTERS 0
#include <toml.hpp>
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

View file

@ -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 <array>
#include <cstdlib>
@ -12,8 +12,7 @@
#include <sys/types.h>
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<std::pair<IdentType, GameConf>> layer::findProfile(
std::optional<std::pair<IdentType, GameConf>> ls::findProfile(
const Configuration& config, const Identification& id) {
const auto& profiles = config.getProfiles();

View file

@ -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)

View file

@ -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 <vulkan/vk_layer.h>
#include <vulkan/vulkan_core.h>
using namespace lsfgvk;
using namespace lsfgvk::layer;
namespace {
// global layer info initialized at layer negotiation
@ -23,7 +23,7 @@ namespace {
std::unordered_map<std::string, PFN_vkVoidFunction> 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

View file

@ -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;
}

View file

@ -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<GameConf> active_profile;
ls::Configuration config;
std::optional<ls::GameConf> active_profile;
ls::lazy<lsfgvk::backend::Instance> backend;
std::unordered_map<VkSwapchainKHR, Swapchain> swapchains;

View file

@ -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<VkSwapchainPresentModeInfoEXT*>(next_chain);

View file

@ -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;
};

View file

@ -0,0 +1,9 @@
#include "backend.hpp"
#include <QObject>
using namespace lsfgvk::ui;
Backend::Backend(QObject* parent) : QObject(parent) {
}

View file

@ -0,0 +1,16 @@
#pragma once
#include <QObject>
namespace lsfgvk::ui {
class Backend : public QObject {
Q_OBJECT
public:
explicit Backend(QObject* parent = nullptr);
private:
};
}