summaryrefslogtreecommitdiffstats
path: root/src/video_core
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-05-08 21:34:41 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:30 +0200
commit2c81ad831192a8234e26a61706f18b460999c89f (patch)
tree9f16c5245fe13d93fa99797f73040a33bdc17a53 /src/video_core
parentglasm: Implement basic GLASM instructions (diff)
downloadyuzu-2c81ad831192a8234e26a61706f18b460999c89f.tar
yuzu-2c81ad831192a8234e26a61706f18b460999c89f.tar.gz
yuzu-2c81ad831192a8234e26a61706f18b460999c89f.tar.bz2
yuzu-2c81ad831192a8234e26a61706f18b460999c89f.tar.lz
yuzu-2c81ad831192a8234e26a61706f18b460999c89f.tar.xz
yuzu-2c81ad831192a8234e26a61706f18b460999c89f.tar.zst
yuzu-2c81ad831192a8234e26a61706f18b460999c89f.zip
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_compute_program.cpp17
-rw-r--r--src/video_core/renderer_opengl/gl_compute_program.h7
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp37
3 files changed, 47 insertions, 14 deletions
diff --git a/src/video_core/renderer_opengl/gl_compute_program.cpp b/src/video_core/renderer_opengl/gl_compute_program.cpp
index d5ef65439..fb54618a4 100644
--- a/src/video_core/renderer_opengl/gl_compute_program.cpp
+++ b/src/video_core/renderer_opengl/gl_compute_program.cpp
@@ -29,11 +29,11 @@ bool ComputeProgramKey::operator==(const ComputeProgramKey& rhs) const noexcept
ComputeProgram::ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_,
Tegra::MemoryManager& gpu_memory_,
Tegra::Engines::KeplerCompute& kepler_compute_,
- ProgramManager& program_manager_, OGLProgram program_,
- const Shader::Info& info_)
+ ProgramManager& program_manager_, const Shader::Info& info_,
+ OGLProgram source_program_, OGLAssemblyProgram assembly_program_)
: texture_cache{texture_cache_}, buffer_cache{buffer_cache_}, gpu_memory{gpu_memory_},
- kepler_compute{kepler_compute_},
- program_manager{program_manager_}, program{std::move(program_)}, info{info_} {
+ kepler_compute{kepler_compute_}, program_manager{program_manager_}, info{info_},
+ source_program{std::move(source_program_)}, assembly_program{std::move(assembly_program_)} {
for (const auto& desc : info.texture_buffer_descriptors) {
num_texture_buffers += desc.count;
}
@@ -124,6 +124,14 @@ void ComputeProgram::Configure() {
const std::span indices_span(image_view_indices.data(), image_view_indices.size());
texture_cache.FillComputeImageViews(indices_span, image_view_ids);
+ if (assembly_program.handle != 0) {
+ // FIXME: State track this
+ glEnable(GL_COMPUTE_PROGRAM_NV);
+ glBindProgramARB(GL_COMPUTE_PROGRAM_NV, assembly_program.handle);
+ program_manager.BindProgram(0);
+ } else {
+ program_manager.BindProgram(source_program.handle);
+ }
buffer_cache.UnbindComputeTextureBuffers();
size_t texbuf_index{};
const auto add_buffer{[&](const auto& desc) {
@@ -172,7 +180,6 @@ void ComputeProgram::Configure() {
if (image_binding != 0) {
glBindImageTextures(0, image_binding, images.data());
}
- program_manager.BindProgram(program.handle);
}
} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/gl_compute_program.h b/src/video_core/renderer_opengl/gl_compute_program.h
index 64a75d44d..ddb00dc1d 100644
--- a/src/video_core/renderer_opengl/gl_compute_program.h
+++ b/src/video_core/renderer_opengl/gl_compute_program.h
@@ -52,8 +52,8 @@ public:
explicit ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_,
Tegra::MemoryManager& gpu_memory_,
Tegra::Engines::KeplerCompute& kepler_compute_,
- ProgramManager& program_manager_, OGLProgram program_,
- const Shader::Info& info_);
+ ProgramManager& program_manager_, const Shader::Info& info_,
+ OGLProgram source_program_, OGLAssemblyProgram assembly_program_);
void Configure();
@@ -64,8 +64,9 @@ private:
Tegra::Engines::KeplerCompute& kepler_compute;
ProgramManager& program_manager;
- OGLProgram program;
Shader::Info info;
+ OGLProgram source_program;
+ OGLAssemblyProgram assembly_program;
u32 num_texture_buffers{};
u32 num_image_buffers{};
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index 9bbdfeb62..d9f0bca78 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -16,6 +16,7 @@
#include "common/scope_exit.h"
#include "core/core.h"
#include "core/frontend/emu_window.h"
+#include "shader_recompiler/backend/glasm/emit_glasm.h"
#include "shader_recompiler/backend/spirv/emit_spirv.h"
#include "shader_recompiler/frontend/ir/program.h"
#include "shader_recompiler/frontend/maxwell/control_flow.h"
@@ -89,6 +90,7 @@ const Shader::Profile profile{
.xfb_varyings = {},
};
+using Shader::Backend::GLASM::EmitGLASM;
using Shader::Backend::SPIRV::EmitSPIRV;
using Shader::Maxwell::TranslateProgram;
using VideoCommon::ComputeEnvironment;
@@ -151,6 +153,22 @@ void LinkProgram(GLuint program) {
}
}
+OGLAssemblyProgram CompileProgram(std::string_view code, GLenum target) {
+ OGLAssemblyProgram program;
+ glGenProgramsARB(1, &program.handle);
+ glNamedProgramStringEXT(program.handle, target, GL_PROGRAM_FORMAT_ASCII_ARB,
+ static_cast<GLsizei>(code.size()), code.data());
+ if (!Settings::values.renderer_debug) {
+ return program;
+ }
+ const auto err = reinterpret_cast<const char*>(glGetString(GL_PROGRAM_ERROR_STRING_NV));
+ if (err && *err) {
+ LOG_CRITICAL(Render_OpenGL, "{}", err);
+ LOG_INFO(Render_OpenGL, "{}", code);
+ }
+ return program;
+}
+
GLenum Stage(size_t stage_index) {
switch (stage_index) {
case 0:
@@ -294,13 +312,20 @@ std::unique_ptr<ComputeProgram> ShaderCache::CreateComputeProgram(ShaderPools& p
Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()};
Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)};
- const std::vector<u32> code{EmitSPIRV(profile, program)};
- OGLProgram gl_program;
- gl_program.handle = glCreateProgram();
- AddShader(GL_COMPUTE_SHADER, gl_program.handle, code);
- LinkProgram(gl_program.handle);
+ OGLAssemblyProgram asm_program;
+ OGLProgram source_program;
+ if (device.UseAssemblyShaders()) {
+ const std::string code{EmitGLASM(profile, program)};
+ asm_program = CompileProgram(code, GL_COMPUTE_PROGRAM_NV);
+ } else {
+ const std::vector<u32> code{EmitSPIRV(profile, program)};
+ source_program.handle = glCreateProgram();
+ AddShader(GL_COMPUTE_SHADER, source_program.handle, code);
+ LinkProgram(source_program.handle);
+ }
return std::make_unique<ComputeProgram>(texture_cache, buffer_cache, gpu_memory, kepler_compute,
- program_manager, std::move(gl_program), program.info);
+ program_manager, program.info,
+ std::move(source_program), std::move(asm_program));
}
} // namespace OpenGL