From cfdf4e1d1bdbb4500b0888dd16715433f3c252ae Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Wed, 16 Jul 2025 22:14:13 +0200 Subject: [PATCH] dynamically unload layer and remove excess logging --- VkLayer_LS_frame_generation.json | 3 - include/config/config.hpp | 3 + src/config/config.cpp | 2 + src/layer.cpp | 1000 ++++++++++++------------------ src/main.cpp | 4 +- 5 files changed, 418 insertions(+), 594 deletions(-) diff --git a/VkLayer_LS_frame_generation.json b/VkLayer_LS_frame_generation.json index ece2a5f..8ad2906 100644 --- a/VkLayer_LS_frame_generation.json +++ b/VkLayer_LS_frame_generation.json @@ -11,9 +11,6 @@ "vkGetInstanceProcAddr": "layer_vkGetInstanceProcAddr", "vkGetDeviceProcAddr": "layer_vkGetDeviceProcAddr" }, - "enable_environment": { - "ENABLE_LSFG": "1" - }, "disable_environment": { "DISABLE_LSFG": "1" } diff --git a/include/config/config.hpp b/include/config/config.hpp index fd63222..69a0d41 100644 --- a/include/config/config.hpp +++ b/include/config/config.hpp @@ -28,6 +28,9 @@ namespace Config { std::shared_ptr valid; }; + /// Active configuration. Must be set in main.cpp. + extern Configuration activeConf; + /// /// Load the config file and create a file watcher. /// diff --git a/src/config/config.cpp b/src/config/config.cpp index 8fab2cc..d028ee8 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -33,6 +33,8 @@ namespace { std::optional> gameConfs; } +Configuration Config::activeConf{}; + bool Config::loadAndWatchConfig(const std::string& file) { if (!std::filesystem::exists(file)) return false; diff --git a/src/layer.cpp b/src/layer.cpp index bc8bb9d..d19dabb 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -1,12 +1,16 @@ #include "layer.hpp" +#include "common/exception.hpp" +#include "config/config.hpp" #include "hooks.hpp" -#include "utils/log.hpp" #include #include -#include #include +#include +#include +#include +#include namespace { PFN_vkCreateInstance next_vkCreateInstance{}; @@ -55,7 +59,7 @@ namespace { bool initInstanceFunc(VkInstance instance, const char* name, T* func) { *func = reinterpret_cast(next_vkGetInstanceProcAddr(instance, name)); if (!*func) { - Log::error("layer", "Failed to get instance function pointer for {}", name); + std::cerr << "(no function pointer for " << name << ")\n"; return false; } return true; @@ -65,205 +69,201 @@ namespace { bool initDeviceFunc(VkDevice device, const char* name, T* func) { *func = reinterpret_cast(next_vkGetDeviceProcAddr(device, name)); if (!*func) { - Log::error("layer", "Failed to get device function pointer for {}", name); + std::cerr << "(no function pointer for " << name << ")\n"; return false; } return true; } } - namespace { - VkInstance gInstance; - VkResult layer_vkCreateInstance( // NOLINTBEGIN + VkResult layer_vkCreateInstance( const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { - Log::debug("layer", "Initializing lsfg-vk instance layer..."); + try { + // prepare layer | NOLINTBEGIN + auto* layerDesc = const_cast( + reinterpret_cast(pCreateInfo->pNext)); + while (layerDesc && (layerDesc->sType != VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO + || layerDesc->function != VK_LAYER_LINK_INFO)) { + layerDesc = const_cast( + reinterpret_cast(layerDesc->pNext)); + } + if (!layerDesc) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "No layer creation info found in pNext chain"); - // find layer creation info - auto* layerDesc = const_cast( - reinterpret_cast(pCreateInfo->pNext)); - while (layerDesc && (layerDesc->sType != VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO - || layerDesc->function != VK_LAYER_LINK_INFO)) { - layerDesc = const_cast( - reinterpret_cast(layerDesc->pNext)); - } - if (!layerDesc) { - Log::error("layer", "No layer creation info found in pNext chain"); + next_vkGetInstanceProcAddr = layerDesc->u.pLayerInfo->pfnNextGetInstanceProcAddr; + layerDesc->u.pLayerInfo = layerDesc->u.pLayerInfo->pNext; + + bool success = initInstanceFunc(nullptr, "vkCreateInstance", &next_vkCreateInstance); + if (!success) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "Failed to get instance function pointer for vkCreateInstance"); + success &= initInstanceFunc(*pInstance, + "vkCreateDevice", &next_vkCreateDevice); + if (!success) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "Failed to get instance function pointer for vkCreateDevice"); + + // NOLINTEND | skip initialization if the layer is disabled + if (!Config::activeConf.enable) + return next_vkCreateInstance(pCreateInfo, pAllocator, pInstance); + + // create instance + try { + auto* createInstanceHook = reinterpret_cast( + Hooks::hooks["vkCreateInstance"]); + auto res = createInstanceHook(pCreateInfo, pAllocator, pInstance); + if (res != VK_SUCCESS) + throw LSFG::vulkan_error(res, "Unknown error"); + } catch (const std::exception& e) { + throw LSFG::rethrowable_error("Failed to create Vulkan instance", e); + } + + // 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, + "vkGetPhysicalDeviceProperties", &next_vkGetPhysicalDeviceProperties); + success &= initInstanceFunc(*pInstance, + "vkGetPhysicalDeviceSurfaceCapabilitiesKHR", &next_vkGetPhysicalDeviceSurfaceCapabilitiesKHR); + if (!success) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "Failed to get instance function pointers"); + + std::cerr << "lsfg-vk: Vulkan instance layer initialized successfully.\n"; + } catch (const std::exception& e) { + std::cerr << "lsfg-vk: An error occurred while initializing the Vulkan instance layer:\n"; + std::cerr << "- " << e.what() << '\n'; return VK_ERROR_INITIALIZATION_FAILED; } - - // advance link info (i don't really know what this does) - next_vkGetInstanceProcAddr = layerDesc->u.pLayerInfo->pfnNextGetInstanceProcAddr; - Log::debug("layer", "Next instance proc addr: {:x}", - reinterpret_cast(next_vkGetInstanceProcAddr)); - - layerDesc->u.pLayerInfo = layerDesc->u.pLayerInfo->pNext; - - // create instance - auto success = initInstanceFunc(nullptr, "vkCreateInstance", &next_vkCreateInstance); - if (!success) return VK_ERROR_INITIALIZATION_FAILED; - - auto* layer_vkCreateInstance2 = reinterpret_cast( - Hooks::hooks["vkCreateInstance"]); - auto res = layer_vkCreateInstance2(pCreateInfo, pAllocator, pInstance); - if (res != VK_SUCCESS) { - Log::error("layer", "Failed to create Vulkan instance: {:x}", - static_cast(res)); - return res; - } - - // 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, - "vkGetPhysicalDeviceProperties", &next_vkGetPhysicalDeviceProperties); - success &= initInstanceFunc(*pInstance, - "vkGetPhysicalDeviceSurfaceCapabilitiesKHR", &next_vkGetPhysicalDeviceSurfaceCapabilitiesKHR); - if (!success) { - Log::error("layer", "Failed to get instance function pointers"); - return VK_ERROR_INITIALIZATION_FAILED; - } - - gInstance = *pInstance; // workaround mesa bug - - Log::debug("layer", "Successfully initialized lsfg-vk instance layer"); - return res; - } // NOLINTEND + return VK_SUCCESS; + } VkResult layer_vkCreateDevice( // NOLINTBEGIN VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { - Log::debug("layer", "Initializing lsfg-vk device layer..."); + try { + // prepare layer | NOLINTBEGIN + auto* layerDesc = const_cast( + reinterpret_cast(pCreateInfo->pNext)); + while (layerDesc && (layerDesc->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO + || layerDesc->function != VK_LAYER_LINK_INFO)) { + layerDesc = const_cast( + reinterpret_cast(layerDesc->pNext)); + } + if (!layerDesc) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "No layer creation info found in pNext chain"); - // find layer creation info - auto* layerDesc = const_cast( - reinterpret_cast(pCreateInfo->pNext)); - while (layerDesc && (layerDesc->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO - || layerDesc->function != VK_LAYER_LINK_INFO)) { - layerDesc = const_cast( - reinterpret_cast(layerDesc->pNext)); - } - if (!layerDesc) { - Log::error("layer", "No layer creation info found in pNext chain"); + next_vkGetDeviceProcAddr = layerDesc->u.pLayerInfo->pfnNextGetDeviceProcAddr; + layerDesc->u.pLayerInfo = layerDesc->u.pLayerInfo->pNext; + + auto* layerDesc2 = const_cast( + reinterpret_cast(pCreateInfo->pNext)); + while (layerDesc2 && (layerDesc2->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO + || layerDesc2->function != VK_LOADER_DATA_CALLBACK)) { + layerDesc2 = const_cast( + reinterpret_cast(layerDesc2->pNext)); + } + if (!layerDesc2) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "No layer device loader data found in pNext chain"); + + next_vSetDeviceLoaderData = layerDesc2->u.pfnSetDeviceLoaderData; + + // NOLINTEND | skip initialization if the layer is disabled + if (!Config::activeConf.enable) + return next_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); + + // create device + try { + auto* createDeviceHook = reinterpret_cast( + Hooks::hooks["vkCreateDevicePre"]); + auto res = createDeviceHook(physicalDevice, pCreateInfo, pAllocator, pDevice); + if (res != VK_SUCCESS) + throw LSFG::vulkan_error(res, "Unknown error"); + } catch (const std::exception& e) { + throw LSFG::rethrowable_error("Failed to create Vulkan device", e); + } + + // get relevant function pointers from the next layer + bool success = true; + success &= initDeviceFunc(*pDevice, "vkDestroyDevice", &next_vkDestroyDevice); + success &= initDeviceFunc(*pDevice, "vkCreateSwapchainKHR", &next_vkCreateSwapchainKHR); + success &= initDeviceFunc(*pDevice, "vkQueuePresentKHR", &next_vkQueuePresentKHR); + success &= initDeviceFunc(*pDevice, "vkDestroySwapchainKHR", &next_vkDestroySwapchainKHR); + success &= initDeviceFunc(*pDevice, "vkGetSwapchainImagesKHR", &next_vkGetSwapchainImagesKHR); + success &= initDeviceFunc(*pDevice, "vkAllocateCommandBuffers", &next_vkAllocateCommandBuffers); + success &= initDeviceFunc(*pDevice, "vkFreeCommandBuffers", &next_vkFreeCommandBuffers); + success &= initDeviceFunc(*pDevice, "vkBeginCommandBuffer", &next_vkBeginCommandBuffer); + success &= initDeviceFunc(*pDevice, "vkEndCommandBuffer", &next_vkEndCommandBuffer); + success &= initDeviceFunc(*pDevice, "vkCreateCommandPool", &next_vkCreateCommandPool); + success &= initDeviceFunc(*pDevice, "vkDestroyCommandPool", &next_vkDestroyCommandPool); + success &= initDeviceFunc(*pDevice, "vkCreateImage", &next_vkCreateImage); + success &= initDeviceFunc(*pDevice, "vkDestroyImage", &next_vkDestroyImage); + success &= initDeviceFunc(*pDevice, "vkGetImageMemoryRequirements", &next_vkGetImageMemoryRequirements); + success &= initDeviceFunc(*pDevice, "vkBindImageMemory", &next_vkBindImageMemory); + success &= initDeviceFunc(*pDevice, "vkGetMemoryFdKHR", &next_vkGetMemoryFdKHR); + success &= initDeviceFunc(*pDevice, "vkAllocateMemory", &next_vkAllocateMemory); + success &= initDeviceFunc(*pDevice, "vkFreeMemory", &next_vkFreeMemory); + success &= initDeviceFunc(*pDevice, "vkCreateSemaphore", &next_vkCreateSemaphore); + success &= initDeviceFunc(*pDevice, "vkDestroySemaphore", &next_vkDestroySemaphore); + success &= initDeviceFunc(*pDevice, "vkGetSemaphoreFdKHR", &next_vkGetSemaphoreFdKHR); + success &= initDeviceFunc(*pDevice, "vkGetDeviceQueue", &next_vkGetDeviceQueue); + success &= initDeviceFunc(*pDevice, "vkQueueSubmit", &next_vkQueueSubmit); + success &= initDeviceFunc(*pDevice, "vkCmdPipelineBarrier", &next_vkCmdPipelineBarrier); + success &= initDeviceFunc(*pDevice, "vkCmdBlitImage", &next_vkCmdBlitImage); + success &= initDeviceFunc(*pDevice, "vkAcquireNextImageKHR", &next_vkAcquireNextImageKHR); + if (!success) + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, + "Failed to get device function pointers"); + + auto postCreateDeviceHook = reinterpret_cast( + Hooks::hooks["vkCreateDevicePost"]); + auto res = postCreateDeviceHook(physicalDevice, pCreateInfo, pAllocator, pDevice); + if (res != VK_SUCCESS) + throw LSFG::vulkan_error(res, "Unknown error"); + + std::cerr << "lsfg-vk: Vulkan device layer initialized successfully.\n"; + } catch (const std::exception& e) { + std::cerr << "lsfg-vk: An error occurred while initializing the Vulkan device layer:\n"; + std::cerr << "- " << e.what() << '\n'; return VK_ERROR_INITIALIZATION_FAILED; } - - next_vkGetDeviceProcAddr = layerDesc->u.pLayerInfo->pfnNextGetDeviceProcAddr; - Log::debug("layer", "Next device proc addr: {:x}", - reinterpret_cast(next_vkGetDeviceProcAddr)); - - // find second layer creation info - auto* layerDesc2 = const_cast( - reinterpret_cast(pCreateInfo->pNext)); - while (layerDesc2 && (layerDesc2->sType != VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO - || layerDesc2->function != VK_LOADER_DATA_CALLBACK)) { - layerDesc2 = const_cast( - reinterpret_cast(layerDesc2->pNext)); - } - if (!layerDesc2) { - Log::error("layer", "No layer creation info found in pNext chain"); - return VK_ERROR_INITIALIZATION_FAILED; - } - - next_vSetDeviceLoaderData = layerDesc2->u.pfnSetDeviceLoaderData; - Log::debug("layer", "Next device loader data: {:x}", - reinterpret_cast(next_vSetDeviceLoaderData)); - - // advance link info (i don't really know what this does) - layerDesc->u.pLayerInfo = layerDesc->u.pLayerInfo->pNext; - - // create device - auto success = initInstanceFunc(gInstance, "vkCreateDevice", &next_vkCreateDevice); - if (!success) return VK_ERROR_INITIALIZATION_FAILED; - - auto* layer_vkCreateDevice2 = reinterpret_cast( - Hooks::hooks["vkCreateDevicePre"]); - auto res = layer_vkCreateDevice2(physicalDevice, pCreateInfo, pAllocator, pDevice); - if (res != VK_SUCCESS) { - Log::error("layer", "Failed to create Vulkan device: {:x}", - static_cast(res)); - return res; - } - - // get relevant function pointers from the next layer - success = true; - success &= initDeviceFunc(*pDevice, "vkDestroyDevice", &next_vkDestroyDevice); - success &= initDeviceFunc(*pDevice, "vkCreateSwapchainKHR", &next_vkCreateSwapchainKHR); - success &= initDeviceFunc(*pDevice, "vkQueuePresentKHR", &next_vkQueuePresentKHR); - success &= initDeviceFunc(*pDevice, "vkDestroySwapchainKHR", &next_vkDestroySwapchainKHR); - success &= initDeviceFunc(*pDevice, "vkGetSwapchainImagesKHR", &next_vkGetSwapchainImagesKHR); - success &= initDeviceFunc(*pDevice, "vkAllocateCommandBuffers", &next_vkAllocateCommandBuffers); - success &= initDeviceFunc(*pDevice, "vkFreeCommandBuffers", &next_vkFreeCommandBuffers); - success &= initDeviceFunc(*pDevice, "vkBeginCommandBuffer", &next_vkBeginCommandBuffer); - success &= initDeviceFunc(*pDevice, "vkEndCommandBuffer", &next_vkEndCommandBuffer); - success &= initDeviceFunc(*pDevice, "vkCreateCommandPool", &next_vkCreateCommandPool); - success &= initDeviceFunc(*pDevice, "vkDestroyCommandPool", &next_vkDestroyCommandPool); - success &= initDeviceFunc(*pDevice, "vkCreateImage", &next_vkCreateImage); - success &= initDeviceFunc(*pDevice, "vkDestroyImage", &next_vkDestroyImage); - success &= initDeviceFunc(*pDevice, "vkGetImageMemoryRequirements", &next_vkGetImageMemoryRequirements); - success &= initDeviceFunc(*pDevice, "vkBindImageMemory", &next_vkBindImageMemory); - success &= initDeviceFunc(*pDevice, "vkGetMemoryFdKHR", &next_vkGetMemoryFdKHR); - success &= initDeviceFunc(*pDevice, "vkAllocateMemory", &next_vkAllocateMemory); - success &= initDeviceFunc(*pDevice, "vkFreeMemory", &next_vkFreeMemory); - success &= initDeviceFunc(*pDevice, "vkCreateSemaphore", &next_vkCreateSemaphore); - success &= initDeviceFunc(*pDevice, "vkDestroySemaphore", &next_vkDestroySemaphore); - success &= initDeviceFunc(*pDevice, "vkGetSemaphoreFdKHR", &next_vkGetSemaphoreFdKHR); - success &= initDeviceFunc(*pDevice, "vkGetDeviceQueue", &next_vkGetDeviceQueue); - success &= initDeviceFunc(*pDevice, "vkQueueSubmit", &next_vkQueueSubmit); - success &= initDeviceFunc(*pDevice, "vkCmdPipelineBarrier", &next_vkCmdPipelineBarrier); - success &= initDeviceFunc(*pDevice, "vkCmdBlitImage", &next_vkCmdBlitImage); - success &= initDeviceFunc(*pDevice, "vkAcquireNextImageKHR", &next_vkAcquireNextImageKHR); - if (!success) { - Log::error("layer", "Failed to get device function pointers"); - return VK_ERROR_INITIALIZATION_FAILED; - } - - layer_vkCreateDevice2 = reinterpret_cast( - Hooks::hooks["vkCreateDevicePost"]); - res = layer_vkCreateDevice2(physicalDevice, pCreateInfo, pAllocator, pDevice); - if (res != VK_SUCCESS) { - Log::error("layer", "Failed to create Vulkan device: {:x}", - static_cast(res)); - return res; - } - - Log::debug("layer", "Successfully initialized lsfg-vk device layer"); - return res; + return VK_SUCCESS; } // NOLINTEND } const std::unordered_map layerFunctions = { { "vkCreateInstance", reinterpret_cast(&layer_vkCreateInstance) }, + { "vkCreateDevice", + reinterpret_cast(&layer_vkCreateDevice) }, { "vkGetInstanceProcAddr", reinterpret_cast(&layer_vkGetInstanceProcAddr) }, { "vkGetDeviceProcAddr", reinterpret_cast(&layer_vkGetDeviceProcAddr) }, - { "vkCreateDevice", - reinterpret_cast(&layer_vkCreateDevice) }, }; PFN_vkVoidFunction layer_vkGetInstanceProcAddr(VkInstance instance, const char* pName) { const std::string name(pName); auto it = layerFunctions.find(name); - if (it != layerFunctions.end()) { - Log::debug("layer", "Inserted layer function for {}", name); + if (it != layerFunctions.end()) return it->second; - } it = Hooks::hooks.find(name); - if (it != Hooks::hooks.end()) { - Log::debug("layer", "Inserted hook function for {}", name); + if (it != Hooks::hooks.end() && Config::activeConf.enable) return it->second; - } return next_vkGetInstanceProcAddr(instance, pName); } @@ -271,443 +271,265 @@ PFN_vkVoidFunction layer_vkGetInstanceProcAddr(VkInstance instance, const char* PFN_vkVoidFunction layer_vkGetDeviceProcAddr(VkDevice device, const char* pName) { const std::string name(pName); auto it = layerFunctions.find(name); - if (it != layerFunctions.end()) { - Log::debug("layer", "Inserted layer function for {}", name); + if (it != layerFunctions.end()) return it->second; - } it = Hooks::hooks.find(name); - if (it != Hooks::hooks.end()) { - Log::debug("layer", "Inserted hook function for {}", name); + if (it != Hooks::hooks.end() && Config::activeConf.enable) return it->second; - } return next_vkGetDeviceProcAddr(device, pName); } // original functions - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" -// NOLINTBEGIN - -VkResult Layer::ovkCreateInstance( - const VkInstanceCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkInstance* pInstance) { - Log::debug("vulkan", "vkCreateInstance called with {} extensions:", - pCreateInfo->enabledExtensionCount); - for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i) - Log::debug("vulkan", " - {}", pCreateInfo->ppEnabledExtensionNames[i]); - auto res = next_vkCreateInstance(pCreateInfo, pAllocator, pInstance); - Log::debug("vulkan", "vkCreateInstance({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pInstance)); - return res; -} -void Layer::ovkDestroyInstance( - VkInstance instance, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan", "vkDestroyInstance called for instance {:x}", - reinterpret_cast(instance)); - next_vkDestroyInstance(instance, pAllocator); -} - -VkResult Layer::ovkCreateDevice( - VkPhysicalDevice physicalDevice, - const VkDeviceCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkDevice* pDevice) { - Log::debug("vulkan", "vkCreateDevice called with {} extensions:", - pCreateInfo->enabledExtensionCount); - for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i) - Log::debug("vulkan", " - {}", pCreateInfo->ppEnabledExtensionNames[i]); - auto res = next_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); - Log::debug("vulkan", "vkCreateDevice({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pDevice)); - return res; -} -void Layer::ovkDestroyDevice( - VkDevice device, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan", "vkDestroyDevice called for device {:x}", - reinterpret_cast(device)); - next_vkDestroyDevice(device, pAllocator); - Log::debug("vulkan", "Device {:x} destroyed successfully", - reinterpret_cast(device)); -} - -VkResult Layer::ovkSetDeviceLoaderData(VkDevice device, void* object) { - Log::debug("vulkan", "vkSetDeviceLoaderData called for object {:x}", - reinterpret_cast(object)); - return next_vSetDeviceLoaderData(device, object); -} - -PFN_vkVoidFunction Layer::ovkGetInstanceProcAddr( - VkInstance instance, - const char* pName) { - return next_vkGetInstanceProcAddr(instance, pName); -} -PFN_vkVoidFunction Layer::ovkGetDeviceProcAddr( - VkDevice device, - const char* 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(physicalDevice)); - next_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); -} -void Layer::ovkGetPhysicalDeviceMemoryProperties( - VkPhysicalDevice physicalDevice, - VkPhysicalDeviceMemoryProperties* pMemoryProperties) { - Log::debug("vulkan", "vkGetPhysicalDeviceMemoryProperties called for physical device {:x}", - reinterpret_cast(physicalDevice)); - next_vkGetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties); -} -void Layer::ovkGetPhysicalDeviceProperties( - VkPhysicalDevice physicalDevice, - VkPhysicalDeviceProperties* pProperties) { - Log::debug("vulkan", "vkGetPhysicalDeviceProperties called for physical device {:x}", - reinterpret_cast(physicalDevice)); - next_vkGetPhysicalDeviceProperties(physicalDevice, pProperties); -} -VkResult Layer::ovkGetPhysicalDeviceSurfaceCapabilitiesKHR( - VkPhysicalDevice physicalDevice, - VkSurfaceKHR surface, - VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) { - Log::debug("vulkan", "vkGetPhysicalDeviceSurfaceCapabilitiesKHR called for physical device {:x} and surface {:x}", - reinterpret_cast(physicalDevice), - reinterpret_cast(surface)); - return next_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities); -} - -VkResult Layer::ovkCreateSwapchainKHR( - VkDevice device, - const VkSwapchainCreateInfoKHR* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkSwapchainKHR* pSwapchain) { - Log::debug("vulkan", "vkCreateSwapchainKHR called with {} images, extent: {}x{}", - pCreateInfo->minImageCount, pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height); - auto res = next_vkCreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); - Log::debug("vulkan", "vkCreateSwapchainKHR({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pSwapchain)); - return res; -} -VkResult Layer::ovkQueuePresentKHR( - VkQueue queue, - const VkPresentInfoKHR* pPresentInfo) { - Log::debug("vulkan2", "vkQueuePresentKHR called with {} wait semaphores:", - pPresentInfo->waitSemaphoreCount); - for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; i++) - Log::debug("vulkan2", " - {:x}", reinterpret_cast(pPresentInfo->pWaitSemaphores[i])); - Log::debug("vulkan2", "and {} signal semaphores:", - pPresentInfo->swapchainCount); - for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) - Log::debug("vulkan2", " - {:x}", reinterpret_cast(pPresentInfo->pSwapchains[i])); - Log::debug("vulkan2", "and queue: {:x}, image: {}", - reinterpret_cast(queue), - *pPresentInfo->pImageIndices); - auto res = next_vkQueuePresentKHR(queue, pPresentInfo); - Log::debug("vulkan2", "vkQueuePresentKHR({}) returned", - static_cast(res)); - return res; -} -void Layer::ovkDestroySwapchainKHR( - VkDevice device, - VkSwapchainKHR swapchain, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan", "vkDestroySwapchainKHR called for swapchain {:x}", - reinterpret_cast(swapchain)); - next_vkDestroySwapchainKHR(device, swapchain, pAllocator); -} - -VkResult Layer::ovkGetSwapchainImagesKHR( - VkDevice device, - VkSwapchainKHR swapchain, - uint32_t* pSwapchainImageCount, - VkImage* pSwapchainImages) { - Log::debug("vulkan", "vkGetSwapchainImagesKHR called for swapchain {:x}", - reinterpret_cast(swapchain)); - auto res = next_vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); - Log::debug("vulkan", "vkGetSwapchainImagesKHR({}) returned {} images", - static_cast(res), - *pSwapchainImageCount); - return res; -} - -VkResult Layer::ovkAllocateCommandBuffers( - VkDevice device, - const VkCommandBufferAllocateInfo* pAllocateInfo, - VkCommandBuffer* pCommandBuffers) { - Log::debug("vulkan2", "vkAllocateCommandBuffers called for command pool {:x}", - reinterpret_cast(pAllocateInfo->commandPool)); - auto res = next_vkAllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers); - Log::debug("vulkan2", "vkAllocateCommandBuffers({}) returned command buffer: {}", - static_cast(res), - reinterpret_cast(*pCommandBuffers)); - return res; -} -void Layer::ovkFreeCommandBuffers( - VkDevice device, - VkCommandPool commandPool, - uint32_t commandBufferCount, - const VkCommandBuffer* pCommandBuffers) { - Log::debug("vulkan2", "vkFreeCommandBuffers called for command buffer: {:x}", - reinterpret_cast(*pCommandBuffers)); - next_vkFreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); -} - -VkResult Layer::ovkBeginCommandBuffer( - VkCommandBuffer commandBuffer, - const VkCommandBufferBeginInfo* pBeginInfo) { - Log::debug("vulkan2", "vkBeginCommandBuffer called for command buffer {:x}", - reinterpret_cast(commandBuffer)); - return next_vkBeginCommandBuffer(commandBuffer, pBeginInfo); -} -VkResult Layer::ovkEndCommandBuffer( - VkCommandBuffer commandBuffer) { - Log::debug("vulkan2", "vkEndCommandBuffer called for command buffer {:x}", - reinterpret_cast(commandBuffer)); - return next_vkEndCommandBuffer(commandBuffer); -} - -VkResult Layer::ovkCreateCommandPool( - VkDevice device, - const VkCommandPoolCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkCommandPool* pCommandPool) { - Log::debug("vulkan", "vkCreateCommandPool called"); - auto res = next_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool); - Log::debug("vulkan", "vkCreateCommandPool({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pCommandPool)); - return res; -} -void Layer::ovkDestroyCommandPool( - VkDevice device, - VkCommandPool commandPool, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan", "vkDestroyCommandPool called for command pool {:x}", - reinterpret_cast(commandPool)); - next_vkDestroyCommandPool(device, commandPool, pAllocator); -} - -VkResult Layer::ovkCreateImage( - VkDevice device, - const VkImageCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkImage* pImage) { - Log::debug("vulkan", "vkCreateImage called with format: {}, extent: {}x{}, usage: {}", - static_cast(pCreateInfo->format), - pCreateInfo->extent.width, pCreateInfo->extent.height, - static_cast(pCreateInfo->usage)); - auto res = next_vkCreateImage(device, pCreateInfo, pAllocator, pImage); - Log::debug("vulkan", "vkCreateImage({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pImage)); - return res; -} -void Layer::ovkDestroyImage( - VkDevice device, - VkImage image, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan", "vkDestroyImage called for image {:x}", - reinterpret_cast(image)); - next_vkDestroyImage(device, image, pAllocator); -} - -void Layer::ovkGetImageMemoryRequirements( - VkDevice device, - VkImage image, - VkMemoryRequirements* pMemoryRequirements) { - Log::debug("vulkan", "vkGetImageMemoryRequirements called for image {:x}", - reinterpret_cast(image)); - next_vkGetImageMemoryRequirements(device, image, pMemoryRequirements); -} -VkResult Layer::ovkBindImageMemory( - VkDevice device, - VkImage image, - VkDeviceMemory memory, - VkDeviceSize memoryOffset) { - Log::debug("vulkan", "vkBindImageMemory called for image {:x}, memory {:x}, offset: {}", - reinterpret_cast(image), - reinterpret_cast(memory), - memoryOffset); - auto res = next_vkBindImageMemory(device, image, memory, memoryOffset); - Log::debug("vulkan", "vkBindImageMemory({}) returned", - static_cast(res)); - return res; -} - -VkResult Layer::ovkAllocateMemory( - VkDevice device, - const VkMemoryAllocateInfo* pAllocateInfo, - const VkAllocationCallbacks* pAllocator, - VkDeviceMemory* pMemory) { - Log::debug("vulkan", "vkAllocateMemory called with size: {}, memory type index: {}", - pAllocateInfo->allocationSize, - pAllocateInfo->memoryTypeIndex); - auto res = next_vkAllocateMemory(device, pAllocateInfo, pAllocator, pMemory); - Log::debug("vulkan", "vkAllocateMemory({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pMemory)); - return res; -} -void Layer::ovkFreeMemory( - VkDevice device, - VkDeviceMemory memory, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan", "vkFreeMemory called for memory {:x}", - reinterpret_cast(memory)); - next_vkFreeMemory(device, memory, pAllocator); -} - -VkResult Layer::ovkCreateSemaphore( - VkDevice device, - const VkSemaphoreCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkSemaphore* pSemaphore) { - Log::debug("vulkan2", "vkCreateSemaphore called", - static_cast(pCreateInfo->flags)); - auto res = next_vkCreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore); - Log::debug("vulkan2", "vkCreateSemaphore({}) returned handle {:x}", - static_cast(res), - reinterpret_cast(*pSemaphore)); - return res; -} -void Layer::ovkDestroySemaphore( - VkDevice device, - VkSemaphore semaphore, - const VkAllocationCallbacks* pAllocator) { - Log::debug("vulkan2", "vkDestroySemaphore called for semaphore {:x}", - reinterpret_cast(semaphore)); - next_vkDestroySemaphore(device, semaphore, pAllocator); -} - -VkResult Layer::ovkGetMemoryFdKHR( - VkDevice device, - const VkMemoryGetFdInfoKHR* pGetFdInfo, - int* pFd) { - Log::debug("vulkan", "vkGetMemoryFdKHR called for memory {:x}, handle type: {}", - reinterpret_cast(pGetFdInfo->memory), - static_cast(pGetFdInfo->handleType)); - auto res = next_vkGetMemoryFdKHR(device, pGetFdInfo, pFd); - Log::debug("vulkan", "vkGetMemoryFdKHR({}) returned fd: {}", - static_cast(res), *pFd); - return res; -} -VkResult Layer::ovkGetSemaphoreFdKHR( - VkDevice device, - const VkSemaphoreGetFdInfoKHR* pGetFdInfo, - int* pFd) { - Log::debug("vulkan2", "vkGetSemaphoreFdKHR called for semaphore {:x}", - reinterpret_cast(pGetFdInfo->semaphore)); - auto res = next_vkGetSemaphoreFdKHR(device, pGetFdInfo, pFd); - Log::debug("vulkan2", "vkGetSemaphoreFdKHR({}) returned fd: {}", - static_cast(res), *pFd); - return res; -} - -void Layer::ovkGetDeviceQueue( - VkDevice device, - uint32_t queueFamilyIndex, - uint32_t queueIndex, - VkQueue* pQueue) { - Log::debug("vulkan", "vkGetDeviceQueue called for device {:x}, queue family index: {}, queue index: {}", - reinterpret_cast(device), - queueFamilyIndex, - queueIndex); - next_vkGetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); -} -VkResult Layer::ovkQueueSubmit( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo* pSubmits, - VkFence fence) { - Log::debug("vulkan2", "vkQueueSubmit called for queue {:x}, submitting: {} with wait semaphores:", - reinterpret_cast(queue), - reinterpret_cast(*pSubmits->pCommandBuffers)); - for (uint32_t i = 0; i < pSubmits->waitSemaphoreCount; ++i) - Log::debug("vulkan2", " - {:x}", reinterpret_cast(pSubmits->pWaitSemaphores[i])); - Log::debug("vulkan2", "and {} signal semaphores:", - pSubmits->waitSemaphoreCount); - for (uint32_t i = 0; i < submitCount; ++i) - Log::debug("vulkan2", " - {:x}", reinterpret_cast(pSubmits[i].pSignalSemaphores)); - Log::debug("vulkan2", "and fence: {:x}", - reinterpret_cast(fence)); - auto res = next_vkQueueSubmit(queue, submitCount, pSubmits, fence); - Log::debug("vulkan2", "vkQueueSubmit({}) returned", - static_cast(res)); - return res; -} - -void Layer::ovkCmdPipelineBarrier( - VkCommandBuffer commandBuffer, - VkPipelineStageFlags srcStageMask, - VkPipelineStageFlags dstStageMask, - VkDependencyFlags dependencyFlags, - uint32_t memoryBarrierCount, - const VkMemoryBarrier* pMemoryBarriers, - uint32_t bufferMemoryBarrierCount, - const VkBufferMemoryBarrier* pBufferMemoryBarriers, - uint32_t imageMemoryBarrierCount, - const VkImageMemoryBarrier* pImageMemoryBarriers) { - Log::debug("vulkan2", "vkCmdPipelineBarrier called for command buffer {:x}, src stage: {}, dst stage: {}, transitioning:", - reinterpret_cast(commandBuffer), - static_cast(srcStageMask), - static_cast(dstStageMask)); - for (uint32_t i = 0; i < imageMemoryBarrierCount; ++i) { - Log::debug("vulkan2", " - image {:x}, old layout: {}, new layout: {}", - reinterpret_cast(pImageMemoryBarriers[i].image), - static_cast(pImageMemoryBarriers[i].oldLayout), - static_cast(pImageMemoryBarriers[i].newLayout)); +namespace Layer { + VkResult ovkCreateInstance( + const VkInstanceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkInstance* pInstance) { + return next_vkCreateInstance(pCreateInfo, pAllocator, pInstance); + } + void ovkDestroyInstance( + VkInstance instance, + const VkAllocationCallbacks* pAllocator) { + next_vkDestroyInstance(instance, pAllocator); } - next_vkCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, - memoryBarrierCount, pMemoryBarriers, - bufferMemoryBarrierCount, pBufferMemoryBarriers, - imageMemoryBarrierCount, pImageMemoryBarriers); -} -void Layer::ovkCmdBlitImage( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkImageBlit* pRegions, - VkFilter filter) { - Log::debug("vulkan2", "vkCmdBlitImage called for command buffer {:x}, src image {:x}, dst image {:x}", - reinterpret_cast(commandBuffer), - reinterpret_cast(srcImage), - reinterpret_cast(dstImage)); - next_vkCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter); -} -VkResult Layer::ovkAcquireNextImageKHR( - VkDevice device, - VkSwapchainKHR swapchain, - uint64_t timeout, - VkSemaphore semaphore, - VkFence fence, - uint32_t* pImageIndex) { - Log::debug("vulkan", "vkAcquireNextImageKHR called for swapchain {:x}, timeout: {}, semaphore: {:x}, fence: {:x}", - reinterpret_cast(swapchain), - timeout, - reinterpret_cast(semaphore), - reinterpret_cast(fence)); - auto res = next_vkAcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex); - Log::debug("vulkan", "vkAcquireNextImageKHR({}) returned image index: {}", - static_cast(res), - *pImageIndex); - return res; -} + VkResult ovkCreateDevice( + VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDevice* pDevice) { + return next_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); + } + void ovkDestroyDevice( + VkDevice device, + const VkAllocationCallbacks* pAllocator) { + next_vkDestroyDevice(device, pAllocator); + } -#pragma clang diagnostic pop -// NOLINTEND + VkResult ovkSetDeviceLoaderData(VkDevice device, void* object) { + return next_vSetDeviceLoaderData(device, object); + } + + PFN_vkVoidFunction ovkGetInstanceProcAddr( + VkInstance instance, + const char* pName) { + return next_vkGetInstanceProcAddr(instance, pName); + } + PFN_vkVoidFunction ovkGetDeviceProcAddr( + VkDevice device, + const char* pName) { + return next_vkGetDeviceProcAddr(device, pName); + } + + void ovkGetPhysicalDeviceQueueFamilyProperties( + VkPhysicalDevice physicalDevice, + uint32_t* pQueueFamilyPropertyCount, + VkQueueFamilyProperties* pQueueFamilyProperties) { + next_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); + } + void ovkGetPhysicalDeviceMemoryProperties( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties* pMemoryProperties) { + next_vkGetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties); + } + void ovkGetPhysicalDeviceProperties( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties* pProperties) { + next_vkGetPhysicalDeviceProperties(physicalDevice, pProperties); + } + VkResult ovkGetPhysicalDeviceSurfaceCapabilitiesKHR( + VkPhysicalDevice physicalDevice, + VkSurfaceKHR surface, + VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) { + return next_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities); + } + + VkResult ovkCreateSwapchainKHR( + VkDevice device, + const VkSwapchainCreateInfoKHR* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSwapchainKHR* pSwapchain) { + return next_vkCreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); + } + VkResult ovkQueuePresentKHR( + VkQueue queue, + const VkPresentInfoKHR* pPresentInfo) { + return next_vkQueuePresentKHR(queue, pPresentInfo); + } + void ovkDestroySwapchainKHR( + VkDevice device, + VkSwapchainKHR swapchain, + const VkAllocationCallbacks* pAllocator) { + next_vkDestroySwapchainKHR(device, swapchain, pAllocator); + } + + VkResult ovkGetSwapchainImagesKHR( + VkDevice device, + VkSwapchainKHR swapchain, + uint32_t* pSwapchainImageCount, + VkImage* pSwapchainImages) { + return next_vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); + } + + VkResult ovkAllocateCommandBuffers( + VkDevice device, + const VkCommandBufferAllocateInfo* pAllocateInfo, + VkCommandBuffer* pCommandBuffers) { + return next_vkAllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers); + } + void ovkFreeCommandBuffers( + VkDevice device, + VkCommandPool commandPool, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers) { + next_vkFreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); + } + + VkResult ovkBeginCommandBuffer( + VkCommandBuffer commandBuffer, + const VkCommandBufferBeginInfo* pBeginInfo) { + return next_vkBeginCommandBuffer(commandBuffer, pBeginInfo); + } + VkResult ovkEndCommandBuffer( + VkCommandBuffer commandBuffer) { + return next_vkEndCommandBuffer(commandBuffer); + } + + VkResult ovkCreateCommandPool( + VkDevice device, + const VkCommandPoolCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkCommandPool* pCommandPool) { + return next_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool); + } + void ovkDestroyCommandPool( + VkDevice device, + VkCommandPool commandPool, + const VkAllocationCallbacks* pAllocator) { + next_vkDestroyCommandPool(device, commandPool, pAllocator); + } + + VkResult ovkCreateImage( + VkDevice device, + const VkImageCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkImage* pImage) { + return next_vkCreateImage(device, pCreateInfo, pAllocator, pImage); + } + void ovkDestroyImage( + VkDevice device, + VkImage image, + const VkAllocationCallbacks* pAllocator) { + next_vkDestroyImage(device, image, pAllocator); + } + + void ovkGetImageMemoryRequirements( + VkDevice device, + VkImage image, + VkMemoryRequirements* pMemoryRequirements) { + next_vkGetImageMemoryRequirements(device, image, pMemoryRequirements); + } + VkResult ovkBindImageMemory( + VkDevice device, + VkImage image, + VkDeviceMemory memory, + VkDeviceSize memoryOffset) { + return next_vkBindImageMemory(device, image, memory, memoryOffset); + } + + VkResult ovkAllocateMemory( + VkDevice device, + const VkMemoryAllocateInfo* pAllocateInfo, + const VkAllocationCallbacks* pAllocator, + VkDeviceMemory* pMemory) { + return next_vkAllocateMemory(device, pAllocateInfo, pAllocator, pMemory); + } + void ovkFreeMemory( + VkDevice device, + VkDeviceMemory memory, + const VkAllocationCallbacks* pAllocator) { + next_vkFreeMemory(device, memory, pAllocator); + } + + VkResult ovkCreateSemaphore( + VkDevice device, + const VkSemaphoreCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSemaphore* pSemaphore) { + return next_vkCreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore); + } + void ovkDestroySemaphore( + VkDevice device, + VkSemaphore semaphore, + const VkAllocationCallbacks* pAllocator) { + next_vkDestroySemaphore(device, semaphore, pAllocator); + } + + VkResult ovkGetMemoryFdKHR( + VkDevice device, + const VkMemoryGetFdInfoKHR* pGetFdInfo, + int* pFd) { + return next_vkGetMemoryFdKHR(device, pGetFdInfo, pFd); + } + VkResult ovkGetSemaphoreFdKHR( + VkDevice device, + const VkSemaphoreGetFdInfoKHR* pGetFdInfo, + int* pFd) { + return next_vkGetSemaphoreFdKHR(device, pGetFdInfo, pFd); + } + + void ovkGetDeviceQueue( + VkDevice device, + uint32_t queueFamilyIndex, + uint32_t queueIndex, + VkQueue* pQueue) { + next_vkGetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); + } + VkResult ovkQueueSubmit( + VkQueue queue, + uint32_t submitCount, + const VkSubmitInfo* pSubmits, + VkFence fence) { + return next_vkQueueSubmit(queue, submitCount, pSubmits, fence); + } + + void ovkCmdPipelineBarrier( + VkCommandBuffer commandBuffer, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask, + VkDependencyFlags dependencyFlags, + uint32_t memoryBarrierCount, + const VkMemoryBarrier* pMemoryBarriers, + uint32_t bufferMemoryBarrierCount, + const VkBufferMemoryBarrier* pBufferMemoryBarriers, + uint32_t imageMemoryBarrierCount, + const VkImageMemoryBarrier* pImageMemoryBarriers) { + next_vkCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, + memoryBarrierCount, pMemoryBarriers, + bufferMemoryBarrierCount, pBufferMemoryBarriers, + imageMemoryBarrierCount, pImageMemoryBarriers); + } + void ovkCmdBlitImage( + VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageBlit* pRegions, + VkFilter filter) { + next_vkCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter); + } + + VkResult ovkAcquireNextImageKHR( + VkDevice device, + VkSwapchainKHR swapchain, + uint64_t timeout, + VkSemaphore semaphore, + VkFence fence, + uint32_t* pImageIndex) { + return next_vkAcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex); + } +} diff --git a/src/main.cpp b/src/main.cpp index 39d54ca..7137e25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,9 +73,8 @@ namespace { } const std::string name = getProcessName(); - Config::Configuration conf{}; try { - conf = Config::getConfig(name); + Config::activeConf = Config::getConfig(name); } catch (const std::exception& e) { std::cerr << "lsfg-vk: The configuration for " << name << " is invalid, exiting.\n"; std::cerr << e.what() << '\n'; @@ -83,6 +82,7 @@ namespace { } // exit silently if not enabled + auto& conf = Config::activeConf; if (!conf.enable) return;