big changes here:

- Eliminate the useless check for cpu modifications option from efb to ram as it must be enabled always
- use constant names in dx11 for buffer length calculation instead to simplify code reading
- implemented scaled efb copy in opengl, still bugy in some games, the option is not in the gui but will add it when it works perfect
- Change the depth calculation behavior:
if the game use z textures is exactly the same as before.
if the game do not use z texture calculate z values in the vertex shader. the advantage id this approach is that early z culling is applied,
improving fill rate. this mus speed up things, even with ssaa and msaa enabled.
please test for regression and enjoy.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5896 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado
2010-07-18 00:18:31 +00:00
parent 4b1a3152b6
commit f78133f261
23 changed files with 128 additions and 149 deletions

View File

@ -45,7 +45,7 @@ GLuint PixelShaderCache::CurrentShader;
bool PixelShaderCache::ShaderEnabled;
static FRAGMENTSHADER* pShaderLast = NULL;
static float lastPSconstants[C_COLORMATRIX+16][4];
static float lastPSconstants[C_PENVCONST_END][4];
void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
@ -89,7 +89,7 @@ void PixelShaderCache::Init()
CurrentShader = 0;
GL_REPORT_ERRORD();
for (unsigned int i = 0; i < (C_COLORMATRIX+16) * 4; i++)
for (unsigned int i = 0; i < (C_PENVCONST_END) * 4; i++)
lastPSconstants[i/4][i%4] = -100000000.0f;
memset(&last_pixel_shader_uid, 0xFF, sizeof(last_pixel_shader_uid));

View File

@ -383,10 +383,7 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture,float MValueX,float
EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight, readStride, true, bScaleByHalf > 0);
TextureMngr::MakeRangeDynamic(address,size_in_bytes);
u64 Hashvalue = 0;
if(g_ActiveConfig.bVerifyTextureModificationsByCPU)
{
Hashvalue = TexDecoder_GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples);
}
Hashvalue = TexDecoder_GetHash64(dest_ptr,size_in_bytes,g_ActiveConfig.iSafeTextureCache_ColorSamples);
return Hashvalue;
}

View File

