From 3ce28342a29610da7652247e2ec5b6b9176e5e4f Mon Sep 17 00:00:00 2001
From: ReinUsesLisp <reinuseslisp@airmail.cc>
Date: Tue, 21 Jan 2020 19:08:08 -0300
Subject: [PATCH] gl_shader_cache: Disable fastmath on Nvidia

---
 src/video_core/renderer_opengl/gl_shader_cache.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index a4acb3796f..3c5bdd377c 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -260,6 +260,10 @@ CachedProgram BuildShader(const Device& device, u64 unique_identifier, ShaderTyp
                   "#extension GL_NV_shader_thread_group : require\n"
                   "#extension GL_NV_shader_thread_shuffle : require\n";
     }
+    // This pragma stops Nvidia's driver from over optimizing math (probably using fp16 operations)
+    // on places where we don't want to.
+    // Thanks to Ryujinx for finding this workaround.
+    source += "#pragma optionNV(fastmath off)\n";
 
     if (shader_type == ShaderType::Geometry) {
         const auto [glsl_topology, max_vertices] = GetPrimitiveDescription(variant.primitive_mode);