Skip to content

Commit

Permalink
Replay check for VR frame end queue submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidd-lunarg committed Jul 11, 2023
1 parent 43d041b commit 2807aeb
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 11 deletions.
6 changes: 5 additions & 1 deletion framework/decode/vulkan_object_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ struct VulkanPoolObjectInfo : public VulkanObjectInfo<T>
// Declarations for Vulkan objects without additional replay state info.
//

typedef VulkanPoolObjectInfo<VkCommandBuffer> CommandBufferInfo;
typedef VulkanObjectInfo<VkEvent> EventInfo;
typedef VulkanObjectInfo<VkQueryPool> QueryPoolInfo;
typedef VulkanObjectInfo<VkBufferView> BufferViewInfo;
Expand Down Expand Up @@ -455,6 +454,11 @@ struct ShaderEXTInfo : VulkanObjectInfo<VkShaderEXT>
std::unordered_map<uint32_t, size_t> array_counts;
};

struct CommandBufferInfo : VulkanPoolObjectInfo<VkCommandBuffer>
{
bool is_frame_boundary{ false };
};

//
// Handle alias types for extension handle types that have been promoted to core types.
//
Expand Down
107 changes: 107 additions & 0 deletions framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,24 @@ void VulkanReplayConsumerBase::WriteScreenshots(const Decoded_VkPresentInfoKHR*
}
}

bool VulkanReplayConsumerBase::CheckCommandBufferInfoForFrameBoundary(const CommandBufferInfo* command_buffer_info)
{
GFXRECON_ASSERT(command_buffer_info != nullptr);
if (command_buffer_info->is_frame_boundary)
{
if (screenshot_handler_->IsScreenshotFrame())
{
GFXRECON_LOG_ERROR("Unable to take screenshot requested for frame %" PRIu32
". The frame ends with vkQueueSubmit* and screenshot requires frames to end with "
"vkQueuePresent.",
screenshot_handler_->GetCurrentFrame());
}
screenshot_handler_->EndFrame();
return true;
}
return false;
}

VkResult
VulkanReplayConsumerBase::OverrideCreateInstance(VkResult original_result,
const StructPointerDecoder<Decoded_VkInstanceCreateInfo>* pCreateInfo,
Expand Down Expand Up @@ -3194,6 +3212,28 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit(PFN_vkQueueSubmit func,
GetDeviceTable(queue_info->handle)->QueueWaitIdle(queue_info->handle);
}

// Check whether any of the submitted command lists buffers are frame boundaries.
if (screenshot_handler_ != nullptr)
{
bool is_frame_boundary = false;
for (uint32_t i = 0; i < submitCount; ++i)
{
if (submit_info_data != nullptr)
{
size_t command_buffer_count = submit_info_data[i].pCommandBuffers.GetLength();
const auto command_buffer_ids = submit_info_data[i].pCommandBuffers.GetPointer();
for (uint32_t j = 0; j < command_buffer_count; ++j)
{
auto command_buffer_info = GetObjectInfoTable().GetCommandBufferInfo(command_buffer_ids[j]);
if (CheckCommandBufferInfoForFrameBoundary(command_buffer_info))
{
break;
}
}
}
}
}

return result;
}

Expand Down Expand Up @@ -3329,6 +3369,29 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit2(PFN_vkQueueSubmit2 func,
GetDeviceTable(queue_info->handle)->QueueWaitIdle(queue_info->handle);
}

// Check whether any of the submitted command buffers are frame boundaries.
if (screenshot_handler_ != nullptr)
{
bool is_frame_boundary = false;
for (uint32_t i = 0; i < submitCount; ++i)
{
if (submit_info_data != nullptr)
{
size_t command_buffer_count = submit_info_data[i].pCommandBufferInfos->GetLength();
const auto command_buffer_infos = submit_info_data[i].pCommandBufferInfos->GetMetaStructPointer();
for (uint32_t j = 0; j < command_buffer_count; ++j)
{
auto command_buffer_info =
GetObjectInfoTable().GetCommandBufferInfo(command_buffer_infos[j].commandBuffer);
if (CheckCommandBufferInfoForFrameBoundary(command_buffer_info))
{
break;
}
}
}
}
}

