-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpt
executable file
·169 lines (146 loc) · 4.9 KB
/
rpt
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# rpt is a Runtime performance tuner.
import os
import sys
import argparse
import shutil
import logging
import subprocess
def SplitArgv(argv):
i = -1
try:
i = argv.index('--')
except ValueError:
pass
if i == -1:
return argv[:], []
return argv[:i], argv[i + 1:]
ext_LD_PRELOAD = set()
ext_LD_LIBRARY_PATH = set()
# TODO: Support customizing environment variables.
ext_ENV = set()
def EnableProtonRTX():
ext_ENV.add('PROTON_HIDE_NVIDIA_GPU=0')
ext_ENV.add('VKD3D_CONFIG=dxr11,dxr')
ext_ENV.add('PROTON_ENABLE_NVAPI=1')
ext_ENV.add('PROTON_ENABLE_NGX_UPDATER=1')
def EnableProtonFSR(level='ultra'):
ext_ENV.add('WINE_FULLSCREEN_FSR=1')
ext_ENV.add(f'WINE_FULLSCREEN_FSR_MODE={level}')
def EnableMangoHud():
ext_LD_LIBRARY_PATH.add('/usr/$LIB/mangohud')
ext_LD_PRELOAD.add('libMangoHud.so')
ext_ENV.add('MANGOHUD=1')
def EnableMangoHudDlsym():
ext_LD_LIBRARY_PATH.add('/usr/$LIB/mangohud')
ext_LD_PRELOAD.add('libMangoHud_dlsym.so')
ext_ENV.add('MANGOHUD=1')
def UseMalloc(allocator):
if allocator == '<default>':
return
elif allocator == 'jemalloc':
ext_LD_PRELOAD.add('libjemalloc.so')
elif allocator == 'mimalloc':
ext_LD_PRELOAD.add('libmimalloc.so')
elif allocator == 'tcmalloc':
ext_LD_PRELOAD.add('libtcmalloc.so')
else:
logging.error('Unsupported allocator: {}'.format(allocator))
def RunProgram(command):
argv = ['env']
argv.extend(ext_ENV)
def UpdatePath(key, extra):
argv.append('{}={}'.format(
key,
os.environ.get(key, '') + os.path.pathsep +
os.path.pathsep.join(extra)))
UpdatePath('LD_LIBRARY_PATH', ext_LD_LIBRARY_PATH)
UpdatePath('LD_PRELOAD', ext_LD_PRELOAD)
argv.extend(command)
return os.execv(shutil.which('env'), argv)
def main():
parser = argparse.ArgumentParser(
description="{} -- %command% in steam's launch options".format(
sys.argv[0]))
parser.add_argument('--mangohud',
action='store_true',
default=False,
help='Enable mangohud hooking')
parser.add_argument('--mangohud_dlsym',
action='store_true',
default=False,
help='Enable mangohud dlsym hooking')
parser.add_argument('--malloc',
default='<default>',
help='Memory allocator to use')
parser.add_argument('-l',
'--preload',
action='append',
help='Append library to LD_PRELOAD')
parser.add_argument('--fsr',
type=str,
default='ultra',
help='Try to enable FSR support in proton')
# Use `lscpu --all --extended` to find out which core a CPU belongs to.
parser.add_argument('--bind_cpus', help='Bind process to specific CPUs')
parser.add_argument('--cpu_affinity', help='Set process affinity')
parser.add_argument('--high_priority',
help='Set process at high priority',
action='store_true',
default=False)
parser.add_argument('--rtx',
help='Tell proton to use NV RTX card features',
action='store_true',
default=False)
my_argv, command = SplitArgv(sys.argv[1:])
if not command:
parser.print_help(sys.stderr)
return 1
config = parser.parse_args(my_argv)
if config.mangohud:
EnableMangoHud()
if config.mangohud_dlsym:
EnableMangoHudDlsym()
if config.fsr:
EnableProtonFSR(config.fsr)
if config.rtx:
EnableProtonRTX()
UseMalloc(config.malloc)
if config.preload:
ext_LD_PRELOAD.update(config.preload)
if config.bind_cpus:
command_prefix = [
'numactl',
'-l',
]
command_prefix.append(f'-C{config.bind_cpus}')
command = command_prefix + command
pid = os.getpid()
if config.cpu_affinity:
cmd = [
'taskset',
'-acp',
config.cpu_affinity,
f'{pid}',
]
subprocess.run(cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
if config.high_priority:
# User has to modify /etc/security/limits.conf to allow negative nice
# value.
# For example:
# @sudo - nice -20
cmd = [
'renice',
'-n',
'-10',
f'{pid}',
]
subprocess.run(cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
return RunProgram(command)
if __name__ == '__main__':
sys.exit(main())