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

Workaround for inconsistent point scaled blitting on NVIDIA

This commit is contained in:
narzoul 2022-09-24 22:13:28 +02:00
parent c7ee5206d8
commit 70b2e42640
2 changed files with 59 additions and 23 deletions

View File

@ -9,12 +9,11 @@ namespace Config
class BltFilter : public MappedSetting<UINT> class BltFilter : public MappedSetting<UINT>
{ {
public: public:
static const UINT NATIVE = 0;
static const UINT POINT = 1; static const UINT POINT = 1;
static const UINT BILINEAR = 2; static const UINT BILINEAR = 2;
BltFilter::BltFilter() BltFilter::BltFilter()
: MappedSetting("BltFilter", "point", { {"native", NATIVE}, {"point", POINT}, {"bilinear", BILINEAR}}) : MappedSetting("BltFilter", "point", { {"point", POINT}, {"bilinear", BILINEAR} })
{ {
} }
}; };

View File

@ -400,10 +400,28 @@ namespace D3dDdi
Resource& dstRes = prepareForBltDst(data); Resource& dstRes = prepareForBltDst(data);
if (!m_fixedData.Flags.ZBuffer)
{
if (D3DDDIPOOL_SYSTEMMEM != m_fixedData.Pool &&
D3DDDIPOOL_SYSTEMMEM != srcResource.m_fixedData.Pool &&
Config::Settings::BltFilter::BILINEAR == Config::bltFilter.get())
{
data.Flags.Linear = 1;
}
else
{
data.Flags.Point = 1;
}
}
if (D3DDDIPOOL_SYSTEMMEM != m_fixedData.Pool && if (D3DDDIPOOL_SYSTEMMEM != m_fixedData.Pool &&
(m_fixedData.Flags.ZBuffer && &dstRes == m_msaaSurface.resource && m_nullSurface.resource || (m_fixedData.Flags.ZBuffer && &dstRes == m_msaaSurface.resource && m_nullSurface.resource ||
m_fixedData.Flags.RenderTarget || data.Flags.SrcColorKey || m_fixedData.Flags.RenderTarget ||
data.Flags.MirrorLeftRight || data.Flags.MirrorUpDown) && !m_fixedData.Flags.ZBuffer && (
data.Flags.SrcColorKey ||
data.Flags.MirrorLeftRight || data.Flags.MirrorUpDown ||
data.DstRect.right - data.DstRect.left != data.SrcRect.right - data.SrcRect.left ||
data.DstRect.bottom - data.DstRect.top != data.SrcRect.bottom - data.SrcRect.top)) &&
SUCCEEDED(shaderBlt(data, dstRes, *srcRes))) SUCCEEDED(shaderBlt(data, dstRes, *srcRes)))
{ {
return S_OK; return S_OK;
@ -418,21 +436,6 @@ namespace D3dDdi
data.SrcRect = r; data.SrcRect = r;
} }
auto bltFilter = Config::bltFilter.get();
if (Config::Settings::BltFilter::NATIVE != bltFilter &&
D3DDDIPOOL_SYSTEMMEM != m_fixedData.Pool &&
D3DDDIPOOL_SYSTEMMEM != srcResource.m_fixedData.Pool)
{
if (Config::Settings::BltFilter::POINT == bltFilter)
{
data.Flags.Point = 1;
}
else
{
data.Flags.Linear = 1;
}
}
HRESULT result = m_device.getOrigVtable().pfnBlt(m_device, &data); HRESULT result = m_device.getOrigVtable().pfnBlt(m_device, &data);
if (D3DDDIPOOL_SYSTEMMEM == m_fixedData.Pool) if (D3DDDIPOOL_SYSTEMMEM == m_fixedData.Pool)
{ {
@ -762,7 +765,8 @@ namespace D3dDdi
std::pair<D3DDDIMULTISAMPLE_TYPE, UINT> Resource::getMultisampleConfig() std::pair<D3DDDIMULTISAMPLE_TYPE, UINT> Resource::getMultisampleConfig()
{ {
if (!m_fixedData.Flags.Texture) if (!m_fixedData.Flags.Texture &&
(!m_isPrimary || m_fixedData.Flags.RenderTarget))
{ {
return m_device.getAdapter().getMultisampleConfig(m_fixedData.Format); return m_device.getAdapter().getMultisampleConfig(m_fixedData.Format);
} }
@ -894,7 +898,23 @@ namespace D3dDdi
else else
{ {
loadVidMemResource(subResourceIndex); loadVidMemResource(subResourceIndex);
copySubResource(*m_msaaResolvedSurface.resource, *this, subResourceIndex); const bool isScaled = static_cast<LONG>(m_fixedData.pSurfList[0].Width) != m_scaledSize.cx ||
static_cast<LONG>(m_fixedData.pSurfList[0].Height) != m_scaledSize.cy;
if (m_fixedData.Flags.ZBuffer || !isScaled)
{
copySubResource(*m_msaaResolvedSurface.resource, *this, subResourceIndex);
}
else
{
D3DDDIARG_BLT blt = {};
blt.hSrcResource = *this;
blt.SrcSubResourceIndex = subResourceIndex;
blt.SrcRect = getRect(subResourceIndex);
blt.hDstResource = *m_msaaResolvedSurface.resource;
blt.DstSubResourceIndex = subResourceIndex;
blt.DstRect = m_msaaResolvedSurface.resource->getRect(subResourceIndex);
shaderBlt(blt, *m_msaaResolvedSurface.resource , *this);
}
} }
m_lockData[subResourceIndex].isMsaaResolvedUpToDate = true; m_lockData[subResourceIndex].isMsaaResolvedUpToDate = true;
} }
@ -924,7 +944,23 @@ namespace D3dDdi
if (!m_fixedData.Flags.RenderTarget || if (!m_fixedData.Flags.RenderTarget ||
Config::Settings::ResolutionScaleFilter::POINT == Config::resolutionScaleFilter.get()) Config::Settings::ResolutionScaleFilter::POINT == Config::resolutionScaleFilter.get())
{ {
copySubResource(*this, *m_msaaResolvedSurface.resource, subResourceIndex); const bool isScaled = static_cast<LONG>(m_fixedData.pSurfList[0].Width) != m_scaledSize.cx ||
static_cast<LONG>(m_fixedData.pSurfList[0].Height) != m_scaledSize.cy;
if (m_fixedData.Flags.ZBuffer || !isScaled)
{
copySubResource(*this, *m_msaaResolvedSurface.resource, subResourceIndex);
}
else
{
D3DDDIARG_BLT blt = {};
blt.hSrcResource = *m_msaaResolvedSurface.resource;
blt.SrcSubResourceIndex = subResourceIndex;
blt.SrcRect = m_msaaResolvedSurface.resource->getRect(subResourceIndex);
blt.hDstResource = *this;
blt.DstSubResourceIndex = subResourceIndex;
blt.DstRect = getRect(subResourceIndex);
shaderBlt(blt, *this, *m_msaaResolvedSurface.resource);
}
return; return;
} }
@ -1154,6 +1190,7 @@ namespace D3dDdi
!srcResource->m_fixedData.Flags.RenderTarget) !srcResource->m_fixedData.Flags.RenderTarget)
{ {
srcResource->m_lockData[data.SrcSubResourceIndex].isVidMemUpToDate = false; srcResource->m_lockData[data.SrcSubResourceIndex].isVidMemUpToDate = false;
srcResource->m_lockData[data.SrcSubResourceIndex].isMsaaResolvedUpToDate = false;
} }
srcResource = &srcResource->prepareForGpuRead(data.SrcSubResourceIndex); srcResource = &srcResource->prepareForGpuRead(data.SrcSubResourceIndex);
@ -1496,7 +1533,7 @@ namespace D3dDdi
else else
{ {
m_device.getShaderBlitter().textureBlt(*dstRes, dstIndex, dstRect, *srcRes, srcIndex, srcRect, m_device.getShaderBlitter().textureBlt(*dstRes, dstIndex, dstRect, *srcRes, srcIndex, srcRect,
D3DTEXF_POINT, data.Flags.SrcColorKey ? &ck : nullptr); data.Flags.Linear ? D3DTEXF_LINEAR : D3DTEXF_POINT, data.Flags.SrcColorKey ? &ck : nullptr);
} }
if (!m_fixedData.Flags.RenderTarget) if (!m_fixedData.Flags.RenderTarget)