|
|
@ -2,7 +2,6 @@
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
#include <thread>
|
|
|
@ -111,38 +110,44 @@ void AsyncShaders::QueueOpenGLShader(const OpenGL::Device& device,
|
|
|
|
VideoCommon::Shader::CompilerSettings compiler_settings,
|
|
|
|
VideoCommon::Shader::CompilerSettings compiler_settings,
|
|
|
|
const VideoCommon::Shader::Registry& registry,
|
|
|
|
const VideoCommon::Shader::Registry& registry,
|
|
|
|
VAddr cpu_addr) {
|
|
|
|
VAddr cpu_addr) {
|
|
|
|
auto params = std::make_unique<WorkerParams>();
|
|
|
|
WorkerParams params{
|
|
|
|
params->backend = device.UseAssemblyShaders() ? Backend::GLASM : Backend::OpenGL;
|
|
|
|
.backend = device.UseAssemblyShaders() ? Backend::GLASM : Backend::OpenGL,
|
|
|
|
params->device = &device;
|
|
|
|
.device = &device,
|
|
|
|
params->shader_type = shader_type;
|
|
|
|
.shader_type = shader_type,
|
|
|
|
params->uid = uid;
|
|
|
|
.uid = uid,
|
|
|
|
params->code = std::move(code);
|
|
|
|
.code = std::move(code),
|
|
|
|
params->code_b = std::move(code_b);
|
|
|
|
.code_b = std::move(code_b),
|
|
|
|
params->main_offset = main_offset;
|
|
|
|
.main_offset = main_offset,
|
|
|
|
params->compiler_settings = compiler_settings;
|
|
|
|
.compiler_settings = compiler_settings,
|
|
|
|
params->registry = ®istry;
|
|
|
|
.registry = ®istry,
|
|
|
|
params->cpu_address = cpu_addr;
|
|
|
|
.cpu_address = cpu_addr,
|
|
|
|
|
|
|
|
};
|
|
|
|
std::unique_lock lock(queue_mutex);
|
|
|
|
std::unique_lock lock(queue_mutex);
|
|
|
|
pending_queue.push(std::move(params));
|
|
|
|
pending_queue.push(std::move(params));
|
|
|
|
cv.notify_one();
|
|
|
|
cv.notify_one();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AsyncShaders::QueueVulkanShader(
|
|
|
|
void AsyncShaders::QueueVulkanShader(Vulkan::VKPipelineCache* pp_cache,
|
|
|
|
Vulkan::VKPipelineCache* pp_cache, std::vector<VkDescriptorSetLayoutBinding> bindings,
|
|
|
|
const Vulkan::VKDevice& device, Vulkan::VKScheduler& scheduler,
|
|
|
|
Vulkan::SPIRVProgram program, Vulkan::RenderPassParams renderpass_params, u32 padding,
|
|
|
|
Vulkan::VKDescriptorPool& descriptor_pool,
|
|
|
|
std::array<GPUVAddr, Vulkan::Maxwell::MaxShaderProgram> shaders,
|
|
|
|
Vulkan::VKUpdateDescriptorQueue& update_descriptor_queue,
|
|
|
|
Vulkan::FixedPipelineState fixed_state) {
|
|
|
|
Vulkan::VKRenderPassCache& renderpass_cache,
|
|
|
|
|
|
|
|
std::vector<VkDescriptorSetLayoutBinding> bindings,
|
|
|
|
|
|
|
|
Vulkan::SPIRVProgram program,
|
|
|
|
|
|
|
|
Vulkan::GraphicsPipelineCacheKey key) {
|
|
|
|
|
|
|
|
|
|
|
|
auto params = std::make_unique<WorkerParams>();
|
|
|
|
WorkerParams params{
|
|
|
|
|
|
|
|
.backend = Backend::Vulkan,
|
|
|
|
params->backend = Backend::Vulkan;
|
|
|
|
.pp_cache = pp_cache,
|
|
|
|
params->pp_cache = pp_cache;
|
|
|
|
.vk_device = &device,
|
|
|
|
params->bindings = bindings;
|
|
|
|
.scheduler = &scheduler,
|
|
|
|
params->program = program;
|
|
|
|
.descriptor_pool = &descriptor_pool,
|
|
|
|
params->renderpass_params = renderpass_params;
|
|
|
|
.update_descriptor_queue = &update_descriptor_queue,
|
|
|
|
params->padding = padding;
|
|
|
|
.renderpass_cache = &renderpass_cache,
|
|
|
|
params->shaders = shaders;
|
|
|
|
.bindings = bindings,
|
|
|
|
params->fixed_state = fixed_state;
|
|
|
|
.program = program,
|
|
|
|
|
|
|
|
.key = key,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_lock lock(queue_mutex);
|
|
|
|
std::unique_lock lock(queue_mutex);
|
|
|
|
pending_queue.push(std::move(params));
|
|
|
|
pending_queue.push(std::move(params));
|
|
|
@ -150,7 +155,6 @@ void AsyncShaders::QueueVulkanShader(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context) {
|
|
|
|
void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context) {
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
while (!is_thread_exiting.load(std::memory_order_relaxed)) {
|
|
|
|
while (!is_thread_exiting.load(std::memory_order_relaxed)) {
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
cv.wait(lock, [this] { return HasWorkQueued() || is_thread_exiting; });
|
|
|
|
cv.wait(lock, [this] { return HasWorkQueued() || is_thread_exiting; });
|
|
|
@ -168,53 +172,43 @@ void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Pull work from queue
|
|
|
|
// Pull work from queue
|
|
|
|
auto work = std::move(pending_queue.front());
|
|
|
|
WorkerParams work = std::move(pending_queue.front());
|
|
|
|
pending_queue.pop();
|
|
|
|
pending_queue.pop();
|
|
|
|
lock.unlock();
|
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
|
|
|
|
if (work->backend == Backend::OpenGL || work->backend == Backend::GLASM) {
|
|
|
|
if (work.backend == Backend::OpenGL || work.backend == Backend::GLASM) {
|
|
|
|
VideoCommon::Shader::Registry registry = *work->registry;
|
|
|
|
VideoCommon::Shader::Registry registry = *work.registry;
|
|
|
|
const ShaderIR ir(work->code, work->main_offset, work->compiler_settings, registry);
|
|
|
|
const ShaderIR ir(work.code, work.main_offset, work.compiler_settings, registry);
|
|
|
|
const auto scope = context->Acquire();
|
|
|
|
const auto scope = context->Acquire();
|
|
|
|
auto program =
|
|
|
|
auto program =
|
|
|
|
OpenGL::BuildShader(*work->device, work->shader_type, work->uid, ir, registry);
|
|
|
|
OpenGL::BuildShader(*work.device, work.shader_type, work.uid, ir, registry);
|
|
|
|
Result result{};
|
|
|
|
Result result{};
|
|
|
|
result.backend = work->backend;
|
|
|
|
result.backend = work.backend;
|
|
|
|
result.cpu_address = work->cpu_address;
|
|
|
|
result.cpu_address = work.cpu_address;
|
|
|
|
result.uid = work->uid;
|
|
|
|
result.uid = work.uid;
|
|
|
|
result.code = std::move(work->code);
|
|
|
|
result.code = std::move(work.code);
|
|
|
|
result.code_b = std::move(work->code_b);
|
|
|
|
result.code_b = std::move(work.code_b);
|
|
|
|
result.shader_type = work->shader_type;
|
|
|
|
result.shader_type = work.shader_type;
|
|
|
|
|
|
|
|
|
|
|
|
if (work->backend == Backend::OpenGL) {
|
|
|
|
if (work.backend == Backend::OpenGL) {
|
|
|
|
result.program.opengl = std::move(program->source_program);
|
|
|
|
result.program.opengl = std::move(program->source_program);
|
|
|
|
} else if (work->backend == Backend::GLASM) {
|
|
|
|
} else if (work.backend == Backend::GLASM) {
|
|
|
|
result.program.glasm = std::move(program->assembly_program);
|
|
|
|
result.program.glasm = std::move(program->assembly_program);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
work.reset();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock complete_lock(completed_mutex);
|
|
|
|
std::unique_lock complete_lock(completed_mutex);
|
|
|
|
finished_work.push_back(std::move(result));
|
|
|
|
finished_work.push_back(std::move(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (work->backend == Backend::Vulkan) {
|
|
|
|
} else if (work.backend == Backend::Vulkan) {
|
|
|
|
Vulkan::GraphicsPipelineCacheKey params_key{
|
|
|
|
|
|
|
|
.renderpass_params = work->renderpass_params,
|
|
|
|
|
|
|
|
.padding = work->padding,
|
|
|
|
|
|
|
|
.shaders = work->shaders,
|
|
|
|
|
|
|
|
.fixed_state = work->fixed_state,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto pipeline = std::make_unique<Vulkan::VKGraphicsPipeline>(
|
|
|
|
auto pipeline = std::make_unique<Vulkan::VKGraphicsPipeline>(
|
|
|
|
work->pp_cache->GetDevice(), work->pp_cache->GetScheduler(),
|
|
|
|
*work.vk_device, *work.scheduler, *work.descriptor_pool,
|
|
|
|
work->pp_cache->GetDescriptorPool(), work->pp_cache->GetUpdateDescriptorQueue(),
|
|
|
|
*work.update_descriptor_queue, *work.renderpass_cache, work.key, work.bindings,
|
|
|
|
work->pp_cache->GetRenderpassCache(), params_key, work->bindings, work->program);
|
|
|
|
work.program);
|
|
|
|
|
|
|
|
|
|
|
|
work->pp_cache->EmplacePipeline(std::move(pipeline));
|
|
|
|
work.pp_cache->EmplacePipeline(std::move(pipeline));
|
|
|
|
work.reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Give a chance for another thread to get work.
|
|
|
|
|
|
|
|
std::this_thread::yield();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|