Skip to content

Commit caf93a4

Browse files
committed
Write frame marker for end-of-frame vkQueueSubmits
1 parent 8128912 commit caf93a4

7 files changed

Lines changed: 95 additions & 10 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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +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),
98-
queue_zero_only_(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), queue_zero_only_(false)
9998
{}
10099

101100
CaptureManager::~CaptureManager()
@@ -683,7 +682,7 @@ bool CaptureManager::ShouldTriggerScreenshot()
683682
uint32_t target_frame = screenshot_indices_.back();
684683

685684
// If this is a frame of interest, take a screenshot
686-
if (target_frame == (global_frame_count_ + 1))
685+
if (target_frame == current_frame_)
687686
{
688687
triger_screenshot = true;
689688

@@ -701,12 +700,27 @@ bool CaptureManager::ShouldTriggerScreenshot()
701700
return triger_screenshot;
702701
}
703702

703+
void CaptureManager::WriteFrameMarker(format::MarkerType marker_type)
704+
{
705+
if ((capture_mode_ & kModeWrite) == kModeWrite)
706+
{
707+
format::Marker marker_cmd;
708+
uint64_t header_size = sizeof(format::Marker);
709+
marker_cmd.header.type = format::BlockType::kFrameMarkerBlock;
710+
marker_cmd.header.size = header_size;
711+
marker_cmd.marker_type = marker_type;
712+
marker_cmd.frame_number = current_frame_;
713+
current_frame_;
714+
WriteToFile(&marker_cmd, header_size);
715+
}
716+
}
717+
704718
void CaptureManager::EndFrame()
705719
{
720+
++current_frame_;
721+
706722
if (trim_enabled_)
707723
{
708-
++current_frame_;
709-
710724
if ((capture_mode_ & kModeWrite) == kModeWrite)
711725
{
712726
// Currently capturing a frame range.
@@ -721,8 +735,6 @@ void CaptureManager::EndFrame()
721735
}
722736
}
723737

724-
global_frame_count_++;
725-
726738
// Flush after presents to help avoid capture files with incomplete final blocks.
727739
if (file_stream_.get() != nullptr)
728740
{

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();
@@ -265,7 +267,6 @@ class CaptureManager
265267
util::Keyboard keyboard_;
266268
std::string screenshot_prefix_;
267269
util::ScreenshotFormat screenshot_format_;
268-
uint32_t global_frame_count_;
269270

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

framework/encode/d3d12_capture_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void D3D12CaptureManager::PrePresent(IDXGISwapChain_Wrapper* swapchain_wrapper)
546546
gfxrecon::graphics::dx12::TakeScreenshot(frame_buffer_renderer_,
547547
swapchain_info->command_queue,
548548
swapchain,
549-
global_frame_count_ + 1,
549+
GetCurrentFrame(),
550550
screenshot_prefix_,
551551
screenshot_format_);
552552
}

framework/encode/vulkan_capture_manager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,11 @@ class VulkanCaptureManager : public CaptureManager
923923
GFXRECON_ASSERT(cmd_buffer_wrapper != nullptr);
924924
if (cmd_buffer_wrapper->is_frame_boundary)
925925
{
926+
// Because not all vkQueueSubmit calls are frame delimiters, add an end frame marker to the capture
927+
// file for this vkQueueSubmit.
928+
WriteFrameMarker(format::MarkerType::kEndMarker);
929+
930+
// Do common capture manager end of frame processing.
926931
EndFrame();
927932
break;
928933
}

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)