From f78133f261f45dced11142cb546feba7a389d416 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Sun, 18 Jul 2010 00:18:31 +0000 Subject: [PATCH] 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 --- Source/Core/Common/Src/LinearDiskCache.cpp | 2 +- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 55 ++++++++---------- Source/Core/VideoCommon/Src/PixelShaderGen.h | 3 +- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 10 ++-- Source/Core/VideoCommon/Src/VertexShaderGen.h | 6 +- .../VideoCommon/Src/VertexShaderManager.cpp | 10 +--- Source/Core/VideoCommon/Src/VideoConfig.cpp | 8 +-- Source/Core/VideoCommon/Src/VideoConfig.h | 3 +- .../Plugins/Plugin_VideoDX11/Src/GfxState.h | 6 +- .../Src/VertexShaderCache.cpp | 16 ++--- .../Plugin_VideoDX9/Src/DlgSettings.cpp | 20 ++----- .../Plugins/Plugin_VideoDX9/Src/DlgSettings.h | 2 - .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 2 +- .../Plugin_VideoDX9/Src/TextureCache.cpp | 41 ++++++------- .../Plugin_VideoDX9/Src/TextureCache.h | 2 +- .../Plugin_VideoDX9/Src/TextureConverter.cpp | 5 +- .../Plugin_VideoDX9/Src/VertexManager.cpp | 1 - .../Plugin_VideoDX9/Src/VertexShaderCache.cpp | 4 +- .../Plugin_VideoOGL/Src/PixelShaderCache.cpp | 4 +- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 5 +- .../Plugin_VideoOGL/Src/TextureMngr.cpp | 58 ++++++++++++------- .../Plugins/Plugin_VideoOGL/Src/TextureMngr.h | 10 ++-- .../Plugin_VideoOGL/Src/VertexShaderCache.cpp | 4 +- 23 files changed, 128 insertions(+), 149 deletions(-) diff --git a/Source/Core/Common/Src/LinearDiskCache.cpp b/Source/Core/Common/Src/LinearDiskCache.cpp index efed2aefe5..f118b67ac1 100644 --- a/Source/Core/Common/Src/LinearDiskCache.cpp +++ b/Source/Core/Common/Src/LinearDiskCache.cpp @@ -22,7 +22,7 @@ static const char ID[4] = {'D', 'C', 'A', 'C'}; // Update this to the current SVN revision every time you change shader generation code. // We don't automatically get this from SVN_REV because that would mean regenerating the // shader cache for every revision, graphics-related or not, which is simply annoying. -const int version = 5820; +const int version = 5896; LinearDiskCache::LinearDiskCache() : file_(NULL), num_entries_(0) { diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 4fb871daf5..6cc3029ff2 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -342,6 +342,7 @@ static const char *swapColors = "rgba"; static char swapModeTable[4][5]; static char text[16384]; +static bool DepthTextureEnable; struct RegisterState { @@ -388,7 +389,7 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_T nIndirectStagesUsed |= 1 << bpmem.tevind[i].bt; } } - + DepthTextureEnable = bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable; // Declare samplers if (texture_mask && ApiType == API_OPENGL) { @@ -454,10 +455,10 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_T WRITE(p, "void main(\n"); if(ApiType != API_D3D11) - WRITE(p, " out float4 ocol0 : COLOR0,\n out float depth : DEPTH,\n in float4 rawpos : POSITION,\n"); + WRITE(p, " out float4 ocol0 : COLOR0,%s\n in float4 rawpos : POSITION,\n",DepthTextureEnable ? "\n out float depth : DEPTH," : ""); else - WRITE(p, " out float4 ocol0 : SV_Target,\n out float depth : SV_Depth,\n in float4 rawpos : SV_Position,\n"); - + WRITE(p, " out float4 ocol0 : SV_Target,%s\n in float4 rawpos : SV_Position,\n",DepthTextureEnable ? "\n out float depth : SV_Depth," : ""); + WRITE(p, " in float4 colors_0 : COLOR0,\n"); WRITE(p, " in float4 colors_1 : COLOR1"); @@ -477,7 +478,8 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_T } WRITE(p, " ) {\n"); - char* pmainstart = p; + char* pmainstart = p; + WRITE(p, " float4 c0 = "I_COLORS"[1], c1 = "I_COLORS"[2], c2 = "I_COLORS"[3], prev = float4(0.0f, 0.0f, 0.0f, 0.0f), textemp = float4(0.0f, 0.0f, 0.0f, 0.0f), rastemp = float4(0.0f, 0.0f, 0.0f, 0.0f), konsttemp = float4(0.0f, 0.0f, 0.0f, 0.0f);\n" " float3 comp16 = float3(1.0f, 255.0f, 0.0f), comp24 = float3(1.0f, 255.0f, 255.0f*255.0f);\n" @@ -561,20 +563,23 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_T // alpha test will always fail, so restart the shader and just make it an empty function p = pmainstart; WRITE(p, "ocol0 = 0;\n"); - WRITE(p, "depth = 1.f;\n"); + if(DepthTextureEnable) + WRITE(p, "depth = 1.f;\n"); WRITE(p, "discard;\n"); if(ApiType != API_D3D11) WRITE(p, "return;\n"); } else { - if (numTexgen >= 7) - WRITE(p, "float4 clipPos = float4(uv0.w, uv1.w, uv2.w, uv3.w);\n"); + if((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable) + { + if (numTexgen >= 7) + WRITE(p, "float4 clipPos = float4(uv0.w, uv1.w, uv2.w, uv3.w);\n"); + // the screen space depth value = far z + (clip z / clip w) * z range + WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n"); + } - // the screen space depth value = far z + (clip z / clip w) * z range - WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n"); - - if (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) + if (DepthTextureEnable) { // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... if (bpmem.ztex2.op == ZTEXTURE_ADD) @@ -586,8 +591,8 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_T WRITE(p, "zCoord = zCoord * (16777215.0f/16777216.0f);\n"); WRITE(p, "zCoord = frac(zCoord);\n"); WRITE(p, "zCoord = zCoord * (16777216.0f/16777215.0f);\n"); + WRITE(p, "depth = zCoord;\n"); } - WRITE(p, "depth = zCoord;\n"); if (dstAlphaEnable) WRITE(p, " ocol0 = float4(prev.rgb, "I_ALPHA"[0].a);\n"); @@ -954,7 +959,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask, API_TYPE ApiType) void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, u32 texture_mask, API_TYPE ApiType) { - if (texture_mask & (1< using std::stack; @@ -57,8 +59,8 @@ public: D3D11_RASTERIZER_DESC rastdesc; D3D11_DEPTH_STENCIL_DESC depthdesc; - float psconstants[116]; - float vsconstants[952]; + float psconstants[C_PENVCONST_END*4]; + float vsconstants[C_VENVCONST_END*4]; bool vscbufchanged; bool pscbufchanged; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp index 04f6f8764a..dbaf1f0cce 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp @@ -48,7 +48,7 @@ ID3D11InputLayout* VertexShaderCache::GetSimpleInputLayout() { return SimpleLayo ID3D11InputLayout* VertexShaderCache::GetClearInputLayout() { return ClearLayout; } // maps the constant numbers to float indices in the constant buffer -unsigned int vs_constant_offset_table[238]; +unsigned int vs_constant_offset_table[C_VENVCONST_END]; void SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { D3D::gfxstate->vsconstants[vs_constant_offset_table[const_number] ] = f1; @@ -164,14 +164,16 @@ void VertexShaderCache::Init() // these values are hardcoded, they depend on internal D3DCompile behavior // TODO: Do this with D3DReflect or something instead unsigned int k; - for (k = 0;k < 64;k++) vs_constant_offset_table[C_TRANSFORMMATRICES+k] = 312+4*k; - for (k = 0;k < 24;k++) vs_constant_offset_table[C_TEXMATRICES+k] = 216+4*k; - for (k = 0;k < 32;k++) vs_constant_offset_table[C_NORMALMATRICES+k] = 568+4*k; for (k = 0;k < 6;k++) vs_constant_offset_table[C_POSNORMALMATRIX+k] = 0+4*k; - for (k = 0;k < 64;k++) vs_constant_offset_table[C_POSTTRANSFORMMATRICES+k] = 696+4*k; - for (k = 0;k < 40;k++) vs_constant_offset_table[C_LIGHTS+k] = 56+4*k; - for (k = 0;k < 4;k++) vs_constant_offset_table[C_MATERIALS+k] = 40+4*k; for (k = 0;k < 4;k++) vs_constant_offset_table[C_PROJECTION+k] = 24+4*k; + for (k = 0;k < 4;k++) vs_constant_offset_table[C_MATERIALS+k] = 40+4*k; + for (k = 0;k < 40;k++) vs_constant_offset_table[C_LIGHTS+k] = 56+4*k; + for (k = 0;k < 24;k++) vs_constant_offset_table[C_TEXMATRICES+k] = 216+4*k; + for (k = 0;k < 64;k++) vs_constant_offset_table[C_TRANSFORMMATRICES+k] = 312+4*k; + for (k = 0;k < 32;k++) vs_constant_offset_table[C_NORMALMATRICES+k] = 568+4*k; + for (k = 0;k < 64;k++) vs_constant_offset_table[C_POSTTRANSFORMMATRICES+k] = 696+4*k; + for (k = 0;k < 4;k++) vs_constant_offset_table[C_DEPTHPARAMS+k] = 952+4*k; + if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX))) File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX)); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp b/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp index 6c751f1ad6..b8c59053de 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp @@ -59,8 +59,7 @@ BEGIN_EVENT_TABLE(GFXConfigDialogDX,wxDialog) EVT_CHECKBOX(ID_DISABLEFOG, GFXConfigDialogDX::AdvancedSettingsChanged) EVT_CHECKBOX(ID_OVERLAYFPS, GFXConfigDialogDX::AdvancedSettingsChanged) EVT_CHECKBOX(ID_ENABLEEFBCOPY, GFXConfigDialogDX::AdvancedSettingsChanged) - EVT_RADIOBUTTON(ID_EFBTORAM, GFXConfigDialogDX::AdvancedSettingsChanged) - EVT_CHECKBOX(ID_VERIFYTEXTUREMODIFICATIONS, GFXConfigDialogDX::AdvancedSettingsChanged) + EVT_RADIOBUTTON(ID_EFBTORAM, GFXConfigDialogDX::AdvancedSettingsChanged) EVT_RADIOBUTTON(ID_EFBTOTEX, GFXConfigDialogDX::AdvancedSettingsChanged) EVT_CHECKBOX(ID_ENABLEHOTKEY, GFXConfigDialogDX::AdvancedSettingsChanged) EVT_CHECKBOX(ID_WIREFRAME, GFXConfigDialogDX::AdvancedSettingsChanged) @@ -138,8 +137,7 @@ void GFXConfigDialogDX::InitializeGUIValues() m_OverlayFPS->SetValue(g_Config.bShowFPS); m_CopyEFB->SetValue(!g_Config.bEFBCopyDisable); - g_Config.bCopyEFBToTexture ? m_Radio_CopyEFBToGL->SetValue(true) : m_Radio_CopyEFBToRAM->SetValue(true); - m_VerifyTextureModification->SetValue(g_Config.bVerifyTextureModificationsByCPU); + g_Config.bCopyEFBToTexture ? m_Radio_CopyEFBToGL->SetValue(true) : m_Radio_CopyEFBToRAM->SetValue(true); m_EnableHotkeys->SetValue(g_Config.bOSDHotKey); m_WireFrame->SetValue(g_Config.bWireFrame); m_EnableXFB->SetValue(g_Config.bUseXFB); @@ -301,7 +299,6 @@ void GFXConfigDialogDX::CreateGUIControls() m_CopyEFB = new wxCheckBox( m_PageAdvanced, ID_ENABLEEFBCOPY, wxT("Enable EFB Copy"), wxDefaultPosition, wxDefaultSize, 0 ); m_EnableHotkeys = new wxCheckBox( m_PageAdvanced, ID_ENABLEHOTKEY, wxT("Enable Hotkey"), wxDefaultPosition, wxDefaultSize, 0 ); m_Radio_CopyEFBToRAM = new wxRadioButton( m_PageAdvanced, ID_EFBTORAM, wxT("To RAM (accuracy)"), wxDefaultPosition, wxDefaultSize, 0 ); - m_VerifyTextureModification = new wxCheckBox( m_PageAdvanced, ID_VERIFYTEXTUREMODIFICATIONS, wxT("Check for textures modified by the cpu"), wxDefaultPosition, wxDefaultSize, 0 ); m_Radio_CopyEFBToGL = new wxRadioButton( m_PageAdvanced, ID_EFBTOTEX, wxT("To Texture (performance, resolution)"), wxDefaultPosition, wxDefaultSize, 0 ); m_WireFrame = new wxCheckBox( m_PageAdvanced, ID_WIREFRAME, wxT("Enable Wireframe"), wxDefaultPosition, wxDefaultSize, 0 ); m_EnableRealXFB = new wxCheckBox( m_PageAdvanced, ID_ENABLEREALXFB, wxT("Enable Real XFB"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -334,12 +331,11 @@ void GFXConfigDialogDX::CreateGUIControls() sSettings->Add( m_CopyEFB, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxALL, 5 ); sSettings->Add( m_EnableHotkeys, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxEXPAND|wxLEFT, 20 ); sSettings->Add( m_Radio_CopyEFBToRAM, wxGBPosition( 2, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 10 ); - sSettings->Add( m_VerifyTextureModification, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP, 10 ); - sSettings->Add( m_Radio_CopyEFBToGL, wxGBPosition( 4, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP, 10 ); + sSettings->Add( m_Radio_CopyEFBToGL, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP, 10 ); sSettings->Add( m_WireFrame, wxGBPosition( 2, 1 ), wxGBSpan( 1, 1 ), wxEXPAND|wxLEFT, 20 ); - sSettings->Add( m_EnableRealXFB, wxGBPosition( 5, 1 ), wxGBSpan( 1, 1 ), wxEXPAND|wxLEFT, 20 ); - sSettings->Add( m_EnableXFB, wxGBPosition( 5, 0 ), wxGBSpan( 1, 1 ), wxALL, 5 ); - sSettings->Add( m_UseNativeMips, wxGBPosition( 6, 0 ), wxGBSpan( 1, 1 ), wxALL, 5 ); + sSettings->Add( m_EnableRealXFB, wxGBPosition( 4, 1 ), wxGBSpan( 1, 1 ), wxEXPAND|wxLEFT, 20 ); + sSettings->Add( m_EnableXFB, wxGBPosition( 4, 0 ), wxGBSpan( 1, 1 ), wxALL, 5 ); + sSettings->Add( m_UseNativeMips, wxGBPosition( 5, 0 ), wxGBSpan( 1, 1 ), wxALL, 5 ); sbSettings->Add( sSettings, 0, wxEXPAND, 5 ); sAdvanced->Add( sbSettings, 0, wxEXPAND|wxALL, 5 ); @@ -466,9 +462,6 @@ void GFXConfigDialogDX::AdvancedSettingsChanged(wxCommandEvent& event) break; case ID_EFBTORAM: g_Config.bCopyEFBToTexture = false; - case ID_VERIFYTEXTUREMODIFICATIONS: - g_Config.bVerifyTextureModificationsByCPU = m_VerifyTextureModification->IsChecked(); - break; case ID_EFBTOTEX: g_Config.bCopyEFBToTexture = true; break; @@ -532,7 +525,6 @@ void GFXConfigDialogDX::UpdateGUI() // Disable the Copy to options when EFBCopy is disabled m_Radio_CopyEFBToRAM->Enable(!g_Config.bEFBCopyDisable); - m_VerifyTextureModification->Enable(!g_Config.bEFBCopyDisable && !g_Config.bCopyEFBToTexture); m_Radio_CopyEFBToGL->Enable(!g_Config.bEFBCopyDisable); // Disable/Enable Safe Texture Cache options diff --git a/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.h b/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.h index 185a0edfec..dba28f09bf 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.h @@ -112,7 +112,6 @@ class GFXConfigDialogDX : public wxDialog wxCheckBox *m_OverlayFPS; wxCheckBox *m_CopyEFB; wxRadioButton *m_Radio_CopyEFBToRAM; - wxCheckBox *m_VerifyTextureModification; wxRadioButton *m_Radio_CopyEFBToGL; wxCheckBox *m_EnableHotkeys; wxCheckBox *m_WireFrame; @@ -150,7 +149,6 @@ class GFXConfigDialogDX : public wxDialog ID_OVERLAYFPS, ID_ENABLEEFBCOPY, ID_EFBTORAM, - ID_VERIFYTEXTUREMODIFICATIONS, ID_EFBTOTEX, ID_ENABLEHOTKEY, ID_WIREFRAME, diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index fbf6bb9e27..2be21a119a 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -266,7 +266,7 @@ void PixelShaderCache::Clear() iter->second.Destroy(); PixelShaders.clear(); - for (int i = 0; i < (C_COLORMATRIX + 16) * 4; i++) + for (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)); } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp index 4da1000df6..d52e04c85e 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp @@ -135,7 +135,7 @@ void TextureCache::Cleanup() if (frameCount > TEXTURE_KILL_THRESHOLD + iter->second.frameCount) { iter->second.Destroy(false); - iter = textures.erase(iter); + textures.erase(iter++); } else { @@ -160,7 +160,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width, u32 texID = address; u64 texHash; 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)) u32 FullFormat = (tex_format | (tlutfmt << 16)); @@ -196,9 +196,9 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, 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)) @@ -218,19 +218,19 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, 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) && FullFormat == entry.fmt/* && entry.MipLevels == maxlevel*/)) { entry.frameCount = frameCount; - entry.isDinamic = false; + entry.isDynamic = false; D3D::SetTexture(stage, entry.texture); return &entry; } @@ -239,11 +239,11 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, 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; + TextureisDynamic = (entry.isRenderTarget || entry.isDynamic) && !g_ActiveConfig.bCopyEFBToTexture; if (!entry.isRenderTarget && - ((!entry.isDinamic && width == entry.w && height==entry.h && FullFormat == entry.fmt /* && entry.MipLevels < maxlevel*/) - || (entry.isDinamic && entry.w == width && entry.h == height))) + ((!entry.isDynamic && width == entry.w && height==entry.h && FullFormat == entry.fmt /* && entry.MipLevels < maxlevel*/) + || (entry.isDynamic && entry.w == width && entry.h == height))) { skip_texture_create = true; } @@ -257,7 +257,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width, // Make an entry in the table TCacheEntry& entry = textures[texID]; - entry.isDinamic = TextureIsDinamic; + entry.isDynamic = TextureisDynamic; PC_TexFormat pcfmt = PC_TEX_FMT_NONE; if (g_ActiveConfig.bHiresTextures) @@ -313,7 +313,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, 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 { @@ -403,9 +403,6 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width, void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle &source_rect) { - int efb_w = source_rect.GetWidth(); - int efb_h = source_rect.GetHeight(); - int tex_w = (abs(source_rect.GetWidth()) >> bScaleByHalf); int tex_h = (abs(source_rect.GetHeight()) >> bScaleByHalf); //compensate the texture grow if supersampling is enabled to conserve memory usage @@ -420,14 +417,14 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo TexCache::iterator iter; LPDIRECT3DTEXTURE9 tex = NULL; iter = textures.find(address); - bool TextureIsDinamic = false; + bool TextureisDynamic = false; if (iter != textures.end()) { if ((iter->second.isRenderTarget && iter->second.Scaledw == Scaledtex_w && iter->second.Scaledh == Scaledtex_h) - || (iter->second.isDinamic && iter->second.w == tex_w && iter->second.h == tex_h)) + || (iter->second.isDynamic && iter->second.w == tex_w && iter->second.h == tex_h)) { tex = iter->second.texture; - TextureIsDinamic = iter->second.isDinamic; + TextureisDynamic = iter->second.isDynamic; iter->second.frameCount = frameCount; } else @@ -439,7 +436,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo textures.erase(iter); } } - if(TextureIsDinamic) + if(TextureisDynamic) { Scaledtex_w = tex_w; Scaledtex_h = tex_h; @@ -457,7 +454,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo entry.Scaledh = Scaledtex_h; entry.fmt = copyfmt; entry.isNonPow2 = true; - entry.isDinamic = false; + entry.isDynamic = false; D3D::dev->CreateTexture(Scaledtex_w, Scaledtex_h, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &entry.texture, 0); textures[address] = entry; tex = entry.texture; @@ -468,7 +465,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo // We have to run a pixel shader, for color conversion. Renderer::ResetAPIState(); // reset any game specific settings - if(!TextureIsDinamic || g_ActiveConfig.bCopyEFBToTexture) + if(!TextureisDynamic || g_ActiveConfig.bCopyEFBToTexture) { float colmat[16]= {0.0f}; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h index 3986a9723f..e9240240b1 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.h @@ -45,7 +45,7 @@ public: float scaleX, scaleY; // Hires texutres need this bool isRenderTarget; - bool isDinamic;// mofified from cpu + bool isDynamic;// mofified from cpu bool isNonPow2; TCacheEntry() diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp index 6100888618..bd59f72789 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureConverter.cpp @@ -450,10 +450,7 @@ u64 EncodeToRamFromTexture(u32 address,LPDIRECT3DTEXTURE9 source_texture,u32 Sou EncodeToRamUsingShader(texconv_shader, source_texture, scaledSource, dest_ptr, expandedWidth / samples, expandedHeight,readStride, true, bScaleByHalf > 0); TextureCache::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; } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index e648004864..cf4de8c8ca 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -243,7 +243,6 @@ void Flush() } } - u32 nonpow2tex = 0; for (int i = 0; i < 8; i++) { if (usedtextures & (1 << i)) { diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp index 60bd7b2f18..2f90b11f99 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp @@ -37,7 +37,7 @@ VertexShaderCache::VSCache VertexShaderCache::vshaders; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; -static float GC_ALIGNED16(lastVSconstants[C_FOGPARAMS + 8][4]); +static float GC_ALIGNED16(lastVSconstants[C_VENVCONST_END][4]); #define MAX_SSAA_SHADERS 3 static LPDIRECT3DVERTEXSHADER9 SimpleVertexShader[MAX_SSAA_SHADERS]; @@ -218,7 +218,7 @@ void VertexShaderCache::Clear() iter->second.Destroy(); vshaders.clear(); - 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)); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 4dfda91fd0..27aaf725d5 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -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)); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 0cb1d74c42..3f25a95972 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -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; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp index 3034b0f15d..d1700a272f 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp @@ -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 diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h index b731a9d985..05c41007e7 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.h @@ -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; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index 08aecd084c..8c34d3377b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -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));