Merge pull request #37 from degasus/VideoCommonApiFixes

VideoCommon API cleanups
This commit is contained in:
Tony Wasserka 2014-02-16 22:08:28 +01:00
commit de5bfd0bce
21 changed files with 71 additions and 129 deletions

View File

@ -29,9 +29,6 @@ PerfQuery::~PerfQuery()
void PerfQuery::EnableQuery(PerfQueryGroup type) void PerfQuery::EnableQuery(PerfQueryGroup type)
{ {
if (!ShouldEmulate())
return;
// Is this sane? // Is this sane?
if (m_query_count > m_query_buffer.size() / 2) if (m_query_count > m_query_buffer.size() / 2)
WeakFlush(); WeakFlush();
@ -57,9 +54,6 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
void PerfQuery::DisableQuery(PerfQueryGroup type) void PerfQuery::DisableQuery(PerfQueryGroup type)
{ {
if (!ShouldEmulate())
return;
// stop query // stop query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{ {
@ -76,9 +70,6 @@ void PerfQuery::ResetQuery()
u32 PerfQuery::GetQueryResult(PerfQueryType type) u32 PerfQuery::GetQueryResult(PerfQueryType type)
{ {
if (!ShouldEmulate())
return 0;
u32 result = 0; u32 result = 0;
if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC) if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC)
@ -103,9 +94,6 @@ u32 PerfQuery::GetQueryResult(PerfQueryType type)
void PerfQuery::FlushOne() void PerfQuery::FlushOne()
{ {
if (!ShouldEmulate())
return;
auto& entry = m_query_buffer[m_query_read_pos]; auto& entry = m_query_buffer[m_query_read_pos];
UINT64 result = 0; UINT64 result = 0;
@ -126,18 +114,12 @@ void PerfQuery::FlushOne()
// TODO: could selectively flush things, but I don't think that will do much // TODO: could selectively flush things, but I don't think that will do much
void PerfQuery::FlushResults() void PerfQuery::FlushResults()
{ {
if (!ShouldEmulate())
return;
while (!IsFlushed()) while (!IsFlushed())
FlushOne(); FlushOne();
} }
void PerfQuery::WeakFlush() void PerfQuery::WeakFlush()
{ {
if (!ShouldEmulate())
return;
while (!IsFlushed()) while (!IsFlushed())
{ {
auto& entry = m_query_buffer[m_query_read_pos]; auto& entry = m_query_buffer[m_query_read_pos];
@ -162,9 +144,6 @@ void PerfQuery::WeakFlush()
bool PerfQuery::IsFlushed() const bool PerfQuery::IsFlushed() const
{ {
if (!ShouldEmulate())
return true;
return 0 == m_query_count; return 0 == m_query_count;
} }

View File

@ -7,7 +7,6 @@
#include "Timer.h" #include "Timer.h"
#include "Debugger.h"
#include "EmuWindow.h" #include "EmuWindow.h"
#include "Fifo.h" #include "Fifo.h"
#include "OnScreenDisplay.h" #include "OnScreenDisplay.h"
@ -303,9 +302,10 @@ bool Renderer::CheckForResize()
return false; 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() void Renderer::SetColorMask()
@ -475,8 +475,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
} }
// Called from VertexShaderManager void Renderer::SetViewport()
void Renderer::UpdateViewport()
{ {
// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
// [0] = width/2 // [0] = width/2
@ -486,6 +485,10 @@ void Renderer::UpdateViewport()
// [4] = yorig + height/2 + 342 // [4] = yorig + height/2 + 342
// [5] = 16777215 * farz // [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 scissorXOff = bpmem.scissorOffset.x * 2;
int scissorYOff = bpmem.scissorOffset.y * 2; int scissorYOff = bpmem.scissorOffset.y * 2;
@ -724,7 +727,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. // 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) if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{ {
@ -944,9 +947,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r
OSD::DrawMessages(); OSD::DrawMessages();
D3D::EndFrame(); D3D::EndFrame();
frameCount++;
GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true);
TextureCache::Cleanup(); TextureCache::Cleanup();
@ -973,11 +973,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r
if (XFBWrited) if (XFBWrited)
s_fps = UpdateFPSCounter(); 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 // Flip/present backbuffer to frontbuffer here
D3D::Present(); D3D::Present();
@ -1017,10 +1012,7 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r
RestoreAPIState(); RestoreAPIState();
D3D::BeginFrame(); D3D::BeginFrame();
D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV()); D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV());
UpdateViewport(); SetViewport();
Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
XFBWrited = false;
} }
// ALWAYS call RestoreAPIState for each ResetAPIState call you're doing // ALWAYS call RestoreAPIState for each ResetAPIState call you're doing
@ -1037,7 +1029,7 @@ void Renderer::RestoreAPIState()
D3D::stateman->PopBlendState(); D3D::stateman->PopBlendState();
D3D::stateman->PopDepthState(); D3D::stateman->PopDepthState();
D3D::stateman->PopRasterizerState(); D3D::stateman->PopRasterizerState();
UpdateViewport(); SetViewport();
BPFunctions::SetScissor(); BPFunctions::SetScissor();
} }

View File

@ -13,7 +13,7 @@ public:
void SetColorMask(); void SetColorMask();
void SetBlendMode(bool forceUpdate); void SetBlendMode(bool forceUpdate);
void SetScissorRect(const TargetRectangle& rc); void SetScissorRect(const EFBRectangle& rc);
void SetGenerationMode(); void SetGenerationMode();
void SetDepthMode(); void SetDepthMode();
void SetLogicOpMode(); void SetLogicOpMode();
@ -21,6 +21,7 @@ public:
void SetLineWidth(); void SetLineWidth();
void SetSamplerState(int stage,int texindex); void SetSamplerState(int stage,int texindex);
void SetInterlacingMode(); void SetInterlacingMode();
void SetViewport();
// TODO: Fix confusing names (see ResetAPIState and RestoreAPIState) // TODO: Fix confusing names (see ResetAPIState and RestoreAPIState)
void ApplyState(bool bUseDstAlpha); void ApplyState(bool bUseDstAlpha);
@ -38,14 +39,12 @@ public:
TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc); 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); void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z);
void ReinterpretPixelData(unsigned int convtype); void ReinterpretPixelData(unsigned int convtype);
void UpdateViewport();
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);
static bool CheckForResize(); static bool CheckForResize();

