From 46471a6ad8e5f6b2aecaa7f558661bfdb3a5132a Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Wed, 5 Mar 2025 12:48:30 +0200 Subject: [PATCH] [d3d9] Validate block aligned format mip > 0 dimensions as well --- src/d3d9/d3d9_surface.cpp | 10 +++++----- src/d3d9/d3d9_volume.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/d3d9/d3d9_surface.cpp b/src/d3d9/d3d9_surface.cpp index 14cbd2f0a..ca46eb1c0 100644 --- a/src/d3d9/d3d9_surface.cpp +++ b/src/d3d9/d3d9_surface.cpp @@ -119,7 +119,7 @@ namespace dxvk { pDesc->MultiSampleType = desc.MultiSample; pDesc->MultiSampleQuality = desc.MultisampleQuality; - pDesc->Width = std::max(1u, desc.Width >> m_mipLevel); + pDesc->Width = std::max(1u, desc.Width >> m_mipLevel); pDesc->Height = std::max(1u, desc.Height >> m_mipLevel); return D3D_OK; @@ -148,9 +148,9 @@ namespace dxvk { bool isBlockAlignedFormat = blockSize.Width > 0 && blockSize.Height > 0; // The boundaries of pRect are validated for D3DPOOL_DEFAULT surfaces - // with formats which need to be block aligned (mip 0), surfaces created via + // with formats which need to be block aligned, surfaces created via // CreateImageSurface and D3D8 cube textures outside of D3DPOOL_DEFAULT - if ((m_mipLevel == 0 && isBlockAlignedFormat && desc.Pool == D3DPOOL_DEFAULT) + if ((isBlockAlignedFormat && desc.Pool == D3DPOOL_DEFAULT) || (desc.Pool == D3DPOOL_SYSTEMMEM && type == D3DRTYPE_SURFACE) || (m_texture->Device()->IsD3D8Compatible() && desc.Pool != D3DPOOL_DEFAULT && type == D3DRTYPE_CUBETEXTURE)) { @@ -161,8 +161,8 @@ namespace dxvk { || pRect->right - pRect->left <= 0 || pRect->bottom - pRect->top <= 0 // Exceeding surface dimensions - || static_cast(pRect->right) > desc.Width - || static_cast(pRect->bottom) > desc.Height) + || static_cast(pRect->right) > std::max(1u, desc.Width >> m_mipLevel) + || static_cast(pRect->bottom) > std::max(1u, desc.Height >> m_mipLevel)) return D3DERR_INVALIDCALL; } diff --git a/src/d3d9/d3d9_volume.cpp b/src/d3d9/d3d9_volume.cpp index 48e988725..3362e813d 100644 --- a/src/d3d9/d3d9_volume.cpp +++ b/src/d3d9/d3d9_volume.cpp @@ -119,9 +119,9 @@ namespace dxvk { || static_cast(pBox->Bottom) - static_cast(pBox->Top) <= 0 || static_cast(pBox->Back) - static_cast(pBox->Front) <= 0 // Exceeding surface dimensions - || pBox->Right > desc.Width - || pBox->Bottom > desc.Height - || pBox->Back > desc.Depth) + || pBox->Right > std::max(1u, desc.Width >> m_mipLevel) + || pBox->Bottom > std::max(1u, desc.Height >> m_mipLevel) + || pBox->Back > std::max(1u, desc.Depth >> m_mipLevel)) return D3DERR_INVALIDCALL; }