Skip to content

Commit

Permalink
Abstracting out vulkan resource reader class
Browse files Browse the repository at this point in the history
  • Loading branch information
panos-lunarg committed Nov 10, 2023
1 parent 8d06c92 commit 5d1cdaf
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 358 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_SOURCE_DIR}/external/cmake-modules")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Version info
set(GFXRECONSTRUCT_PROJECT_VERSION_MAJOR 1)
Expand Down Expand Up @@ -175,7 +176,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 +188,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
2 changes: 2 additions & 0 deletions android/framework/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ target_sources(gfxrecon_graphics
${GFXRECON_SOURCE_DIR}/framework/graphics/fps_info.cpp
${GFXRECON_SOURCE_DIR}/framework/graphics/vulkan_device_util.h
${GFXRECON_SOURCE_DIR}/framework/graphics/vulkan_device_util.cpp
${GFXRECON_SOURCE_DIR}/framework/graphics/vulkan_resources_util.h
${GFXRECON_SOURCE_DIR}/framework/graphics/vulkan_resources_util.cpp
${GFXRECON_SOURCE_DIR}/framework/graphics/vulkan_util.h
${GFXRECON_SOURCE_DIR}/framework/graphics/vulkan_util.cpp
)
Expand Down
6 changes: 6 additions & 0 deletions framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId
DeviceInfo* device_info = object_info_table_.GetDeviceInfo(device_id);
const ImageInfo* image_info = object_info_table_.GetImageInfo(image_id);

GFXRECON_WRITE_CONSOLE("%s()", __func__)

if ((device_info != nullptr) && (image_info != nullptr))
{
VkResult result = VK_SUCCESS;
Expand All @@ -878,6 +880,8 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT)) ==
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT))
{
GFXRECON_WRITE_CONSOLE(" does NOT need level_sizes")

result = initializer->LoadData(data_size, data, image_info->allocator_data);

if (result != VK_SUCCESS)
Expand All @@ -903,6 +907,8 @@ void VulkanReplayConsumerBase::ProcessInitImageCommand(format::HandleId
copy_region.imageSubresource.baseArrayLayer = 0;
copy_region.imageSubresource.layerCount = image_info->layer_count;

GFXRECON_WRITE_CONSOLE(" needs level_sizes")

assert(image_info->level_count == level_sizes.size());

for (uint32_t i = 0; i < image_info->level_count; ++i)
Expand Down
374 changes: 42 additions & 332 deletions framework/encode/vulkan_state_writer.cpp

Large diffs are not rendered by default.

34 changes: 12 additions & 22 deletions framework/encode/vulkan_state_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "format/format.h"
#include "format/platform_types.h"
#include "generated/generated_vulkan_dispatch_table.h"
#include "graphics/vulkan_resources_util.h"
#include "util/compressor.h"
#include "util/defines.h"
#include "util/file_output_stream.h"
Expand Down Expand Up @@ -71,6 +72,7 @@ class VulkanStateWriter
VkImageAspectFlagBits aspect{};
VkDeviceSize resource_size{ 0 }; // Combined size of all sub-resources.
std::vector<uint64_t> level_sizes; // Combined size of all layers in a mip level.
std::vector<uint64_t> level_offsets; // Offset of each mip level from start of image
};

struct ResourceSnapshotInfo
Expand Down Expand Up @@ -140,7 +142,6 @@ class VulkanStateWriter

void ProcessBufferMemory(const DeviceWrapper* device_wrapper,
const std::vector<BufferSnapshotInfo>& buffer_snapshot_info,
uint32_t queue_family_index,
VkQueue queue,
VkCommandBuffer command_buffer,
VkBuffer staging_buffer,
Expand All @@ -149,7 +150,6 @@ class VulkanStateWriter

void ProcessImageMemory(const DeviceWrapper* device_wrapper,
const std::vector<ImageSnapshotInfo>& image_snapshot_info,
uint32_t queue_family_index,
VkQueue queue,
VkCommandBuffer command_buffer,
VkBuffer staging_buffer,
Expand Down Expand Up @@ -306,16 +306,11 @@ class VulkanStateWriter
});
}

VkMemoryPropertyFlags GetMemoryProperties(const DeviceWrapper* device_wrapper,
const DeviceMemoryWrapper* memory_wrapper,
const VulkanStateTable& state_table);

bool FindMemoryTypeIndex(const DeviceWrapper* device_wrapper,
uint32_t memory_type_bits,
VkMemoryPropertyFlags desired_flags,
uint32_t* found_index,
VkMemoryPropertyFlags* found_flags,
const VulkanStateTable& state_table) const;
bool FindMemoryTypeIndex(const DeviceWrapper* device_wrapper,
uint32_t memory_type_bits,
VkMemoryPropertyFlags desired_flags,
uint32_t* found_index,
VkMemoryPropertyFlags* found_flags) const;

void InvalidateMappedMemoryRange(const DeviceWrapper* device_wrapper,
VkDeviceMemory memory,
Expand All @@ -332,12 +327,11 @@ class VulkanStateWriter

VkResult SubmitCommandBuffer(VkQueue queue, VkCommandBuffer command_buffer, const DeviceTable* device_table);

VkResult CreateStagingBuffer(const DeviceWrapper* device_wrapper,
VkDeviceSize size,
VkBuffer* buffer,
VkDeviceMemory* memory,
VkMemoryPropertyFlags* memory_property_flags,
const VulkanStateTable& state_table);
VkResult CreateStagingBuffer(const DeviceWrapper* device_wrapper,
VkDeviceSize size,
VkBuffer* buffer,
VkDeviceMemory* memory,
VkMemoryPropertyFlags* memory_property_flags);

VkResult ResolveImage(const DeviceWrapper* device_wrapper,
const ImageWrapper* image_wrapper,
Expand All @@ -349,10 +343,6 @@ class VulkanStateWriter

VkImageAspectFlags GetFormatAspectMask(VkFormat format);

void GetFormatAspects(VkFormat format, std::vector<VkImageAspectFlagBits>* aspects, bool* combined_depth_stencil);

VkFormat GetImageAspectFormat(VkFormat format, VkImageAspectFlagBits aspect);

void GetImageSizes(const ImageWrapper* image_wrapper, ImageSnapshotInfo* info);

bool CheckCommandHandles(const CommandBufferWrapper* wrapper, const VulkanStateTable& state_table);
Expand Down
2 changes: 2 additions & 0 deletions framework/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ target_sources(gfxrecon_graphics
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_CURRENT_LIST_DIR}/dx12_image_renderer.cpp>
${CMAKE_CURRENT_LIST_DIR}/fps_info.h
${CMAKE_CURRENT_LIST_DIR}/fps_info.cpp
${CMAKE_CURRENT_LIST_DIR}/vulkan_resources_util.h
${CMAKE_CURRENT_LIST_DIR}/vulkan_resources_util.cpp
${CMAKE_CURRENT_LIST_DIR}/vulkan_device_util.h
${CMAKE_CURRENT_LIST_DIR}/vulkan_device_util.cpp
${CMAKE_CURRENT_LIST_DIR}/vulkan_util.h
Expand Down
Loading

0 comments on commit 5d1cdaf

Please sign in to comment.