mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2026-04-22 10:21:43 +00:00
first batch of original vulkan pointers
This commit is contained in:
parent
935dd2f452
commit
f31b5842d8
2 changed files with 70 additions and 0 deletions
26
include/vulkan/funcs.hpp
Normal file
26
include/vulkan/funcs.hpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef FUNCS_HPP
|
||||
#define FUNCS_HPP
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
namespace Vulkan::Funcs {
|
||||
|
||||
///
|
||||
/// Initialize the global Vulkan function pointers.
|
||||
///
|
||||
void initialize();
|
||||
|
||||
/// Call to the original vkCreateInstance function.
|
||||
VkResult vkCreateInstanceOriginal(
|
||||
const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkInstance* pInstance
|
||||
);
|
||||
/// Call to the original vkDestroyInstance function.
|
||||
void vkDestroyInstanceOriginal(
|
||||
VkInstance instance,
|
||||
const VkAllocationCallbacks* pAllocator
|
||||
);
|
||||
}
|
||||
|
||||
#endif // FUNCS_HPP
|
||||
44
src/vulkan/funcs.cpp
Normal file
44
src/vulkan/funcs.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "vulkan/funcs.hpp"
|
||||
#include "loader/dl.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
using namespace Vulkan;
|
||||
|
||||
namespace {
|
||||
PFN_vkCreateInstance vkCreateInstance_ptr{};
|
||||
PFN_vkDestroyInstance vkDestroyInstance_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");
|
||||
}
|
||||
|
||||
// original function calls
|
||||
|
||||
VkResult Funcs::vkCreateInstanceOriginal(
|
||||
const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkInstance* pInstance) {
|
||||
return vkCreateInstance_ptr(pCreateInfo, pAllocator, pInstance);
|
||||
}
|
||||
|
||||
void Funcs::vkDestroyInstanceOriginal(
|
||||
VkInstance instance,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
vkDestroyInstance_ptr(instance, pAllocator);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue