diff --git a/include/layer.hpp b/include/layer.hpp index a7dd653..ad86679 100644 --- a/include/layer.hpp +++ b/include/layer.hpp @@ -25,6 +25,11 @@ namespace Layer { VkDevice device, const VkAllocationCallbacks* pAllocator); + /// Call to the original vkSetDeviceLoaderData function. + VkResult ovkSetDeviceLoaderData( + VkDevice device, + void* object); + /// Call to the original vkGetInstanceProcAddr function. PFN_vkVoidFunction ovkGetInstanceProcAddr( VkInstance instance, diff --git a/src/layer.cpp b/src/layer.cpp index ea2003b..7bede45 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -16,6 +16,8 @@ namespace { PFN_vkCreateDevice next_vkCreateDevice{}; PFN_vkDestroyDevice next_vkDestroyDevice{}; + PFN_vkSetDeviceLoaderData next_vSetDeviceLoaderData{}; + PFN_vkGetInstanceProcAddr next_vkGetInstanceProcAddr{}; PFN_vkGetDeviceProcAddr next_vkGetDeviceProcAddr{}; @@ -152,11 +154,28 @@ namespace { return VK_ERROR_INITIALIZATION_FAILED; } - // advance link info (i don't really know what this does) - next_vkGetDeviceProcAddr = layerDesc->u.pLayerInfo->pfnNextGetDeviceProcAddr; + 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 @@ -317,6 +336,12 @@ void Layer::ovkDestroyDevice( 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) { diff --git a/src/mini/commandbuffer.cpp b/src/mini/commandbuffer.cpp index 5887f65..b8679b1 100644 --- a/src/mini/commandbuffer.cpp +++ b/src/mini/commandbuffer.cpp @@ -17,6 +17,7 @@ CommandBuffer::CommandBuffer(VkDevice device, const CommandPool& pool) { auto res = Layer::ovkAllocateCommandBuffers(device, &desc, &commandBufferHandle); if (res != VK_SUCCESS || commandBufferHandle == VK_NULL_HANDLE) throw LSFG::vulkan_error(res, "Unable to allocate command buffer"); + res = Layer::ovkSetDeviceLoaderData(device, commandBufferHandle); // store command buffer in shared ptr this->state = std::make_shared(CommandBufferState::Empty); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 843acca..00322af 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -36,6 +36,10 @@ std::pair Utils::findQueue(VkDevice device, VkPhysicalDevice VkQueue queue{}; Layer::ovkGetDeviceQueue(device, *idx, 0, &queue); + auto res = Layer::ovkSetDeviceLoaderData(device, queue); + if (res != VK_SUCCESS) + throw LSFG::vulkan_error(res, "Unable to set device loader data for queue"); + return { *idx, queue }; }