From 61121d1b22cd4aa6537fcc212d08a2e2314ca39c Mon Sep 17 00:00:00 2001
From: lat9nq <lat9nq@gmail.com>
Date: Thu, 28 Oct 2021 19:04:06 -0400
Subject: [PATCH] gl_device: Force GLASM on NVIDIA drivers 495-496

GLSL shaders currently do not render correctly on the recent NVIDIA
drivers. This adds a check that forces assembly shaders for these
drivers since they seem unaffected and adds a warning informing of the
decision.

Developers can disable the check by enabling graphics debugging.
---
 src/video_core/renderer_opengl/gl_device.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp
index 1e1d1d020..0764ea6e0 100644
--- a/src/video_core/renderer_opengl/gl_device.cpp
+++ b/src/video_core/renderer_opengl/gl_device.cpp
@@ -181,6 +181,21 @@ Device::Device() {
         LOG_ERROR(Render_OpenGL, "Assembly shaders enabled but not supported");
         shader_backend = Settings::ShaderBackend::GLSL;
     }
+
+    if (shader_backend == Settings::ShaderBackend::GLSL && is_nvidia &&
+        !Settings::values.renderer_debug) {
+        const std::string_view driver_version = version.substr(13);
+        const int version_major =
+            std::atoi(driver_version.substr(0, driver_version.find(".")).data());
+
+        if (version_major >= 495) {
+            LOG_WARNING(Render_OpenGL, "NVIDIA drivers 495 and later causes significant problems "
+                                       "with yuzu. Forcing GLASM as a mitigation.");
+            shader_backend = Settings::ShaderBackend::GLASM;
+            use_assembly_shaders = true;
+        }
+    }
+
     // Blocks AMD and Intel OpenGL drivers on Windows from using asynchronous shader compilation.
     use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue() &&
                                !(is_amd || (is_intel && !is_linux));