View File

@ -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( if (!PixelShaderCache::SetShader(
useDstAlpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, useDstAlpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE,
g_nativeVertexFmt->m_components)) g_nativeVertexFmt->m_components))
@ -219,11 +216,7 @@ void VertexManager::vFlush()
g_nativeVertexFmt->SetupVertexPointers(); g_nativeVertexFmt->SetupVertexPointers();
g_renderer->ApplyState(useDstAlpha); g_renderer->ApplyState(useDstAlpha);
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
Draw(stride); 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(); g_renderer->RestoreState();
} }

View File

@ -30,7 +30,7 @@ private:
void PrepareDrawBuffers(); void PrepareDrawBuffers();
void Draw(u32 stride); void Draw(u32 stride);
// temp // temp
void vFlush(); void vFlush(bool useDstAlpha);
u32 m_vertex_buffer_cursor; u32 m_vertex_buffer_cursor;
u32 m_vertex_draw_offset; u32 m_vertex_draw_offset;

View File

@ -28,9 +28,6 @@ PerfQuery::~PerfQuery()
void PerfQuery::EnableQuery(PerfQueryGroup type) void PerfQuery::EnableQuery(PerfQueryGroup type)
{ {
if (!ShouldEmulate())
return;
// Is this sane? // Is this sane?
if (m_query_count > m_query_buffer.size() / 2) if (m_query_count > m_query_buffer.size() / 2)
WeakFlush(); WeakFlush();
@ -55,9 +52,6 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
void PerfQuery::DisableQuery(PerfQueryGroup type) void PerfQuery::DisableQuery(PerfQueryGroup type)
{ {
if (!ShouldEmulate())
return;
// stop query // stop query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{ {
@ -67,17 +61,11 @@ void PerfQuery::DisableQuery(PerfQueryGroup type)
bool PerfQuery::IsFlushed() const bool PerfQuery::IsFlushed() const
{ {
if (!ShouldEmulate())
return true;
return 0 == m_query_count; return 0 == m_query_count;
} }
void PerfQuery::FlushOne() void PerfQuery::FlushOne()
{ {
if (!ShouldEmulate())
return;
auto& entry = m_query_buffer[m_query_read_pos]; auto& entry = m_query_buffer[m_query_read_pos];
GLuint result = 0; GLuint result = 0;
@ -93,18 +81,12 @@ void PerfQuery::FlushOne()
// TODO: could selectively flush things, but I don't think that will do much // TODO: could selectively flush things, but I don't think that will do much
void PerfQuery::FlushResults() void PerfQuery::FlushResults()
{ {
if (!ShouldEmulate())
return;
while (!IsFlushed()) while (!IsFlushed())
FlushOne(); FlushOne();
} }
void PerfQuery::WeakFlush() void PerfQuery::WeakFlush()
{ {
if (!ShouldEmulate())
return;
while (!IsFlushed()) while (!IsFlushed())
{ {
auto& entry = m_query_buffer[m_query_read_pos]; auto& entry = m_query_buffer[m_query_read_pos];
@ -131,9 +113,6 @@ void PerfQuery::ResetQuery()
u32 PerfQuery::GetQueryResult(PerfQueryType type) u32 PerfQuery::GetQueryResult(PerfQueryType type)
{ {
if (!ShouldEmulate())
return 0;
u32 result = 0; u32 result = 0;
if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC) if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC)

View File

@ -44,7 +44,6 @@
#include "StringUtil.h" #include "StringUtil.h"
#include "FramebufferManager.h" #include "FramebufferManager.h"
#include "Fifo.h" #include "Fifo.h"
#include "Debugger.h"
#include "Core.h" #include "Core.h"
#include "Movie.h" #include "Movie.h"
#include "BPFunctions.h" #include "BPFunctions.h"
@ -862,9 +861,10 @@ TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
// Renderer::GetTargetHeight() = the fixed ini file setting // Renderer::GetTargetHeight() = the fixed ini file setting
// donkopunchstania - it appears scissorBR is the bottom right pixel inside the scissor box // donkopunchstania - it appears scissorBR is the bottom right pixel inside the scissor box
// therefore the width and height are (scissorBR + 1) - scissorTL // 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() void Renderer::SetColorMask()
@ -1077,8 +1077,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
return 0; return 0;
} }
// Called from VertexShaderManager void Renderer::SetViewport()
void Renderer::UpdateViewport()
{ {
// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
// [0] = width/2 // [0] = width/2
@ -1276,7 +1275,7 @@ void DumpFrame(const std::vector<u8>& data, int w, int h)
} }
// This function has the final picture. We adjust the aspect ratio here. // 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; static int w = 0, h = 0;
if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
@ -1592,15 +1591,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. // Clean out old stuff from caches. It's not worth it to clean out the shader caches.
TextureCache::Cleanup(); 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. // Render to the framebuffer.
FramebufferManager::SetFramebuffer(0); FramebufferManager::SetFramebuffer(0);
@ -1618,8 +1608,6 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangle& r
// Renderer::SetZBufferRender(); // Renderer::SetZBufferRender();
// SaveTexture("tex.png", GL_TEXTURE_2D, s_FakeZTarget, // SaveTexture("tex.png", GL_TEXTURE_2D, s_FakeZTarget,
// GetTargetWidth(), GetTargetHeight()); // GetTargetWidth(), GetTargetHeight());
Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
XFBWrited = false;
// Invalidate EFB cache // Invalidate EFB cache
ClearEFBCache(); ClearEFBCache();
@ -1650,7 +1638,7 @@ void Renderer::RestoreAPIState()
SetDepthMode(); SetDepthMode();
SetBlendMode(true); SetBlendMode(true);
SetLogicOpMode(); SetLogicOpMode();
UpdateViewport(); SetViewport();
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
glPolygonMode(GL_FRONT_AND_BACK, g_ActiveConfig.bWireFrame ? GL_LINE : GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, g_ActiveConfig.bWireFrame ? GL_LINE : GL_FILL);

View File

@ -46,7 +46,7 @@ public:
void SetColorMask() override; void SetColorMask() override;
void SetBlendMode(bool forceUpdate) override; void SetBlendMode(bool forceUpdate) override;
void SetScissorRect(const TargetRectangle& rc) override; void SetScissorRect(const EFBRectangle& rc) override;
void SetGenerationMode() override; void SetGenerationMode() override;
void SetDepthMode() override; void SetDepthMode() override;
void SetLogicOpMode() override; void SetLogicOpMode() override;
@ -54,6 +54,7 @@ public:
void SetLineWidth() override; void SetLineWidth() override;
void SetSamplerState(int stage,int texindex) override; void SetSamplerState(int stage,int texindex) override;
void SetInterlacingMode() override; void SetInterlacingMode() override;
void SetViewport() override;
// TODO: Implement and use these // TODO: Implement and use these
void ApplyState(bool bUseDstAlpha) override {} void ApplyState(bool bUseDstAlpha) override {}
@ -70,14 +71,12 @@ public:
TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) override; 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; void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) override;
void ReinterpretPixelData(unsigned int convtype) override; void ReinterpretPixelData(unsigned int convtype) override;
void UpdateViewport() override;
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);
private: private:

View File

@ -25,9 +25,7 @@
#include "VertexManager.h" #include "VertexManager.h"
#include "IndexGenerator.h" #include "IndexGenerator.h"
#include "FileUtil.h" #include "FileUtil.h"
#include "Debugger.h"
#include "StreamBuffer.h" #include "StreamBuffer.h"
#include "PerfQueryBase.h"
#include "Render.h" #include "Render.h"
#include "main.h" #include "main.h"
@ -131,7 +129,7 @@ void VertexManager::Draw(u32 stride)
INCSTAT(stats.thisFrame.numIndexedDrawCalls); INCSTAT(stats.thisFrame.numIndexedDrawCalls);
} }
void VertexManager::vFlush() void VertexManager::vFlush(bool useDstAlpha)
{ {
GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)g_nativeVertexFmt; GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)g_nativeVertexFmt;
u32 stride = nativeVertexFmt->GetVertexStride(); u32 stride = nativeVertexFmt->GetVertexStride();
@ -144,9 +142,6 @@ void VertexManager::vFlush()
PrepareDrawBuffers(stride); PrepareDrawBuffers(stride);
GL_REPORT_ERRORD(); 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 // Makes sure we can actually do Dual source blending
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend; bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
@ -177,10 +172,7 @@ void VertexManager::vFlush()
g_nativeVertexFmt->SetupVertexPointers(); g_nativeVertexFmt->SetupVertexPointers();
GL_REPORT_ERRORD(); GL_REPORT_ERRORD();
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
Draw(stride); 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 // run through vertex groups again to set alpha
if (useDstAlpha && !dualSourcePossible) if (useDstAlpha && !dualSourcePossible)
@ -200,7 +192,6 @@ void VertexManager::vFlush()
if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract) if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
glEnable(GL_BLEND); glEnable(GL_BLEND);
} }
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS) if (g_ActiveConfig.iLog & CONF_SAVESHADERS)

