From 49b18f03fe7c6dd29e9aa296c5cd072d3765a1bb Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Tue, 20 Feb 2024 23:34:26 +0100 Subject: [PATCH] [d3d9] Unbind buffers in EndScene & Reset --- src/d3d9/d3d9_device.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index f11ae400..2b340c74 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -481,6 +481,14 @@ namespace dxvk { return hr; } + // Unbind all buffers that were still bound to the backend to avoid leaks. + EmitCs([](DxvkContext* ctx) { + ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32); + for (uint32_t i = 0; i < DxvkLimits::MaxNumVertexBindings; i++) { + ctx->bindVertexBuffer(i, DxvkBufferSlice(), 0); + } + }); + Flush(); SynchronizeCsThread(DxvkCsThread::SynchronizeAll); @@ -1603,6 +1611,16 @@ namespace dxvk { m_flags.clr(D3D9DeviceFlag::InScene); + // D3D9 resets the internally bound vertex buffers and index buffer in EndScene. + // We have to ignore unbinding those buffers because of Operation Flashpoint Red River, + // so we should also clear the bindings here, to avoid leaks. + EmitCs([](DxvkContext* ctx) { + ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32); + for (uint32_t i = 0; i < DxvkLimits::MaxNumVertexBindings; i++) { + ctx->bindVertexBuffer(i, DxvkBufferSlice(), 0); + } + }); + return D3D_OK; }