From 423c86bf5e7cf320e9a17098042a7d645baa920f Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Tue, 19 Nov 2024 16:13:14 +0200 Subject: [PATCH] [d3d8] Validate DS dimensions on SetRenderTarget --- src/d3d8/d3d8_device.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/d3d8/d3d8_device.cpp b/src/d3d8/d3d8_device.cpp index b4aee77e..a1925cb7 100644 --- a/src/d3d8/d3d8_device.cpp +++ b/src/d3d8/d3d8_device.cpp @@ -935,15 +935,31 @@ namespace dxvk { // SetDepthStencilSurface is a separate call D3D8Surface* zStencil = static_cast(pNewZStencil); - if (likely(m_depthStencil != zStencil)) { - StateChange(); - res = GetD3D9()->SetDepthStencilSurface(D3D8Surface::GetD3D9Nullable(zStencil)); + // Depth stencil dimensions can not be lower than + // those of the currently set render target. + if (m_renderTarget != nullptr && zStencil != nullptr) { + D3DSURFACE_DESC rtDesc; + res = m_renderTarget->GetDesc(&rtDesc); if (unlikely(FAILED(res))) return res; - m_depthStencil = zStencil; + D3DSURFACE_DESC dsDesc; + res = zStencil->GetDesc(&dsDesc); + + if (unlikely(FAILED(res))) return res; + + if (unlikely(dsDesc.Width < rtDesc.Width + || dsDesc.Height < rtDesc.Height)) + return D3DERR_INVALIDCALL; } + StateChange(); + res = GetD3D9()->SetDepthStencilSurface(D3D8Surface::GetD3D9Nullable(zStencil)); + + if (unlikely(FAILED(res))) return res; + + m_depthStencil = zStencil; + return D3D_OK; }