refactor: Get rid of gstate from depalshadercache

This commit is contained in:
Henrik Rydgard 2015-07-29 14:28:40 +02:00
parent b5f7d9346f
commit 1c68069083
6 changed files with 30 additions and 33 deletions

View file

@ -20,7 +20,6 @@
#include "base/logging.h"
#include "Common/Log.h"
#include "Core/Reporting.h"
#include "GPU/GPUState.h"
#include "GPU/Directx9/TextureCacheDX9.h"
#include "GPU/Directx9/DepalettizeShaderDX9.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
@ -64,13 +63,12 @@ DepalShaderCacheDX9::~DepalShaderCacheDX9() {
}
}
u32 DepalShaderCacheDX9::GenerateShaderID(GEBufferFormat pixelFormat) {
return (gstate.clutformat & 0xFFFFFF) | (pixelFormat << 24);
u32 DepalShaderCacheDX9::GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
return (clutFormat & 0xFFFFFF) | (pixelFormat << 24);
}
LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(const u32 clutID, u32 *rawClut) {
GEPaletteFormat palFormat = gstate.getClutPaletteFormat();
const u32 realClutID = clutID ^ palFormat;
LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) {
const u32 realClutID = clutID ^ clutFormat;
auto oldtex = texCache_.find(realClutID);
if (oldtex != texCache_.end()) {
@ -78,8 +76,8 @@ LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(const u32 clutID, u32 *ra
return oldtex->second->texture;
}
D3DFORMAT dstFmt = DX9::getClutDestFormat(palFormat);
int texturePixels = palFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
D3DFORMAT dstFmt = DX9::getClutDestFormat(clutFormat);
int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
DepalTextureDX9 *tex = new DepalTextureDX9();
@ -144,8 +142,8 @@ void DepalShaderCacheDX9::Decimate() {
}
}
LPDIRECT3DPIXELSHADER9 DepalShaderCacheDX9::GetDepalettizePixelShader(GEBufferFormat pixelFormat) {
u32 id = GenerateShaderID(pixelFormat);
LPDIRECT3DPIXELSHADER9 DepalShaderCacheDX9::GetDepalettizePixelShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
u32 id = GenerateShaderID(clutFormat, pixelFormat);
auto shader = cache_.find(id);
if (shader != cache_.end()) {

View file

@ -42,14 +42,14 @@ public:
~DepalShaderCacheDX9();
// This also uploads the palette and binds the correct texture.
LPDIRECT3DPIXELSHADER9 GetDepalettizePixelShader(GEBufferFormat pixelFormat);
LPDIRECT3DPIXELSHADER9 GetDepalettizePixelShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
LPDIRECT3DVERTEXSHADER9 GetDepalettizeVertexShader() { return vertexShader_; }
LPDIRECT3DTEXTURE9 GetClutTexture(const u32 clutHash, u32 *rawClut);
LPDIRECT3DTEXTURE9 GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut);
void Clear();
void Decimate();
private:
u32 GenerateShaderID(GEBufferFormat pixelFormat);
u32 GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
LPDIRECT3DVERTEXSHADER9 vertexShader_;
std::map<u32, DepalShaderDX9 *> cache_;

View file

@ -911,13 +911,15 @@ void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebu
framebuffer->usageFlags |= FB_USAGE_TEXTURE;
bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
if (useBufferedRendering) {
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
LPDIRECT3DPIXELSHADER9 pshader = nullptr;
if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) {
pshader = depalShaderCache_->GetDepalettizePixelShader(framebuffer->drawnFormat);
pshader = depalShaderCache_->GetDepalettizePixelShader(clutFormat, framebuffer->drawnFormat);
}
if (pshader) {
LPDIRECT3DTEXTURE9 clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBuf_);
LPDIRECT3DTEXTURE9 clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_);
FBO *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888);
fbo_bind_as_render_target(depalFBO);
@ -974,11 +976,10 @@ void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebu
dxstate.Restore();
dxstate.viewport.restore();
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;
TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(gstate.getClutPaletteFormat()), clutTotalColors, clutTotalColors, 1);
TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(clutFormat), clutTotalColors, clutTotalColors, 1);
gstate_c.textureFullAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_SIMPLE;
} else {

View file

@ -21,7 +21,6 @@
#include "Common/Log.h"
#include "Core/Reporting.h"
#include "DepalettizeShader.h"
#include "GPU/GPUState.h"
#include "GPU/GLES/TextureCache.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
@ -121,13 +120,12 @@ bool DepalShaderCache::CreateVertexShader() {
return !vertexShaderFailed_;
}
u32 DepalShaderCache::GenerateShaderID(GEBufferFormat pixelFormat) {
u32 DepalShaderCache::GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
return (gstate.clutformat & 0xFFFFFF) | (pixelFormat << 24);
}
GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) {
GEPaletteFormat palFormat = gstate.getClutPaletteFormat();
const u32 realClutID = clutID ^ palFormat;
GLuint DepalShaderCache::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) {
const u32 realClutID = clutID ^ clutFormat;
auto oldtex = texCache_.find(realClutID);
if (oldtex != texCache_.end()) {
@ -135,8 +133,8 @@ GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) {
return oldtex->second->texture;
}
GLuint dstFmt = getClutDestFormat(palFormat);
int texturePixels = palFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
GLuint dstFmt = getClutDestFormat(clutFormat);
int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
bool useBGRA = UseBGRA8888() && dstFmt == GL_UNSIGNED_BYTE;
@ -194,8 +192,8 @@ void DepalShaderCache::Decimate() {
}
}
DepalShader *DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) {
u32 id = GenerateShaderID(pixelFormat);
DepalShader *DepalShaderCache::GetDepalettizeShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
u32 id = GenerateShaderID(clutFormat, pixelFormat);
auto shader = cache_.find(id);
if (shader != cache_.end()) {

View file

@ -42,13 +42,13 @@ public:
~DepalShaderCache();
// This also uploads the palette and binds the correct texture.
DepalShader *GetDepalettizeShader(GEBufferFormat pixelFormat);
GLuint GetClutTexture(const u32 clutHash, u32 *rawClut);
DepalShader *GetDepalettizeShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
GLuint GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut);
void Clear();
void Decimate();
private:
u32 GenerateShaderID(GEBufferFormat pixelFormat);
u32 GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
bool CreateVertexShader();
bool useGL3_;

View file

@ -980,12 +980,13 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe
framebuffer->usageFlags |= FB_USAGE_TEXTURE;
bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
if (useBufferedRendering) {
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
DepalShader *depal = nullptr;
if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) {
depal = depalShaderCache_->GetDepalettizeShader(framebuffer->drawnFormat);
depal = depalShaderCache_->GetDepalettizeShader(clutFormat, framebuffer->drawnFormat);
}
if (depal) {
GLuint clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBuf_);
GLuint clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_);
FBO *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888);
fbo_bind_as_render_target(depalFBO);
static const float pos[12] = {
@ -1040,11 +1041,10 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe
glstate.Restore();
framebufferManager_->RebindFramebuffer();
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;
TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(gstate.getClutPaletteFormat()), clutTotalColors, clutTotalColors, 1);
TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(clutFormat), clutTotalColors, clutTotalColors, 1);
gstate_c.textureFullAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_SIMPLE;
} else {