Merge branch 'master' into GLSL-master

Conflicts:
	CMakeLists.txt
	Source/Core/DolphinWX/CMakeLists.txt
	Source/Core/DolphinWX/Src/GLInterface.h
	Source/Core/VideoCommon/Src/PixelShaderGen.cpp
	Source/Core/VideoCommon/Src/TextureCacheBase.cpp
	Source/Core/VideoCommon/Src/VertexManagerBase.cpp
	Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
	Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp
	Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcxproj
	Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcxproj.filters
	Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h
	Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
	Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
	Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
	Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp
	Source/Plugins/Plugin_VideoOGL/Src/main.cpp
This commit is contained in:
degasus
2013-03-06 15:59:29 +01:00
443 changed files with 16217 additions and 6374 deletions

View File

@ -51,7 +51,9 @@ void VideoBackend::UpdateFPSDisplay(const char *text)
}
void InitInterface()
{
#if defined(USE_EGL) && USE_EGL
#ifdef ANDROID
GLInterface = new cInterfaceBase;
#elif defined(USE_EGL) && USE_EGL
GLInterface = new cInterfaceEGL;
#elif defined(__APPLE__)
GLInterface = new cInterfaceAGL;

View File

@ -17,7 +17,7 @@
#include "GLUtil.h"
#include "x64Emitter.h"
#include "ABI.h"
#include "x64ABI.h"
#include "MemoryUtil.h"
#include "ProgramShaderCache.h"
#include "VertexShaderGen.h"

View File

@ -0,0 +1,133 @@
#include "RenderBase.h"
#include "GLUtil.h"
#include "PerfQuery.h"
namespace OGL
{
PerfQuery::PerfQuery()
: m_query_read_pos()
, m_query_count()
{
for (u32 i = 0; i != ARRAYSIZE(m_query_buffer); ++i)
glGenQueries(1, &m_query_buffer[i].query_id);
ResetQuery();
}
PerfQuery::~PerfQuery()
{
for (u32 i = 0; i != ARRAYSIZE(m_query_buffer); ++i)
glDeleteQueries(1, &m_query_buffer[i].query_id);
}
void PerfQuery::EnableQuery(PerfQueryGroup type)
{
// Is this sane?
if (m_query_count > ARRAYSIZE(m_query_buffer) / 2)
WeakFlush();
if (ARRAYSIZE(m_query_buffer) == m_query_count)
{
FlushOne();
//ERROR_LOG(VIDEO, "flushed query buffer early!");
}
// start query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % ARRAYSIZE(m_query_buffer)];
glBeginQuery(GL_SAMPLES_PASSED, entry.query_id);
entry.query_type = type;
++m_query_count;
}
}
void PerfQuery::DisableQuery(PerfQueryGroup type)
{
// stop query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{
glEndQuery(GL_SAMPLES_PASSED);
}
}
bool PerfQuery::IsFlushed() const
{
return 0 == m_query_count;
}
void PerfQuery::FlushOne()
{
auto& entry = m_query_buffer[m_query_read_pos];
GLuint result = 0;
glGetQueryObjectuiv(entry.query_id, GL_QUERY_RESULT, &result);
// 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_query_read_pos = (m_query_read_pos + 1) % ARRAYSIZE(m_query_buffer);
--m_query_count;
}
// TODO: could selectively flush things, but I don't think that will do much
void PerfQuery::FlushResults()
{
while (!IsFlushed())
FlushOne();
}
void PerfQuery::WeakFlush()
{
while (!IsFlushed())
{
auto& entry = m_query_buffer[m_query_read_pos];
GLuint result = GL_FALSE;
glGetQueryObjectuiv(entry.query_id, GL_QUERY_RESULT_AVAILABLE, &result);
if (GL_TRUE == result)
{
FlushOne();
}
else
{
break;
}
}
}
void PerfQuery::ResetQuery()
{
m_query_count = 0;
std::fill_n(m_results, ARRAYSIZE(m_results), 0);
}
u32 PerfQuery::GetQueryResult(PerfQueryType type)
{
u32 result = 0;
if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC)
{
result = m_results[PQG_ZCOMP_ZCOMPLOC];
}
else if (type == PQ_ZCOMP_INPUT || type == PQ_ZCOMP_OUTPUT)
{
result = m_results[PQG_ZCOMP];
}
else if (type == PQ_BLEND_INPUT)
{
result = m_results[PQG_ZCOMP] + m_results[PQG_ZCOMP_ZCOMPLOC];
}
else if (type == PQ_EFB_COPY_CLOCKS)
{
result = m_results[PQG_EFB_COPY_CLOCKS];
}
return result / 4;
}
} // namespace