View File

@ -43,7 +43,7 @@ protected:
virtual void ResetBuffer(u32 stride); virtual void ResetBuffer(u32 stride);
private: private:
void Draw(u32 stride); void Draw(u32 stride);
void vFlush() override; void vFlush(bool useDstAlpha) override;
void PrepareDrawBuffers(u32 stride); void PrepareDrawBuffers(u32 stride);
NativeVertexFormat *m_CurrentVertexFmt; NativeVertexFormat *m_CurrentVertexFmt;
}; };

View File

@ -97,7 +97,7 @@ std::string VideoBackend::GetName()
std::string VideoBackend::GetDisplayName() std::string VideoBackend::GetDisplayName()
{ {
if (g_renderer && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
return "OpenGLES"; return "OpenGLES";
else else
return "OpenGL"; return "OpenGL";

View File

@ -47,8 +47,7 @@ void SetScissor()
if (rc.left > rc.right) rc.right = rc.left; if (rc.left > rc.right) rc.right = rc.left;
if (rc.top > rc.bottom) rc.bottom = rc.top; if (rc.top > rc.bottom) rc.bottom = rc.top;
TargetRectangle trc = g_renderer->ConvertEFBRectangle(rc); g_renderer->SetScissorRect(rc);
g_renderer->SetScissorRect(trc);
} }
void SetLineWidth() void SetLineWidth()

View File

@ -423,7 +423,8 @@ 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_perf_query->ResetQuery(); if(PerfQueryBase::ShouldEmulate())
g_perf_query->ResetQuery();
break; break;
case BPMEM_PRELOAD_ADDR: case BPMEM_PRELOAD_ADDR:

View File

@ -72,7 +72,7 @@ void VideoFifo_CheckSwapRequest()
if (Common::AtomicLoadAcquire(s_swapRequested)) if (Common::AtomicLoadAcquire(s_swapRequested))
{ {
EFBRectangle rc; 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); Common::AtomicStoreRelease(s_swapRequested, false);
} }
} }