return result;
}

Expand Down Expand Up @@ -6283,6 +6346,50 @@ VkResult VulkanReplayConsumerBase::OverrideGetAndroidHardwareBufferPropertiesAND
}
}

void VulkanReplayConsumerBase::ClearCommandBufferInfo(CommandBufferInfo* command_buffer_info)
{
command_buffer_info->is_frame_boundary = false;
}

VkResult VulkanReplayConsumerBase::OverrideBeginCommandBuffer(
PFN_vkBeginCommandBuffer func,
VkResult original_result,
CommandBufferInfo* command_buffer_info,
StructPointerDecoder<Decoded_VkCommandBufferBeginInfo>* begin_info_decoder)
{
ClearCommandBufferInfo(command_buffer_info);

VkCommandBuffer command_buffer = command_buffer_info->handle;
const VkCommandBufferBeginInfo* begin_info = begin_info_decoder->GetPointer();
return func(command_buffer, begin_info);
}

VkResult VulkanReplayConsumerBase::OverrideResetCommandBuffer(PFN_vkResetCommandBuffer func,
VkResult original_result,
CommandBufferInfo* command_buffer_info,
VkCommandBufferResetFlags flags)
{
ClearCommandBufferInfo(command_buffer_info);

VkCommandBuffer command_buffer = command_buffer_info->handle;
return func(command_buffer, flags);
}

void VulkanReplayConsumerBase::OverrideCmdDebugMarkerInsertEXT(
PFN_vkCmdDebugMarkerInsertEXT func,
CommandBufferInfo* command_buffer_info,
StructPointerDecoder<Decoded_VkDebugMarkerMarkerInfoEXT>* marker_info_decoder)
{
const VkDebugMarkerMarkerInfoEXT* marker_info = marker_info_decoder->GetPointer();
func(command_buffer_info->handle, marker_info);

// Look for the debug marker that identifies this command buffer as a VR frame boundary.
if (util::platform::StringContains(marker_info->pMarkerName, graphics::kVulkanVrFrameDelimiterString))
{
command_buffer_info->is_frame_boundary = true;
}
};

// 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
20 changes: 19 additions & 1 deletion framework/decode/vulkan_replay_consumer_base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2022 LunarG, Inc.
** Copyright (c) 2018-2023 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -920,6 +920,22 @@ class VulkanReplayConsumerBase : public VulkanConsumer
const struct AHardwareBuffer* hardware_buffer,
StructPointerDecoder<Decoded_VkAndroidHardwareBufferPropertiesANDROID>* pProperties);

void ClearCommandBufferInfo(CommandBufferInfo* command_buffer_info);

VkResult OverrideBeginCommandBuffer(PFN_vkBeginCommandBuffer func,
VkResult original_result,
CommandBufferInfo* command_buffer_info,
StructPointerDecoder<Decoded_VkCommandBufferBeginInfo>* begin_info_decoder);

VkResult OverrideResetCommandBuffer(PFN_vkResetCommandBuffer func,
VkResult original_result,
CommandBufferInfo* command_buffer_info,
VkCommandBufferResetFlags flags);

void OverrideCmdDebugMarkerInsertEXT(PFN_vkCmdDebugMarkerInsertEXT func,
CommandBufferInfo* command_buffer_info,
StructPointerDecoder<Decoded_VkDebugMarkerMarkerInfoEXT>* marker_info_decoder);

private:
void RaiseFatalError(const char* message) const;

Expand Down Expand Up @@ -1036,6 +1052,8 @@ class VulkanReplayConsumerBase : public VulkanConsumer

void WriteScreenshots(const Decoded_VkPresentInfoKHR* meta_info) const;

bool CheckCommandBufferInfoForFrameBoundary(const CommandBufferInfo* command_buffer_info);

private:
typedef std::unordered_set<Window*> ActiveWindows;

