From f70e2f9d32c4b806c9a7154bb357b4a276bc7c9d Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 11 May 2024 15:50:14 +0200 Subject: [PATCH] Fixed ValidateDevice --- DDrawCompat/D3dDdi/Adapter.cpp | 3 -- DDrawCompat/D3dDdi/Adapter.h | 1 - DDrawCompat/D3dDdi/Device.cpp | 62 +++++++--------------- DDrawCompat/D3dDdi/Device.h | 1 + DDrawCompat/D3dDdi/DeviceFuncs.cpp | 1 + DDrawCompat/D3dDdi/Log/DeviceFuncsLog.cpp | 6 +++ DDrawCompat/D3dDdi/Log/DeviceFuncsLog.h | 1 + DDrawCompat/D3dDdi/ShaderBlitter.cpp | 14 +---- DDrawCompat/D3dDdi/ShaderBlitter.h | 1 - DDrawCompat/DDraw/DirectDraw.cpp | 2 +- DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp | 6 --- DDrawCompat/Direct3d/Direct3d.cpp | 20 +------ DDrawCompat/Direct3d/Direct3d.h | 3 +- DDrawCompat/Dll/DllMain.cpp | 2 +- DDrawCompat/Overlay/Steam.cpp | 2 +- 15 files changed, 34 insertions(+), 91 deletions(-) diff --git a/DDrawCompat/D3dDdi/Adapter.cpp b/DDrawCompat/D3dDdi/Adapter.cpp index ab87240..c0fce79 100644 --- a/DDrawCompat/D3dDdi/Adapter.cpp +++ b/DDrawCompat/D3dDdi/Adapter.cpp @@ -103,9 +103,6 @@ namespace D3dDdi auto d3d9on12 = GetModuleHandle("d3d9on12"); info.isD3D9On12 = d3d9on12 && d3d9on12 == Compat::getModuleHandleFromAddress(m_origVtable.pfnGetCaps); - auto trinity = GetModuleHandle("igd9trinity32"); - info.isTrinity = trinity && trinity == Compat::getModuleHandleFromAddress(m_origVtable.pfnGetCaps); - info.isMsaaDepthResolveSupported = !info.isD3D9On12 && info.formatOps.find(FOURCC_RESZ) != info.formatOps.end() && diff --git a/DDrawCompat/D3dDdi/Adapter.h b/DDrawCompat/D3dDdi/Adapter.h index 10adfb1..df88c15 100644 --- a/DDrawCompat/D3dDdi/Adapter.h +++ b/DDrawCompat/D3dDdi/Adapter.h @@ -25,7 +25,6 @@ namespace D3dDdi DWORD supportedZBufferBitDepths; bool isMsaaDepthResolveSupported; bool isD3D9On12; - bool isTrinity; }; Adapter(const D3DDDIARG_OPENADAPTER& data); diff --git a/DDrawCompat/D3dDdi/Device.cpp b/DDrawCompat/D3dDdi/Device.cpp index 30f97ee..0b9b6a4 100644 --- a/DDrawCompat/D3dDdi/Device.cpp +++ b/DDrawCompat/D3dDdi/Device.cpp @@ -106,55 +106,23 @@ namespace D3dDdi UINT Device::detectColorKeyMethod() { LOG_FUNC("Device::detectColorKeyMethod"); - if (m_adapter.getInfo().isTrinity) + + auto method = Config::Settings::ColorKeyMethod::NATIVE; + if (m_adapter.getInfo().isD3D9On12) { - LOG_ONCE("Auto-detected ColorKeyMethod: alphatest"); - return LOG_RESULT(Config::Settings::ColorKeyMethod::ALPHATEST); - } - - auto method = Config::Settings::ColorKeyMethod::NONE; - - auto& repo = getRepo(); - SurfaceRepository::Surface tex; - SurfaceRepository::Surface rt; - repo.getTempSurface(tex, 1, 1, D3DDDIFMT_R5G6B5, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY); - repo.getTempSurface(rt, 1, 1, D3DDDIFMT_R5G6B5, DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY); - - if (tex.resource && rt.resource) - { - DDSURFACEDESC2 desc = {}; - desc.dwSize = sizeof(desc); - tex.surface->Lock(tex.surface, nullptr, &desc, DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT, nullptr); - if (desc.lpSurface) - { - const WORD testColor = static_cast(getFormatInfo(D3DDDIFMT_R5G6B5).pixelFormat.dwGBitMask); - static_cast(desc.lpSurface)[0] = testColor; - tex.surface->Unlock(tex.surface, nullptr); - - m_shaderBlitter.colorKeyTestBlt(*rt.resource, *tex.resource); - - desc = {}; - desc.dwSize = sizeof(desc); - rt.surface->Lock(rt.surface, nullptr, &desc, DDLOCK_READONLY | DDLOCK_WAIT, nullptr); - if (desc.lpSurface) - { - method = testColor == static_cast(desc.lpSurface)[0] - ? Config::Settings::ColorKeyMethod::ALPHATEST - : Config::Settings::ColorKeyMethod::NATIVE; - rt.surface->Unlock(rt.surface, nullptr); - } - } - } - - if (Config::Settings::ColorKeyMethod::NONE == method) - { - LOG_ONCE("Auto-detected ColorKeyMethod: unknown, using native"); + method = Config::Settings::ColorKeyMethod::ALPHATEST; } else { - LOG_ONCE("Auto-detected ColorKeyMethod: " << - (Config::Settings::ColorKeyMethod::NATIVE == method ? "native" : "alphatest")); + auto trinity = GetModuleHandle("igd9trinity32"); + if (trinity && trinity == Compat::getModuleHandleFromAddress(m_origVtable.pfnDrawPrimitive)) + { + method = Config::Settings::ColorKeyMethod::ALPHATEST; + } } + + LOG_ONCE("Auto-detected ColorKeyMethod: " << + (Config::Settings::ColorKeyMethod::NATIVE == method ? "native" : "alphatest")); return LOG_RESULT(method); } @@ -558,6 +526,12 @@ namespace D3dDdi return S_OK; } + HRESULT Device::pfnValidateDevice(D3DDDIARG_VALIDATETEXTURESTAGESTATE* data) + { + m_state.flush(); + return m_origVtable.pfnValidateDevice(m_device, data); + } + void Device::updateAllConfig() { g_isConfigUpdatePending = true; diff --git a/DDrawCompat/D3dDdi/Device.h b/DDrawCompat/D3dDdi/Device.h index 1ae222c..7c598ec 100644 --- a/DDrawCompat/D3dDdi/Device.h +++ b/DDrawCompat/D3dDdi/Device.h @@ -52,6 +52,7 @@ namespace D3dDdi HRESULT pfnSetPalette(const D3DDDIARG_SETPALETTE* data); HRESULT pfnUnlock(const D3DDDIARG_UNLOCK* data); HRESULT pfnUpdatePalette(const D3DDDIARG_UPDATEPALETTE* data, const PALETTEENTRY* paletteData); + HRESULT pfnValidateDevice(D3DDDIARG_VALIDATETEXTURESTAGESTATE* data); Adapter& getAdapter() const { return m_adapter; } std::pair getColorKeyMethod(); diff --git a/DDrawCompat/D3dDdi/DeviceFuncs.cpp b/DDrawCompat/D3dDdi/DeviceFuncs.cpp index e15030f..5bf21fd 100644 --- a/DDrawCompat/D3dDdi/DeviceFuncs.cpp +++ b/DDrawCompat/D3dDdi/DeviceFuncs.cpp @@ -69,6 +69,7 @@ namespace SET_DEVICE_FUNC(pfnSetPalette); SET_DEVICE_FUNC(pfnUnlock); SET_DEVICE_FUNC(pfnUpdatePalette); + SET_DEVICE_FUNC(pfnValidateDevice); SET_DEVICE_STATE_FUNC(pfnCreatePixelShader); SET_DEVICE_STATE_FUNC(pfnCreateVertexShaderDecl); diff --git a/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.cpp b/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.cpp index 2c2b21f..93f65aa 100644 --- a/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.cpp +++ b/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.cpp @@ -318,6 +318,12 @@ std::ostream& operator<<(std::ostream& os, const D3DDDIARG_UPDATEPALETTE& val) << val.NumEntries; } +std::ostream& operator<<(std::ostream& os, const D3DDDIARG_VALIDATETEXTURESTAGESTATE& val) +{ + return Compat::LogStruct(os) + << val.NumPasses; +} + std::ostream& operator<<(std::ostream& os, const D3DDDIARG_VIEWPORTINFO& val) { return Compat::LogStruct(os) diff --git a/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.h b/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.h index fad5a07..014e383 100644 --- a/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.h +++ b/DDrawCompat/D3dDdi/Log/DeviceFuncsLog.h @@ -39,6 +39,7 @@ std::ostream& operator<<(std::ostream& os, const D3DDDIARG_TEXBLT1& val); std::ostream& operator<<(std::ostream& os, const D3DDDIARG_TEXTURESTAGESTATE& val); std::ostream& operator<<(std::ostream& os, const D3DDDIARG_UNLOCK& val); std::ostream& operator<<(std::ostream& os, const D3DDDIARG_UPDATEPALETTE& val); +std::ostream& operator<<(std::ostream& os, const D3DDDIARG_VALIDATETEXTURESTAGESTATE& val); std::ostream& operator<<(std::ostream& os, const D3DDDIARG_VIEWPORTINFO& val); std::ostream& operator<<(std::ostream& os, const D3DDDIARG_WINFO& val); std::ostream& operator<<(std::ostream& os, const D3DDDIARG_ZRANGE& val); diff --git a/DDrawCompat/D3dDdi/ShaderBlitter.cpp b/DDrawCompat/D3dDdi/ShaderBlitter.cpp index 0c6c55a..213db6e 100644 --- a/DDrawCompat/D3dDdi/ShaderBlitter.cpp +++ b/DDrawCompat/D3dDdi/ShaderBlitter.cpp @@ -32,7 +32,6 @@ namespace { const UINT BLT_SRCALPHA = 1; const UINT BLT_PREMULTIPLIED = 2; - const UINT BLT_COLORKEYTEST = 4; const UINT CF_HORIZONTAL = 1; const UINT CF_GAMMARAMP = 2; @@ -225,7 +224,7 @@ namespace D3dDdi state.setTempRenderState({ D3DDDIRS_DITHERENABLE, FALSE }); state.setTempRenderState({ D3DDDIRS_ALPHABLENDENABLE, (flags & BLT_SRCALPHA) || alpha }); state.setTempRenderState({ D3DDDIRS_FOGENABLE, FALSE }); - state.setTempRenderState({ D3DDDIRS_COLORKEYENABLE, 0 != (flags & BLT_COLORKEYTEST) }); + state.setTempRenderState({ D3DDDIRS_COLORKEYENABLE, FALSE }); state.setTempRenderState({ D3DDDIRS_STENCILENABLE, FALSE }); state.setTempRenderState({ D3DDDIRS_CLIPPING, FALSE }); state.setTempRenderState({ D3DDDIRS_CLIPPLANEENABLE, 0 }); @@ -255,11 +254,6 @@ namespace D3dDdi setTempTextureStage(0, srcResource, srcSubResourceIndex, srcRect, LOWORD(filter) | (srgbRead ? D3DTEXF_SRGBREAD : 0)); - if (flags & BLT_COLORKEYTEST) - { - const DWORD testColor = getFormatInfo(D3DDDIFMT_R5G6B5).pixelFormat.dwGBitMask; - state.setTempTextureStageState({ 0, D3DDDITSS_TEXTURECOLORKEYVAL, testColor }); - } state.setTempStreamSourceUm({ 0, sizeof(Vertex) }, m_vertices.data()); @@ -294,12 +288,6 @@ namespace D3dDdi m_psColorKeyBlend.get(), D3DTEXF_POINT); } - void ShaderBlitter::colorKeyTestBlt(const Resource& dstResource, const Resource& srcResource) - { - blt(dstResource, 0, dstResource.getRect(0), srcResource, 0, srcResource.getRect(0), - m_psTextureSampler.get(), D3DTEXF_POINT, BLT_COLORKEYTEST); - } - void ShaderBlitter::convolution(const Resource& dstResource, UINT dstSubResourceIndex, const RECT& dstRect, const Resource& srcResource, UINT srcSubResourceIndex, const RECT& srcRect, Float2 support, HANDLE pixelShader, const std::function setExtraParams, DWORD flags) diff --git a/DDrawCompat/D3dDdi/ShaderBlitter.h b/DDrawCompat/D3dDdi/ShaderBlitter.h index 30b6955..5298977 100644 --- a/DDrawCompat/D3dDdi/ShaderBlitter.h +++ b/DDrawCompat/D3dDdi/ShaderBlitter.h @@ -40,7 +40,6 @@ namespace D3dDdi const Resource& srcResource, UINT srcSubResourceIndex, const RECT& srcRect, UINT blurPercent); void colorKeyBlt(const Resource& dstResource, UINT dstSubResourceIndex, const Resource& srcResource, UINT srcSubResourceIndex, ColorKeyInfo srcColorKey); - void colorKeyTestBlt(const Resource& dstResource, const Resource& srcResource); void cursorBlt(const Resource& dstResource, UINT dstSubResourceIndex, const RECT& dstRect, HCURSOR cursor, POINT pt); void depthBlt(const Resource& dstResource, const RECT& dstRect, diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index 394ffc3..668cb8b 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -347,7 +347,7 @@ namespace DDraw { return; } - repo.get()->lpVtbl->SetCooperativeLevel(repo, nullptr, DDSCL_NORMAL); + repo.get()->lpVtbl->SetCooperativeLevel(repo, nullptr, DDSCL_NORMAL | DDSCL_FPUPRESERVE); it = repositories.insert({ adapterInfo.luid, repo }).first; D3dDdi::Adapter::setRepository(adapterInfo.luid, guid, it->second); repo.detach(); diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index febcdfc..55e581a 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -7,12 +7,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include @@ -264,10 +262,6 @@ namespace DDraw result = getOrigVtable(This).QueryInterface(This, iid, obp); m_data->setSizeOverride(0, 0); } - if (SUCCEEDED(result)) - { - Direct3d::onCreateDevice(iid, *m_data->m_surface); - } return result; } diff --git a/DDrawCompat/Direct3d/Direct3d.cpp b/DDrawCompat/Direct3d/Direct3d.cpp index ce74d2a..f097a04 100644 --- a/DDrawCompat/Direct3d/Direct3d.cpp +++ b/DDrawCompat/Direct3d/Direct3d.cpp @@ -6,9 +6,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -49,13 +47,12 @@ namespace } } - if (SUCCEEDED(result)) + if constexpr (std::is_same_v) { - if constexpr (std::is_same_v) + if (SUCCEEDED(result)) { Direct3d::Direct3dDevice::hookVtable(*(*lplpD3DDevice)->lpVtbl); } - Direct3d::onCreateDevice(iid, *CompatPtr::from(lpDDS)); } return result; } @@ -151,19 +148,6 @@ namespace Direct3d return g_vbDesc; } - void onCreateDevice(const IID& iid, IDirectDrawSurface7& surface) - { - if (IID_IDirect3DHALDevice == iid || IID_IDirect3DTnLHalDevice == iid) - { - auto device = D3dDdi::Device::findDeviceByResource( - DDraw::DirectDrawSurface::getDriverResourceHandle(surface)); - if (device) - { - device->getState().flush(); - } - } - } - const IID& replaceDevice(const IID& iid) { if (IID_IDirect3DRampDevice != iid && diff --git a/DDrawCompat/Direct3d/Direct3d.h b/DDrawCompat/Direct3d/Direct3d.h index 76596e8..c642a28 100644 --- a/DDrawCompat/Direct3d/Direct3d.h +++ b/DDrawCompat/Direct3d/Direct3d.h @@ -1,13 +1,12 @@ #pragma once -#include +#include #include namespace Direct3d { D3DVERTEXBUFFERDESC getVertexBufferDesc(); - void onCreateDevice(const IID& iid, IDirectDrawSurface7& surface); const IID& replaceDevice(const IID& iid); namespace Direct3d diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index 1840bf3..0907f80 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -116,7 +116,7 @@ namespace if (SUCCEEDED(result)) { CompatVtable::s_origVtable = *dd7.get()->lpVtbl; - dd7->SetCooperativeLevel(dd7, nullptr, DDSCL_NORMAL); + dd7->SetCooperativeLevel(dd7, nullptr, DDSCL_NORMAL | DDSCL_FPUPRESERVE); } if (FAILED(result)) { diff --git a/DDrawCompat/Overlay/Steam.cpp b/DDrawCompat/Overlay/Steam.cpp index cb1c4cd..d3c2c9e 100644 --- a/DDrawCompat/Overlay/Steam.cpp +++ b/DDrawCompat/Overlay/Steam.cpp @@ -224,7 +224,7 @@ namespace return false; } - result = g_dd->lpVtbl->SetCooperativeLevel(g_dd, nullptr, DDSCL_NORMAL); + result = g_dd->lpVtbl->SetCooperativeLevel(g_dd, nullptr, DDSCL_NORMAL | DDSCL_FPUPRESERVE); if (FAILED(result)) { LOG_ONCE("Failed to set cooperative level for Steam overlay: " << Compat::hex(result));