View File

@ -3,7 +3,7 @@
PerfQueryBase* g_perf_query = 0; PerfQueryBase* g_perf_query = 0;
bool PerfQueryBase::ShouldEmulate() const bool PerfQueryBase::ShouldEmulate()
{ {
return g_ActiveConfig.bPerfQueriesEnable; return g_ActiveConfig.bPerfQueriesEnable;
} }

View File

@ -29,7 +29,7 @@ public:
// Checks if performance queries are enabled in the gameini configuration. // Checks if performance queries are enabled in the gameini configuration.
// NOTE: Called from CPU+GPU thread // NOTE: Called from CPU+GPU thread
bool ShouldEmulate() const; static bool ShouldEmulate();
// Begin querying the specified value for the following host GPU commands // Begin querying the specified value for the following host GPU commands
virtual void EnableQuery(PerfQueryGroup type) {} virtual void EnableQuery(PerfQueryGroup type) {}

View File

@ -30,6 +30,9 @@
#include "XFMemory.h" #include "XFMemory.h"
#include "FifoPlayer/FifoRecorder.h" #include "FifoPlayer/FifoRecorder.h"
#include "AVIDump.h" #include "AVIDump.h"
#include "Debugger.h"
#include "Statistics.h"
#include "Core.h"
#include <cmath> #include <cmath>
#include <string> #include <string>
@ -117,7 +120,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
} }
else else
{ {
g_renderer->Swap(xfbAddr, fbWidth, fbHeight,sourceRc,Gamma); Swap(xfbAddr, fbWidth, fbHeight,sourceRc,Gamma);
Common::AtomicStoreRelease(s_swapRequested, false); Common::AtomicStoreRelease(s_swapRequested, false);
} }
} }
@ -509,8 +512,19 @@ void Renderer::RecordVideoMemory()
FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFRegisters) / 4); FifoRecorder::GetInstance().SetVideoMemory(bpMem, cpMem, xfMem, xfRegs, sizeof(XFRegisters) / 4);
} }
void UpdateViewport() void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& rc, float Gamma)
{ {
if (xfregs.viewport.wd != 0 && xfregs.viewport.ht != 0) // TODO: merge more generic parts into VideoCommon
g_renderer->UpdateViewport(); 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;
} }

