Skip to content

Commit

Permalink
plumb filename instead of attaching to FileOutputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
bradgrantham-lunarg authored and panos-lunarg committed Oct 25, 2024
1 parent b538408 commit 427af72
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 33 deletions.
11 changes: 7 additions & 4 deletions framework/encode/api_capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ class ApiCaptureManager
static auto AcquireExclusiveApiCallLock() { return std::move(CommonCaptureManager::AcquireExclusiveApiCallLock()); }

// Virtual interface
virtual void CreateStateTracker() = 0;
virtual void DestroyStateTracker() = 0;
virtual void CreateStateTracker() = 0;
virtual void DestroyStateTracker() = 0;
virtual void WriteTrackedState(util::FileOutputStream* file_stream,
format::ThreadId thread_id,
util::FileOutputStream* asset_file_stream = nullptr) = 0;
virtual void WriteAssets(util::FileOutputStream* asset_file_stream, format::ThreadId thread_id) = 0;
util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name) = 0;
virtual void WriteAssets(util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name,
format::ThreadId thread_id) = 0;

virtual CaptureSettings::TraceSettings GetDefaultTraceSettings();

Expand Down
18 changes: 9 additions & 9 deletions framework/encode/capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ void CommonCaptureManager::CheckStartCaptureForTrackMode(format::ApiFamilyId

for (auto& manager : api_capture_managers_)
{
manager.first->WriteAssets(asset_file_stream_.get(), thread_data->thread_id_);
manager.first->WriteAssets(asset_file_stream_.get(), asset_file_name_, thread_data->thread_id_);
}

capture_mode_ = kModeTrack;
Expand Down Expand Up @@ -1047,16 +1047,16 @@ std::string CommonCaptureManager::CreateTrimDrawCallsFilename(const std::string&
return util::filepath::InsertFilenamePostfix(base_filename, range_string);
}

std::string CommonCaptureManager::CreateAssetFile()
void CommonCaptureManager::CreateAssetFile()
{
std::string asset_file_name = CreateAssetFilename(base_filename_);
asset_file_name_ = CreateAssetFilename(base_filename_);

if (timestamp_filename_)
{
asset_file_name = util::filepath::GenerateTimestampedFilename(asset_file_name);
asset_file_name_ = util::filepath::GenerateTimestampedFilename(asset_file_name_);
}

asset_file_stream_ = std::make_unique<util::FileOutputStream>(asset_file_name, kFileStreamBufferSize);
asset_file_stream_ = std::make_unique<util::FileOutputStream>(asset_file_name_, kFileStreamBufferSize);
if (asset_file_stream_->IsValid())
{
WriteFileHeader(asset_file_stream_.get());
Expand All @@ -1065,8 +1065,6 @@ std::string CommonCaptureManager::CreateAssetFile()
{
asset_file_stream_ = nullptr;
}

return asset_file_name;
}

std::string CommonCaptureManager::CreateAssetFilename(const std::string& base_filename) const
Expand Down Expand Up @@ -1238,8 +1236,10 @@ void CommonCaptureManager::ActivateTrimming(std::shared_lock<ApiCallMutexT>& cur

for (auto& manager : api_capture_managers_)
{
manager.first->WriteTrackedState(
file_stream_.get(), thread_data->thread_id_, use_asset_file_ ? asset_file_stream_.get() : nullptr);
manager.first->WriteTrackedState(file_stream_.get(),
thread_data->thread_id_,
use_asset_file_ ? asset_file_stream_.get() : nullptr,
use_asset_file_ ? asset_file_name_ : "");
}
}

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 @@ -278,7 +278,7 @@ class CommonCaptureManager
std::string CreateTrimFilename(const std::string& base_filename, const util::UintRange& trim_range);
std::string CreateTrimDrawCallsFilename(const std::string& base_filename,
const CaptureSettings::TrimDrawCalls& trim_draw_calls);
std::string CreateAssetFile();
void CreateAssetFile();
std::string CreateAssetFilename(const std::string& base_filename) const;
bool CreateCaptureFile(format::ApiFamilyId api_family, const std::string& base_filename);
void WriteCaptureOptions(std::string& operation_annotation);
Expand Down Expand Up @@ -377,6 +377,7 @@ class CommonCaptureManager
format::EnabledOptions file_options_;
std::string base_filename_;
std::string capture_filename_;
std::string asset_file_name_;
bool timestamp_filename_;
bool force_file_flush_;
CaptureSettings::MemoryTrackingMode memory_tracking_mode_;
Expand Down
19 changes: 15 additions & 4 deletions framework/encode/vulkan_capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,29 @@ void VulkanCaptureManager::DestroyInstance()

void VulkanCaptureManager::WriteTrackedState(util::FileOutputStream* file_stream,
format::ThreadId thread_id,
util::FileOutputStream* asset_file_stream)
util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name)
{
uint64_t n_blocks = state_tracker_->WriteState(
file_stream, thread_id, [] { return GetUniqueId(); }, GetCompressor(), GetCurrentFrame(), asset_file_stream);
file_stream,
thread_id,
[] { return GetUniqueId(); },
GetCompressor(),
GetCurrentFrame(),
asset_file_stream,
asset_file_name);

common_manager_->IncrementBlockIndex(n_blocks);
}

void VulkanCaptureManager::WriteAssets(util::FileOutputStream* asset_file_stream, format::ThreadId thread_id)
void VulkanCaptureManager::WriteAssets(util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name,
format::ThreadId thread_id)
{
assert(state_tracker_ != nullptr);
uint64_t n_blocks = state_tracker_->WriteAssets(
asset_file_stream, thread_id, [] { return GetUniqueId(); }, GetCompressor());
asset_file_stream, asset_file_name, thread_id, [] { return GetUniqueId(); }, GetCompressor());

common_manager_->IncrementBlockIndex(n_blocks);
}

Expand Down
7 changes: 5 additions & 2 deletions framework/encode/vulkan_capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1604,9 +1604,12 @@ class VulkanCaptureManager : public ApiCaptureManager

virtual void WriteTrackedState(util::FileOutputStream* file_stream,
format::ThreadId thread_id,
util::FileOutputStream* asset_file_stream = nullptr) override;
util::FileOutputStream* asset_file_stream = nullptr,
const std::string& asset_file_name = "") override;

virtual void WriteAssets(util::FileOutputStream* asset_file_stream, format::ThreadId thread_id) override;
virtual void WriteAssets(util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name,
format::ThreadId thread_id) override;

private:
struct HardwareBufferInfo
Expand Down
7 changes: 5 additions & 2 deletions framework/encode/vulkan_state_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,31 @@ class VulkanStateTracker
std::function<format::HandleId()> get_unique_id_fn,
util::Compressor* compressor,
uint64_t frame_number,
util::FileOutputStream* asset_file_stream = nullptr)
util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name)
{
VulkanStateWriter state_writer(file_stream,
compressor,
thread_id,
get_unique_id_fn,
asset_file_stream,
asset_file_name,
asset_file_stream != nullptr ? &asset_file_offsets_ : nullptr);

std::unique_lock<std::mutex> lock(state_table_mutex_);
return state_writer.WriteState(state_table_, frame_number);
}

uint64_t WriteAssets(util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name,
format::ThreadId thread_id,
std::function<format::HandleId()> get_unique_id_fn,
util::Compressor* compressor)
{
assert(asset_file_stream != nullptr);

VulkanStateWriter state_writer(
nullptr, compressor, thread_id, get_unique_id_fn, asset_file_stream, &asset_file_offsets_);
nullptr, compressor, thread_id, get_unique_id_fn, asset_file_stream, asset_file_name, &asset_file_offsets_);

