Skip to content

Commit

Permalink
Make vkFrameBoundaryANDROID trigger screenshots
Browse files Browse the repository at this point in the history
This commit is part of what is requested in LunarG#1494

Change-Id: Ie448deebfb9858588779200ba6e78a9a0c5d6424
  • Loading branch information
marius-pelegrin-arm committed Apr 18, 2024
1 parent 8f31cd2 commit df498f6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 23 deletions.
54 changes: 54 additions & 0 deletions framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7229,6 +7229,60 @@ VkResult VulkanReplayConsumerBase::OverrideCreateFramebuffer(
return result;
}

void VulkanReplayConsumerBase::OverrideFrameBoundaryANDROID(PFN_vkFrameBoundaryANDROID func,
const DeviceInfo* device_info,
const SemaphoreInfo* semaphore_info,
const ImageInfo* image_info)
{
GFXRECON_ASSERT((device_info != nullptr));

VkDevice device = device_info->handle;
VkSemaphore semaphore = semaphore_info ? semaphore_info->handle : VK_NULL_HANDLE;
VkImage image = image_info ? image_info->handle : VK_NULL_HANDLE;

if (screenshot_handler_ != nullptr)
{
if (screenshot_handler_->IsScreenshotFrame() && image_info != nullptr)
{
const std::string filename_prefix =
screenshot_file_prefix_ + "_frame_" + std::to_string(screenshot_handler_->GetCurrentFrame());

const uint32_t screenshot_width =
options_.screenshot_scale
? static_cast<uint32_t>(options_.screenshot_scale * image_info->extent.width)
: (options_.screenshot_width ? options_.screenshot_width : image_info->extent.width);

const uint32_t screenshot_height =
options_.screenshot_scale
? static_cast<uint32_t>(options_.screenshot_scale * image_info->extent.height)
: (options_.screenshot_height ? options_.screenshot_height : image_info->extent.height);

auto instance_table = GetInstanceTable(device_info->parent);
GFXRECON_ASSERT(instance_table != nullptr);

VkPhysicalDeviceMemoryProperties memory_properties;
instance_table->GetPhysicalDeviceMemoryProperties(device_info->parent, &memory_properties);

screenshot_handler_->WriteImage(filename_prefix,
device,
GetDeviceTable(device),
memory_properties,
device_info->allocator.get(),
image,
image_info->format,
image_info->extent.width,
image_info->extent.height,
screenshot_width,
screenshot_height,
image_info->current_layout);
}

screenshot_handler_->EndFrame();
}

func(device, semaphore, image);
}

// We want to allow skipping the query for tool properties because the capture layer actually adds this extension
// and the application may end up using the query. However, this extension may not be present for replay, so
// we stub it out in that case. This will generate warnings in the GfxReconstruct output, but it shouldn't result
Expand Down
39 changes: 22 additions & 17 deletions framework/decode/vulkan_replay_consumer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,11 @@ class VulkanReplayConsumerBase : public VulkanConsumer
StructPointerDecoder<Decoded_VkAllocationCallbacks>* allocator_decoder,
HandlePointerDecoder<VkFramebuffer>* frame_buffer_decoder);

void OverrideFrameBoundaryANDROID(PFN_vkFrameBoundaryANDROID func,
const DeviceInfo* device_info,
const SemaphoreInfo* semaphore_info,
const ImageInfo* image_info);

const VulkanReplayOptions options_;

private:
Expand Down Expand Up @@ -1180,25 +1185,25 @@ class VulkanReplayConsumerBase : public VulkanConsumer
typedef std::unordered_map<format::HandleId, HardwareBufferMemoryInfo> HardwareBufferMemoryMap;