View File

@ -0,0 +1,46 @@
#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);
void FlushResults();
bool IsFlushed() const;
private:
struct ActiveQuery
{
GLuint query_id;
PerfQueryGroup query_type;
};
// when testing in SMS: 64 was too small, 128 was ok
static const u32 PERF_QUERY_BUFFER_SIZE = 512;
void WeakFlush();
// Only use when non-empty
void FlushOne();
// This contains gl query objects with unretrieved results.
ActiveQuery m_query_buffer[PERF_QUERY_BUFFER_SIZE];
u32 m_query_read_pos;
// TODO: sloppy
volatile u32 m_query_count;
volatile u32 m_results[PQG_NUM_MEMBERS];
};
} // namespace
#endif // _PERFQUERY_H_

View File

@ -24,6 +24,7 @@
#include <cstdio>
#include "GLUtil.h"
#include "WxUtils.h"
#include "FileUtil.h"
@ -962,20 +963,23 @@ void Renderer::SetBlendMode(bool forceUpdate)
s_blendMode = newval;
}
void DumpFrame(const std::vector<u8>& data, int w, int h)
{
#if defined(HAVE_LIBAV) || defined(_WIN32)
if (g_ActiveConfig.bDumpFrames && !data.empty())
{
AVIDump::AddFrame(&data[0], w, h);
}
#endif
}
// This function has the final picture. We adjust the aspect ratio here.
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
{
static int w = 0, h = 0;
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{
if (g_ActiveConfig.bDumpFrames && frame_data)
{
#ifdef _WIN32
AVIDump::AddFrame(frame_data);
#elif defined HAVE_LIBAV
AVIDump::AddFrame((u8*)frame_data, w, h);
#endif
}
DumpFrame(frame_data, w, h);
Core::Callback_VideoCopiedToXFB(false);
return;
}
@ -985,14 +989,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
if (g_ActiveConfig.VirtualXFBEnabled() && (!xfbSourceList || xfbCount == 0))
{
if (g_ActiveConfig.bDumpFrames && frame_data)
{
#ifdef _WIN32
AVIDump::AddFrame(frame_data);
#elif defined HAVE_LIBAV
AVIDump::AddFrame((u8*)frame_data, w, h);
#endif
}
DumpFrame(frame_data, w, h);
Core::Callback_VideoCopiedToXFB(false);
return;
}
@ -1117,16 +1114,15 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
if (g_ActiveConfig.bDumpFrames)
{
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
if (!frame_data || w != flipped_trc.GetWidth() ||
if (frame_data.empty() || w != flipped_trc.GetWidth() ||
h != flipped_trc.GetHeight())
{
if (frame_data) delete[] frame_data;
w = flipped_trc.GetWidth();
h = flipped_trc.GetHeight();
frame_data = new char[3 * w * h];
frame_data.resize(3 * w * h);
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data);
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
if (GL_REPORT_ERROR() == GL_NO_ERROR && w > 0 && h > 0)
{
if (!bLastFrameDumped)
@ -1147,12 +1143,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
}
if (bAVIDumping)
{
#ifdef _WIN32
AVIDump::AddFrame(frame_data);
#else
FlipImageData((u8*)frame_data, w, h);
AVIDump::AddFrame((u8*)frame_data, w, h);
#ifndef _WIN32
FlipImageData(&frame_data[0], w, h);
#endif
AVIDump::AddFrame(&frame_data[0], w, h);
}
bLastFrameDumped = true;
@ -1164,12 +1159,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
{
if (bLastFrameDumped && bAVIDumping)
{
if (frame_data)
{
delete[] frame_data;
frame_data = NULL;
w = h = 0;
}
std::vector<u8>().swap(frame_data);
w = h = 0;
AVIDump::Stop();
bAVIDumping = false;
OSD::AddMessage("Stop dumping frames", 2000);
@ -1183,9 +1174,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
std::string movie_file_name;
w = GetTargetRectangle().GetWidth();
h = GetTargetRectangle().GetHeight();
frame_data = new char[3 * w * h];
frame_data.resize(3 * w * h);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(GetTargetRectangle().left, GetTargetRectangle().bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data);
glReadPixels(GetTargetRectangle().left, GetTargetRectangle().bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
if (GL_REPORT_ERROR() == GL_NO_ERROR)
{
if (!bLastFrameDumped)
@ -1196,21 +1187,17 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
else
{
char msg [255];
sprintf(msg, "Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h);
OSD::AddMessage(msg, 2000);
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h).c_str(), 2000);
}
}
if (pFrameDump)
{
FlipImageData((u8*)frame_data, w, h);
pFrameDump.WriteBytes(frame_data, w * 3 * h);
FlipImageData(&frame_data[0], w, h);
pFrameDump.WriteBytes(&frame_data[0], w * 3 * h);
pFrameDump.Flush();
}
bLastFrameDumped = true;
}
delete[] frame_data;
}
else
{
@ -1399,6 +1386,7 @@ void Renderer::SetDepthMode()
else
{
// if the test is disabled write is disabled too
// TODO: When PE performance metrics are being emulated via occlusion queries, we should (probably?) enable depth test with depth function ALWAYS here
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
}
@ -1522,7 +1510,7 @@ void TakeScreenshot(ScrStrct* threadStruct)
// Save the screenshot and finally kill the wxImage object
// This is really expensive when saving to PNG, but not at all when using BMP
threadStruct->img->SaveFile(wxString::FromAscii(threadStruct->filename.c_str()),
threadStruct->img->SaveFile(StrToWxStr(threadStruct->filename),
wxBITMAP_TYPE_PNG);
threadStruct->img->Destroy();

View File

@ -65,6 +65,7 @@ static u32 s_DepthCbufid;
static u32 s_Textures[8];
static u32 s_ActiveTexture;
static u32 s_NextStage;
struct VBOCache {
GLuint vbo;
@ -204,23 +205,25 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
entry.pcfmt = pcfmt;
entry.m_tex_levels = tex_levels;
entry.Load(width, height, expanded_width, 0);
return &entry;
}
void TextureCache::TCacheEntry::Load(unsigned int stage, unsigned int width, unsigned int height,
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level)
{
if (s_ActiveTexture != stage)
if (s_ActiveTexture != s_NextStage)
{
glActiveTexture(GL_TEXTURE0 + stage);
s_ActiveTexture = stage;
glActiveTexture(GL_TEXTURE0 + s_NextStage);
s_ActiveTexture = s_NextStage;
}
if (s_Textures[stage] != texture)
if (s_Textures[s_NextStage] != texture)
{
glBindTexture(GL_TEXTURE_2D, texture);
s_Textures[stage] = texture;
s_Textures[s_NextStage] = texture;
}
// TODO: sloppy, just do this on creation?
@ -458,6 +461,7 @@ TextureCache::TextureCache()
s_DepthCbufid = -1;
s_ActiveTexture = -1;
s_NextStage = -1;
for(int i=0; i<8; i++)
s_Textures[i] = -1;
}
@ -490,5 +494,11 @@ void TextureCache::SetStage ()
glActiveTexture(GL_TEXTURE0 + s_ActiveTexture);
}
void TextureCache::SetNextStage ( unsigned int stage )
{
s_NextStage = stage;
}
}

View File

@ -35,6 +35,7 @@ public:
TextureCache();
static void DisableStage(unsigned int stage);
static void SetStage();
static void SetNextStage(unsigned int stage);
private:
struct TCacheEntry : TCacheEntryBase
@ -55,7 +56,7 @@ private:
TCacheEntry();
~TCacheEntry();
void Load(unsigned int stage, unsigned int width, unsigned int height,
void Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level);
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,

View File

@ -40,6 +40,7 @@
#include "FileUtil.h"
#include "Debugger.h"
#include "StreamBuffer.h"
#include "PerfQueryBase.h"
#include "main.h"
@ -99,21 +100,21 @@ void VertexManager::PrepareDrawBuffers(u32 stride)
u32 index_size = (triangle_index_size+line_index_size+point_index_size) * sizeof(u16);
s_vertexBuffer->Alloc(vertex_data_size, stride);
u32 offset = s_vertexBuffer->Upload(LocalVBuffer, vertex_data_size);
u32 offset = s_vertexBuffer->Upload(GetVertexBuffer(), vertex_data_size);
s_baseVertex = offset / stride;
s_indexBuffer->Alloc(index_size);
if(triangle_index_size)
{
s_offset[0] = s_indexBuffer->Upload((u8*)TIBuffer, triangle_index_size * sizeof(u16));
s_offset[0] = s_indexBuffer->Upload((u8*)GetTriangleIndexBuffer(), triangle_index_size * sizeof(u16));
}
if(line_index_size)
{
s_offset[1] = s_indexBuffer->Upload((u8*)LIBuffer, line_index_size * sizeof(u16));
s_offset[1] = s_indexBuffer->Upload((u8*)GetLineIndexBuffer(), line_index_size * sizeof(u16));
}
if(point_index_size)
{
s_offset[2] = s_indexBuffer->Upload((u8*)PIBuffer, point_index_size * sizeof(u16));
s_offset[2] = s_indexBuffer->Upload((u8*)GetPointIndexBuffer(), point_index_size * sizeof(u16));
}
}
@ -159,7 +160,6 @@ void VertexManager::Draw(u32 stride)
void VertexManager::vFlush()
{
VideoFifo_CheckEFBAccess();
#if defined(_DEBUG) || defined(DEBUGFAST)
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGen.numTexGens,
xfregs.numChan.numColorChans, xfregs.dualTexTrans.enabled, bpmem.ztex2.op,
@ -215,6 +215,7 @@ void VertexManager::vFlush()
{
if (usedtextures & (1 << i))
{
TextureCache::SetNextStage(i);
g_renderer->SetSamplerState(i % 4, i / 4);
FourTexUnits &tex = bpmem.tex[i >> 2];
TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
@ -271,7 +272,10 @@ void VertexManager::vFlush()
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)
@ -299,7 +303,6 @@ void VertexManager::vFlush()
}
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
ResetBuffer();
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
{
@ -307,10 +310,12 @@ void VertexManager::vFlush()
ProgramShaderCache::PCacheEntry prog = ProgramShaderCache::GetShaderProgram();
char strfile[255];
sprintf(strfile, "%sps%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
std::ofstream fps(strfile);
std::ofstream fps;
OpenFStream(fps, strfile, std::ios_base::out);
fps << prog.shader.strpprog.c_str();
sprintf(strfile, "%svs%.3d.txt", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), g_ActiveConfig.iSaveTargetId);
std::ofstream fvs(strfile);
std::ofstream fvs;
OpenFStream(fvs, strfile, std::ios_base::out);
fvs << prog.shader.strvprog.c_str();
}

View File

@ -92,6 +92,7 @@ Make AA apply instantly during gameplay if possible
#include "Core.h"
#include "Host.h"
#include "SamplerCache.h"
#include "PerfQuery.h"
#include "VideoState.h"
#include "VideoBackend.h"
@ -130,6 +131,7 @@ void InitBackendInfo()
{
g_Config.backend_info.APIType = API_OPENGL;
g_Config.backend_info.bUseRGBATextures = true;
g_Config.backend_info.bUseMinimalMipCount = false;
g_Config.backend_info.bSupports3DVision = false;
//g_Config.backend_info.bSupportsDualSourceBlend = true; // is gpu depenend and must be set in renderer
g_Config.backend_info.bSupportsFormatReinterpretation = false;
@ -191,6 +193,7 @@ void VideoBackend::Video_Prepare()
BPInit();
g_vertex_manager = new VertexManager;
g_perf_query = new PerfQuery;
Fifo_Init(); // must be done before OpcodeDecoder_Init()
OpcodeDecoder_Init();
VertexShaderManager::Init();
@ -203,7 +206,9 @@ void VideoBackend::Video_Prepare()
GL_REPORT_ERRORD();
VertexLoaderManager::Init();
TextureConverter::Init();
#ifndef _M_GENERIC
DLCache::Init();
#endif
// Notify the core that the video backend is ready
Host_Message(WM_USER_CREATE);
@ -222,7 +227,9 @@ void VideoBackend::Video_Cleanup() {
s_efbAccessRequested = false;
s_FifoShuttingDown = false;
s_swapRequested = false;
#ifndef _M_GENERIC
DLCache::Shutdown();
#endif
Fifo_Shutdown();
PostProcessing::Shutdown();