OGL: Implement pixel metrics (untested)

This commit is contained in:
NeoBrainX 2012-06-17 13:58:29 +02:00
parent 4d8d86bd6a
commit cf8744cf2c
10 changed files with 166 additions and 13 deletions

View File

@ -16,6 +16,7 @@ set(SRCS Src/BPFunctions.cpp
Src/OpcodeDecoding.cpp Src/OpcodeDecoding.cpp
Src/OpenCL.cpp Src/OpenCL.cpp
Src/OpenCL/OCLTextureDecoder.cpp Src/OpenCL/OCLTextureDecoder.cpp
Src/PerfQueryBase.cpp
Src/PixelEngine.cpp Src/PixelEngine.cpp
Src/PixelShaderGen.cpp Src/PixelShaderGen.cpp
Src/PixelShaderManager.cpp Src/PixelShaderManager.cpp

View File

@ -31,6 +31,7 @@
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "Thread.h" #include "Thread.h"
#include "HW/Memmap.h" #include "HW/Memmap.h"
#include "PerfQueryBase.h"
using namespace BPFunctions; using namespace BPFunctions;
@ -487,7 +488,7 @@ void BPWritten(const BPCmd& bp)
case BPMEM_CLEAR_PIXEL_PERF: case BPMEM_CLEAR_PIXEL_PERF:
// GXClearPixMetric writes 0xAAA here, Sunshine alternates this register between values 0x000 and 0xAAA // GXClearPixMetric writes 0xAAA here, Sunshine alternates this register between values 0x000 and 0xAAA
g_renderer->ResetPixelPerf(); g_perf_query->ResetQuery();
break; break;
case BPMEM_PRELOAD_ADDR: case BPMEM_PRELOAD_ADDR:

View File

@ -0,0 +1,3 @@
#include "PerfQueryBase.h"
PerfQueryBase* g_perf_query = 0;

View File

@ -0,0 +1,39 @@
#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() {}
virtual void EnableQuery(PerfQueryGroup type) {}
virtual void DisableQuery(PerfQueryGroup type) {}
virtual void ResetQuery() {}
virtual u32 GetQueryResult(PerfQueryType type) { return 0; }
};
extern PerfQueryBase* g_perf_query;
#endif // _PERFQUERY_H_

View File

@ -33,6 +33,8 @@
#include "HW/ProcessorInterface.h" #include "HW/ProcessorInterface.h"
#include "DLCache.h" #include "DLCache.h"
#include "State.h" #include "State.h"
#include "PerfQueryBase.h"
namespace PixelEngine namespace PixelEngine
{ {
@ -258,35 +260,35 @@ void Read16(u16& _uReturnValue, const u32 _iAddress)
// 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). // 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: case PE_PERF_ZCOMP_INPUT_ZCOMPLOC_L:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_INPUT_ZCOMPLOC) & 0xFFFF; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_INPUT_ZCOMPLOC) & 0xFFFF;
break; break;
case PE_PERF_ZCOMP_INPUT_ZCOMPLOC_H: case PE_PERF_ZCOMP_INPUT_ZCOMPLOC_H:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_INPUT_ZCOMPLOC) >> 16; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_INPUT_ZCOMPLOC) >> 16;
break; break;
case PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_L: case PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_L:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_OUTPUT_ZCOMPLOC) & 0xFFFF; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_OUTPUT_ZCOMPLOC) & 0xFFFF;
break; break;
case PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_H: case PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_H:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_OUTPUT_ZCOMPLOC) >> 16; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_OUTPUT_ZCOMPLOC) >> 16;
break; break;
case PE_PERF_ZCOMP_INPUT_L: case PE_PERF_ZCOMP_INPUT_L:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_INPUT) & 0xFFFF; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_INPUT) & 0xFFFF;
break; break;
case PE_PERF_ZCOMP_INPUT_H: case PE_PERF_ZCOMP_INPUT_H:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_INPUT) >> 16; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_INPUT) >> 16;
break; break;
case PE_PERF_ZCOMP_OUTPUT_L: case PE_PERF_ZCOMP_OUTPUT_L:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_OUTPUT) & 0xFFFF; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_OUTPUT) & 0xFFFF;
break; break;
case PE_PERF_ZCOMP_OUTPUT_H: case PE_PERF_ZCOMP_OUTPUT_H:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_ZCOMP_OUTPUT) >> 16; _uReturnValue = g_perf_query->GetQueryResult(PQ_ZCOMP_OUTPUT) >> 16;
break; break;
case PE_PERF_BLEND_INPUT_L: case PE_PERF_BLEND_INPUT_L:
@ -296,19 +298,19 @@ void Read16(u16& _uReturnValue, const u32 _iAddress)
// 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). // 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. // 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. // Note that currently this functionality is only implemented in the D3D11 backend.
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_BLEND_INPUT) & 0xFFFF; _uReturnValue = g_perf_query->GetQueryResult(PQ_BLEND_INPUT) & 0xFFFF;
break; break;
case PE_PERF_BLEND_INPUT_H: case PE_PERF_BLEND_INPUT_H:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_BLEND_INPUT) >> 16; _uReturnValue = g_perf_query->GetQueryResult(PQ_BLEND_INPUT) >> 16;
break; break;
case PE_PERF_EFB_COPY_CLOCKS_L: case PE_PERF_EFB_COPY_CLOCKS_L:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_EFB_COPY_CLOCKS) & 0xFFFF; _uReturnValue = g_perf_query->GetQueryResult(PQ_EFB_COPY_CLOCKS) & 0xFFFF;
break; break;
case PE_PERF_EFB_COPY_CLOCKS_H: case PE_PERF_EFB_COPY_CLOCKS_H:
_uReturnValue = g_renderer->GetPixelPerfResult(Renderer::PP_EFB_COPY_CLOCKS) >> 16; _uReturnValue = g_perf_query->GetQueryResult(PQ_EFB_COPY_CLOCKS) >> 16;
break; break;
default: default:

