diff options
| -rw-r--r-- | src/video_core/renderer_opengl/gl_compute_program.cpp | 17 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_compute_program.h | 7 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 37 |
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 | |||
| 29 | ComputeProgram::ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_, | 29 | ComputeProgram::ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_, |
| 30 | Tegra::MemoryManager& gpu_memory_, | 30 | Tegra::MemoryManager& gpu_memory_, |
| 31 | Tegra::Engines::KeplerCompute& kepler_compute_, | 31 | Tegra::Engines::KeplerCompute& kepler_compute_, |
| 32 | ProgramManager& program_manager_, OGLProgram program_, | 32 | ProgramManager& program_manager_, const Shader::Info& info_, |
| 33 | const Shader::Info& info_) | 33 | OGLProgram source_program_, OGLAssemblyProgram assembly_program_) |
| 34 | : texture_cache{texture_cache_}, buffer_cache{buffer_cache_}, gpu_memory{gpu_memory_}, | 34 | : texture_cache{texture_cache_}, buffer_cache{buffer_cache_}, gpu_memory{gpu_memory_}, |
| 35 | kepler_compute{kepler_compute_}, | 35 | kepler_compute{kepler_compute_}, program_manager{program_manager_}, info{info_}, |
| 36 | program_manager{program_manager_}, program{std::move(program_)}, info{info_} { | 36 | source_program{std::move(source_program_)}, assembly_program{std::move(assembly_program_)} { |
| 37 | for (const auto& desc : info.texture_buffer_descriptors) { | 37 | for (const auto& desc : info.texture_buffer_descriptors) { |
| 38 | num_texture_buffers += desc.count; | 38 | num_texture_buffers += desc.count; |
| 39 | } | 39 | } |
| @@ -124,6 +124,14 @@ void ComputeProgram::Configure() { | |||
| 124 | const std::span indices_span(image_view_indices.data(), image_view_indices.size()); | 124 | const std::span indices_span(image_view_indices.data(), image_view_indices.size()); |
| 125 | texture_cache.FillComputeImageViews(indices_span, image_view_ids); | 125 | texture_cache.FillComputeImageViews(indices_span, image_view_ids); |
| 126 | 126 | ||
| 127 | if (assembly_program.handle != 0) { | ||
| 128 | // FIXME: State track this | ||
| 129 | glEnable(GL_COMPUTE_PROGRAM_NV); | ||
| 130 | glBindProgramARB(GL_COMPUTE_PROGRAM_NV, assembly_program.handle); | ||
| 131 | program_manager.BindProgram(0); | ||
| 132 | } else { | ||
| 133 | program_manager.BindProgram(source_program.handle); | ||
| 134 | } | ||
| 127 | buffer_cache.UnbindComputeTextureBuffers(); | 135 | buffer_cache.UnbindComputeTextureBuffers(); |
| 128 | size_t texbuf_index{}; | 136 | size_t texbuf_index{}; |
| 129 | const auto add_buffer{[&](const auto& desc) { | 137 | const auto add_buffer{[&](const auto& desc) { |
| @@ -172,7 +180,6 @@ void ComputeProgram::Configure() { | |||
| 172 | if (image_binding != 0) { | 180 | if (image_binding != 0) { |
| 173 | glBindImageTextures(0, image_binding, images.data()); | 181 | glBindImageTextures(0, image_binding, images.data()); |
| 174 | } | 182 | } |
| 175 | program_manager.BindProgram(program.handle); | ||
| 176 | } | 183 | } |
| 177 | 184 | ||
| 178 | } // namespace OpenGL | 185 | } // 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: | |||
| 52 | explicit ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_, | 52 | explicit ComputeProgram(TextureCache& texture_cache_, BufferCache& buffer_cache_, |
| 53 | Tegra::MemoryManager& gpu_memory_, | 53 | Tegra::MemoryManager& gpu_memory_, |
| 54 | Tegra::Engines::KeplerCompute& kepler_compute_, | 54 | Tegra::Engines::KeplerCompute& kepler_compute_, |
| 55 | ProgramManager& program_manager_, OGLProgram program_, | 55 | ProgramManager& program_manager_, const Shader::Info& info_, |
| 56 | const Shader::Info& info_); | 56 | OGLProgram source_program_, OGLAssemblyProgram assembly_program_); |
| 57 | 57 | ||
| 58 | void Configure(); | 58 | void Configure(); |
| 59 | 59 | ||
| @@ -64,8 +64,9 @@ private: | |||
| 64 | Tegra::Engines::KeplerCompute& kepler_compute; | 64 | Tegra::Engines::KeplerCompute& kepler_compute; |
| 65 | ProgramManager& program_manager; | 65 | ProgramManager& program_manager; |
| 66 | 66 | ||
| 67 | OGLProgram program; | ||
| 68 | Shader::Info info; | 67 | Shader::Info info; |
| 68 | OGLProgram source_program; | ||
| 69 | OGLAssemblyProgram assembly_program; | ||
| 69 | 70 | ||
| 70 | u32 num_texture_buffers{}; | 71 | u32 num_texture_buffers{}; |
| 71 | u32 num_image_buffers{}; | 72 | 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 @@ | |||
| 16 | #include "common/scope_exit.h" | 16 | #include "common/scope_exit.h" |
| 17 | #include "core/core.h" | 17 | #include "core/core.h" |
| 18 | #include "core/frontend/emu_window.h" | 18 | #include "core/frontend/emu_window.h" |
| 19 | #include "shader_recompiler/backend/glasm/emit_glasm.h" | ||
| 19 | #include "shader_recompiler/backend/spirv/emit_spirv.h" | 20 | #include "shader_recompiler/backend/spirv/emit_spirv.h" |
| 20 | #include "shader_recompiler/frontend/ir/program.h" | 21 | #include "shader_recompiler/frontend/ir/program.h" |
| 21 | #include "shader_recompiler/frontend/maxwell/control_flow.h" | 22 | #include "shader_recompiler/frontend/maxwell/control_flow.h" |
| @@ -89,6 +90,7 @@ const Shader::Profile profile{ | |||
| 89 | .xfb_varyings = {}, | 90 | .xfb_varyings = {}, |
| 90 | }; | 91 | }; |
| 91 | 92 | ||
| 93 | using Shader::Backend::GLASM::EmitGLASM; | ||
| 92 | using Shader::Backend::SPIRV::EmitSPIRV; | 94 | using Shader::Backend::SPIRV::EmitSPIRV; |
| 93 | using Shader::Maxwell::TranslateProgram; | 95 | using Shader::Maxwell::TranslateProgram; |
| 94 | using VideoCommon::ComputeEnvironment; | 96 | using VideoCommon::ComputeEnvironment; |
| @@ -151,6 +153,22 @@ void LinkProgram(GLuint program) { | |||
| 151 | } | 153 | } |
| 152 | } | 154 | } |
| 153 | 155 | ||
| 156 | OGLAssemblyProgram CompileProgram(std::string_view code, GLenum target) { | ||
| 157 | OGLAssemblyProgram program; | ||
| 158 | glGenProgramsARB(1, &program.handle); | ||
| 159 | glNamedProgramStringEXT(program.handle, target, GL_PROGRAM_FORMAT_ASCII_ARB, | ||
| 160 | static_cast<GLsizei>(code.size()), code.data()); | ||
| 161 | if (!Settings::values.renderer_debug) { | ||
| 162 | return program; | ||
| 163 | } | ||
| 164 | const auto err = reinterpret_cast<const char*>(glGetString(GL_PROGRAM_ERROR_STRING_NV)); | ||
| 165 | if (err && *err) { | ||
| 166 | LOG_CRITICAL(Render_OpenGL, "{}", err); | ||
| 167 | LOG_INFO(Render_OpenGL, "{}", code); | ||
| 168 | } | ||
| 169 | return program; | ||
| 170 | } | ||
| 171 | |||
| 154 | GLenum Stage(size_t stage_index) { | 172 | GLenum Stage(size_t stage_index) { |
| 155 | switch (stage_index) { | 173 | switch (stage_index) { |
| 156 | case 0: | 174 | case 0: |
| @@ -294,13 +312,20 @@ std::unique_ptr<ComputeProgram> ShaderCache::CreateComputeProgram(ShaderPools& p | |||
| 294 | 312 | ||
| 295 | Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()}; | 313 | Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()}; |
| 296 | Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)}; | 314 | Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)}; |
| 297 | const std::vector<u32> code{EmitSPIRV(profile, program)}; | 315 | OGLAssemblyProgram asm_program; |
| 298 | OGLProgram gl_program; | 316 | OGLProgram source_program; |
| 299 | gl_program.handle = glCreateProgram(); | 317 | if (device.UseAssemblyShaders()) { |
| 300 | AddShader(GL_COMPUTE_SHADER, gl_program.handle, code); | 318 | const std::string code{EmitGLASM(profile, program)}; |
| 301 | LinkProgram(gl_program.handle); | 319 | asm_program = CompileProgram(code, GL_COMPUTE_PROGRAM_NV); |
| 320 | } else { | ||
| 321 | const std::vector<u32> code{EmitSPIRV(profile, program)}; | ||
| 322 | source_program.handle = glCreateProgram(); | ||
| 323 | AddShader(GL_COMPUTE_SHADER, source_program.handle, code); | ||
| 324 | LinkProgram(source_program.handle); | ||
| 325 | } | ||
| 302 | return std::make_unique<ComputeProgram>(texture_cache, buffer_cache, gpu_memory, kepler_compute, | 326 | return std::make_unique<ComputeProgram>(texture_cache, buffer_cache, gpu_memory, kepler_compute, |
| 303 | program_manager, std::move(gl_program), program.info); | 327 | program_manager, program.info, |
| 328 | std::move(source_program), std::move(asm_program)); | ||
| 304 | } | 329 | } |
| 305 | 330 | ||
| 306 | } // namespace OpenGL | 331 | } // namespace OpenGL |