aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/GraphicsDriver/DriverUtilities.cs
blob: a9163f348545605cbef0a9d428e1354b6ae72478 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Ryujinx.Common.Utilities;
using System;

namespace Ryujinx.Common.GraphicsDriver
{
    public static class DriverUtilities
    {
        private static void AddMesaFlags(string envVar, string newFlags)
        {
            string existingFlags = Environment.GetEnvironmentVariable(envVar);

            string flags = existingFlags == null ? newFlags : $"{existingFlags},{newFlags}";

            OsUtils.SetEnvironmentVariableNoCaching(envVar, flags);
        }

        public static void InitDriverConfig(bool oglThreading)
        {
            if (OperatingSystem.IsLinux())
            {
                AddMesaFlags("RADV_DEBUG", "nodcc");
            }

            ToggleOGLThreading(oglThreading);
        }

        public static void ToggleOGLThreading(bool enabled)
        {
            OsUtils.SetEnvironmentVariableNoCaching("mesa_glthread", enabled.ToString().ToLower());
            OsUtils.SetEnvironmentVariableNoCaching("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");

            try
            {
                NVThreadedOptimization.SetThreadedOptimization(enabled);
            }
            catch
            {
                // NVAPI is not available, or couldn't change the application profile.
            }
        }
    }
}