From d032f3fd799c7b144c8ab78a97cbd1c0238a6f02 Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Thu, 4 Apr 2013 12:53:06 -0300 Subject: [PATCH] Fix for the hang after close caused by my previews perf queries commit. Sorry for that. fix issue 6205 --- .../Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp | 21 +++++++++++++------ .../Plugins/Plugin_VideoDX9/Src/PerfQuery.h | 5 +++-- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 4 ++-- Source/Plugins/Plugin_VideoDX9/Src/main.cpp | 6 ++++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp index cea140031f..8a1d5c59a9 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.cpp @@ -8,6 +8,16 @@ namespace DX9 { PerfQuery::PerfQuery() : m_query_read_pos() , m_query_count() +{ + +} + +PerfQuery::~PerfQuery() +{ + +} + +void PerfQuery::CreateDeviceObjects() { for (int i = 0; i != ARRAYSIZE(m_query_buffer); ++i) { @@ -15,8 +25,7 @@ PerfQuery::PerfQuery() } ResetQuery(); } - -PerfQuery::~PerfQuery() +void PerfQuery::DestroyDeviceObjects() { for (int i = 0; i != ARRAYSIZE(m_query_buffer); ++i) { @@ -91,7 +100,7 @@ void PerfQuery::FlushOne() { auto& entry = m_query_buffer[m_query_read_pos]; - UINT64 result = 0; + DWORD result = 0; HRESULT hr = S_FALSE; while (hr != S_OK && hr != D3DERR_DEVICELOST) { @@ -100,7 +109,7 @@ void PerfQuery::FlushOne() } // NOTE: Reported pixel metrics should be referenced to native resolution - m_results[entry.query_type] += (u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight(); + m_results[entry.query_type] += (u32)((u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight()); m_query_read_pos = (m_query_read_pos + 1) % ARRAYSIZE(m_query_buffer); --m_query_count; @@ -119,13 +128,13 @@ void PerfQuery::WeakFlush() { auto& entry = m_query_buffer[m_query_read_pos]; - UINT64 result = 0; + DWORD result = 0; HRESULT hr = entry.query->GetData(&result, sizeof(result), 0); if (hr == S_OK) { // NOTE: Reported pixel metrics should be referenced to native resolution - m_results[entry.query_type] += (u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight(); + m_results[entry.query_type] += (u32)((u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight()); m_query_read_pos = (m_query_read_pos + 1) % ARRAYSIZE(m_query_buffer); --m_query_count; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h b/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h index 56f964f7ed..9b8f637655 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/PerfQuery.h @@ -17,6 +17,8 @@ public: u32 GetQueryResult(PerfQueryType type); void FlushResults(); bool IsFlushed() const; + void CreateDeviceObjects(); + void DestroyDeviceObjects(); private: struct ActiveQuery @@ -25,8 +27,7 @@ private: PerfQueryGroup query_type; }; - void WeakFlush(); - + void WeakFlush(); // Only use when non-empty void FlushOne(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 2838895d4c..147ad0c35d 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -88,7 +88,7 @@ void SetupDeviceObjects() VertexShaderCache::Init(); PixelShaderCache::Init(); g_vertex_manager->CreateDeviceObjects(); - g_perf_query = new PerfQuery; + ((PerfQuery*)g_perf_query)->CreateDeviceObjects(); // Texture cache will recreate themselves over time. } @@ -101,7 +101,7 @@ void TeardownDeviceObjects() D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface()); D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface()); delete g_framebuffer_manager; - delete g_perf_query; + ((PerfQuery*)g_perf_query)->DestroyDeviceObjects(); D3D::font.Shutdown(); TextureCache::Invalidate(); VertexLoaderManager::Shutdown(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index df8f939504..f52ad1e40d 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -57,6 +57,7 @@ #include "ConfigManager.h" #include "VideoBackend.h" +#include "PerfQuery.h" namespace DX9 { @@ -176,8 +177,9 @@ void VideoBackend::Video_Prepare() // internal interfaces g_vertex_manager = new VertexManager; + g_perf_query = new PerfQuery; g_renderer = new Renderer; - g_texture_cache = new TextureCache; + g_texture_cache = new TextureCache; // VideoCommon BPInit(); Fifo_Init(); @@ -215,9 +217,9 @@ void VideoBackend::Shutdown() // internal interfaces PixelShaderCache::Shutdown(); VertexShaderCache::Shutdown(); - delete g_perf_query; delete g_texture_cache; delete g_renderer; + delete g_perf_query; delete g_vertex_manager; g_renderer = NULL; g_texture_cache = NULL;