From e5318d262428bda1a7c5c80eae117981384a7fe5 Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 3 Feb 2014 16:56:17 +0100 Subject: [PATCH 1/7] move shared parts from VertexManager::vFlush into VideoCommon --- Source/Core/VideoBackends/D3D/VertexManager.cpp | 7 +------ Source/Core/VideoBackends/D3D/VertexManager.h | 2 +- Source/Core/VideoBackends/OGL/VertexManager.cpp | 7 +------ Source/Core/VideoBackends/OGL/VertexManager.h | 2 +- Source/Core/VideoCommon/VertexManagerBase.cpp | 8 +++++++- Source/Core/VideoCommon/VertexManagerBase.h | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/VertexManager.cpp b/Source/Core/VideoBackends/D3D/VertexManager.cpp index f8274ee283..f7de0c63cb 100644 --- a/Source/Core/VideoBackends/D3D/VertexManager.cpp +++ b/Source/Core/VideoBackends/D3D/VertexManager.cpp @@ -197,11 +197,8 @@ void VertexManager::Draw(UINT stride) } } -void VertexManager::vFlush() +void VertexManager::vFlush(bool useDstAlpha) { - bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && - bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; - if (!PixelShaderCache::SetShader( useDstAlpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, g_nativeVertexFmt->m_components)) @@ -223,8 +220,6 @@ void VertexManager::vFlush() Draw(stride); g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); - GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); - g_renderer->RestoreState(); } diff --git a/Source/Core/VideoBackends/D3D/VertexManager.h b/Source/Core/VideoBackends/D3D/VertexManager.h index db8be6de62..fea814bac2 100644 --- a/Source/Core/VideoBackends/D3D/VertexManager.h +++ b/Source/Core/VideoBackends/D3D/VertexManager.h @@ -30,7 +30,7 @@ private: void PrepareDrawBuffers(); void Draw(u32 stride); // temp - void vFlush(); + void vFlush(bool useDstAlpha); u32 m_vertex_buffer_cursor; u32 m_vertex_draw_offset; diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp index aed97e2ebd..f0e55ee86d 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.cpp +++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp @@ -25,7 +25,6 @@ #include "VertexManager.h" #include "IndexGenerator.h" #include "FileUtil.h" -#include "Debugger.h" #include "StreamBuffer.h" #include "PerfQueryBase.h" #include "Render.h" @@ -131,7 +130,7 @@ void VertexManager::Draw(u32 stride) INCSTAT(stats.thisFrame.numIndexedDrawCalls); } -void VertexManager::vFlush() +void VertexManager::vFlush(bool useDstAlpha) { GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)g_nativeVertexFmt; u32 stride = nativeVertexFmt->GetVertexStride(); @@ -144,9 +143,6 @@ void VertexManager::vFlush() PrepareDrawBuffers(stride); GL_REPORT_ERRORD(); - bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate - && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; - // Makes sure we can actually do Dual source blending bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend; @@ -200,7 +196,6 @@ void VertexManager::vFlush() if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract) glEnable(GL_BLEND); } - GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); #if defined(_DEBUG) || defined(DEBUGFAST) if (g_ActiveConfig.iLog & CONF_SAVESHADERS) diff --git a/Source/Core/VideoBackends/OGL/VertexManager.h b/Source/Core/VideoBackends/OGL/VertexManager.h index db0573e8f6..ded0ff2796 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.h +++ b/Source/Core/VideoBackends/OGL/VertexManager.h @@ -43,7 +43,7 @@ protected: virtual void ResetBuffer(u32 stride); private: void Draw(u32 stride); - void vFlush() override; + void vFlush(bool useDstAlpha) override; void PrepareDrawBuffers(u32 stride); NativeVertexFormat *m_CurrentVertexFmt; }; diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index c4980ae190..cd2eec39ce 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -11,6 +11,7 @@ #include "RenderBase.h" #include "BPStructs.h" #include "XFMemory.h" +#include "Debugger.h" #include "VertexManagerBase.h" #include "MainBase.h" @@ -216,8 +217,13 @@ void VertexManager::Flush() VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); + bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate + && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; + // TODO: need to merge more stuff into VideoCommon - g_vertex_manager->vFlush(); + g_vertex_manager->vFlush(useDstAlpha); + + GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); IsFlushed = true; } diff --git a/Source/Core/VideoCommon/VertexManagerBase.h b/Source/Core/VideoCommon/VertexManagerBase.h index 6854bc5b73..997cf308d1 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.h +++ b/Source/Core/VideoCommon/VertexManagerBase.h @@ -58,7 +58,7 @@ private: //virtual void Draw(u32 stride, bool alphapass) = 0; // temp - virtual void vFlush() = 0; + virtual void vFlush(bool useDstAlpha) = 0; }; extern VertexManager *g_vertex_manager; From 3cd6918dec654688eb1a85fd1e80a390bf703a62 Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 3 Feb 2014 16:59:23 +0100 Subject: [PATCH 2/7] fix ogl video config crash This will happen when playing on any other backend than ogl which have a non-trival GLInterface::GetMode() method. --- Source/Core/VideoBackends/OGL/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index ba7f1a0689..184b56724d 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -97,7 +97,7 @@ std::string VideoBackend::GetName() std::string VideoBackend::GetDisplayName() { - if (g_renderer && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) + if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) return "OpenGLES"; else return "OpenGL"; From 5a660c27bc0188727c3c56f957938eda87cd89da Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 4 Feb 2014 10:45:38 +0100 Subject: [PATCH 3/7] rename UpdateViewport to SetViewport like all others setters in RenderBase.h --- Source/Core/VideoBackends/D3D/Render.cpp | 7 +++---- Source/Core/VideoBackends/D3D/Render.h | 3 +-- Source/Core/VideoBackends/OGL/Render.cpp | 5 ++--- Source/Core/VideoBackends/OGL/Render.h | 3 +-- Source/Core/VideoCommon/RenderBase.cpp | 4 ++-- Source/Core/VideoCommon/RenderBase.h | 6 +++--- Source/Core/VideoCommon/VertexShaderManager.cpp | 5 ++--- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 1c1955aea6..c46b44c07d 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -476,8 +476,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) } -// Called from VertexShaderManager -void Renderer::UpdateViewport() +void Renderer::SetViewport() { // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // [0] = width/2 @@ -1018,7 +1017,7 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r RestoreAPIState(); D3D::BeginFrame(); D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV()); - UpdateViewport(); + SetViewport(); Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB)); XFBWrited = false; @@ -1038,7 +1037,7 @@ void Renderer::RestoreAPIState() D3D::stateman->PopBlendState(); D3D::stateman->PopDepthState(); D3D::stateman->PopRasterizerState(); - UpdateViewport(); + SetViewport(); BPFunctions::SetScissor(); } diff --git a/Source/Core/VideoBackends/D3D/Render.h b/Source/Core/VideoBackends/D3D/Render.h index f391e4b47d..11b902c93e 100644 --- a/Source/Core/VideoBackends/D3D/Render.h +++ b/Source/Core/VideoBackends/D3D/Render.h @@ -21,6 +21,7 @@ public: void SetLineWidth(); void SetSamplerState(int stage,int texindex); void SetInterlacingMode(); + void SetViewport(); // TODO: Fix confusing names (see ResetAPIState and RestoreAPIState) void ApplyState(bool bUseDstAlpha); @@ -44,8 +45,6 @@ public: void ReinterpretPixelData(unsigned int convtype); - void UpdateViewport(); - bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); static bool CheckForResize(); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 6d4d73da38..3d22168300 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1078,8 +1078,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) return 0; } -// Called from VertexShaderManager -void Renderer::UpdateViewport() +void Renderer::SetViewport() { // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // [0] = width/2 @@ -1651,7 +1650,7 @@ void Renderer::RestoreAPIState() SetDepthMode(); SetBlendMode(true); SetLogicOpMode(); - UpdateViewport(); + SetViewport(); if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) glPolygonMode(GL_FRONT_AND_BACK, g_ActiveConfig.bWireFrame ? GL_LINE : GL_FILL); diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index feaad32aa1..8f3e37ef1c 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -54,6 +54,7 @@ public: void SetLineWidth() override; void SetSamplerState(int stage,int texindex) override; void SetInterlacingMode() override; + void SetViewport() override; // TODO: Implement and use these void ApplyState(bool bUseDstAlpha) override {} @@ -76,8 +77,6 @@ public: void ReinterpretPixelData(unsigned int convtype) override; - void UpdateViewport() override; - bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); private: diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 7f046e53a3..836a0ec03d 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -509,8 +509,8 @@ void Renderer::RecordVideoMemory() FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFRegisters) / 4); } -void UpdateViewport() +void SetViewport() { if (xfregs.viewport.wd != 0 && xfregs.viewport.ht != 0) - g_renderer->UpdateViewport(); + g_renderer->SetViewport(); } diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 81ca9f75fd..acb6797264 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -57,6 +57,7 @@ public: virtual void SetLineWidth() = 0; virtual void SetSamplerState(int stage,int texindex) = 0; virtual void SetInterlacingMode() = 0; + virtual void SetViewport() = 0; virtual void ApplyState(bool bUseDstAlpha) = 0; virtual void RestoreState() = 0; @@ -107,8 +108,6 @@ public: // Finish up the current frame, print some stats virtual void Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f) = 0; - virtual void UpdateViewport() = 0; - virtual bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc) = 0; static unsigned int GetPrevPixelFormat() { return prev_efb_format; } @@ -160,4 +159,5 @@ private: extern Renderer *g_renderer; -void UpdateViewport(); +extern void SetViewport(); + diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 4632d098c4..169de08e4e 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -18,6 +18,7 @@ #include "XFMemory.h" #include "VideoCommon.h" #include "VertexManagerBase.h" +#include "RenderBase.h" #include "RenderBase.h" float GC_ALIGNED16(g_fProjectionMatrix[16]); @@ -173,8 +174,6 @@ static void ViewportCorrectionMatrix(Matrix44& result) result.data[4*1+3] = (-intendedHt + 2.f * (Y - intendedY)) / Ht + 1.f; } -void UpdateViewport(); - void VertexShaderManager::Init() { Dirty(); @@ -373,7 +372,7 @@ void VertexShaderManager::SetConstants() constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f; dirty = true; // This is so implementation-dependent that we can't have it here. - UpdateViewport(); + SetViewport(); // Update projection if the viewport isn't 1:1 useable if(!g_ActiveConfig.backend_info.bSupportsOversizedViewports) From 1f4219b5b4c5877efa12ac07d7647ed5285b288c Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 4 Feb 2014 20:16:03 +0100 Subject: [PATCH 4/7] move perfquery enable checks into videocommon (caller side) --- Source/Core/VideoBackends/D3D/PerfQuery.cpp | 21 ------------------- .../Core/VideoBackends/D3D/VertexManager.cpp | 2 -- Source/Core/VideoBackends/OGL/PerfQuery.cpp | 21 ------------------- .../Core/VideoBackends/OGL/VertexManager.cpp | 4 ---- Source/Core/VideoCommon/BPStructs.cpp | 3 ++- Source/Core/VideoCommon/PerfQueryBase.cpp | 2 +- Source/Core/VideoCommon/PerfQueryBase.h | 2 +- Source/Core/VideoCommon/VertexManagerBase.cpp | 6 +++++- 8 files changed, 9 insertions(+), 52 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/PerfQuery.cpp b/Source/Core/VideoBackends/D3D/PerfQuery.cpp index b2c77a876e..425721dbe2 100644 --- a/Source/Core/VideoBackends/D3D/PerfQuery.cpp +++ b/Source/Core/VideoBackends/D3D/PerfQuery.cpp @@ -28,9 +28,6 @@ PerfQuery::~PerfQuery() void PerfQuery::EnableQuery(PerfQueryGroup type) { - if (!ShouldEmulate()) - return; - // Is this sane? if (m_query_count > ArraySize(m_query_buffer) / 2) WeakFlush(); @@ -56,9 +53,6 @@ void PerfQuery::EnableQuery(PerfQueryGroup type) void PerfQuery::DisableQuery(PerfQueryGroup type) { - if (!ShouldEmulate()) - return; - // stop query if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) { @@ -75,9 +69,6 @@ void PerfQuery::ResetQuery() u32 PerfQuery::GetQueryResult(PerfQueryType type) { - if (!ShouldEmulate()) - return 0; - u32 result = 0; if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC) @@ -102,9 +93,6 @@ u32 PerfQuery::GetQueryResult(PerfQueryType type) void PerfQuery::FlushOne() { - if (!ShouldEmulate()) - return; - auto& entry = m_query_buffer[m_query_read_pos]; UINT64 result = 0; @@ -125,18 +113,12 @@ void PerfQuery::FlushOne() // TODO: could selectively flush things, but I don't think that will do much void PerfQuery::FlushResults() { - if (!ShouldEmulate()) - return; - while (!IsFlushed()) FlushOne(); } void PerfQuery::WeakFlush() { - if (!ShouldEmulate()) - return; - while (!IsFlushed()) { auto& entry = m_query_buffer[m_query_read_pos]; @@ -161,9 +143,6 @@ void PerfQuery::WeakFlush() bool PerfQuery::IsFlushed() const { - if (!ShouldEmulate()) - return true; - return 0 == m_query_count; } diff --git a/Source/Core/VideoBackends/D3D/VertexManager.cpp b/Source/Core/VideoBackends/D3D/VertexManager.cpp index f7de0c63cb..a85c85027d 100644 --- a/Source/Core/VideoBackends/D3D/VertexManager.cpp +++ b/Source/Core/VideoBackends/D3D/VertexManager.cpp @@ -216,9 +216,7 @@ void VertexManager::vFlush(bool useDstAlpha) g_nativeVertexFmt->SetupVertexPointers(); g_renderer->ApplyState(useDstAlpha); - g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); Draw(stride); - g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); g_renderer->RestoreState(); } diff --git a/Source/Core/VideoBackends/OGL/PerfQuery.cpp b/Source/Core/VideoBackends/OGL/PerfQuery.cpp index 0dd97d95cb..a002051584 100644 --- a/Source/Core/VideoBackends/OGL/PerfQuery.cpp +++ b/Source/Core/VideoBackends/OGL/PerfQuery.cpp @@ -28,9 +28,6 @@ PerfQuery::~PerfQuery() void PerfQuery::EnableQuery(PerfQueryGroup type) { - if (!ShouldEmulate()) - return; - // Is this sane? if (m_query_count > ArraySize(m_query_buffer) / 2) WeakFlush(); @@ -55,9 +52,6 @@ void PerfQuery::EnableQuery(PerfQueryGroup type) void PerfQuery::DisableQuery(PerfQueryGroup type) { - if (!ShouldEmulate()) - return; - // stop query if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) { @@ -67,17 +61,11 @@ void PerfQuery::DisableQuery(PerfQueryGroup type) bool PerfQuery::IsFlushed() const { - if (!ShouldEmulate()) - return true; - return 0 == m_query_count; } void PerfQuery::FlushOne() { - if (!ShouldEmulate()) - return; - auto& entry = m_query_buffer[m_query_read_pos]; GLuint result = 0; @@ -93,18 +81,12 @@ void PerfQuery::FlushOne() // TODO: could selectively flush things, but I don't think that will do much void PerfQuery::FlushResults() { - if (!ShouldEmulate()) - return; - while (!IsFlushed()) FlushOne(); } void PerfQuery::WeakFlush() { - if (!ShouldEmulate()) - return; - while (!IsFlushed()) { auto& entry = m_query_buffer[m_query_read_pos]; @@ -131,9 +113,6 @@ void PerfQuery::ResetQuery() u32 PerfQuery::GetQueryResult(PerfQueryType type) { - if (!ShouldEmulate()) - return 0; - u32 result = 0; if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC) diff --git a/Source/Core/VideoBackends/OGL/VertexManager.cpp b/Source/Core/VideoBackends/OGL/VertexManager.cpp index f0e55ee86d..670dd7d8a0 100644 --- a/Source/Core/VideoBackends/OGL/VertexManager.cpp +++ b/Source/Core/VideoBackends/OGL/VertexManager.cpp @@ -26,7 +26,6 @@ #include "IndexGenerator.h" #include "FileUtil.h" #include "StreamBuffer.h" -#include "PerfQueryBase.h" #include "Render.h" #include "main.h" @@ -173,10 +172,7 @@ void VertexManager::vFlush(bool useDstAlpha) g_nativeVertexFmt->SetupVertexPointers(); GL_REPORT_ERRORD(); - g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); Draw(stride); - g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); - //ERROR_LOG(VIDEO, "PerfQuery result: %d", g_perf_query->GetQueryResult(bpmem.zcontrol.early_ztest ? PQ_ZCOMP_OUTPUT_ZCOMPLOC : PQ_ZCOMP_OUTPUT)); // run through vertex groups again to set alpha if (useDstAlpha && !dualSourcePossible) diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 5482dae102..2434d347fa 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -423,7 +423,8 @@ void BPWritten(const BPCmd& bp) case BPMEM_CLEAR_PIXEL_PERF: // GXClearPixMetric writes 0xAAA here, Sunshine alternates this register between values 0x000 and 0xAAA - g_perf_query->ResetQuery(); + if(PerfQueryBase::ShouldEmulate()) + g_perf_query->ResetQuery(); break; case BPMEM_PRELOAD_ADDR: diff --git a/Source/Core/VideoCommon/PerfQueryBase.cpp b/Source/Core/VideoCommon/PerfQueryBase.cpp index af8bfa72e5..ada539c05e 100644 --- a/Source/Core/VideoCommon/PerfQueryBase.cpp +++ b/Source/Core/VideoCommon/PerfQueryBase.cpp @@ -3,7 +3,7 @@ PerfQueryBase* g_perf_query = 0; -bool PerfQueryBase::ShouldEmulate() const +bool PerfQueryBase::ShouldEmulate() { return g_ActiveConfig.bPerfQueriesEnable; } diff --git a/Source/Core/VideoCommon/PerfQueryBase.h b/Source/Core/VideoCommon/PerfQueryBase.h index 64a22c2712..ad112ede9d 100644 --- a/Source/Core/VideoCommon/PerfQueryBase.h +++ b/Source/Core/VideoCommon/PerfQueryBase.h @@ -29,7 +29,7 @@ public: // Checks if performance queries are enabled in the gameini configuration. // NOTE: Called from CPU+GPU thread - bool ShouldEmulate() const; + static bool ShouldEmulate(); // Begin querying the specified value for the following host GPU commands virtual void EnableQuery(PerfQueryGroup type) {} diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index cd2eec39ce..0ea44d9a57 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -12,6 +12,7 @@ #include "BPStructs.h" #include "XFMemory.h" #include "Debugger.h" +#include "PerfQueryBase.h" #include "VertexManagerBase.h" #include "MainBase.h" @@ -220,8 +221,11 @@ void VertexManager::Flush() bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; - // TODO: need to merge more stuff into VideoCommon + if(PerfQueryBase::ShouldEmulate()) + g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); g_vertex_manager->vFlush(useDstAlpha); + if(PerfQueryBase::ShouldEmulate()) + g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); From 3551259c7a278ef27b365e25dfcda0865c012c99 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 4 Feb 2014 21:17:38 +0100 Subject: [PATCH 5/7] use EFBRectangle for scissor rect This one is backend independed. The backend should recalc such things on their own. --- Source/Core/VideoBackends/D3D/Render.cpp | 5 +++-- Source/Core/VideoBackends/D3D/Render.h | 2 +- Source/Core/VideoBackends/OGL/Render.cpp | 5 +++-- Source/Core/VideoBackends/OGL/Render.h | 2 +- Source/Core/VideoCommon/BPFunctions.cpp | 3 +-- Source/Core/VideoCommon/RenderBase.h | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index c46b44c07d..6b452b84c8 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -303,9 +303,10 @@ bool Renderer::CheckForResize() return false; } -void Renderer::SetScissorRect(const TargetRectangle& rc) +void Renderer::SetScissorRect(const EFBRectangle& rc) { - D3D::context->RSSetScissorRects(1, rc.AsRECT()); + TargetRectangle trc = ConvertEFBRectangle(rc); + D3D::context->RSSetScissorRects(1, trc.AsRECT()); } void Renderer::SetColorMask() diff --git a/Source/Core/VideoBackends/D3D/Render.h b/Source/Core/VideoBackends/D3D/Render.h index 11b902c93e..17ac782beb 100644 --- a/Source/Core/VideoBackends/D3D/Render.h +++ b/Source/Core/VideoBackends/D3D/Render.h @@ -13,7 +13,7 @@ public: void SetColorMask(); void SetBlendMode(bool forceUpdate); - void SetScissorRect(const TargetRectangle& rc); + void SetScissorRect(const EFBRectangle& rc); void SetGenerationMode(); void SetDepthMode(); void SetLogicOpMode(); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 3d22168300..7e31ace68d 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -862,9 +862,10 @@ TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc) // Renderer::GetTargetHeight() = the fixed ini file setting // donkopunchstania - it appears scissorBR is the bottom right pixel inside the scissor box // therefore the width and height are (scissorBR + 1) - scissorTL -void Renderer::SetScissorRect(const TargetRectangle& rc) +void Renderer::SetScissorRect(const EFBRectangle& rc) { - glScissor(rc.left, rc.bottom, rc.GetWidth(), rc.GetHeight()); + TargetRectangle trc = g_renderer->ConvertEFBRectangle(rc); + glScissor(trc.left, trc.bottom, trc.GetWidth(), trc.GetHeight()); } void Renderer::SetColorMask() diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index 8f3e37ef1c..2af37e0d93 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -46,7 +46,7 @@ public: void SetColorMask() override; void SetBlendMode(bool forceUpdate) override; - void SetScissorRect(const TargetRectangle& rc) override; + void SetScissorRect(const EFBRectangle& rc) override; void SetGenerationMode() override; void SetDepthMode() override; void SetLogicOpMode() override; diff --git a/Source/Core/VideoCommon/BPFunctions.cpp b/Source/Core/VideoCommon/BPFunctions.cpp index 43623a94a8..3cc1764f3b 100644 --- a/Source/Core/VideoCommon/BPFunctions.cpp +++ b/Source/Core/VideoCommon/BPFunctions.cpp @@ -47,8 +47,7 @@ void SetScissor() if (rc.left > rc.right) rc.right = rc.left; if (rc.top > rc.bottom) rc.bottom = rc.top; - TargetRectangle trc = g_renderer->ConvertEFBRectangle(rc); - g_renderer->SetScissorRect(trc); + g_renderer->SetScissorRect(rc); } void SetLineWidth() diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index acb6797264..df176c1346 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -49,7 +49,7 @@ public: virtual void SetColorMask() = 0; virtual void SetBlendMode(bool forceUpdate) = 0; - virtual void SetScissorRect(const TargetRectangle& rc) = 0; + virtual void SetScissorRect(const EFBRectangle& rc) = 0; virtual void SetGenerationMode() = 0; virtual void SetDepthMode() = 0; virtual void SetLogicOpMode() = 0; From d5f1f0d4a9482359a99a2c737ec077d3e6ef9291 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 5 Feb 2014 11:48:45 +0100 Subject: [PATCH 6/7] merge some common parts of Swap() into VideoCommon --- Source/Core/VideoBackends/D3D/Render.cpp | 14 +------------- Source/Core/VideoBackends/D3D/Render.h | 2 +- Source/Core/VideoBackends/OGL/Render.cpp | 14 +------------- Source/Core/VideoBackends/OGL/Render.h | 2 +- Source/Core/VideoCommon/MainBase.cpp | 2 +- Source/Core/VideoCommon/RenderBase.cpp | 22 +++++++++++++++++++++- Source/Core/VideoCommon/RenderBase.h | 3 ++- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 6b452b84c8..cb803c270b 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -7,7 +7,6 @@ #include "Timer.h" -#include "Debugger.h" #include "EmuWindow.h" #include "Fifo.h" #include "OnScreenDisplay.h" @@ -725,7 +724,7 @@ void formatBufferDump(const u8* in, u8* out, int w, int h, int p) } // This function has the final picture. We adjust the aspect ratio here. -void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) +void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) { if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) { @@ -945,9 +944,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r OSD::DrawMessages(); D3D::EndFrame(); - frameCount++; - - GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true); TextureCache::Cleanup(); @@ -974,11 +970,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r if (XFBWrited) s_fps = UpdateFPSCounter(); - // Begin new frame - // Set default viewport and scissor, for the clear to work correctly - // New frame - stats.ResetFrame(); - // Flip/present backbuffer to frontbuffer here D3D::Present(); @@ -1019,9 +1010,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r D3D::BeginFrame(); D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV()); SetViewport(); - - Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB)); - XFBWrited = false; } // ALWAYS call RestoreAPIState for each ResetAPIState call you're doing diff --git a/Source/Core/VideoBackends/D3D/Render.h b/Source/Core/VideoBackends/D3D/Render.h index 17ac782beb..5c5a922cf1 100644 --- a/Source/Core/VideoBackends/D3D/Render.h +++ b/Source/Core/VideoBackends/D3D/Render.h @@ -39,7 +39,7 @@ public: TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc); - void Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma); + void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma); void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 7e31ace68d..844b7f3e98 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -44,7 +44,6 @@ #include "StringUtil.h" #include "FramebufferManager.h" #include "Fifo.h" -#include "Debugger.h" #include "Core.h" #include "Movie.h" #include "BPFunctions.h" @@ -1277,7 +1276,7 @@ void DumpFrame(const std::vector& data, int w, int h) } // This function has the final picture. We adjust the aspect ratio here. -void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) +void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) { static int w = 0, h = 0; if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) @@ -1593,15 +1592,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r // Clean out old stuff from caches. It's not worth it to clean out the shader caches. TextureCache::Cleanup(); - frameCount++; - - GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true); - - // Begin new frame - // Set default viewport and scissor, for the clear to work correctly - // New frame - stats.ResetFrame(); - // Render to the framebuffer. FramebufferManager::SetFramebuffer(0); @@ -1619,8 +1609,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r // Renderer::SetZBufferRender(); // SaveTexture("tex.png", GL_TEXTURE_2D, s_FakeZTarget, // GetTargetWidth(), GetTargetHeight()); - Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB)); - XFBWrited = false; // Invalidate EFB cache ClearEFBCache(); diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index 2af37e0d93..fb15462921 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -71,7 +71,7 @@ public: TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) override; - void Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma) override; + void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma) override; void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) override; diff --git a/Source/Core/VideoCommon/MainBase.cpp b/Source/Core/VideoCommon/MainBase.cpp index 7d81e4a10a..128570780b 100644 --- a/Source/Core/VideoCommon/MainBase.cpp +++ b/Source/Core/VideoCommon/MainBase.cpp @@ -72,7 +72,7 @@ void VideoFifo_CheckSwapRequest() if (Common::AtomicLoadAcquire(s_swapRequested)) { EFBRectangle rc; - g_renderer->Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight,rc); + Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight,rc); Common::AtomicStoreRelease(s_swapRequested, false); } } diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 836a0ec03d..31d5d091c7 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -30,6 +30,9 @@ #include "XFMemory.h" #include "FifoPlayer/FifoRecorder.h" #include "AVIDump.h" +#include "Debugger.h" +#include "Statistics.h" +#include "Core.h" #include #include @@ -117,7 +120,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect } else { - g_renderer->Swap(xfbAddr, fbWidth, fbHeight,sourceRc,Gamma); + Swap(xfbAddr, fbWidth, fbHeight,sourceRc,Gamma); Common::AtomicStoreRelease(s_swapRequested, false); } } @@ -514,3 +517,20 @@ void SetViewport() if (xfregs.viewport.wd != 0 && xfregs.viewport.ht != 0) g_renderer->SetViewport(); } + +void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc, float Gamma) +{ + // TODO: merge more generic parts into VideoCommon + g_renderer->SwapImpl(xfbAddr, fbWidth, fbHeight, rc, Gamma); + + frameCount++; + GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true); + + // Begin new frame + // Set default viewport and scissor, for the clear to work correctly + // New frame + stats.ResetFrame(); + + Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB)); + XFBWrited = false; +} diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index df176c1346..6744767d14 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -106,7 +106,8 @@ public: virtual void RestoreAPIState() = 0; // Finish up the current frame, print some stats - virtual void Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f) = 0; + static void Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f); + virtual void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc,float Gamma = 1.0f) = 0; virtual bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc) = 0; From 647aad0a19acc2a7bcb637160bb43d794771ed41 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 15 Feb 2014 18:57:55 +0100 Subject: [PATCH 7/7] inline SetViewport into VertexShaderManager --- Source/Core/VideoBackends/D3D/Render.cpp | 4 ++++ Source/Core/VideoCommon/RenderBase.cpp | 6 ------ Source/Core/VideoCommon/RenderBase.h | 2 -- Source/Core/VideoCommon/VertexShaderManager.cpp | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index cb803c270b..818a8ad62e 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -486,6 +486,10 @@ void Renderer::SetViewport() // [4] = yorig + height/2 + 342 // [5] = 16777215 * farz + // D3D crashes for zero viewports + if (xfregs.viewport.wd == 0 || xfregs.viewport.ht == 0) + return; + int scissorXOff = bpmem.scissorOffset.x * 2; int scissorYOff = bpmem.scissorOffset.y * 2; diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 31d5d091c7..45bd870670 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -512,12 +512,6 @@ void Renderer::RecordVideoMemory() FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFRegisters) / 4); } -void SetViewport() -{ - if (xfregs.viewport.wd != 0 && xfregs.viewport.ht != 0) - g_renderer->SetViewport(); -} - void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc, float Gamma) { // TODO: merge more generic parts into VideoCommon diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 6744767d14..fb99362a2a 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -160,5 +160,3 @@ private: extern Renderer *g_renderer; -extern void SetViewport(); - diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 169de08e4e..f39bd6231f 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -372,7 +372,7 @@ void VertexShaderManager::SetConstants() constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f; dirty = true; // This is so implementation-dependent that we can't have it here. - SetViewport(); + g_renderer->SetViewport(); // Update projection if the viewport isn't 1:1 useable if(!g_ActiveConfig.backend_info.bSupportsOversizedViewports)