From 582b06a7066c0a81d8d7ffd0146b5fe9e45bf30f Mon Sep 17 00:00:00 2001
From: Philip Rebohle <philip.rebohle@tu-dortmund.de>
Date: Thu, 23 Jan 2020 23:28:36 +0100
Subject: [PATCH] [d3d9] Rotate swap chain back buffers

Restores functionality removed in 81c3daa3d068f6a1fd2e8960efa0a109a61ebe78.
---
 src/d3d9/d3d9_subresource.h | 8 ++++++++
 src/d3d9/d3d9_swapchain.cpp | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/src/d3d9/d3d9_subresource.h b/src/d3d9/d3d9_subresource.h
index a76a0ac6..2d2c981b 100644
--- a/src/d3d9/d3d9_subresource.h
+++ b/src/d3d9/d3d9_subresource.h
@@ -111,6 +111,14 @@ namespace dxvk {
       return m_container;
     }
 
+    void Swap(D3D9Subresource* Other) {
+      // Only used for swap chain back buffers that don't
+      // have a container and all have identical properties
+      std::swap(m_texture,          Other->m_texture);
+      std::swap(m_sampleView,       Other->m_sampleView);
+      std::swap(m_renderTargetView, Other->m_renderTargetView);
+    }
+
   protected:
 
     IDirect3DBaseTexture9*  m_container;
diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp
index 757df1e4..15822b40 100644
--- a/src/d3d9/d3d9_swapchain.cpp
+++ b/src/d3d9/d3d9_swapchain.cpp
@@ -739,6 +739,13 @@ namespace dxvk {
 
       SubmitPresent(sync, i);
     }
+
+    // Rotate swap chain buffers so that the back
+    // buffer at index 0 becomes the front buffer.
+    for (uint32_t i = 1; i < m_backBuffers.size(); i++)
+      m_backBuffers[i]->Swap(m_backBuffers[i - 1].ptr());
+
+    m_parent->m_flags.set(D3D9DeviceFlag::DirtyFramebuffer);
   }