Skip to content

Commit

Permalink
Merge pull request #37 from degasus/VideoCommonApiFixes
Browse files Browse the repository at this point in the history
VideoCommon API cleanups
  • Loading branch information
neobrain committed Feb 16, 2014
2 parents 2a7a943 + 647aad0 commit de5bfd0
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 129 deletions.
21 changes: 0 additions & 21 deletions Source/Core/VideoBackends/D3D/PerfQuery.cpp
Expand Up @@ -29,9 +29,6 @@ PerfQuery::~PerfQuery()

void PerfQuery::EnableQuery(PerfQueryGroup type)
{
if (!ShouldEmulate())
return;

// Is this sane?
if (m_query_count > m_query_buffer.size() / 2)
WeakFlush();
Expand All @@ -57,9 +54,6 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)

void PerfQuery::DisableQuery(PerfQueryGroup type)
{
if (!ShouldEmulate())
return;

// stop query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{
Expand All @@ -76,9 +70,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)
Expand All @@ -103,9 +94,6 @@ u32 PerfQuery::GetQueryResult(PerfQueryType type)

void PerfQuery::FlushOne()
{
if (!ShouldEmulate())
return;

auto& entry = m_query_buffer[m_query_read_pos];

UINT64 result = 0;
Expand All @@ -126,18 +114,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];
Expand All @@ -162,9 +144,6 @@ void PerfQuery::WeakFlush()

bool PerfQuery::IsFlushed() const
{
if (!ShouldEmulate())
return true;

return 0 == m_query_count;
}

Expand Down
30 changes: 11 additions & 19 deletions Source/Core/VideoBackends/D3D/Render.cpp
Expand Up @@ -7,7 +7,6 @@

#include "Timer.h"

#include "Debugger.h"
#include "EmuWindow.h"
#include "Fifo.h"
#include "OnScreenDisplay.h"
Expand Down Expand Up @@ -303,9 +302,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()
Expand Down Expand Up @@ -475,8 +475,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
Expand All @@ -486,6 +485,10 @@ void Renderer::UpdateViewport()
// [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;

Expand Down Expand Up @@ -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.
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)
{
Expand Down Expand Up @@ -944,9 +947,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();

Expand All @@ -973,11 +973,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();

Expand Down Expand Up @@ -1017,10 +1012,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();

Core::Callback_VideoCopiedToXFB(XFBWrited || (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
XFBWrited = false;
SetViewport();
}

// ALWAYS call RestoreAPIState for each ResetAPIState call you're doing
Expand All @@ -1037,7 +1029,7 @@ void Renderer::RestoreAPIState()
D3D::stateman->PopBlendState();
D3D::stateman->PopDepthState();
D3D::stateman->PopRasterizerState();
UpdateViewport();
SetViewport();
BPFunctions::SetScissor();
}

Expand Down
7 changes: 3 additions & 4 deletions Source/Core/VideoBackends/D3D/Render.h
Expand Up @@ -13,14 +13,15 @@ class Renderer : public ::Renderer

void SetColorMask();
void SetBlendMode(bool forceUpdate);
void SetScissorRect(const TargetRectangle& rc);
void SetScissorRect(const EFBRectangle& rc);
void SetGenerationMode();
void SetDepthMode();
void SetLogicOpMode();
void SetDitherMode();
void SetLineWidth();
void SetSamplerState(int stage,int texindex);
void SetInterlacingMode();
void SetViewport();

// TODO: Fix confusing names (see ResetAPIState and RestoreAPIState)
void ApplyState(bool bUseDstAlpha);
Expand All @@ -38,14 +39,12 @@ class Renderer : public ::Renderer

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 ReinterpretPixelData(unsigned int convtype);

void UpdateViewport();

bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);

static bool CheckForResize();
Expand Down
9 changes: 1 addition & 8 deletions Source/Core/VideoBackends/D3D/VertexManager.cpp
Expand Up @@ -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))
Expand All @@ -219,11 +216,7 @@ void VertexManager::vFlush()
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);

GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);

g_renderer->RestoreState();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/D3D/VertexManager.h
Expand Up @@ -30,7 +30,7 @@ class VertexManager : public ::VertexManager
void PrepareDrawBuffers();
void Draw(u32 stride);
// temp
void vFlush();
void vFlush(bool useDstAlpha);

u32 m_vertex_buffer_cursor;
u32 m_vertex_draw_offset;
Expand Down
21 changes: 0 additions & 21 deletions Source/Core/VideoBackends/OGL/PerfQuery.cpp
Expand Up @@ -28,9 +28,6 @@ PerfQuery::~PerfQuery()

void PerfQuery::EnableQuery(PerfQueryGroup type)
{
if (!ShouldEmulate())
return;

// Is this sane?
if (m_query_count > m_query_buffer.size() / 2)
WeakFlush();
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -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)
Expand Down
24 changes: 6 additions & 18 deletions Source/Core/VideoBackends/OGL/Render.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -862,9 +861,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()
Expand Down Expand Up @@ -1077,8 +1077,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
Expand Down Expand Up @@ -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.
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)
Expand Down Expand Up @@ -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.
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);

Expand All @@ -1618,8 +1608,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();
Expand Down Expand Up @@ -1650,7 +1638,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);
Expand Down

0 comments on commit de5bfd0

Please sign in to comment.