Skip to content

Commit

Permalink
Refactor code for handling cmd buffers as frames
Browse files Browse the repository at this point in the history
  • Loading branch information
davidd-lunarg committed Jun 29, 2023
1 parent 185f6ab commit 57abf89
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
58 changes: 23 additions & 35 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 @@ -3207,28 +3225,13 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit(PFN_vkQueueSubmit func,
for (uint32_t j = 0; j < command_buffer_count; ++j)
{
auto command_buffer_info = GetObjectInfoTable().GetCommandBufferInfo(command_buffer_ids[j]);
if (command_buffer_info != nullptr)
if (CheckCommandBufferInfoForFrameBoundary(command_buffer_info))
{
if (command_buffer_info->is_frame_boundary)
{
is_frame_boundary = true;
break;
}
break;
}
}
}
}
if (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 result;
Expand Down Expand Up @@ -3380,28 +3383,13 @@ VkResult VulkanReplayConsumerBase::OverrideQueueSubmit2(PFN_vkQueueSubmit2 func,
{
auto command_buffer_info =
GetObjectInfoTable().GetCommandBufferInfo(command_buffer_infos[j].commandBuffer);
if (command_buffer_info != nullptr)
if (CheckCommandBufferInfoForFrameBoundary(command_buffer_info))
{
if (command_buffer_info->is_frame_boundary)
{
is_frame_boundary = true;
break;
}
break;
}
}
}
}
if (is_frame_boundary)
{
if (screenshot_handler_->IsScreenshotFrame())
{
GFXRECON_LOG_ERROR(
"Unable to take screenshot requested for frame %" PRIu32
". The frame ends with vkQueueSubmit2 and screenshot requires frames to end with vkQueuePresent.",
screenshot_handler_->GetCurrentFrame());
}
screenshot_handler_->EndFrame();
}
}

return result;
Expand Down Expand Up @@ -6396,7 +6384,7 @@ void VulkanReplayConsumerBase::OverrideCmdDebugMarkerInsertEXT(
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, "vr-marker,frame_end,type,application"))
if (util::platform::StringContains(marker_info->pMarkerName, graphics::kVulkanVrFrameDelimiterString))
{
command_buffer_info->is_frame_boundary = true;
}
Expand Down
4 changes: 3 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 @@ -1052,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
27 changes: 21 additions & 6 deletions framework/encode/vulkan_capture_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2021 Valve Corporation
** Copyright (c) 2018-2021 LunarG, Inc.
** Copyright (c) 2018-2023 LunarG, Inc.
** Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -31,6 +31,7 @@
#include "format/format_util.h"
#include "generated/generated_vulkan_struct_handle_wrappers.h"
#include "graphics/vulkan_device_util.h"
#include "graphics/vulkan_util.h"
#include "util/compressor.h"
#include "util/logging.h"
#include "util/page_guard_manager.h"
Expand Down Expand Up @@ -2361,13 +2362,11 @@ void VulkanCaptureManager::PostProcess_vkCmdDebugMarkerInsertEXT(VkCommandBuffer
if (pMarkerInfo != nullptr)
{
// Look for the debug marker that identifies this command buffer as a VR frame boundary.
if (util::platform::StringContains(pMarkerInfo->pMarkerName, "vr-marker,frame_end,type,application"))
if (util::platform::StringContains(pMarkerInfo->pMarkerName, graphics::kVulkanVrFrameDelimiterString))
{
auto cmd_buffer_wrapper = GetWrapper<CommandBufferWrapper>(commandBuffer);
if (cmd_buffer_wrapper != nullptr)
{
cmd_buffer_wrapper->is_frame_boundary = true;
}
GFXRECON_ASSERT(cmd_buffer_wrapper != nullptr);
cmd_buffer_wrapper->is_frame_boundary = true;
}
}
}
Expand Down Expand Up @@ -2395,6 +2394,22 @@ bool VulkanCaptureManager::CheckBindAlignment(VkDeviceSize memoryOffset)
return true;
}

bool VulkanCaptureManager::CheckCommandBufferWrapperForFrameBoundary(const CommandBufferWrapper* command_buffer_wrapper)
{
GFXRECON_ASSERT(command_buffer_wrapper != nullptr);
if (command_buffer_wrapper->is_frame_boundary)
{
// Because not all vkQueueSubmit calls are frame delimiters, add an end frame marker to the capture
// file for this vkQueueSubmit.
WriteFrameMarker(format::MarkerType::kEndMarker);

// Do common capture manager end of frame processing.
EndFrame();
return true;
}
return false;
}

void VulkanCaptureManager::PreProcess_vkBindBufferMemory(VkDevice device,
VkBuffer buffer,
VkDeviceMemory memory,
Expand Down
17 changes: 5 additions & 12 deletions framework/encode/vulkan_capture_manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2021 Valve Corporation
** Copyright (c) 2018-2021 LunarG, Inc.
** Copyright (c) 2018-2023 LunarG, Inc.
** Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -920,15 +920,8 @@ class VulkanCaptureManager : public CaptureManager
for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; ++j)
{
auto cmd_buffer_wrapper = GetWrapper<CommandBufferWrapper>(pSubmits[i].pCommandBuffers[j]);
GFXRECON_ASSERT(cmd_buffer_wrapper != nullptr);
if (cmd_buffer_wrapper->is_frame_boundary)
if (CheckCommandBufferWrapperForFrameBoundary(cmd_buffer_wrapper))
{
// Because not all vkQueueSubmit calls are frame delimiters, add an end frame marker to the capture
// file for this vkQueueSubmit.
WriteFrameMarker(format::MarkerType::kEndMarker);

// Do common capture manager end of frame processing.
EndFrame();
break;
}
}
Expand Down Expand Up @@ -960,10 +953,8 @@ class VulkanCaptureManager : public CaptureManager
{
auto cmd_buffer_wrapper =
GetWrapper<CommandBufferWrapper>(pSubmits[i].pCommandBufferInfos[j].commandBuffer);
GFXRECON_ASSERT(cmd_buffer_wrapper != nullptr);
if (cmd_buffer_wrapper->is_frame_boundary)
if (CheckCommandBufferWrapperForFrameBoundary(cmd_buffer_wrapper))
{
EndFrame();
break;
}
}
Expand Down Expand Up @@ -1293,6 +1284,8 @@ class VulkanCaptureManager : public CaptureManager
void ReleaseAndroidHardwareBuffer(AHardwareBuffer* hardware_buffer);
bool CheckBindAlignment(VkDeviceSize memoryOffset);

bool CheckCommandBufferWrapperForFrameBoundary(const CommandBufferWrapper* command_buffer_wrapper);

private:
void QueueSubmitWriteFillMemoryCmd();

Expand Down
4 changes: 3 additions & 1 deletion framework/graphics/vulkan_util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright (c) 2021 LunarG, Inc.
** Copyright (c) 2021-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 @@ -61,6 +61,8 @@ static T* GetPNextStruct(const Parent_T* parent, VkStructureType struct_type)
return nullptr;
}

static const char* kVulkanVrFrameDelimiterString = "vr-marker,frame_end,type,application";

GFXRECON_END_NAMESPACE(graphics)
GFXRECON_END_NAMESPACE(gfxrecon)

Expand Down

0 comments on commit 57abf89

Please sign in to comment.