diff options
Diffstat (limited to '')
-rw-r--r-- | src/common/lz4_compression.cpp | 21 | ||||
-rw-r--r-- | src/common/lz4_compression.h | 10 | ||||
-rw-r--r-- | src/common/zstd_compression.cpp | 13 | ||||
-rw-r--r-- | src/common/zstd_compression.h | 7 | ||||
-rw-r--r-- | src/core/frontend/emu_window.h | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/memory/system_control.cpp | 21 | ||||
-rw-r--r-- | src/core/hle/kernel/memory/system_control.h | 5 | ||||
-rw-r--r-- | src/core/hle/kernel/scheduler.h | 2 | ||||
-rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.cpp | 3 | ||||
-rw-r--r-- | src/core/hle/service/time/time_zone_content_manager.cpp | 4 | ||||
-rw-r--r-- | src/video_core/engines/maxwell_dma.cpp | 21 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 3 | ||||
-rw-r--r-- | src/video_core/textures/decoders.cpp | 42 | ||||
-rw-r--r-- | src/video_core/textures/decoders.h | 5 |
14 files changed, 74 insertions, 87 deletions
diff --git a/src/common/lz4_compression.cpp b/src/common/lz4_compression.cpp index ade6759bb..8e2e4094b 100644 --- a/src/common/lz4_compression.cpp +++ b/src/common/lz4_compression.cpp @@ -10,14 +10,14 @@ namespace Common::Compression { -std::vector<u8> CompressDataLZ4(const u8* source, std::size_t source_size) { - ASSERT_MSG(source_size <= LZ4_MAX_INPUT_SIZE, "Source size exceeds LZ4 maximum input size"); +std::vector<u8> CompressDataLZ4(std::span<const u8> source) { + ASSERT_MSG(source.size() <= LZ4_MAX_INPUT_SIZE, "Source size exceeds LZ4 maximum input size"); - const auto source_size_int = static_cast<int>(source_size); + const auto source_size_int = static_cast<int>(source.size()); const int max_compressed_size = LZ4_compressBound(source_size_int); std::vector<u8> compressed(max_compressed_size); - const int compressed_size = LZ4_compress_default(reinterpret_cast<const char*>(source), + const int compressed_size = LZ4_compress_default(reinterpret_cast<const char*>(source.data()), reinterpret_cast<char*>(compressed.data()), source_size_int, max_compressed_size); @@ -31,18 +31,17 @@ std::vector<u8> CompressDataLZ4(const u8* source, std::size_t source_size) { return compressed; } -std::vector<u8> CompressDataLZ4HC(const u8* source, std::size_t source_size, - s32 compression_level) { - ASSERT_MSG(source_size <= LZ4_MAX_INPUT_SIZE, "Source size exceeds LZ4 maximum input size"); +std::vector<u8> CompressDataLZ4HC(std::span<const u8> source, s32 compression_level) { + ASSERT_MSG(source.size() <= LZ4_MAX_INPUT_SIZE, "Source size exceeds LZ4 maximum input size"); compression_level = std::clamp(compression_level, LZ4HC_CLEVEL_MIN, LZ4HC_CLEVEL_MAX); - const auto source_size_int = static_cast<int>(source_size); + const auto source_size_int = static_cast<int>(source.size()); const int max_compressed_size = LZ4_compressBound(source_size_int); std::vector<u8> compressed(max_compressed_size); const int compressed_size = LZ4_compress_HC( - reinterpret_cast<const char*>(source), reinterpret_cast<char*>(compressed.data()), + reinterpret_cast<const char*>(source.data()), reinterpret_cast<char*>(compressed.data()), source_size_int, max_compressed_size, compression_level); if (compressed_size <= 0) { @@ -55,8 +54,8 @@ std::vector<u8> CompressDataLZ4HC(const u8* source, std::size_t source_size, return compressed; } -std::vector<u8> CompressDataLZ4HCMax(const u8* source, std::size_t source_size) { - return CompressDataLZ4HC(source, source_size, LZ4HC_CLEVEL_MAX); +std::vector<u8> CompressDataLZ4HCMax(std::span<const u8> source) { + return CompressDataLZ4HC(source, LZ4HC_CLEVEL_MAX); } std::vector<u8> DecompressDataLZ4(const std::vector<u8>& compressed, diff --git a/src/common/lz4_compression.h b/src/common/lz4_compression.h index 4c16f6e03..173f9b9ad 100644 --- a/src/common/lz4_compression.h +++ b/src/common/lz4_compression.h @@ -4,6 +4,7 @@ #pragma once +#include <span> #include <vector> #include "common/common_types.h" @@ -14,11 +15,10 @@ namespace Common::Compression { * Compresses a source memory region with LZ4 and returns the compressed data in a vector. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * * @return the compressed data. */ -std::vector<u8> CompressDataLZ4(const u8* source, std::size_t source_size); +std::vector<u8> CompressDataLZ4(std::span<const u8> source); /** * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression @@ -27,22 +27,20 @@ std::vector<u8> CompressDataLZ4(const u8* source, std::size_t source_size); * also be decompressed with the default LZ4 decompression. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * @param compression_level the used compression level. Should be between 3 and 12. * * @return the compressed data. */ -std::vector<u8> CompressDataLZ4HC(const u8* source, std::size_t source_size, s32 compression_level); +std::vector<u8> CompressDataLZ4HC(std::span<const u8> source, s32 compression_level); /** * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * * @return the compressed data. */ -std::vector<u8> CompressDataLZ4HCMax(const u8* source, std::size_t source_size); +std::vector<u8> CompressDataLZ4HCMax(std::span<const u8> source); /** * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector. diff --git a/src/common/zstd_compression.cpp b/src/common/zstd_compression.cpp index 978526492..770833ee7 100644 --- a/src/common/zstd_compression.cpp +++ b/src/common/zstd_compression.cpp @@ -5,19 +5,18 @@ #include <algorithm> #include <zstd.h> -#include "common/assert.h" #include "common/zstd_compression.h" namespace Common::Compression { -std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32 compression_level) { +std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_level) { compression_level = std::clamp(compression_level, 1, ZSTD_maxCLevel()); - const std::size_t max_compressed_size = ZSTD_compressBound(source_size); + const std::size_t max_compressed_size = ZSTD_compressBound(source.size()); std::vector<u8> compressed(max_compressed_size); - const std::size_t compressed_size = - ZSTD_compress(compressed.data(), compressed.size(), source, source_size, compression_level); + const std::size_t compressed_size = ZSTD_compress( + compressed.data(), compressed.size(), source.data(), source.size(), compression_level); if (ZSTD_isError(compressed_size)) { // Compression failed @@ -29,8 +28,8 @@ std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32 return compressed; } -std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size) { - return CompressDataZSTD(source, source_size, ZSTD_CLEVEL_DEFAULT); +std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source) { + return CompressDataZSTD(source, ZSTD_CLEVEL_DEFAULT); } std::vector<u8> DecompressDataZSTD(const std::vector<u8>& compressed) { diff --git a/src/common/zstd_compression.h b/src/common/zstd_compression.h index e9de941c8..b5edf19e7 100644 --- a/src/common/zstd_compression.h +++ b/src/common/zstd_compression.h @@ -4,6 +4,7 @@ #pragma once +#include <span> #include <vector> #include "common/common_types.h" @@ -14,23 +15,21 @@ namespace Common::Compression { * Compresses a source memory region with Zstandard and returns the compressed data in a vector. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * @param compression_level the used compression level. Should be between 1 and 22. * * @return the compressed data. */ -std::vector<u8> CompressDataZSTD(const u8* source, std::size_t source_size, s32 compression_level); +std::vector<u8> CompressDataZSTD(std::span<const u8> source, s32 compression_level); /** * Compresses a source memory region with Zstandard with the default compression level and returns * the compressed data in a vector. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * * @return the compressed data. */ -std::vector<u8> CompressDataZSTDDefault(const u8* source, std::size_t source_size); +std::vector<u8> CompressDataZSTDDefault(std::span<const u8> source); /** * Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector. diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index 13aa14934..3e8780243 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h @@ -39,7 +39,7 @@ public: class Scoped { public: - explicit Scoped(GraphicsContext& context_) : context(context_) { + [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) { context.MakeCurrent(); } ~Scoped() { @@ -52,7 +52,7 @@ public: /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value /// ends - Scoped Acquire() { + [[nodiscard]] Scoped Acquire() { return Scoped{*this}; } }; diff --git a/src/core/hle/kernel/memory/system_control.cpp b/src/core/hle/kernel/memory/system_control.cpp index 2f98e9c4c..11d204bc2 100644 --- a/src/core/hle/kernel/memory/system_control.cpp +++ b/src/core/hle/kernel/memory/system_control.cpp @@ -7,22 +7,15 @@ #include "core/hle/kernel/memory/system_control.h" namespace Kernel::Memory::SystemControl { - -u64 GenerateRandomU64ForInit() { - static std::random_device device; - static std::mt19937 gen(device()); - static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); - return distribution(gen); -} - +namespace { template <typename F> u64 GenerateUniformRange(u64 min, u64 max, F f) { - /* Handle the case where the difference is too large to represent. */ + // Handle the case where the difference is too large to represent. if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) { return f(); } - /* Iterate until we get a value in range. */ + // Iterate until we get a value in range. const u64 range_size = ((max + 1) - min); const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size; while (true) { @@ -32,6 +25,14 @@ u64 GenerateUniformRange(u64 min, u64 max, F f) { } } +u64 GenerateRandomU64ForInit() { + static std::random_device device; + static std::mt19937 gen(device()); + static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); + return distribution(gen); +} +} // Anonymous namespace + u64 GenerateRandomRange(u64 min, u64 max) { return GenerateUniformRange(min, max, GenerateRandomU64ForInit); } diff --git a/src/core/hle/kernel/memory/system_control.h b/src/core/hle/kernel/memory/system_control.h index 3fa93111d..19cab8cbc 100644 --- a/src/core/hle/kernel/memory/system_control.h +++ b/src/core/hle/kernel/memory/system_control.h @@ -8,11 +8,6 @@ namespace Kernel::Memory::SystemControl { -u64 GenerateRandomU64ForInit(); - -template <typename F> -u64 GenerateUniformRange(u64 min, u64 max, F f); - u64 GenerateRandomRange(u64 min, u64 max); } // namespace Kernel::Memory::SystemControl diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h index b3b4b5169..36e3c26fb 100644 --- a/src/core/hle/kernel/scheduler.h +++ b/src/core/hle/kernel/scheduler.h @@ -289,7 +289,7 @@ private: class SchedulerLock { public: - explicit SchedulerLock(KernelCore& kernel); + [[nodiscard]] explicit SchedulerLock(KernelCore& kernel); ~SchedulerLock(); protected: diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 289da2619..bdeb0737a 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -122,8 +122,7 @@ void SoftwareKeyboard::ExecuteInteractive() { switch (request) { case Request::Calc: { - broker.PushNormalDataFromApplet( - std::make_shared<IStorage>(std::move(std::vector<u8>{1}))); + broker.PushNormalDataFromApplet(std::make_shared<IStorage>(std::vector<u8>{1})); broker.SignalStateChanged(); break; } diff --git a/src/core/hle/service/time/time_zone_content_manager.cpp b/src/core/hle/service/time/time_zone_content_manager.cpp index c070d6e97..320672add 100644 --- a/src/core/hle/service/time/time_zone_content_manager.cpp +++ b/src/core/hle/service/time/time_zone_content_manager.cpp @@ -73,10 +73,8 @@ TimeZoneContentManager::TimeZoneContentManager(TimeManager& time_manager, Core:: std::string location_name; const auto timezone_setting = Settings::GetTimeZoneString(); - if (timezone_setting == "auto") { + if (timezone_setting == "auto" || timezone_setting == "default") { location_name = Common::TimeZone::GetDefaultTimeZone(); - } else if (timezone_setting == "default") { - location_name = location_name; } else { location_name = timezone_setting; } diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp index a2d3d7823..e88290754 100644 --- a/src/video_core/engines/maxwell_dma.cpp +++ b/src/video_core/engines/maxwell_dma.cpp @@ -94,7 +94,8 @@ void MaxwellDMA::CopyPitchToPitch() { } void MaxwellDMA::CopyBlockLinearToPitch() { - ASSERT(regs.src_params.block_size.depth == 0); + UNIMPLEMENTED_IF(regs.src_params.block_size.depth != 0); + UNIMPLEMENTED_IF(regs.src_params.layer != 0); // Optimized path for micro copies. const size_t dst_size = static_cast<size_t>(regs.pitch_out) * regs.line_count; @@ -123,17 +124,12 @@ void MaxwellDMA::CopyBlockLinearToPitch() { write_buffer.resize(dst_size); } - if (Settings::IsGPULevelExtreme()) { - memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); - memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); - } else { - memory_manager.ReadBlockUnsafe(regs.offset_in, read_buffer.data(), src_size); - memory_manager.ReadBlockUnsafe(regs.offset_out, write_buffer.data(), dst_size); - } + memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); + memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); UnswizzleSubrect(regs.line_length_in, regs.line_count, regs.pitch_out, width, bytes_per_pixel, - read_buffer.data() + src_layer_size * src_params.layer, write_buffer.data(), - block_height, src_params.origin.x, src_params.origin.y); + block_height, src_params.origin.x, src_params.origin.y, write_buffer.data(), + read_buffer.data()); memory_manager.WriteBlock(regs.offset_out, write_buffer.data(), dst_size); } @@ -198,7 +194,6 @@ void MaxwellDMA::FastCopyBlockLinearToPitch() { if (read_buffer.size() < src_size) { read_buffer.resize(src_size); } - if (write_buffer.size() < dst_size) { write_buffer.resize(dst_size); } @@ -212,8 +207,8 @@ void MaxwellDMA::FastCopyBlockLinearToPitch() { } UnswizzleSubrect(regs.line_length_in, regs.line_count, regs.pitch_out, regs.src_params.width, - bytes_per_pixel, read_buffer.data(), write_buffer.data(), - regs.src_params.block_size.height, pos_x, pos_y); + bytes_per_pixel, regs.src_params.block_size.height, pos_x, pos_y, + write_buffer.data(), read_buffer.data()); memory_manager.WriteBlock(regs.offset_out, write_buffer.data(), dst_size); } diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 2dcc2b0eb..c0e73789b 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -422,8 +422,7 @@ void ShaderDiskCacheOpenGL::SavePrecompiledHeaderToVirtualPrecompiledCache() { void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() { precompiled_cache_virtual_file_offset = 0; const std::vector<u8> uncompressed = precompiled_cache_virtual_file.ReadAllBytes(); - const std::vector<u8> compressed = - Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size()); + const std::vector<u8> compressed = Common::Compression::CompressDataZSTDDefault(uncompressed); const auto precompiled_path{GetPrecompiledPath()}; FileUtil::IOFile file(precompiled_path, "wb"); diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 474ae620a..16d46a018 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp @@ -228,24 +228,30 @@ void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 } } -void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width, - u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, - u32 block_height_bit, u32 offset_x, u32 offset_y) { - const u32 block_height = 1U << block_height_bit; - for (u32 line = 0; line < subrect_height; ++line) { - const u32 y2 = line + offset_y; - const u32 gob_address_y = (y2 / (GOB_SIZE_Y * block_height)) * GOB_SIZE * block_height + - ((y2 % (GOB_SIZE_Y * block_height)) / GOB_SIZE_Y) * GOB_SIZE; - const auto& table = LEGACY_SWIZZLE_TABLE[y2 % GOB_SIZE_Y]; - for (u32 x = 0; x < subrect_width; ++x) { - const u32 x2 = (x + offset_x) * bytes_per_pixel; - const u32 gob_address = gob_address_y + (x2 / GOB_SIZE_X) * GOB_SIZE * block_height; - const u32 swizzled_offset = gob_address + table[x2 % GOB_SIZE_X]; - const u32 unswizzled_offset = line * dest_pitch + x * bytes_per_pixel; - u8* dest_line = unswizzled_data + unswizzled_offset; - u8* source_addr = swizzled_data + swizzled_offset; +void UnswizzleSubrect(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 bytes_per_pixel, + u32 block_height, u32 origin_x, u32 origin_y, u8* output, const u8* input) { + const u32 stride = width * bytes_per_pixel; + const u32 gobs_in_x = (stride + GOB_SIZE_X - 1) / GOB_SIZE_X; + const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height); + + const u32 block_height_mask = (1U << block_height) - 1; + const u32 x_shift = static_cast<u32>(GOB_SIZE_SHIFT) + block_height; + + for (u32 line = 0; line < line_count; ++line) { + const u32 src_y = line + origin_y; + const auto& table = LEGACY_SWIZZLE_TABLE[src_y % GOB_SIZE_Y]; + + const u32 block_y = src_y >> GOB_SIZE_Y_SHIFT; + const u32 src_offset_y = (block_y >> block_height) * block_size + + ((block_y & block_height_mask) << GOB_SIZE_SHIFT); + for (u32 column = 0; column < line_length_in; ++column) { + const u32 src_x = (column + origin_x) * bytes_per_pixel; + const u32 src_offset_x = (src_x >> GOB_SIZE_X_SHIFT) << x_shift; + + const u32 swizzled_offset = src_offset_y + src_offset_x + table[src_x % GOB_SIZE_X]; + const u32 unswizzled_offset = line * pitch + column * bytes_per_pixel; - std::memcpy(dest_line, source_addr, bytes_per_pixel); + std::memcpy(output + unswizzled_offset, input + swizzled_offset, bytes_per_pixel); } } } @@ -261,7 +267,7 @@ void SwizzleSliceToVoxel(u32 line_length_in, u32 line_count, u32 pitch, u32 widt const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height + block_depth); const u32 block_height_mask = (1U << block_height) - 1; - const u32 x_shift = Common::CountTrailingZeroes32(GOB_SIZE << (block_height + block_depth)); + const u32 x_shift = static_cast<u32>(GOB_SIZE_SHIFT) + block_height + block_depth; for (u32 line = 0; line < line_count; ++line) { const auto& table = LEGACY_SWIZZLE_TABLE[line % GOB_SIZE_Y]; diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h index d6fe35d37..01e156bc8 100644 --- a/src/video_core/textures/decoders.h +++ b/src/video_core/textures/decoders.h @@ -48,9 +48,8 @@ void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 u32 block_height_bit, u32 offset_x, u32 offset_y); /// Copies a tiled subrectangle into a linear surface. -void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width, - u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height, - u32 offset_x, u32 offset_y); +void UnswizzleSubrect(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 bytes_per_pixel, + u32 block_height, u32 origin_x, u32 origin_y, u8* output, const u8* input); /// @brief Swizzles a 2D array of pixels into a 3D texture /// @param line_length_in Number of pixels per line |