Skip to content

Commit

Permalink
encode: CommandWriter
Browse files Browse the repository at this point in the history
Move CombineAndWrite helper function to OutputStream and introduce two
new classes to extract some common code.

- The capture manager performs some operations before and after writing
  to a file output stream. Make this explicit by wrapping the file output
  stream in a decorator class.

- CommandWriter is an encode utility for writing commands to an output
  stream and it's used by both the capture manager and the state tracker.
  • Loading branch information
antonio-lunarg committed Jan 30, 2025
1 parent 47c218b commit f74a09c
Show file tree
Hide file tree
Showing 21 changed files with 775 additions and 397 deletions.
2 changes: 2 additions & 0 deletions android/framework/encode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ target_sources(gfxrecon_encode
${GFXRECON_SOURCE_DIR}/framework/encode/capture_manager.cpp
${GFXRECON_SOURCE_DIR}/framework/encode/capture_settings.h
${GFXRECON_SOURCE_DIR}/framework/encode/capture_settings.cpp
${GFXRECON_SOURCE_DIR}/framework/encode/command_writer.h
${GFXRECON_SOURCE_DIR}/framework/encode/command_writer.cpp
${GFXRECON_SOURCE_DIR}/framework/encode/custom_vulkan_encoder_commands.h
${GFXRECON_SOURCE_DIR}/framework/encode/custom_vulkan_api_call_encoders.h
${GFXRECON_SOURCE_DIR}/framework/encode/custom_vulkan_api_call_encoders.cpp
Expand Down
2 changes: 2 additions & 0 deletions android/framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ target_sources(gfxrecon_util
${GFXRECON_SOURCE_DIR}/framework/util/spirv_parsing_util.cpp
${GFXRECON_SOURCE_DIR}/framework/util/strings.h
${GFXRECON_SOURCE_DIR}/framework/util/strings.cpp
${GFXRECON_SOURCE_DIR}/framework/util/thread_data.h
${GFXRECON_SOURCE_DIR}/framework/util/thread_data.cpp
${GFXRECON_SOURCE_DIR}/framework/util/to_string.h
${GFXRECON_SOURCE_DIR}/framework/util/to_string.cpp
${GFXRECON_SOURCE_DIR}/framework/util/options.h
Expand Down
21 changes: 9 additions & 12 deletions framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4360,9 +4360,9 @@ VkResult VulkanReplayConsumerBase::OverrideAllocateMemory(

VulkanResourceAllocator::MemoryData allocator_data;

auto *modified_allocate_info = const_cast<VkMemoryAllocateInfo*>(pAllocateInfo->GetPointer());
auto replay_memory = pMemory->GetHandlePointer();
auto capture_id = (*pMemory->GetPointer());
auto* modified_allocate_info = const_cast<VkMemoryAllocateInfo*>(pAllocateInfo->GetPointer());
auto replay_memory = pMemory->GetHandlePointer();
auto capture_id = (*pMemory->GetPointer());

#if defined(VK_USE_PLATFORM_ANDROID_KHR)
ProcessImportAndroidHardwareBufferInfo(pAllocateInfo);
Expand Down Expand Up @@ -4450,18 +4450,15 @@ VkResult VulkanReplayConsumerBase::OverrideAllocateMemory(
opaque_address = 0;
}

VkMemoryOpaqueCaptureAddressAllocateInfo address_info = {
VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO,
modified_allocate_info->pNext,
opaque_address
VkMemoryOpaqueCaptureAddressAllocateInfo address_info = {
VK_STRUCTURE_TYPE_MEMORY_OPAQUE_CAPTURE_ADDRESS_ALLOCATE_INFO,
modified_allocate_info->pNext,
opaque_address
};
modified_allocate_info->pNext = &address_info;

result = allocator->AllocateMemory(modified_allocate_info,
GetAllocationCallbacks(pAllocator),
capture_id,
replay_memory,
&allocator_data);
result = allocator->AllocateMemory(
modified_allocate_info, GetAllocationCallbacks(pAllocator), capture_id, replay_memory, &allocator_data);
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion framework/encode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2018-2022 LunarG, Inc.
# Copyright (c) 2018-2025 LunarG, Inc.
# Copyright (c) 2019-2023 Advanced Micro Devices, Inc.
# All rights reserved
#
Expand Down Expand Up @@ -36,6 +36,8 @@ target_sources(gfxrecon_encode
${CMAKE_CURRENT_LIST_DIR}/capture_manager.cpp
${CMAKE_CURRENT_LIST_DIR}/capture_settings.h
${CMAKE_CURRENT_LIST_DIR}/capture_settings.cpp
${CMAKE_CURRENT_LIST_DIR}/command_writer.h
${CMAKE_CURRENT_LIST_DIR}/command_writer.cpp
${CMAKE_CURRENT_LIST_DIR}/custom_vulkan_encoder_commands.h
${CMAKE_CURRENT_LIST_DIR}/custom_vulkan_api_call_encoders.h
${CMAKE_CURRENT_LIST_DIR}/custom_vulkan_api_call_encoders.cpp
Expand Down
39 changes: 17 additions & 22 deletions framework/encode/api_capture_manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2022 Valve Corporation
** Copyright (c) 2018-2024 LunarG, Inc.
** Copyright (c) 2018-2025 LunarG, Inc.
** Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -43,16 +43,16 @@ class ApiCaptureManager
static auto AcquireExclusiveApiCallLock() { return std::move(CommonCaptureManager::AcquireExclusiveApiCallLock()); }

// Virtual interface
virtual void CreateStateTracker() = 0;
virtual void DestroyStateTracker() = 0;
virtual void WriteTrackedState(util::FileOutputStream* file_stream, format::ThreadId thread_id) = 0;
virtual void CreateStateTracker() = 0;
virtual void DestroyStateTracker() = 0;
virtual void WriteTrackedState(util::FileOutputStream* file_stream, util::ThreadData* thread_data) = 0;
virtual void WriteTrackedStateWithAssetFile(util::FileOutputStream* file_stream,
format::ThreadId thread_id,
util::ThreadData* thread_data,
util::FileOutputStream* asset_file_stream,
const std::string* asset_file_name) = 0;
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;
util::ThreadData* thread_data) = 0;

virtual CaptureSettings::TraceSettings GetDefaultTraceSettings();

Expand Down Expand Up @@ -212,12 +212,6 @@ class ApiCaptureManager
common_manager_->WriteEndResourceInitCmd(api_family_, device_id);
}

void WriteInitBufferCmd(
format::HandleId device_id, format::HandleId buffer_id, uint64_t offset, uint64_t size, const void* data)
{
common_manager_->WriteInitBufferCmd(api_family_, device_id, buffer_id, offset, size, data);
}

void WriteCreateHeapAllocationCmd(uint64_t allocation_id, uint64_t allocation_size)
{
common_manager_->WriteCreateHeapAllocationCmd(api_family_, allocation_id, allocation_size);
Expand All @@ -230,15 +224,16 @@ class ApiCaptureManager
common_manager_->CombineAndWriteToFile<N>(buffers);
}

CommonCaptureManager::ThreadData* GetThreadData() { return common_manager_->GetThreadData(); }
util::Compressor* GetCompressor() { return common_manager_->GetCompressor(); }
std::mutex& GetMappedMemoryLock() { return common_manager_->GetMappedMemoryLock(); }
util::Keyboard& GetKeyboard() { return common_manager_->GetKeyboard(); }
const std::string& GetScreenshotPrefix() const { return common_manager_->GetScreenshotPrefix(); }
util::ScreenshotFormat GetScreenshotFormat() { return common_manager_->GetScreenshotFormat(); }
auto GetTrimBoundary() const { return common_manager_->GetTrimBoundary(); }
auto GetTrimDrawCalls() const { return common_manager_->GetTrimDrawCalls(); }
bool GetUseAssetFile() const { return common_manager_->GetUseAssetFile(); }
util::ThreadData* GetThreadData() { return common_manager_->GetThreadData(); }
util::Compressor* GetCompressor() { return common_manager_->GetCompressor(); }
std::mutex& GetMappedMemoryLock() { return common_manager_->GetMappedMemoryLock(); }
util::Keyboard& GetKeyboard() { return common_manager_->GetKeyboard(); }
const std::string& GetScreenshotPrefix() const { return common_manager_->GetScreenshotPrefix(); }
util::ScreenshotFormat GetScreenshotFormat() { return common_manager_->GetScreenshotFormat(); }
auto GetTrimBoundary() const { return common_manager_->GetTrimBoundary(); }
auto GetTrimDrawCalls() const { return common_manager_->GetTrimDrawCalls(); }
bool GetUseAssetFile() const { return common_manager_->GetUseAssetFile(); }
CommandWriter* GetCommandWriter() { return common_manager_->GetCommandWriter(); }

protected:
const format::ApiFamilyId api_family_;
Expand Down
Loading

0 comments on commit f74a09c

Please sign in to comment.