Merge pull request #1648 from LukeUsher/fix-viewport-resolution-change

Fix black screen in some titles when switching resolutions during gameplay
This commit is contained in:
RadWolfie 2019-07-04 21:01:43 -05:00 committed by GitHub
commit 4574b4bbdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 5 deletions

View File

@ -3207,15 +3207,40 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetViewport)
DWORD top = std::max((int)pViewport->Y, 0);
DWORD right = std::min((int)pViewport->X + (int)pViewport->Width, (int)XboxRenderTarget_Width);
DWORD bottom = std::min((int)pViewport->Y + (int)pViewport->Height, (int)XboxRenderTarget_Height);
DWORD width = right - left;
DWORD height = bottom - top;
XboxViewPort.X = left;
XboxViewPort.Y = top;
XboxViewPort.Width = right - left;
XboxViewPort.Height = bottom - top;
XboxViewPort.Width = width;
XboxViewPort.Height = height;
XboxViewPort.MinZ = pViewport->MinZ;
XboxViewPort.MaxZ = pViewport->MaxZ;
if (g_ScaleViewport) {
// This operation is often used to change the display resolution without calling SetRenderTarget!
// This works by updating the underlying Width & Height of the Xbox surface, without reallocating the data
// Because of this, we need to validate that the associated host resource still matches the dimensions of the Xbox Render Target
// If not, we must force them to be re-created
// TEST CASE: Chihiro Factory Test Program
DWORD HostRenderTarget_Width = 0, HostRenderTarget_Height = 0;
GetHostRenderTargetDimensions(&HostRenderTarget_Width, &HostRenderTarget_Height);
if (HostRenderTarget_Width != XboxRenderTarget_Width || HostRenderTarget_Height != XboxRenderTarget_Height) {
LOG_TEST_CASE("RenderTarget width/height changed without calling SetRenderTarget");
// NOTE: If the host backbuffer hack is enabled, we must skip this operation for the back buffer, otherwise everything will break
// In that situation, there's nothing we can do without causing damage.
if (!g_DirectHostBackBufferAccess && g_pXboxRenderTarget != g_XboxBackBufferSurface) {
FreeHostResource(GetHostResourceKey(g_pXboxRenderTarget)); g_pD3DDevice->SetRenderTarget(0, GetHostSurface(g_pXboxRenderTarget, D3DUSAGE_RENDERTARGET));
FreeHostResource(GetHostResourceKey(g_pXboxDepthStencil)); g_pD3DDevice->SetDepthStencilSurface(GetHostSurface(g_pXboxRenderTarget, D3DUSAGE_DEPTHSTENCIL));
}
}
// Store the updated viewport data ready to pass to host SetViewPort
HostViewPort = XboxViewPort;
// We *must* scale the viewport when using the DirectHostBackBuffer hack for the backbuffer render target
// Otherwise, we only get partial screen updates
if (g_ScaleViewport || (g_DirectHostBackBufferAccess && g_pXboxRenderTarget == g_XboxBackBufferSurface)) {
// Get current host render target dimensions
DWORD HostRenderTarget_Width;
DWORD HostRenderTarget_Height;
@ -3229,8 +3254,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetViewport)
// TODO : Fix test-case Shenmue 2 (which halves height, leaving the bottom half unused)
HostViewPort.MinZ = XboxViewPort.MinZ; // No need scale Z for now
HostViewPort.MaxZ = XboxViewPort.MaxZ;
}
else {
} else {
EmuLog(LOG_LEVEL::WARNING, "GetHostRenderTargetDimensions failed - SetViewport sets Xbox viewport instead!");
}
}