From 0ec526c5f1eecea5957d571e4e7ed21890b62cdf Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 31 Jul 2021 02:50:22 +0300 Subject: [PATCH] rsx: Do not use VTC tiling on NPOT textures - Seems to be ignored for 'normal' textures. Mostly verified through games. --- rpcs3/Emu/RSX/Common/TextureUtils.cpp | 10 ++++++++-- rpcs3/util/asm.hpp | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index 505bb8dedc..0ff3b88470 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -689,7 +689,10 @@ namespace rsx case CELL_GCM_TEXTURE_COMPRESSED_DXT1: { - if (depth > 1 && !caps.supports_vtc_decoding) + if (depth > 1 && + utils::is_power_of_2(src_layout.width_in_texel) && + utils::is_power_of_2(src_layout.height_in_texel) && + !caps.supports_vtc_decoding) { // PS3 uses the Nvidia VTC memory layout for compressed 3D textures. // This is only supported using Nvidia OpenGL. @@ -711,7 +714,10 @@ namespace rsx case CELL_GCM_TEXTURE_COMPRESSED_DXT23: case CELL_GCM_TEXTURE_COMPRESSED_DXT45: { - if (depth > 1 && !caps.supports_vtc_decoding) + if (depth > 1 && + utils::is_power_of_2(src_layout.width_in_texel) && + utils::is_power_of_2(src_layout.height_in_texel) && + !caps.supports_vtc_decoding) { // PS3 uses the Nvidia VTC memory layout for compressed 3D textures. // This is only supported using Nvidia OpenGL. diff --git a/rpcs3/util/asm.hpp b/rpcs3/util/asm.hpp index 5757e06233..571c70a0f1 100644 --- a/rpcs3/util/asm.hpp +++ b/rpcs3/util/asm.hpp @@ -385,6 +385,13 @@ namespace utils return static_cast(value / align + (value > 0 ? T{(value % align) > (align / 2)} : 0 - T{(value % align) < (align / 2)})); } + // Returns true if input is an unsigned integer with a power of 2 + template requires(std::is_integral_v && std::is_unsigned_v) + constexpr T is_power_of_2(T value) + { + return !(value & (value - 1)); + } + // Hack. Pointer cast util to workaround UB. Use with extreme care. template [[nodiscard]] T* bless(U* ptr)