summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorNeoBrainX <NeoBrainX@gmail.com>2013-03-02 00:04:44 +0100
committerNeoBrainX <NeoBrainX@gmail.com>2013-03-02 00:17:37 +0100
commit008fdc73106a142212fc5cd4481d13535103b954 (patch)
treebc7307aa6bca3b2f060762c014ef0d09e5e5d533 /Source/Core/VideoCommon
parentef7083d78cdeb9eb8881a0d1593164ad1dd04225 (diff)
parentcb1d21c032b92412d5d795705642189657db37e3 (diff)
Merge branch 'perfqueries'.
Adds support for PE performance metrics. Used in Super Mario Sunshine's "Scrubbing Sirena Beach" level to determine when enough goop has been cleaned up to finish the level. Also used in TimeSplitters: Future Perfect to determine the appearance of flares around light sources (e.g. sun). OpenGL and D3D11 only. D3D9 support unlikely to be added unless anyone bothers to do the work. Initial work and D3D11 support by me. Kudos go to Billiard for adding the OpenGL support and reviving development of this branch that way :D Slightly (~7%) decreases performance when performance metrics are used (and only then). Fixes issue 1498. Fixes issue 5368.
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/CMakeLists.txt1
-rw-r--r--Source/Core/VideoCommon/Src/BPMemory.h2
-rw-r--r--Source/Core/VideoCommon/Src/BPStructs.cpp12
-rw-r--r--Source/Core/VideoCommon/Src/MainBase.cpp43
-rw-r--r--Source/Core/VideoCommon/Src/OnScreenDisplay.h2
-rw-r--r--Source/Core/VideoCommon/Src/PerfQueryBase.cpp3
-rw-r--r--Source/Core/VideoCommon/Src/PerfQueryBase.h54
-rw-r--r--Source/Core/VideoCommon/Src/PixelEngine.cpp73
-rw-r--r--Source/Core/VideoCommon/Src/PixelEngine.h27
-rw-r--r--Source/Core/VideoCommon/Src/RenderBase.h9
-rw-r--r--Source/Core/VideoCommon/Src/VertexManagerBase.cpp2
-rw-r--r--Source/Core/VideoCommon/Src/VideoConfig.h2
-rw-r--r--Source/Core/VideoCommon/VideoCommon.vcxproj2
-rw-r--r--Source/Core/VideoCommon/VideoCommon.vcxproj.filters8
14 files changed, 201 insertions, 39 deletions
diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt
index cba3666399..89b6828281 100644
--- a/Source/Core/VideoCommon/CMakeLists.txt
+++ b/Source/Core/VideoCommon/CMakeLists.txt
@@ -16,6 +16,7 @@ set(SRCS Src/BPFunctions.cpp
Src/OpcodeDecoding.cpp
Src/OpenCL.cpp
Src/OpenCL/OCLTextureDecoder.cpp
+ Src/PerfQueryBase.cpp
Src/PixelEngine.cpp
Src/PixelShaderGen.cpp
Src/PixelShaderManager.cpp
diff --git a/Source/Core/VideoCommon/Src/BPMemory.h b/Source/Core/VideoCommon/Src/BPMemory.h
index 85e95f4f8b..0ee00f911e 100644
--- a/Source/Core/VideoCommon/Src/BPMemory.h
+++ b/Source/Core/VideoCommon/Src/BPMemory.h
@@ -62,7 +62,7 @@
#define BPMEM_COPYFILTER1 0x54
#define BPMEM_CLEARBBOX1 0x55
#define BPMEM_CLEARBBOX2 0x56
-#define BPMEM_UNKNOWN_57 0x57
+#define BPMEM_CLEAR_PIXEL_PERF 0x57
#define BPMEM_REVBITS 0x58
#define BPMEM_SCISSOROFFSET 0x59
#define BPMEM_PRELOAD_ADDR 0x60
diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp
index 0d7d741a92..fa6bc08966 100644
--- a/Source/Core/VideoCommon/Src/BPStructs.cpp
+++ b/Source/Core/VideoCommon/Src/BPStructs.cpp
@@ -31,6 +31,7 @@
#include "VertexShaderManager.h"
#include "Thread.h"
#include "HW/Memmap.h"
+#include "PerfQueryBase.h"
using namespace BPFunctions;
@@ -62,7 +63,6 @@ void RenderToXFB(const BPCmd &bp, const EFBRectangle &rc, float yScale, float xf
{
Renderer::RenderToXFB(xfbAddr, dstWidth, dstHeight, rc, gamma);
}
-
void BPWritten(const BPCmd& bp)
{
/*
@@ -144,7 +144,8 @@ void BPWritten(const BPCmd& bp)
|| bp.address == BPMEM_LOADTLUT0
|| bp.address == BPMEM_LOADTLUT1
|| bp.address == BPMEM_TEXINVALIDATE
- || bp.address == BPMEM_PRELOAD_MODE))
+ || bp.address == BPMEM_PRELOAD_MODE
+ || bp.address == BPMEM_CLEAR_PIXEL_PERF))
{
return;
}
@@ -484,9 +485,10 @@ void BPWritten(const BPCmd& bp)
case BPMEM_IND_IMASK: // Index Mask ?
case BPMEM_REVBITS: // Always set to 0x0F when GX_InitRevBits() is called.
break;
-
- case BPMEM_UNKNOWN_57: // Sunshine alternates this register between values 0x000 and 0xAAA
- DEBUG_LOG(VIDEO, "Unknown BP Reg 0x57: %08x", bp.newvalue);
+
+ case BPMEM_CLEAR_PIXEL_PERF:
+ // GXClearPixMetric writes 0xAAA here, Sunshine alternates this register between values 0x000 and 0xAAA
+ g_perf_query->ResetQuery();
break;
case BPMEM_PRELOAD_ADDR:
diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp
index a881bebfb2..1472367f21 100644
--- a/Source/Core/VideoCommon/Src/MainBase.cpp
+++ b/Source/Core/VideoCommon/Src/MainBase.cpp
@@ -21,6 +21,10 @@ volatile u32 s_swapRequested = false;
u32 s_efbAccessRequested = false;
volatile u32 s_FifoShuttingDown = false;
+std::condition_variable s_perf_query_cond;
+std::mutex s_perf_query_lock;
+static volatile bool s_perf_query_requested;
+
static volatile struct
{
u32 xfbAddr;
@@ -169,6 +173,43 @@ u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32
return 0;
}
+static bool QueryResultIsReady()
+{
+ return !s_perf_query_requested || s_FifoShuttingDown;
+}
+
+void VideoFifo_CheckPerfQueryRequest()
+{
+ if (s_perf_query_requested)
+ {
+ g_perf_query->FlushResults();
+
+ {
+ std::lock_guard<std::mutex> lk(s_perf_query_lock);
+ s_perf_query_requested = false;
+ }
+
+ s_perf_query_cond.notify_one();
+ }
+}
+
+u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
+{
+ // TODO: Is this check sane?
+ if (!g_perf_query->IsFlushed())
+ {
+ if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread)
+ {
+ s_perf_query_requested = true;
+ std::unique_lock<std::mutex> lk(s_perf_query_lock);
+ s_perf_query_cond.wait(lk, QueryResultIsReady);
+ }
+ else
+ g_perf_query->FlushResults();
+ }
+
+ return g_perf_query->GetQueryResult(type);
+}
void VideoBackendHardware::InitializeShared()
{
@@ -176,6 +217,7 @@ void VideoBackendHardware::InitializeShared()
s_swapRequested = 0;
s_efbAccessRequested = 0;
+ s_perf_query_requested = false;
s_FifoShuttingDown = 0;
memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs));
memset(&s_accessEFBArgs, 0, sizeof(s_accessEFBArgs));
@@ -238,6 +280,7 @@ void VideoFifo_CheckAsyncRequest()
{
VideoFifo_CheckSwapRequest();
VideoFifo_CheckEFBAccess();
+ VideoFifo_CheckPerfQueryRequest();
}
void VideoBackendHardware::Video_GatherPipeBursted()
diff --git a/Source/Core/VideoCommon/Src/OnScreenDisplay.h b/Source/Core/VideoCommon/Src/OnScreenDisplay.h
index 3777e2b5d3..80187b8ac3 100644
--- a/Source/Core/VideoCommon/Src/OnScreenDisplay.h
+++ b/Source/Core/VideoCommon/Src/OnScreenDisplay.h
@@ -22,7 +22,7 @@ namespace OSD
{
// On-screen message display
-void AddMessage(const char* str, u32 ms);
+void AddMessage(const char* str, u32 ms = 2000);
void DrawMessages(); // draw the current messages on the screen. Only call once per frame.
void ClearMessages();
diff --git a/Source/Core/VideoCommon/Src/PerfQueryBase.cpp b/Source/Core/VideoCommon/Src/PerfQueryBase.cpp
new file mode 100644
index 0000000000..c537d176f6
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/PerfQueryBase.cpp
@@ -0,0 +1,3 @@
+#include "PerfQueryBase.h"
+
+PerfQueryBase* g_perf_query = 0;
diff --git a/Source/Core/VideoCommon/Src/PerfQueryBase.h b/Source/Core/VideoCommon/Src/PerfQueryBase.h
new file mode 100644
index 0000000000..b979449edb
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/PerfQueryBase.h
@@ -0,0 +1,54 @@
+#ifndef _PERFQUERY_BASE_H_
+#define _PERFQUERY_BASE_H_
+
+#include "CommonTypes.h"
+
+enum PerfQueryType
+{
+ PQ_ZCOMP_INPUT_ZCOMPLOC = 0,
+ PQ_ZCOMP_OUTPUT_ZCOMPLOC,
+ PQ_ZCOMP_INPUT,
+ PQ_ZCOMP_OUTPUT,
+ PQ_BLEND_INPUT,
+ PQ_EFB_COPY_CLOCKS,
+ PQ_NUM_MEMBERS
+};
+
+enum PerfQueryGroup
+{
+ PQG_ZCOMP_ZCOMPLOC,
+ PQG_ZCOMP,
+ PQG_EFB_COPY_CLOCKS,
+ PQG_NUM_MEMBERS,
+};
+
+class PerfQueryBase
+{
+public:
+ PerfQueryBase() {};
+ virtual ~PerfQueryBase() {}
+
+ // Begin querying the specified value for the following host GPU commands
+ virtual void EnableQuery(PerfQueryGroup type) {}
+
+ // Stop querying the specified value for the following host GPU commands
+ virtual void DisableQuery(PerfQueryGroup type) {}
+
+ // Reset query counters to zero and drop any pending queries
+ virtual void ResetQuery() {}
+
+ // Return the measured value for the specified query type
+ // NOTE: Called from CPU thread
+ virtual u32 GetQueryResult(PerfQueryType type) { return 0; }
+
+ // Request the value of any pending queries - causes a pipeline flush and thus should be used carefully!
+ virtual void FlushResults() {}
+
+ // True if there are no further pending query results
+ // NOTE: Called from CPU thread
+ virtual bool IsFlushed() const { return true; }
+};
+
+extern PerfQueryBase* g_perf_query;
+
+#endif // _PERFQUERY_H_
diff --git a/Source/Core/VideoCommon/Src/PixelEngine.cpp b/Source/Core/VideoCommon/Src/PixelEngine.cpp
index a488e52b42..e5ba554678 100644
--- a/Source/Core/VideoCommon/Src/PixelEngine.cpp
+++ b/Source/Core/VideoCommon/Src/PixelEngine.cpp
@@ -28,10 +28,13 @@
#include "ConfigManager.h"
#include "PixelEngine.h"
+#include "RenderBase.h"
#include "CommandProcessor.h"
#include "HW/ProcessorInterface.h"
#include "DLCache.h"
#include "State.h"
+#include "PerfQueryBase.h"
+
namespace PixelEngine
{
@@ -255,23 +258,59 @@ void Read16(u16& _uReturnValue, const u32 _iAddress)
break;
}
- case PE_PERF_0L:
- case PE_PERF_0H:
- case PE_PERF_1L:
- case PE_PERF_1H:
- case PE_PERF_2L:
- case PE_PERF_2H:
- case PE_PERF_3L:
- case PE_PERF_3H:
- case PE_PERF_4L:
- case PE_PERF_4H:
- case PE_PERF_5L:
- case PE_PERF_5H:
- INFO_LOG(PIXELENGINE, "(r16) perf counter @ %08x", _iAddress);
- // git r90a2096a24f4 (svn r3663) added the PE_PERF cases, without setting
- // _uReturnValue to anything, this reverts to the previous behaviour which allows
- // The timer in SMS:Scrubbing Serena Beach to countdown correctly
- _uReturnValue = 1;
+ // NOTE(neobrain): only PE_PERF_ZCOMP_OUTPUT is implemented in D3D11, but the other values shouldn't be contradictionary to the value of that register (i.e. INPUT registers should always be greater or equal to their corresponding OUTPUT registers).
+ case PE_PERF_ZCOMP_INPUT_ZCOMPLOC_L:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_INPUT_ZCOMPLOC) & 0xFFFF;
+ break;
+
+ case PE_PERF_ZCOMP_INPUT_ZCOMPLOC_H:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_INPUT_ZCOMPLOC) >> 16;
+ break;
+
+ case PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_L:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_OUTPUT_ZCOMPLOC) & 0xFFFF;
+ break;
+
+ case PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_H:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_OUTPUT_ZCOMPLOC) >> 16;
+ break;
+
+ case PE_PERF_ZCOMP_INPUT_L:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_INPUT) & 0xFFFF;
+ break;
+
+ case PE_PERF_ZCOMP_INPUT_H:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_INPUT) >> 16;
+ break;
+
+ case PE_PERF_ZCOMP_OUTPUT_L:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_OUTPUT) & 0xFFFF;
+ break;
+
+ case PE_PERF_ZCOMP_OUTPUT_H:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_ZCOMP_OUTPUT) >> 16;
+ break;
+
+ case PE_PERF_BLEND_INPUT_L:
+ // Super Mario Sunshine uses this register in episode 6 of Sirena Beach:
+ // The amount of remaining goop is determined by checking how many pixels reach the blending stage.
+ // Once this register falls below a particular value (around 0x90), the game regards the challenge finished.
+ // In very old builds, Dolphin only returned 0. That caused the challenge to be immediately finished without any goop being cleaned (the timer just didn't even start counting from 3:00:00).
+ // Later builds returned 1 for the high register. That caused the timer to actually count down, but made the challenge unbeatable because the game always thought you didn't clear any goop at all.
+ // Note that currently this functionality is only implemented in the D3D11 backend.
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_BLEND_INPUT) & 0xFFFF;
+ break;
+
+ case PE_PERF_BLEND_INPUT_H:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_BLEND_INPUT) >> 16;
+ break;
+
+ case PE_PERF_EFB_COPY_CLOCKS_L:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_EFB_COPY_CLOCKS) & 0xFFFF;
+ break;
+
+ case PE_PERF_EFB_COPY_CLOCKS_H:
+ _uReturnValue = g_video_backend->Video_GetQueryResult(PQ_EFB_COPY_CLOCKS) >> 16;
break;
default:
diff --git a/Source/Core/VideoCommon/Src/PixelEngine.h b/Source/Core/VideoCommon/Src/PixelEngine.h
index 64f959009f..eaf55f0031 100644
--- a/Source/Core/VideoCommon/Src/PixelEngine.h
+++ b/Source/Core/VideoCommon/Src/PixelEngine.h
@@ -36,19 +36,20 @@ enum
PE_BBOX_TOP = 0x14, // Flip Top
PE_BBOX_BOTTOM = 0x16, // Flip Bottom
- // These have not yet been RE:d. They are the perf counters.
- PE_PERF_0L = 0x18,
- PE_PERF_0H = 0x1a,
- PE_PERF_1L = 0x1c,
- PE_PERF_1H = 0x1e,
- PE_PERF_2L = 0x20,
- PE_PERF_2H = 0x22,
- PE_PERF_3L = 0x24,
- PE_PERF_3H = 0x26,
- PE_PERF_4L = 0x28,
- PE_PERF_4H = 0x2a,
- PE_PERF_5L = 0x2c,
- PE_PERF_5H = 0x2e,
+ // NOTE: Order not verified
+ // These indicate the number of quads that are being used as input/output for each particular stage
+ PE_PERF_ZCOMP_INPUT_ZCOMPLOC_L = 0x18,
+ PE_PERF_ZCOMP_INPUT_ZCOMPLOC_H = 0x1a,
+ PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_L = 0x1c,
+ PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_H = 0x1e,
+ PE_PERF_ZCOMP_INPUT_L = 0x20,
+ PE_PERF_ZCOMP_INPUT_H = 0x22,
+ PE_PERF_ZCOMP_OUTPUT_L = 0x24,
+ PE_PERF_ZCOMP_OUTPUT_H = 0x26,
+ PE_PERF_BLEND_INPUT_L = 0x28,
+ PE_PERF_BLEND_INPUT_H = 0x2a,
+ PE_PERF_EFB_COPY_CLOCKS_L = 0x2c,
+ PE_PERF_EFB_COPY_CLOCKS_H = 0x2e,
};
namespace PixelEngine
diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h
index 8b5505e082..55678f3f5a 100644
--- a/Source/Core/VideoCommon/Src/RenderBase.h
+++ b/Source/Core/VideoCommon/Src/RenderBase.h
@@ -52,6 +52,15 @@ public:
Renderer();
virtual ~Renderer();
+ enum PixelPerfQuery {
+ PP_ZCOMP_INPUT_ZCOMPLOC,
+ PP_ZCOMP_OUTPUT_ZCOMPLOC,
+ PP_ZCOMP_INPUT,
+ PP_ZCOMP_OUTPUT,
+ PP_BLEND_INPUT,
+ PP_EFB_COPY_CLOCKS
+ };
+
virtual void SetColorMask() = 0;
virtual void SetBlendMode(bool forceUpdate) = 0;
virtual void SetScissorRect(const TargetRectangle& rc) = 0;
diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp
index cd5a01c6b3..520fc21090 100644
--- a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp
+++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp
@@ -257,7 +257,9 @@ void VertexManager::Flush()
//if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers();
+ g_renderer->ResumePixelPerf(false);
g_vertex_manager->Draw(stride, false);
+ g_renderer->PausePixelPerf(false);
// run through vertex groups again to set alpha
if (false == g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h
index 183fcf784c..0531918183 100644
--- a/Source/Core/VideoCommon/Src/VideoConfig.h
+++ b/Source/Core/VideoCommon/Src/VideoConfig.h
@@ -115,7 +115,7 @@ struct VideoConfig
int iAnaglyphStereoSeparation;
int iAnaglyphFocalAngle;
bool b3DVision;
-
+
// Hacks
bool bEFBAccessEnable;
bool bDlistCachingEnable;
diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj b/Source/Core/VideoCommon/VideoCommon.vcxproj
index 0c1b13f301..f785cb5c84 100644
--- a/Source/Core/VideoCommon/VideoCommon.vcxproj
+++ b/Source/Core/VideoCommon/VideoCommon.vcxproj
@@ -196,6 +196,7 @@
<ClCompile Include="Src\OpcodeDecoding.cpp" />
<ClCompile Include="Src\OpenCL.cpp" />
<ClCompile Include="Src\OpenCL\OCLTextureDecoder.cpp" />
+ <ClCompile Include="Src\PerfQueryBase.cpp" />
<ClCompile Include="Src\PixelEngine.cpp" />
<ClCompile Include="Src\PixelShaderGen.cpp" />
<ClCompile Include="Src\PixelShaderManager.cpp" />
@@ -244,6 +245,7 @@
<ClInclude Include="Src\OpcodeDecoding.h" />
<ClInclude Include="Src\OpenCL.h" />
<ClInclude Include="Src\OpenCL\OCLTextureDecoder.h" />
+ <ClInclude Include="Src\PerfQueryBase.h" />
<ClInclude Include="Src\PixelEngine.h" />
<ClInclude Include="Src\PixelShaderGen.h" />
<ClInclude Include="Src\PixelShaderManager.h" />
diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
index 6038d5e9e2..330b23d370 100644
--- a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
+++ b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
@@ -101,6 +101,9 @@
<ClCompile Include="Src\MainBase.cpp">
<Filter>Base</Filter>
</ClCompile>
+ <ClCompile Include="Src\PerfQueryBase.cpp">
+ <Filter>Base</Filter>
+ </ClCompile>
<ClCompile Include="Src\RenderBase.cpp">
<Filter>Base</Filter>
</ClCompile>
@@ -237,6 +240,9 @@
<ClInclude Include="Src\MainBase.h">
<Filter>Base</Filter>
</ClInclude>
+ <ClInclude Include="Src\PerfQueryBase.h">
+ <Filter>Base</Filter>
+ </ClInclude>
<ClInclude Include="Src\RenderBase.h">
<Filter>Base</Filter>
</ClInclude>
@@ -285,4 +291,4 @@
<UniqueIdentifier>{e2a527a2-ccc8-4ab8-a93e-dd2628c0f3b6}</UniqueIdentifier>
</Filter>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>