mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2026-04-27 12:51:52 +00:00
feat: mangohud integration
This commit is contained in:
parent
1975f2f64f
commit
44dcc2b7d0
3 changed files with 46 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ option(LSFGVK_BUILD_CLI "Build the command line interface" ON)
|
||||||
option(LSFGVK_INSTALL_DEVELOP "Install development libraries and headers" OFF)
|
option(LSFGVK_INSTALL_DEVELOP "Install development libraries and headers" OFF)
|
||||||
option(LSFGVK_INSTALL_XDG_FILES "Install the application icon and desktop files" OFF)
|
option(LSFGVK_INSTALL_XDG_FILES "Install the application icon and desktop files" OFF)
|
||||||
set(LSFGVK_LAYER_LIBRARY_PATH liblsfg-vk-layer.so CACHE STRING "Change where Vulkan searches for the layer library")
|
set(LSFGVK_LAYER_LIBRARY_PATH liblsfg-vk-layer.so CACHE STRING "Change where Vulkan searches for the layer library")
|
||||||
|
option(LSFGVK_LAYER_MANGOHUD "Enable MangoHud support in the Vulkan layer" ON)
|
||||||
option(LSFGVK_TESTING_RENDERDOC "Enable RenderDoc integration for testing purposes" OFF)
|
option(LSFGVK_TESTING_RENDERDOC "Enable RenderDoc integration for testing purposes" OFF)
|
||||||
# === READ HERE FOR BUILD OPTIONS ===
|
# === READ HERE FOR BUILD OPTIONS ===
|
||||||
|
|
||||||
|
|
@ -44,6 +45,9 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(LSFGVK_LAYER_MANGOHUD)
|
||||||
|
add_compile_definitions(LSFGVK_LAYER_MANGOHUD)
|
||||||
|
endif()
|
||||||
if(LSFGVK_TESTING_RENDERDOC)
|
if(LSFGVK_TESTING_RENDERDOC)
|
||||||
add_compile_definitions(LSFGVK_TESTING_RENDERDOC)
|
add_compile_definitions(LSFGVK_TESTING_RENDERDOC)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,15 @@
|
||||||
|
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace lsfgvk;
|
using namespace lsfgvk;
|
||||||
using namespace lsfgvk::layer;
|
using namespace lsfgvk::layer;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
/// helper to create an image memory barrier
|
||||||
VkImageMemoryBarrier barrierHelper(VkImage handle,
|
VkImageMemoryBarrier barrierHelper(VkImage handle,
|
||||||
VkAccessFlags srcAccessMask,
|
VkAccessFlags srcAccessMask,
|
||||||
VkAccessFlags dstAccessMask,
|
VkAccessFlags dstAccessMask,
|
||||||
|
|
@ -48,6 +53,21 @@ namespace {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
/// load MangoHud integration
|
||||||
|
PFN_MangoHud_notify loadMangoHudIntegration() {
|
||||||
|
void* module = dlopen("libMangoHud.so", RTLD_NOW | RTLD_NOLOAD);
|
||||||
|
if (!module)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto func = reinterpret_cast<PFN_MangoHud_notify>(
|
||||||
|
dlsym(module, "notify_extra_frame"));
|
||||||
|
if (!func)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void layer::context_ModifySwapchainCreateInfo(const ls::GameConf& profile, uint32_t maxImages,
|
void layer::context_ModifySwapchainCreateInfo(const ls::GameConf& profile, uint32_t maxImages,
|
||||||
|
|
@ -124,6 +144,10 @@ Swapchain::Swapchain(const vk::Vulkan& vk, backend::Instance& backend,
|
||||||
vk::Semaphore(vk)
|
vk::Semaphore(vk)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
this->mangohud_notify = loadMangoHudIntegration();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult Swapchain::present(const vk::Vulkan& vk,
|
VkResult Swapchain::present(const vk::Vulkan& vk,
|
||||||
|
|
@ -281,6 +305,11 @@ VkResult Swapchain::present(const vk::Vulkan& vk,
|
||||||
if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR)
|
if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR)
|
||||||
throw ls::vulkan_error(res, "vkQueuePresentKHR() failed");
|
throw ls::vulkan_error(res, "vkQueuePresentKHR() failed");
|
||||||
|
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
if (this->mangohud_notify)
|
||||||
|
this->mangohud_notify(this->fidx, swapchain, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
this->idx++;
|
this->idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,6 +327,11 @@ VkResult Swapchain::present(const vk::Vulkan& vk,
|
||||||
if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR)
|
if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR)
|
||||||
throw ls::vulkan_error(res, "vkQueuePresentKHR() failed");
|
throw ls::vulkan_error(res, "vkQueuePresentKHR() failed");
|
||||||
|
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
if (this->mangohud_notify)
|
||||||
|
this->mangohud_notify(this->fidx, swapchain, false);
|
||||||
|
#endif
|
||||||
|
|
||||||
this->fidx++;
|
this->fidx++;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ namespace lsfgvk::layer {
|
||||||
void context_ModifySwapchainCreateInfo(const ls::GameConf& profile, uint32_t maxImages,
|
void context_ModifySwapchainCreateInfo(const ls::GameConf& profile, uint32_t maxImages,
|
||||||
VkSwapchainCreateInfoKHR& createInfo);
|
VkSwapchainCreateInfoKHR& createInfo);
|
||||||
|
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
using PFN_MangoHud_notify = void(*)(uint64_t, VkSwapchainKHR, bool);
|
||||||
|
#endif
|
||||||
|
|
||||||
/// swapchain context for a layer instance
|
/// swapchain context for a layer instance
|
||||||
class Swapchain {
|
class Swapchain {
|
||||||
public:
|
public:
|
||||||
|
|
@ -79,6 +83,10 @@ namespace lsfgvk::layer {
|
||||||
|
|
||||||
ls::GameConf profile;
|
ls::GameConf profile;
|
||||||
SwapchainInfo info;
|
SwapchainInfo info;
|
||||||
|
|
||||||
|
#ifdef LSFGVK_LAYER_MANGOHUD
|
||||||
|
PFN_MangoHud_notify mangohud_notify{nullptr};
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue