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