From ce9f404bef32e6e02c5ac067449eeb15a7e8c8d6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 Apr 2015 12:39:04 -0700 Subject: [PATCH] Unswizzle when reading from the swizzled mirror. --- GPU/Directx9/TextureCacheDX9.cpp | 18 ++++++++++++------ GPU/GLES/TextureCache.cpp | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index cc8639c6b..8cefc2628 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1450,9 +1450,15 @@ void *TextureCacheDX9::DecodeTextureLevel(GETextureFormat format, GEPaletteForma void *finalBuf = NULL; u32 texaddr = gstate.getTextureAddress(level); - if (texaddr & 0x00600000 && Memory::IsVRAMAddress(texaddr)) { + bool swizzled = gstate.isTextureSwizzled(); + if ((texaddr & 0x00600000) != 0 && Memory::IsVRAMAddress(texaddr)) { // This means it's in a mirror, possibly a swizzled mirror. Let's report. - WARN_LOG_REPORT_ONCE(texmirror, G3D, "Decoding texture from VRAM mirror at %08x swizzle=%d", texaddr, gstate.isTextureSwizzled() ? 1 : 0); + WARN_LOG_REPORT_ONCE(texmirror, G3D, "Decoding texture from VRAM mirror at %08x swizzle=%d", texaddr, swizzled ? 1 : 0); + if ((texaddr & 0x00200000) == 0x00200000) { + // Technically 2 and 6 are slightly different, but this is better than nothing probably. + swizzled = !swizzled; + } + // Note that (texaddr & 0x00600000) == 0x00600000 is very likely to be depth texturing. } int bufw = GetTextureBufw(level, texaddr, format); @@ -1477,7 +1483,7 @@ void *TextureCacheDX9::DecodeTextureLevel(GETextureFormat format, GEPaletteForma tmpTexBufRearrange.resize(std::max(bufw, w) * h); const u16 *clut = GetCurrentClut() + clutSharingOffset; texByteAlign = 2; - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { if (clutAlphaLinear_ && mipmapShareClut) { DeIndexTexture4Optimal(tmpTexBuf16.data(), texptr, bufw * h, clutAlphaLinearColor_); } else { @@ -1501,7 +1507,7 @@ void *TextureCacheDX9::DecodeTextureLevel(GETextureFormat format, GEPaletteForma tmpTexBuf32.resize(std::max(bufw, w) * h); tmpTexBufRearrange.resize(std::max(bufw, w) * h); const u32 *clut = GetCurrentClut() + clutSharingOffset; - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { DeIndexTexture4(tmpTexBuf32.data(), texptr, bufw * h, clut); finalBuf = tmpTexBuf32.data(); } else { @@ -1541,7 +1547,7 @@ void *TextureCacheDX9::DecodeTextureLevel(GETextureFormat format, GEPaletteForma case GE_TFMT_5650: texByteAlign = 2; - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { int len = std::max(bufw, w) * h; tmpTexBuf16.resize(len); tmpTexBufRearrange.resize(len); @@ -1555,7 +1561,7 @@ void *TextureCacheDX9::DecodeTextureLevel(GETextureFormat format, GEPaletteForma break; case GE_TFMT_8888: - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { // Special case: if we don't need to deal with packing, we don't need to copy. //if (w == bufw) { // finalBuf = Memory::GetPointer(texaddr); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 28ad071d4..65ca7067b 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1687,9 +1687,15 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c void *finalBuf = NULL; u32 texaddr = gstate.getTextureAddress(level); - if (texaddr & 0x00600000 && Memory::IsVRAMAddress(texaddr)) { + bool swizzled = gstate.isTextureSwizzled(); + if ((texaddr & 0x00600000) != 0 && Memory::IsVRAMAddress(texaddr)) { // This means it's in a mirror, possibly a swizzled mirror. Let's report. - WARN_LOG_REPORT_ONCE(texmirror, G3D, "Decoding texture from VRAM mirror at %08x swizzle=%d", texaddr, gstate.isTextureSwizzled() ? 1 : 0); + WARN_LOG_REPORT_ONCE(texmirror, G3D, "Decoding texture from VRAM mirror at %08x swizzle=%d", texaddr, swizzled ? 1 : 0); + if ((texaddr & 0x00200000) == 0x00200000) { + // Technically 2 and 6 are slightly different, but this is better than nothing probably. + swizzled = !swizzled; + } + // Note that (texaddr & 0x00600000) == 0x00600000 is very likely to be depth texturing. } int bufw = GetTextureBufw(level, texaddr, format); @@ -1714,7 +1720,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c tmpTexBufRearrange.resize(std::max(bufw, w) * h); const u16 *clut = GetCurrentClut() + clutSharingOffset; texByteAlign = 2; - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { if (clutAlphaLinear_ && mipmapShareClut) { DeIndexTexture4Optimal(tmpTexBuf16.data(), texptr, bufw * h, clutAlphaLinearColor_); } else { @@ -1738,7 +1744,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c tmpTexBuf32.resize(std::max(bufw, w) * h); tmpTexBufRearrange.resize(std::max(bufw, w) * h); const u32 *clut = GetCurrentClut() + clutSharingOffset; - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { DeIndexTexture4(tmpTexBuf32.data(), texptr, bufw * h, clut); finalBuf = tmpTexBuf32.data(); } else { @@ -1778,7 +1784,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c case GE_TFMT_5650: texByteAlign = 2; - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { int len = std::max(bufw, w) * h; tmpTexBuf16.resize(len); tmpTexBufRearrange.resize(len); @@ -1792,7 +1798,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c break; case GE_TFMT_8888: - if (!gstate.isTextureSwizzled()) { + if (!swizzled) { // Special case: if we don't need to deal with packing, we don't need to copy. if ((g_Config.iTexScalingLevel == 1 && gl_extensions.EXT_unpack_subimage) || w == bufw) { if (UseBGRA8888()) {