From 72c86b82291166de874b76fb786a58a9f7417d26 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Wed, 6 Mar 2024 22:17:02 +0100 Subject: [PATCH] [d3d9] Only unbind in EndScene if the game cleared the binding --- src/d3d9/d3d9_device.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index cc424259..628fc6f6 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -1616,15 +1616,22 @@ namespace dxvk { m_flags.clr(D3D9DeviceFlag::InScene); - // D3D9 resets the internally bound vertex buffers and index buffer in EndScene. + // D3D9 resets the internally bound vertex buffers and index buffer in EndScene if they were unbound in the meantime. // 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); + if (m_state.indices == nullptr) { + EmitCs([](DxvkContext* ctx) { + ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32); + }); + } + + for (uint32_t i = 0; i < DxvkLimits::MaxNumVertexBindings; i++) { + if (m_state.vertexBuffers[i].vertexBuffer == nullptr) { + EmitCs([cIndex = i](DxvkContext* ctx) { + ctx->bindVertexBuffer(cIndex, DxvkBufferSlice(), 0); + }); } - }); + } return D3D_OK; }