Merge pull request #12217 from malleoz/savestate_lz4

Savestates: Use LZ4 algorithm for faster decompression
This commit is contained in:
Admiral H. Curtiss
2023-10-10 10:34:38 +02:00
committed by GitHub
11 changed files with 449 additions and 147 deletions
+3
View File
@@ -63,3 +63,6 @@
[submodule "Externals/fmt/fmt"]
path = Externals/fmt/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "Externals/lz4/lz4"]
path = Externals/lz4/lz4
url = https://github.com/lz4/lz4
+2
View File
@@ -682,6 +682,8 @@ dolphin_find_optional_system_library_pkgconfig(MINIZIP minizip>=3.0.0 minizip::m
dolphin_find_optional_system_library(LZO Externals/LZO)
dolphin_find_optional_system_library_pkgconfig(lz4 liblz4>=1.8 LZ4::LZ4 Externals/lz4)
dolphin_find_optional_system_library_pkgconfig(SPNG spng spng::spng Externals/libspng)
# Using static FreeSurround from Externals
+13
View File
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.13)
# We only want the static library, nothing else.
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(LZ4_BUILD_CLI OFF)
set(LZ4_BUILD_LEGACY_LZ4C OFF)
set(LZ4_BUNDLED_MODE ON)
add_subdirectory(lz4/build/cmake)
dolphin_disable_warnings_msvc(lz4_static)
add_library(LZ4::LZ4 ALIAS lz4_static)
+34
View File
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Import Project="..\..\Source\VSProps\Base.Macros.props" />
<Import Project="$(VSPropsDir)Base.Targets.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VSPropsDir)Configuration.StaticLibrary.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VSPropsDir)Base.props" />
<Import Project="$(VSPropsDir)ClDisableAllWarnings.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<ClInclude Include="lz4\lib\lz4.h" />
<ClInclude Include="lz4\lib\lz4frame.h" />
<ClInclude Include="lz4\lib\lz4frame_static.h" />
<ClInclude Include="lz4\lib\lz4hc.h" />
<ClInclude Include="lz4\lib\xxhash.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="lz4\lib\lz4.c" />
<ClCompile Include="lz4\lib\lz4frame.c" />
<ClCompile Include="lz4\lib\lz4hc.c" />
<ClCompile Include="lz4\lib\xxhash.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(ExternalsDir)lz4\lz4\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="$(ExternalsDir)LZ4\LZ4.vcxproj">
<Project>{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}</Project>
</ProjectReference>
</ItemGroup>
</Project>
Vendored Submodule
+1
Submodule Externals/lz4/lz4 added at 5fc0630a0e
+1
View File
@@ -627,6 +627,7 @@ PRIVATE
FatFs
fmt::fmt
LZO::LZO
LZ4::LZ4
ZLIB::ZLIB
)
+317 -139
View File
File diff suppressed because it is too large Load Diff
+53 -8
View File
@@ -8,6 +8,7 @@
#include <cstddef>
#include <functional>
#include <string>
#include <type_traits>
#include <vector>
#include "Common/CommonTypes.h"
@@ -17,18 +18,62 @@ namespace State
// number of states
static const u32 NUM_STATES = 10;
struct StateHeader
struct StateHeaderLegacy
{
char gameID[6];
u16 reserved1;
u32 size;
u32 reserved2;
char game_id[6];
char reserved1[2];
u32 lzo_size = 0; // Must be zero for new states. Used to support legacy decompression algorithm.
char reserved2[4];
double time;
};
constexpr size_t STATE_HEADER_SIZE = sizeof(StateHeader);
constexpr size_t STATE_HEADER_SIZE = sizeof(StateHeaderLegacy);
static_assert(STATE_HEADER_SIZE == 24);
static_assert(offsetof(StateHeader, size) == 8);
static_assert(offsetof(StateHeader, time) == 16);
static_assert(offsetof(StateHeaderLegacy, lzo_size) == 8);
static_assert(offsetof(StateHeaderLegacy, time) == 16);
static_assert(std::is_trivially_copyable_v<StateHeaderLegacy>);
struct StateHeaderVersion
{
u32 version_cookie;
u32 version_string_length;
};
static_assert(std::is_trivially_copyable_v<StateHeaderVersion>);
struct StateHeader
{
StateHeaderLegacy legacy_header;
StateHeaderVersion version_header;
std::string version_string;
};
enum CompressionType : u16
{
Uncompressed = 0,
LZ4 = 1,
// Add new compression types after this, as the compression type
// is numerically stored in the state file.
};
struct StateExtendedBaseHeader
{
u16 header_version;
u16 compression_type;
u32 payload_offset;
u64 uncompressed_size;
};
constexpr size_t EXTENDED_BASE_HEADER_SIZE = sizeof(StateExtendedBaseHeader);
static_assert(EXTENDED_BASE_HEADER_SIZE == 16);
static_assert(offsetof(StateExtendedBaseHeader, payload_offset) == 4);
static_assert(offsetof(StateExtendedBaseHeader, uncompressed_size) == 8);
static_assert(std::is_trivially_copyable_v<StateExtendedBaseHeader>);
struct StateExtendedHeader
{
StateExtendedBaseHeader base_header;
// Feel free to add new fields here, adjusting COMPRESSED_DATA_OFFSET accordingly, as well as
// CreateExtendedHeader(). Add the appropriate IOFile read/write calls within LoadFileStateData()
// and WriteHeadersToFile()
};
void Init();
+1
View File
@@ -46,6 +46,7 @@
<Import Project="$(ExternalsDir)libspng\exports.props" />
<Import Project="$(ExternalsDir)libusb\exports.props" />
<Import Project="$(ExternalsDir)LZO\exports.props" />
<Import Project="$(ExternalsDir)LZ4\exports.props" />
<Import Project="$(ExternalsDir)mbedtls\exports.props" />
<Import Project="$(ExternalsDir)mGBA\exports.props" />
<Import Project="$(ExternalsDir)miniupnpc\exports.props" />
+11
View File
@@ -25,6 +25,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Languages", "..\Languages\L
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LZO", "..\Externals\LZO\LZO.vcxproj", "{AB993F38-C31D-4897-B139-A620C42BC565}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lz4", "..\Externals\LZ4\LZ4.vcxproj", "{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniupnpc", "..\Externals\miniupnpc\miniupnpc.vcxproj", "{31643FDB-1BB8-4965-9DE7-000FC88D35AE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xxhash", "..\Externals\xxhash\xxhash.vcxproj", "{677EA016-1182-440C-9345-DC88D1E98C0C}"
@@ -173,6 +175,14 @@ Global
{AB993F38-C31D-4897-B139-A620C42BC565}.Release|ARM64.Build.0 = Release|ARM64
{AB993F38-C31D-4897-B139-A620C42BC565}.Release|x64.ActiveCfg = Release|x64
{AB993F38-C31D-4897-B139-A620C42BC565}.Release|x64.Build.0 = Release|x64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Debug|ARM64.ActiveCfg = Debug|x64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Debug|ARM64.Build.0 = Debug|x64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Debug|x64.ActiveCfg = Debug|x64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Debug|x64.Build.0 = Debug|x64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Release|ARM64.ActiveCfg = Release|ARM64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Release|ARM64.Build.0 = Release|ARM64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Release|x64.ActiveCfg = Release|x64
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476}.Release|x64.Build.0 = Release|x64
{31643FDB-1BB8-4965-9DE7-000FC88D35AE}.Debug|ARM64.ActiveCfg = Debug|ARM64
{31643FDB-1BB8-4965-9DE7-000FC88D35AE}.Debug|ARM64.Build.0 = Debug|ARM64
{31643FDB-1BB8-4965-9DE7-000FC88D35AE}.Debug|x64.ActiveCfg = Debug|x64
@@ -436,6 +446,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{8ADA04D7-6DB1-4DA4-AB55-64FB12A0997B} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{AB993F38-C31D-4897-B139-A620C42BC565} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{9092C5CC-3E71-41B3-BF68-4A7BDD8A5476} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{31643FDB-1BB8-4965-9DE7-000FC88D35AE} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{677EA016-1182-440C-9345-DC88D1E98C0C} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{F6EA7144-8D64-4EBB-A13E-76DFBD911EAE} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}