mirror of
https://github.com/libretro/Play-.git
synced 2024-11-30 20:21:25 +00:00
Use GsTextureCache in OpenGL GS handler.
This commit is contained in:
parent
c9df382661
commit
ae30df7683
@ -65,11 +65,6 @@ void CGSH_OpenGL::InitializeImpl()
|
||||
|
||||
m_nVtxCount = 0;
|
||||
|
||||
for(unsigned int i = 0; i < MAX_TEXTURE_CACHE; i++)
|
||||
{
|
||||
m_textureCache.push_back(TexturePtr(new CTexture()));
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < MAX_PALETTE_CACHE; i++)
|
||||
{
|
||||
m_paletteCache.push_back(PalettePtr(new CPalette()));
|
||||
@ -84,7 +79,6 @@ void CGSH_OpenGL::ReleaseImpl()
|
||||
{
|
||||
ResetImpl();
|
||||
|
||||
m_textureCache.clear();
|
||||
m_paletteCache.clear();
|
||||
m_shaders.clear();
|
||||
m_presentProgram.reset();
|
||||
@ -103,7 +97,7 @@ void CGSH_OpenGL::ReleaseImpl()
|
||||
void CGSH_OpenGL::ResetImpl()
|
||||
{
|
||||
LoadPreferences();
|
||||
TexCache_Flush();
|
||||
m_textureCache.Flush();
|
||||
PalCache_Flush();
|
||||
m_framebuffers.clear();
|
||||
m_depthbuffers.clear();
|
||||
@ -285,8 +279,12 @@ void CGSH_OpenGL::FlipImpl()
|
||||
void CGSH_OpenGL::LoadState(Framework::CZipArchiveReader& archive)
|
||||
{
|
||||
CGSHandler::LoadState(archive);
|
||||
|
||||
m_mailBox.SendCall(std::bind(&CGSH_OpenGL::TexCache_InvalidateTextures, this, 0, RAMSIZE));
|
||||
m_mailBox.SendCall(
|
||||
[this] ()
|
||||
{
|
||||
m_textureCache.InvalidateRange(0, RAMSIZE);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::RegisterPreferences()
|
||||
@ -299,7 +297,7 @@ void CGSH_OpenGL::RegisterPreferences()
|
||||
void CGSH_OpenGL::NotifyPreferencesChangedImpl()
|
||||
{
|
||||
LoadPreferences();
|
||||
TexCache_Flush();
|
||||
m_textureCache.Flush();
|
||||
PalCache_Flush();
|
||||
m_framebuffers.clear();
|
||||
m_depthbuffers.clear();
|
||||
@ -2012,7 +2010,7 @@ void CGSH_OpenGL::ProcessHostToLocalTransfer()
|
||||
uint32 transferSize = pageCount * CGsPixelFormats::PAGESIZE;
|
||||
uint32 transferOffset = (trxPos.nDSAY / transferPageSize.second) * pageCountX * CGsPixelFormats::PAGESIZE;
|
||||
|
||||
TexCache_InvalidateTextures(transferAddress + transferOffset, transferSize);
|
||||
m_textureCache.InvalidateRange(transferAddress + transferOffset, transferSize);
|
||||
|
||||
bool isUpperByteTransfer = (bltBuf.nDstPsm == PSMT8H) || (bltBuf.nDstPsm == PSMT4HL) || (bltBuf.nDstPsm == PSMT4HH);
|
||||
for(const auto& framebuffer : m_framebuffers)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <unordered_map>
|
||||
#include "../GSHandler.h"
|
||||
#include "../GsCachedArea.h"
|
||||
#include "../GsTextureCache.h"
|
||||
#include "opengl/OpenGlDef.h"
|
||||
#include "opengl/Program.h"
|
||||
#include "opengl/Shader.h"
|
||||
@ -29,7 +30,6 @@ public:
|
||||
void ReadFramebuffer(uint32, uint32, void*) override;
|
||||
|
||||
protected:
|
||||
void TexCache_Flush();
|
||||
void PalCache_Flush();
|
||||
void LoadPreferences();
|
||||
virtual void InitializeImpl() override;
|
||||
@ -41,6 +41,8 @@ protected:
|
||||
GLuint m_presentFramebuffer = 0;
|
||||
|
||||
private:
|
||||
typedef CGsTextureCache<Framework::OpenGl::CTexture> TextureCache;
|
||||
|
||||
enum class TECHNIQUE
|
||||
{
|
||||
STANDARD,
|
||||
@ -174,22 +176,6 @@ private:
|
||||
|
||||
typedef std::unordered_map<uint32, Framework::OpenGl::ProgramPtr> ShaderMap;
|
||||
|
||||
class CTexture
|
||||
{
|
||||
public:
|
||||
CTexture();
|
||||
~CTexture();
|
||||
void Free();
|
||||
|
||||
uint64 m_tex0;
|
||||
GLuint m_texture;
|
||||
bool m_live;
|
||||
|
||||
CGsCachedArea m_cachedArea;
|
||||
};
|
||||
typedef std::shared_ptr<CTexture> TexturePtr;
|
||||
typedef std::list<TexturePtr> TextureList;
|
||||
|
||||
class CPalette
|
||||
{
|
||||
public:
|
||||
@ -375,10 +361,6 @@ private:
|
||||
|
||||
uint8* m_pCvtBuffer;
|
||||
|
||||
CTexture* TexCache_Search(const TEX0&);
|
||||
void TexCache_Insert(const TEX0&, GLuint);
|
||||
void TexCache_InvalidateTextures(uint32, uint32);
|
||||
|
||||
GLuint PalCache_Search(const TEX0&);
|
||||
GLuint PalCache_Search(unsigned int, const uint32*);
|
||||
void PalCache_Insert(const TEX0&, const uint32*, GLuint);
|
||||
@ -401,7 +383,7 @@ private:
|
||||
GLint m_copyToFbSrcPositionUniform = -1;
|
||||
GLint m_copyToFbSrcSizeUniform = -1;
|
||||
|
||||
TextureList m_textureCache;
|
||||
TextureCache m_textureCache;
|
||||
PaletteList m_paletteCache;
|
||||
FramebufferList m_framebuffers;
|
||||
DepthbufferList m_depthbuffers;
|
||||
|
@ -143,7 +143,7 @@ CGSH_OpenGL::TEXTURE_INFO CGSH_OpenGL::PrepareTexture(const TEX0& tex0)
|
||||
}
|
||||
}
|
||||
|
||||
auto texture = TexCache_Search(tex0);
|
||||
auto texture = m_textureCache.Search(tex0);
|
||||
if(!texture)
|
||||
{
|
||||
//Validate texture dimensions to prevent problems
|
||||
@ -155,22 +155,21 @@ CGSH_OpenGL::TEXTURE_INFO CGSH_OpenGL::PrepareTexture(const TEX0& tex0)
|
||||
texHeight = std::min<uint32>(texHeight, 1024);
|
||||
auto texFormat = GetTextureFormatInfo(tex0.nPsm);
|
||||
|
||||
GLuint textureHandle = 0;
|
||||
glGenTextures(1, &textureHandle);
|
||||
glBindTexture(GL_TEXTURE_2D, textureHandle);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, texFormat.internalFormat, texWidth, texHeight);
|
||||
CHECKGLERROR();
|
||||
|
||||
TexCache_Insert(tex0, textureHandle);
|
||||
texture = TexCache_Search(tex0);
|
||||
assert(textureHandle == texture->m_texture);
|
||||
{
|
||||
auto textureHandle = Framework::OpenGl::CTexture::Create();
|
||||
glBindTexture(GL_TEXTURE_2D, textureHandle);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, texFormat.internalFormat, texWidth, texHeight);
|
||||
CHECKGLERROR();
|
||||
m_textureCache.Insert(tex0, std::move(textureHandle));
|
||||
}
|
||||
|
||||
texture = m_textureCache.Search(tex0);
|
||||
texture->m_cachedArea.Invalidate(0, RAMSIZE);
|
||||
}
|
||||
|
||||
texInfo.textureHandle = texture->m_texture;
|
||||
texInfo.textureHandle = texture->m_textureHandle;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->m_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->m_textureHandle);
|
||||
auto& cachedArea = texture->m_cachedArea;
|
||||
auto texturePageSize = CGsPixelFormats::GetPsmPageSize(tex0.nPsm);
|
||||
auto areaRect = cachedArea.GetAreaPageRect();
|
||||
@ -402,83 +401,6 @@ void CGSH_OpenGL::TexUpdater_Psm48H(uint32 bufPtr, uint32 bufWidth, unsigned int
|
||||
CHECKGLERROR();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Texture
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
CGSH_OpenGL::CTexture::CTexture()
|
||||
: m_tex0(0)
|
||||
, m_texture(0)
|
||||
, m_live(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CGSH_OpenGL::CTexture::~CTexture()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::CTexture::Free()
|
||||
{
|
||||
if(m_texture != 0)
|
||||
{
|
||||
glDeleteTextures(1, &m_texture);
|
||||
m_texture = 0;
|
||||
}
|
||||
m_live = false;
|
||||
m_cachedArea.ClearDirtyPages();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Texture Caching
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
CGSH_OpenGL::CTexture* CGSH_OpenGL::TexCache_Search(const TEX0& tex0)
|
||||
{
|
||||
uint64 maskedTex0 = static_cast<uint64>(tex0) & TEX0_CLUTINFO_MASK;
|
||||
|
||||
for(auto textureIterator(m_textureCache.begin());
|
||||
textureIterator != m_textureCache.end(); textureIterator++)
|
||||
{
|
||||
auto texture = *textureIterator;
|
||||
if(!texture->m_live) continue;
|
||||
if(maskedTex0 != texture->m_tex0) continue;
|
||||
m_textureCache.erase(textureIterator);
|
||||
m_textureCache.push_front(texture);
|
||||
return texture.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::TexCache_Insert(const TEX0& tex0, GLuint textureHandle)
|
||||
{
|
||||
auto texture = *m_textureCache.rbegin();
|
||||
texture->Free();
|
||||
|
||||
texture->m_cachedArea.SetArea(tex0.nPsm, tex0.GetBufPtr(), tex0.GetBufWidth(), tex0.GetHeight());
|
||||
|
||||
texture->m_tex0 = static_cast<uint64>(tex0) & TEX0_CLUTINFO_MASK;
|
||||
texture->m_texture = textureHandle;
|
||||
texture->m_live = true;
|
||||
|
||||
m_textureCache.pop_back();
|
||||
m_textureCache.push_front(texture);
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::TexCache_InvalidateTextures(uint32 start, uint32 size)
|
||||
{
|
||||
std::for_each(std::begin(m_textureCache), std::end(m_textureCache),
|
||||
[start, size] (TexturePtr& texture) { if(texture->m_live) { texture->m_cachedArea.Invalidate(start, size); } });
|
||||
}
|
||||
|
||||
void CGSH_OpenGL::TexCache_Flush()
|
||||
{
|
||||
std::for_each(std::begin(m_textureCache), std::end(m_textureCache),
|
||||
[] (TexturePtr& texture) { texture->Free(); });
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Palette
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user