Expand Down
15 changes: 7 additions & 8 deletions framework/generated/generated_vulkan_replay_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,11 +1402,11 @@ void VulkanReplayConsumer::Process_vkBeginCommandBuffer(
format::HandleId commandBuffer,
StructPointerDecoder<Decoded_VkCommandBufferBeginInfo>* pBeginInfo)
{
VkCommandBuffer in_commandBuffer = MapHandle<CommandBufferInfo>(commandBuffer, &VulkanObjectInfoTable::GetCommandBufferInfo);
const VkCommandBufferBeginInfo* in_pBeginInfo = pBeginInfo->GetPointer();
auto in_commandBuffer = GetObjectInfoTable().GetCommandBufferInfo(commandBuffer);

MapStructHandles(pBeginInfo->GetMetaStructPointer(), GetObjectInfoTable());

VkResult replay_result = GetDeviceTable(in_commandBuffer)->BeginCommandBuffer(in_commandBuffer, in_pBeginInfo);
VkResult replay_result = OverrideBeginCommandBuffer(GetDeviceTable(in_commandBuffer->handle)->BeginCommandBuffer, returnValue, in_commandBuffer, pBeginInfo);
CheckResult("vkBeginCommandBuffer", returnValue, replay_result);
}

Expand All @@ -1427,9 +1427,9 @@ void VulkanReplayConsumer::Process_vkResetCommandBuffer(
format::HandleId commandBuffer,
VkCommandBufferResetFlags flags)
{
VkCommandBuffer in_commandBuffer = MapHandle<CommandBufferInfo>(commandBuffer, &VulkanObjectInfoTable::GetCommandBufferInfo);
auto in_commandBuffer = GetObjectInfoTable().GetCommandBufferInfo(commandBuffer);

VkResult replay_result = GetDeviceTable(in_commandBuffer)->ResetCommandBuffer(in_commandBuffer, flags);
VkResult replay_result = OverrideResetCommandBuffer(GetDeviceTable(in_commandBuffer->handle)->ResetCommandBuffer, returnValue, in_commandBuffer, flags);
CheckResult("vkResetCommandBuffer", returnValue, replay_result);
}

Expand Down Expand Up @@ -5377,10 +5377,9 @@ void VulkanReplayConsumer::Process_vkCmdDebugMarkerInsertEXT(
format::HandleId commandBuffer,
StructPointerDecoder<Decoded_VkDebugMarkerMarkerInfoEXT>* pMarkerInfo)
{
VkCommandBuffer in_commandBuffer = MapHandle<CommandBufferInfo>(commandBuffer, &VulkanObjectInfoTable::GetCommandBufferInfo);
const VkDebugMarkerMarkerInfoEXT* in_pMarkerInfo = pMarkerInfo->GetPointer();
auto in_commandBuffer = GetObjectInfoTable().GetCommandBufferInfo(commandBuffer);

GetDeviceTable(in_commandBuffer)->CmdDebugMarkerInsertEXT(in_commandBuffer, in_pMarkerInfo);
OverrideCmdDebugMarkerInsertEXT(GetDeviceTable(in_commandBuffer->handle)->CmdDebugMarkerInsertEXT, in_commandBuffer, pMarkerInfo);
}

void VulkanReplayConsumer::Process_vkCmdBindTransformFeedbackBuffersEXT(
Expand Down
5 changes: 4 additions & 1 deletion framework/generated/vulkan_generators/replay_overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
"vkGetAndroidHardwareBufferPropertiesANDROID": "OverrideGetAndroidHardwareBufferPropertiesANDROID",
"vkDeferredOperationJoinKHR": "OverrideDeferredOperationJoinKHR",
"vkGetPhysicalDeviceToolProperties": "OverrideGetPhysicalDeviceToolProperties",
"vkGetPhysicalDeviceToolPropertiesEXT": "OverrideGetPhysicalDeviceToolProperties"
"vkGetPhysicalDeviceToolPropertiesEXT": "OverrideGetPhysicalDeviceToolProperties",
"vkBeginCommandBuffer": "OverrideBeginCommandBuffer",
"vkResetCommandBuffer": "OverrideResetCommandBuffer",
"vkCmdDebugMarkerInsertEXT": "OverrideCmdDebugMarkerInsertEXT"
}
}

0 comments on commit 2807aeb

Please sign in to comment.