Skip to content

Commit daa3f4f

Browse files
committed
Write frame marker for end-of-frame vkQueueSubmits
1 parent d904800 commit daa3f4f

7 files changed

Lines changed: 95 additions & 9 deletions

File tree

framework/decode/file_processor.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,31 @@ bool FileProcessor::ProcessBlocks()
317317
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read meta-data block header");
318318
}
319319
}
320+
else if (block_header.type == format::BlockType::kFrameMarkerBlock)
321+
{
322+
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
323+
uint64_t frame_number = 0;
324+
325+
success = ReadBytes(&marker_type, sizeof(marker_type));
326+
327+
if (success)
328+
{
329+
success = ProcessFrameMarker(block_header, marker_type);
330+
331+
// Break from loop on frame delimiter.
332+
if (IsFrameDelimiter(block_header.type, marker_type))
333+
{
334+
// Make sure to increment the frame number on the way out.
335+
++current_frame_number_;
336+
++block_index_;
337+
break;
338+
}
339+
}
340+
else
341+
{
342+
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read frame marker header");
343+
}
344+
}
320345
else if (block_header.type == format::BlockType::kStateMarkerBlock)
321346
{
322347
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
@@ -1721,6 +1746,14 @@ bool FileProcessor::ProcessMetaData(const format::BlockHeader& block_header, for
17211746
return success;
17221747
}
17231748

1749+
bool FileProcessor::ProcessFrameMarker(const format::BlockHeader& block_header, format::MarkerType marker_type)
1750+
{
1751+
// Read the rest of the frame marker data. Currently frame markers are not dispatched to decoders.
1752+
uint64_t frame_number = 0;
1753+
bool success = ReadBytes(&frame_number, sizeof(frame_number));
1754+
return success;
1755+
}
1756+
17241757
bool FileProcessor::ProcessStateMarker(const format::BlockHeader& block_header, format::MarkerType marker_type)
17251758
{
17261759
uint64_t frame_number = 0;
@@ -1812,6 +1845,11 @@ bool FileProcessor::ProcessAnnotation(const format::BlockHeader& block_header, f
18121845
return success;
18131846
}
18141847

1848+
bool FileProcessor::IsFrameDelimiter(format::BlockType block_type, format::MarkerType marker_type) const
1849+
{
1850+
return ((block_type == format::BlockType::kFrameMarkerBlock) && (marker_type == format::MarkerType::kEndMarker));
1851+
}
1852+
18151853
bool FileProcessor::IsFrameDelimiter(format::ApiCallId call_id) const
18161854
{
18171855
// TODO: IDs of API calls that were treated as frame delimiters by the GFXReconstruct layer should be in the capture

framework/decode/file_processor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ class FileProcessor
112112

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

115+
bool IsFrameDelimiter(format::BlockType block_type, format::MarkerType marker_type) const;
116+
115117
bool IsFrameDelimiter(format::ApiCallId call_id) const;
116118

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

121+
bool ProcessFrameMarker(const format::BlockHeader& block_header, format::MarkerType marker_type);
122+
119123
bool ProcessStateMarker(const format::BlockHeader& block_header, format::MarkerType marker_type);
120124

121125
bool ProcessAnnotation(const format::BlockHeader& block_header, format::AnnotationType annotation_type);

framework/encode/capture_manager.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ CaptureManager::CaptureManager(format::ApiFamilyId api_family) :
9393
page_guard_memory_mode_(kMemoryModeShadowInternal), trim_enabled_(false), trim_current_range_(0),
9494
current_frame_(kFirstFrame), capture_mode_(kModeWrite), previous_hotkey_state_(false),
9595
previous_runtime_trigger_state_(CaptureSettings::RuntimeTriggerState::kNotUsed), debug_layer_(false),
96-
debug_device_lost_(false), screenshot_prefix_(""), screenshots_enabled_(false), global_frame_count_(0),
97-
disable_dxr_(false), accel_struct_padding_(0), iunknown_wrapping_(false), force_command_serialization_(false)
96+
debug_device_lost_(false), screenshot_prefix_(""), screenshots_enabled_(false), disable_dxr_(false),
97+
accel_struct_padding_(0), iunknown_wrapping_(false), force_command_serialization_(false)
9898
{}
9999

100100
CaptureManager::~CaptureManager()
@@ -662,7 +662,7 @@ bool CaptureManager::ShouldTriggerScreenshot()
662662
uint32_t target_frame = screenshot_indices_.back();
663663

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

@@ -680,12 +680,27 @@ bool CaptureManager::ShouldTriggerScreenshot()
680680
return triger_screenshot;
681681
}
682682

683+
void CaptureManager::WriteFrameMarker(format::MarkerType marker_type)
684+
{
685+
if ((capture_mode_ & kModeWrite) == kModeWrite)
686+
{
687+
format::Marker marker_cmd;
688+
uint64_t header_size = sizeof(format::Marker);
689+
marker_cmd.header.type = format::BlockType::kFrameMarkerBlock;
690+
marker_cmd.header.size = header_size;
691+
marker_cmd.marker_type = marker_type;
692+
marker_cmd.frame_number = current_frame_;
693+
current_frame_;
694+
WriteToFile(&marker_cmd, header_size);
695+
}
696+
}
697+
683698
void CaptureManager::EndFrame()
684699
{
700+
++current_frame_;
701+
685702
if (trim_enabled_)
686703
{
687-
++current_frame_;
688-
689704
if ((capture_mode_ & kModeWrite) == kModeWrite)
690705
{
691706
// Currently capturing a frame range.
@@ -700,8 +715,6 @@ void CaptureManager::EndFrame()
700715
}
701716
}
702717

703-
global_frame_count_++;
704-
705718
// Flush after presents to help avoid capture files with incomplete final blocks.
706719
if (file_stream_.get() != nullptr)
707720
{

framework/encode/capture_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class CaptureManager
112112

113113
void EndMethodCallCapture();
114114

115+
void WriteFrameMarker(format::MarkerType marker_type);
116+
115117
void EndFrame();
116118

117119
bool ShouldTriggerScreenshot();
@@ -259,7 +261,6 @@ class CaptureManager
259261
util::Keyboard keyboard_;
260262
std::string screenshot_prefix_;
261263
util::ScreenshotFormat screenshot_format_;
262-
uint32_t global_frame_count_;
263264

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

framework/encode/d3d12_capture_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void D3D12CaptureManager::PrePresent(IDXGISwapChain_Wrapper* swapchain_wrapper)
537537
gfxrecon::graphics::dx12::TakeScreenshot(frame_buffer_renderer_,
538538
swapchain_info->command_queue,
539539
swapchain,
540-
global_frame_count_ + 1,
540+
GetCurrentFrame(),
541541
screenshot_prefix_,
542542
screenshot_format_);
543543
}

framework/encode/vulkan_capture_manager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,11 @@ class VulkanCaptureManager : public CaptureManager
911911
GFXRECON_ASSERT(cmd_buffer_wrapper != nullptr);
912912
if (cmd_buffer_wrapper->is_frame_boundary)
913913
{
914+
// Because not all vkQueueSubmit calls are frame delimiters, add an end frame marker to the capture
915+
// file for this vkQueueSubmit.
916+
WriteFrameMarker(format::MarkerType::kEndMarker);
917+
918+
// Do common capture manager end of frame processing.
914919
EndFrame();
915920
break;
916921
}

tools/optimize/block_skipping_file_processor.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ bool BlockSkippingFileProcessor::ProcessBlocks()
136136
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read meta-data block header");
137137
}
138138
}
139+
else if (block_header.type == format::BlockType::kFrameMarkerBlock)
140+
{
141+
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;
142+
uint64_t frame_number = 0;
143+
144+
success = ReadBytes(&marker_type, sizeof(marker_type));
145+
146+
if (success)
147+
{
148+
success = ProcessFrameMarker(block_header, marker_type);
149+
150+
// Break from loop on frame delimiter.
151+
if (IsFrameDelimiter(block_header.type, marker_type))
152+
{
153+
// Make sure to increment the frame number on the way out.
154+
++current_frame_number_;
155+
++block_index_;
156+
break;
157+
}
158+
}
159+
else
160+
{
161+
HandleBlockReadError(kErrorReadingBlockHeader, "Failed to read frame marker header");
162+
}
163+
}
139164
else if (block_header.type == format::BlockType::kStateMarkerBlock)
140165
{
141166
format::MarkerType marker_type = format::MarkerType::kUnknownMarker;

0 commit comments

Comments
 (0)