mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-12-03 06:32:20 +00:00
parent
9f806d5bb5
commit
4ad1ea8523
6 changed files with 80 additions and 35 deletions
|
|
@ -34,6 +34,20 @@ namespace Layer {
|
|||
VkDevice device,
|
||||
const char* pName);
|
||||
|
||||
/// Call to the original vkGetPhysicalDeviceQueueFamilyProperties function.
|
||||
void ovkGetPhysicalDeviceQueueFamilyProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t* pQueueFamilyPropertyCount,
|
||||
VkQueueFamilyProperties* pQueueFamilyProperties);
|
||||
/// Call to the original vkGetPhysicalDeviceMemoryProperties function.
|
||||
void ovkGetPhysicalDeviceMemoryProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDeviceMemoryProperties* pMemoryProperties);
|
||||
/// Call to the original vkGetPhysicalDeviceProperties function.
|
||||
void ovkGetPhysicalDeviceProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDeviceProperties* pProperties);
|
||||
|
||||
/// Call to the original vkCreateSwapchainKHR function.
|
||||
VkResult ovkCreateSwapchainKHR(
|
||||
VkDevice device,
|
||||
|
|
@ -147,16 +161,6 @@ namespace Layer {
|
|||
const VkSemaphoreGetFdInfoKHR* pGetFdInfo,
|
||||
int* pFd);
|
||||
|
||||
/// Call to the original vkGetPhysicalDeviceQueueFamilyProperties function.
|
||||
void ovkGetPhysicalDeviceQueueFamilyProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t* pQueueFamilyPropertyCount,
|
||||
VkQueueFamilyProperties* pQueueFamilyProperties);
|
||||
/// Call to the original vkGetPhysicalDeviceMemoryProperties function.
|
||||
void ovkGetPhysicalDeviceMemoryProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDeviceMemoryProperties* pMemoryProperties);
|
||||
|
||||
/// Call to the original vkGetDeviceQueue function.
|
||||
void ovkGetDeviceQueue(
|
||||
VkDevice device,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,14 @@ namespace Utils {
|
|||
std::pair<uint32_t, VkQueue> findQueue(VkDevice device, VkPhysicalDevice physicalDevice,
|
||||
VkDeviceCreateInfo* desc, VkQueueFlags flags);
|
||||
|
||||
///
|
||||
/// Get the UUID of the physical device.
|
||||
///
|
||||
/// @param physicalDevice The physical device to get the UUID from.
|
||||
/// @return The UUID of the physical device.
|
||||
///
|
||||
uint64_t getDeviceUUID(VkPhysicalDevice physicalDevice);
|
||||
|
||||
///
|
||||
/// Ensure a list of extensions is present in the given array.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -24,18 +24,28 @@ Device::Device(const Instance& instance) {
|
|||
if (res != VK_SUCCESS)
|
||||
throw LSFG::vulkan_error(res, "Failed to get physical devices");
|
||||
|
||||
// get uuid env vars
|
||||
const char* deviceUUIDEnv = std::getenv("LSFG_DEVICE_UUID");
|
||||
if (!deviceUUIDEnv)
|
||||
throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED,
|
||||
"LSFG_DEVICE_UUID environment variable not set");
|
||||
const uint64_t deviceUUID = std::stoull(deviceUUIDEnv);
|
||||
|
||||
// find first discrete GPU
|
||||
std::optional<VkPhysicalDevice> physicalDevice;
|
||||
for (const auto& device : devices) {
|
||||
VkPhysicalDeviceProperties properties;
|
||||
vkGetPhysicalDeviceProperties(device, &properties);
|
||||
physicalDevice = device;
|
||||
|
||||
if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
||||
break; // dedicated will always work
|
||||
const uint64_t uuid = static_cast<uint64_t>(properties.vendorID) << 32 | properties.deviceID;
|
||||
if (deviceUUID == uuid) {
|
||||
physicalDevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!physicalDevice)
|
||||
throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "No discrete GPU found");
|
||||
throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED,
|
||||
"Could not find physical device with UUID");
|
||||
|
||||
// find queue family indices
|
||||
uint32_t familyCount{};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "utils/log.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <lsfg.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
|
@ -46,6 +47,9 @@ 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)");
|
||||
Utils::storeLayerEnv();
|
||||
LSFG::initialize();
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ namespace {
|
|||
PFN_vkGetInstanceProcAddr next_vkGetInstanceProcAddr{};
|
||||
PFN_vkGetDeviceProcAddr next_vkGetDeviceProcAddr{};
|
||||
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties next_vkGetPhysicalDeviceQueueFamilyProperties{};
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties next_vkGetPhysicalDeviceMemoryProperties{};
|
||||
PFN_vkGetPhysicalDeviceProperties next_vkGetPhysicalDeviceProperties{};
|
||||
|
||||
PFN_vkCreateSwapchainKHR next_vkCreateSwapchainKHR{};
|
||||
PFN_vkQueuePresentKHR next_vkQueuePresentKHR{};
|
||||
PFN_vkDestroySwapchainKHR next_vkDestroySwapchainKHR{};
|
||||
|
|
@ -39,8 +43,6 @@ namespace {
|
|||
PFN_vkDestroySemaphore next_vkDestroySemaphore{};
|
||||
PFN_vkGetMemoryFdKHR next_vkGetMemoryFdKHR{};
|
||||
PFN_vkGetSemaphoreFdKHR next_vkGetSemaphoreFdKHR{};
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties next_vkGetPhysicalDeviceQueueFamilyProperties{};
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties next_vkGetPhysicalDeviceMemoryProperties{};
|
||||
PFN_vkGetDeviceQueue next_vkGetDeviceQueue{};
|
||||
PFN_vkQueueSubmit next_vkQueueSubmit{};
|
||||
PFN_vkCmdPipelineBarrier next_vkCmdPipelineBarrier{};
|
||||
|
|
@ -112,8 +114,12 @@ namespace {
|
|||
// get relevant function pointers from the next layer
|
||||
success = true;
|
||||
success &= initInstanceFunc(*pInstance, "vkDestroyInstance", &next_vkDestroyInstance);
|
||||
success &= initInstanceFunc(*pInstance, "vkGetPhysicalDeviceQueueFamilyProperties", &next_vkGetPhysicalDeviceQueueFamilyProperties);
|
||||
success &= initInstanceFunc(*pInstance, "vkGetPhysicalDeviceMemoryProperties", &next_vkGetPhysicalDeviceMemoryProperties);
|
||||
success &= initInstanceFunc(*pInstance,
|
||||
"vkGetPhysicalDeviceQueueFamilyProperties", &next_vkGetPhysicalDeviceQueueFamilyProperties);
|
||||
success &= initInstanceFunc(*pInstance,
|
||||
"vkGetPhysicalDeviceMemoryProperties", &next_vkGetPhysicalDeviceMemoryProperties);
|
||||
success &= initInstanceFunc(*pInstance,
|
||||
"vkGetPhysicalDeviceProperties", &next_vkGetPhysicalDeviceProperties);
|
||||
if (!success) {
|
||||
Log::error("layer", "Failed to get instance function pointers");
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
|
|
@ -319,6 +325,29 @@ PFN_vkVoidFunction Layer::ovkGetDeviceProcAddr(
|
|||
return next_vkGetDeviceProcAddr(device, pName);
|
||||
}
|
||||
|
||||
void Layer::ovkGetPhysicalDeviceQueueFamilyProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t* pQueueFamilyPropertyCount,
|
||||
VkQueueFamilyProperties* pQueueFamilyProperties) {
|
||||
Log::debug("vulkan", "vkGetPhysicalDeviceQueueFamilyProperties called for physical device {:x}",
|
||||
reinterpret_cast<uintptr_t>(physicalDevice));
|
||||
next_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
|
||||
}
|
||||
void Layer::ovkGetPhysicalDeviceMemoryProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDeviceMemoryProperties* pMemoryProperties) {
|
||||
Log::debug("vulkan", "vkGetPhysicalDeviceMemoryProperties called for physical device {:x}",
|
||||
reinterpret_cast<uintptr_t>(physicalDevice));
|
||||
next_vkGetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
|
||||
}
|
||||
void Layer::ovkGetPhysicalDeviceProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDeviceProperties* pProperties) {
|
||||
Log::debug("vulkan", "vkGetPhysicalDeviceProperties called for physical device {:x}",
|
||||
reinterpret_cast<uintptr_t>(physicalDevice));
|
||||
next_vkGetPhysicalDeviceProperties(physicalDevice, pProperties);
|
||||
}
|
||||
|
||||
VkResult Layer::ovkCreateSwapchainKHR(
|
||||
VkDevice device,
|
||||
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||
|
|
@ -547,22 +576,6 @@ VkResult Layer::ovkGetSemaphoreFdKHR(
|
|||
return res;
|
||||
}
|
||||
|
||||
void Layer::ovkGetPhysicalDeviceQueueFamilyProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t* pQueueFamilyPropertyCount,
|
||||
VkQueueFamilyProperties* pQueueFamilyProperties) {
|
||||
Log::debug("vulkan", "vkGetPhysicalDeviceQueueFamilyProperties called for physical device {:x}",
|
||||
reinterpret_cast<uintptr_t>(physicalDevice));
|
||||
next_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties);
|
||||
}
|
||||
void Layer::ovkGetPhysicalDeviceMemoryProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDeviceMemoryProperties* pMemoryProperties) {
|
||||
Log::debug("vulkan", "vkGetPhysicalDeviceMemoryProperties called for physical device {:x}",
|
||||
reinterpret_cast<uintptr_t>(physicalDevice));
|
||||
next_vkGetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
|
||||
}
|
||||
|
||||
void Layer::ovkGetDeviceQueue(
|
||||
VkDevice device,
|
||||
uint32_t queueFamilyIndex,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
|
|
@ -38,6 +37,13 @@ std::pair<uint32_t, VkQueue> Utils::findQueue(VkDevice device, VkPhysicalDevice
|
|||
return { *idx, queue };
|
||||
}
|
||||
|
||||
uint64_t Utils::getDeviceUUID(VkPhysicalDevice physicalDevice) {
|
||||
VkPhysicalDeviceProperties properties{};
|
||||
Layer::ovkGetPhysicalDeviceProperties(physicalDevice, &properties);
|
||||
|
||||
return static_cast<uint64_t>(properties.vendorID) << 32 | properties.deviceID;
|
||||
}
|
||||
|
||||
std::vector<const char*> Utils::addExtensions(const char* const* extensions, size_t count,
|
||||
const std::vector<const char*>& requiredExtensions) {
|
||||
std::vector<const char*> ext(count);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue