Merge pull request #1872 from degasus/texcache

Texcache cleanup 2
This commit is contained in:
Markus Wick 2015-01-13 22:45:49 +01:00
commit 7069450ce5
13 changed files with 133 additions and 114 deletions

View File

@ -853,7 +853,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
OSD::DrawMessages();
D3D::EndFrame();
TextureCache::Cleanup();
TextureCache::Cleanup(frameCount);
// Enable configuration changes
UpdateActiveConfig();

View File

@ -100,7 +100,12 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, u
const HRESULT hr = D3D::device->CreateTexture2D(&texdesc, nullptr, &pTexture);
CHECK(SUCCEEDED(hr), "Create texture of the TextureCache");
TCacheEntry* const entry = new TCacheEntry(new D3DTexture2D(pTexture, D3D11_BIND_SHADER_RESOURCE));
TCacheEntryConfig config;
config.width = width;
config.height = height;
config.levels = tex_levels;
TCacheEntry* const entry = new TCacheEntry(config, new D3DTexture2D(pTexture, D3D11_BIND_SHADER_RESOURCE));
entry->usage = usage;
// TODO: better debug names
@ -122,7 +127,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
g_renderer->ResetAPIState();
// stretch picture with increased internal resolution
const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)virtual_width, (float)virtual_height);
const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)config.width, (float)config.height);
D3D::context->RSSetViewports(1, &vp);
// set transformation
@ -188,11 +193,17 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
}
TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
unsigned int scaled_tex_w, unsigned int scaled_tex_h)
unsigned int scaled_tex_w, unsigned int scaled_tex_h, unsigned int layers)
{
return new TCacheEntry(D3DTexture2D::Create(scaled_tex_w, scaled_tex_h,
TCacheEntryConfig config;
config.width = scaled_tex_w;
config.height = scaled_tex_h;
config.layers = layers;
config.rendertarget = true;
return new TCacheEntry(config, D3DTexture2D::Create(scaled_tex_w, scaled_tex_h,
(D3D11_BIND_FLAG)((int)D3D11_BIND_RENDER_TARGET | (int)D3D11_BIND_SHADER_RESOURCE),
D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, FramebufferManager::GetEFBLayers()));
D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM, 1, layers));
}
TextureCache::TextureCache()

View File

@ -23,7 +23,7 @@ private:
D3D11_USAGE usage;
TCacheEntry(D3DTexture2D *_tex) : texture(_tex) {}
TCacheEntry(const TCacheEntryConfig& config, D3DTexture2D *_tex) : TCacheEntryBase(config), texture(_tex) {}
~TCacheEntry();
void Load(unsigned int width, unsigned int height,
@ -41,7 +41,7 @@ private:
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
unsigned int tex_levels, PC_TexFormat pcfmt) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h, unsigned int layers) override;
u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source) {return 0;};
void CompileShaders() override { }

View File

@ -75,7 +75,6 @@ void InitBackendInfo()
}
g_Config.backend_info.APIType = API_D3D;
g_Config.backend_info.bUseMinimalMipCount = true;
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
g_Config.backend_info.bSupportsDualSourceBlend = true;
g_Config.backend_info.bSupportsPrimitiveRestart = true;

View File

@ -1715,7 +1715,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
}
// Clean out old stuff from caches. It's not worth it to clean out the shader caches.
TextureCache::Cleanup();
TextureCache::Cleanup(frameCount);
// Render to the framebuffer.
FramebufferManager::SetFramebuffer(0);

View File

@ -81,7 +81,8 @@ TextureCache::TCacheEntry::~TCacheEntry()
}
}
TextureCache::TCacheEntry::TCacheEntry()
TextureCache::TCacheEntry::TCacheEntry(const TCacheEntryConfig& _config)
: TCacheEntryBase(_config)
{
glGenTextures(1, &texture);
@ -105,7 +106,7 @@ void TextureCache::TCacheEntry::Bind(unsigned int stage)
bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int level)
{
return SaveTexture(filename, GL_TEXTURE_2D_ARRAY, texture, virtual_width, virtual_height, level);
return SaveTexture(filename, GL_TEXTURE_2D_ARRAY, texture, config.width, config.height, level);
}
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, unsigned int height,
@ -164,7 +165,12 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, u
}
}
TCacheEntry &entry = *new TCacheEntry;
TCacheEntryConfig config;
config.width = width;
config.height = height;
config.levels = tex_levels;
TCacheEntry &entry = *new TCacheEntry(config);
entry.gl_format = gl_format;
entry.gl_iformat = gl_iformat;
entry.gl_type = gl_type;
@ -182,6 +188,12 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, u
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level)
{
if (level >= config.levels)
PanicAlert("Texture only has %d levels, can't update level %d", config.levels, level);
if (width != std::max(1u, config.width >> level) || height != std::max(1u, config.height >> level))
PanicAlert("size of level %d must be %dx%d, but %dx%d requested",
level, std::max(1u, config.width >> level), std::max(1u, config.height >> level), width, height);
if (pcfmt != PC_TEX_FMT_DXT1)
{
glActiveTexture(GL_TEXTURE0+9);
@ -205,9 +217,15 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
}
TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
unsigned int scaled_tex_w, unsigned int scaled_tex_h)
unsigned int scaled_tex_w, unsigned int scaled_tex_h, unsigned int layers)
{
TCacheEntry *const entry = new TCacheEntry;
TCacheEntryConfig config;
config.width = scaled_tex_w;
config.height = scaled_tex_h;
config.layers = layers;
config.rendertarget = true;
TCacheEntry *const entry = new TCacheEntry(config);
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_2D_ARRAY, entry->texture);
@ -217,7 +235,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
gl_type = GL_UNSIGNED_BYTE;
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, gl_iformat, scaled_tex_w, scaled_tex_h, FramebufferManager::GetEFBLayers(), 0, gl_format, gl_type, nullptr);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, gl_iformat, scaled_tex_w, scaled_tex_h, layers, 0, gl_format, gl_type, nullptr);
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
glGenFramebuffers(1, &entry->framebuffer);
@ -250,7 +268,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_2D_ARRAY, read_texture);
glViewport(0, 0, virtual_width, virtual_height);
glViewport(0, 0, config.width, config.height);
GLuint uniform_location;
if (srcFormat == PEControl::Z24)
@ -308,7 +326,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
{
static int count = 0;
SaveTexture(StringFromFormat("%sefb_frame_%i.png", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
count++), GL_TEXTURE_2D_ARRAY, texture, virtual_width, virtual_height, 0);
count++), GL_TEXTURE_2D_ARRAY, texture, config.width, config.height, 0);
}
g_renderer->RestoreAPIState();

View File

@ -36,7 +36,7 @@ private:
//TexMode0 mode; // current filter and clamp modes that texture is set to
//TexMode1 mode1; // current filter and clamp modes that texture is set to
TCacheEntry();
TCacheEntry(const TCacheEntryConfig& config);
~TCacheEntry();
void Load(unsigned int width, unsigned int height,
@ -56,7 +56,7 @@ private:
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
unsigned int tex_levels, PC_TexFormat pcfmt) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h, unsigned int layers) override;
void CompileShaders() override;
void DeleteShaders() override;

View File

@ -133,7 +133,6 @@ static void GetShaders(std::vector<std::string> &shaders)
static void InitBackendInfo()
{
g_Config.backend_info.APIType = API_OPENGL;
g_Config.backend_info.bUseMinimalMipCount = false;
g_Config.backend_info.bSupportsExclusiveFullscreen = false;
//g_Config.backend_info.bSupportsDualSourceBlend = true; // is gpu dependent and must be set in renderer
//g_Config.backend_info.bSupportsEarlyZ = true; // is gpu dependent and must be set in renderer

View File

@ -13,17 +13,17 @@
#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"
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/VideoConfig.h"
enum
{
TEXTURE_KILL_THRESHOLD = 200,
RENDER_TARGET_KILL_THRESHOLD = 3,
};
static const u64 TEXHASH_INVALID = 0;
static const int TEXTURE_KILL_THRESHOLD = 200;
static const int RENDER_TARGET_KILL_THRESHOLD = 3;
static const u64 FRAMECOUNT_INVALID = 0;
TextureCache *g_texture_cache;
@ -116,11 +116,7 @@ void TextureCache::OnConfigChanged(VideoConfig& config)
}
// TODO: Probably shouldn't clear all render targets here, just mark them dirty or something.
if (config.bEFBCopyCacheEnable != backup_config.s_copy_cache_enable || // TODO: not sure if this is needed?
config.bCopyEFBToTexture != backup_config.s_copy_efb_to_texture ||
config.bCopyEFBScaled != backup_config.s_copy_efb_scaled ||
config.bEFBCopyEnable != backup_config.s_copy_efb ||
config.iEFBScale != backup_config.s_efb_scale)
if (config.bEFBCopyCacheEnable != backup_config.s_copy_cache_enable) // TODO: not sure if this is needed?
{
g_texture_cache->ClearRenderTargets();
}
@ -134,10 +130,6 @@ void TextureCache::OnConfigChanged(VideoConfig& config)
}
backup_config.s_colorsamples = config.iSafeTextureCache_ColorSamples;
backup_config.s_copy_efb_to_texture = config.bCopyEFBToTexture;
backup_config.s_copy_efb_scaled = config.bCopyEFBScaled;
backup_config.s_copy_efb = config.bEFBCopyEnable;
backup_config.s_efb_scale = config.iEFBScale;
backup_config.s_texfmt_overlay = config.bTexFmtOverlayEnable;
backup_config.s_texfmt_overlay_center = config.bTexFmtOverlayCenter;
backup_config.s_hires_textures = config.bHiresTextures;
@ -146,18 +138,22 @@ void TextureCache::OnConfigChanged(VideoConfig& config)
backup_config.s_efb_mono_depth = config.bStereoEFBMonoDepth;
}
void TextureCache::Cleanup()
void TextureCache::Cleanup(int _frameCount)
{
TexCache::iterator iter = textures.begin();
TexCache::iterator tcend = textures.end();
while (iter != tcend)
{
if (frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount &&
if(iter->second->frameCount == FRAMECOUNT_INVALID)
{
iter->second->frameCount = _frameCount;
}
if (_frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount &&
// EFB copies living on the host GPU are unrecoverable and thus shouldn't be deleted
!iter->second->IsEfbCopy())
{
delete iter->second;
textures.erase(iter++);
iter = textures.erase(iter);
}
else
{
@ -169,7 +165,7 @@ void TextureCache::Cleanup()
{
auto rt = render_target_pool[i];
if (frameCount > RENDER_TARGET_KILL_THRESHOLD + rt->frameCount)
if (_frameCount > RENDER_TARGET_KILL_THRESHOLD + rt->frameCount)
{
delete rt;
render_target_pool[i] = render_target_pool.back();
@ -189,8 +185,7 @@ void TextureCache::InvalidateRange(u32 start_address, u32 size)
tcend = textures.end();
while (iter != tcend)
{
const int rangePosition = iter->second->IntersectsMemoryRange(start_address, size);
if (0 == rangePosition)
if (iter->second->OverlapsMemoryRange(start_address, size))
{
delete iter->second;
textures.erase(iter++);
@ -213,8 +208,7 @@ void TextureCache::MakeRangeDynamic(u32 start_address, u32 size)
for (; iter != tcend; ++iter)
{
const int rangePosition = iter->second->IntersectsMemoryRange(start_address, size);
if (0 == rangePosition)
if (iter->second->OverlapsMemoryRange(start_address, size))
{
iter->second->SetHashes(TEXHASH_INVALID);
}
@ -231,15 +225,15 @@ bool TextureCache::Find(u32 start_address, u64 hash)
return false;
}
int TextureCache::TCacheEntryBase::IntersectsMemoryRange(u32 range_address, u32 range_size) const
bool TextureCache::TCacheEntryBase::OverlapsMemoryRange(u32 range_address, u32 range_size) const
{
if (addr + size_in_bytes < range_address)
return -1;
return false;
if (addr >= range_address + range_size)
return 1;
return false;
return 0;
return true;
}
void TextureCache::ClearRenderTargets()
@ -289,7 +283,7 @@ static u32 CalculateLevelSize(u32 level_0_size, u32 level)
// Used by TextureCache::Load
static TextureCache::TCacheEntryBase* ReturnEntry(unsigned int stage, TextureCache::TCacheEntryBase* entry)
{
entry->frameCount = frameCount;
entry->frameCount = FRAMECOUNT_INVALID;
entry->Bind(stage);
GFX_DEBUGGER_PAUSE_AT(NEXT_TEXTURE_CHANGE, true);
@ -297,10 +291,20 @@ static TextureCache::TCacheEntryBase* ReturnEntry(unsigned int stage, TextureCac
return entry;
}
TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
u32 const address, unsigned int width, unsigned int height, int const texformat,
unsigned int const tlutaddr, int const tlutfmt, bool const use_mipmaps, unsigned int maxlevel, bool const from_tmem)
TextureCache::TCacheEntryBase* TextureCache::Load(const u32 stage)
{
const FourTexUnits &tex = bpmem.tex[stage >> 2];
const u32 id = stage & 3;
const u32 address = (tex.texImage3[id].image_base/* & 0x1FFFFF*/) << 5;
u32 width = tex.texImage0[id].width + 1;
u32 height = tex.texImage0[id].height + 1;
const int texformat = tex.texImage0[id].format;
const u32 tlutaddr = tex.texTlut[id].tmem_offset << 9;
const u32 tlutfmt = tex.texTlut[id].tlut_format;
const bool use_mipmaps = (tex.texMode0[id].min_filter & 3) != 0;
u32 tex_levels = (tex.texMode1[id].max_lod + 0xf) / 0x10 + 1;
const bool from_tmem = tex.texImage1[id].image_type != 0;
if (0 == address)
return nullptr;
@ -354,10 +358,9 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
tex_hash ^= tlut_hash;
}
// D3D doesn't like when the specified mipmap count would require more than one 1x1-sized LOD in the mipmap chain
// e.g. 64x64 with 7 LODs would have the mipmap chain 64x64,32x32,16x16,8x8,4x4,2x2,1x1,1x1, so we limit the mipmap count to 6 there
while (g_ActiveConfig.backend_info.bUseMinimalMipCount && std::max(width, height) >> maxlevel == 0)
--maxlevel;
// GPUs don't like when the specified mipmap count would require more than one 1x1-sized LOD in the mipmap chain
// e.g. 64x64 with 7 LODs would have the mipmap chain 64x64,32x32,16x16,8x8,4x4,2x2,1x1,0x0, so we limit the mipmap count to 6 there
tex_levels = std::min<u32>(IntLog2(std::max(width, height)) + 1, tex_levels);
TCacheEntryBase *entry = textures[texID];
if (entry)
@ -380,7 +383,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const 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->num_mipmaps > maxlevel && entry->native_width == nativeW && entry->native_height == nativeH)
entry->native_levels >= tex_levels && entry->native_width == nativeW && entry->native_height == nativeH)
{
return ReturnEntry(stage, entry);
}
@ -391,14 +394,14 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const 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->num_mipmaps > maxlevel) ||
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
}
@ -457,33 +460,30 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
}
}
u32 texLevels = use_mipmaps ? (maxlevel + 1) : 1;
u32 texLevels = use_mipmaps ? tex_levels : 1;
const bool using_custom_lods = hires_tex && hires_tex->m_levels.size() >= texLevels;
// Only load native mips if their dimensions fit to our virtual texture dimensions
const bool use_native_mips = use_mipmaps && !using_custom_lods && (width == nativeW && height == nativeH);
texLevels = (use_native_mips || using_custom_lods) ? texLevels : 1; // TODO: Should be forced to 1 for non-pow2 textures (e.g. efb copies with automatically adjusted IR)
if (entry && entry->config.levels != texLevels)
{
// delete the texture and make a new one
delete entry;
entry = nullptr;
}
// create the entry/texture
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->num_mipmaps = maxlevel + 1;
entry->num_layers = 1;
entry->type = TCET_NORMAL;
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
}
entry->SetGeneralParameters(address, texture_size, full_format, entry->num_mipmaps, entry->num_layers);
entry->SetDimensions(nativeW, nativeH, width, height);
entry->SetGeneralParameters(address, texture_size, full_format);
entry->SetDimensions(nativeW, nativeH, tex_levels);
entry->hash = tex_hash;
// load texture
@ -851,12 +851,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)
{
@ -876,27 +876,27 @@ 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, 1);
entry->SetHashes(TEXHASH_INVALID);
entry->type = TCET_EC_VRAM;
}
entry->frameCount = frameCount;
entry->frameCount = FRAMECOUNT_INVALID;
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();
@ -905,7 +905,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)

View File

@ -25,9 +25,18 @@ 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
{
#define TEXHASH_INVALID 0
const TCacheEntryConfig config;
// common members
u32 addr;
@ -37,30 +46,25 @@ public:
enum TexCacheEntryType type;
unsigned int num_mipmaps;
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
unsigned int native_levels;
// 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 _num_mipmaps, unsigned int _num_layers)
void SetGeneralParameters(u32 _addr, u32 _size, u32 _format)
{
addr = _addr;
size_in_bytes = _size;
format = _format;
num_mipmaps = _num_mipmaps;
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, unsigned int _native_levels)
{
native_width = _native_width;
native_height = _native_height;
virtual_width = _virtual_width;
virtual_height = _virtual_height;
native_levels = _native_levels;
}
void SetHashes(u64 _hash)
@ -68,7 +72,7 @@ public:
hash = _hash;
}
TCacheEntryBase(const TCacheEntryConfig& c) : config(c) {}
virtual ~TCacheEntryBase();
virtual void Bind(unsigned int stage) = 0;
@ -81,7 +85,7 @@ public:
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
const float *colmat) = 0;
int IntersectsMemoryRange(u32 range_address, u32 range_size) const;
bool OverlapsMemoryRange(u32 range_address, u32 range_size) const;
bool IsEfbCopy() { return (type == TCET_EC_VRAM || type == TCET_EC_DYNAMIC); }
};
@ -89,7 +93,10 @@ public:
virtual ~TextureCache(); // needs virtual for DX11 dtor
static void OnConfigChanged(VideoConfig& config);
static void Cleanup();
// Removes textures which aren't used for more than TEXTURE_KILL_THRESHOLD frames,
// frameCount is the current frame number.
static void Cleanup(int frameCount);
static void Invalidate();
static void InvalidateRange(u32 start_address, u32 size);
@ -99,13 +106,12 @@ 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
static TCacheEntryBase* Load(unsigned int stage, u32 address, unsigned int width, unsigned int height,
int format, unsigned int tlutaddr, int tlutfmt, bool use_mipmaps, unsigned int maxlevel, bool from_tmem);
static TCacheEntryBase* Load(const u32 stage);
static void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, PEControl::PixelFormat srcFormat,
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf);
@ -121,7 +127,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;
@ -134,10 +140,6 @@ private:
static struct BackupConfig
{
int s_colorsamples;
bool s_copy_efb_to_texture;
bool s_copy_efb_scaled;
bool s_copy_efb;
int s_efb_scale;
bool s_texfmt_overlay;
bool s_texfmt_overlay_center;
bool s_hires_textures;

View File

@ -202,15 +202,7 @@ void VertexManager::Flush()
for (unsigned int i : usedtextures)
{
g_renderer->SetSamplerState(i & 3, i >> 2);
const FourTexUnits &tex = bpmem.tex[i >> 2];
const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
tex.texTlut[i&3].tlut_format,
((tex.texMode0[i&3].min_filter & 3) != 0),
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
(tex.texImage1[i&3].image_type != 0));
const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i);
if (tentry)
{

View File

@ -36,7 +36,6 @@ VideoConfig::VideoConfig()
// disable all features by default
backend_info.APIType = API_NONE;
backend_info.bUseMinimalMipCount = false;
backend_info.bSupportsExclusiveFullscreen = false;
// Game-specific stereoscopy settings

View File

@ -146,7 +146,6 @@ struct VideoConfig final
std::vector<std::string> AAModes;
std::vector<std::string> PPShaders; // post-processing shaders
bool bUseMinimalMipCount;
bool bSupportsExclusiveFullscreen;
bool bSupportsDualSourceBlend;
bool bSupportsPrimitiveRestart;