implement lsfg 3.1 into main project

fixes #39 fixes #40 fixes #43
This commit is contained in:
PancakeTAS 2025-07-10 16:16:25 +02:00
parent 7e1d46189e
commit 3b302e63d8
No known key found for this signature in database
3 changed files with 68 additions and 40 deletions

View file

@ -1,62 +1,72 @@
cmake_minimum_required(VERSION 3.29)
# cmake options
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SKIP_RPATH ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("-DLSFG_NO_DEBUG")
endif()
# subprojects
set(CMAKE_SKIP_RPATH ON)
include(cmake/FetchDXVK.cmake)
include(cmake/FetchPeParse.cmake)
add_subdirectory(lsfg-vk-gen)
add_subdirectory(lsfg-vk-v3.1)
# main project
project(lsfg-vk
VERSION 0.0.1
DESCRIPTION "lsfg-vk: LSFG on Linux through Vulkan"
DESCRIPTION "LSFG on Linux"
LANGUAGES CXX)
file(GLOB SOURCES
"src/utils/*.cpp"
"src/extract/*.cpp"
"src/mini/*.cpp"
"src/utils/*.cpp"
"src/*.cpp"
)
add_library(lsfg-vk SHARED ${SOURCES})
# target
set_target_properties(lsfg-vk PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)
target_include_directories(lsfg-vk
PRIVATE include)
target_link_libraries(lsfg-vk
PRIVATE lsfg-vk-gen vulkan)
target_compile_options(lsfg-vk 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
# required for vulkan
-Wno-cast-function-type-strict
)
PRIVATE lsfg-vk-v3.1 peparse dxvk vulkan)
# diagnostics
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(lsfg-vk PROPERTIES
EXPORT_COMPILE_COMMANDS ON)
endif()
if(LSFGVK_EXCESS_DEBUG)
message(STATUS "LSFGVK_EXCESS_DEBUG is only compatible with clang")
target_compile_options(lsfg-vk 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 PROPERTIES
CXX_CLANG_TIDY clang-tidy)
endif()
# install
install(FILES "${CMAKE_BINARY_DIR}/liblsfg-vk.so"
DESTINATION lib)
install(FILES "${CMAKE_SOURCE_DIR}/VkLayer_LS_frame_generation.json"

View file

@ -36,7 +36,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()
if(LSFGVK_EXCESS_DEBUG)
message(STATUS "LSFGVK_EXCESS_DEBUG is only compatible with clang")
target_compile_options(lsfg-vk-v3.1 PRIVATE
-Weverything
# disable compat c++ flags

View file

@ -1,4 +1,6 @@
#include "context.hpp"
#include "extract/extract.hpp"
#include "extract/trans.hpp"
#include "layer.hpp"
#include "utils/log.hpp"
#include "utils/utils.hpp"
@ -12,10 +14,20 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
VkExtent2D extent, const std::vector<VkImage>& swapchainImages)
: swapchain(swapchain), swapchainImages(swapchainImages),
extent(extent) {
// read environment variables
const char* lsfgFlowScaleStr = getenv("LSFG_FLOW_SCALE");
const float flowScale = lsfgFlowScaleStr
? std::stof(lsfgFlowScaleStr)
: 1.0F;
const char* lsfgHdrStr = getenv("LSFG_HDR");
const bool isHdr = lsfgHdrStr
? *lsfgHdrStr == '1'
: false;
// we could take the format from the swapchain,
// but honestly this is safer.
const VkFormat format = getenv("LSFG_HDR") == nullptr
const VkFormat format = isHdr
? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R16G16B16A16_SFLOAT;
@ -53,19 +65,26 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
}
// initialize lsfg
const uint64_t deviceUUID = Utils::getDeviceUUID(info.physicalDevice);
setenv("LSFG_DEVICE_UUID", std::to_string(deviceUUID).c_str(), 1);
Log::debug("context", "(entering LSFG initialization)");
setenv("DISABLE_LSFG", "1", 1);
LSFG::initialize();
Extract::extractShaders();
LSFG::initialize(
Utils::getDeviceUUID(info.physicalDevice),
isHdr, 1.0F / flowScale, info.frameGen,
[](const std::string& name) {
auto dxbc = Extract::getShader(name);
auto spirv = Extract::translateShader(dxbc);
return spirv;
}
);
unsetenv("DISABLE_LSFG");
Log::debug("context", "(exiting LSFG initialization)");
// create lsfg context
Log::debug("context", "(entering LSFG context creation)");
this->lsfgCtxId = std::shared_ptr<int32_t>(
new int32_t(LSFG::createContext(extent.width, extent.height,
frame_0_fd, frame_1_fd, out_n_fds)),
new int32_t(LSFG::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);