1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Fixed ValidateDevice

This commit is contained in:
narzoul 2024-05-11 15:50:14 +02:00
parent f7ea662c47
commit f70e2f9d32
15 changed files with 34 additions and 91 deletions

View File

@ -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() &&

View File

@ -25,7 +25,6 @@ namespace D3dDdi
DWORD supportedZBufferBitDepths;
bool isMsaaDepthResolveSupported;
bool isD3D9On12;
bool isTrinity;
};
Adapter(const D3DDDIARG_OPENADAPTER& data);

View File

@ -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<WORD>(getFormatInfo(D3DDDIFMT_R5G6B5).pixelFormat.dwGBitMask);
static_cast<WORD*>(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<WORD*>(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;

View File

@ -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<UINT, UINT> getColorKeyMethod();

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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<void(bool)> setExtraParams, DWORD flags)

View File

@ -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,

View File

@ -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();

View File

@ -7,12 +7,10 @@
#include <Common/CompatPtr.h>
#include <D3dDdi/Device.h>
#include <D3dDdi/Resource.h>
#include <D3dDdi/SurfaceRepository.h>
#include <DDraw/DirectDrawClipper.h>
#include <DDraw/DirectDrawSurface.h>
#include <DDraw/LogUsedResourceFormat.h>
#include <DDraw/RealPrimarySurface.h>
#include <DDraw/Surfaces/PrimarySurface.h>
#include <DDraw/Surfaces/Surface.h>
#include <DDraw/Surfaces/SurfaceImpl.h>
#include <Direct3d/Direct3d.h>
@ -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;
}

View File

@ -6,9 +6,7 @@
#include <Config/Settings/SoftwareDevice.h>
#include <Config/Settings/SupportedDepthFormats.h>
#include <Config/Settings/VertexBufferMemoryType.h>
#include <D3dDdi/Device.h>
#include <D3dDdi/FormatInfo.h>
#include <DDraw/DirectDrawSurface.h>
#include <DDraw/LogUsedResourceFormat.h>
#include <DDraw/ScopedThreadLock.h>
#include <DDraw/Surfaces/Surface.h>
@ -49,13 +47,12 @@ namespace
}
}
if (SUCCEEDED(result))
if constexpr (std::is_same_v<TDirect3d, IDirect3D7>)
{
if constexpr (std::is_same_v<TDirect3d, IDirect3D7>)
if (SUCCEEDED(result))
{
Direct3d::Direct3dDevice::hookVtable(*(*lplpD3DDevice)->lpVtbl);
}
Direct3d::onCreateDevice(iid, *CompatPtr<IDirectDrawSurface7>::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 &&

View File

@ -1,13 +1,12 @@
#pragma once
#include <ddraw.h>
#include <d3d.h>
#include <Direct3d/Log.h>
namespace Direct3d
{
D3DVERTEXBUFFERDESC getVertexBufferDesc();
void onCreateDevice(const IID& iid, IDirectDrawSurface7& surface);
const IID& replaceDevice(const IID& iid);
namespace Direct3d

View File

@ -116,7 +116,7 @@ namespace
if (SUCCEEDED(result))
{
CompatVtable<IDirectDraw7Vtbl>::s_origVtable = *dd7.get()->lpVtbl;
dd7->SetCooperativeLevel(dd7, nullptr, DDSCL_NORMAL);
dd7->SetCooperativeLevel(dd7, nullptr, DDSCL_NORMAL | DDSCL_FPUPRESERVE);
}
if (FAILED(result))
{

View File

@ -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));