mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-03 04:09:59 +00:00
video_core: Enable GL SPIR-V shaders
This commit is contained in:
parent
1152d66ddd
commit
fb9b1787f8
7 changed files with 105 additions and 38 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "common/cityhash.h"
|
#include "common/cityhash.h"
|
||||||
|
#include "common/settings.h" // for enum class Settings::ShaderBackend
|
||||||
#include "video_core/renderer_opengl/gl_compute_pipeline.h"
|
#include "video_core/renderer_opengl/gl_compute_pipeline.h"
|
||||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||||
|
@ -40,15 +41,23 @@ ComputePipeline::ComputePipeline(const Device& device, TextureCache& texture_cac
|
||||||
BufferCache& buffer_cache_, Tegra::MemoryManager& gpu_memory_,
|
BufferCache& buffer_cache_, Tegra::MemoryManager& gpu_memory_,
|
||||||
Tegra::Engines::KeplerCompute& kepler_compute_,
|
Tegra::Engines::KeplerCompute& kepler_compute_,
|
||||||
ProgramManager& program_manager_, const Shader::Info& info_,
|
ProgramManager& program_manager_, const Shader::Info& info_,
|
||||||
std::string code)
|
std::string code, std::vector<u32> code_v)
|
||||||
: texture_cache{texture_cache_}, buffer_cache{buffer_cache_}, gpu_memory{gpu_memory_},
|
: texture_cache{texture_cache_}, buffer_cache{buffer_cache_}, gpu_memory{gpu_memory_},
|
||||||
kepler_compute{kepler_compute_}, program_manager{program_manager_}, info{info_} {
|
kepler_compute{kepler_compute_}, program_manager{program_manager_}, info{info_} {
|
||||||
if (device.UseAssemblyShaders()) {
|
switch (device.GetShaderBackend()) {
|
||||||
assembly_program = CompileProgram(code, GL_COMPUTE_PROGRAM_NV);
|
case Settings::ShaderBackend::GLSL:
|
||||||
} else {
|
|
||||||
source_program.handle = glCreateProgram();
|
source_program.handle = glCreateProgram();
|
||||||
AttachShader(GL_COMPUTE_SHADER, source_program.handle, code);
|
AttachShader(GL_COMPUTE_SHADER, source_program.handle, code);
|
||||||
LinkProgram(source_program.handle);
|
LinkProgram(source_program.handle);
|
||||||
|
break;
|
||||||
|
case Settings::ShaderBackend::GLASM:
|
||||||
|
assembly_program = CompileProgram(code, GL_COMPUTE_PROGRAM_NV);
|
||||||
|
break;
|
||||||
|
case Settings::ShaderBackend::SPIRV:
|
||||||
|
source_program.handle = glCreateProgram();
|
||||||
|
AttachShader(GL_COMPUTE_SHADER, source_program.handle, code_v);
|
||||||
|
LinkProgram(source_program.handle);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
std::copy_n(info.constant_buffer_used_sizes.begin(), uniform_buffer_sizes.size(),
|
std::copy_n(info.constant_buffer_used_sizes.begin(), uniform_buffer_sizes.size(),
|
||||||
uniform_buffer_sizes.begin());
|
uniform_buffer_sizes.begin());
|
||||||
|
|
|
@ -54,7 +54,7 @@ public:
|
||||||
BufferCache& buffer_cache_, Tegra::MemoryManager& gpu_memory_,
|
BufferCache& buffer_cache_, Tegra::MemoryManager& gpu_memory_,
|
||||||
Tegra::Engines::KeplerCompute& kepler_compute_,
|
Tegra::Engines::KeplerCompute& kepler_compute_,
|
||||||
ProgramManager& program_manager_, const Shader::Info& info_,
|
ProgramManager& program_manager_, const Shader::Info& info_,
|
||||||
std::string code);
|
std::string code, std::vector<u32> code_v);
|
||||||
|
|
||||||
void Configure();
|
void Configure();
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,11 @@ Device::Device() {
|
||||||
GLAD_GL_NV_gpu_program5 && GLAD_GL_NV_compute_program5 && GLAD_GL_NV_transform_feedback &&
|
GLAD_GL_NV_gpu_program5 && GLAD_GL_NV_compute_program5 && GLAD_GL_NV_transform_feedback &&
|
||||||
GLAD_GL_NV_transform_feedback2;
|
GLAD_GL_NV_transform_feedback2;
|
||||||
|
|
||||||
|
shader_backend = (Settings::values.shader_backend.GetValue() ==
|
||||||
|
Settings::ShaderBackend::GLASM) == use_assembly_shaders
|
||||||
|
? Settings::values.shader_backend.GetValue()
|
||||||
|
: Settings::ShaderBackend::GLSL;
|
||||||
|
|
||||||
// Blocks AMD and Intel OpenGL drivers on Windows from using asynchronous shader compilation.
|
// Blocks AMD and Intel OpenGL drivers on Windows from using asynchronous shader compilation.
|
||||||
use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue() &&
|
use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue() &&
|
||||||
!(is_amd || (is_intel && !is_linux));
|
!(is_amd || (is_intel && !is_linux));
|
||||||
|
@ -188,8 +193,7 @@ Device::Device() {
|
||||||
LOG_INFO(Render_OpenGL, "Renderer_BrokenTextureViewFormats: {}",
|
LOG_INFO(Render_OpenGL, "Renderer_BrokenTextureViewFormats: {}",
|
||||||
has_broken_texture_view_formats);
|
has_broken_texture_view_formats);
|
||||||
|
|
||||||
if (Settings::values.shader_backend.GetValue() == Settings::ShaderBackend::GLASM &&
|
if (shader_backend == Settings::ShaderBackend::GLASM && !use_assembly_shaders) {
|
||||||
!use_assembly_shaders) {
|
|
||||||
LOG_ERROR(Render_OpenGL, "Assembly shaders enabled but not supported");
|
LOG_ERROR(Render_OpenGL, "Assembly shaders enabled but not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "shader_recompiler/stage.h"
|
#include "shader_recompiler/stage.h"
|
||||||
|
|
||||||
|
namespace Settings {
|
||||||
|
enum class ShaderBackend : u32;
|
||||||
|
};
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
class Device {
|
class Device {
|
||||||
|
@ -148,6 +152,10 @@ public:
|
||||||
return need_fastmath_off;
|
return need_fastmath_off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Settings::ShaderBackend GetShaderBackend() const {
|
||||||
|
return shader_backend;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool TestVariableAoffi();
|
static bool TestVariableAoffi();
|
||||||
static bool TestPreciseBug();
|
static bool TestPreciseBug();
|
||||||
|
@ -159,6 +167,9 @@ private:
|
||||||
u32 max_varyings{};
|
u32 max_varyings{};
|
||||||
u32 max_compute_shared_memory_size{};
|
u32 max_compute_shared_memory_size{};
|
||||||
u32 max_glasm_storage_buffer_blocks{};
|
u32 max_glasm_storage_buffer_blocks{};
|
||||||
|
|
||||||
|
Settings::ShaderBackend shader_backend{};
|
||||||
|
|
||||||
bool has_warp_intrinsics{};
|
bool has_warp_intrinsics{};
|
||||||
bool has_shader_ballot{};
|
bool has_shader_ballot{};
|
||||||
bool has_vertex_viewport_layer{};
|
bool has_vertex_viewport_layer{};
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/settings.h" // for enum class Settings::ShaderBackend
|
||||||
#include "common/thread_worker.h"
|
#include "common/thread_worker.h"
|
||||||
#include "shader_recompiler/shader_info.h"
|
#include "shader_recompiler/shader_info.h"
|
||||||
#include "video_core/renderer_opengl/gl_graphics_pipeline.h"
|
#include "video_core/renderer_opengl/gl_graphics_pipeline.h"
|
||||||
|
@ -179,7 +183,8 @@ GraphicsPipeline::GraphicsPipeline(
|
||||||
Tegra::MemoryManager& gpu_memory_, Tegra::Engines::Maxwell3D& maxwell3d_,
|
Tegra::MemoryManager& gpu_memory_, Tegra::Engines::Maxwell3D& maxwell3d_,
|
||||||
ProgramManager& program_manager_, StateTracker& state_tracker_, ShaderWorker* thread_worker,
|
ProgramManager& program_manager_, StateTracker& state_tracker_, ShaderWorker* thread_worker,
|
||||||
VideoCore::ShaderNotify* shader_notify, std::array<std::string, 5> sources,
|
VideoCore::ShaderNotify* shader_notify, std::array<std::string, 5> sources,
|
||||||
const std::array<const Shader::Info*, 5>& infos, const GraphicsPipelineKey& key_)
|
std::array<std::vector<u32>, 5> sources_spirv, const std::array<const Shader::Info*, 5>& infos,
|
||||||
|
const GraphicsPipelineKey& key_)
|
||||||
: texture_cache{texture_cache_}, buffer_cache{buffer_cache_},
|
: texture_cache{texture_cache_}, buffer_cache{buffer_cache_},
|
||||||
gpu_memory{gpu_memory_}, maxwell3d{maxwell3d_}, program_manager{program_manager_},
|
gpu_memory{gpu_memory_}, maxwell3d{maxwell3d_}, program_manager{program_manager_},
|
||||||
state_tracker{state_tracker_}, key{key_} {
|
state_tracker{state_tracker_}, key{key_} {
|
||||||
|
@ -232,19 +237,34 @@ GraphicsPipeline::GraphicsPipeline(
|
||||||
if (key.xfb_enabled && device.UseAssemblyShaders()) {
|
if (key.xfb_enabled && device.UseAssemblyShaders()) {
|
||||||
GenerateTransformFeedbackState();
|
GenerateTransformFeedbackState();
|
||||||
}
|
}
|
||||||
auto func{[this, device, sources, shader_notify](ShaderContext::Context*) mutable {
|
auto func{
|
||||||
|
[this, device, sources, sources_spirv, shader_notify](ShaderContext::Context*) mutable {
|
||||||
if (!device.UseAssemblyShaders()) {
|
if (!device.UseAssemblyShaders()) {
|
||||||
program.handle = glCreateProgram();
|
program.handle = glCreateProgram();
|
||||||
}
|
}
|
||||||
for (size_t stage = 0; stage < 5; ++stage) {
|
for (size_t stage = 0; stage < 5; ++stage) {
|
||||||
|
switch (device.GetShaderBackend()) {
|
||||||
|
case Settings::ShaderBackend::GLSL: {
|
||||||
const auto code{sources[stage]};
|
const auto code{sources[stage]};
|
||||||
if (code.empty()) {
|
if (code.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (device.UseAssemblyShaders()) {
|
|
||||||
assembly_programs[stage] = CompileProgram(code, AssemblyStage(stage));
|
|
||||||
} else {
|
|
||||||
AttachShader(Stage(stage), program.handle, code);
|
AttachShader(Stage(stage), program.handle, code);
|
||||||
|
} break;
|
||||||
|
case Settings::ShaderBackend::GLASM: {
|
||||||
|
const auto code{sources[stage]};
|
||||||
|
if (code.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assembly_programs[stage] = CompileProgram(code, AssemblyStage(stage));
|
||||||
|
} break;
|
||||||
|
case Settings::ShaderBackend::SPIRV: {
|
||||||
|
const auto code{sources_spirv[stage]};
|
||||||
|
if (code.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
AttachShader(Stage(stage), program.handle, code);
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!device.UseAssemblyShaders()) {
|
if (!device.UseAssemblyShaders()) {
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
ProgramManager& program_manager_, StateTracker& state_tracker_,
|
ProgramManager& program_manager_, StateTracker& state_tracker_,
|
||||||
ShaderWorker* thread_worker, VideoCore::ShaderNotify* shader_notify,
|
ShaderWorker* thread_worker, VideoCore::ShaderNotify* shader_notify,
|
||||||
std::array<std::string, 5> sources,
|
std::array<std::string, 5> sources,
|
||||||
|
std::array<std::vector<u32>, 5> sources_spirv,
|
||||||
const std::array<const Shader::Info*, 5>& infos,
|
const std::array<const Shader::Info*, 5>& infos,
|
||||||
const GraphicsPipelineKey& key_);
|
const GraphicsPipelineKey& key_);
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "common/fs/path_util.h"
|
#include "common/fs/path_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
|
#include "common/settings.h"
|
||||||
#include "common/thread_worker.h"
|
#include "common/thread_worker.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "shader_recompiler/backend/glasm/emit_glasm.h"
|
#include "shader_recompiler/backend/glasm/emit_glasm.h"
|
||||||
|
@ -415,6 +416,7 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
|
||||||
|
|
||||||
OGLProgram source_program;
|
OGLProgram source_program;
|
||||||
std::array<std::string, 5> sources;
|
std::array<std::string, 5> sources;
|
||||||
|
std::array<std::vector<u32>, 5> sources_spirv;
|
||||||
Shader::Backend::Bindings binding;
|
Shader::Backend::Bindings binding;
|
||||||
Shader::IR::Program* previous_program{};
|
Shader::IR::Program* previous_program{};
|
||||||
const bool use_glasm{device.UseAssemblyShaders()};
|
const bool use_glasm{device.UseAssemblyShaders()};
|
||||||
|
@ -431,17 +433,23 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
|
||||||
|
|
||||||
const auto runtime_info{
|
const auto runtime_info{
|
||||||
MakeRuntimeInfo(key, program, previous_program, glasm_use_storage_buffers, use_glasm)};
|
MakeRuntimeInfo(key, program, previous_program, glasm_use_storage_buffers, use_glasm)};
|
||||||
if (use_glasm) {
|
switch (device.GetShaderBackend()) {
|
||||||
sources[stage_index] = EmitGLASM(profile, runtime_info, program, binding);
|
case Settings::ShaderBackend::GLSL:
|
||||||
} else {
|
|
||||||
sources[stage_index] = EmitGLSL(profile, runtime_info, program, binding);
|
sources[stage_index] = EmitGLSL(profile, runtime_info, program, binding);
|
||||||
|
break;
|
||||||
|
case Settings::ShaderBackend::GLASM:
|
||||||
|
sources[stage_index] = EmitGLASM(profile, runtime_info, program, binding);
|
||||||
|
break;
|
||||||
|
case Settings::ShaderBackend::SPIRV:
|
||||||
|
sources_spirv[stage_index] = EmitSPIRV(profile, runtime_info, program, binding);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
previous_program = &program;
|
previous_program = &program;
|
||||||
}
|
}
|
||||||
auto* const thread_worker{build_in_parallel ? workers.get() : nullptr};
|
auto* const thread_worker{build_in_parallel ? workers.get() : nullptr};
|
||||||
return std::make_unique<GraphicsPipeline>(device, texture_cache, buffer_cache, gpu_memory,
|
return std::make_unique<GraphicsPipeline>(
|
||||||
maxwell3d, program_manager, state_tracker,
|
device, texture_cache, buffer_cache, gpu_memory, maxwell3d, program_manager, state_tracker,
|
||||||
thread_worker, &shader_notify, sources, infos, key);
|
thread_worker, &shader_notify, sources, sources_spirv, infos, key);
|
||||||
|
|
||||||
} catch (Shader::Exception& exception) {
|
} catch (Shader::Exception& exception) {
|
||||||
LOG_ERROR(Render_OpenGL, "{}", exception.what());
|
LOG_ERROR(Render_OpenGL, "{}", exception.what());
|
||||||
|
@ -478,10 +486,24 @@ std::unique_ptr<ComputePipeline> ShaderCache::CreateComputePipeline(
|
||||||
}
|
}
|
||||||
Shader::RuntimeInfo info;
|
Shader::RuntimeInfo info;
|
||||||
info.glasm_use_storage_buffers = num_storage_buffers <= device.GetMaxGLASMStorageBufferBlocks();
|
info.glasm_use_storage_buffers = num_storage_buffers <= device.GetMaxGLASMStorageBufferBlocks();
|
||||||
const std::string code{device.UseAssemblyShaders() ? EmitGLASM(profile, info, program)
|
|
||||||
: EmitGLSL(profile, program)};
|
std::string code{};
|
||||||
|
std::vector<u32> code_spirv;
|
||||||
|
switch (device.GetShaderBackend()) {
|
||||||
|
case Settings::ShaderBackend::GLSL:
|
||||||
|
code = EmitGLSL(profile, program);
|
||||||
|
break;
|
||||||
|
case Settings::ShaderBackend::GLASM:
|
||||||
|
code = EmitGLASM(profile, info, program);
|
||||||
|
break;
|
||||||
|
case Settings::ShaderBackend::SPIRV:
|
||||||
|
code_spirv = EmitSPIRV(profile, program);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return std::make_unique<ComputePipeline>(device, texture_cache, buffer_cache, gpu_memory,
|
return std::make_unique<ComputePipeline>(device, texture_cache, buffer_cache, gpu_memory,
|
||||||
kepler_compute, program_manager, program.info, code);
|
kepler_compute, program_manager, program.info, code,
|
||||||
|
code_spirv);
|
||||||
} catch (Shader::Exception& exception) {
|
} catch (Shader::Exception& exception) {
|
||||||
LOG_ERROR(Render_OpenGL, "{}", exception.what());
|
LOG_ERROR(Render_OpenGL, "{}", exception.what());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in a new issue