diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4318e5e5b..dfa7bbf06 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -117,7 +117,7 @@ set(RECOMPILER_SRCS target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_link_libraries(core PUBLIC Threads::Threads common util zlib) -target_link_libraries(core PRIVATE stb xxhash imgui rapidjson tinyxml2 Zstd::Zstd) +target_link_libraries(core PRIVATE stb xxhash imgui rapidjson tinyxml2) if(WIN32) target_sources(core PRIVATE diff --git a/src/core/core.props b/src/core/core.props index 9ead9141b..0e59e3b41 100644 --- a/src/core/core.props +++ b/src/core/core.props @@ -20,7 +20,7 @@ - $(RootBuildDir)zstd\zstd.lib;$(RootBuildDir)tinyxml2\tinyxml2.lib;$(RootBuildDir)rcheevos\rcheevos.lib;$(RootBuildDir)imgui\imgui.lib;$(RootBuildDir)stb\stb.lib;$(RootBuildDir)xxhash\xxhash.lib;$(RootBuildDir)zlib\zlib.lib;$(RootBuildDir)util\util.lib;$(RootBuildDir)common\common.lib;%(AdditionalDependencies) + $(RootBuildDir)tinyxml2\tinyxml2.lib;$(RootBuildDir)rcheevos\rcheevos.lib;$(RootBuildDir)imgui\imgui.lib;$(RootBuildDir)stb\stb.lib;$(RootBuildDir)xxhash\xxhash.lib;$(RootBuildDir)zlib\zlib.lib;$(RootBuildDir)util\util.lib;$(RootBuildDir)common\common.lib;%(AdditionalDependencies) $(RootBuildDir)rainterface\rainterface.lib;%(AdditionalDependencies) $(RootBuildDir)vixl\vixl.lib;%(AdditionalDependencies) diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 9352564d8..e7165b3a3 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -162,7 +162,6 @@ $(IntDir)/%(RelativeDir)/ - %(AdditionalIncludeDirectories);$(SolutionDir)dep\zstd\lib diff --git a/src/core/system.cpp b/src/core/system.cpp index 540ac3014..513439bc4 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -43,8 +43,6 @@ #include "util/iso_reader.h" #include "util/state_wrapper.h" #include "xxhash.h" -#include "zstd.h" -#include "zstd_errors.h" #include #include #include @@ -1866,19 +1864,8 @@ bool System::DoLoadState(ByteStream* state, bool force_software_renderer, bool u } else if (header.data_compression_type == SAVE_STATE_HEADER::COMPRESSION_TYPE_ZSTD) { - std::unique_ptr compressed_buffer(std::make_unique(header.data_compressed_size)); - std::unique_ptr uncompressed_buffer(std::make_unique(header.data_uncompressed_size)); - if (!state->Read2(compressed_buffer.get(), header.data_compressed_size)) - return false; - - const size_t result = ZSTD_decompress(uncompressed_buffer.get(), header.data_uncompressed_size, - compressed_buffer.get(), header.data_compressed_size); - if (ZSTD_isError(result) || result != header.data_uncompressed_size) - return false; - - compressed_buffer.reset(); - ReadOnlyMemoryByteStream uncompressed_stream(uncompressed_buffer.get(), header.data_uncompressed_size); - StateWrapper sw(&uncompressed_stream, StateWrapper::Mode::Read, header.version); + std::unique_ptr dstream(ByteStream::CreateZstdDecompressStream(state, header.data_compressed_size)); + StateWrapper sw(dstream.get(), StateWrapper::Mode::Read, header.version); if (!DoState(sw, nullptr, update_display, false)) return false; } @@ -1988,29 +1975,11 @@ bool System::InternalSaveState(ByteStream* state, u32 screenshot_size /* = 256 * } else if (compression_method == SAVE_STATE_HEADER::COMPRESSION_TYPE_ZSTD) { - GrowableMemoryByteStream staging(nullptr, MAX_SAVE_STATE_SIZE); - StateWrapper sw(&staging, StateWrapper::Mode::Write, SAVE_STATE_VERSION); - result = DoState(sw, nullptr, false, false); - if (result) - { - header.data_uncompressed_size = static_cast(staging.GetSize()); - - const size_t max_compressed_size = ZSTD_compressBound(header.data_uncompressed_size * 2); - std::unique_ptr compress_buffer(std::make_unique(max_compressed_size)); - size_t compress_size = ZSTD_compress(compress_buffer.get(), max_compressed_size, staging.GetMemoryPointer(), - header.data_uncompressed_size, 0); - if (ZSTD_isError(compress_size)) - { - Log_ErrorPrintf("ZSTD_compress() failed: %s", ZSTD_getErrorString(ZSTD_getErrorCode(compress_size))); - } - else - { - header.data_compressed_size = static_cast(compress_size); - result = state->Write2(compress_buffer.get(), header.data_compressed_size); - Log_DevPrintf("Compressed %u bytes of state to %u bytes with zstd", header.data_uncompressed_size, - header.data_compressed_size); - } - } + std::unique_ptr cstream(ByteStream::CreateZstdCompressStream(state, 0)); + StateWrapper sw(cstream.get(), StateWrapper::Mode::Write, SAVE_STATE_VERSION); + result = DoState(sw, nullptr, false, false) && cstream->Commit(); + header.data_uncompressed_size = static_cast(cstream->GetPosition()); + header.data_compressed_size = static_cast(state->GetPosition() - header.offset_to_data); } g_gpu->ResetGraphicsAPIState();