From 47555f1ddaf665805219456e856a1985e05289f4 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Thu, 9 Jan 2020 03:29:58 +0000 Subject: [PATCH] [d3d9] Add GetSurfaceExtent helper --- src/d3d9/d3d9_device.cpp | 18 ++++++++---------- src/d3d9/d3d9_surface.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 15cf72675..711d98512 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -1134,22 +1134,21 @@ namespace dxvk { return D3DERR_INVALIDCALL; if (RenderTargetIndex == 0) { - uint32_t width = std::max(1u, desc->Width >> rt->GetMipLevel()); - uint32_t height = std::max(1u, desc->Height >> rt->GetMipLevel()); + auto rtSize = rt->GetSurfaceExtent(); D3DVIEWPORT9 viewport; viewport.X = 0; viewport.Y = 0; - viewport.Width = width; - viewport.Height = height; + viewport.Width = rtSize.width; + viewport.Height = rtSize.height; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; RECT scissorRect; scissorRect.left = 0; scissorRect.top = 0; - scissorRect.right = width; - scissorRect.bottom = height; + scissorRect.right = rtSize.width; + scissorRect.bottom = rtSize.height; if (m_state.viewport != viewport) { m_flags.set(D3D9DeviceFlag::DirtyFFViewport); @@ -1398,11 +1397,10 @@ namespace dxvk { // This works around that. uint32_t alignment = m_d3d9Options.lenientClear ? 8 : 1; - uint32_t rt0Width = std::max(1u, rt0Desc->Width >> m_state.renderTargets[0]->GetMipLevel()); - uint32_t rt0Height = std::max(1u, rt0Desc->Height >> m_state.renderTargets[0]->GetMipLevel()); + auto rtSize = m_state.renderTargets[0]->GetSurfaceExtent(); - bool extentMatches = align(extent.width, alignment) == align(rt0Width, alignment) - && align(extent.height, alignment) == align(rt0Height, alignment); + bool extentMatches = align(extent.width, alignment) == align(rtSize.width, alignment) + && align(extent.height, alignment) == align(rtSize.height, alignment); bool rtSizeMatchesClearSize = offset.x == 0 && offset.y == 0 && extentMatches; diff --git a/src/d3d9/d3d9_surface.h b/src/d3d9/d3d9_surface.h index 27b57bcff..7161c3a9a 100644 --- a/src/d3d9/d3d9_surface.h +++ b/src/d3d9/d3d9_surface.h @@ -6,6 +6,8 @@ #include "../util/util_gdi.h" +#include + namespace dxvk { using D3D9GDIDesc = D3DKMT_DESTROYDCFROMMEMORY; @@ -45,6 +47,15 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE ReleaseDC(HDC hDC) final; + inline VkExtent2D GetSurfaceExtent() const { + const auto* desc = m_texture->Desc(); + + return VkExtent2D { + std::max(1u, desc->Width >> GetMipLevel()), + std::max(1u, desc->Height >> GetMipLevel()) + }; + } + private: D3D9GDIDesc m_dcDesc;