View File

@ -2,6 +2,7 @@ set(SRCS Src/FramebufferManager.cpp
Src/GLUtil.cpp Src/GLUtil.cpp
Src/main.cpp Src/main.cpp
Src/NativeVertexFormat.cpp Src/NativeVertexFormat.cpp
Src/PerfQuery.cpp
Src/PixelShaderCache.cpp Src/PixelShaderCache.cpp
Src/PostProcessing.cpp Src/PostProcessing.cpp
Src/RasterFont.cpp Src/RasterFont.cpp

View File

@ -0,0 +1,78 @@
#include "GLUtil.h"
#include "PerfQuery.h"
namespace OGL {
u32 results[PQG_NUM_MEMBERS] = { 0 };
GLuint query_id;
PerfQueryGroup active_query;
PerfQuery::PerfQuery()
{
glGenQueries(1, &query_id);
}
PerfQuery::~PerfQuery()
{
glDeleteQueries(1, &query_id);
}
void PerfQuery::EnableQuery(PerfQueryGroup type)
{
// start query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{
glBeginQuery(GL_SAMPLES_PASSED, query_id);
}
active_query = type;
}
void PerfQuery::DisableQuery(PerfQueryGroup type)
{
// stop query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{
glEndQuery(GL_SAMPLES_PASSED);
GLuint query_result = GL_FALSE;
while (query_result != GL_TRUE)
{
glGetQueryObjectuiv(query_id, GL_QUERY_RESULT_AVAILABLE, &query_result);
}
glGetQueryObjectuiv(query_id, GL_QUERY_RESULT, &query_result);
results[active_query] += query_result;
}
}
void PerfQuery::ResetQuery()
{
memset(results, 0, sizeof(results));
}
u32 PerfQuery::GetQueryResult(PerfQueryType type)
{
if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC || type == PQ_BLEND_INPUT)
{
}
if (type == PQ_ZCOMP_INPUT || type == PQ_ZCOMP_OUTPUT || type == PQ_BLEND_INPUT)
{
}
if (type == PQ_BLEND_INPUT)
{
results[PQ_BLEND_INPUT] = results[PQ_ZCOMP_OUTPUT] + results[PQ_ZCOMP_OUTPUT_ZCOMPLOC];
}
if (type == PQ_EFB_COPY_CLOCKS)
{
// TODO
}
return results[type];
}
} // namespace

View File

@ -0,0 +1,22 @@
#ifndef _PERFQUERY_H_
#define _PERFQUERY_H_
#include "PerfQueryBase.h"
namespace OGL {
class PerfQuery : public PerfQueryBase
{
public:
PerfQuery();
~PerfQuery();
void EnableQuery(PerfQueryGroup type);
void DisableQuery(PerfQueryGroup type);
void ResetQuery();
u32 GetQueryResult(PerfQueryType type);
};
} // namespace
#endif // _PERFQUERY_H_

View File

@ -40,6 +40,7 @@
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "FileUtil.h" #include "FileUtil.h"
#include "Debugger.h" #include "Debugger.h"
#include "PerfQueryBase.h"
#include "main.h" #include "main.h"
@ -207,7 +208,10 @@ void VertexManager::vFlush()
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here. if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here.
if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid); if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid);
g_perf_query->EnableQuery(bpmem.zcontrol.zcomploc ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
Draw(); Draw();
g_perf_query->DisableQuery(bpmem.zcontrol.zcomploc ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
ERROR_LOG(VIDEO, "PerfQuery result: %d", g_perf_query->GetQueryResult(bpmem.zcontrol.zcomploc ? PQ_ZCOMP_OUTPUT_ZCOMPLOC : PQ_ZCOMP_OUTPUT));
// run through vertex groups again to set alpha // run through vertex groups again to set alpha
if (useDstAlpha && !dualSourcePossible) if (useDstAlpha && !dualSourcePossible)

View File

@ -93,6 +93,7 @@ Make AA apply instantly during gameplay if possible
#include "FramebufferManager.h" #include "FramebufferManager.h"
#include "Core.h" #include "Core.h"
#include "Host.h" #include "Host.h"
#include "PerfQuery.h"
#include "VideoState.h" #include "VideoState.h"
#include "VideoBackend.h" #include "VideoBackend.h"
@ -194,6 +195,7 @@ void VideoBackend::Video_Prepare()
BPInit(); BPInit();
g_vertex_manager = new VertexManager; g_vertex_manager = new VertexManager;
g_perf_query = new PerfQuery;
Fifo_Init(); // must be done before OpcodeDecoder_Init() Fifo_Init(); // must be done before OpcodeDecoder_Init()
OpcodeDecoder_Init(); OpcodeDecoder_Init();
VertexShaderCache::Init(); VertexShaderCache::Init();