From cd94b7957115083ff5495f7d82778c10843b5aa8 Mon Sep 17 00:00:00 2001 From: Panagiotis Apostolou Date: Mon, 16 Sep 2024 17:29:26 +0300 Subject: [PATCH] Attempt to notify about vulkan commands generated by replay --- .../decode/vulkan_captured_swapchain.cpp | 15 ++-- framework/decode/vulkan_captured_swapchain.h | 16 +++-- .../decode/vulkan_offscreen_swapchain.cpp | 15 ++-- framework/decode/vulkan_offscreen_swapchain.h | 16 +++-- .../decode/vulkan_replay_consumer_base.cpp | 32 +++++++-- .../decode/vulkan_replay_consumer_base.h | 2 + framework/decode/vulkan_swapchain.h | 26 ++++--- framework/decode/vulkan_virtual_swapchain.cpp | 72 ++++++++++++++++--- framework/decode/vulkan_virtual_swapchain.h | 16 +++-- 9 files changed, 152 insertions(+), 58 deletions(-) diff --git a/framework/decode/vulkan_captured_swapchain.cpp b/framework/decode/vulkan_captured_swapchain.cpp index c14d28d762..e98f12938b 100644 --- a/framework/decode/vulkan_captured_swapchain.cpp +++ b/framework/decode/vulkan_captured_swapchain.cpp @@ -28,13 +28,14 @@ GFXRECON_BEGIN_NAMESPACE(gfxrecon) GFXRECON_BEGIN_NAMESPACE(decode) -VkResult VulkanCapturedSwapchain::CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) +VkResult VulkanCapturedSwapchain::CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands) { VkDevice device = VK_NULL_HANDLE; diff --git a/framework/decode/vulkan_captured_swapchain.h b/framework/decode/vulkan_captured_swapchain.h index 89a35d6877..e947ff5d5a 100644 --- a/framework/decode/vulkan_captured_swapchain.h +++ b/framework/decode/vulkan_captured_swapchain.h @@ -33,13 +33,15 @@ class VulkanCapturedSwapchain : public VulkanSwapchain public: virtual ~VulkanCapturedSwapchain() override {} - virtual VkResult CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) override; + virtual VkResult + CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) override; virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func, const DeviceInfo* device_info, diff --git a/framework/decode/vulkan_offscreen_swapchain.cpp b/framework/decode/vulkan_offscreen_swapchain.cpp index ba351155a2..b814eee420 100644 --- a/framework/decode/vulkan_offscreen_swapchain.cpp +++ b/framework/decode/vulkan_offscreen_swapchain.cpp @@ -79,13 +79,14 @@ void VulkanOffscreenSwapchain::DestroySurface(PFN_vkDestroySurfaceKHR func, const VkAllocationCallbacks* allocator) {} -VkResult VulkanOffscreenSwapchain::CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) +VkResult VulkanOffscreenSwapchain::CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands) { GFXRECON_ASSERT(device_info); device_table_ = device_table; diff --git a/framework/decode/vulkan_offscreen_swapchain.h b/framework/decode/vulkan_offscreen_swapchain.h index fb646949cd..e5dc6af87a 100644 --- a/framework/decode/vulkan_offscreen_swapchain.h +++ b/framework/decode/vulkan_offscreen_swapchain.h @@ -53,13 +53,15 @@ class VulkanOffscreenSwapchain : public VulkanVirtualSwapchain const SurfaceKHRInfo* surface_info, const VkAllocationCallbacks* allocator) override; - virtual VkResult CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) override; + virtual VkResult + CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) override; virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func, const DeviceInfo* device_info, diff --git a/framework/decode/vulkan_replay_consumer_base.cpp b/framework/decode/vulkan_replay_consumer_base.cpp index caa08ee807..ba1fd1e530 100644 --- a/framework/decode/vulkan_replay_consumer_base.cpp +++ b/framework/decode/vulkan_replay_consumer_base.cpp @@ -2504,6 +2504,9 @@ VulkanReplayConsumerBase::OverrideCreateInstance(VkResult original_result, modified_create_info.ppEnabledExtensionNames + modified_create_info.enabledExtensionCount); } + + report_generated_vulkan_commands_fp_ = reinterpret_cast( + get_instance_proc_addr_(*replay_instance, "ReportGeneratedVulkanCommands")); } return result; @@ -3928,6 +3931,11 @@ VkResult VulkanReplayConsumerBase::OverrideAllocateDescriptorSets( if ((original_result >= 0) && (result == VK_ERROR_OUT_OF_POOL_MEMORY)) { + if (report_generated_vulkan_commands_fp_ != nullptr) + { + report_generated_vulkan_commands_fp_(true); + } + // Handle case where replay runs out of descriptor pool memory when capture did not by creating a new // descriptor pool and attempting the allocation a second time. VkDescriptorPool new_pool = VK_NULL_HANDLE; @@ -3974,6 +3982,11 @@ VkResult VulkanReplayConsumerBase::OverrideAllocateDescriptorSets( result = func(device_info->handle, &modified_allocate_info, pDescriptorSets->GetHandlePointer()); } + + if (report_generated_vulkan_commands_fp_ != nullptr) + { + report_generated_vulkan_commands_fp_(false); + } } // The information gathered here is only relevant to the dump resources feature @@ -4230,9 +4243,9 @@ VkResult VulkanReplayConsumerBase::OverrideAllocateMemory( VkMemoryAllocateInfo modified_allocate_info = (*replay_allocate_info); VkMemoryOpaqueCaptureAddressAllocateInfo address_info = { - VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO, - modified_allocate_info.pNext, - opaque_address + VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO, + modified_allocate_info.pNext, + opaque_address }; modified_allocate_info.pNext = &address_info; @@ -6070,7 +6083,8 @@ VkResult VulkanReplayConsumerBase::OverrideCreateSwapchainKHR( &modified_create_info, GetAllocationCallbacks(pAllocator), pSwapchain, - GetDeviceTable(device_info->handle)); + GetDeviceTable(device_info->handle), + report_generated_vulkan_commands_fp_); } else { @@ -6597,6 +6611,11 @@ VulkanReplayConsumerBase::OverrideQueuePresentKHR(PFN_vkQueuePresentKHR WriteScreenshots(meta_info); } + if (report_generated_vulkan_commands_fp_ != nullptr) + { + report_generated_vulkan_commands_fp_(true); + } + // If rendering is restricted to a specific surface, need to check for dummy swapchains at present. if (options_.surface_index != -1) { @@ -6837,6 +6856,11 @@ VulkanReplayConsumerBase::OverrideQueuePresentKHR(PFN_vkQueuePresentKHR GetDeviceTable(device)->DeviceWaitIdle(device); } + if (report_generated_vulkan_commands_fp_ != nullptr) + { + report_generated_vulkan_commands_fp_(false); + } + // Only attempt to find imported or shadow semaphores if we know at least one around. if ((!have_imported_semaphores_) && (shadow_semaphores_.empty()) && (modified_present_info.swapchainCount != 0)) { diff --git a/framework/decode/vulkan_replay_consumer_base.h b/framework/decode/vulkan_replay_consumer_base.h index 851627f4f2..6f7771d3bc 100644 --- a/framework/decode/vulkan_replay_consumer_base.h +++ b/framework/decode/vulkan_replay_consumer_base.h @@ -1503,6 +1503,8 @@ class VulkanReplayConsumerBase : public VulkanConsumer void* capture_pipeline_cache_data_; bool matched_replay_cache_data_exist_ = false; std::vector matched_replay_cache_data_; + + PFN_ReportReplayGeneratedVulkanCommands report_generated_vulkan_commands_fp_ = nullptr; }; GFXRECON_END_NAMESPACE(decode) diff --git a/framework/decode/vulkan_swapchain.h b/framework/decode/vulkan_swapchain.h index 0b31cd06ba..398d2c680e 100644 --- a/framework/decode/vulkan_swapchain.h +++ b/framework/decode/vulkan_swapchain.h @@ -44,6 +44,8 @@ const int32_t kDefaultWindowPositionY = 0; const uint32_t kDefaultWindowWidth = 320; const uint32_t kDefaultWindowHeight = 240; +using PFN_ReportReplayGeneratedVulkanCommands = void (*)(uint32_t); + class ScreenshotHandler; struct VulkanSwapchainOptions @@ -80,13 +82,14 @@ class VulkanSwapchain const SurfaceKHRInfo* surface_info, const VkAllocationCallbacks* allocator); - virtual VkResult CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) = 0; + virtual VkResult CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) = 0; virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func, const DeviceInfo* device_info, @@ -179,10 +182,11 @@ class VulkanSwapchain const encode::VulkanInstanceTable* instance_table_{ nullptr }; const encode::VulkanDeviceTable* device_table_{ nullptr }; - application::Application* application_{ nullptr }; - ActiveWindows active_windows_; - int32_t create_surface_count_{ 0 }; - VulkanSwapchainOptions swapchain_options_; + application::Application* application_{ nullptr }; + ActiveWindows active_windows_; + int32_t create_surface_count_{ 0 }; + VulkanSwapchainOptions swapchain_options_; + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands_fp_ = nullptr; }; GFXRECON_END_NAMESPACE(decode) diff --git a/framework/decode/vulkan_virtual_swapchain.cpp b/framework/decode/vulkan_virtual_swapchain.cpp index 99ce11e0e5..1c9ba7f221 100644 --- a/framework/decode/vulkan_virtual_swapchain.cpp +++ b/framework/decode/vulkan_virtual_swapchain.cpp @@ -24,6 +24,7 @@ #include "decode/vulkan_resource_allocator.h" #include "decode/decoder_util.h" +#include "vulkan/vulkan_core.h" #include @@ -42,13 +43,14 @@ bool VulkanVirtualSwapchain::AddSwapchainResourceData(VkSwapchainKHR swapchain) return true; } -VkResult VulkanVirtualSwapchain::CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) +VkResult VulkanVirtualSwapchain::CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands) { VkDevice device = VK_NULL_HANDLE; VkSurfaceCapabilitiesKHR surfCapabilities{}; @@ -59,6 +61,7 @@ VkResult VulkanVirtualSwapchain::CreateSwapchainKHR(VkResult } device_table_ = device_table; VkPhysicalDevice physical_device = device_info->parent; + report_vulkan_commands_fp_ = report_vulkan_commands; VkSwapchainCreateInfoKHR modified_create_info = *create_info; modified_create_info.imageUsage = @@ -148,8 +151,18 @@ void VulkanVirtualSwapchain::DestroySwapchainKHR(PFN_vkDestroySwapchainKHR fu { if ((device_info != nullptr) && (swapchain_info != nullptr)) { + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(true); + } + CleanSwapchainResourceData(device_info, swapchain_info); + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + VkDevice device = device_info->handle; VkSwapchainKHR swapchain = swapchain_info->handle; func(device, swapchain, allocator); @@ -585,8 +598,20 @@ VkResult VulkanVirtualSwapchain::GetSwapchainImagesKHR(VkResult return result; } - return CreateSwapchainResourceData( + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(true); + } + + VkResult res = CreateSwapchainResourceData( device_info, swapchain_info, capture_image_count, replay_image_count, images, false); + + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + + return res; } return result; @@ -673,6 +698,11 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(VkResult return func(queue_info->handle, present_info); } + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(true); + } + VkQueue queue = queue_info->handle; uint32_t queue_family_index = queue_info->family_index; @@ -792,11 +822,21 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(VkResult result = device_table_->ResetCommandBuffer(command_buffer, 0); if (result != VK_SUCCESS) { + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + return result; } result = device_table_->BeginCommandBuffer(command_buffer, &begin_info); if (result != VK_SUCCESS) { + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + return result; } @@ -871,6 +911,11 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(VkResult result = device_table_->EndCommandBuffer(command_buffer); if (result != VK_SUCCESS) { + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + return result; } @@ -896,13 +941,24 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(VkResult if (result != VK_SUCCESS) { + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + return result; } } + if (report_vulkan_commands_fp_ != nullptr) + { + report_vulkan_commands_fp_(false); + } + VkPresentInfoKHR modified_present_info = *present_info; modified_present_info.waitSemaphoreCount = static_cast(present_wait_semaphores.size()); modified_present_info.pWaitSemaphores = present_wait_semaphores.data(); + return func(queue, &modified_present_info); } diff --git a/framework/decode/vulkan_virtual_swapchain.h b/framework/decode/vulkan_virtual_swapchain.h index 0b62529981..29bf6a3298 100644 --- a/framework/decode/vulkan_virtual_swapchain.h +++ b/framework/decode/vulkan_virtual_swapchain.h @@ -33,13 +33,15 @@ class VulkanVirtualSwapchain : public VulkanSwapchain public: virtual ~VulkanVirtualSwapchain() override {} - virtual VkResult CreateSwapchainKHR(VkResult original_result, - PFN_vkCreateSwapchainKHR func, - const DeviceInfo* device_info, - const VkSwapchainCreateInfoKHR* create_info, - const VkAllocationCallbacks* allocator, - HandlePointerDecoder* swapchain, - const encode::VulkanDeviceTable* device_table) override; + virtual VkResult + CreateSwapchainKHR(VkResult original_result, + PFN_vkCreateSwapchainKHR func, + const DeviceInfo* device_info, + const VkSwapchainCreateInfoKHR* create_info, + const VkAllocationCallbacks* allocator, + HandlePointerDecoder* swapchain, + const encode::VulkanDeviceTable* device_table, + PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) override; virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func, const DeviceInfo* device_info,