From c1ed8cd1f3d3ebb03e2d956be464cd03db881e5c Mon Sep 17 00:00:00 2001
From: Philip Rebohle <philip.rebohle@tu-dortmund.de>
Date: Mon, 13 Jan 2025 11:32:12 +0100
Subject: [PATCH] [hud] Add function to change API name dynamically

Needed for D3D8 due to implicit swapchain shenanigans.
---
 src/dxvk/hud/dxvk_hud_item.cpp | 10 +++++++++-
 src/dxvk/hud/dxvk_hud_item.h   |  5 ++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/dxvk/hud/dxvk_hud_item.cpp b/src/dxvk/hud/dxvk_hud_item.cpp
index d676202a0..19d7f29e1 100644
--- a/src/dxvk/hud/dxvk_hud_item.cpp
+++ b/src/dxvk/hud/dxvk_hud_item.cpp
@@ -112,7 +112,7 @@ namespace dxvk::hud {
 
 
   HudClientApiItem::HudClientApiItem(std::string api)
-  : m_api(api) {
+  : m_api(std::move(api)) {
 
   }
 
@@ -122,12 +122,20 @@ namespace dxvk::hud {
   }
 
 
+  void HudClientApiItem::setApiName(std::string api) {
+    std::lock_guard lock(m_mutex);
+    m_api = std::move(api);
+  }
+
+
   HudPos HudClientApiItem::render(
     const DxvkContextObjects& ctx,
     const HudPipelineKey&     key,
     const HudOptions&         options,
           HudRenderer&        renderer,
           HudPos              position) {
+    std::lock_guard lock(m_mutex);
+
     position.y += 16;
     renderer.drawText(16, position, 0xffffffffu, m_api);
 
diff --git a/src/dxvk/hud/dxvk_hud_item.h b/src/dxvk/hud/dxvk_hud_item.h
index 749c12172..de5eb1917 100644
--- a/src/dxvk/hud/dxvk_hud_item.h
+++ b/src/dxvk/hud/dxvk_hud_item.h
@@ -163,6 +163,8 @@ namespace dxvk::hud {
 
     ~HudClientApiItem();
 
+    void setApiName(std::string api);
+
     HudPos render(
       const DxvkContextObjects& ctx,
       const HudPipelineKey&     key,
@@ -172,7 +174,8 @@ namespace dxvk::hud {
 
   private:
 
-    std::string m_api;
+    sync::Spinlock  m_mutex;
+    std::string     m_api;
 
   };