mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-15 23:30:05 +00:00
shader: Remove atomic flags and use mutex + cond variable for pipelines
This commit is contained in:
parent
0b26f2b90e
commit
5ed68e83db
@ -55,8 +55,9 @@ ComputePipeline::ComputePipeline(const Device& device, VKDescriptorPool& descrip
|
||||
.basePipelineHandle = 0,
|
||||
.basePipelineIndex = 0,
|
||||
});
|
||||
building_flag.test_and_set();
|
||||
building_flag.notify_all();
|
||||
std::lock_guard lock{build_mutex};
|
||||
is_built = true;
|
||||
build_condvar.notify_one();
|
||||
}};
|
||||
if (thread_worker) {
|
||||
thread_worker->QueueWork(std::move(func));
|
||||
@ -75,7 +76,8 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
||||
size_t ssbo_index{};
|
||||
for (const auto& desc : info.storage_buffers_descriptors) {
|
||||
ASSERT(desc.count == 1);
|
||||
buffer_cache.BindComputeStorageBuffer(ssbo_index, desc.cbuf_index, desc.cbuf_offset, desc.is_written);
|
||||
buffer_cache.BindComputeStorageBuffer(ssbo_index, desc.cbuf_index, desc.cbuf_offset,
|
||||
desc.is_written);
|
||||
++ssbo_index;
|
||||
}
|
||||
buffer_cache.UpdateComputeBuffers();
|
||||
@ -112,9 +114,12 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
||||
PushImageDescriptors(info, samplers.data(), image_view_ids.data(), texture_cache,
|
||||
update_descriptor_queue, image_index);
|
||||
|
||||
if (!building_flag.test()) {
|
||||
if (!is_built.load(std::memory_order::relaxed)) {
|
||||
// Wait for the pipeline to be built
|
||||
scheduler.Record([this](vk::CommandBuffer) { building_flag.wait(false); });
|
||||
scheduler.Record([this](vk::CommandBuffer) {
|
||||
std::unique_lock lock{build_mutex};
|
||||
build_condvar.wait(lock, [this] { return is_built.load(std::memory_order::relaxed); });
|
||||
});
|
||||
}
|
||||
scheduler.Record([this](vk::CommandBuffer cmdbuf) {
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
#include "common/common_types.h"
|
||||
@ -47,7 +49,10 @@ private:
|
||||
vk::PipelineLayout pipeline_layout;
|
||||
vk::DescriptorUpdateTemplateKHR descriptor_update_template;
|
||||
vk::Pipeline pipeline;
|
||||
std::atomic_flag building_flag{};
|
||||
|
||||
std::condition_variable build_condvar;
|
||||
std::mutex build_mutex;
|
||||
std::atomic_bool is_built{false};
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
|
@ -135,8 +135,10 @@ GraphicsPipeline::GraphicsPipeline(Tegra::Engines::Maxwell3D& maxwell3d_,
|
||||
|
||||
const VkRenderPass render_pass{render_pass_cache.Get(MakeRenderPassKey(state))};
|
||||
MakePipeline(device, render_pass);
|
||||
building_flag.test_and_set();
|
||||
building_flag.notify_all();
|
||||
|
||||
std::lock_guard lock{build_mutex};
|
||||
is_built = true;
|
||||
build_condvar.notify_one();
|
||||
}};
|
||||
if (worker_thread) {
|
||||
worker_thread->QueueWork(std::move(func));
|
||||
@ -196,8 +198,12 @@ void GraphicsPipeline::Configure(bool is_indexed) {
|
||||
texture_cache.UpdateRenderTargets(false);
|
||||
scheduler.RequestRenderpass(texture_cache.GetFramebuffer());
|
||||
|
||||
if (!building_flag.test()) {
|
||||
scheduler.Record([this](vk::CommandBuffer) { building_flag.wait(false); });
|
||||
if (!is_built.load(std::memory_order::relaxed)) {
|
||||
// Wait for the pipeline to be built
|
||||
scheduler.Record([this](vk::CommandBuffer) {
|
||||
std::unique_lock lock{build_mutex};
|
||||
build_condvar.wait(lock, [this] { return is_built.load(std::memory_order::relaxed); });
|
||||
});
|
||||
}
|
||||
if (scheduler.UpdateGraphicsPipeline(this)) {
|
||||
scheduler.Record([this](vk::CommandBuffer cmdbuf) {
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/thread_worker.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
@ -63,7 +65,10 @@ private:
|
||||
vk::PipelineLayout pipeline_layout;
|
||||
vk::DescriptorUpdateTemplateKHR descriptor_update_template;
|
||||
vk::Pipeline pipeline;
|
||||
std::atomic_flag building_flag{};
|
||||
|
||||
std::condition_variable build_condvar;
|
||||
std::mutex build_mutex;
|
||||
std::atomic_bool is_built{false};
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
|
Loading…
Reference in New Issue
Block a user