From 5733c8681ea4eeefc7bfefc62e5eeb2d4f77abde Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Tue, 21 Nov 2023 06:05:35 +0200 Subject: [PATCH] vk_pipeline_cache: Move SPIRV emittion to a worker thread (#7170) * vk_scheduler: Remove RenderpassCache dependency * vk_pipeline_cache: Move spirv emittion to worker thread --- .../renderer_vulkan/renderer_vulkan.cpp | 4 +--- .../renderer_vulkan/vk_pipeline_cache.cpp | 19 +++++++++---------- .../renderer_vulkan/vk_scheduler.cpp | 5 ++--- src/video_core/renderer_vulkan/vk_scheduler.h | 11 +++-------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 2f63ecd2f..c3104524c 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -7,7 +7,6 @@ #include "common/memory_detect.h" #include "common/microprofile.h" #include "common/settings.h" -#include "common/texture.h" #include "core/core.h" #include "core/frontend/emu_window.h" #include "core/hw/gpu.h" @@ -21,7 +20,6 @@ #include "video_core/host_shaders/vulkan_present_frag_spv.h" #include "video_core/host_shaders/vulkan_present_interlaced_frag_spv.h" #include "video_core/host_shaders/vulkan_present_vert_spv.h" -#include "vulkan/vulkan_format_traits.hpp" #include @@ -57,7 +55,7 @@ RendererVulkan::RendererVulkan(Core::System& system, Frontend::EmuWindow& window Frontend::EmuWindow* secondary_window) : RendererBase{system, window, secondary_window}, memory{system.Memory()}, instance{system.TelemetrySession(), window, Settings::values.physical_device.GetValue()}, - scheduler{instance, renderpass_cache}, renderpass_cache{instance, scheduler}, pool{instance}, + scheduler{instance}, renderpass_cache{instance, scheduler}, pool{instance}, main_window{window, instance, scheduler}, vertex_buffer{instance, scheduler, vk::BufferUsageFlagBits::eVertexBuffer, VERTEX_BUFFER_SIZE}, diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 0949abd79..2022c8da2 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -469,19 +469,18 @@ void PipelineCache::UseFragmentShader(const Pica::Regs& regs, auto& shader = it->second; if (new_shader) { - const bool use_spirv = Settings::values.spirv_shader_gen.GetValue(); - if (use_spirv && !fs_config.UsesShadowPipeline()) { - const std::vector code = SPIRV::GenerateFragmentShader(fs_config, profile); - shader.module = CompileSPV(code, instance.GetDevice()); - shader.MarkDone(); - } else { - workers.QueueWork([fs_config, this, &shader]() { + workers.QueueWork([fs_config, this, &shader]() { + const bool use_spirv = Settings::values.spirv_shader_gen.GetValue(); + if (use_spirv && !fs_config.UsesShadowPipeline()) { + const std::vector code = SPIRV::GenerateFragmentShader(fs_config, profile); + shader.module = CompileSPV(code, instance.GetDevice()); + } else { const std::string code = GLSL::GenerateFragmentShader(fs_config, profile); shader.module = Compile(code, vk::ShaderStageFlagBits::eFragment, instance.GetDevice()); - shader.MarkDone(); - }); - } + } + shader.MarkDone(); + }); } current_shaders[ProgramType::FS] = &shader; diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index bc72f00c9..315fe0ea7 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp @@ -42,8 +42,8 @@ void Scheduler::CommandChunk::ExecuteAll(vk::CommandBuffer cmdbuf) { last = nullptr; } -Scheduler::Scheduler(const Instance& instance, RenderpassCache& renderpass_cache) - : renderpass_cache{renderpass_cache}, master_semaphore{MakeMasterSemaphore(instance)}, +Scheduler::Scheduler(const Instance& instance) + : master_semaphore{MakeMasterSemaphore(instance)}, command_pool{instance, master_semaphore.get()}, use_worker_thread{true} { AllocateWorkerCommandBuffers(); if (use_worker_thread) { @@ -173,7 +173,6 @@ void Scheduler::SubmitExecution(vk::Semaphore signal_semaphore, vk::Semaphore wa state = StateFlags::AllDirty; const u64 signal_value = master_semaphore->NextTick(); - renderpass_cache.EndRendering(); Record([signal_semaphore, wait_semaphore, signal_value, this](vk::CommandBuffer cmdbuf) { MICROPROFILE_SCOPE(Vulkan_Submit); std::scoped_lock lock{submit_mutex}; diff --git a/src/video_core/renderer_vulkan/vk_scheduler.h b/src/video_core/renderer_vulkan/vk_scheduler.h index faffd22e8..82a14addd 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.h +++ b/src/video_core/renderer_vulkan/vk_scheduler.h @@ -8,7 +8,6 @@ #include #include "common/alignment.h" #include "common/common_funcs.h" -#include "common/logging/log.h" #include "common/polyfill_thread.h" #include "video_core/renderer_vulkan/vk_master_semaphore.h" #include "video_core/renderer_vulkan/vk_resource_pool.h" @@ -17,21 +16,18 @@ namespace Vulkan { enum class StateFlags { AllDirty = 0, - Renderpass = 1 << 0, - Pipeline = 1 << 1, - DescriptorSets = 1 << 2 + Pipeline = 1 << 0, + DescriptorSets = 1 << 1, }; - DECLARE_ENUM_FLAG_OPERATORS(StateFlags) class Instance; -class RenderpassCache; /// The scheduler abstracts command buffer and fence management with an interface that's able to do /// OpenGL-like operations on Vulkan command buffers. class Scheduler { public: - explicit Scheduler(const Instance& instance, RenderpassCache& renderpass_cache); + explicit Scheduler(const Instance& instance); ~Scheduler(); /// Sends the current execution context to the GPU. @@ -191,7 +187,6 @@ private: void AcquireNewChunk(); private: - RenderpassCache& renderpass_cache; std::unique_ptr master_semaphore; CommandPool command_pool; std::unique_ptr chunk;