@ -285,7 +285,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
u32 texID = address;
u64 texHash = 0;
u32 FullFormat = tex_format;
bool TextureIsDinamic = false;
bool TextureisDynamic = false;
if ((tex_format == GX_TF_C4) || (tex_format == GX_TF_C8) || (tex_format == GX_TF_C14X2))
FullFormat = (tex_format | (tlutfmt << 16));
if (g_ActiveConfig.bSafeTextureCache || g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures)
@ -320,9 +320,9 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
if (!g_ActiveConfig.bSafeTextureCache)
{
if(entry.isRenderTarget || entry.isDinamic)
if(entry.isRenderTarget || entry.isDynamic)
{
if(!g_ActiveConfig.bCopyEFBToTexture && g_ActiveConfig.bVerifyTextureModificationsByCPU)
if(!g_ActiveConfig.bCopyEFBToTexture)
{
hash_value = TexDecoder_GetHash64(ptr,TexDecoder_GetTextureSizeInBytes(expandedWidth, expandedHeight, tex_format),g_ActiveConfig.iSafeTextureCache_ColorSamples);
if ((tex_format == GX_TF_C4) || (tex_format == GX_TF_C8) || (tex_format == GX_TF_C14X2))
@ -342,16 +342,16 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
}
else
{
if(entry.isRenderTarget || entry.isDinamic)
if(entry.isRenderTarget || entry.isDynamic)
{
if(g_ActiveConfig.bCopyEFBToTexture || !g_ActiveConfig.bVerifyTextureModificationsByCPU)
if(g_ActiveConfig.bCopyEFBToTexture)
{
hash_value = 0;
}
}
}
if (((entry.isRenderTarget || entry.isDinamic) && hash_value == entry.hash && address == entry.addr)
if (((entry.isRenderTarget || entry.isDynamic) && hash_value == entry.hash && address == entry.addr)
|| ((address == entry.addr) && (hash_value == entry.hash) && ((int) FullFormat == entry.fmt) && entry.MipLevels >= maxlevel))
{
entry.frameCount = frameCount;
@ -359,7 +359,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
glBindTexture(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D, entry.texture);
GL_REPORT_ERRORD();
entry.SetTextureParameters(tm0,tm1);
entry.isDinamic = false;
entry.isDynamic = false;
return &entry;
}
else
@ -367,11 +367,11 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
// Let's reload the new texture data into the same texture,
// instead of destroying it and having to create a new one.
// Might speed up movie playback very, very slightly.
TextureIsDinamic = (entry.isRenderTarget || entry.isDinamic) && !g_ActiveConfig.bCopyEFBToTexture;
if (!entry.isRenderTarget && ((!entry.isDinamic &&
TextureisDynamic = (entry.isRenderTarget || entry.isDynamic) && !g_ActiveConfig.bCopyEFBToTexture;
if (!entry.isRenderTarget && ((!entry.isDynamic &&
width == entry.w && height == entry.h &&
(int)FullFormat == entry.fmt) ||
(entry.isDinamic &&
(entry.isDynamic &&
entry.w == width && entry.h == height)))
{
glBindTexture(entry.isRectangle ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D, entry.texture);
@ -389,7 +389,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
//Make an entry in the table
TCacheEntry& entry = textures[texID];
entry.isDinamic = TextureIsDinamic;
entry.isDynamic = TextureisDynamic;
PC_TexFormat dfmt = PC_TEX_FMT_NONE;
if (g_ActiveConfig.bHiresTextures)
@ -416,7 +416,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
entry.oldpixel = ((u32 *)ptr)[0];
if (g_ActiveConfig.bSafeTextureCache || entry.isDinamic)
if (g_ActiveConfig.bSafeTextureCache || entry.isDynamic)
entry.hash = hash_value;
else
{
@ -574,6 +574,8 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
entry.frameCount = frameCount;
entry.w = width;
entry.h = height;
entry.Scaledw = width;
entry.Scaledh = height;
entry.fmt = FullFormat;
entry.SetTextureParameters(tm0,tm1);
if (g_ActiveConfig.bDumpTextures) // dump texture to file
@ -731,6 +733,12 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
int w = (abs(source_rect.GetWidth()) >> bScaleByHalf);
int h = (abs(source_rect.GetHeight()) >> bScaleByHalf);
float xScale = Renderer::GetTargetScaleX();
float yScale = Renderer::GetTargetScaleY();
int Scaledtex_w = (g_ActiveConfig.bCopyEFBScaled)?((int)(xScale * w)) : w;
int Scaledtex_h = (g_ActiveConfig.bCopyEFBScaled)?((int)(yScale * h)) : h;
GLenum gl_format = GL_RGBA;
GLenum gl_iformat = 4;
GLenum gl_type = GL_UNSIGNED_BYTE;
@ -743,16 +751,17 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
glGenTextures(1, (GLuint *)&entry.texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture);
GL_REPORT_ERRORD();
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, gl_iformat, w, h, 0, gl_format, gl_type, NULL);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, gl_iformat, Scaledtex_w, Scaledtex_h, 0, gl_format, gl_type, NULL);
GL_REPORT_ERRORD();
entry.isRenderTarget = true;
entry.isDinamic = false;
entry.isDynamic = false;
}
else
{
_assert_(entry.texture);
GL_REPORT_ERRORD();
if (entry.w == w && entry.h == h && entry.isRectangle)
if (((!entry.isDynamic && entry.Scaledw == Scaledtex_w && entry.Scaledh == Scaledtex_h)
|| (entry.isDynamic && entry.w == w && entry.h == h)) && entry.isRectangle)
{
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture);
// for some reason mario sunshine errors here...
@ -760,13 +769,18 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
GL_REPORT_ERRORD();
} else {
// Delete existing texture.
if(entry.isDynamic)
{
Scaledtex_h = h;
Scaledtex_w = w;
}
glDeleteTextures(1,(GLuint *)&entry.texture);
glGenTextures(1, (GLuint *)&entry.texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, gl_iformat, w, h, 0, gl_format, gl_type, NULL);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, gl_iformat, Scaledtex_w, Scaledtex_h, 0, gl_format, gl_type, NULL);
GL_REPORT_ERRORD();
entry.isRenderTarget = true;
entry.isDinamic = false;
entry.isRenderTarget = !entry.isDynamic;
}
}
@ -786,7 +800,11 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
entry.w = w;
entry.h = h;
entry.Scaledw = Scaledtex_w;
entry.Scaledh = Scaledtex_h;
entry.isRectangle = true;
entry.scaleX = g_ActiveConfig.bCopyEFBScaled ? xScale : 1.0f;
entry.scaleY = g_ActiveConfig.bCopyEFBScaled ? yScale : 1.0f;
entry.fmt = copyfmt;
// Make sure to resolve anything we need to read from.
@ -796,7 +814,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
// We have to run a pixel shader, for color conversion.
Renderer::ResetAPIState(); // reset any game specific settings
if(!entry.isDinamic || g_ActiveConfig.bCopyEFBToTexture)
if(!entry.isDynamic || g_ActiveConfig.bCopyEFBToTexture)
{
if (s_TempFramebuffer == 0)
glGenFramebuffersEXT(1, (GLuint *)&s_TempFramebuffer);
@ -812,7 +830,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, read_texture);
glViewport(0, 0, w, h);
glViewport(0, 0, Scaledtex_w, Scaledtex_h);
PixelShaderCache::SetCurrentShader(bFromZBuffer ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
PixelShaderManager::SetColorMatrix(colmat, fConstAdd); // set transformation

View File

@ -30,8 +30,8 @@ public:
struct TCacheEntry
{
TCacheEntry() : texture(0), addr(0), size_in_bytes(0), hash(0),
w(0), h(0), MipLevels(0), scaleX(1.0f), scaleY(1.0f),
isRenderTarget(false), isDinamic(false), isRectangle(true),
w(0), h(0), MipLevels(0),Scaledw(0), Scaledh(0), scaleX(1.0f), scaleY(1.0f),
isRenderTarget(false), isDynamic(false), isRectangle(true),
bHaveMipMaps(false) { mode.hex = 0xFCFCFCFC; }
GLuint texture;
@ -42,15 +42,15 @@ public:
u32 oldpixel; // used for simple cleanup
TexMode0 mode; // current filter and clamp modes that texture is set to
TexMode1 mode1; // current filter and clamp modes that texture is set to
int frameCount;
int w, h, fmt,MipLevels;
int Scaledw, Scaledh;
float scaleX, scaleY; // Hires texutres need this
bool isRenderTarget; // if render texture, then rendertex is filled with the direct copy of the render target
// later conversions would have to convert properly from rendertexfmt to texfmt
bool isDinamic; // modified from cpu
bool isDynamic; // modified from cpu
bool isRectangle; // if nonpow2, use GL_TEXTURE_2D, else GL_TEXTURE_RECTANGLE_NV
bool bHaveMipMaps;

View File

@ -44,7 +44,7 @@ bool VertexShaderCache::ShaderEnabled;
static VERTEXSHADER *pShaderLast = NULL;
static int s_nMaxVertexInstructions;
static float GC_ALIGNED16(lastVSconstants[C_FOGPARAMS+8][4]);
static float GC_ALIGNED16(lastVSconstants[C_VENVCONST_END][4]);
void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
@ -105,7 +105,7 @@ void VertexShaderCache::Init()
glEnable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled = true;
CurrentShader = 0;
for (int i = 0; i < (C_FOGPARAMS + 8) * 4; i++)
for (int i = 0; i < (C_VENVCONST_END * 4); i++)
lastVSconstants[i / 4][i % 4] = -100000000.0f;
memset(&last_vertex_shader_uid, 0xFF, sizeof(last_vertex_shader_uid));