summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-01-20 20:09:57 -0300
committerGravatar ReinUsesLisp2021-01-21 00:41:03 -0300
commit51512d01d8e956b2afada91e51dfd7c0a6444ad6 (patch)
tree920ed6ec21b438894b7caeef0a946dbfc2ead10a /src/video_core
parentMerge pull request #5755 from FearlessTobi/port-5344 (diff)
downloadyuzu-51512d01d8e956b2afada91e51dfd7c0a6444ad6.tar.gz
yuzu-51512d01d8e956b2afada91e51dfd7c0a6444ad6.tar.xz
yuzu-51512d01d8e956b2afada91e51dfd7c0a6444ad6.zip
renderer_opengl: Avoid precompiled cache and force NV GL cache directory
Setting __GL_SHADER_DISK_CACHE_PATH we can force the cache directory to be in yuzu's user directory to stop commonly distributed malware from deleting our driver shader cache. And by setting __GL_SHADER_DISK_CACHE_SKIP_CLEANUP we can have an unbounded shader cache size. This has only been implemented on Windows, mostly because previous tests didn't seem to work on Linux. Disable the precompiled cache on Nvidia's driver. There's no need to hide information the driver already has in its own cache.
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_device.cpp1
-rw-r--r--src/video_core/renderer_opengl/gl_device.h5
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp13
3 files changed, 14 insertions, 5 deletions
diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp
index 81b71edfb..04c267ee4 100644
--- a/src/video_core/renderer_opengl/gl_device.cpp
+++ b/src/video_core/renderer_opengl/gl_device.cpp
@@ -246,6 +246,7 @@ Device::Device()
246 GLAD_GL_NV_transform_feedback && GLAD_GL_NV_transform_feedback2; 246 GLAD_GL_NV_transform_feedback && GLAD_GL_NV_transform_feedback2;
247 247
248 use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue(); 248 use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue();
249 use_driver_cache = is_nvidia;
249 250
250 LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi); 251 LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi);
251 LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug); 252 LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug);
diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.h
index 3e79d1e37..9141de635 100644
--- a/src/video_core/renderer_opengl/gl_device.h
+++ b/src/video_core/renderer_opengl/gl_device.h
@@ -120,6 +120,10 @@ public:
120 return use_asynchronous_shaders; 120 return use_asynchronous_shaders;
121 } 121 }
122 122
123 bool UseDriverCache() const {
124 return use_driver_cache;
125 }
126
123private: 127private:
124 static bool TestVariableAoffi(); 128 static bool TestVariableAoffi();
125 static bool TestPreciseBug(); 129 static bool TestPreciseBug();
@@ -147,6 +151,7 @@ private:
147 bool has_debugging_tool_attached{}; 151 bool has_debugging_tool_attached{};
148 bool use_assembly_shaders{}; 152 bool use_assembly_shaders{};
149 bool use_asynchronous_shaders{}; 153 bool use_asynchronous_shaders{};
154 bool use_driver_cache{};
150}; 155};
151 156
152} // namespace OpenGL 157} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index d4841fdb7..529570ff0 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -159,6 +159,10 @@ std::unordered_set<GLenum> GetSupportedFormats() {
159 159
160ProgramSharedPtr BuildShader(const Device& device, ShaderType shader_type, u64 unique_identifier, 160ProgramSharedPtr BuildShader(const Device& device, ShaderType shader_type, u64 unique_identifier,
161 const ShaderIR& ir, const Registry& registry, bool hint_retrievable) { 161 const ShaderIR& ir, const Registry& registry, bool hint_retrievable) {
162 if (device.UseDriverCache()) {
163 // Ignore hint retrievable if we are using the driver cache
164 hint_retrievable = false;
165 }
162 const std::string shader_id = MakeShaderID(unique_identifier, shader_type); 166 const std::string shader_id = MakeShaderID(unique_identifier, shader_type);
163 LOG_INFO(Render_OpenGL, "{}", shader_id); 167 LOG_INFO(Render_OpenGL, "{}", shader_id);
164 168
@@ -336,7 +340,7 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
336 } 340 }
337 341
338 std::vector<ShaderDiskCachePrecompiled> gl_cache; 342 std::vector<ShaderDiskCachePrecompiled> gl_cache;
339 if (!device.UseAssemblyShaders()) { 343 if (!device.UseAssemblyShaders() && !device.UseDriverCache()) {
340 // Only load precompiled cache when we are not using assembly shaders 344 // Only load precompiled cache when we are not using assembly shaders
341 gl_cache = disk_cache.LoadPrecompiled(); 345 gl_cache = disk_cache.LoadPrecompiled();
342 } 346 }
@@ -356,8 +360,7 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
356 std::atomic_bool gl_cache_failed = false; 360 std::atomic_bool gl_cache_failed = false;
357 361
358 const auto find_precompiled = [&gl_cache](u64 id) { 362 const auto find_precompiled = [&gl_cache](u64 id) {
359 return std::find_if(gl_cache.begin(), gl_cache.end(), 363 return std::ranges::find(gl_cache, id, &ShaderDiskCachePrecompiled::unique_identifier);
360 [id](const auto& entry) { return entry.unique_identifier == id; });
361 }; 364 };
362 365
363 const auto worker = [&](Core::Frontend::GraphicsContext* context, std::size_t begin, 366 const auto worker = [&](Core::Frontend::GraphicsContext* context, std::size_t begin,
@@ -432,8 +435,8 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
432 return; 435 return;
433 } 436 }
434 437
435 if (device.UseAssemblyShaders()) { 438 if (device.UseAssemblyShaders() || device.UseDriverCache()) {
436 // Don't store precompiled binaries for assembly shaders. 439 // Don't store precompiled binaries for assembly shaders or when using the driver cache
437 return; 440 return;
438 } 441 }
439 442