From 82bcf2bb72fcbc4dbff2967db19b76d3114d47f9 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Sat, 12 Jul 2025 18:19:18 +0200 Subject: [PATCH] allow for multiple lsfg versions to coexist --- CMakeLists.txt | 3 +- lsfg-vk-common/CMakeLists.txt | 59 +++++++++++++++++++ lsfg-vk-common/include/common/exception.hpp | 34 +++++++++++ .../include/common}/utils.hpp | 0 .../include/core/buffer.hpp | 0 .../include/core/commandbuffer.hpp | 0 .../include/core/commandpool.hpp | 0 .../include/core/descriptorpool.hpp | 0 .../include/core/descriptorset.hpp | 0 .../include/core/device.hpp | 0 .../include/core/fence.hpp | 0 .../include/core/image.hpp | 0 .../include/core/instance.hpp | 0 .../include/core/pipeline.hpp | 0 .../include/core/sampler.hpp | 0 .../include/core/semaphore.hpp | 0 .../include/core/shadermodule.hpp | 0 .../include/pool/resourcepool.hpp | 0 .../include/pool/shaderpool.hpp | 0 lsfg-vk-common/src/common/exception.cpp | 16 +++++ .../src/common}/utils.cpp | 4 +- .../src/core/buffer.cpp | 2 +- .../src/core/commandbuffer.cpp | 2 +- .../src/core/commandpool.cpp | 2 +- .../src/core/descriptorpool.cpp | 2 +- .../src/core/descriptorset.cpp | 2 +- .../src/core/device.cpp | 2 +- .../src/core/fence.cpp | 2 +- .../src/core/image.cpp | 2 +- .../src/core/instance.cpp | 2 +- .../src/core/pipeline.cpp | 2 +- .../src/core/sampler.cpp | 2 +- .../src/core/semaphore.cpp | 2 +- .../src/core/shadermodule.cpp | 2 +- .../src/pool/resourcepool.cpp | 0 .../src/pool/shaderpool.cpp | 0 lsfg-vk-v3.1/CMakeLists.txt | 4 +- lsfg-vk-v3.1/README.md | 6 +- lsfg-vk-v3.1/include/context.hpp | 2 +- lsfg-vk-v3.1/include/shaders/alpha.hpp | 2 +- lsfg-vk-v3.1/include/shaders/beta.hpp | 2 +- lsfg-vk-v3.1/include/shaders/delta.hpp | 2 +- lsfg-vk-v3.1/include/shaders/gamma.hpp | 2 +- lsfg-vk-v3.1/include/shaders/generate.hpp | 2 +- lsfg-vk-v3.1/include/shaders/mipmaps.hpp | 2 +- lsfg-vk-v3.1/public/lsfg.hpp | 27 +-------- lsfg-vk-v3.1/src/context.cpp | 4 +- lsfg-vk-v3.1/src/lsfg.cpp | 33 +++++------ lsfg-vk-v3.1/src/shaders/alpha.cpp | 2 +- lsfg-vk-v3.1/src/shaders/beta.cpp | 2 +- lsfg-vk-v3.1/src/shaders/delta.cpp | 2 +- lsfg-vk-v3.1/src/shaders/gamma.cpp | 2 +- lsfg-vk-v3.1/src/shaders/generate.cpp | 2 +- lsfg-vk-v3.1/src/shaders/mipmaps.cpp | 2 +- src/context.cpp | 9 +-- src/hooks.cpp | 2 +- src/mini/commandbuffer.cpp | 2 +- src/mini/commandpool.cpp | 2 +- src/mini/image.cpp | 2 +- src/mini/semaphore.cpp | 2 +- src/utils/benchmark.cpp | 6 +- src/utils/utils.cpp | 2 +- 62 files changed, 174 insertions(+), 95 deletions(-) create mode 100644 lsfg-vk-common/CMakeLists.txt create mode 100644 lsfg-vk-common/include/common/exception.hpp rename {lsfg-vk-v3.1/include/utils => lsfg-vk-common/include/common}/utils.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/buffer.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/commandbuffer.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/commandpool.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/descriptorpool.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/descriptorset.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/device.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/fence.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/image.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/instance.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/pipeline.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/sampler.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/semaphore.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/core/shadermodule.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/pool/resourcepool.hpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/include/pool/shaderpool.hpp (100%) create mode 100644 lsfg-vk-common/src/common/exception.cpp rename {lsfg-vk-v3.1/src/utils => lsfg-vk-common/src/common}/utils.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/buffer.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/commandbuffer.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/commandpool.cpp (96%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/descriptorpool.cpp (97%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/descriptorset.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/device.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/fence.cpp (97%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/image.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/instance.cpp (97%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/pipeline.cpp (98%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/sampler.cpp (97%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/semaphore.cpp (99%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/core/shadermodule.cpp (98%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/pool/resourcepool.cpp (100%) rename {lsfg-vk-v3.1 => lsfg-vk-common}/src/pool/shaderpool.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca7a3c6..cd59fc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ endif() include(cmake/FetchDXVK.cmake) include(cmake/FetchPeParse.cmake) +add_subdirectory(lsfg-vk-common) add_subdirectory(lsfg-vk-v3.1) # main project @@ -38,7 +39,7 @@ set_target_properties(lsfg-vk PROPERTIES target_include_directories(lsfg-vk PRIVATE include) target_link_libraries(lsfg-vk - PRIVATE lsfg-vk-v3.1 peparse dxvk vulkan) + PRIVATE lsfg-vk-common lsfg-vk-v3.1 peparse dxvk vulkan) if(CMAKE_BUILD_TYPE STREQUAL "Release") set_target_properties(lsfg-vk PROPERTIES diff --git a/lsfg-vk-common/CMakeLists.txt b/lsfg-vk-common/CMakeLists.txt new file mode 100644 index 0000000..50b4525 --- /dev/null +++ b/lsfg-vk-common/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required(VERSION 3.29) + +# project +project(lsfg-vk-common + LANGUAGES CXX) + +file(GLOB SOURCES + "src/core/*.cpp" + "src/pool/*.cpp" + "src/common/*.cpp" + "src/*.cpp" +) + +add_library(lsfg-vk-common STATIC ${SOURCES}) + +# target +set_target_properties(lsfg-vk-common PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON) +target_include_directories(lsfg-vk-common + PUBLIC include) +target_link_libraries(lsfg-vk-common + PRIVATE vulkan) +target_compile_options(lsfg-vk-common PRIVATE + -fPIC) + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set_target_properties(lsfg-vk-common PROPERTIES + INTERPROCEDURAL_OPTIMIZATION ON) +endif() + +# diagnostics +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set_target_properties(lsfg-vk-common PROPERTIES + EXPORT_COMPILE_COMMANDS ON) +endif() + +if(LSFGVK_EXCESS_DEBUG) + target_compile_options(lsfg-vk-common PRIVATE + -Weverything + # disable compat c++ flags + -Wno-pre-c++20-compat-pedantic + -Wno-pre-c++17-compat + -Wno-c++98-compat-pedantic + -Wno-c++98-compat + # disable other flags + -Wno-missing-designated-field-initializers + -Wno-shadow # allow shadowing + -Wno-switch-enum # ignore missing cases + -Wno-switch-default # ignore missing default + -Wno-padded # ignore automatic padding + -Wno-exit-time-destructors # allow globals + -Wno-global-constructors # allow globals + -Wno-cast-function-type-strict # for vulkan + ) + + set_target_properties(lsfg-vk-common PROPERTIES + CXX_CLANG_TIDY clang-tidy) +endif() diff --git a/lsfg-vk-common/include/common/exception.hpp b/lsfg-vk-common/include/common/exception.hpp new file mode 100644 index 0000000..3808ca8 --- /dev/null +++ b/lsfg-vk-common/include/common/exception.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include + +#include +#include + +namespace LSFG { + + /// Simple exception class for Vulkan errors. + class vulkan_error : public std::runtime_error { + public: + /// + /// Construct a vulkan_error with a message and a Vulkan result code. + /// + /// @param result The Vulkan result code associated with the error. + /// @param message The error message. + /// + explicit vulkan_error(VkResult result, const std::string& message); + + /// Get the Vulkan result code associated with this error. + [[nodiscard]] VkResult error() const { return this->result; } + + // Trivially copyable, moveable and destructible + vulkan_error(const vulkan_error&) = default; + vulkan_error(vulkan_error&&) = default; + vulkan_error& operator=(const vulkan_error&) = default; + vulkan_error& operator=(vulkan_error&&) = default; + ~vulkan_error() noexcept override; + private: + VkResult result; + }; + +} diff --git a/lsfg-vk-v3.1/include/utils/utils.hpp b/lsfg-vk-common/include/common/utils.hpp similarity index 100% rename from lsfg-vk-v3.1/include/utils/utils.hpp rename to lsfg-vk-common/include/common/utils.hpp diff --git a/lsfg-vk-v3.1/include/core/buffer.hpp b/lsfg-vk-common/include/core/buffer.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/buffer.hpp rename to lsfg-vk-common/include/core/buffer.hpp diff --git a/lsfg-vk-v3.1/include/core/commandbuffer.hpp b/lsfg-vk-common/include/core/commandbuffer.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/commandbuffer.hpp rename to lsfg-vk-common/include/core/commandbuffer.hpp diff --git a/lsfg-vk-v3.1/include/core/commandpool.hpp b/lsfg-vk-common/include/core/commandpool.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/commandpool.hpp rename to lsfg-vk-common/include/core/commandpool.hpp diff --git a/lsfg-vk-v3.1/include/core/descriptorpool.hpp b/lsfg-vk-common/include/core/descriptorpool.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/descriptorpool.hpp rename to lsfg-vk-common/include/core/descriptorpool.hpp diff --git a/lsfg-vk-v3.1/include/core/descriptorset.hpp b/lsfg-vk-common/include/core/descriptorset.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/descriptorset.hpp rename to lsfg-vk-common/include/core/descriptorset.hpp diff --git a/lsfg-vk-v3.1/include/core/device.hpp b/lsfg-vk-common/include/core/device.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/device.hpp rename to lsfg-vk-common/include/core/device.hpp diff --git a/lsfg-vk-v3.1/include/core/fence.hpp b/lsfg-vk-common/include/core/fence.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/fence.hpp rename to lsfg-vk-common/include/core/fence.hpp diff --git a/lsfg-vk-v3.1/include/core/image.hpp b/lsfg-vk-common/include/core/image.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/image.hpp rename to lsfg-vk-common/include/core/image.hpp diff --git a/lsfg-vk-v3.1/include/core/instance.hpp b/lsfg-vk-common/include/core/instance.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/instance.hpp rename to lsfg-vk-common/include/core/instance.hpp diff --git a/lsfg-vk-v3.1/include/core/pipeline.hpp b/lsfg-vk-common/include/core/pipeline.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/pipeline.hpp rename to lsfg-vk-common/include/core/pipeline.hpp diff --git a/lsfg-vk-v3.1/include/core/sampler.hpp b/lsfg-vk-common/include/core/sampler.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/sampler.hpp rename to lsfg-vk-common/include/core/sampler.hpp diff --git a/lsfg-vk-v3.1/include/core/semaphore.hpp b/lsfg-vk-common/include/core/semaphore.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/semaphore.hpp rename to lsfg-vk-common/include/core/semaphore.hpp diff --git a/lsfg-vk-v3.1/include/core/shadermodule.hpp b/lsfg-vk-common/include/core/shadermodule.hpp similarity index 100% rename from lsfg-vk-v3.1/include/core/shadermodule.hpp rename to lsfg-vk-common/include/core/shadermodule.hpp diff --git a/lsfg-vk-v3.1/include/pool/resourcepool.hpp b/lsfg-vk-common/include/pool/resourcepool.hpp similarity index 100% rename from lsfg-vk-v3.1/include/pool/resourcepool.hpp rename to lsfg-vk-common/include/pool/resourcepool.hpp diff --git a/lsfg-vk-v3.1/include/pool/shaderpool.hpp b/lsfg-vk-common/include/pool/shaderpool.hpp similarity index 100% rename from lsfg-vk-v3.1/include/pool/shaderpool.hpp rename to lsfg-vk-common/include/pool/shaderpool.hpp diff --git a/lsfg-vk-common/src/common/exception.cpp b/lsfg-vk-common/src/common/exception.cpp new file mode 100644 index 0000000..f675833 --- /dev/null +++ b/lsfg-vk-common/src/common/exception.cpp @@ -0,0 +1,16 @@ +#include "common/exception.hpp" + +#include + +#include +#include +#include +#include + +using namespace LSFG; + +vulkan_error::vulkan_error(VkResult result, const std::string& message) + : std::runtime_error(std::format("{} (error {})", message, static_cast(result))), + result(result) {} + +vulkan_error::~vulkan_error() noexcept = default; diff --git a/lsfg-vk-v3.1/src/utils/utils.cpp b/lsfg-vk-common/src/common/utils.cpp similarity index 99% rename from lsfg-vk-v3.1/src/utils/utils.cpp rename to lsfg-vk-common/src/common/utils.cpp index 5aea8fd..5b083ee 100644 --- a/lsfg-vk-v3.1/src/utils/utils.cpp +++ b/lsfg-vk-common/src/common/utils.cpp @@ -1,10 +1,10 @@ -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/buffer.hpp" #include "core/image.hpp" #include "core/device.hpp" #include "core/commandpool.hpp" #include "core/fence.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/buffer.cpp b/lsfg-vk-common/src/core/buffer.cpp similarity index 99% rename from lsfg-vk-v3.1/src/core/buffer.cpp rename to lsfg-vk-common/src/core/buffer.cpp index c18a8ae..001c77b 100644 --- a/lsfg-vk-v3.1/src/core/buffer.cpp +++ b/lsfg-vk-common/src/core/buffer.cpp @@ -1,6 +1,6 @@ #include "core/buffer.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/commandbuffer.cpp b/lsfg-vk-common/src/core/commandbuffer.cpp similarity index 99% rename from lsfg-vk-v3.1/src/core/commandbuffer.cpp rename to lsfg-vk-common/src/core/commandbuffer.cpp index 84999de..762db6a 100644 --- a/lsfg-vk-v3.1/src/core/commandbuffer.cpp +++ b/lsfg-vk-common/src/core/commandbuffer.cpp @@ -3,7 +3,7 @@ #include "core/commandpool.hpp" #include "core/fence.hpp" #include "core/semaphore.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/commandpool.cpp b/lsfg-vk-common/src/core/commandpool.cpp similarity index 96% rename from lsfg-vk-v3.1/src/core/commandpool.cpp rename to lsfg-vk-common/src/core/commandpool.cpp index 377de39..ffa89de 100644 --- a/lsfg-vk-v3.1/src/core/commandpool.cpp +++ b/lsfg-vk-common/src/core/commandpool.cpp @@ -1,6 +1,6 @@ #include "core/commandpool.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/descriptorpool.cpp b/lsfg-vk-common/src/core/descriptorpool.cpp similarity index 97% rename from lsfg-vk-v3.1/src/core/descriptorpool.cpp rename to lsfg-vk-common/src/core/descriptorpool.cpp index ac08956..f9cd359 100644 --- a/lsfg-vk-v3.1/src/core/descriptorpool.cpp +++ b/lsfg-vk-common/src/core/descriptorpool.cpp @@ -1,6 +1,6 @@ #include "core/descriptorpool.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/descriptorset.cpp b/lsfg-vk-common/src/core/descriptorset.cpp similarity index 99% rename from lsfg-vk-v3.1/src/core/descriptorset.cpp rename to lsfg-vk-common/src/core/descriptorset.cpp index b8f95a2..e72ba72 100644 --- a/lsfg-vk-v3.1/src/core/descriptorset.cpp +++ b/lsfg-vk-common/src/core/descriptorset.cpp @@ -7,7 +7,7 @@ #include "core/image.hpp" #include "core/sampler.hpp" #include "core/buffer.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/device.cpp b/lsfg-vk-common/src/core/device.cpp similarity index 99% rename from lsfg-vk-v3.1/src/core/device.cpp rename to lsfg-vk-common/src/core/device.cpp index 81ec914..72cfa4b 100644 --- a/lsfg-vk-v3.1/src/core/device.cpp +++ b/lsfg-vk-common/src/core/device.cpp @@ -1,6 +1,6 @@ #include "core/device.hpp" #include "core/instance.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/fence.cpp b/lsfg-vk-common/src/core/fence.cpp similarity index 97% rename from lsfg-vk-v3.1/src/core/fence.cpp rename to lsfg-vk-common/src/core/fence.cpp index 52a05a2..e402019 100644 --- a/lsfg-vk-v3.1/src/core/fence.cpp +++ b/lsfg-vk-common/src/core/fence.cpp @@ -1,6 +1,6 @@ #include "core/fence.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/image.cpp b/lsfg-vk-common/src/core/image.cpp similarity index 99% rename from lsfg-vk-v3.1/src/core/image.cpp rename to lsfg-vk-common/src/core/image.cpp index 9eb333d..50b522e 100644 --- a/lsfg-vk-v3.1/src/core/image.cpp +++ b/lsfg-vk-common/src/core/image.cpp @@ -1,6 +1,6 @@ #include "core/image.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/instance.cpp b/lsfg-vk-common/src/core/instance.cpp similarity index 97% rename from lsfg-vk-v3.1/src/core/instance.cpp rename to lsfg-vk-common/src/core/instance.cpp index 29203fc..1302b7a 100644 --- a/lsfg-vk-v3.1/src/core/instance.cpp +++ b/lsfg-vk-common/src/core/instance.cpp @@ -1,5 +1,5 @@ #include "core/instance.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include #include diff --git a/lsfg-vk-v3.1/src/core/pipeline.cpp b/lsfg-vk-common/src/core/pipeline.cpp similarity index 98% rename from lsfg-vk-v3.1/src/core/pipeline.cpp rename to lsfg-vk-common/src/core/pipeline.cpp index cff1bd6..e3dfd9d 100644 --- a/lsfg-vk-v3.1/src/core/pipeline.cpp +++ b/lsfg-vk-common/src/core/pipeline.cpp @@ -2,7 +2,7 @@ #include "core/device.hpp" #include "core/shadermodule.hpp" #include "core/commandbuffer.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/sampler.cpp b/lsfg-vk-common/src/core/sampler.cpp similarity index 97% rename from lsfg-vk-v3.1/src/core/sampler.cpp rename to lsfg-vk-common/src/core/sampler.cpp index 0b82a8f..f44fe2d 100644 --- a/lsfg-vk-v3.1/src/core/sampler.cpp +++ b/lsfg-vk-common/src/core/sampler.cpp @@ -1,6 +1,6 @@ #include "core/sampler.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/semaphore.cpp b/lsfg-vk-common/src/core/semaphore.cpp similarity index 99% rename from lsfg-vk-v3.1/src/core/semaphore.cpp rename to lsfg-vk-common/src/core/semaphore.cpp index 0ef4de9..57bcd42 100644 --- a/lsfg-vk-v3.1/src/core/semaphore.cpp +++ b/lsfg-vk-common/src/core/semaphore.cpp @@ -1,6 +1,6 @@ #include "core/semaphore.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/core/shadermodule.cpp b/lsfg-vk-common/src/core/shadermodule.cpp similarity index 98% rename from lsfg-vk-v3.1/src/core/shadermodule.cpp rename to lsfg-vk-common/src/core/shadermodule.cpp index 50b36b2..099b08b 100644 --- a/lsfg-vk-v3.1/src/core/shadermodule.cpp +++ b/lsfg-vk-common/src/core/shadermodule.cpp @@ -1,6 +1,6 @@ #include "core/shadermodule.hpp" #include "core/device.hpp" -#include "lsfg.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/pool/resourcepool.cpp b/lsfg-vk-common/src/pool/resourcepool.cpp similarity index 100% rename from lsfg-vk-v3.1/src/pool/resourcepool.cpp rename to lsfg-vk-common/src/pool/resourcepool.cpp diff --git a/lsfg-vk-v3.1/src/pool/shaderpool.cpp b/lsfg-vk-common/src/pool/shaderpool.cpp similarity index 100% rename from lsfg-vk-v3.1/src/pool/shaderpool.cpp rename to lsfg-vk-common/src/pool/shaderpool.cpp diff --git a/lsfg-vk-v3.1/CMakeLists.txt b/lsfg-vk-v3.1/CMakeLists.txt index 2b1042c..314c0ad 100644 --- a/lsfg-vk-v3.1/CMakeLists.txt +++ b/lsfg-vk-v3.1/CMakeLists.txt @@ -5,8 +5,6 @@ project(lsfg-vk-v3.1 DESCRIPTION "Lossless Scaling Frame Generation v3.1" LANGUAGES CXX) -option(LDFGVK_EXCESS_DEBUG "Enable excessive debug output" OFF) - file(GLOB SOURCES "src/core/*.cpp" "src/pool/*.cpp" @@ -25,7 +23,7 @@ target_include_directories(lsfg-vk-v3.1 PRIVATE include PUBLIC public) target_link_libraries(lsfg-vk-v3.1 - PRIVATE vulkan) + PUBLIC lsfg-vk-common vulkan) target_compile_options(lsfg-vk-v3.1 PRIVATE -fPIC) diff --git a/lsfg-vk-v3.1/README.md b/lsfg-vk-v3.1/README.md index 016bfa4..238e37b 100644 --- a/lsfg-vk-v3.1/README.md +++ b/lsfg-vk-v3.1/README.md @@ -7,8 +7,8 @@ The project is intentionally structured as a fully external project, such that i ### Interface -Interfacing with lsfg-vk-v3.1 is done via `lsfg.hpp` header. The internal Vulkan instance is created using `LSFG::initialize()` and requires a specific deviceUUID, as well as parts of the lsfg-vk configuration, including a function loading SPIR-V shaders by name. Cleanup is done via `LSFG::finalize()` after which `LSFG::initialize()` may be called again. Please note that the initialization process is expensive and may take a while. It is recommended to call this function once during the applications lifetime. +Interfacing with lsfg-vk-v3.1 is done via `lsfg.hpp` header. The internal Vulkan instance is created using `LSFG_3_1::initialize()` and requires a specific deviceUUID, as well as parts of the lsfg-vk configuration, including a function loading SPIR-V shaders by name. Cleanup is done via `LSFG_3_1::finalize()` after which `LSFG_3_1::initialize()` may be called again. Please note that the initialization process is expensive and may take a while. It is recommended to call this function once during the applications lifetime. -Once the format and extent of the requested images is determined, `LSFG::createContext()` should be called to initialize a frame generation context. The Vulkan images are created from backing memory, which is passed through the file descriptor arguments. A context can be destroyed using `LSFG::deleteContext()`. +Once the format and extent of the requested images is determined, `LSFG_3_1::createContext()` should be called to initialize a frame generation context. The Vulkan images are created from backing memory, which is passed through the file descriptor arguments. A context can be destroyed using `LSFG_3_1::deleteContext()`. -Presenting the context can be done via `LSFG::presentContext()`. Before calling the function a second time, make sure the outgoing semaphores have been signaled. +Presenting the context can be done via `LSFG_3_1::presentContext()`. Before calling the function a second time, make sure the outgoing semaphores have been signaled. diff --git a/lsfg-vk-v3.1/include/context.hpp b/lsfg-vk-v3.1/include/context.hpp index 6283236..3819f02 100644 --- a/lsfg-vk-v3.1/include/context.hpp +++ b/lsfg-vk-v3.1/include/context.hpp @@ -10,7 +10,7 @@ #include "shaders/gamma.hpp" #include "shaders/generate.hpp" #include "shaders/mipmaps.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include diff --git a/lsfg-vk-v3.1/include/shaders/alpha.hpp b/lsfg-vk-v3.1/include/shaders/alpha.hpp index fa48ec2..c837264 100644 --- a/lsfg-vk-v3.1/include/shaders/alpha.hpp +++ b/lsfg-vk-v3.1/include/shaders/alpha.hpp @@ -6,7 +6,7 @@ #include "core/pipeline.hpp" #include "core/sampler.hpp" #include "core/shadermodule.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include #include diff --git a/lsfg-vk-v3.1/include/shaders/beta.hpp b/lsfg-vk-v3.1/include/shaders/beta.hpp index b8e2a2b..6921673 100644 --- a/lsfg-vk-v3.1/include/shaders/beta.hpp +++ b/lsfg-vk-v3.1/include/shaders/beta.hpp @@ -7,7 +7,7 @@ #include "core/pipeline.hpp" #include "core/sampler.hpp" #include "core/shadermodule.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include #include diff --git a/lsfg-vk-v3.1/include/shaders/delta.hpp b/lsfg-vk-v3.1/include/shaders/delta.hpp index 5e81aec..52a64d8 100644 --- a/lsfg-vk-v3.1/include/shaders/delta.hpp +++ b/lsfg-vk-v3.1/include/shaders/delta.hpp @@ -7,7 +7,7 @@ #include "core/pipeline.hpp" #include "core/sampler.hpp" #include "core/shadermodule.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include #include diff --git a/lsfg-vk-v3.1/include/shaders/gamma.hpp b/lsfg-vk-v3.1/include/shaders/gamma.hpp index 0f09ab3..6298bb3 100644 --- a/lsfg-vk-v3.1/include/shaders/gamma.hpp +++ b/lsfg-vk-v3.1/include/shaders/gamma.hpp @@ -7,7 +7,7 @@ #include "core/pipeline.hpp" #include "core/sampler.hpp" #include "core/shadermodule.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include #include diff --git a/lsfg-vk-v3.1/include/shaders/generate.hpp b/lsfg-vk-v3.1/include/shaders/generate.hpp index 1a6ecb7..cf8d5f4 100644 --- a/lsfg-vk-v3.1/include/shaders/generate.hpp +++ b/lsfg-vk-v3.1/include/shaders/generate.hpp @@ -7,7 +7,7 @@ #include "core/pipeline.hpp" #include "core/sampler.hpp" #include "core/shadermodule.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include diff --git a/lsfg-vk-v3.1/include/shaders/mipmaps.hpp b/lsfg-vk-v3.1/include/shaders/mipmaps.hpp index 741c93c..cdffed7 100644 --- a/lsfg-vk-v3.1/include/shaders/mipmaps.hpp +++ b/lsfg-vk-v3.1/include/shaders/mipmaps.hpp @@ -7,7 +7,7 @@ #include "core/pipeline.hpp" #include "core/sampler.hpp" #include "core/shadermodule.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include #include diff --git a/lsfg-vk-v3.1/public/lsfg.hpp b/lsfg-vk-v3.1/public/lsfg.hpp index 3ebfee8..ae8b86e 100644 --- a/lsfg-vk-v3.1/public/lsfg.hpp +++ b/lsfg-vk-v3.1/public/lsfg.hpp @@ -3,12 +3,11 @@ #include #include -#include #include #include #include -namespace LSFG { +namespace LSFG_3_1 { /// /// Initialize the LSFG library. @@ -64,28 +63,4 @@ namespace LSFG { /// void finalize(); - /// Simple exception class for Vulkan errors. - class vulkan_error : public std::runtime_error { - public: - /// - /// Construct a vulkan_error with a message and a Vulkan result code. - /// - /// @param result The Vulkan result code associated with the error. - /// @param message The error message. - /// - explicit vulkan_error(VkResult result, const std::string& message); - - /// Get the Vulkan result code associated with this error. - [[nodiscard]] VkResult error() const { return this->result; } - - // Trivially copyable, moveable and destructible - vulkan_error(const vulkan_error&) = default; - vulkan_error(vulkan_error&&) = default; - vulkan_error& operator=(const vulkan_error&) = default; - vulkan_error& operator=(vulkan_error&&) = default; - ~vulkan_error() noexcept override; - private: - VkResult result; - }; - } diff --git a/lsfg-vk-v3.1/src/context.cpp b/lsfg-vk-v3.1/src/context.cpp index 5bd9d51..0e45687 100644 --- a/lsfg-vk-v3.1/src/context.cpp +++ b/lsfg-vk-v3.1/src/context.cpp @@ -1,6 +1,6 @@ #include "context.hpp" -#include "lsfg.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" +#include "common/exception.hpp" #include diff --git a/lsfg-vk-v3.1/src/lsfg.cpp b/lsfg-vk-v3.1/src/lsfg.cpp index 49fc018..7873e8a 100644 --- a/lsfg-vk-v3.1/src/lsfg.cpp +++ b/lsfg-vk-v3.1/src/lsfg.cpp @@ -4,22 +4,22 @@ #include "core/descriptorpool.hpp" #include "core/instance.hpp" #include "pool/shaderpool.hpp" -#include "utils/utils.hpp" +#include "common/exception.hpp" +#include "common/utils.hpp" #include #include +#include #include #include -#include -#include #include #include -#include #include #include using namespace LSFG; +using namespace LSFG_3_1; namespace { std::optional instance; @@ -27,7 +27,7 @@ namespace { std::unordered_map contexts; } -void LSFG::initialize(uint64_t deviceUUID, +void LSFG_3_1::initialize(uint64_t deviceUUID, bool isHdr, float flowScale, uint64_t generationCount, const std::function(const std::string&)>& loader) { if (instance.has_value() || device.has_value()) @@ -51,41 +51,41 @@ void LSFG::initialize(uint64_t deviceUUID, std::srand(static_cast(std::time(nullptr))); } -int32_t LSFG::createContext( +int32_t LSFG_3_1::createContext( int in0, int in1, const std::vector& outN, VkExtent2D extent, VkFormat format) { if (!instance.has_value() || !device.has_value()) - throw vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "LSFG not initialized"); + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "LSFG not initialized"); const int32_t id = std::rand(); contexts.emplace(id, Context(*device, in0, in1, outN, extent, format)); return id; } -void LSFG::presentContext(int32_t id, int inSem, const std::vector& outSem) { +void LSFG_3_1::presentContext(int32_t id, int inSem, const std::vector& outSem) { if (!instance.has_value() || !device.has_value()) - throw vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "LSFG not initialized"); + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "LSFG not initialized"); auto it = contexts.find(id); if (it == contexts.end()) - throw vulkan_error(VK_ERROR_UNKNOWN, "Context not found"); + throw LSFG::vulkan_error(VK_ERROR_UNKNOWN, "Context not found"); it->second.present(*device, inSem, outSem); } -void LSFG::deleteContext(int32_t id) { +void LSFG_3_1::deleteContext(int32_t id) { if (!instance.has_value() || !device.has_value()) - throw vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "LSFG not initialized"); + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "LSFG not initialized"); auto it = contexts.find(id); if (it == contexts.end()) - throw vulkan_error(VK_ERROR_DEVICE_LOST, "No such context"); + throw LSFG::vulkan_error(VK_ERROR_DEVICE_LOST, "No such context"); vkDeviceWaitIdle(device->device.handle()); contexts.erase(it); } -void LSFG::finalize() { +void LSFG_3_1::finalize() { if (!instance.has_value() || !device.has_value()) return; @@ -94,8 +94,3 @@ void LSFG::finalize() { device.reset(); instance.reset(); } - -vulkan_error::vulkan_error(VkResult result, const std::string& message) - : std::runtime_error(std::format("{} (error {})", message, static_cast(result))), result(result) {} - -vulkan_error::~vulkan_error() noexcept = default; diff --git a/lsfg-vk-v3.1/src/shaders/alpha.cpp b/lsfg-vk-v3.1/src/shaders/alpha.cpp index 7eb3019..79c555c 100644 --- a/lsfg-vk-v3.1/src/shaders/alpha.cpp +++ b/lsfg-vk-v3.1/src/shaders/alpha.cpp @@ -1,5 +1,5 @@ #include "shaders/alpha.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/commandbuffer.hpp" #include "core/image.hpp" diff --git a/lsfg-vk-v3.1/src/shaders/beta.cpp b/lsfg-vk-v3.1/src/shaders/beta.cpp index afa185a..64b3fd3 100644 --- a/lsfg-vk-v3.1/src/shaders/beta.cpp +++ b/lsfg-vk-v3.1/src/shaders/beta.cpp @@ -1,5 +1,5 @@ #include "shaders/beta.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/commandbuffer.hpp" #include "core/image.hpp" diff --git a/lsfg-vk-v3.1/src/shaders/delta.cpp b/lsfg-vk-v3.1/src/shaders/delta.cpp index 548ab39..8c05f20 100644 --- a/lsfg-vk-v3.1/src/shaders/delta.cpp +++ b/lsfg-vk-v3.1/src/shaders/delta.cpp @@ -1,5 +1,5 @@ #include "shaders/delta.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/commandbuffer.hpp" #include "core/image.hpp" diff --git a/lsfg-vk-v3.1/src/shaders/gamma.cpp b/lsfg-vk-v3.1/src/shaders/gamma.cpp index 647e31a..e703d4e 100644 --- a/lsfg-vk-v3.1/src/shaders/gamma.cpp +++ b/lsfg-vk-v3.1/src/shaders/gamma.cpp @@ -1,5 +1,5 @@ #include "shaders/gamma.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/commandbuffer.hpp" #include "core/image.hpp" diff --git a/lsfg-vk-v3.1/src/shaders/generate.cpp b/lsfg-vk-v3.1/src/shaders/generate.cpp index 95c2f74..dde317c 100644 --- a/lsfg-vk-v3.1/src/shaders/generate.cpp +++ b/lsfg-vk-v3.1/src/shaders/generate.cpp @@ -1,5 +1,5 @@ #include "shaders/generate.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/commandbuffer.hpp" #include "core/image.hpp" diff --git a/lsfg-vk-v3.1/src/shaders/mipmaps.cpp b/lsfg-vk-v3.1/src/shaders/mipmaps.cpp index 8bd4a40..eab1e91 100644 --- a/lsfg-vk-v3.1/src/shaders/mipmaps.cpp +++ b/lsfg-vk-v3.1/src/shaders/mipmaps.cpp @@ -1,5 +1,5 @@ #include "shaders/mipmaps.hpp" -#include "utils/utils.hpp" +#include "common/utils.hpp" #include "core/image.hpp" #include "core/commandbuffer.hpp" diff --git a/src/context.cpp b/src/context.cpp index ebbc269..ae1bcdf 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -5,6 +5,7 @@ #include "utils/log.hpp" #include "hooks.hpp" #include "layer.hpp" +#include "common/exception.hpp" #include #include @@ -75,7 +76,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain, Log::debug("context", "(entering LSFG initialization)"); setenv("DISABLE_LSFG", "1", 1); // NOLINT Extract::extractShaders(); - LSFG::initialize( + LSFG_3_1::initialize( Utils::getDeviceUUID(info.physicalDevice), isHdr, 1.0F / flowScale, info.frameGen, [](const std::string& name) { @@ -90,12 +91,12 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain, // create lsfg context Log::debug("context", "(entering LSFG context creation)"); this->lsfgCtxId = std::shared_ptr( - new int32_t(LSFG::createContext(frame_0_fd, frame_1_fd, out_n_fds, + new int32_t(LSFG_3_1::createContext(frame_0_fd, frame_1_fd, out_n_fds, extent, format)), [](const int32_t* id) { Log::info("context", "(entering LSFG context deletion with id: {})", *id); - LSFG::deleteContext(*id); + LSFG_3_1::deleteContext(*id); Log::info("context", "(exiting LSFG context deletion with id: {})", *id); } @@ -156,7 +157,7 @@ VkResult LsContext::present(const Hooks::DeviceInfo& info, const void* pNext, Vk Log::debug("context2", "(entering LSFG present with id: {})", *this->lsfgCtxId); - LSFG::presentContext(*this->lsfgCtxId, + LSFG_3_1::presentContext(*this->lsfgCtxId, preCopySemaphoreFd, renderSemaphoreFds); Log::debug("context2", diff --git a/src/hooks.cpp b/src/hooks.cpp index dff7d95..c589b79 100644 --- a/src/hooks.cpp +++ b/src/hooks.cpp @@ -3,8 +3,8 @@ #include "layer.hpp" #include "utils/log.hpp" #include "utils/utils.hpp" +#include "common/exception.hpp" -#include #include #include diff --git a/src/mini/commandbuffer.cpp b/src/mini/commandbuffer.cpp index d7eb230..3b0e49a 100644 --- a/src/mini/commandbuffer.cpp +++ b/src/mini/commandbuffer.cpp @@ -1,9 +1,9 @@ #include "mini/commandbuffer.hpp" #include "mini/commandpool.hpp" +#include "common/exception.hpp" #include "layer.hpp" #include -#include #include #include diff --git a/src/mini/commandpool.cpp b/src/mini/commandpool.cpp index bd63454..e43c7db 100644 --- a/src/mini/commandpool.cpp +++ b/src/mini/commandpool.cpp @@ -1,7 +1,7 @@ #include "mini/commandpool.hpp" +#include "common/exception.hpp" #include "layer.hpp" -#include #include #include diff --git a/src/mini/image.cpp b/src/mini/image.cpp index 6b74864..978c67c 100644 --- a/src/mini/image.cpp +++ b/src/mini/image.cpp @@ -1,8 +1,8 @@ #include "mini/image.hpp" +#include "common/exception.hpp" #include "layer.hpp" #include -#include #include #include diff --git a/src/mini/semaphore.cpp b/src/mini/semaphore.cpp index c240c87..cd03031 100644 --- a/src/mini/semaphore.cpp +++ b/src/mini/semaphore.cpp @@ -1,7 +1,7 @@ #include "mini/semaphore.hpp" +#include "common/exception.hpp" #include "layer.hpp" -#include #include #include diff --git a/src/utils/benchmark.cpp b/src/utils/benchmark.cpp index 3f805e7..cb1afbf 100644 --- a/src/utils/benchmark.cpp +++ b/src/utils/benchmark.cpp @@ -55,7 +55,7 @@ namespace { ? std::stoull(std::string(lsfgDeviceUUID), nullptr, 16) : 0x1463ABAC; Extract::extractShaders(); - LSFG::initialize( + LSFG_3_1::initialize( deviceUUID, // some magic number if not given isHdr, 1.0F / flowScale, multiplier - 1, [](const std::string& name) -> std::vector { @@ -64,7 +64,7 @@ namespace { return spirv; } ); - const int32_t ctx = LSFG::createContext(-1, -1, {}, + const int32_t ctx = LSFG_3_1::createContext(-1, -1, {}, { .width = width, .height = height }, isHdr ? VK_FORMAT_R16G16B16A16_SFLOAT : VK_FORMAT_R8G8B8A8_UNORM ); @@ -75,7 +75,7 @@ namespace { const auto now = std::chrono::high_resolution_clock::now(); const uint64_t iterations = (8 * 500) + 1; for (uint64_t count = 0; count < iterations; count++) { - LSFG::presentContext(ctx, -1, {}); + LSFG_3_1::presentContext(ctx, -1, {}); if (count % 500 == 0) Log::info("bench", "{:.2f}% done ({}/{})", diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index d09de7f..8340464 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -1,8 +1,8 @@ #include "utils/utils.hpp" #include "utils/log.hpp" +#include "common/exception.hpp" #include "layer.hpp" -#include #include #include