From 28a07ef44596f83e6eaa9838d1b84872f5f6336d Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Sun, 25 Jul 2021 15:12:25 +0200 Subject: [PATCH] [d3d9] Validate vertex declaration on draws --- src/d3d9/d3d9_device.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 1cd82557..b15632d3 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -2369,11 +2369,14 @@ namespace dxvk { D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) { - if (unlikely(!PrimitiveCount)) - return S_OK; - D3D9DeviceLock lock = LockDevice(); + if (unlikely(m_state.vertexDecl == nullptr)) + return D3DERR_INVALIDCALL; + + if (unlikely(!PrimitiveCount)) + return S_OK; + PrepareDraw(PrimitiveType); EmitCs([this, @@ -2402,11 +2405,14 @@ namespace dxvk { UINT NumVertices, UINT StartIndex, UINT PrimitiveCount) { - if (unlikely(!PrimitiveCount)) - return S_OK; - D3D9DeviceLock lock = LockDevice(); + if (unlikely(m_state.vertexDecl == nullptr)) + return D3DERR_INVALIDCALL; + + if (unlikely(!PrimitiveCount)) + return S_OK; + PrepareDraw(PrimitiveType); EmitCs([this, @@ -2435,11 +2441,14 @@ namespace dxvk { UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride) { - if (unlikely(!PrimitiveCount)) - return S_OK; - D3D9DeviceLock lock = LockDevice(); + if (unlikely(m_state.vertexDecl == nullptr)) + return D3DERR_INVALIDCALL; + + if (unlikely(!PrimitiveCount)) + return S_OK; + PrepareDraw(PrimitiveType); auto drawInfo = GenerateDrawInfo(PrimitiveType, PrimitiveCount, 0); @@ -2485,11 +2494,14 @@ namespace dxvk { D3DFORMAT IndexDataFormat, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride) { - if (unlikely(!PrimitiveCount)) - return S_OK; - D3D9DeviceLock lock = LockDevice(); + if (unlikely(m_state.vertexDecl == nullptr)) + return D3DERR_INVALIDCALL; + + if (unlikely(!PrimitiveCount)) + return S_OK; + PrepareDraw(PrimitiveType); auto drawInfo = GenerateDrawInfo(PrimitiveType, PrimitiveCount, 0);