mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
TexCache: create a const Config struct
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
#include "VideoCommon/Debugger.h"
|
||||
#include "VideoCommon/FramebufferManagerBase.h"
|
||||
#include "VideoCommon/HiresTextures.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
@ -383,7 +384,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage)
|
||||
|
||||
// 2. b) For normal textures, all texture parameters need to match
|
||||
if (address == entry->addr && tex_hash == entry->hash && full_format == entry->format &&
|
||||
entry->tex_levels >= tex_levels && entry->native_width == nativeW && entry->native_height == nativeH)
|
||||
entry->config.levels >= tex_levels && entry->native_width == nativeW && entry->native_height == nativeH)
|
||||
{
|
||||
return ReturnEntry(stage, entry);
|
||||
}
|
||||
@ -394,14 +395,14 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage)
|
||||
// TODO: Don't we need to force texture decoding to RGBA8 for dynamic EFB copies?
|
||||
// TODO: Actually, it should be enough if the internal texture format matches...
|
||||
if (((entry->type == TCET_NORMAL &&
|
||||
width == entry->virtual_width &&
|
||||
height == entry->virtual_height &&
|
||||
width == entry->config.width &&
|
||||
height == entry->config.height &&
|
||||
full_format == entry->format &&
|
||||
entry->tex_levels >= tex_levels) ||
|
||||
entry->config.levels >= tex_levels) ||
|
||||
(entry->type == TCET_EC_DYNAMIC &&
|
||||
entry->native_width == width &&
|
||||
entry->native_height == height)) &&
|
||||
entry->num_layers == 1)
|
||||
entry->config.layers == 1)
|
||||
{
|
||||
// reuse the texture
|
||||
}
|
||||
@ -470,23 +471,13 @@ TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage)
|
||||
if (nullptr == entry)
|
||||
{
|
||||
textures[texID] = entry = g_texture_cache->CreateTexture(width, height, texLevels, pcfmt);
|
||||
|
||||
// Sometimes, we can get around recreating a texture if only the number of mip levels changes
|
||||
// e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states
|
||||
// Thus, we don't update this member for every Load, but just whenever the texture gets recreated
|
||||
|
||||
// TODO: This is the wrong value. We should be storing the number of levels our actual texture has.
|
||||
// But that will currently make the above "existing entry" tests fail as "texLevels" is not calculated until after.
|
||||
// Currently, we might try to reuse a texture which appears to have more levels than actual, maybe..
|
||||
entry->tex_levels = tex_levels;
|
||||
entry->num_layers = 1;
|
||||
entry->type = TCET_NORMAL;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
|
||||
}
|
||||
|
||||
entry->SetGeneralParameters(address, texture_size, full_format, entry->tex_levels, entry->num_layers);
|
||||
entry->SetDimensions(nativeW, nativeH, width, height);
|
||||
entry->SetGeneralParameters(address, texture_size, full_format);
|
||||
entry->SetDimensions(nativeW, nativeH);
|
||||
entry->hash = tex_hash;
|
||||
|
||||
// load texture
|
||||
@ -854,12 +845,12 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
|
||||
TCacheEntryBase *entry = textures[dstAddr];
|
||||
if (entry)
|
||||
{
|
||||
if (entry->type == TCET_EC_DYNAMIC && entry->native_width == tex_w && entry->native_height == tex_h && entry->num_layers == efb_layers)
|
||||
if (entry->type == TCET_EC_DYNAMIC && entry->native_width == tex_w && entry->native_height == tex_h && entry->config.layers == efb_layers)
|
||||
{
|
||||
scaled_tex_w = tex_w;
|
||||
scaled_tex_h = tex_h;
|
||||
}
|
||||
else if (!(entry->type == TCET_EC_VRAM && entry->virtual_width == scaled_tex_w && entry->virtual_height == scaled_tex_h && entry->num_layers == efb_layers))
|
||||
else if (!(entry->type == TCET_EC_VRAM && entry->config.width == scaled_tex_w && entry->config.height == scaled_tex_h && entry->config.layers == efb_layers))
|
||||
{
|
||||
if (entry->type == TCET_EC_VRAM)
|
||||
{
|
||||
@ -879,11 +870,11 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
|
||||
if (nullptr == entry)
|
||||
{
|
||||
// create the texture
|
||||
textures[dstAddr] = entry = AllocateRenderTarget(scaled_tex_w, scaled_tex_h);
|
||||
textures[dstAddr] = entry = AllocateRenderTarget(scaled_tex_w, scaled_tex_h, FramebufferManagerBase::GetEFBLayers());
|
||||
|
||||
// TODO: Using the wrong dstFormat, dumb...
|
||||
entry->SetGeneralParameters(dstAddr, 0, dstFormat, 1, efb_layers);
|
||||
entry->SetDimensions(tex_w, tex_h, scaled_tex_w, scaled_tex_h);
|
||||
entry->SetGeneralParameters(dstAddr, 0, dstFormat);
|
||||
entry->SetDimensions(tex_w, tex_h);
|
||||
entry->SetHashes(TEXHASH_INVALID);
|
||||
entry->type = TCET_EC_VRAM;
|
||||
}
|
||||
@ -893,13 +884,13 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
|
||||
entry->FromRenderTarget(dstAddr, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat);
|
||||
}
|
||||
|
||||
TextureCache::TCacheEntryBase* TextureCache::AllocateRenderTarget(unsigned int width, unsigned int height)
|
||||
TextureCache::TCacheEntryBase* TextureCache::AllocateRenderTarget(unsigned int width, unsigned int height, unsigned int layers)
|
||||
{
|
||||
for (size_t i = 0; i < render_target_pool.size(); ++i)
|
||||
{
|
||||
auto rt = render_target_pool[i];
|
||||
|
||||
if (rt->virtual_width != width || rt->virtual_height != height)
|
||||
if (rt->config.width != width || rt->config.height != height || rt->config.layers != layers)
|
||||
continue;
|
||||
|
||||
render_target_pool[i] = render_target_pool.back();
|
||||
@ -908,7 +899,7 @@ TextureCache::TCacheEntryBase* TextureCache::AllocateRenderTarget(unsigned int w
|
||||
return rt;
|
||||
}
|
||||
|
||||
return g_texture_cache->CreateRenderTargetTexture(width, height);
|
||||
return g_texture_cache->CreateRenderTargetTexture(width, height, layers);
|
||||
}
|
||||
|
||||
void TextureCache::FreeRenderTarget(TCacheEntryBase* entry)
|
||||
|
@ -25,8 +25,19 @@ public:
|
||||
TCET_EC_DYNAMIC, // EFB copy which sits in RAM and needs to be decoded before being used
|
||||
};
|
||||
|
||||
struct TCacheEntryConfig
|
||||
{
|
||||
TCacheEntryConfig() : width(0), height(0), levels(1), layers(1), rendertarget(false) {}
|
||||
|
||||
u32 width, height;
|
||||
u32 levels, layers;
|
||||
bool rendertarget;
|
||||
};
|
||||
|
||||
struct TCacheEntryBase
|
||||
{
|
||||
const TCacheEntryConfig config;
|
||||
|
||||
// common members
|
||||
u32 addr;
|
||||
u32 size_in_bytes;
|
||||
@ -35,30 +46,23 @@ public:
|
||||
|
||||
enum TexCacheEntryType type;
|
||||
|
||||
unsigned int tex_levels;
|
||||
unsigned int num_layers;
|
||||
unsigned int native_width, native_height; // Texture dimensions from the GameCube's point of view
|
||||
unsigned int virtual_width, virtual_height; // Texture dimensions from OUR point of view - for hires textures or scaled EFB copies
|
||||
|
||||
// used to delete textures which haven't been used for TEXTURE_KILL_THRESHOLD frames
|
||||
int frameCount;
|
||||
|
||||
|
||||
void SetGeneralParameters(u32 _addr, u32 _size, u32 _format, unsigned int _tex_levels, unsigned int _num_layers)
|
||||
void SetGeneralParameters(u32 _addr, u32 _size, u32 _format)
|
||||
{
|
||||
addr = _addr;
|
||||
size_in_bytes = _size;
|
||||
format = _format;
|
||||
tex_levels = _tex_levels;
|
||||
num_layers = _num_layers;
|
||||
}
|
||||
|
||||
void SetDimensions(unsigned int _native_width, unsigned int _native_height, unsigned int _virtual_width, unsigned int _virtual_height)
|
||||
void SetDimensions(unsigned int _native_width, unsigned int _native_height)
|
||||
{
|
||||
native_width = _native_width;
|
||||
native_height = _native_height;
|
||||
virtual_width = _virtual_width;
|
||||
virtual_height = _virtual_height;
|
||||
}
|
||||
|
||||
void SetHashes(u64 _hash)
|
||||
@ -66,7 +70,7 @@ public:
|
||||
hash = _hash;
|
||||
}
|
||||
|
||||
|
||||
TCacheEntryBase(const TCacheEntryConfig& c) : config(c) {}
|
||||
virtual ~TCacheEntryBase();
|
||||
|
||||
virtual void Bind(unsigned int stage) = 0;
|
||||
@ -100,7 +104,7 @@ public:
|
||||
|
||||
virtual TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
|
||||
unsigned int tex_levels, PC_TexFormat pcfmt) = 0;
|
||||
virtual TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) = 0;
|
||||
virtual TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h, unsigned int layers) = 0;
|
||||
|
||||
virtual void CompileShaders() = 0; // currently only implemented by OGL
|
||||
virtual void DeleteShaders() = 0; // currently only implemented by OGL
|
||||
@ -121,7 +125,7 @@ private:
|
||||
static void DumpTexture(TCacheEntryBase* entry, std::string basename, unsigned int level);
|
||||
static void CheckTempSize(size_t required_size);
|
||||
|
||||
static TCacheEntryBase* AllocateRenderTarget(unsigned int width, unsigned int height);
|
||||
static TCacheEntryBase* AllocateRenderTarget(unsigned int width, unsigned int height, unsigned int layers);
|
||||
static void FreeRenderTarget(TCacheEntryBase* entry);
|
||||
|
||||
typedef std::map<u32, TCacheEntryBase*> TexCache;
|
||||
|
Reference in New Issue
Block a user