From c1b39ecc582d5f6e7716f69644fbd54e53be538d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 21 Jan 2018 22:12:32 +1000 Subject: [PATCH] BPFunctions: Move upscaling of scissor rect to VideoCommon --- Source/Core/VideoBackends/D3D/Render.cpp | 6 ++--- Source/Core/VideoBackends/D3D/Render.h | 2 +- Source/Core/VideoBackends/OGL/Render.cpp | 15 ++----------- Source/Core/VideoBackends/OGL/Render.h | 2 +- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 10 +++------ Source/Core/VideoBackends/Vulkan/Renderer.h | 2 +- Source/Core/VideoCommon/BPFunctions.cpp | 22 +++++-------------- Source/Core/VideoCommon/RenderBase.h | 2 +- 8 files changed, 17 insertions(+), 44 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 28c317d72b..1e6e7d5290 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -258,10 +258,10 @@ bool Renderer::CheckForResize() return false; } -void Renderer::SetScissorRect(const EFBRectangle& rc) +void Renderer::SetScissorRect(const MathUtil::Rectangle& rc) { - TargetRectangle trc = ConvertEFBRectangle(rc); - D3D::context->RSSetScissorRects(1, trc.AsRECT()); + const RECT rect = {rc.left, rc.top, rc.right, rc.bottom}; + D3D::context->RSSetScissorRects(1, &rect); } // This function allows the CPU to directly access the EFB. diff --git a/Source/Core/VideoBackends/D3D/Render.h b/Source/Core/VideoBackends/D3D/Render.h index 63bc8d5a53..986d80c3ce 100644 --- a/Source/Core/VideoBackends/D3D/Render.h +++ b/Source/Core/VideoBackends/D3D/Render.h @@ -27,7 +27,7 @@ public: CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; void SetBlendingState(const BlendingState& state) override; - void SetScissorRect(const EFBRectangle& rc) override; + void SetScissorRect(const MathUtil::Rectangle& rc) override; void SetRasterizationState(const RasterizationState& state) override; void SetDepthState(const DepthState& state) override; void SetTexture(u32 index, const AbstractTexture* texture) override; diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 0322fe99d8..22bfd58982 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -863,20 +863,9 @@ TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc) return result; } -// Function: This function handles the OpenGL glScissor() function -// ---------------------------- -// Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg() -// case 0x52 > SetScissorRect() -// ---------------------------- -// bpmem.scissorTL.x, y = 342x342 -// bpmem.scissorBR.x, y = 981x821 -// 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 EFBRectangle& rc) +void Renderer::SetScissorRect(const MathUtil::Rectangle& rc) { - TargetRectangle trc = ConvertEFBRectangle(rc); - glScissor(trc.left, trc.bottom, trc.GetWidth(), trc.GetHeight()); + glScissor(rc.left, rc.bottom, rc.GetWidth(), rc.GetHeight()); } void ClearEFBCache() diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index 8efde3a2a5..68e173f568 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -91,7 +91,7 @@ public: CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; void SetBlendingState(const BlendingState& state) override; - void SetScissorRect(const EFBRectangle& rc) override; + void SetScissorRect(const MathUtil::Rectangle& rc) override; void SetRasterizationState(const RasterizationState& state) override; void SetDepthState(const DepthState& state) override; void SetTexture(u32 index, const AbstractTexture* texture) override; diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index 7a882217cb..413f4bb750 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -899,14 +899,10 @@ void Renderer::SetInterlacingMode() { } -void Renderer::SetScissorRect(const EFBRectangle& rc) +void Renderer::SetScissorRect(const MathUtil::Rectangle& rc) { - TargetRectangle target_rc = ConvertEFBRectangle(rc); - - VkRect2D scissor = { - {target_rc.left, target_rc.top}, - {static_cast(target_rc.GetWidth()), static_cast(target_rc.GetHeight())}}; - + VkRect2D scissor = {{rc.left, rc.top}, + {static_cast(rc.GetWidth()), static_cast(rc.GetHeight())}}; StateTracker::GetInstance()->SetScissor(scissor); } diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.h b/Source/Core/VideoBackends/Vulkan/Renderer.h index 88102ecefd..d5a2e9ae1d 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.h +++ b/Source/Core/VideoBackends/Vulkan/Renderer.h @@ -60,7 +60,7 @@ public: void RestoreAPIState() override; void SetBlendingState(const BlendingState& state) override; - void SetScissorRect(const EFBRectangle& rc) override; + void SetScissorRect(const MathUtil::Rectangle& rc) override; void SetRasterizationState(const RasterizationState& state) override; void SetDepthState(const DepthState& state) override; void SetTexture(u32 index, const AbstractTexture* texture) override; diff --git a/Source/Core/VideoCommon/BPFunctions.cpp b/Source/Core/VideoCommon/BPFunctions.cpp index 9ae6c27730..0e4551da09 100644 --- a/Source/Core/VideoCommon/BPFunctions.cpp +++ b/Source/Core/VideoCommon/BPFunctions.cpp @@ -49,24 +49,12 @@ void SetScissor() const int xoff = bpmem.scissorOffset.x * 2; const int yoff = bpmem.scissorOffset.y * 2; - EFBRectangle rc(bpmem.scissorTL.x - xoff, bpmem.scissorTL.y - yoff, bpmem.scissorBR.x - xoff + 1, - bpmem.scissorBR.y - yoff + 1); + EFBRectangle native_rc(bpmem.scissorTL.x - xoff, bpmem.scissorTL.y - yoff, + bpmem.scissorBR.x - xoff + 1, bpmem.scissorBR.y - yoff + 1); + native_rc.ClampUL(0, 0, EFB_WIDTH, EFB_HEIGHT); - if (rc.left < 0) - rc.left = 0; - if (rc.top < 0) - rc.top = 0; - if (rc.right > EFB_WIDTH) - rc.right = EFB_WIDTH; - if (rc.bottom > EFB_HEIGHT) - rc.bottom = EFB_HEIGHT; - - if (rc.left > rc.right) - rc.right = rc.left; - if (rc.top > rc.bottom) - rc.bottom = rc.top; - - g_renderer->SetScissorRect(rc); + TargetRectangle target_rc = g_renderer->ConvertEFBRectangle(native_rc); + g_renderer->SetScissorRect(target_rc); } void SetViewport() diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 2fe6f49bbf..9ffd378d67 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -70,7 +70,7 @@ public: }; virtual void SetBlendingState(const BlendingState& state) {} - virtual void SetScissorRect(const EFBRectangle& rc) {} + virtual void SetScissorRect(const MathUtil::Rectangle& rc) {} virtual void SetRasterizationState(const RasterizationState& state) {} virtual void SetDepthState(const DepthState& state) {} virtual void SetTexture(u32 index, const AbstractTexture* texture) {}