From ecd1a04e4470e23b8bea03d17b977fe6aba935b3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 19 Feb 2018 09:02:22 -0800 Subject: [PATCH] GLES: Fix unpack misalignment, Qt debugger freeing. We no longer use unpack, so we should always decode to w not bufw. --- GPU/GLES/TextureCacheGLES.cpp | 68 ++++++++++++++--------------------- GPU/GLES/TextureCacheGLES.h | 3 -- 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index cfa0ab0cb0..0430decbf1 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -696,29 +696,6 @@ GLenum TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat c } } -u8 *TextureCacheGLES::DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufwout) { - void *finalBuf = nullptr; - u32 texaddr = gstate.getTextureAddress(level); - int bufw = GetTextureBufw(level, texaddr, format); - if (bufwout) - *bufwout = bufw; - - int w = gstate.getTextureWidth(level); - int h = gstate.getTextureHeight(level); - - int decPitch = 0; - int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; - if (!(scaleFactor == 1 && gstate_c.Supports(GPU_SUPPORTS_UNPACK_SUBIMAGE)) && w != bufw) { - decPitch = w * pixelSize; - } else { - decPitch = bufw * pixelSize; - } - - uint8_t *texBuf = (uint8_t *)AllocateAlignedMemory(std::max(w, bufw) * h * pixelSize, 16); - DecodeTextureLevel(texBuf, decPitch, format, clutformat, texaddr, level, bufw, true, false, false); - return texBuf; -} - TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h) { CheckAlphaResult res; switch (dstFmt) { @@ -766,15 +743,19 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r PROFILE_THIS_SCOPE("decodetex"); GEPaletteFormat clutformat = gstate.getClutPaletteFormat(); - int bufw; - uint8_t *finalBuf = DecodeTextureLevelOld(GETextureFormat(entry.format), clutformat, level, dstFmt, scaleFactor, &bufw); - if (!finalBuf) { - return; - } + u32 texaddr = gstate.getTextureAddress(level); + int bufw = GetTextureBufw(level, texaddr, GETextureFormat(entry.format)); + int w = gstate.getTextureWidth(level); + int h = gstate.getTextureHeight(level); + + int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; + int decPitch = w * pixelSize; + + pixelData = (uint8_t *)AllocateAlignedMemory(decPitch * h * pixelSize, 16); + DecodeTextureLevel(pixelData, decPitch, GETextureFormat(entry.format), clutformat, texaddr, level, bufw, true, false, false); // Textures are always aligned to 16 bytes bufw, so this could safely be 4 always. texByteAlign = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; - pixelData = finalBuf; // We check before scaling since scaling shouldn't invent alpha from a full alpha texture. if ((entry.status & TexCacheEntry::STATUS_CHANGE_FREQUENT) == 0) { @@ -787,8 +768,8 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r if (scaleFactor > 1) { uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16); scaler.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, dstFmt, w, h, scaleFactor); + FreeAlignedMemory(pixelData); pixelData = rearrange; - FreeAlignedMemory(finalBuf); } if (replacer_.Enabled()) { @@ -844,16 +825,17 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) { int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); - void *finalBuf = DecodeTextureLevelOld(format, clutformat, level, dstFmt, 1); - if (finalBuf == NULL) { - return false; - } + int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; + int decPitch = w * pixelSize; + + void *finalBuf = AllocateAlignedMemory(decPitch * h * pixelSize, 16); + DecodeTextureLevel((uint8_t *)finalBuf, decPitch, format, clutformat, texaddr, level, bufw, true, false, false); switch (dstFmt) { case GL_UNSIGNED_SHORT_4_4_4_4: for (int y = 0; y < h; y++) - for (int x = 0; x < bufw; x++) { - u32 val = ((u16*)finalBuf)[y*bufw + x]; + for (int x = 0; x < w; x++) { + u32 val = ((u16*)finalBuf)[y*w + x]; u32 r = ((val>>12) & 0xF) * 17; u32 g = ((val>> 8) & 0xF) * 17; u32 b = ((val>> 4) & 0xF) * 17; @@ -864,8 +846,8 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) { case GL_UNSIGNED_SHORT_5_5_5_1: for (int y = 0; y < h; y++) - for (int x = 0; x < bufw; x++) { - u32 val = ((u16*)finalBuf)[y*bufw + x]; + for (int x = 0; x < w; x++) { + u32 val = ((u16*)finalBuf)[y*w + x]; u32 r = Convert5To8((val>>11) & 0x1F); u32 g = Convert5To8((val>> 6) & 0x1F); u32 b = Convert5To8((val>> 1) & 0x1F); @@ -876,8 +858,8 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) { case GL_UNSIGNED_SHORT_5_6_5: for (int y = 0; y < h; y++) - for (int x = 0; x < bufw; x++) { - u32 val = ((u16*)finalBuf)[y*bufw + x]; + for (int x = 0; x < w; x++) { + u32 val = ((u16*)finalBuf)[y*w + x]; u32 a = 0xFF; u32 r = Convert5To8((val>>11) & 0x1F); u32 g = Convert6To8((val>> 5) & 0x3F); @@ -888,13 +870,15 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) { default: for (int y = 0; y < h; y++) - for (int x = 0; x < bufw; x++) { - u32 val = ((u32*)finalBuf)[y*bufw + x]; + for (int x = 0; x < w; x++) { + u32 val = ((u32*)finalBuf)[y*w + x]; ((u32*)output)[y*w + x] = ((val & 0xFF000000)) | ((val & 0x00FF0000)>>16) | ((val & 0x0000FF00)) | ((val & 0x000000FF)<<16); } break; } + FreeAlignedMemory(finalBuf); + gstate = oldState; return true; } diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 2d415c599a..eb81e44663 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -81,9 +81,6 @@ private: void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, bool replaceImages, int scaleFactor, GLenum dstFmt); GLenum GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; - // Caller owns the returned buffer. Delete[]. - u8 *DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufw = 0); - TexCacheEntry::TexStatus CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override;