From 912a530d1cf6668f48f7f266547fbfb925ca80ff Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Fri, 4 Oct 2024 18:42:08 +0300 Subject: [PATCH] [d3d9] Enforce various CheckDeviceMultiSampleType validations --- src/d3d9/d3d9_adapter.cpp | 13 ++++++++++++- src/d3d9/d3d9_device.cpp | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/d3d9/d3d9_adapter.cpp b/src/d3d9/d3d9_adapter.cpp index f44bab70a..75120417b 100644 --- a/src/d3d9/d3d9_adapter.cpp +++ b/src/d3d9/d3d9_adapter.cpp @@ -186,6 +186,12 @@ namespace dxvk { if (pQualityLevels != nullptr) *pQualityLevels = 1; + if (unlikely(MultiSampleType > D3DMULTISAMPLE_16_SAMPLES)) + return D3DERR_INVALIDCALL; + + if (unlikely(SurfaceFormat == D3D9Format::Unknown)) + return D3DERR_INVALIDCALL; + auto dst = ConvertFormatUnfixed(SurfaceFormat); if (dst.FormatColor == VK_FORMAT_UNDEFINED) return D3DERR_NOTAVAILABLE; @@ -194,7 +200,12 @@ namespace dxvk { && (SurfaceFormat == D3D9Format::D32_LOCKABLE || SurfaceFormat == D3D9Format::D32F_LOCKABLE || SurfaceFormat == D3D9Format::D16_LOCKABLE - || SurfaceFormat == D3D9Format::INTZ)) + || SurfaceFormat == D3D9Format::INTZ + || SurfaceFormat == D3D9Format::DXT1 + || SurfaceFormat == D3D9Format::DXT2 + || SurfaceFormat == D3D9Format::DXT3 + || SurfaceFormat == D3D9Format::DXT4 + || SurfaceFormat == D3D9Format::DXT5)) return D3DERR_NOTAVAILABLE; uint32_t sampleCount = std::max(MultiSampleType, 1u); diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 37a49ea0d..588b75886 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -3948,6 +3948,15 @@ namespace dxvk { if (unlikely(ppSurface == nullptr)) return D3DERR_INVALIDCALL; + if (unlikely(MultiSample > D3DMULTISAMPLE_16_SAMPLES)) + return D3DERR_INVALIDCALL; + + uint32_t sampleCount = std::max(MultiSample, 1u); + + // Check if this is a power of two... + if (sampleCount & (sampleCount - 1)) + return D3DERR_NOTAVAILABLE; + D3D9_COMMON_TEXTURE_DESC desc; desc.Width = Width; desc.Height = Height;