Skip to content

Commit

Permalink
Write frame marker for end-of-frame vkQueueSubmits
Browse files Browse the repository at this point in the history
  • Loading branch information
davidd-lunarg committed May 31, 2023
1 parent 8128912 commit caf93a4
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 10 deletions.
38 changes: 38 additions & 0 deletions framework/decode/file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,31 @@ bool FileProcessor::ProcessBlocks()
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read meta-data block header");
}
}
else if (block_header.type == format::BlockType::kFrameMarkerBlock)
{
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
uint64_t frame_number = 0;

success = ReadBytes(&marker_type, sizeof(marker_type));

if (success)
{
success = ProcessFrameMarker(block_header, marker_type);

// Break from loop on frame delimiter.
if (IsFrameDelimiter(block_header.type, marker_type))
{
// Make sure to increment the frame number on the way out.
++current_frame_number_;
++block_index_;
break;
}
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read frame marker header");
}
}
else if (block_header.type == format::BlockType::kStateMarkerBlock)
{
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
Expand Down Expand Up @@ -1721,6 +1746,14 @@ bool FileProcessor::ProcessMetaData(const format::BlockHeader& block_header, for
return success;
}

bool FileProcessor::ProcessFrameMarker(const format::BlockHeader& block_header, format::MarkerType marker_type)
{
// Read the rest of the frame marker data. Currently frame markers are not dispatched to decoders.
uint64_t frame_number = 0;
bool success = ReadBytes(&frame_number, sizeof(frame_number));
return success;
}

bool FileProcessor::ProcessStateMarker(const format::BlockHeader& block_header, format::MarkerType marker_type)
{
uint64_t frame_number = 0;
Expand Down Expand Up @@ -1812,6 +1845,11 @@ bool FileProcessor::ProcessAnnotation(const format::BlockHeader& block_header, f
return success;
}

bool FileProcessor::IsFrameDelimiter(format::BlockType block_type, format::MarkerType marker_type) const
{
return ((block_type == format::BlockType::kFrameMarkerBlock) && (marker_type == format::MarkerType::kEndMarker));
}

bool FileProcessor::IsFrameDelimiter(format::ApiCallId call_id) const
{
// TODO: IDs of API calls that were treated as frame delimiters by the GFXReconstruct layer should be in the capture
Expand Down
4 changes: 4 additions & 0 deletions framework/decode/file_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ class FileProcessor

bool ProcessMetaData(const format::BlockHeader& block_header, format::MetaDataId meta_data_id);

bool IsFrameDelimiter(format::BlockType block_type, format::MarkerType marker_type) const;

bool IsFrameDelimiter(format::ApiCallId call_id) const;

void HandleBlockReadError(Error error_code, const char* error_message);

bool ProcessFrameMarker(const format::BlockHeader& block_header, format::MarkerType marker_type);

bool ProcessStateMarker(const format::BlockHeader& block_header, format::MarkerType marker_type);

bool ProcessAnnotation(const format::BlockHeader& block_header, format::AnnotationType annotation_type);
Expand Down
28 changes: 20 additions & 8 deletions framework/encode/capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ CaptureManager::CaptureManager(format::ApiFamilyId api_family) :
page_guard_memory_mode_(kMemoryModeShadowInternal), trim_enabled_(false), trim_current_range_(0),
current_frame_(kFirstFrame), capture_mode_(kModeWrite), previous_hotkey_state_(false),
previous_runtime_trigger_state_(CaptureSettings::RuntimeTriggerState::kNotUsed), debug_layer_(false),
debug_device_lost_(false), screenshot_prefix_(""), screenshots_enabled_(false), global_frame_count_(0),
disable_dxr_(false), accel_struct_padding_(0), iunknown_wrapping_(false), force_command_serialization_(false),
queue_zero_only_(false)
debug_device_lost_(false), screenshot_prefix_(""), screenshots_enabled_(false), disable_dxr_(false),
accel_struct_padding_(0), iunknown_wrapping_(false), force_command_serialization_(false), queue_zero_only_(false)
{}

CaptureManager::~CaptureManager()
Expand Down Expand Up @@ -683,7 +682,7 @@ bool CaptureManager::ShouldTriggerScreenshot()
uint32_t target_frame = screenshot_indices_.back();

// If this is a frame of interest, take a screenshot
if (target_frame == (global_frame_count_ + 1))
if (target_frame == current_frame_)
{
triger_screenshot = true;

Expand All @@ -701,12 +700,27 @@ bool CaptureManager::ShouldTriggerScreenshot()
return triger_screenshot;
}

void CaptureManager::WriteFrameMarker(format::MarkerType marker_type)
{
if ((capture_mode_ & kModeWrite) == kModeWrite)
{
format::Marker marker_cmd;
uint64_t header_size = sizeof(format::Marker);
marker_cmd.header.type = format::BlockType::kFrameMarkerBlock;
marker_cmd.header.size = header_size;
marker_cmd.marker_type = marker_type;
marker_cmd.frame_number = current_frame_;
current_frame_;
WriteToFile(&marker_cmd, header_size);
}
}

void CaptureManager::EndFrame()
{
++current_frame_;

if (trim_enabled_)
{
++current_frame_;

if ((capture_mode_ & kModeWrite) == kModeWrite)
{
// Currently capturing a frame range.
Expand All @@ -721,8 +735,6 @@ void CaptureManager::EndFrame()
}
}

global_frame_count_++;

// Flush after presents to help avoid capture files with incomplete final blocks.
if (file_stream_.get() != nullptr)
{
Expand Down
3 changes: 2 additions & 1 deletion framework/encode/capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class CaptureManager

void EndMethodCallCapture();

void WriteFrameMarker(format::MarkerType marker_type);

void EndFrame();

bool ShouldTriggerScreenshot();
Expand Down Expand Up @@ -265,7 +267,6 @@ class CaptureManager
util::Keyboard keyboard_;
std::string screenshot_prefix_;
util::ScreenshotFormat screenshot_format_;
uint32_t global_frame_count_;

void WriteToFile(const void* data, size_t size);

Expand Down
2 changes: 1 addition & 1 deletion framework/encode/d3d12_capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void D3D12CaptureManager::PrePresent(IDXGISwapChain_Wrapper* swapchain_wrapper)
gfxrecon::graphics::dx12::TakeScreenshot(frame_buffer_renderer_,
swapchain_info->command_queue,
swapchain,
global_frame_count_ + 1,
GetCurrentFrame(),
screenshot_prefix_,
screenshot_format_);
}
Expand Down
5 changes: 5 additions & 0 deletions framework/encode/vulkan_capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ class VulkanCaptureManager : public CaptureManager
GFXRECON_ASSERT(cmd_buffer_wrapper != nullptr);
if (cmd_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();
break;
}
Expand Down
25 changes: 25 additions & 0 deletions tools/optimize/block_skipping_file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ bool BlockSkippingFileProcessor::ProcessBlocks()
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read meta-data block header");
}
}
else if (block_header.type == format::BlockType::kFrameMarkerBlock)
{
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
uint64_t frame_number = 0;

success = ReadBytes(&marker_type, sizeof(marker_type));

if (success)
{
success = ProcessFrameMarker(block_header, marker_type);

// Break from loop on frame delimiter.
if (IsFrameDelimiter(block_header.type, marker_type))
{
// Make sure to increment the frame number on the way out.
++current_frame_number_;
++block_index_;
break;
}
}
else
{
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read frame marker header");
}
}
else if (block_header.type == format::BlockType::kStateMarkerBlock)
{
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
Expand Down

0 comments on commit caf93a4

Please sign in to comment.