From 5b441fa25d7003d7fc85584d2e5c30e9d54e69f6 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Fri, 20 Nov 2020 04:34:02 -0500
Subject: [PATCH 1/4] async_shaders: std::move data within QueueVulkanShader()

Same behavior, but avoids redundant copies.

While we're at it, we can simplify the pushing of the parameters into
the pending queue.
---
 src/video_core/shader/async_shaders.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index 39cc3b8698..c106b2a20a 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -153,8 +153,8 @@ void AsyncShaders::QueueVulkanShader(Vulkan::VKPipelineCache* pp_cache,
         .descriptor_pool = &descriptor_pool,
         .update_descriptor_queue = &update_descriptor_queue,
         .renderpass_cache = &renderpass_cache,
-        .bindings = bindings,
-        .program = program,
+        .bindings = std::move(bindings),
+        .program = std::move(program),
         .key = key,
     };
 

From 3fcc98e11adc1cafc4644483a81b29e55e90d11a Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Fri, 20 Nov 2020 04:41:27 -0500
Subject: [PATCH 2/4] async_shaders: Simplify moving data into the pending
 queue

---
 src/video_core/shader/async_shaders.cpp | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index c106b2a20a..c6bd75b7c6 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -116,11 +116,10 @@ std::vector<AsyncShaders::Result> AsyncShaders::GetCompletedWork() {
 void AsyncShaders::QueueOpenGLShader(const OpenGL::Device& device,
                                      Tegra::Engines::ShaderType shader_type, u64 uid,
                                      std::vector<u64> code, std::vector<u64> code_b,
-                                     u32 main_offset,
-                                     VideoCommon::Shader::CompilerSettings compiler_settings,
-                                     const VideoCommon::Shader::Registry& registry,
-                                     VAddr cpu_addr) {
-    WorkerParams params{
+                                     u32 main_offset, CompilerSettings compiler_settings,
+                                     const Registry& registry, VAddr cpu_addr) {
+    std::unique_lock lock(queue_mutex);
+    pending_queue.push({
         .backend = device.UseAssemblyShaders() ? Backend::GLASM : Backend::OpenGL,
         .device = &device,
         .shader_type = shader_type,
@@ -131,9 +130,7 @@ void AsyncShaders::QueueOpenGLShader(const OpenGL::Device& device,
         .compiler_settings = compiler_settings,
         .registry = registry,
         .cpu_address = cpu_addr,
-    };
-    std::unique_lock lock(queue_mutex);
-    pending_queue.push(std::move(params));
+    });
     cv.notify_one();
 }
 
@@ -145,7 +142,8 @@ void AsyncShaders::QueueVulkanShader(Vulkan::VKPipelineCache* pp_cache,
                                      std::vector<VkDescriptorSetLayoutBinding> bindings,
                                      Vulkan::SPIRVProgram program,
                                      Vulkan::GraphicsPipelineCacheKey key) {
-    WorkerParams params{
+    std::unique_lock lock(queue_mutex);
+    pending_queue.push({
         .backend = Backend::Vulkan,
         .pp_cache = pp_cache,
         .vk_device = &device,
@@ -156,10 +154,7 @@ void AsyncShaders::QueueVulkanShader(Vulkan::VKPipelineCache* pp_cache,
         .bindings = std::move(bindings),
         .program = std::move(program),
         .key = key,
-    };
-
-    std::unique_lock lock(queue_mutex);
-    pending_queue.push(std::move(params));
+    });
     cv.notify_one();
 }
 

From ba3916fc67bac5f9cb40ebc91fccca065e877174 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Fri, 20 Nov 2020 04:44:42 -0500
Subject: [PATCH 3/4] async_shaders: Simplify implementation of
 GetCompletedWork()

This is equivalent to moving all the contents and then clearing the
vector. This avoids a redundant allocation.
---
 src/video_core/shader/async_shaders.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index c6bd75b7c6..85cda31c0e 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -106,8 +106,7 @@ std::vector<AsyncShaders::Result> AsyncShaders::GetCompletedWork() {
     std::vector<Result> results;
     {
         std::unique_lock lock{completed_mutex};
-        results.assign(std::make_move_iterator(finished_work.begin()),
-                       std::make_move_iterator(finished_work.end()));
+        results = std::move(finished_work);
         finished_work.clear();
     }
     return results;

From 01db5cf20313125e2a88a6df1bb1696c0f08f346 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Fri, 20 Nov 2020 04:46:53 -0500
Subject: [PATCH 4/4] async_shaders: emplace threads into the worker thread
 vector

Same behavior, but constructs the threads in place instead of moving
them.
---
 src/video_core/shader/async_shaders.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index 85cda31c0e..6920afdf21 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -43,8 +43,8 @@ void AsyncShaders::AllocateWorkers() {
     // Create workers
     for (std::size_t i = 0; i < num_workers; i++) {
         context_list.push_back(emu_window.CreateSharedContext());
-        worker_threads.push_back(
-            std::thread(&AsyncShaders::ShaderCompilerThread, this, context_list[i].get()));
+        worker_threads.emplace_back(&AsyncShaders::ShaderCompilerThread, this,
+                                    context_list[i].get());
     }
 }