Skip to content

Commit

Permalink
Merge branch 'dev' into replay-pipeline-caches
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-pelegrin-arm authored Sep 27, 2023
2 parents 2de4d42 + f3de76c commit b3848bb
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 122 deletions.
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ option(BUILD_WERROR "Build with warnings as errors" ON)
include("CodeStyle")
include("Lint")
include("Test")
include("FindVulkanVersion")

# Apply misc build directives to the given target
macro(common_build_directives TARGET)
Expand Down Expand Up @@ -175,7 +174,7 @@ if(MSVC)
"set D3D12_SUPPORT=OFF or configure the build with the recommended Windows SDK version. See BUILD.md "
"for more information.")
endif()

else()
set(BUILD_LAUNCHER_AND_INTERCEPTOR OFF)
endif()
Expand All @@ -187,22 +186,22 @@ if(MSVC)

# Add option to enable/disable AGS support.
option(GFXRECON_AGS_SUPPORT "Build with AGS support enabled. Ignored if D3D12_SUPPORT=OFF." ON)

if (${D3D12_SUPPORT})
if (${GFXRECON_AGS_SUPPORT})
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_package(AGS)
if (TARGET AGS::AGS)
add_definitions(-DGFXRECON_AGS_SUPPORT)

# The value for option GFXRECON_AGS_SUPPORT gets cached so use a non-cached variable
# to determine the final result.
set(GFXRECON_AGS_SUPPORT_FINAL ON)
endif() # TARGET AGS::AGS
endif() # CMAKE_SIZEOF_VOID_P EQUAL 8
endif() # GFXRECON_AGS_SUPPORT
endif() # D3D12_SUPPORT

else(MSVC)
# Turn off D3D12 support for non MSVC builds.
set(D3D12_SUPPORT OFF)
Expand Down Expand Up @@ -288,9 +287,12 @@ if(BUILD_WERROR)
endif()
endif()

add_library(vulkan_registry INTERFACE)
target_include_directories(vulkan_registry INTERFACE ${CMAKE_SOURCE_DIR}/external/Vulkan-Headers/include)
target_compile_definitions(vulkan_registry INTERFACE VK_NO_PROTOTYPES VK_ENABLE_BETA_EXTENSIONS)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/Vulkan-Headers)
message(FATAL_ERROR "The Vulkan-Headers submodule has not been initialized! Please run `git submodule update --init` in the source directory.")
endif()

add_subdirectory(${CMAKE_SOURCE_DIR}/external/Vulkan-Headers)
target_compile_definitions(Vulkan-Headers INTERFACE VK_NO_PROTOTYPES VK_ENABLE_BETA_EXTENSIONS)

