From 75f2995f258b2c63c494b03217f6d96dea11554b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 25 Sep 2013 23:16:34 -0700 Subject: [PATCH] Move some texture deindexing to GPU/Common/. --- GPU/Common/TextureDecoder.h | 81 ++++++++++++++++++++++++++++++++ GPU/Directx9/TextureCacheDX9.cpp | 81 -------------------------------- GPU/GLES/TextureCache.cpp | 81 -------------------------------- 3 files changed, 81 insertions(+), 162 deletions(-) diff --git a/GPU/Common/TextureDecoder.h b/GPU/Common/TextureDecoder.h index db036194dd..96152b461e 100644 --- a/GPU/Common/TextureDecoder.h +++ b/GPU/Common/TextureDecoder.h @@ -98,3 +98,84 @@ static inline u32 GetTextureBufw(int level, u32 texaddr, GETextureFormat format) } return bufw; } + +template +inline void DeIndexTexture(ClutT *dest, const IndexT *indexed, int length, const ClutT *clut) { + // Usually, there is no special offset, mask, or shift. + const bool nakedIndex = gstate.isClutIndexSimple(); + + if (nakedIndex) { + if (sizeof(IndexT) == 1) { + for (int i = 0; i < length; ++i) { + *dest++ = clut[*indexed++]; + } + } else { + for (int i = 0; i < length; ++i) { + *dest++ = clut[(*indexed++) & 0xFF]; + } + } + } else { + for (int i = 0; i < length; ++i) { + *dest++ = clut[gstate.transformClutIndex(*indexed++)]; + } + } +} + +template +inline void DeIndexTexture(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { + const IndexT *indexed = (const IndexT *) Memory::GetPointer(texaddr); + DeIndexTexture(dest, indexed, length, clut); +} + +template +inline void DeIndexTexture4(ClutT *dest, const u8 *indexed, int length, const ClutT *clut) { + // Usually, there is no special offset, mask, or shift. + const bool nakedIndex = gstate.isClutIndexSimple(); + + if (nakedIndex) { + for (int i = 0; i < length; i += 2) { + u8 index = *indexed++; + dest[i + 0] = clut[(index >> 0) & 0xf]; + dest[i + 1] = clut[(index >> 4) & 0xf]; + } + } else { + for (int i = 0; i < length; i += 2) { + u8 index = *indexed++; + dest[i + 0] = clut[gstate.transformClutIndex((index >> 0) & 0xf)]; + dest[i + 1] = clut[gstate.transformClutIndex((index >> 4) & 0xf)]; + } + } +} + +template +inline void DeIndexTexture4Optimal(ClutT *dest, const u8 *indexed, int length, ClutT color) { + for (int i = 0; i < length; i += 2) { + u8 index = *indexed++; + dest[i + 0] = color | ((index >> 0) & 0xf); + dest[i + 1] = color | ((index >> 4) & 0xf); + } +} + +template <> +inline void DeIndexTexture4Optimal(u16 *dest, const u8 *indexed, int length, u16 color) { + const u16_le *indexed16 = (const u16_le *)indexed; + const u32 color32 = (color << 16) | color; + u32 *dest32 = (u32 *)dest; + for (int i = 0; i < length / 2; i += 2) { + u16 index = *indexed16++; + dest32[i + 0] = color32 | ((index & 0x00f0) << 12) | ((index & 0x000f) >> 0); + dest32[i + 1] = color32 | ((index & 0xf000) << 4) | ((index & 0x0f00) >> 8); + } +} + +template +inline void DeIndexTexture4(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { + const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); + DeIndexTexture4(dest, indexed, length, clut); +} + +template +inline void DeIndexTexture4Optimal(ClutT *dest, const u32 texaddr, int length, ClutT color) { + const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); + DeIndexTexture4Optimal(dest, indexed, length, color); +} diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 12854f9d94..d5dd08f674 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -324,87 +324,6 @@ void *TextureCacheDX9::UnswizzleFromMem(u32 texaddr, u32 bufw, u32 bytesPerPixel return tmpTexBuf32.data(); } -template -inline void DeIndexTexture(ClutT *dest, const IndexT *indexed, int length, const ClutT *clut) { - // Usually, there is no special offset, mask, or shift. - const bool nakedIndex = gstate.isClutIndexSimple(); - - if (nakedIndex) { - if (sizeof(IndexT) == 1) { - for (int i = 0; i < length; ++i) { - *dest++ = clut[*indexed++]; - } - } else { - for (int i = 0; i < length; ++i) { - *dest++ = clut[(*indexed++) & 0xFF]; - } - } - } else { - for (int i = 0; i < length; ++i) { - *dest++ = clut[gstate.transformClutIndex(*indexed++)]; - } - } -} - -template -inline void DeIndexTexture(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { - const IndexT *indexed = (const IndexT *) Memory::GetPointer(texaddr); - DeIndexTexture(dest, indexed, length, clut); -} - -template -inline void DeIndexTexture4(ClutT *dest, const u8 *indexed, int length, const ClutT *clut) { - // Usually, there is no special offset, mask, or shift. - const bool nakedIndex = gstate.isClutIndexSimple(); - - if (nakedIndex) { - for (int i = 0; i < length; i += 2) { - u8 index = *indexed++; - dest[i + 0] = clut[(index >> 0) & 0xf]; - dest[i + 1] = clut[(index >> 4) & 0xf]; - } - } else { - for (int i = 0; i < length; i += 2) { - u8 index = *indexed++; - dest[i + 0] = clut[gstate.transformClutIndex((index >> 0) & 0xf)]; - dest[i + 1] = clut[gstate.transformClutIndex((index >> 4) & 0xf)]; - } - } -} - -template -inline void DeIndexTexture4Optimal(ClutT *dest, const u8 *indexed, int length, ClutT color) { - for (int i = 0; i < length; i += 2) { - u8 index = *indexed++; - dest[i + 0] = color | ((index >> 0) & 0xf); - dest[i + 1] = color | ((index >> 4) & 0xf); - } -} - -template <> -inline void DeIndexTexture4Optimal(u16 *dest, const u8 *indexed, int length, u16 color) { - const u16_le *indexed16 = (const u16_le *)indexed; - const u32 color32 = (color << 16) | color; - u32 *dest32 = (u32 *)dest; - for (int i = 0; i < length / 2; i += 2) { - u16 index = *indexed16++; - dest32[i + 0] = color32 | ((index & 0x00f0) << 12) | ((index & 0x000f) >> 0); - dest32[i + 1] = color32 | ((index & 0xf000) << 4) | ((index & 0x0f00) >> 8); - } -} - -template -inline void DeIndexTexture4(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { - const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); - DeIndexTexture4(dest, indexed, length, clut); -} - -template -inline void DeIndexTexture4Optimal(ClutT *dest, const u32 texaddr, int length, ClutT color) { - const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); - DeIndexTexture4Optimal(dest, indexed, length, color); -} - void *TextureCacheDX9::ReadIndexedTex(int level, u32 texaddr, int bytesPerIndex, u32 dstFmt, int bufw) { int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 64f6fea120..af9b6a070f 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -329,87 +329,6 @@ void *TextureCache::UnswizzleFromMem(u32 texaddr, u32 bufw, u32 bytesPerPixel, u return tmpTexBuf32.data(); } -template -inline void DeIndexTexture(ClutT *dest, const IndexT *indexed, int length, const ClutT *clut) { - // Usually, there is no special offset, mask, or shift. - const bool nakedIndex = gstate.isClutIndexSimple(); - - if (nakedIndex) { - if (sizeof(IndexT) == 1) { - for (int i = 0; i < length; ++i) { - *dest++ = clut[*indexed++]; - } - } else { - for (int i = 0; i < length; ++i) { - *dest++ = clut[(*indexed++) & 0xFF]; - } - } - } else { - for (int i = 0; i < length; ++i) { - *dest++ = clut[gstate.transformClutIndex(*indexed++)]; - } - } -} - -template -inline void DeIndexTexture(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { - const IndexT *indexed = (const IndexT *) Memory::GetPointer(texaddr); - DeIndexTexture(dest, indexed, length, clut); -} - -template -inline void DeIndexTexture4(ClutT *dest, const u8 *indexed, int length, const ClutT *clut) { - // Usually, there is no special offset, mask, or shift. - const bool nakedIndex = gstate.isClutIndexSimple(); - - if (nakedIndex) { - for (int i = 0; i < length; i += 2) { - u8 index = *indexed++; - dest[i + 0] = clut[(index >> 0) & 0xf]; - dest[i + 1] = clut[(index >> 4) & 0xf]; - } - } else { - for (int i = 0; i < length; i += 2) { - u8 index = *indexed++; - dest[i + 0] = clut[gstate.transformClutIndex((index >> 0) & 0xf)]; - dest[i + 1] = clut[gstate.transformClutIndex((index >> 4) & 0xf)]; - } - } -} - -template -inline void DeIndexTexture4Optimal(ClutT *dest, const u8 *indexed, int length, ClutT color) { - for (int i = 0; i < length; i += 2) { - u8 index = *indexed++; - dest[i + 0] = color | ((index >> 0) & 0xf); - dest[i + 1] = color | ((index >> 4) & 0xf); - } -} - -template <> -inline void DeIndexTexture4Optimal(u16 *dest, const u8 *indexed, int length, u16 color) { - const u16 *indexed16 = (const u16 *)indexed; - const u32 color32 = (color << 16) | color; - u32 *dest32 = (u32 *)dest; - for (int i = 0; i < length / 2; i += 2) { - u16 index = *indexed16++; - dest32[i + 0] = color32 | ((index & 0x00f0) << 12) | ((index & 0x000f) >> 0); - dest32[i + 1] = color32 | ((index & 0xf000) << 4) | ((index & 0x0f00) >> 8); - } -} - -template -inline void DeIndexTexture4(ClutT *dest, const u32 texaddr, int length, const ClutT *clut) { - const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); - DeIndexTexture4(dest, indexed, length, clut); -} - -template -inline void DeIndexTexture4Optimal(ClutT *dest, const u32 texaddr, int length, ClutT color) { - const u8 *indexed = (const u8 *) Memory::GetPointer(texaddr); - DeIndexTexture4Optimal(dest, indexed, length, color); -} - void *TextureCache::ReadIndexedTex(int level, u32 texaddr, int bytesPerIndex, GLuint dstFmt, int bufw) { int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level);