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
This commit is contained in:
GPUCode 2023-11-21 06:05:35 +02:00 committed by GitHub
parent f8ae41dfe3
commit 5733c8681e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 24 deletions

View file

@ -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 <vk_mem_alloc.h>
@ -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},

View file

@ -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;

View file

@ -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};

View file

@ -8,7 +8,6 @@
#include <utility>
#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<MasterSemaphore> master_semaphore;
CommandPool command_pool;
std::unique_ptr<CommandChunk> chunk;