View File

@ -49,7 +49,7 @@ public:
virtual void SetColorMask() = 0; virtual void SetColorMask() = 0;
virtual void SetBlendMode(bool forceUpdate) = 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 SetGenerationMode() = 0;
virtual void SetDepthMode() = 0; virtual void SetDepthMode() = 0;
virtual void SetLogicOpMode() = 0; virtual void SetLogicOpMode() = 0;
@ -57,6 +57,7 @@ public:
virtual void SetLineWidth() = 0; virtual void SetLineWidth() = 0;
virtual void SetSamplerState(int stage,int texindex) = 0; virtual void SetSamplerState(int stage,int texindex) = 0;
virtual void SetInterlacingMode() = 0; virtual void SetInterlacingMode() = 0;
virtual void SetViewport() = 0;
virtual void ApplyState(bool bUseDstAlpha) = 0; virtual void ApplyState(bool bUseDstAlpha) = 0;
virtual void RestoreState() = 0; virtual void RestoreState() = 0;
@ -105,9 +106,8 @@ public:
virtual void RestoreAPIState() = 0; virtual void RestoreAPIState() = 0;
// Finish up the current frame, print some stats // 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 void UpdateViewport() = 0;
virtual bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc) = 0; virtual bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc) = 0;
@ -160,4 +160,3 @@ private:
extern Renderer *g_renderer; extern Renderer *g_renderer;
void UpdateViewport();

