mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
link statically with Vulkan
This commit is contained in:
parent
59b05ce220
commit
eb1cee1355
6 changed files with 10 additions and 217 deletions
|
|
@ -20,7 +20,6 @@ add_subdirectory(lsfg-vk-gen)
|
|||
|
||||
file(GLOB SOURCES
|
||||
"src/loader/*.cpp"
|
||||
"src/vulkan/*.cpp"
|
||||
"src/*.cpp"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef HOOKS_HPP
|
||||
#define HOOKS_HPP
|
||||
|
||||
namespace Vulkan::Hooks {
|
||||
namespace Hooks {
|
||||
|
||||
///
|
||||
/// Install overrides for hooked Vulkan functions.
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
#ifndef FUNCS_HPP
|
||||
#define FUNCS_HPP
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
namespace Vulkan::Funcs {
|
||||
|
||||
///
|
||||
/// Initialize the global Vulkan function pointers.
|
||||
///
|
||||
void initialize();
|
||||
|
||||
///
|
||||
/// Initialize the instance Vulkan function pointers.
|
||||
///
|
||||
/// @param instance The Vulkan instance to initialize.
|
||||
///
|
||||
void initializeInstance(VkInstance instance);
|
||||
|
||||
///
|
||||
/// Initialize the device Vulkan function pointers.
|
||||
///
|
||||
/// @param device The Vulkan device to initialize.
|
||||
///
|
||||
void initializeDevice(VkDevice device);
|
||||
|
||||
/// Call to the original vkCreateInstance function.
|
||||
VkResult ovkCreateInstance(
|
||||
const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkInstance* pInstance
|
||||
);
|
||||
/// Call to the original vkDestroyInstance function.
|
||||
void ovkDestroyInstance(
|
||||
VkInstance instance,
|
||||
const VkAllocationCallbacks* pAllocator
|
||||
);
|
||||
|
||||
/// Call to the original vkCreateDevice function.
|
||||
VkResult ovkCreateDevice(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkDeviceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDevice* pDevice
|
||||
);
|
||||
/// Call to the original vkDestroyDevice function.
|
||||
void ovkDestroyDevice(
|
||||
VkDevice device,
|
||||
const VkAllocationCallbacks* pAllocator
|
||||
);
|
||||
|
||||
/// Call to the original vkCreateSwapchainKHR function.
|
||||
VkResult ovkCreateSwapchainKHR(
|
||||
VkDevice device,
|
||||
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSwapchainKHR* pSwapchain
|
||||
);
|
||||
/// Call to the original vkDestroySwapchainKHR function.
|
||||
void ovkDestroySwapchainKHR(
|
||||
VkDevice device,
|
||||
VkSwapchainKHR swapchain,
|
||||
const VkAllocationCallbacks* pAllocator
|
||||
);
|
||||
}
|
||||
|
||||
#endif // FUNCS_HPP
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#include "vulkan/hooks.hpp"
|
||||
#include "vulkan/funcs.hpp"
|
||||
#include "hooks.hpp"
|
||||
#include "loader/dl.hpp"
|
||||
#include "loader/vk.hpp"
|
||||
#include "application.hpp"
|
||||
|
|
@ -9,31 +8,18 @@
|
|||
|
||||
#include <optional>
|
||||
|
||||
using namespace Vulkan;
|
||||
using namespace Hooks;
|
||||
|
||||
namespace {
|
||||
bool initialized{false};
|
||||
std::optional<Application> application;
|
||||
|
||||
VkResult myvkCreateInstance(
|
||||
const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkInstance* pInstance) {
|
||||
auto res = Funcs::ovkCreateInstance(pCreateInfo, pAllocator, pInstance);
|
||||
|
||||
Funcs::initializeInstance(*pInstance);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
VkResult myvkCreateDevice(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkDeviceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDevice* pDevice) {
|
||||
auto res = Funcs::ovkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
|
||||
|
||||
Funcs::initializeDevice(*pDevice);
|
||||
auto res = vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
|
||||
|
||||
// create the main application
|
||||
if (application.has_value()) {
|
||||
|
|
@ -61,7 +47,7 @@ namespace {
|
|||
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSwapchainKHR* pSwapchain) {
|
||||
auto res = Funcs::ovkCreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
|
||||
auto res = vkCreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
|
||||
|
||||
// add the swapchain to the application
|
||||
if (!application.has_value()) {
|
||||
|
|
@ -120,7 +106,7 @@ namespace {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Funcs::ovkDestroySwapchainKHR(device, swapchain, pAllocator);
|
||||
vkDestroySwapchainKHR(device, swapchain, pAllocator);
|
||||
}
|
||||
|
||||
void myvkDestroyDevice(
|
||||
|
|
@ -134,7 +120,7 @@ namespace {
|
|||
Log::warn("lsfg-vk(hooks): No application to destroy, continuing");
|
||||
}
|
||||
|
||||
Funcs::ovkDestroyDevice(device, pAllocator);
|
||||
vkDestroyDevice(device, pAllocator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -146,8 +132,6 @@ void Hooks::initialize() {
|
|||
}
|
||||
|
||||
// register hooks to vulkan loader
|
||||
Loader::VK::registerSymbol("vkCreateInstance",
|
||||
reinterpret_cast<void*>(myvkCreateInstance));
|
||||
Loader::VK::registerSymbol("vkCreateDevice",
|
||||
reinterpret_cast<void*>(myvkCreateDevice));
|
||||
Loader::VK::registerSymbol("vkDestroyDevice",
|
||||
|
|
@ -159,8 +143,6 @@ void Hooks::initialize() {
|
|||
|
||||
// register hooks to dynamic loader under libvulkan.so.1
|
||||
Loader::DL::File vk1("libvulkan.so.1");
|
||||
vk1.defineSymbol("vkCreateInstance",
|
||||
reinterpret_cast<void*>(myvkCreateInstance));
|
||||
vk1.defineSymbol("vkCreateDevice",
|
||||
reinterpret_cast<void*>(myvkCreateDevice));
|
||||
vk1.defineSymbol("vkDestroyDevice",
|
||||
|
|
@ -173,8 +155,6 @@ void Hooks::initialize() {
|
|||
|
||||
// register hooks to dynamic loader under libvulkan.so
|
||||
Loader::DL::File vk2("libvulkan.so");
|
||||
vk2.defineSymbol("vkCreateInstance",
|
||||
reinterpret_cast<void*>(myvkCreateInstance));
|
||||
vk2.defineSymbol("vkCreateDevice",
|
||||
reinterpret_cast<void*>(myvkCreateDevice));
|
||||
vk2.defineSymbol("vkDestroyDevice",
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#include "loader/dl.hpp"
|
||||
#include "loader/vk.hpp"
|
||||
#include "vulkan/funcs.hpp"
|
||||
#include "vulkan/hooks.hpp"
|
||||
#include "hooks.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
extern "C" void __attribute__((constructor)) init();
|
||||
|
|
@ -14,9 +13,8 @@ void init() {
|
|||
Loader::DL::initialize();
|
||||
Loader::VK::initialize();
|
||||
|
||||
// setup vulkan stuff
|
||||
Vulkan::Funcs::initialize();
|
||||
Vulkan::Hooks::initialize();
|
||||
// setup hooks
|
||||
Hooks::initialize();
|
||||
|
||||
Log::info("lsfg-vk: init() completed successfully");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
#include "vulkan/funcs.hpp"
|
||||
#include "loader/dl.hpp"
|
||||
#include "loader/vk.hpp"
|
||||
#include "log.hpp"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
using namespace Vulkan;
|
||||
|
||||
namespace {
|
||||
PFN_vkCreateInstance vkCreateInstance_ptr{};
|
||||
PFN_vkDestroyInstance vkDestroyInstance_ptr{};
|
||||
|
||||
PFN_vkCreateDevice vkCreateDevice_ptr{};
|
||||
PFN_vkDestroyDevice vkDestroyDevice_ptr{};
|
||||
|
||||
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR_ptr{};
|
||||
PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR_ptr{};
|
||||
}
|
||||
|
||||
void Funcs::initialize() {
|
||||
if (vkCreateInstance_ptr || vkDestroyInstance_ptr) {
|
||||
Log::warn("lsfg-vk(funcs): Global Vulkan functions already initialized, did you call it twice?");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* handle = Loader::DL::odlopen("libvulkan.so.1", 0x2);
|
||||
vkCreateInstance_ptr = reinterpret_cast<PFN_vkCreateInstance>(
|
||||
Loader::DL::odlsym(handle, "vkCreateInstance"));
|
||||
vkDestroyInstance_ptr = reinterpret_cast<PFN_vkDestroyInstance>(
|
||||
Loader::DL::odlsym(handle, "vkDestroyInstance"));
|
||||
if (!vkCreateInstance_ptr || !vkDestroyInstance_ptr) {
|
||||
Log::error("lsfg-vk(funcs): Failed to initialize Vulkan functions, missing symbols");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Log::debug("lsfg-vk(funcs): Initialized global Vulkan functions with original pointers");
|
||||
}
|
||||
|
||||
void Funcs::initializeInstance(VkInstance instance) {
|
||||
if (vkCreateDevice_ptr || vkDestroyDevice_ptr) {
|
||||
Log::warn("lsfg-vk(funcs): Instance Vulkan functions already initialized, did you call it twice?");
|
||||
return;
|
||||
}
|
||||
|
||||
vkCreateDevice_ptr = reinterpret_cast<PFN_vkCreateDevice>(
|
||||
Loader::VK::ovkGetInstanceProcAddr(instance, "vkCreateDevice"));
|
||||
vkDestroyDevice_ptr = reinterpret_cast<PFN_vkDestroyDevice>(
|
||||
Loader::VK::ovkGetInstanceProcAddr(instance, "vkDestroyDevice"));
|
||||
if (!vkCreateDevice_ptr || !vkDestroyDevice_ptr) {
|
||||
Log::error("lsfg-vk(funcs): Failed to initialize Vulkan instance functions, missing symbols");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Log::debug("lsfg-vk(funcs): Initialized instance Vulkan functions with original pointers");
|
||||
}
|
||||
|
||||
void Funcs::initializeDevice(VkDevice device) {
|
||||
if (vkCreateSwapchainKHR_ptr || vkDestroySwapchainKHR_ptr) {
|
||||
Log::warn("lsfg-vk(funcs): Device Vulkan functions already initialized, did you call it twice?");
|
||||
return;
|
||||
}
|
||||
|
||||
vkCreateSwapchainKHR_ptr = reinterpret_cast<PFN_vkCreateSwapchainKHR>(
|
||||
Loader::VK::ovkGetDeviceProcAddr(device, "vkCreateSwapchainKHR"));
|
||||
vkDestroySwapchainKHR_ptr = reinterpret_cast<PFN_vkDestroySwapchainKHR>(
|
||||
Loader::VK::ovkGetDeviceProcAddr(device, "vkDestroySwapchainKHR"));
|
||||
if (!vkCreateSwapchainKHR_ptr || !vkDestroySwapchainKHR_ptr) {
|
||||
Log::error("lsfg-vk(funcs): Failed to initialize Vulkan device functions, missing symbols");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Log::debug("lsfg-vk(funcs): Initialized device Vulkan functions with original pointers");
|
||||
}
|
||||
|
||||
// original function calls
|
||||
|
||||
VkResult Funcs::ovkCreateInstance(
|
||||
const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkInstance* pInstance) {
|
||||
return vkCreateInstance_ptr(pCreateInfo, pAllocator, pInstance);
|
||||
}
|
||||
|
||||
void Funcs::ovkDestroyInstance(
|
||||
VkInstance instance,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
vkDestroyInstance_ptr(instance, pAllocator);
|
||||
}
|
||||
|
||||
VkResult Funcs::ovkCreateDevice(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkDeviceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDevice* pDevice) {
|
||||
return vkCreateDevice_ptr(physicalDevice, pCreateInfo, pAllocator, pDevice);
|
||||
}
|
||||
|
||||
void Funcs::ovkDestroyDevice(
|
||||
VkDevice device,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
vkDestroyDevice_ptr(device, pAllocator);
|
||||
}
|
||||
|
||||
VkResult Funcs::ovkCreateSwapchainKHR(
|
||||
VkDevice device,
|
||||
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSwapchainKHR* pSwapchain) {
|
||||
return vkCreateSwapchainKHR_ptr(device, pCreateInfo, pAllocator, pSwapchain);
|
||||
}
|
||||
|
||||
void Funcs::ovkDestroySwapchainKHR(
|
||||
VkDevice device,
|
||||
VkSwapchainKHR swapchain,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
vkDestroySwapchainKHR_ptr(device, swapchain, pAllocator);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue