Skip to content

Commit

Permalink
Expose WriteAssetsGFXR through the layer
Browse files Browse the repository at this point in the history
  • Loading branch information
panos-lunarg committed Aug 2, 2024
1 parent 54585d4 commit e21b66f
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 131 deletions.
8 changes: 5 additions & 3 deletions framework/encode/api_capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ 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* asseet_file_stream = nullptr) = 0;
util::FileOutputStream* asseet_file_stream = nullptr) = 0;
virtual void WriteAssets(util::FileOutputStream* assert_file_stream, format::ThreadId thread_id) = 0;

virtual CaptureSettings::TraceSettings GetDefaultTraceSettings();

Expand Down Expand Up @@ -156,6 +157,7 @@ class ApiCaptureManager
uint16_t GetDescriptorMask() const { return common_manager_->GetDescriptorMask(); }
uint64_t GetShaderIDMask() const { return common_manager_->GetShaderIDMask(); }
uint64_t GetBlockIndex() const { return common_manager_->GetBlockIndex(); }
void SetWriteAssets() const { return common_manager_->SetWriteAssets(); }

bool GetForceFileFlush() const { return common_manager_->GetForceFileFlush(); }
CaptureSettings::MemoryTrackingMode GetMemoryTrackingMode() const
Expand Down
20 changes: 19 additions & 1 deletion framework/encode/capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ CommonCaptureManager::CommonCaptureManager() :
previous_runtime_trigger_state_(CaptureSettings::RuntimeTriggerState::kNotUsed), debug_layer_(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),
allow_pipeline_compile_required_(false), quit_after_frame_ranges_(false), use_asset_file_(false), block_index_(0)
allow_pipeline_compile_required_(false), quit_after_frame_ranges_(false), use_asset_file_(false), block_index_(0),
write_assets_(false)
{}

CommonCaptureManager::~CommonCaptureManager()
Expand Down Expand Up @@ -778,6 +779,21 @@ void CommonCaptureManager::CheckStartCaptureForTrackMode(format::ApiFamilyId api
capture_mode_ = kModeDisabled;
}
}
else if (write_assets_ && capture_mode_ == kModeTrack)
{
capture_mode_ |= kModeWrite;

auto thread_data = GetThreadData();
assert(thread_data != nullptr);

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

capture_mode_ = kModeTrack;
write_assets_ = false;
}
}

bool CommonCaptureManager::ShouldTriggerScreenshot()
Expand Down Expand Up @@ -1034,6 +1050,8 @@ void CommonCaptureManager::ActivateTrimming()
manager.first->WriteTrackedState(
file_stream_.get(), thread_data->thread_id_, use_asset_file_ ? asset_file_stream_.get() : nullptr);
}

write_assets_ = false;
}

void CommonCaptureManager::DeactivateTrimming()
Expand Down
3 changes: 3 additions & 0 deletions framework/encode/capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ class CommonCaptureManager
GetThreadData()->block_index_ = block_index_;
}

void SetWriteAssets() { write_assets_ = true; }

protected:
std::unique_ptr<util::Compressor> compressor_;
std::mutex mapped_memory_lock_;
Expand Down Expand Up @@ -384,6 +386,7 @@ class CommonCaptureManager
bool allow_pipeline_compile_required_;
bool quit_after_frame_ranges_;
bool use_asset_file_;
bool write_assets_;

struct
{
Expand Down
3 changes: 2 additions & 1 deletion framework/encode/custom_layer_func_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
GFXRECON_BEGIN_NAMESPACE(gfxrecon)

const std::unordered_map<std::string, PFN_vkVoidFunction> custom_func_table = {
{ "GetBlockIndexGFXR", reinterpret_cast<PFN_vkVoidFunction>(encode::GetBlockIndexGFXR) }
{ "GetBlockIndexGFXR", reinterpret_cast<PFN_vkVoidFunction>(encode::GetBlockIndexGFXR) },
{ "DumpDirtyAssetsGFXR", reinterpret_cast<PFN_vkVoidFunction>(encode::WriteAssetsGFXR) }
};

GFXRECON_END_NAMESPACE(gfxrecon)
Expand Down
6 changes: 6 additions & 0 deletions framework/encode/custom_vulkan_api_call_encoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ VKAPI_ATTR uint64_t VKAPI_CALL GetBlockIndexGFXR()
return manager->GetBlockIndex();
}

VKAPI_ATTR void VKAPI_CALL WriteAssetsGFXR()
{
VulkanCaptureManager* manager = VulkanCaptureManager::Get();
manager->SetWriteAssets();
}

VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device,
VkPipelineCache pipelineCache,
uint32_t createInfoCount,
Expand Down
2 changes: 2 additions & 0 deletions framework/encode/custom_vulkan_api_call_encoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ VKAPI_ATTR VkResult VKAPI_CALL CopyAccelerationStructureKHR(VkDevice

VKAPI_ATTR uint64_t VKAPI_CALL GetBlockIndexGFXR();

VKAPI_ATTR void VKAPI_CALL WriteAssetsGFXR();

VKAPI_ATTR VkResult VKAPI_CALL CreateGraphicsPipelines(VkDevice device,
VkPipelineCache pipelineCache,
uint32_t createInfoCount,
Expand Down
6 changes: 6 additions & 0 deletions framework/encode/vulkan_capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ void VulkanCaptureManager::WriteTrackedState(util::FileOutputStream* file_stream
common_manager_->IncrementBlockIndex(n_blocks);
}

void VulkanCaptureManager::WriteAssets(util::FileOutputStream* assert_file_stream, format::ThreadId thread_id)
{
assert(state_tracker_ != nullptr);
state_tracker_->WriteAssets(assert_file_stream, thread_id, GetCompressor());
}

void VulkanCaptureManager::SetLayerFuncs(PFN_vkCreateInstance create_instance, PFN_vkCreateDevice create_device)
{
assert((create_instance != nullptr) && (create_device != nullptr));
Expand Down
2 changes: 2 additions & 0 deletions framework/encode/vulkan_capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,8 @@ class VulkanCaptureManager : public ApiCaptureManager
format::ThreadId thread_id,
util::FileOutputStream* assert_file_stream = nullptr) override;

virtual void WriteAssets(util::FileOutputStream* assert_file_stream, format::ThreadId thread_id) override;

private:
struct HardwareBufferInfo
{
Expand Down
11 changes: 11 additions & 0 deletions framework/encode/vulkan_state_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ class VulkanStateTracker
return state_writer.WriteState(state_table_, frame_number);
}

uint64_t
WriteAssets(util::FileOutputStream* asset_file_stream, format::ThreadId thread_id, util::Compressor* compressor)
{
assert(asset_file_stream != nullptr);

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

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

template <typename ParentHandle, typename Wrapper, typename CreateInfo>
void AddEntry(ParentHandle parent_handle,
typename Wrapper::HandleType* new_handle,
Expand Down
Loading

0 comments on commit e21b66f

Please sign in to comment.