diff options
author | Fernando S <fsahmkow27@gmail.com> | 2023-05-24 03:55:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 03:55:45 +0200 |
commit | 76f63889692a0836dafd626841aa050ef26b407b (patch) | |
tree | 442b586dc2ead257e4411101b05a06298c97e423 /src | |
parent | Merge pull request #10388 from GPUCode/fence-wait (diff) | |
parent | textures: add BC1 and BC3 compressors and recompression setting (diff) | |
download | yuzu-76f63889692a0836dafd626841aa050ef26b407b.tar yuzu-76f63889692a0836dafd626841aa050ef26b407b.tar.gz yuzu-76f63889692a0836dafd626841aa050ef26b407b.tar.bz2 yuzu-76f63889692a0836dafd626841aa050ef26b407b.tar.lz yuzu-76f63889692a0836dafd626841aa050ef26b407b.tar.xz yuzu-76f63889692a0836dafd626841aa050ef26b407b.tar.zst yuzu-76f63889692a0836dafd626841aa050ef26b407b.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/settings.cpp | 2 | ||||
-rw-r--r-- | src/common/settings.h | 9 | ||||
-rw-r--r-- | src/video_core/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/video_core/buffer_cache/buffer_cache.h | 2 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 31 | ||||
-rw-r--r-- | src/video_core/renderer_vulkan/maxwell_to_vk.cpp | 24 | ||||
-rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 8 | ||||
-rw-r--r-- | src/video_core/texture_cache/util.cpp | 77 | ||||
-rw-r--r-- | src/video_core/textures/astc.cpp | 5 | ||||
-rw-r--r-- | src/video_core/textures/bcn.cpp | 87 | ||||
-rw-r--r-- | src/video_core/textures/bcn.h | 17 | ||||
-rw-r--r-- | src/video_core/textures/workers.cpp | 15 | ||||
-rw-r--r-- | src/video_core/textures/workers.h | 12 | ||||
-rw-r--r-- | src/video_core/vulkan_common/vulkan_device.cpp | 6 | ||||
-rw-r--r-- | src/yuzu/configuration/config.cpp | 5 | ||||
-rw-r--r-- | src/yuzu/configuration/config.h | 1 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_graphics_advanced.cpp | 14 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_graphics_advanced.ui | 44 | ||||
-rw-r--r-- | src/yuzu_cmd/config.cpp | 1 | ||||
-rw-r--r-- | src/yuzu_cmd/default_ini.h | 4 |
20 files changed, 344 insertions, 26 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp index ba617aea1..ff53e80bb 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -61,6 +61,7 @@ void LogSettings() { log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue()); log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue()); log_setting("Renderer_AsyncASTC", values.async_astc.GetValue()); + log_setting("Renderer_AstcRecompression", values.astc_recompression.GetValue()); log_setting("Renderer_UseVsync", values.vsync_mode.GetValue()); log_setting("Renderer_UseReactiveFlushing", values.use_reactive_flushing.GetValue()); log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); @@ -224,6 +225,7 @@ void RestoreGlobalState(bool is_powered_on) { values.nvdec_emulation.SetGlobal(true); values.accelerate_astc.SetGlobal(true); values.async_astc.SetGlobal(true); + values.astc_recompression.SetGlobal(true); values.use_reactive_flushing.SetGlobal(true); values.shader_backend.SetGlobal(true); values.use_asynchronous_shaders.SetGlobal(true); diff --git a/src/common/settings.h b/src/common/settings.h index 36ffcd693..7f865b2a7 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -90,6 +90,12 @@ enum class AntiAliasing : u32 { LastAA = Smaa, }; +enum class AstcRecompression : u32 { + Uncompressed = 0, + Bc1 = 1, + Bc3 = 2, +}; + struct ResolutionScalingInfo { u32 up_scale{1}; u32 down_shift{0}; @@ -473,6 +479,9 @@ struct Values { SwitchableSetting<bool> use_vulkan_driver_pipeline_cache{true, "use_vulkan_driver_pipeline_cache"}; SwitchableSetting<bool> enable_compute_pipelines{false, "enable_compute_pipelines"}; + SwitchableSetting<AstcRecompression, true> astc_recompression{ + AstcRecompression::Uncompressed, AstcRecompression::Uncompressed, AstcRecompression::Bc3, + "astc_recompression"}; SwitchableSetting<u8> bg_red{0, "bg_red"}; SwitchableSetting<u8> bg_green{0, "bg_green"}; diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index a0009a36f..308d013d6 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -246,10 +246,14 @@ add_library(video_core STATIC texture_cache/util.h textures/astc.h textures/astc.cpp + textures/bcn.cpp + textures/bcn.h textures/decoders.cpp textures/decoders.h textures/texture.cpp textures/texture.h + textures/workers.cpp + textures/workers.h transform_feedback.cpp transform_feedback.h video_core.cpp @@ -275,7 +279,7 @@ add_library(video_core STATIC create_target_directory_groups(video_core) target_link_libraries(video_core PUBLIC common core) -target_link_libraries(video_core PUBLIC glad shader_recompiler) +target_link_libraries(video_core PUBLIC glad shader_recompiler stb) if (YUZU_USE_BUNDLED_FFMPEG AND NOT WIN32) add_dependencies(video_core ffmpeg-build) diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 98756e4da..f2508fbf0 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -1664,7 +1664,7 @@ typename BufferCache<P>::Binding BufferCache<P>::StorageBufferBinding(GPUVAddr s // cbufs, which do not store the sizes adjacent to the addresses, so use the fully // mapped buffer size for now. const u32 memory_layout_size = static_cast<u32>(gpu_memory->GetMemoryLayoutSize(gpu_addr)); - return memory_layout_size; + return std::min(memory_layout_size, static_cast<u32>(8_MiB)); }(); const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); if (!cpu_addr || size == 0) { diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 31118886f..1e0823836 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -233,6 +233,8 @@ void ApplySwizzle(GLuint handle, PixelFormat format, std::array<SwizzleSource, 4 const VideoCommon::ImageInfo& info) { if (IsPixelFormatASTC(info.format) && info.size.depth == 1 && !runtime.HasNativeASTC()) { return Settings::values.accelerate_astc.GetValue() && + Settings::values.astc_recompression.GetValue() == + Settings::AstcRecompression::Uncompressed && !Settings::values.async_astc.GetValue(); } // Disable other accelerated uploads for now as they don't implement swizzled uploads @@ -437,6 +439,19 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form return GL_R32UI; } +[[nodiscard]] GLenum SelectAstcFormat(PixelFormat format, bool is_srgb) { + switch (Settings::values.astc_recompression.GetValue()) { + case Settings::AstcRecompression::Bc1: + return is_srgb ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + break; + case Settings::AstcRecompression::Bc3: + return is_srgb ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + default: + return is_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8; + } +} + } // Anonymous namespace ImageBufferMap::~ImageBufferMap() { @@ -739,9 +754,16 @@ Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_, if (IsConverted(runtime->device, info.format, info.type)) { flags |= ImageFlagBits::Converted; flags |= ImageFlagBits::CostlyLoad; - gl_internal_format = IsPixelFormatSRGB(info.format) ? GL_SRGB8_ALPHA8 : GL_RGBA8; + + const bool is_srgb = IsPixelFormatSRGB(info.format); + gl_internal_format = is_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8; gl_format = GL_RGBA; gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; + + if (IsPixelFormatASTC(info.format)) { + gl_internal_format = SelectAstcFormat(info.format, is_srgb); + gl_format = GL_NONE; + } } else { const auto& tuple = MaxwellToGL::GetFormatTuple(info.format); gl_internal_format = tuple.internal_format; @@ -1130,7 +1152,12 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewI views{runtime.null_image_views} { const Device& device = runtime.device; if (True(image.flags & ImageFlagBits::Converted)) { - internal_format = IsPixelFormatSRGB(info.format) ? GL_SRGB8_ALPHA8 : GL_RGBA8; + const bool is_srgb = IsPixelFormatSRGB(info.format); + internal_format = is_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8; + + if (IsPixelFormatASTC(info.format)) { + internal_format = SelectAstcFormat(info.format, is_srgb); + } } else { internal_format = MaxwellToGL::GetFormatTuple(format).internal_format; } diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp index 8853cf0f7..b75d7220d 100644 --- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp +++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp @@ -6,6 +6,7 @@ #include "common/assert.h" #include "common/common_types.h" #include "common/logging/log.h" +#include "common/settings.h" #include "video_core/engines/maxwell_3d.h" #include "video_core/renderer_vulkan/maxwell_to_vk.h" #include "video_core/surface.h" @@ -237,14 +238,25 @@ FormatInfo SurfaceFormat(const Device& device, FormatType format_type, bool with PixelFormat pixel_format) { ASSERT(static_cast<size_t>(pixel_format) < std::size(tex_format_tuples)); FormatTuple tuple = tex_format_tuples[static_cast<size_t>(pixel_format)]; - // Use A8B8G8R8_UNORM on hardware that doesn't support ASTC natively + // Transcode on hardware that doesn't support ASTC natively if (!device.IsOptimalAstcSupported() && VideoCore::Surface::IsPixelFormatASTC(pixel_format)) { const bool is_srgb = with_srgb && VideoCore::Surface::IsPixelFormatSRGB(pixel_format); - if (is_srgb) { - tuple.format = VK_FORMAT_A8B8G8R8_SRGB_PACK32; - } else { - tuple.format = VK_FORMAT_A8B8G8R8_UNORM_PACK32; - tuple.usage |= Storage; + + switch (Settings::values.astc_recompression.GetValue()) { + case Settings::AstcRecompression::Uncompressed: + if (is_srgb) { + tuple.format = VK_FORMAT_A8B8G8R8_SRGB_PACK32; + } else { + tuple.format = VK_FORMAT_A8B8G8R8_UNORM_PACK32; + tuple.usage |= Storage; + } + break; + case Settings::AstcRecompression::Bc1: + tuple.format = is_srgb ? VK_FORMAT_BC1_RGBA_SRGB_BLOCK : VK_FORMAT_BC1_RGBA_UNORM_BLOCK; + break; + case Settings::AstcRecompression::Bc3: + tuple.format = is_srgb ? VK_FORMAT_BC3_SRGB_BLOCK : VK_FORMAT_BC3_UNORM_BLOCK; + break; } } const bool attachable = (tuple.usage & Attachable) != 0; diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index da5af25eb..8711e2a87 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -1272,7 +1272,9 @@ Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { if (Settings::values.async_astc.GetValue()) { flags |= VideoCommon::ImageFlagBits::AsynchronousDecode; - } else if (Settings::values.accelerate_astc.GetValue() && info.size.depth == 1) { + } else if (Settings::values.astc_recompression.GetValue() == + Settings::AstcRecompression::Uncompressed && + Settings::values.accelerate_astc.GetValue() && info.size.depth == 1) { flags |= VideoCommon::ImageFlagBits::AcceleratedUpload; } flags |= VideoCommon::ImageFlagBits::Converted; @@ -1287,7 +1289,9 @@ Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu .usage = VK_IMAGE_USAGE_STORAGE_BIT, }; current_image = *original_image; - if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { + if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported() && + Settings::values.astc_recompression.GetValue() == + Settings::AstcRecompression::Uncompressed) { const auto& device = runtime->device.GetLogical(); storage_image_views.reserve(info.resources.levels); for (s32 level = 0; level < info.resources.levels; ++level) { diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index f1071aa23..1463f157b 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp @@ -18,6 +18,8 @@ #include "common/bit_util.h" #include "common/common_types.h" #include "common/div_ceil.h" +#include "common/scratch_buffer.h" +#include "common/settings.h" #include "video_core/compatible_formats.h" #include "video_core/engines/maxwell_3d.h" #include "video_core/memory_manager.h" @@ -28,6 +30,7 @@ #include "video_core/texture_cache/samples_helper.h" #include "video_core/texture_cache/util.h" #include "video_core/textures/astc.h" +#include "video_core/textures/bcn.h" #include "video_core/textures/decoders.h" namespace VideoCommon { @@ -585,6 +588,21 @@ u32 CalculateConvertedSizeBytes(const ImageInfo& info) noexcept { return info.size.width * BytesPerBlock(info.format); } static constexpr Extent2D TILE_SIZE{1, 1}; + if (IsPixelFormatASTC(info.format) && Settings::values.astc_recompression.GetValue() != + Settings::AstcRecompression::Uncompressed) { + const u32 bpp_div = + Settings::values.astc_recompression.GetValue() == Settings::AstcRecompression::Bc1 ? 2 + : 1; + // NumBlocksPerLayer doesn't account for this correctly, so we have to do it manually. + u32 output_size = 0; + for (s32 i = 0; i < info.resources.levels; i++) { + const auto mip_size = AdjustMipSize(info.size, i); + const u32 plane_dim = + Common::AlignUp(mip_size.width, 4U) * Common::AlignUp(mip_size.height, 4U); + output_size += (plane_dim * info.size.depth * info.resources.layers) / bpp_div; + } + return output_size; + } return NumBlocksPerLayer(info, TILE_SIZE) * info.resources.layers * CONVERTED_BYTES_PER_BLOCK; } @@ -885,6 +903,7 @@ BufferCopy UploadBufferCopy(Tegra::MemoryManager& gpu_memory, GPUVAddr gpu_addr, void ConvertImage(std::span<const u8> input, const ImageInfo& info, std::span<u8> output, std::span<BufferImageCopy> copies) { u32 output_offset = 0; + Common::ScratchBuffer<u8> decode_scratch; const Extent2D tile_size = DefaultBlockSize(info.format); for (BufferImageCopy& copy : copies) { @@ -895,22 +914,58 @@ void ConvertImage(std::span<const u8> input, const ImageInfo& info, std::span<u8 ASSERT(copy.image_extent == mip_size); ASSERT(copy.buffer_row_length == Common::AlignUp(mip_size.width, tile_size.width)); ASSERT(copy.buffer_image_height == Common::AlignUp(mip_size.height, tile_size.height)); - if (IsPixelFormatASTC(info.format)) { + + const auto input_offset = input.subspan(copy.buffer_offset); + copy.buffer_offset = output_offset; + copy.buffer_row_length = mip_size.width; + copy.buffer_image_height = mip_size.height; + + const auto recompression_setting = Settings::values.astc_recompression.GetValue(); + const bool astc = IsPixelFormatASTC(info.format); + + if (astc && recompression_setting == Settings::AstcRecompression::Uncompressed) { Tegra::Texture::ASTC::Decompress( - input.subspan(copy.buffer_offset), copy.image_extent.width, - copy.image_extent.height, + input_offset, copy.image_extent.width, copy.image_extent.height, copy.image_subresource.num_layers * copy.image_extent.depth, tile_size.width, tile_size.height, output.subspan(output_offset)); + + output_offset += copy.image_extent.width * copy.image_extent.height * + copy.image_subresource.num_layers * CONVERTED_BYTES_PER_BLOCK; + } else if (astc) { + // BC1 uses 0.5 bytes per texel + // BC3 uses 1 byte per texel + const auto compress = recompression_setting == Settings::AstcRecompression::Bc1 + ? Tegra::Texture::BCN::CompressBC1 + : Tegra::Texture::BCN::CompressBC3; + const auto bpp_div = recompression_setting == Settings::AstcRecompression::Bc1 ? 2 : 1; + + const u32 plane_dim = copy.image_extent.width * copy.image_extent.height; + const u32 level_size = plane_dim * copy.image_extent.depth * + copy.image_subresource.num_layers * CONVERTED_BYTES_PER_BLOCK; + decode_scratch.resize_destructive(level_size); + + Tegra::Texture::ASTC::Decompress( + input_offset, copy.image_extent.width, copy.image_extent.height, + copy.image_subresource.num_layers * copy.image_extent.depth, tile_size.width, + tile_size.height, decode_scratch); + + compress(decode_scratch, copy.image_extent.width, copy.image_extent.height, + copy.image_subresource.num_layers * copy.image_extent.depth, + output.subspan(output_offset)); + + const u32 aligned_plane_dim = Common::AlignUp(copy.image_extent.width, 4) * + Common::AlignUp(copy.image_extent.height, 4); + + copy.buffer_size = + (aligned_plane_dim * copy.image_extent.depth * copy.image_subresource.num_layers) / + bpp_div; + output_offset += static_cast<u32>(copy.buffer_size); } else { - DecompressBC4(input.subspan(copy.buffer_offset), copy.image_extent, - output.subspan(output_offset)); - } - copy.buffer_offset = output_offset; - copy.buffer_row_length = mip_size.width; - copy.buffer_image_height = mip_size.height; + DecompressBC4(input_offset, copy.image_extent, output.subspan(output_offset)); - output_offset += copy.image_extent.width * copy.image_extent.height * - copy.image_subresource.num_layers * CONVERTED_BYTES_PER_BLOCK; + output_offset += copy.image_extent.width * copy.image_extent.height * + copy.image_subresource.num_layers * CONVERTED_BYTES_PER_BLOCK; + } } } diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp index a68bc0d77..fef0be31d 100644 --- a/src/video_core/textures/astc.cpp +++ b/src/video_core/textures/astc.cpp @@ -16,8 +16,8 @@ #include "common/alignment.h" #include "common/common_types.h" #include "common/polyfill_ranges.h" -#include "common/thread_worker.h" #include "video_core/textures/astc.h" +#include "video_core/textures/workers.h" class InputBitStream { public: @@ -1656,8 +1656,7 @@ void Decompress(std::span<const uint8_t> data, uint32_t width, uint32_t height, const u32 rows = Common::DivideUp(height, block_height); const u32 cols = Common::DivideUp(width, block_width); - static Common::ThreadWorker workers{std::max(std::thread::hardware_concurrency(), 2U) / 2, - "ASTCDecompress"}; + Common::ThreadWorker& workers{GetThreadWorkers()}; for (u32 z = 0; z < depth; ++z) { const u32 depth_offset = z * height * width * 4; diff --git a/src/video_core/textures/bcn.cpp b/src/video_core/textures/bcn.cpp new file mode 100644 index 000000000..671212a49 --- /dev/null +++ b/src/video_core/textures/bcn.cpp @@ -0,0 +1,87 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <stb_dxt.h> +#include <string.h> + +#include "common/alignment.h" +#include "video_core/textures/bcn.h" +#include "video_core/textures/workers.h" + +namespace Tegra::Texture::BCN { + +using BCNCompressor = void(u8* block_output, const u8* block_input, bool any_alpha); + +template <u32 BytesPerBlock, bool ThresholdAlpha = false> +void CompressBCN(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth, + std::span<uint8_t> output, BCNCompressor f) { + constexpr u8 alpha_threshold = 128; + constexpr u32 bytes_per_px = 4; + const u32 plane_dim = width * height; + + Common::ThreadWorker& workers{GetThreadWorkers()}; + + for (u32 z = 0; z < depth; z++) { + for (u32 y = 0; y < height; y += 4) { + auto compress_row = [z, y, width, height, plane_dim, f, data, output]() { + for (u32 x = 0; x < width; x += 4) { + // Gather 4x4 block of RGBA texels + u8 input_colors[4][4][4]; + bool any_alpha = false; + + for (u32 j = 0; j < 4; j++) { + for (u32 i = 0; i < 4; i++) { + const size_t coord = + (z * plane_dim + (y + j) * width + (x + i)) * bytes_per_px; + + if ((x + i < width) && (y + j < height)) { + if constexpr (ThresholdAlpha) { + if (data[coord + 3] >= alpha_threshold) { + input_colors[j][i][0] = data[coord + 0]; + input_colors[j][i][1] = data[coord + 1]; + input_colors[j][i][2] = data[coord + 2]; + input_colors[j][i][3] = 255; + } else { + any_alpha = true; + memset(input_colors[j][i], 0, bytes_per_px); + } + } else { + memcpy(input_colors[j][i], &data[coord], bytes_per_px); + } + } else { + memset(input_colors[j][i], 0, bytes_per_px); + } + } + } + + const u32 bytes_per_row = BytesPerBlock * Common::DivideUp(width, 4U); + const u32 bytes_per_plane = bytes_per_row * Common::DivideUp(height, 4U); + f(output.data() + z * bytes_per_plane + (y / 4) * bytes_per_row + + (x / 4) * BytesPerBlock, + reinterpret_cast<u8*>(input_colors), any_alpha); + } + }; + workers.QueueWork(std::move(compress_row)); + } + workers.WaitForRequests(); + } +} + +void CompressBC1(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth, + std::span<uint8_t> output) { + CompressBCN<8, true>(data, width, height, depth, output, + [](u8* block_output, const u8* block_input, bool any_alpha) { + stb_compress_bc1_block(block_output, block_input, any_alpha, + STB_DXT_NORMAL); + }); +} + +void CompressBC3(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth, + std::span<uint8_t> output) { + CompressBCN<16, false>(data, width, height, depth, output, + [](u8* block_output, const u8* block_input, bool any_alpha) { + stb_compress_bc3_block(block_output, block_input, STB_DXT_NORMAL); + }); +} + +} // namespace Tegra::Texture::BCN diff --git a/src/video_core/textures/bcn.h b/src/video_core/textures/bcn.h new file mode 100644 index 000000000..6464af885 --- /dev/null +++ b/src/video_core/textures/bcn.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <span> +#include <stdint.h> + +namespace Tegra::Texture::BCN { + +void CompressBC1(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth, + std::span<uint8_t> output); + +void CompressBC3(std::span<const uint8_t> data, uint32_t width, uint32_t height, uint32_t depth, + std::span<uint8_t> output); + +} // namespace Tegra::Texture::BCN diff --git a/src/video_core/textures/workers.cpp b/src/video_core/textures/workers.cpp new file mode 100644 index 000000000..a71c305f4 --- /dev/null +++ b/src/video_core/textures/workers.cpp @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "video_core/textures/workers.h" + +namespace Tegra::Texture { + +Common::ThreadWorker& GetThreadWorkers() { + static Common::ThreadWorker workers{std::max(std::thread::hardware_concurrency(), 2U) / 2, + "ImageTranscode"}; + + return workers; +} + +} // namespace Tegra::Texture diff --git a/src/video_core/textures/workers.h b/src/video_core/textures/workers.h new file mode 100644 index 000000000..008dd05b3 --- /dev/null +++ b/src/video_core/textures/workers.h @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/thread_worker.h" + +namespace Tegra::Texture { + +Common::ThreadWorker& GetThreadWorkers(); + +} diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index c0b2b3e17..3a7c2dedf 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp @@ -1001,6 +1001,11 @@ u64 Device::GetDeviceMemoryUsage() const { } void Device::CollectPhysicalMemoryInfo() { + // Account for resolution scaling in memory limits + const size_t normal_memory = 6_GiB; + const size_t scaler_memory = 1_GiB * Settings::values.resolution_info.ScaleUp(1); + + // Calculate limits using memory budget VkPhysicalDeviceMemoryBudgetPropertiesEXT budget{}; budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT; const auto mem_info = @@ -1030,6 +1035,7 @@ void Device::CollectPhysicalMemoryInfo() { if (!is_integrated) { const u64 reserve_memory = std::min<u64>(device_access_memory / 8, 1_GiB); device_access_memory -= reserve_memory; + device_access_memory = std::min<u64>(device_access_memory, normal_memory + scaler_memory); return; } const s64 available_memory = static_cast<s64>(device_access_memory - device_initial_usage); diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 70737c54e..662651196 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -711,6 +711,7 @@ void Config::ReadRendererValues() { ReadGlobalSetting(Settings::values.nvdec_emulation); ReadGlobalSetting(Settings::values.accelerate_astc); ReadGlobalSetting(Settings::values.async_astc); + ReadGlobalSetting(Settings::values.astc_recompression); ReadGlobalSetting(Settings::values.use_reactive_flushing); ReadGlobalSetting(Settings::values.shader_backend); ReadGlobalSetting(Settings::values.use_asynchronous_shaders); @@ -1359,6 +1360,10 @@ void Config::SaveRendererValues() { Settings::values.nvdec_emulation.UsingGlobal()); WriteGlobalSetting(Settings::values.accelerate_astc); WriteGlobalSetting(Settings::values.async_astc); + WriteSetting(QString::fromStdString(Settings::values.astc_recompression.GetLabel()), + static_cast<u32>(Settings::values.astc_recompression.GetValue(global)), + static_cast<u32>(Settings::values.astc_recompression.GetDefault()), + Settings::values.astc_recompression.UsingGlobal()); WriteGlobalSetting(Settings::values.use_reactive_flushing); WriteSetting(QString::fromStdString(Settings::values.shader_backend.GetLabel()), static_cast<u32>(Settings::values.shader_backend.GetValue(global)), diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 7d26e9ab6..9cb9db6cf 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -208,3 +208,4 @@ Q_DECLARE_METATYPE(Settings::ScalingFilter); Q_DECLARE_METATYPE(Settings::AntiAliasing); Q_DECLARE_METATYPE(Settings::RendererBackend); Q_DECLARE_METATYPE(Settings::ShaderBackend); +Q_DECLARE_METATYPE(Settings::AstcRecompression); diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index 1f3e489d0..896863f87 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -27,6 +27,7 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { ui->async_present->setEnabled(runtime_lock); ui->renderer_force_max_clock->setEnabled(runtime_lock); ui->async_astc->setEnabled(runtime_lock); + ui->astc_recompression_combobox->setEnabled(runtime_lock); ui->use_asynchronous_shaders->setEnabled(runtime_lock); ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); ui->enable_compute_pipelines_checkbox->setEnabled(runtime_lock); @@ -47,14 +48,20 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { static_cast<int>(Settings::values.gpu_accuracy.GetValue())); ui->anisotropic_filtering_combobox->setCurrentIndex( Settings::values.max_anisotropy.GetValue()); + ui->astc_recompression_combobox->setCurrentIndex( + static_cast<int>(Settings::values.astc_recompression.GetValue())); } else { ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy); ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox, &Settings::values.max_anisotropy); + ConfigurationShared::SetPerGameSetting(ui->astc_recompression_combobox, + &Settings::values.astc_recompression); ConfigurationShared::SetHighlight(ui->label_gpu_accuracy, !Settings::values.gpu_accuracy.UsingGlobal()); ConfigurationShared::SetHighlight(ui->af_label, !Settings::values.max_anisotropy.UsingGlobal()); + ConfigurationShared::SetHighlight(ui->label_astc_recompression, + !Settings::values.astc_recompression.UsingGlobal()); } } @@ -71,6 +78,8 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() { ui->use_reactive_flushing, use_reactive_flushing); ConfigurationShared::ApplyPerGameSetting(&Settings::values.async_astc, ui->async_astc, async_astc); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.astc_recompression, + ui->astc_recompression_combobox); ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, ui->use_asynchronous_shaders, use_asynchronous_shaders); @@ -105,6 +114,8 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { Settings::values.renderer_force_max_clock.UsingGlobal()); ui->use_reactive_flushing->setEnabled(Settings::values.use_reactive_flushing.UsingGlobal()); ui->async_astc->setEnabled(Settings::values.async_astc.UsingGlobal()); + ui->astc_recompression_combobox->setEnabled( + Settings::values.astc_recompression.UsingGlobal()); ui->use_asynchronous_shaders->setEnabled( Settings::values.use_asynchronous_shaders.UsingGlobal()); ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); @@ -144,6 +155,9 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { ConfigurationShared::SetColoredComboBox( ui->anisotropic_filtering_combobox, ui->af_label, static_cast<int>(Settings::values.max_anisotropy.GetValue(true))); + ConfigurationShared::SetColoredComboBox( + ui->astc_recompression_combobox, ui->label_astc_recompression, + static_cast<int>(Settings::values.astc_recompression.GetValue(true))); } void ConfigureGraphicsAdvanced::ExposeComputeOption() { diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 9ef7c8e8f..37757a918 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui @@ -70,6 +70,50 @@ </widget> </item> <item> + <widget class="QWidget" name="astc_recompression_layout" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label_astc_recompression"> + <property name="text"> + <string>ASTC recompression:</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="astc_recompression_combobox"> + <item> + <property name="text"> + <string>Uncompressed (Best quality)</string> + </property> + </item> + <item> + <property name="text"> + <string>BC1 (Low quality)</string> + </property> + </item> + <item> + <property name="text"> + <string>BC3 (Medium quality)</string> + </property> + </item> + </widget> + </item> + </layout> + </widget> + </item> + <item> <widget class="QCheckBox" name="async_present"> <property name="text"> <string>Enable asynchronous presentation (Vulkan only)</string> diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index dc9a3d68f..c5bc472ca 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -318,6 +318,7 @@ void Config::ReadValues() { ReadSetting("Renderer", Settings::values.nvdec_emulation); ReadSetting("Renderer", Settings::values.accelerate_astc); ReadSetting("Renderer", Settings::values.async_astc); + ReadSetting("Renderer", Settings::values.astc_recompression); ReadSetting("Renderer", Settings::values.use_fast_gpu_time); ReadSetting("Renderer", Settings::values.use_vulkan_driver_pipeline_cache); diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 5e7c3ac04..644a30e59 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -360,6 +360,10 @@ accelerate_astc = # 0 (default): Off, 1: On async_astc = +# Recompress ASTC textures to a different format. +# 0 (default): Uncompressed, 1: BC1 (Low quality), 2: BC3: (Medium quality) +async_astc = + # Turns on the speed limiter, which will limit the emulation speed to the desired speed limit value # 0: Off, 1: On (default) use_speed_limit = |