From 77db8158c86159c4aed32068db41fb1adbe2e649 Mon Sep 17 00:00:00 2001
From: Philip Rebohle <philip.rebohle@tu-dortmund.de>
Date: Fri, 5 Jul 2019 21:09:46 +0200
Subject: [PATCH] [dxvk] Add option to toggle asynchronous presentation

---
 dxvk.conf                   | 13 +++++++++++++
 src/d3d11/d3d11_options.cpp |  1 +
 src/d3d11/d3d11_options.h   |  4 ++++
 3 files changed, 18 insertions(+)

diff --git a/dxvk.conf b/dxvk.conf
index 2da3e6463..cdda1cc7e 100644
--- a/dxvk.conf
+++ b/dxvk.conf
@@ -63,6 +63,19 @@
 # dxgi.syncInterval = -1
 
 
+# Toggles asynchronous present.
+#
+# Off-loads presentation to the queue submission thread in
+# order to reduce stalling on the main rendering thread and
+# improve performance.
+#
+# Supported values:
+# - Auto: Enable on certain drivers
+# - True / False: Always enable / disable
+
+# dxgi.asyncPresent = Auto
+
+
 # Enables or dsables d3d10 support.
 # 
 # Supported values: True, False
diff --git a/src/d3d11/d3d11_options.cpp b/src/d3d11/d3d11_options.cpp
index 21a33a11f..e1f28211e 100644
--- a/src/d3d11/d3d11_options.cpp
+++ b/src/d3d11/d3d11_options.cpp
@@ -17,6 +17,7 @@ namespace dxvk {
     this->numBackBuffers        = config.getOption<int32_t>("dxgi.numBackBuffers", 0);
     this->maxFrameLatency       = config.getOption<int32_t>("dxgi.maxFrameLatency", 0);
     this->syncInterval          = config.getOption<int32_t>("dxgi.syncInterval", -1);
+    this->asyncPresent          = config.getOption<Tristate>("dxgi.asyncPresent", Tristate::Auto);
   }
   
 }
\ No newline at end of file
diff --git a/src/d3d11/d3d11_options.h b/src/d3d11/d3d11_options.h
index c87d5a058..879c02a84 100644
--- a/src/d3d11/d3d11_options.h
+++ b/src/d3d11/d3d11_options.h
@@ -76,6 +76,10 @@ namespace dxvk {
     /// fixes issues with games that create multiple swap chains
     /// for a single window that may interfere with each other.
     bool deferSurfaceCreation;
+
+    /// Whether to use the submission thread for presentation.
+    /// May increase performance in some games with some drivers.
+    Tristate asyncPresent;
   };
   
 }
\ No newline at end of file