Skip to content

Commit

Permalink
Attempt to notify about vulkan commands generated by replay
Browse files Browse the repository at this point in the history
  • Loading branch information
panos-lunarg committed Sep 17, 2024
1 parent 318b1d4 commit cd94b79
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 58 deletions.
15 changes: 8 additions & 7 deletions framework/decode/vulkan_captured_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkSwapchainKHR>* 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<VkSwapchainKHR>* swapchain,
const encode::VulkanDeviceTable* device_table,
PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands)
{
VkDevice device = VK_NULL_HANDLE;

Expand Down
16 changes: 9 additions & 7 deletions framework/decode/vulkan_captured_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkSwapchainKHR>* 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<VkSwapchainKHR>* swapchain,
const encode::VulkanDeviceTable* device_table,
PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) override;

virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func,
const DeviceInfo* device_info,
Expand Down
15 changes: 8 additions & 7 deletions framework/decode/vulkan_offscreen_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkSwapchainKHR>* 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<VkSwapchainKHR>* swapchain,
const encode::VulkanDeviceTable* device_table,
PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands)
{
GFXRECON_ASSERT(device_info);
device_table_ = device_table;
Expand Down
16 changes: 9 additions & 7 deletions framework/decode/vulkan_offscreen_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkSwapchainKHR>* 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<VkSwapchainKHR>* swapchain,
const encode::VulkanDeviceTable* device_table,
PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) override;

virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func,
const DeviceInfo* device_info,
Expand Down
32 changes: 28 additions & 4 deletions framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,9 @@ VulkanReplayConsumerBase::OverrideCreateInstance(VkResult original_result,
modified_create_info.ppEnabledExtensionNames +
modified_create_info.enabledExtensionCount);
}

report_generated_vulkan_commands_fp_ = reinterpret_cast<PFN_ReportReplayGeneratedVulkanCommands>(
get_instance_proc_addr_(*replay_instance, "ReportGeneratedVulkanCommands"));
}

return result;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 2 additions & 0 deletions framework/decode/vulkan_replay_consumer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,8 @@ class VulkanReplayConsumerBase : public VulkanConsumer
void* capture_pipeline_cache_data_;
bool matched_replay_cache_data_exist_ = false;
std::vector<uint8_t> matched_replay_cache_data_;

PFN_ReportReplayGeneratedVulkanCommands report_generated_vulkan_commands_fp_ = nullptr;
};

GFXRECON_END_NAMESPACE(decode)
Expand Down
26 changes: 15 additions & 11 deletions framework/decode/vulkan_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<VkSwapchainKHR>* 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<VkSwapchainKHR>* swapchain,
const encode::VulkanDeviceTable* device_table,
PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands = nullptr) = 0;

virtual void DestroySwapchainKHR(PFN_vkDestroySwapchainKHR func,
const DeviceInfo* device_info,
Expand Down Expand Up @@ -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)
Expand Down
72 changes: 64 additions & 8 deletions framework/decode/vulkan_virtual_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "decode/vulkan_resource_allocator.h"
#include "decode/decoder_util.h"
#include "vulkan/vulkan_core.h"

#include <array>

Expand All @@ -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<VkSwapchainKHR>* 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<VkSwapchainKHR>* swapchain,
const encode::VulkanDeviceTable* device_table,
PFN_ReportReplayGeneratedVulkanCommands report_vulkan_commands)
{
VkDevice device = VK_NULL_HANDLE;
VkSurfaceCapabilitiesKHR surfCapabilities{};
Expand All @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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<uint32_t>(present_wait_semaphores.size());
modified_present_info.pWaitSemaphores = present_wait_semaphores.data();

return func(queue, &modified_present_info);
}

Expand Down
Loading

0 comments on commit cd94b79

Please sign in to comment.