From 802fbe3cfd44f39caf86f8c91a1d0db5353ba8b0 Mon Sep 17 00:00:00 2001
From: Philip Rebohle <philip.rebohle@tu-dortmund.de>
Date: Fri, 1 Dec 2017 14:27:53 +0100
Subject: [PATCH] [dxvk] Some minor refactoring

---
 src/dxvk/dxvk_cmdlist.cpp | 24 ++++++++++++++++++++++++
 src/dxvk/dxvk_cmdlist.h   | 16 +++++++++++-----
 src/dxvk/dxvk_device.cpp  | 23 ++++-------------------
 3 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/src/dxvk/dxvk_cmdlist.cpp b/src/dxvk/dxvk_cmdlist.cpp
index 2c0822475..b3ff05b76 100644
--- a/src/dxvk/dxvk_cmdlist.cpp
+++ b/src/dxvk/dxvk_cmdlist.cpp
@@ -35,6 +35,30 @@ namespace dxvk {
   }
   
   
+  void DxvkCommandList::submit(
+          VkQueue         queue,
+          VkSemaphore     waitSemaphore,
+          VkSemaphore     wakeSemaphore,
+          VkFence         fence) {
+    const VkPipelineStageFlags waitStageMask
+      = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+    
+    VkSubmitInfo info;
+    info.sType                = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+    info.pNext                = nullptr;
+    info.waitSemaphoreCount   = waitSemaphore == VK_NULL_HANDLE ? 0 : 1;
+    info.pWaitSemaphores      = &waitSemaphore;
+    info.pWaitDstStageMask    = &waitStageMask;
+    info.commandBufferCount   = 1;
+    info.pCommandBuffers      = &m_buffer;
+    info.signalSemaphoreCount = wakeSemaphore == VK_NULL_HANDLE ? 0 : 1;
+    info.pSignalSemaphores    = &wakeSemaphore;
+    
+    if (m_vkd->vkQueueSubmit(queue, 1, &info, fence) != VK_SUCCESS)
+      throw DxvkError("DxvkDevice::submitCommandList: Command submission failed");
+  }
+  
+  
   void DxvkCommandList::beginRecording() {
     VkCommandBufferBeginInfo info;
     info.sType            = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
diff --git a/src/dxvk/dxvk_cmdlist.h b/src/dxvk/dxvk_cmdlist.h
index 5895cdc2d..0e107b7b0 100644
--- a/src/dxvk/dxvk_cmdlist.h
+++ b/src/dxvk/dxvk_cmdlist.h
@@ -26,12 +26,18 @@ namespace dxvk {
     ~DxvkCommandList();
     
     /**
-     * \brief Command buffer handle
-     * \returns Command buffer handle
+     * \brief Submits command list
+     * 
+     * \param [in] queue Device queue
+     * \param [in] waitSemaphore Semaphore to wait on
+     * \param [in] wakeSemaphore Semaphore to signal
+     * \param [in] fence Fence to signal
      */
-    VkCommandBuffer handle() const {
-      return m_buffer;
-    }
+    void submit(
+            VkQueue         queue,
+            VkSemaphore     waitSemaphore,
+            VkSemaphore     wakeSemaphore,
+            VkFence         fence);
     
     /**
      * \brief Begins recording
diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp
index ed606fa23..604cb1eab 100644
--- a/src/dxvk/dxvk_device.cpp
+++ b/src/dxvk/dxvk_device.cpp
@@ -105,9 +105,8 @@ namespace dxvk {
     const Rc<DxvkSemaphore>&        wakeSync) {
     Rc<DxvkFence> fence = new DxvkFence(m_vkd);
     
-    VkCommandBuffer commandBuffer = commandList->handle();
-    VkSemaphore     waitSemaphore = VK_NULL_HANDLE;
-    VkSemaphore     wakeSemaphore = VK_NULL_HANDLE;
+    VkSemaphore waitSemaphore = VK_NULL_HANDLE;
+    VkSemaphore wakeSemaphore = VK_NULL_HANDLE;
     
     if (waitSync != nullptr) {
       waitSemaphore = waitSync->handle();
@@ -119,22 +118,8 @@ namespace dxvk {
       commandList->trackResource(wakeSync);
     }
     
-    const VkPipelineStageFlags waitStageMask
-      = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
-    
-    VkSubmitInfo info;
-    info.sType                = VK_STRUCTURE_TYPE_SUBMIT_INFO;
-    info.pNext                = nullptr;
-    info.waitSemaphoreCount   = waitSemaphore == VK_NULL_HANDLE ? 0 : 1;
-    info.pWaitSemaphores      = &waitSemaphore;
-    info.pWaitDstStageMask    = &waitStageMask;
-    info.commandBufferCount   = commandBuffer == VK_NULL_HANDLE ? 0 : 1;
-    info.pCommandBuffers      = &commandBuffer;
-    info.signalSemaphoreCount = wakeSemaphore == VK_NULL_HANDLE ? 0 : 1;
-    info.pSignalSemaphores    = &wakeSemaphore;
-    
-    if (m_vkd->vkQueueSubmit(m_graphicsQueue, 1, &info, fence->handle()) != VK_SUCCESS)
-      throw DxvkError("DxvkDevice::submitCommandList: Command submission failed");
+    commandList->submit(m_graphicsQueue,
+      waitSemaphore, wakeSemaphore, fence->handle());
     
     // TODO Delay synchronization by putting these into a ring buffer
     fence->wait(std::numeric_limits<uint64_t>::max());