Skip to content

Commit

Permalink
Merge pull request #19717 from hrydgard/tag-force-texture-hashing
Browse files Browse the repository at this point in the history
Add special texture hashing mode solving the Tag Force problem
  • Loading branch information
hrydgard authored Dec 10, 2024
2 parents 034bf1f + ec19c47 commit cc9a25c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
12 changes: 11 additions & 1 deletion GPU/Common/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ bool TextureReplacer::LoadIniValues(IniFile &ini, VFSBackend *dir, bool isOverri
// Multiplies sizeInRAM/bytesPerLine in XXHASH by 0.5.
options->Get("reduceHash", &reduceHash_, reduceHash_);
options->Get("ignoreMipmap", &ignoreMipmap_, ignoreMipmap_);
options->Get("skipLastDXT1Blocks128x64", &skipLastDXT1Blocks128x64_, skipLastDXT1Blocks128x64_);
if (reduceHash_ && hash_ == ReplacedTextureHash::QUICK) {
reduceHash_ = false;
ERROR_LOG(Log::TexReplacement, "Texture Replacement: reduceHash option requires safer hash, use xxh32 or xxh64 instead.");
Expand Down Expand Up @@ -506,21 +507,30 @@ u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, bool swizzled
}

const u8 *checkp = Memory::GetPointerUnchecked(addr);

float reduceHashSize = 1.0f;
if (reduceHash_) {
reduceHashSize = LookupReduceHashRange(w, h);
// default to reduceHashGlobalValue which default is 0.5
}

if (bufw <= w) {
// We can assume the data is contiguous. These are the total used pixels.
const u32 totalPixels = bufw * h + (w - bufw);
const u32 sizeInRAM = (textureBitsPerPixel[fmt] * totalPixels) / 8 * reduceHashSize;
u32 sizeInRAM = (textureBitsPerPixel[fmt] * totalPixels) / 8 * reduceHashSize;

// Sanity check: Ignore textures that are at the end of RAM.
if (Memory::MaxSizeAtAddress(addr) < sizeInRAM) {
ERROR_LOG(Log::G3D, "Can't hash a %d bytes textures at %08x - end point is outside memory", sizeInRAM, addr);
return 0;
}

// Hack for Yu Gi Oh texture hashing problem. See issue #19714
if (skipLastDXT1Blocks128x64_ && fmt == GE_TFMT_DXT1 && w == 128 && h == 64) {
// Skip the last few blocks as specified.
sizeInRAM -= 8 * skipLastDXT1Blocks128x64_;
}

switch (hash_) {
case ReplacedTextureHash::QUICK:
return StableQuickTexHash(checkp, sizeInRAM);
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TextureReplacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class TextureReplacer {
bool ignoreAddress_ = false;
bool reduceHash_ = false;
bool ignoreMipmap_ = false;
int skipLastDXT1Blocks128x64_ = 0;

float reduceHashSize = 1.0f; // default value with reduceHash to false
float reduceHashGlobalValue = 0.5f; // Global value for textures dump pngs of all sizes, 0.5 by default but can be set in textures.ini

double lastTextureCacheSizeGB_ = 0.0;
Expand Down
2 changes: 0 additions & 2 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,6 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
}
// Format might be wrong in lowMemoryMode_, so don't save.
if (plan.saveTexture && !lowMemoryMode_) {
INFO_LOG(Log::G3D, "Calling NotifyTextureDecoded %08x", entry->addr);

// When hardware texture scaling is enabled, this saves the original.
int w = dataScaled ? mipWidth : mipUnscaledWidth;
int h = dataScaled ? mipHeight : mipUnscaledHeight;
Expand Down
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,7 @@ UI::EventReturn DeveloperToolsScreen::OnLoggingChanged(UI::EventParams &e) {
}

UI::EventReturn DeveloperToolsScreen::OnRunCPUTests(UI::EventParams &e) {
// TODO: If game is loaded, don't do anything.
#if !PPSSPP_PLATFORM(UWP)
RunTests();
#endif
Expand Down

0 comments on commit cc9a25c

Please sign in to comment.