2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
2012-11-26 03:25:14 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "../Globals.h"
|
2013-04-09 08:59:47 +00:00
|
|
|
#include "Common/MemoryUtil.h"
|
2013-01-31 23:18:23 +00:00
|
|
|
#include "gfx_es2/fbo.h"
|
2013-02-17 00:06:06 +00:00
|
|
|
#include "GPU/GPUState.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-21 20:37:19 +00:00
|
|
|
struct VirtualFramebuffer;
|
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
class TextureCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextureCache();
|
|
|
|
~TextureCache();
|
|
|
|
|
|
|
|
void SetTexture();
|
|
|
|
|
|
|
|
void Clear(bool delete_them);
|
|
|
|
void StartFrame();
|
|
|
|
void Invalidate(u32 addr, int size, bool force);
|
|
|
|
void InvalidateAll(bool force);
|
|
|
|
|
2013-01-31 23:18:23 +00:00
|
|
|
// FramebufferManager keeps TextureCache updated about what regions of memory
|
|
|
|
// are being rendered to. This is barebones so far.
|
2013-02-21 20:37:19 +00:00
|
|
|
void NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer);
|
|
|
|
void NotifyFramebufferDestroyed(u32 address, VirtualFramebuffer *framebuffer);
|
2013-01-31 23:18:23 +00:00
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
size_t NumLoadedTextures() const {
|
|
|
|
return cache.size();
|
|
|
|
}
|
|
|
|
|
2013-02-17 00:06:06 +00:00
|
|
|
bool DecodeTexture(u8 *output, GPUgstate state);
|
2013-02-21 20:37:19 +00:00
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
private:
|
2013-04-27 17:35:42 +00:00
|
|
|
// Wow this is starting to grow big. Soon need to start looking at resizing it.
|
2013-01-30 19:40:26 +00:00
|
|
|
struct TexCacheEntry {
|
2013-02-11 07:29:44 +00:00
|
|
|
// After marking STATUS_UNRELIABLE, if it stays the same this many frames we'll trust it again.
|
|
|
|
const static int FRAMES_REGAIN_TRUST = 1000;
|
|
|
|
|
2013-02-10 22:11:53 +00:00
|
|
|
enum Status {
|
|
|
|
STATUS_HASHING,
|
|
|
|
STATUS_RELIABLE, // cache, don't hash
|
|
|
|
STATUS_UNRELIABLE, // never cache
|
|
|
|
};
|
|
|
|
|
|
|
|
// Status, but int so we can zero initialize.
|
|
|
|
int status;
|
2013-01-30 19:40:26 +00:00
|
|
|
u32 addr;
|
|
|
|
u32 hash;
|
2013-02-21 20:37:19 +00:00
|
|
|
VirtualFramebuffer *framebuffer; // if null, not sourced from an FBO.
|
2013-01-30 19:40:26 +00:00
|
|
|
u32 sizeInRAM;
|
2013-02-10 21:19:01 +00:00
|
|
|
int lastFrame;
|
|
|
|
int numFrames;
|
|
|
|
u32 framesUntilNextFullHash;
|
2013-01-31 23:18:23 +00:00
|
|
|
u8 format;
|
2013-02-18 16:34:51 +00:00
|
|
|
u8 clutformat;
|
2013-04-27 17:35:42 +00:00
|
|
|
u16 dim;
|
2013-01-30 19:40:26 +00:00
|
|
|
u32 clutaddr;
|
|
|
|
u32 texture; //GLuint
|
|
|
|
int invalidHint;
|
|
|
|
u32 fullhash;
|
2013-02-07 23:04:34 +00:00
|
|
|
int maxLevel;
|
|
|
|
float lodBias;
|
2013-01-30 19:40:26 +00:00
|
|
|
|
|
|
|
// Cache the current filter settings so we can avoid setting it again.
|
2013-04-27 17:35:42 +00:00
|
|
|
// (OpenGL madness where filter settings are attached to each texture).
|
2013-01-30 19:40:26 +00:00
|
|
|
u8 magFilt;
|
|
|
|
u8 minFilt;
|
|
|
|
bool sClamp;
|
|
|
|
bool tClamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Decimate(); // Run this once per frame to get rid of old textures.
|
2013-04-18 12:59:00 +00:00
|
|
|
void *UnswizzleFromMem(u32 texaddr, u32 bufw, u32 bytesPerPixel, u32 level);
|
2013-01-30 19:40:26 +00:00
|
|
|
void *readIndexedTex(int level, u32 texaddr, int bytesPerIndex);
|
|
|
|
void UpdateSamplingParams(TexCacheEntry &entry, bool force);
|
2013-02-07 23:04:34 +00:00
|
|
|
void LoadTextureLevel(TexCacheEntry &entry, int level);
|
2013-01-30 19:40:26 +00:00
|
|
|
|
2013-01-31 23:18:23 +00:00
|
|
|
TexCacheEntry *GetEntryAt(u32 texaddr);
|
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
typedef std::map<u64, TexCacheEntry> TexCache;
|
|
|
|
TexCache cache;
|
|
|
|
|
2013-04-09 08:52:19 +00:00
|
|
|
template <typename T>
|
|
|
|
class SimpleBuf {
|
|
|
|
public:
|
|
|
|
SimpleBuf() : buf_(NULL), size_(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleBuf(size_t size) : buf_(NULL) {
|
|
|
|
resize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SimpleBuf() {
|
|
|
|
if (buf_ != NULL) {
|
2013-04-09 08:59:47 +00:00
|
|
|
FreeMemoryPages(buf_, size_ * sizeof(T));
|
2013-04-09 08:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T &operator[](size_t index) {
|
|
|
|
return buf_[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doesn't preserve contents.
|
|
|
|
void resize(size_t size) {
|
|
|
|
if (size_ < size) {
|
|
|
|
if (buf_ != NULL) {
|
2013-04-09 08:59:47 +00:00
|
|
|
FreeMemoryPages(buf_, size_ * sizeof(T));
|
2013-04-09 08:52:19 +00:00
|
|
|
}
|
2013-04-09 08:59:47 +00:00
|
|
|
buf_ = (T *)AllocateMemoryPages(size * sizeof(T));
|
2013-04-09 08:52:19 +00:00
|
|
|
size_ = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
T *data() {
|
|
|
|
return buf_;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size() {
|
|
|
|
return size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T *buf_;
|
|
|
|
size_t size_;
|
|
|
|
};
|
|
|
|
|
|
|
|
SimpleBuf<u32> tmpTexBuf32;
|
|
|
|
SimpleBuf<u16> tmpTexBuf16;
|
2013-01-30 19:40:26 +00:00
|
|
|
|
2013-04-09 08:52:19 +00:00
|
|
|
SimpleBuf<u32> tmpTexBufRearrange;
|
2013-01-30 19:40:26 +00:00
|
|
|
|
|
|
|
u32 *clutBuf32;
|
|
|
|
u16 *clutBuf16;
|
2013-02-12 18:05:30 +00:00
|
|
|
|
2013-02-18 16:34:51 +00:00
|
|
|
u32 lastBoundTexture;
|
2013-02-14 23:30:02 +00:00
|
|
|
float maxAnisotropyLevel;
|
2013-01-30 19:40:26 +00:00
|
|
|
};
|
2012-11-01 15:19:01 +00:00
|
|
|
|