View File

@ -11,6 +11,8 @@
#include "RenderBase.h" #include "RenderBase.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "XFMemory.h" #include "XFMemory.h"
#include "Debugger.h"
#include "PerfQueryBase.h"
#include "VertexManagerBase.h" #include "VertexManagerBase.h"
#include "MainBase.h" #include "MainBase.h"
@ -216,8 +218,16 @@ void VertexManager::Flush()
VertexShaderManager::SetConstants(); VertexShaderManager::SetConstants();
PixelShaderManager::SetConstants(); PixelShaderManager::SetConstants();
// TODO: need to merge more stuff into VideoCommon bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate
g_vertex_manager->vFlush(); && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
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);
IsFlushed = true; IsFlushed = true;
} }

View File

@ -58,7 +58,7 @@ private:
//virtual void Draw(u32 stride, bool alphapass) = 0; //virtual void Draw(u32 stride, bool alphapass) = 0;
// temp // temp
virtual void vFlush() = 0; virtual void vFlush(bool useDstAlpha) = 0;
}; };
extern VertexManager *g_vertex_manager; extern VertexManager *g_vertex_manager;

View File

@ -18,6 +18,7 @@
#include "XFMemory.h" #include "XFMemory.h"
#include "VideoCommon.h" #include "VideoCommon.h"
#include "VertexManagerBase.h" #include "VertexManagerBase.h"
#include "RenderBase.h"
#include "RenderBase.h" #include "RenderBase.h"
float GC_ALIGNED16(g_fProjectionMatrix[16]); 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; result.data[4*1+3] = (-intendedHt + 2.f * (Y - intendedY)) / Ht + 1.f;
} }
void UpdateViewport();
void VertexShaderManager::Init() void VertexShaderManager::Init()
{ {
Dirty(); Dirty();
@ -373,7 +372,7 @@ void VertexShaderManager::SetConstants()
constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f; constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f;
dirty = true; dirty = true;
// This is so implementation-dependent that we can't have it here. // This is so implementation-dependent that we can't have it here.
UpdateViewport(); g_renderer->SetViewport();
// Update projection if the viewport isn't 1:1 useable // Update projection if the viewport isn't 1:1 useable
if(!g_ActiveConfig.backend_info.bSupportsOversizedViewports) if(!g_ActiveConfig.backend_info.bSupportsOversizedViewports)