mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-24 16:49:50 +00:00
Merge pull request #1235 from unknownbrackets/texcache
Allocate the temp texcache buffers dynamically
This commit is contained in:
commit
be5af6831e
@ -43,23 +43,16 @@ u32 RoundUpToPowerOf2(u32 v)
|
||||
|
||||
TextureCache::TextureCache() {
|
||||
lastBoundTexture = -1;
|
||||
// TODO: Switch to aligned allocations for alignment. AllocateMemoryPages would do the trick.
|
||||
// This is 5MB of temporary storage. Might be possible to shrink it.
|
||||
tmpTexBuf32 = new u32[1024 * 512]; // 2MB
|
||||
tmpTexBuf16 = new u16[1024 * 512]; // 1MB
|
||||
tmpTexBufRearrange = new u32[1024 * 512]; // 2MB
|
||||
tmpTexBuf32.resize(1024 * 512); // 2MB
|
||||
tmpTexBuf16.resize(1024 * 512); // 1MB
|
||||
tmpTexBufRearrange.resize(1024 * 512); // 2MB
|
||||
clutBuf32 = new u32[4096]; // 4K
|
||||
clutBuf16 = new u16[4096]; // 4K
|
||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropyLevel);
|
||||
}
|
||||
|
||||
TextureCache::~TextureCache() {
|
||||
delete [] tmpTexBuf32;
|
||||
tmpTexBuf32 = 0;
|
||||
delete [] tmpTexBuf16;
|
||||
tmpTexBuf16 = 0;
|
||||
delete [] tmpTexBufRearrange;
|
||||
tmpTexBufRearrange = 0;
|
||||
delete [] clutBuf32;
|
||||
delete [] clutBuf16;
|
||||
}
|
||||
@ -231,7 +224,7 @@ void *TextureCache::UnswizzleFromMem(u32 texaddr, u32 bytesPerPixel, u32 level)
|
||||
}
|
||||
}
|
||||
}
|
||||
return tmpTexBuf32;
|
||||
return tmpTexBuf32.data();
|
||||
}
|
||||
|
||||
void *TextureCache::readIndexedTex(int level, u32 texaddr, int bytesPerIndex) {
|
||||
@ -242,6 +235,8 @@ void *TextureCache::readIndexedTex(int level, u32 texaddr, int bytesPerIndex) {
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
{
|
||||
tmpTexBuf16.resize(length);
|
||||
tmpTexBufRearrange.resize(length);
|
||||
ReadClut16(clutBuf16);
|
||||
const u16 *clut = clutBuf16;
|
||||
if (!(gstate.texmode & 1)) {
|
||||
@ -297,7 +292,7 @@ void *TextureCache::readIndexedTex(int level, u32 texaddr, int bytesPerIndex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf = tmpTexBuf16;
|
||||
buf = tmpTexBuf16.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -358,7 +353,7 @@ void *TextureCache::readIndexedTex(int level, u32 texaddr, int bytesPerIndex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf = tmpTexBuf32;
|
||||
buf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -929,6 +924,8 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
{
|
||||
tmpTexBuf16.resize(bufw * h);
|
||||
tmpTexBufRearrange.resize(bufw * h);
|
||||
ReadClut16(clutBuf16);
|
||||
const u16 *clut = clutBuf16;
|
||||
u32 clutSharingOffset = 0; //(gstate.mipmapShareClut & 1) ? 0 : level * 16;
|
||||
@ -953,7 +950,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
}
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf16;
|
||||
finalBuf = tmpTexBuf16.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -981,7 +978,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
}
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1022,9 +1019,11 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
|
||||
if (!(gstate.texmode & 1)) {
|
||||
int len = std::max(bufw, w) * h;
|
||||
tmpTexBuf16.resize(len);
|
||||
tmpTexBufRearrange.resize(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
tmpTexBuf16[i] = Memory::ReadUnchecked_U16(texaddr + i * 2);
|
||||
finalBuf = tmpTexBuf16;
|
||||
finalBuf = tmpTexBuf16.data();
|
||||
}
|
||||
else
|
||||
finalBuf = UnswizzleFromMem(texaddr, 2, level);
|
||||
@ -1036,7 +1035,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
int len = bufw * h;
|
||||
for (int i = 0; i < len; i++)
|
||||
tmpTexBuf32[i] = Memory::ReadUnchecked_U32(texaddr + i * 4);
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
else
|
||||
finalBuf = UnswizzleFromMem(texaddr, 4, level);
|
||||
@ -1045,7 +1044,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
case GE_TFMT_DXT1:
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
u32 *dst = tmpTexBuf32;
|
||||
u32 *dst = tmpTexBuf32.data();
|
||||
DXT1Block *src = (DXT1Block*)texptr;
|
||||
|
||||
for (int y = 0; y < h; y += 4) {
|
||||
@ -1055,7 +1054,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
blockIndex++;
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
w = (w + 3) & ~3;
|
||||
}
|
||||
break;
|
||||
@ -1063,7 +1062,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
case GE_TFMT_DXT3:
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
u32 *dst = tmpTexBuf32;
|
||||
u32 *dst = tmpTexBuf32.data();
|
||||
DXT3Block *src = (DXT3Block*)texptr;
|
||||
|
||||
// Alpha is off
|
||||
@ -1075,7 +1074,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
}
|
||||
}
|
||||
w = (w + 3) & ~3;
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1083,7 +1082,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
ERROR_LOG(G3D, "Unhandled compressed texture, format %i! swizzle=%i", entry.format, gstate.texmode & 1);
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
u32 *dst = tmpTexBuf32;
|
||||
u32 *dst = tmpTexBuf32.data();
|
||||
DXT5Block *src = (DXT5Block*)texptr;
|
||||
|
||||
// Alpha is almost right
|
||||
@ -1095,13 +1094,13 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
}
|
||||
}
|
||||
w = (w + 3) & ~3;
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG_REPORT(G3D, "Unknown Texture Format %d!!!", entry.format);
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1129,8 +1128,8 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level)
|
||||
const u8 *read = (const u8 *)finalBuf;
|
||||
u8 *write = 0;
|
||||
if (w > bufw) {
|
||||
write = (u8 *)tmpTexBufRearrange;
|
||||
finalBuf = tmpTexBufRearrange;
|
||||
write = (u8 *)tmpTexBufRearrange.data();
|
||||
finalBuf = tmpTexBufRearrange.data();
|
||||
} else {
|
||||
write = (u8 *)finalBuf;
|
||||
}
|
||||
@ -1199,6 +1198,8 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
case GE_CMODE_16BIT_ABGR5551:
|
||||
case GE_CMODE_16BIT_ABGR4444:
|
||||
{
|
||||
tmpTexBuf16.resize(bufw * h);
|
||||
tmpTexBufRearrange.resize(bufw * h);
|
||||
ReadClut16(clutBuf16);
|
||||
const u16 *clut = clutBuf16;
|
||||
u32 clutSharingOff = 0;//gstate.mipmapShareClut ? 0 : level * 16;
|
||||
@ -1223,7 +1224,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
}
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf16;
|
||||
finalBuf = tmpTexBuf16.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1251,7 +1252,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
}
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1292,9 +1293,11 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
|
||||
if (!(gstate.texmode & 1)) {
|
||||
int len = std::max(bufw, w) * h;
|
||||
tmpTexBuf16.resize(len);
|
||||
tmpTexBufRearrange.resize(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
tmpTexBuf16[i] = Memory::ReadUnchecked_U16(texaddr + i * 2);
|
||||
finalBuf = tmpTexBuf16;
|
||||
finalBuf = tmpTexBuf16.data();
|
||||
}
|
||||
else
|
||||
finalBuf = UnswizzleFromMem(texaddr, 2, level);
|
||||
@ -1306,7 +1309,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
int len = bufw * h;
|
||||
for (int i = 0; i < len; i++)
|
||||
tmpTexBuf32[i] = Memory::ReadUnchecked_U32(texaddr + i * 4);
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
else
|
||||
finalBuf = UnswizzleFromMem(texaddr, 4, level);
|
||||
@ -1315,7 +1318,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
case GE_TFMT_DXT1:
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
u32 *dst = tmpTexBuf32;
|
||||
u32 *dst = tmpTexBuf32.data();
|
||||
DXT1Block *src = (DXT1Block*)texptr;
|
||||
|
||||
for (int y = 0; y < h; y += 4) {
|
||||
@ -1325,7 +1328,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
blockIndex++;
|
||||
}
|
||||
}
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
w = (w + 3) & ~3;
|
||||
}
|
||||
break;
|
||||
@ -1333,7 +1336,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
case GE_TFMT_DXT3:
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
u32 *dst = tmpTexBuf32;
|
||||
u32 *dst = tmpTexBuf32.data();
|
||||
DXT3Block *src = (DXT3Block*)texptr;
|
||||
|
||||
// Alpha is off
|
||||
@ -1345,7 +1348,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
}
|
||||
}
|
||||
w = (w + 3) & ~3;
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1353,7 +1356,7 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
ERROR_LOG(G3D, "Unhandled compressed texture, format %i! swizzle=%i", format, gstate.texmode & 1);
|
||||
dstFmt = GL_UNSIGNED_BYTE;
|
||||
{
|
||||
u32 *dst = tmpTexBuf32;
|
||||
u32 *dst = tmpTexBuf32.data();
|
||||
DXT5Block *src = (DXT5Block*)texptr;
|
||||
|
||||
// Alpha is almost right
|
||||
@ -1365,13 +1368,13 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
||||
}
|
||||
}
|
||||
w = (w + 3) & ~3;
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG(G3D, "Unknown Texture Format %d!!!", format);
|
||||
finalBuf = tmpTexBuf32;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Globals.h"
|
||||
#include "Common/MemoryUtil.h"
|
||||
#include "gfx_es2/fbo.h"
|
||||
#include "GPU/GPUState.h"
|
||||
|
||||
@ -96,10 +97,54 @@ private:
|
||||
typedef std::map<u64, TexCacheEntry> TexCache;
|
||||
TexCache cache;
|
||||
|
||||
u32 *tmpTexBuf32;
|
||||
u16 *tmpTexBuf16;
|
||||
template <typename T>
|
||||
class SimpleBuf {
|
||||
public:
|
||||
SimpleBuf() : buf_(NULL), size_(0) {
|
||||
}
|
||||
|
||||
u32 *tmpTexBufRearrange;
|
||||
SimpleBuf(size_t size) : buf_(NULL) {
|
||||
resize(size);
|
||||
}
|
||||
|
||||
~SimpleBuf() {
|
||||
if (buf_ != NULL) {
|
||||
FreeMemoryPages(buf_, size_ * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
inline T &operator[](size_t index) {
|
||||
return buf_[index];
|
||||
}
|
||||
|
||||
// Doesn't preserve contents.
|
||||
void resize(size_t size) {
|
||||
if (size_ < size) {
|
||||
if (buf_ != NULL) {
|
||||
FreeMemoryPages(buf_, size_ * sizeof(T));
|
||||
}
|
||||
buf_ = (T *)AllocateMemoryPages(size * sizeof(T));
|
||||
size_ = size;
|
||||
}
|
||||
}
|
||||
|
||||
T *data() {
|
||||
return buf_;
|
||||
}
|
||||
|
||||
size_t size() {
|
||||
return size_;
|
||||
}
|
||||
|
||||
private:
|
||||
T *buf_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
SimpleBuf<u32> tmpTexBuf32;
|
||||
SimpleBuf<u16> tmpTexBuf16;
|
||||
|
||||
SimpleBuf<u32> tmpTexBufRearrange;
|
||||
|
||||
u32 *clutBuf32;
|
||||
u16 *clutBuf16;
|
||||
|
Loading…
Reference in New Issue
Block a user