std::unique_lock<std::mutex> lock(state_table_mutex_);
return state_writer.WriteAssets(state_table_);
Expand Down
19 changes: 11 additions & 8 deletions framework/encode/vulkan_state_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ VulkanStateWriter::VulkanStateWriter(util::FileOutputStream* ou
format::ThreadId thread_id,
std::function<format::HandleId()> get_unique_id_fn,
util::FileOutputStream* asset_file_stream,
const std::string& asset_file_name,
VulkanStateWriter::AssetFileOffsetsInfo* asset_file_offsets) :
output_stream_(output_stream),
compressor_(compressor), thread_id_(thread_id), encoder_(&parameter_stream_),
get_unique_id_(std::move(get_unique_id_fn)), asset_file_stream_(asset_file_stream),
asset_file_offsets_(asset_file_offsets)
asset_file_name_(asset_file_name), asset_file_offsets_(asset_file_offsets)
{
assert(output_stream != nullptr || asset_file_stream != nullptr);
}
Expand Down Expand Up @@ -990,7 +991,7 @@ void VulkanStateWriter::WriteDescriptorSetStateWithAssetFile(const VulkanStateTa
wrapper->set_layout_dependency.create_call_id, dep_create_parameters, asset_file_stream_);
if (output_stream_ != nullptr)
{
WriteExecuteFromFile(asset_file_stream_->GetFilename(), 1, offset);
WriteExecuteFromFile(asset_file_name_, 1, offset);
}
}
else
Expand All @@ -999,7 +1000,7 @@ void VulkanStateWriter::WriteDescriptorSetStateWithAssetFile(const VulkanStateTa
{
assert((*asset_file_offsets_).find(wrapper->handle_id) != (*asset_file_offsets_).end());
const int64_t offset = (*asset_file_offsets_)[wrapper->handle_id];
WriteExecuteFromFile(asset_file_stream_->GetFilename(), 1, offset);
WriteExecuteFromFile(asset_file_name_, 1, offset);
}
}
}
Expand Down Expand Up @@ -1106,7 +1107,7 @@ void VulkanStateWriter::WriteDescriptorSetStateWithAssetFile(const VulkanStateTa
// as execute till the end of file
if (output_stream_ != nullptr && n_blocks)
{
WriteExecuteFromFile(asset_file_stream_->GetFilename(), n_blocks, offset);
WriteExecuteFromFile(asset_file_name_, n_blocks, offset);
}

if (wrapper->dirty)
Expand Down Expand Up @@ -2253,7 +2254,7 @@ void VulkanStateWriter::ProcessBufferMemoryWithAssetFile(const vulkan_wrappers::

if (output_stream_ != nullptr)
{
WriteExecuteFromFile(asset_file_stream_->GetFilename(), 1, offset);
WriteExecuteFromFile(asset_file_name_, 1, offset);
}

++blocks_written_;
Expand All @@ -2275,7 +2276,7 @@ void VulkanStateWriter::ProcessBufferMemoryWithAssetFile(const vulkan_wrappers::
{
assert((*asset_file_offsets_).find(buffer_wrapper->handle_id) != (*asset_file_offsets_).end());
const int64_t offset = (*asset_file_offsets_)[buffer_wrapper->handle_id];
WriteExecuteFromFile(asset_file_stream_->GetFilename(), 1, offset);
WriteExecuteFromFile(asset_file_name_, 1, offset);
}
}
}
Expand Down Expand Up @@ -2573,7 +2574,7 @@ void VulkanStateWriter::ProcessImageMemoryWithAssetFile(const vulkan_wrappers::D

if (output_stream_ != nullptr)
{
WriteExecuteFromFile(asset_file_stream_->GetFilename(), 1, offset);
WriteExecuteFromFile(asset_file_name_, 1, offset);
}

if (!snapshot_entry.need_staging_copy && memory_wrapper->mapped_data == nullptr)
Expand Down Expand Up @@ -2603,7 +2604,7 @@ void VulkanStateWriter::ProcessImageMemoryWithAssetFile(const vulkan_wrappers::D
{
assert((*asset_file_offsets_).find(image_wrapper->handle_id) != (*asset_file_offsets_).end());
const int64_t offset = (*asset_file_offsets_)[image_wrapper->handle_id];
WriteExecuteFromFile(asset_file_stream_->GetFilename(), 1, offset);
WriteExecuteFromFile(asset_file_name_, 1, offset);
}
}
}
Expand Down Expand Up @@ -4421,6 +4422,8 @@ bool VulkanStateWriter::IsFramebufferValid(const vulkan_wrappers::FramebufferWra

void VulkanStateWriter::WriteExecuteFromFile(const std::string& filename, uint32_t n_blocks, int64_t offset)
{
assert(!filename.empty());

// Remove path from filename
std::string relative_file;
const size_t last_slash_pos = filename.find_last_of("\\/");
Expand Down
2 changes: 2 additions & 0 deletions framework/encode/vulkan_state_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class VulkanStateWriter
format::ThreadId thread_id,
std::function<format::HandleId()> get_unique_id_fn,
util::FileOutputStream* asset_file_stream = nullptr,
const std::string& asset_file_name = "",
VulkanStateWriter::AssetFileOffsetsInfo* asset_file_offsets = nullptr);

// Returns number of blocks written to the output_stream.
Expand Down Expand Up @@ -430,6 +431,7 @@ class VulkanStateWriter
std::function<format::HandleId()> get_unique_id_;

util::FileOutputStream* asset_file_stream_;
std::string asset_file_name_;
AssetFileOffsetsInfo* asset_file_offsets_;
};

Expand Down
2 changes: 1 addition & 1 deletion framework/util/file_output_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(util)

FileOutputStream::FileOutputStream(const std::string& filename, size_t buffer_size, bool append) :
file_(nullptr), own_file_(true), filename(filename)
file_(nullptr), own_file_(true)
{
const char* mode = append ? "ab" : "wb";
int32_t result = platform::FileOpen(&file_, filename.c_str(), mode);
Expand Down
2 changes: 0 additions & 2 deletions framework/util/file_output_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class FileOutputStream : public OutputStream

virtual int64_t GetOffset() const { return platform::FileTell(file_); }

virtual const std::string& GetFilename() const { return filename; }

protected:
FileOutputStream(const FileOutputStream&) = delete;
FileOutputStream& operator=(const FileOutputStream&) = delete;
Expand Down

0 comments on commit 427af72

Please sign in to comment.