summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader
diff options
context:
space:
mode:
authorameerj <aj662@drexel.edu>2020-07-28 06:08:02 +0200
committerameerj <aj662@drexel.edu>2020-08-16 18:02:22 +0200
commit6ac97405df021d5d2bd9a529253bd5c5a418c1a9 (patch)
tree0abc29657e9187bcfd3484ed7b091d0ea0f89f0f /src/video_core/shader
parentMerge pull request #4528 from lioncash/discard (diff)
downloadyuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.tar
yuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.tar.gz
yuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.tar.bz2
yuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.tar.lz
yuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.tar.xz
yuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.tar.zst
yuzu-6ac97405df021d5d2bd9a529253bd5c5a418c1a9.zip
Diffstat (limited to 'src/video_core/shader')
-rw-r--r--src/video_core/shader/async_shaders.cpp59
-rw-r--r--src/video_core/shader/async_shaders.h31
2 files changed, 84 insertions, 6 deletions
diff --git a/src/video_core/shader/async_shaders.cpp b/src/video_core/shader/async_shaders.cpp
index b7f66d7ee..335a0d05b 100644
--- a/src/video_core/shader/async_shaders.cpp
+++ b/src/video_core/shader/async_shaders.cpp
@@ -113,15 +113,38 @@ void AsyncShaders::QueueOpenGLShader(const OpenGL::Device& device,
VAddr cpu_addr) {
WorkerParams params{device.UseAssemblyShaders() ? AsyncShaders::Backend::GLASM
: AsyncShaders::Backend::OpenGL,
- device,
+ &device,
shader_type,
uid,
std::move(code),
std::move(code_b),
main_offset,
compiler_settings,
- registry,
+ &registry,
cpu_addr};
+
+ std::unique_lock lock(queue_mutex);
+ pending_queue.push_back(std::move(params));
+ cv.notify_one();
+}
+
+void AsyncShaders::QueueVulkanShader(
+ Vulkan::VKPipelineCache* pp_cache, std::vector<VkDescriptorSetLayoutBinding> bindings,
+ Vulkan::SPIRVProgram program, Vulkan::RenderPassParams renderpass_params, u32 padding,
+ std::array<GPUVAddr, Vulkan::Maxwell::MaxShaderProgram> shaders,
+ Vulkan::FixedPipelineState fixed_state) {
+
+ WorkerParams params{
+ .backend = AsyncShaders::Backend::Vulkan,
+ .pp_cache = pp_cache,
+ .bindings = bindings,
+ .program = program,
+ .renderpass_params = renderpass_params,
+ .padding = padding,
+ .shaders = shaders,
+ .fixed_state = fixed_state,
+ };
+
std::unique_lock lock(queue_mutex);
pending_queue.push_back(std::move(params));
cv.notify_one();
@@ -140,6 +163,7 @@ void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context
if (!HasWorkQueued()) {
continue;
}
+
// Another thread beat us, just unlock and wait for the next load
if (pending_queue.empty()) {
continue;
@@ -152,10 +176,11 @@ void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context
if (work.backend == AsyncShaders::Backend::OpenGL ||
work.backend == AsyncShaders::Backend::GLASM) {
- const ShaderIR ir(work.code, work.main_offset, work.compiler_settings, work.registry);
+ VideoCommon::Shader::Registry registry = *work.registry;
+ const ShaderIR ir(work.code, work.main_offset, work.compiler_settings, registry);
const auto scope = context->Acquire();
auto program =
- OpenGL::BuildShader(work.device, work.shader_type, work.uid, ir, work.registry);
+ OpenGL::BuildShader(*work.device, work.shader_type, work.uid, ir, registry);
Result result{};
result.backend = work.backend;
result.cpu_address = work.cpu_address;
@@ -174,6 +199,32 @@ void AsyncShaders::ShaderCompilerThread(Core::Frontend::GraphicsContext* context
std::unique_lock complete_lock(completed_mutex);
finished_work.push_back(std::move(result));
}
+
+ } else if (work.backend == AsyncShaders::Backend::Vulkan) {
+ Vulkan::GraphicsPipelineCacheKey params_key{
+ work.renderpass_params,
+ work.padding,
+ work.shaders,
+ work.fixed_state,
+ };
+ {
+ std::unique_lock complete_lock(completed_mutex);
+
+ // Duplicate creation of pipelines leads to instability and crashing, caused by a
+ // race condition but band-aid solution is locking the making of the pipeline
+ // results in only one pipeline created at a time.
+ Result result{
+ .backend = work.backend,
+ .pipeline = std::make_unique<Vulkan::VKGraphicsPipeline>(
+ work.pp_cache->GetDevice(), work.pp_cache->GetScheduler(),
+ work.pp_cache->GetDescriptorPool(),
+ work.pp_cache->GetUpdateDescriptorQueue(),
+ work.pp_cache->GetRenderpassCache(), params_key, work.bindings,
+ work.program),
+ };
+
+ finished_work.push_back(std::move(result));
+ }
}
}
}
diff --git a/src/video_core/shader/async_shaders.h b/src/video_core/shader/async_shaders.h
index 2f5ee94ad..702026ce2 100644
--- a/src/video_core/shader/async_shaders.h
+++ b/src/video_core/shader/async_shaders.h
@@ -14,6 +14,10 @@
#include "video_core/renderer_opengl/gl_device.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
+#include "video_core/renderer_vulkan/vk_device.h"
+#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
+#include "video_core/renderer_vulkan/vk_scheduler.h"
+#include "video_core/renderer_vulkan/vk_update_descriptor.h"
namespace Core::Frontend {
class EmuWindow;
@@ -24,6 +28,10 @@ namespace Tegra {
class GPU;
}
+namespace Vulkan {
+class VKPipelineCache;
+}
+
namespace VideoCommon::Shader {
class AsyncShaders {
@@ -31,6 +39,7 @@ public:
enum class Backend {
OpenGL,
GLASM,
+ Vulkan,
};
struct ResultPrograms {
@@ -46,6 +55,7 @@ public:
std::vector<u64> code;
std::vector<u64> code_b;
Tegra::Engines::ShaderType shader_type;
+ std::unique_ptr<Vulkan::VKGraphicsPipeline> pipeline;
};
explicit AsyncShaders(Core::Frontend::EmuWindow& emu_window);
@@ -76,6 +86,13 @@ public:
VideoCommon::Shader::CompilerSettings compiler_settings,
const VideoCommon::Shader::Registry& registry, VAddr cpu_addr);
+ void QueueVulkanShader(Vulkan::VKPipelineCache* pp_cache,
+ std::vector<VkDescriptorSetLayoutBinding> bindings,
+ Vulkan::SPIRVProgram program, Vulkan::RenderPassParams renderpass_params,
+ u32 padding,
+ std::array<GPUVAddr, Vulkan::Maxwell::MaxShaderProgram> shaders,
+ Vulkan::FixedPipelineState fixed_state);
+
private:
void ShaderCompilerThread(Core::Frontend::GraphicsContext* context);
@@ -84,15 +101,25 @@ private:
struct WorkerParams {
AsyncShaders::Backend backend;
- OpenGL::Device device;
+ // For OGL
+ 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;
- VideoCommon::Shader::Registry registry;
+ const VideoCommon::Shader::Registry* registry;
VAddr cpu_address;
+
+ // For Vulkan
+ Vulkan::VKPipelineCache* pp_cache;
+ std::vector<VkDescriptorSetLayoutBinding> bindings;
+ Vulkan::SPIRVProgram program;
+ Vulkan::RenderPassParams renderpass_params;
+ u32 padding;
+ std::array<GPUVAddr, Vulkan::Maxwell::MaxShaderProgram> shaders;
+ Vulkan::FixedPipelineState fixed_state;
};
std::condition_variable cv;