From 4f98844f479f4466ebb161100a292fb13405f363 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Tue, 19 Nov 2024 13:51:40 +0200 Subject: [PATCH] [d3d9] Skip some validations for D3DDEVTYPE_NULLREF devices --- src/d3d9/d3d9_device.cpp | 23 ++++++++++++++--------- src/d3d9/d3d9_interface.cpp | 16 +++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 938d4d65..8cca6cc0 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -476,10 +476,15 @@ namespace dxvk { Logger::info("Device reset"); m_deviceLostState = D3D9DeviceLostState::Ok; - HRESULT hr = m_parent->ValidatePresentationParameters(pPresentationParameters); + HRESULT hr; + // Black Desert creates a D3DDEVTYPE_NULLREF device and + // expects reset to work despite passing invalid parameters. + if (likely(m_deviceType != D3DDEVTYPE_NULLREF)) { + hr = m_parent->ValidatePresentationParameters(pPresentationParameters); - if (unlikely(FAILED(hr))) - return hr; + if (unlikely(FAILED(hr))) + return hr; + } if (!IsExtended()) { // The internal references are always cleared, regardless of whether the Reset call succeeds. @@ -8304,12 +8309,12 @@ namespace dxvk { " - Windowed: ", pPresentationParameters->Windowed ? "true" : "false", "\n", " - Swap effect: ", pPresentationParameters->SwapEffect, "\n")); - // Black Desert creates a device with a NULL hDeviceWindow and - // seemingly expects this validation to not prevent a swapchain reset. - if (pPresentationParameters->hDeviceWindow != nullptr && - !pPresentationParameters->Windowed && - (pPresentationParameters->BackBufferWidth == 0 - || pPresentationParameters->BackBufferHeight == 0)) { + // Black Desert creates a D3DDEVTYPE_NULLREF device and + // expects this validation to not prevent a swapchain reset. + if (likely(m_deviceType != D3DDEVTYPE_NULLREF) && + unlikely(!pPresentationParameters->Windowed && + (pPresentationParameters->BackBufferWidth == 0 + || pPresentationParameters->BackBufferHeight == 0))) { return D3DERR_INVALIDCALL; } diff --git a/src/d3d9/d3d9_interface.cpp b/src/d3d9/d3d9_interface.cpp index 12ec02f2..1d3946cf 100644 --- a/src/d3d9/d3d9_interface.cpp +++ b/src/d3d9/d3d9_interface.cpp @@ -360,10 +360,15 @@ namespace dxvk { !(BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING))) return D3DERR_INVALIDCALL; - HRESULT hr = ValidatePresentationParameters(pPresentationParameters); + HRESULT hr; + // Black Desert creates a D3DDEVTYPE_NULLREF device and + // expects it be created despite passing invalid parameters. + if (likely(DeviceType != D3DDEVTYPE_NULLREF)) { + hr = ValidatePresentationParameters(pPresentationParameters); - if (unlikely(FAILED(hr))) - return hr; + if (unlikely(FAILED(hr))) + return hr; + } auto* adapter = GetAdapter(Adapter); @@ -421,10 +426,7 @@ namespace dxvk { } // The swap effect value can not be 0. - // Black Desert sets this to 0 with a NULL hDeviceWindow - // and expects device creation to succeed. - if (unlikely(pPresentationParameters->hDeviceWindow != nullptr - && !pPresentationParameters->SwapEffect)) + if (unlikely(!pPresentationParameters->SwapEffect)) return D3DERR_INVALIDCALL; // D3DSWAPEFFECT_COPY can not be used with more than one back buffer.