add_library(vulkan_memory_allocator INTERFACE)
target_compile_options(vulkan_memory_allocator INTERFACE
Expand Down
10 changes: 10 additions & 0 deletions USAGE_desktop_D3D12.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Usage:
[-m <mode> | --memory-translation <mode>]
[--fw <width,height> | --force-windowed <width,height>]
[--log-level <level>] [--log-file <file>] [--log-debugview]
[--batching-memory-usage <pct>]
[--api <api>] <file>
Required arguments:
Expand Down Expand Up @@ -327,6 +328,15 @@ D3D12-only:
--dx12-override-object-names Generates unique names for all ID3D12Objects and
assigns each object the generated name.
This is intended to assist replay debugging.
--batching-memory-usage <pct>
Limits the max amount of additional memory that can be used to batch
resource data uploads during trim state load. Batching resource data
uploads may reduce the number of GPU submissions required to load the
trim state. <pct> is applied to the total available physical system memory
and to the application's GPU memory budget. This only limits memory use
for batching and does not guarantee overall max memory usage.
Acceptable values range from 0 to 100 (default: 80). 0 means no batching,
100 means use all available system and GPU memory.
```


Expand Down
2 changes: 1 addition & 1 deletion android/framework/encode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_library(gfxrecon_encode STATIC "")
target_sources(gfxrecon_encode
PRIVATE
${GFXRECON_SOURCE_DIR}/framework/encode/capture_manager.h
${GFXRECON_SOURCE_DIR}/framework/encode/capture_manager.cpp
${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/custom_vulkan_encoder_commands.h
Expand Down
73 changes: 0 additions & 73 deletions cmake/FindVulkanVersion.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion cmake/GenerateLayerJson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function(GENERATE_LAYER_JSON_FILE TARGET RELATIVE_PATH_PREFIX LAYER_BINARY IN_FI

set(CONFIG_DEFINES
-DINPUT_FILE=${IN_FILE}
-DVK_VERSION=${VULKAN_VERSION_MAJOR}.${VULKAN_VERSION_MINOR}.${VULKAN_VERSION_PATCH}
-DVK_VERSION=${VULKAN_HEADERS_VERSION}
-DGFXRECONSTRUCT_VERSION=${GFXRECONSTRUCT_LAYER_JSON_VERSION}
-DGFXRECONSTRUCT_VERSION_STRING=${GFXRECONSTRUCT_PROJECT_VERSION_MAJOR}.${GFXRECONSTRUCT_PROJECT_VERSION_MINOR}.${GFXRECONSTRUCT_PROJECT_VERSION_PATCH}${GFXRECON_PROJECT_VERSION_DESIGNATION}
-DOUTPUT_FILE=${OUT_FILE}
Expand Down
2 changes: 1 addition & 1 deletion framework/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ target_link_libraries(gfxrecon_application
gfxrecon_graphics
gfxrecon_format
gfxrecon_util
vulkan_registry
Vulkan::Headers
platform_specific
)

Expand Down
2 changes: 1 addition & 1 deletion framework/decode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ target_include_directories(gfxrecon_decode
${CMAKE_SOURCE_DIR}/framework
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_SOURCE_DIR}/external/AgilitySDK/inc>)

target_link_libraries(gfxrecon_decode gfxrecon_graphics gfxrecon_format gfxrecon_util vulkan_registry vulkan_memory_allocator platform_specific nlohmann_json::nlohmann_json $<$<BOOL:${D3D12_SUPPORT}>:dxguid.lib>)
target_link_libraries(gfxrecon_decode gfxrecon_graphics gfxrecon_format gfxrecon_util Vulkan::Headers vulkan_memory_allocator platform_specific nlohmann_json::nlohmann_json $<$<BOOL:${D3D12_SUPPORT}>:dxguid.lib>)

common_build_directives(gfxrecon_decode)

Expand Down
6 changes: 6 additions & 0 deletions framework/decode/api_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ GFXRECON_BEGIN_NAMESPACE(decode)

struct ApiCallInfo
{
/// The block index of a function call. Stream processors like FileProcessor
/// must set this before dispatching function calls to decoders.
/// @note This is lightly used: only for a log output in replay and for JSON
/// Convert.
/// @see ApiDecoder::SetCurrentBlockIndex() which can pass the block index
/// to decoders so it is available for any block type, not just API calls.
uint64_t index{ 0 };
format::ThreadId thread_id{ 0 };
};
Expand Down
4 changes: 2 additions & 2 deletions framework/decode/dx12_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ void Dx12ReplayConsumerBase::ProcessInitSubresourceCommand(const format::InitSub
// If no entry exists in resource_init_infos_, this is the first subresource of a new resource.
GFXRECON_ASSERT(command_header.subresource == 0);

const double max_cpu_mem_usage = 15.0 / 16.0;
const double max_mem_usage = static_cast<double>(options_.memory_usage) / 100.0;
if (!graphics::dx12::IsMemoryAvailable(
total_size_in_bytes, extra_device_info->adapter3, max_cpu_mem_usage, extra_device_info->is_uma))
total_size_in_bytes, extra_device_info->adapter3, max_mem_usage, extra_device_info->is_uma))
{
// If neither system memory or GPU memory are able to accommodate next resource,
// execute the Copy() calls and release temp buffer to free memory
Expand Down
3 changes: 3 additions & 0 deletions framework/decode/dx_replay_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)

static constexpr uint32_t kDefaultBatchingMemoryUsage = 80;

struct DxReplayOptions : public ReplayOptions
{
bool enable_d3d12{ true };
Expand All @@ -50,6 +52,7 @@ struct DxReplayOptions : public ReplayOptions
std::string screenshot_dir;
std::string screenshot_file_prefix{ kDefaultScreenshotFilePrefix };
std::string replace_dir;
int32_t memory_usage{ kDefaultBatchingMemoryUsage };
};

GFXRECON_END_NAMESPACE(decode)
Expand Down
9 changes: 4 additions & 5 deletions framework/decode/file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,8 @@ bool FileProcessor::ProcessFunctionCall(const format::BlockHeader& block_header,
{
size_t parameter_buffer_size = static_cast<size_t>(block_header.size) - sizeof(call_id);
uint64_t uncompressed_size = 0;
ApiCallInfo call_info = {};
call_info.index = block_index_;
bool success = ReadBytes(&call_info.thread_id, sizeof(call_info.thread_id));
ApiCallInfo call_info{ block_index_ };
bool success = ReadBytes(&call_info.thread_id, sizeof(call_info.thread_id));

if (success)
{
Expand Down Expand Up @@ -590,7 +589,7 @@ bool FileProcessor::ProcessMethodCall(const format::BlockHeader& block_header, f
size_t parameter_buffer_size = static_cast<size_t>(block_header.size) - sizeof(call_id);
uint64_t uncompressed_size = 0;
format::HandleId object_id = 0;
ApiCallInfo call_info = {};
ApiCallInfo call_info{ block_index_ };

bool success = ReadBytes(&object_id, sizeof(object_id));
success = success && ReadBytes(&call_info.thread_id, sizeof(call_info.thread_id));
Expand Down Expand Up @@ -1835,7 +1834,7 @@ bool FileProcessor::ProcessStateMarker(const format::BlockHeader& block_header,

bool FileProcessor::ProcessAnnotation(const format::BlockHeader& block_header, format::AnnotationType annotation_type)
{
bool success = false;
bool success = false;
decltype(format::AnnotationHeader::label_length) label_length = 0;
decltype(format::AnnotationHeader::data_length) data_length = 0;

Expand Down
2 changes: 1 addition & 1 deletion framework/encode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ target_include_directories(gfxrecon_encode
${CMAKE_SOURCE_DIR}/framework
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_SOURCE_DIR}/external/AgilitySDK/inc>)

target_link_libraries(gfxrecon_encode gfxrecon_graphics gfxrecon_format gfxrecon_util vulkan_registry platform_specific)
target_link_libraries(gfxrecon_encode gfxrecon_graphics gfxrecon_format gfxrecon_util Vulkan::Headers platform_specific)

common_build_directives(gfxrecon_encode)

Expand Down
4 changes: 2 additions & 2 deletions framework/encode/dx12_state_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,11 @@ void Dx12StateWriter::WriteResourceSnapshots(
uint64_t size_in_bytes = resource_info.get()->size_in_bytes;
auto device_info = device_wrapper->GetObjectInfo();

const double max_cpu_mem_usage = 7.0 / 8.0;
const double max_mem_usage = 7.0 / 8.0;

const bool is_uma = device_wrapper->GetObjectInfo()->is_uma;
if (!graphics::dx12::IsMemoryAvailable(
size_in_bytes, device_info.get()->adapter3, max_cpu_mem_usage, is_uma))
size_in_bytes, device_info.get()->adapter3, max_mem_usage, is_uma))
{
// If neither system memory or GPU memory are able to accommodate next resource,
// execute the existing Copy() calls and release temp buffer to free memory
Expand Down
2 changes: 1 addition & 1 deletion framework/format/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ target_include_directories(gfxrecon_format
${CMAKE_SOURCE_DIR}/framework
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_SOURCE_DIR}/external/AgilitySDK/inc>)

target_link_libraries(gfxrecon_format gfxrecon_util vulkan_registry platform_specific)
target_link_libraries(gfxrecon_format gfxrecon_util Vulkan::Headers platform_specific)

common_build_directives(gfxrecon_format)

Expand Down
2 changes: 1 addition & 1 deletion framework/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ target_include_directories(gfxrecon_graphics
${CMAKE_SOURCE_DIR}/framework
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_SOURCE_DIR}/external/AgilitySDK/inc>)

target_link_libraries(gfxrecon_graphics gfxrecon_util vulkan_registry platform_specific $<$<BOOL:${D3D12_SUPPORT}>:D3DCompiler.lib>)
target_link_libraries(gfxrecon_graphics gfxrecon_util Vulkan::Headers platform_specific $<$<BOOL:${D3D12_SUPPORT}>:D3DCompiler.lib>)

common_build_directives(gfxrecon_graphics)

Expand Down
43 changes: 26 additions & 17 deletions framework/graphics/dx12_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,10 @@ bool IsUma(ID3D12Device* device)
return isUma;
}

uint64_t GetAvailableGpuAdapterMemory(IDXGIAdapter3* adapter, const bool is_uma)
uint64_t GetAvailableGpuAdapterMemory(IDXGIAdapter3* adapter, double memory_usage, const bool is_uma)
{
GFXRECON_ASSERT(memory_usage > 0.0 && memory_usage <= 1.0);
uint64_t available_mem = 0;

if (adapter != nullptr)
{
DXGI_QUERY_VIDEO_MEMORY_INFO video_memory_info = {};
Expand All @@ -992,13 +992,10 @@ uint64_t GetAvailableGpuAdapterMemory(IDXGIAdapter3* adapter, const bool is_uma)
}
if (SUCCEEDED(adapter->QueryVideoMemoryInfo(0, memory_segment, &video_memory_info)))
{
if (video_memory_info.Budget > video_memory_info.CurrentUsage)
{
available_mem = video_memory_info.Budget - video_memory_info.CurrentUsage;
}
else
uint64_t total_memory = static_cast<uint64_t>(video_memory_info.Budget * memory_usage);
if (total_memory > video_memory_info.CurrentUsage)
{
GFXRECON_LOG_ERROR("Detected adapter memory oversubscription");
available_mem = total_memory - video_memory_info.CurrentUsage;
}
}
else
Expand All @@ -1016,6 +1013,7 @@ uint64_t GetAvailableGpuAdapterMemory(IDXGIAdapter3* adapter, const bool is_uma)

uint64_t GetAvailableCpuMemory(double max_usage)
{
GFXRECON_ASSERT(max_usage > 0.0 && max_usage <= 1.0);
MEMORYSTATUSEX mem_info = {};
mem_info.dwLength = sizeof(MEMORYSTATUSEX);
if (GlobalMemoryStatusEx(&mem_info) == FALSE)
Expand All @@ -1030,27 +1028,38 @@ uint64_t GetAvailableCpuMemory(double max_usage)
double reserved_phys = mem_info.ullTotalPhys * (1.0 - max_usage);
avail_phys = static_cast<uint64_t>(std::max(0.0, mem_info.ullAvailPhys - reserved_phys));
}

// Always limit by available virtual memory.
return std::min(avail_phys, mem_info.ullAvailVirtual);
}

bool IsMemoryAvailable(uint64_t required_memory, IDXGIAdapter3* adapter, double max_cpu_mem_usage, const bool is_uma)
bool IsMemoryAvailable(uint64_t required_memory, IDXGIAdapter3* adapter, double max_mem_usage, const bool is_uma)
{
bool available = false;
if (max_mem_usage == 0.0)
{
// 0.0 means no batching, skip memory checking
return available;
}
#ifdef _WIN64
// For 32bit, only upload one buffer at one time, to save memory usage.
if (adapter != nullptr)
if (max_mem_usage > 0.0 && max_mem_usage <= 1.0)
{
uint64_t total_available_gpu_adapter_memory = GetAvailableGpuAdapterMemory(adapter, is_uma);
uint64_t total_available_cpu_memory = GetAvailableCpuMemory(max_cpu_mem_usage);
uint64_t total_required_memory = static_cast<uint64_t>(required_memory * kMemoryTolerance);
if ((total_required_memory < total_available_gpu_adapter_memory) &&
(total_required_memory < total_available_cpu_memory))
if (adapter != nullptr)
{
available = true;
uint64_t total_available_gpu_adapter_memory = GetAvailableGpuAdapterMemory(adapter, max_mem_usage, is_uma);
uint64_t total_available_cpu_memory = GetAvailableCpuMemory(max_mem_usage);
uint64_t total_required_memory = static_cast<uint64_t>(required_memory * kMemoryTolerance);
if ((total_required_memory < total_available_gpu_adapter_memory) &&
(total_required_memory < total_available_cpu_memory))
{
available = true;
}
}
}
else
{
GFXRECON_LOG_ERROR("Memory usage setting out of range");
}
#endif
return available;
}
Expand Down
Loading

0 comments on commit b3848bb

Please sign in to comment.