private:
util::platform::LibraryHandle loader_handle_;
PFN_vkGetInstanceProcAddr get_instance_proc_addr_;
PFN_vkCreateInstance create_instance_proc_;
std::unordered_map<encode::DispatchKey, PFN_vkGetDeviceProcAddr> get_device_proc_addrs_;
std::unordered_map<encode::DispatchKey, PFN_vkCreateDevice> create_device_procs_;
util::platform::LibraryHandle loader_handle_;
PFN_vkGetInstanceProcAddr get_instance_proc_addr_;
PFN_vkCreateInstance create_instance_proc_;
std::unordered_map<encode::DispatchKey, PFN_vkGetDeviceProcAddr> get_device_proc_addrs_;
std::unordered_map<encode::DispatchKey, PFN_vkCreateDevice> create_device_procs_;
std::unordered_map<encode::DispatchKey, encode::VulkanInstanceTable> instance_tables_;
std::unordered_map<encode::DispatchKey, encode::VulkanDeviceTable> device_tables_;
std::function<void(const char*)> fatal_error_handler_;
std::shared_ptr<application::Application> application_;
VulkanObjectInfoTable object_info_table_;
bool loading_trim_state_;
bool replaying_trimmed_capture_;
SwapchainImageTracker swapchain_image_tracker_;
HardwareBufferMap hardware_buffers_;
HardwareBufferMemoryMap hardware_buffer_memory_info_;
std::unique_ptr<ScreenshotHandler> screenshot_handler_;
std::unique_ptr<VulkanSwapchain> swapchain_;
std::string screenshot_file_prefix_;
graphics::FpsInfo* fps_info_;
std::function<void(const char*)> fatal_error_handler_;
std::shared_ptr<application::Application> application_;
VulkanObjectInfoTable object_info_table_;
bool loading_trim_state_;
bool replaying_trimmed_capture_;
SwapchainImageTracker swapchain_image_tracker_;
HardwareBufferMap hardware_buffers_;
HardwareBufferMemoryMap hardware_buffer_memory_info_;
std::unique_ptr<ScreenshotHandler> screenshot_handler_;
std::unique_ptr<VulkanSwapchain> swapchain_;
std::string screenshot_file_prefix_;
graphics::FpsInfo* fps_info_;

// Imported semaphores are semaphores that are used to track external memory.
// During replay, the external memory is not present (we have no Fds or handles to valid
Expand Down
8 changes: 4 additions & 4 deletions framework/generated/generated_vulkan_replay_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5589,11 +5589,11 @@ void VulkanReplayConsumer::Process_vkFrameBoundaryANDROID(
format::HandleId semaphore,
format::HandleId image)
{
VkDevice in_device = MapHandle<DeviceInfo>(device, &VulkanObjectInfoTable::GetDeviceInfo);
VkSemaphore in_semaphore = MapHandle<SemaphoreInfo>(semaphore, &VulkanObjectInfoTable::GetSemaphoreInfo);
VkImage in_image = MapHandle<ImageInfo>(image, &VulkanObjectInfoTable::GetImageInfo);
auto in_device = GetObjectInfoTable().GetDeviceInfo(device);
auto in_semaphore = GetObjectInfoTable().GetSemaphoreInfo(semaphore);
auto in_image = GetObjectInfoTable().GetImageInfo(image);

GetDeviceTable(in_device)->FrameBoundaryANDROID(in_device, in_semaphore, in_image);
OverrideFrameBoundaryANDROID(GetDeviceTable(in_device->handle)->FrameBoundaryANDROID, in_device, in_semaphore, in_image);
}

void VulkanReplayConsumer::Process_vkCreateDebugReportCallbackEXT(
Expand Down
5 changes: 3 additions & 2 deletions framework/generated/vulkan_generators/replay_overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"vkCreateFramebuffer": "OverrideCreateFramebuffer",
"vkAcquireProfilingLockKHR": "OverrideAcquireProfilingLockKHR",
"vkWaitForPresentKHR": "OverrideWaitForPresentKHR",
"vkWaitSemaphores": "OverrideWaitSemaphores"
"vkWaitSemaphores": "OverrideWaitSemaphores",
"vkFrameBoundaryANDROID": "OverrideFrameBoundaryANDROID"
}
}
}

0 comments on commit df498f6

Please sign in to comment.