D3D9: Fix issue where the shader caches were lost whenever the render window was resized. Add some error logging to LinearDiskCache. + some minor cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5747 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2010-06-19 16:22:24 +00:00
parent 8c6ae1f6f4
commit ccbc1feb0b
12 changed files with 43 additions and 30 deletions

View File

@ -46,6 +46,11 @@ bool LinearDiskCache::ValidateHeader() {
}
int LinearDiskCache::OpenAndRead(const char *filename, LinearDiskCacheReader *reader) {
if (file_)
{
ERROR_LOG(VIDEO, "LinearDiskCache trying to open an alredy opened cache");
return 0;
}
int items_read_count = 0;
file_ = fopen(filename, "rb");
int file_size = 0;
@ -143,11 +148,25 @@ void LinearDiskCache::Append(
}
void LinearDiskCache::Sync() {
fflush(file_);
if (file_)
{
fflush(file_);
}
else
{
ERROR_LOG(VIDEO, "LinearDiskCache trying to sync closed cache");
}
}
void LinearDiskCache::Close() {
fclose(file_);
file_ = 0;
num_entries_ = 0;
if (file_)
{
fclose(file_);
file_ = 0;
num_entries_ = 0;
}
else
{
ERROR_LOG(VIDEO, "LinearDiskCache trying to close an alredy closed cache");
}
}

View File

@ -49,8 +49,6 @@ public:
static void ResetAPIState();
static void RestoreAPIState();
static void ReinitView();
static void SetColorMask();
static void SetBlendMode(bool forceUpdate);
static bool SetScissorRect();

View File

@ -333,12 +333,10 @@ void GFXDebuggerDX9::OnClearTextureCacheButton(wxCommandEvent& event)
void GFXDebuggerDX9::OnClearVertexShaderCacheButton(wxCommandEvent& event)
{
VertexShaderCache::Clear();
}
void GFXDebuggerDX9::OnClearPixelShaderCacheButton(wxCommandEvent& event)
{
PixelShaderCache::Clear();
}
void UpdateFPSDisplay(const char *text);

View File

@ -297,8 +297,8 @@ void GFXConfigDialogDX::CreateGUIControls()
m_OverlayFPS = new wxCheckBox( m_PageAdvanced, ID_OVERLAYFPS, wxT("Overlay FPS Counter"), wxDefaultPosition, wxDefaultSize, 0 );
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"), wxDefaultPosition, wxDefaultSize, 0 );
m_Radio_CopyEFBToGL = new wxRadioButton( m_PageAdvanced, ID_EFBTOTEX, wxT("To Texture"), wxDefaultPosition, wxDefaultSize, 0 );
m_Radio_CopyEFBToRAM = new wxRadioButton( m_PageAdvanced, ID_EFBTORAM, wxT("To RAM (accuracy)"), 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 );
m_EnableXFB = new wxCheckBox( m_PageAdvanced, ID_ENABLEXFB, wxT("Enable XFB"), wxDefaultPosition, wxDefaultSize, 0 );

View File

@ -258,6 +258,9 @@ void PixelShaderCache::Init()
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
SETSTAT(stats.numPixelShadersCreated, 0);
SETSTAT(stats.numPixelShadersAlive, 0);
char cache_filename[MAX_PATH];
sprintf(cache_filename, "%sdx9-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX), globals->unique_id);
PixelShaderCacheInserter inserter;

View File

@ -54,11 +54,10 @@ private:
static PSCache PixelShaders;
static const PSCacheEntry *last_entry;
static void Clear();
public:
static void Init();
static void Clear();
static void Shutdown();
static bool SetShader(bool dstAlpha);
static bool InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate);

View File

@ -225,8 +225,12 @@ void SetupDeviceObjects()
VertexShaderManager::Dirty();
PixelShaderManager::Dirty();
TextureConverter::Init();
// Tex and shader caches will recreate themselves over time.
// To avoid shader compilation stutters, read back all shaders from cache.
VertexShaderCache::Init();
PixelShaderCache::Init();
// Texture cache will recreate themselves over time.
}
// Kill off all POOL_DEFAULT device objects.
@ -241,8 +245,8 @@ void TeardownDeviceObjects()
D3D::font.Shutdown();
TextureCache::Invalidate(false);
VertexLoaderManager::Shutdown();
VertexShaderCache::Clear();
PixelShaderCache::Clear();
VertexShaderCache::Shutdown();
PixelShaderCache::Shutdown();
TextureConverter::Shutdown();
}
@ -499,7 +503,6 @@ void CheckForResize()
{
Sleep(10);
}
if (EmuWindow::GetParentWnd())
{

View File

@ -214,6 +214,9 @@ void VertexShaderCache::Init()
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
SETSTAT(stats.numVertexShadersCreated, 0);
SETSTAT(stats.numVertexShadersAlive, 0);
char cache_filename[MAX_PATH];
sprintf(cache_filename, "%sdx9-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX), globals->unique_id);
VertexShaderCacheInserter inserter;
@ -234,7 +237,7 @@ void VertexShaderCache::Clear()
void VertexShaderCache::Shutdown()
{
for (int i = 0; i<3;i++)
for (int i = 0; i < 3; i++)
{
if (SimpleVertexShader[i])
SimpleVertexShader[i]->Release();
@ -245,7 +248,6 @@ void VertexShaderCache::Shutdown()
ClearVertexShader->Release();
ClearVertexShader = NULL;
Clear();
g_vs_disk_cache.Sync();
g_vs_disk_cache.Close();

View File

@ -49,10 +49,10 @@ private:
static VSCache vshaders;
static const VSCacheEntry *last_entry;
static void Clear();
public:
static void Init();
static void Clear();
static void Shutdown();
static bool SetShader(u32 components);
static LPDIRECT3DVERTEXSHADER9 GetSimpleVertexShader(int level);

View File

@ -287,9 +287,7 @@ void Video_Prepare()
Fifo_Init();
VertexLoaderManager::Init();
OpcodeDecoder_Init();
VertexShaderCache::Init();
VertexShaderManager::Init();
PixelShaderCache::Init();
PixelShaderManager::Init();
CommandProcessor::Init();
PixelEngine::Init();
@ -307,9 +305,7 @@ void Shutdown()
CommandProcessor::Shutdown();
VertexManager::Shutdown();
VertexLoaderManager::Shutdown();
VertexShaderCache::Shutdown();
VertexShaderManager::Shutdown();
PixelShaderCache::Shutdown();
PixelShaderManager::Shutdown();
TextureCache::Shutdown();
OpcodeDecoder_Shutdown();

View File

@ -448,8 +448,8 @@ void GFXConfigDialogOGL::CreateGUIControls()
m_StaticBox_EFB = new wxStaticBox(m_PageAdvanced, ID_STATICBOX_EFB, wxT("EFB Copy"));
m_CheckBox_DisableCopyEFB = new wxCheckBox(m_PageAdvanced, ID_CHECKBOX_DISABLECOPYEFB, wxT("Disable"));
m_Radio_CopyEFBToRAM = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTORAM, wxT("Copy EFB to system RAM (real)"));
m_Radio_CopyEFBToGL = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTOGL, wxT("Copy EFB to GL texture (hack)"));
m_Radio_CopyEFBToRAM = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTORAM, wxT("To RAM (accuracy)"));
m_Radio_CopyEFBToGL = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTOGL, wxT("To GL texture (performance)"));
// Utility
sbUtilities = new wxStaticBoxSizer(wxVERTICAL, m_PageAdvanced, wxT("Utilities"));

View File

@ -571,11 +571,6 @@ void Renderer::ResetAPIState()
void UpdateViewport();
void Renderer::ReinitView()
{
}
void Renderer::RestoreAPIState()
{
// Gets us back into a more game-like state.