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 e0bb8e7
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 55 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
67 changes: 66 additions & 1 deletion 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 @@ -2758,7 +2761,18 @@ void VulkanReplayConsumerBase::OverrideDestroyDevice(

if (screenshot_handler_ != nullptr)
{

if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(true);
}

screenshot_handler_->DestroyDeviceResources(device, GetDeviceTable(device));

if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(false);
}
}

device_info->allocator->Destroy();
Expand Down Expand Up @@ -3461,6 +3475,11 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit(PFN_vkQueueSubmit func,

if (screenshot_handler_ != nullptr)
{
if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(true);
}

CommandBufferInfo* frame_boundary_command_buffer_info = nullptr;
for (uint32_t i = 0; i < submitCount; ++i)
{
Expand Down Expand Up @@ -3496,6 +3515,11 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit(PFN_vkQueueSubmit func,
}
}
}

if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(false);
}
}

return result;
Expand Down Expand Up @@ -3636,6 +3660,11 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit2(PFN_vkQueueSubmit2 func,
// Check whether any of the submitted command buffers are frame boundaries.
if (screenshot_handler_ != nullptr)
{
if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(true);
}

bool is_frame_boundary = false;
for (uint32_t i = 0; i < submitCount; ++i)
{
Expand All @@ -3660,6 +3689,11 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit2(PFN_vkQueueSubmit2 func,
}
}
}

if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(false);
}
}

return result;
Expand Down Expand Up @@ -3928,6 +3962,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 +4013,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 @@ -6070,7 +6114,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 @@ -6589,6 +6634,11 @@ VulkanReplayConsumerBase::OverrideQueuePresentKHR(PFN_vkQueuePresentKHR
capture_image_indices_.clear();
swapchain_infos_.clear();

if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(true);
}

if ((screenshot_handler_ != nullptr) && (screenshot_handler_->IsScreenshotFrame()))
{
auto meta_info = pPresentInfo->GetMetaStructPointer();
Expand Down Expand Up @@ -6837,6 +6887,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 Expand Up @@ -8166,6 +8221,11 @@ void VulkanReplayConsumerBase::OverrideFrameBoundaryANDROID(PFN_vkFrameBoundaryA

if (screenshot_handler_ != nullptr)
{
if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(true);
}

if (screenshot_handler_->IsScreenshotFrame() && image_info != nullptr)
{
const std::string filename_prefix =
Expand Down Expand Up @@ -8202,6 +8262,11 @@ void VulkanReplayConsumerBase::OverrideFrameBoundaryANDROID(PFN_vkFrameBoundaryA
}

screenshot_handler_->EndFrame();

if (report_generated_vulkan_commands_fp_ != nullptr)
{
report_generated_vulkan_commands_fp_(false);
}
}

func(device, semaphore, image);
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
Loading

0 comments on commit e0bb8e7

Please sign in to comment.