From df46e5137c64bacb4eca4be8fce8dff70eb3d494 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Thu, 6 Oct 2022 21:53:59 +0300 Subject: [PATCH] gl: Fix texture reconstruction logic - Use correct target types - Fix key generation to apply differently for each target type --- rpcs3/Emu/RSX/GL/GLTextureCache.cpp | 49 ++++++++++++++++++++++++----- rpcs3/Emu/RSX/GL/GLTextureCache.h | 2 +- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.cpp b/rpcs3/Emu/RSX/GL/GLTextureCache.cpp index 39954b6192..edf113f129 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.cpp +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.cpp @@ -8,6 +8,44 @@ namespace gl { + static u64 encode_properties(GLenum sized_internal_fmt, GLenum target, u16 width, u16 height, u16 depth, u8 mipmaps) + { + // Generate cache key + // 00..13 = width + // 14..27 = height + // 28..35 = depth + // 36..39 = mipmaps + // 40..41 = type + // 42..57 = format + ensure(((width | height) & ~0x3fff) == 0, "Image dimensions are too large - lower your resolution scale."); + ensure(mipmaps <= 13); + + GLuint target_encoding = 0; + switch (target) + { + case GL_TEXTURE_1D: + target_encoding = 0; break; + case GL_TEXTURE_2D: + target_encoding = 1; break; + case GL_TEXTURE_3D: + target_encoding = 2; break; + case GL_TEXTURE_CUBE_MAP: + target_encoding = 3; break; + default: + fmt::throw_exception("Unsupported destination target 0x%x", target); + } + + const u64 key = + (static_cast(width) << 0) | + (static_cast(height) << 14) | + (static_cast(depth) << 28) | + (static_cast(mipmaps) << 36) | + (static_cast(target_encoding) << 40) | + (static_cast(sized_internal_fmt) << 42); + + return key; + } + void cached_texture_section::finish_flush() { // Free resources @@ -83,7 +121,7 @@ namespace gl } } - gl::texture_view* texture_cache::create_temporary_subresource_impl(gl::command_context& cmd, gl::texture* src, GLenum sized_internal_fmt, GLenum dst_type, + gl::texture_view* texture_cache::create_temporary_subresource_impl(gl::command_context& cmd, gl::texture* src, GLenum sized_internal_fmt, GLenum dst_target, u32 gcm_format, u16 x, u16 y, u16 width, u16 height, u16 depth, u8 mipmaps, const rsx::texture_channel_remap_t& remap, bool copy) { if (sized_internal_fmt == GL_NONE) @@ -92,12 +130,7 @@ namespace gl } temporary_image_t* dst = nullptr; - const u64 match_key = - (static_cast(width) << 0) | - (static_cast(height) << 16) | - (static_cast(depth) << 32) | - (static_cast(mipmaps) << 40) | - (static_cast(sized_internal_fmt) << 48); + const auto match_key = encode_properties(sized_internal_fmt, dst_target, width, height, depth, mipmaps); // Search image cache for (auto& e : m_temporary_surfaces) @@ -116,7 +149,7 @@ namespace gl if (!dst) { - std::unique_ptr data = std::make_unique(dst_type, width, height, depth, mipmaps, sized_internal_fmt, rsx::classify_format(gcm_format)); + std::unique_ptr data = std::make_unique(dst_target, width, height, depth, mipmaps, sized_internal_fmt, rsx::classify_format(gcm_format)); dst = data.get(); dst->properties_encoding = match_key; m_temporary_surfaces.emplace_back(std::move(data)); diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.h b/rpcs3/Emu/RSX/GL/GLTextureCache.h index 4f4b640978..86559d45b8 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.h +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.h @@ -558,7 +558,7 @@ namespace gl gl::texture_view* generate_cubemap_from_images(gl::command_context& cmd, u32 gcm_format, u16 size, const std::vector& sources, const rsx::texture_channel_remap_t& remap_vector) override { auto _template = get_template_from_collection_impl(sources); - auto result = create_temporary_subresource_impl(cmd, _template, GL_NONE, GL_TEXTURE_3D, gcm_format, 0, 0, size, size, 1, 1, remap_vector, false); + auto result = create_temporary_subresource_impl(cmd, _template, GL_NONE, GL_TEXTURE_CUBE_MAP, gcm_format, 0, 0, size, size, 1, 1, remap_vector, false); copy_transfer_regions_impl(cmd, result->image(), sources); return result;