Skip to content

Commit

Permalink
[d3d8] Validate viewport dimensions on SetViewport
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Sep 7, 2024
1 parent daccde7 commit 292383a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,31 @@ namespace dxvk {
}

HRESULT STDMETHODCALLTYPE D3D8Device::SetViewport(const D3DVIEWPORT8* pViewport) {
if (likely(pViewport != nullptr)) {
HRESULT res;

// get the D3D9 render target if we haven't cached it yet
if (unlikely(m_renderTarget == nullptr)) {
Com<d3d9::IDirect3DSurface9> pRT9 = nullptr;
res = GetD3D9()->GetRenderTarget(0, &pRT9); // use RT index 0

if (likely(SUCCEEDED(res)))
m_renderTarget = new D3D8Surface(this, std::move(pRT9));
}

if (likely(m_renderTarget != nullptr)) {
D3DSURFACE_DESC rtDesc;
res = m_renderTarget->GetDesc(&rtDesc);

// D3D8 will fail when setting a viewport that's outside of the
// current render target, although this apparently works in D3D9
if (likely(SUCCEEDED(res)) &&
unlikely(pViewport->Width > rtDesc.Width ||
pViewport->Height > rtDesc.Height))
return D3DERR_INVALIDCALL;
}
}

StateChange();
return GetD3D9()->SetViewport(reinterpret_cast<const d3d9::D3DVIEWPORT9*>(pViewport));
}
Expand Down

0 comments on commit 292383a

Please sign in to comment.