Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## version 2.0
- ## run this script with any parameter in terminal for help, like this:
- ## KSP_launcher.sh --help
- ## otherwise place it into the same directory where KSP binary exists, run.
- ## if you use GOG standalone installer, in start.sh replace strings "KSP.x86_64" and "KSP.x86", with "KSP_launcher.sh"
- ## you can also make the KSP desktop file invoke this script.
- ########################### values: >default< / possible
- ## debug setting.
- ## setting this variable to anything other than "off", will cause script to dump the launch string, instead of running ksp.
- KSP_debuglauncher="off"
- KSP_gallium_bench="off" ## on / >off<
- KSP_ksp_cleanprefs="on" ## >on< / off
- KSP_ksp_forceversion="off" ## >off< / 32 / 64
- KSP_ksp_protect="on" ## >on< / off
- KSP_mesa_disableDRI3="off" ## on / >off<
- KSP_mesa_noerror="off" ## on / >off<
- KSP_mesa_software="off" ## on / >off<
- KSP_mesa_vsync="on" ## >on< / off
- KSP_nv_opts="on" ## >on< / off
- KSP_nv_preload="off" ## on / >off<
- KSP_nv_vsync="on" ## >on< / off
- KSP_radeon_R600_DEBUG="off" ## >off< / clear / (nosb/>sb<,sbcl,sbsafemaths),(>hyperz<,nohyperz), (nocpdma,nodma/forcedma), nowc
- KSP_unity_forceX="off" ## >off< / horizontal resolution, like 1920
- KSP_unity_forceY="off" ## >off< / vertical resolution, like 1080
- KSP_unity_forceLC="on" ## >on< / off
- KSP_unity_fullscreen="off" ## on / >off<
- KSP_unity_gl_old="off" ## on / >off<
- KSP_unity_glclamp="off" ## on / >off<
- KSP_unity_glcore="off" ## on / >off< / 32 / 33 / 40 / 41 / 42 / 43 / 44 / 45
- KSP_unity_gles="off" ## on / >off< / 20 / 30 / 31 / 31aep
- KSP_unity_glthread="off" ## on / >off<
- display_help() {
- echo 'written by Kerbal101. GPL3+ '
- echo ''
- echo '==============================================='
- echo 'KSP_gallium_bench '
- echo 'on / >off< '
- echo ''
- echo 'gallium-drivers only: radeon/amdgpu, nouveau, intel-gallium (not intel classic). '
- echo 'enable string to debug performance. outputs cpu, gpu, fps, gpu memory graphs. '
- echo ''
- echo '==============================================='
- echo 'KSP_ksp_cleanprefs '
- echo '>on< / off '
- echo 'cleans "prefs" file, which is unity thing and will prevent game from starting, '
- echo 'if you change video resolution in settings. its absolutely safe. '
- echo ''
- echo '==============================================='
- echo 'KSP_ksp_forceversion '
- echo '>off< (autodetect) / 32 / 64 '
- echo ''
- echo 'you can force the 32 or 64 bit version here.'
- echo ''
- echo '==============================================='
- echo 'KSP_ksp_protect '
- echo '>on< / off '
- echo 'enable crash protection, if KSP requests too much memory too fast. '
- echo 'this causes Linux to kill KSP instead of whole Xorg session, by rising KSP "naughtiness level". '
- echo 'you should really leave at "on". '
- echo ''
- echo '==============================================='
- echo 'KSP_mesa_disableDRI3 '
- echo 'on / >off< '
- echo ''
- echo 'mesa only: disables DRI3, which will cause driver to fallback to DRI2. '
- echo 'this will impact (worsen) performance and is used for debugging. '
- echo 'known to solve issue with game freezing at random points on intel driver. '
- echo 'https://bugs.freedesktop.org/show_bug.cgi?id=97890 '
- echo ''
- echo '==============================================='
- echo 'KSP_mesa_noerror'
- echo 'on / >off< '
- echo ''
- echo 'mesa only: disables error checking in mesa driver. '
- echo 'this may reduce CPU overhead, at the price of disabled error checks, which would crash the misbehaving game. '
- echo ''
- echo '==============================================='
- echo 'KSP_mesa_software '
- echo 'on / >off< '
- echo ''
- echo 'mesa only: disables hardware accelerated rendering completely and switches to LLVM-assisted software renderer. '
- echo 'usefull for debugging properties only, severely impacts performance. '
- echo ''
- echo '==============================================='
- echo 'KSP_mesa_vsync '
- echo '>on< / off '
- echo ''
- echo 'mesa only: disables vsync (off setting), which improves performance at cost of tearing and will cause GPU to run constantly hot. '
- echo 'you may want to disable SwapBuffersWait for DDX driver (in xorg.conf.d) too '
- echo 'see https://www.x.org/wiki/RadeonFeature/ '
- echo ''
- echo '==============================================='
- echo 'KSP_nv_opts '
- echo '>on< / off '
- echo 'nvidia proprietary only: force driver threaded optimizations by exporting a variable. '
- echo ''
- echo '==============================================='
- echo 'KSP_nv_preload '
- echo 'on / >off< '
- echo 'nvidia proprietary only: preloads the blob, which can solve some problems. '
- echo 'will interfere with benchmarking software like GLXOSD. '
- echo ''
- echo '==============================================='
- echo 'KSP_nv_vsync '
- echo '>on< / off '
- echo ''
- echo 'nvidia proprietary only: disables vsync (off) on nvidia proprietary driver. '
- echo ''
- echo '==============================================='
- echo 'KSP_radeon_R600_DEBUG '
- echo '>off< / clear / (nosb/>sb<,sbcl,sbsafemaths),(>hyperz<,nohyperz), (nocpdma,nodma/forcedma), nowc '
- echo ''
- echo 'radeon/amdgpu driver only: "R600_DEBUG" is a variable for changing driver options of Radeon/RadeonSI/AMDGPU. '
- echo 'some options may be already enabled in the driver internally, these are marked with "enabled by default" below. '
- echo '"off" and "clear" are handled by the script and can′t be combined with others. '
- echo 'options can be combined using comma where it makes sense: "KSP_mesa_R600_DEBUG=sbcl,hyperz,llvm,sisched,forcedma" '
- echo ''
- echo 'off - (script) do not touch R600_DEBUG variable. '
- echo 'clear - (script) clear the R600_DEBUG variable, causing driver to run with default options. '
- echo 'sb - enable shader optimizer. (enabled by default) '
- echo 'sbcl - enable shader optimizer with opencl improvements. '
- echo 'sbsafemaths - enable optimized shader backend but disable fast unsafe math ops. '
- echo 'nosb - disable shader backend. '
- echo 'hyperz - enable hyperz. (enabled by default) '
- echo 'nohyperz - disable hyperz. '
- echo 'forcedma - enable dma. '
- echo 'nodma - disable dma. '
- echo 'nocpdma - disable CP dma. '
- echo 'nowc - disable write combining. '
- echo 'llvm - enable llvm backend for shader compilation. (enabled by default?) '
- echo 'sisched - enable improved radensi scheduler in llvm. '
- echo ''
- echo '==============================================='
- echo 'KSP_unity_forceX '
- echo '>off< / horizontal resolution, like 1920 '
- echo 'KSP_unity_forceY '
- echo '>off< / vertical resolution, like 1080 '
- echo ''
- echo 'unity option: force horizontal and vertical resolution. '
- echo 'useful to if KSP starts with window of weird sizes. '
- echo ''
- echo '==============================================='
- echo 'KSP_unity_forceLC '
- echo '>on< / off '
- echo ''
- echo 'exports LC_ALL=C var, which solves the problem of non-us_US encoding with numeric comma. '
- echo 'symptons include absent savegames and KSP forgetting settings. '
- echo ''
- echo '==============================================='
- echo 'KSP_unity_fullscreen '
- echo 'on / >off<'
- echo ''
- echo 'unity option: force fullscreen in KSP. '
- echo ''
- echo '==============================================='
- echo 'KSP_unity_gl_old '
- echo 'on / >off< '
- echo ''
- echo 'unity option: force old unity OpenGL backend. blocks gles settings. '
- echo ''
- echo '==============================================='
- echo 'KSP_unity_glclamp '
- echo 'on / >off< '
- echo ''
- echo 'unity option: disable opengl extensions. primary used for debugging.'
- echo ''
- echo '==============================================='
- echo 'KSP_unity_glcore '
- echo 'on / >off< / 32 / 33 / 40 / 41 / 42 / 43 / 44 / 45 '
- echo ''
- echo 'unity option: force unity to use GL "core profile", instead of the "compat. profile" - which has legacy/outdated GL codepaths. '
- echo 'recommended on mesa and drivers that dont implement legacy functions fully. '
- echo 'enable if you experience weird planet colors or black screen during launch. '
- echo 'see: https://docs.unity3d.com/Manual/OpenGLCoreDetails.html '
- echo 'blocks gles settings. '
- echo 'off = use compat. profile, on = force and detect core profile, number = on +limit core profile to specified level'
- echo ''
- echo '==============================================='
- echo 'KSP_unity_gles '
- echo 'on / >off< / 20 / 30 / 31 / 31aep '
- echo 'unity option: force opengles. will not work, if glcore or oldgl options are enabled. '
- echo 'see: https://docs.unity3d.com/Manual/OpenGLCoreDetails.html '
- echo 'off = use opengl, on = use gles, number = on+limit gles profile to level'
- echo ''
- echo '==============================================='
- echo 'KSP_unity_glthread '
- echo 'on / >off< '
- echo ''
- echo 'unity option: force OpenGL backend to use single rendering thread. may reduce render performance. '
- echo 'this is known to solve issues with old amd proprietary driver (fglrx/catalyst) freezing, but is applicable to all drivers. '
- echo ''
- exit 0
- }
- ## this is an internal variable that is filled as needed. Do not change.
- KSP_params=""
- ## this is an internal variable that is filled with exported values, shown at debug. Do not change.
- KSP_env_debug=""
- ## display help if we have any parameters, else run.
- if [[ -n "$1" ]]; then display_help; fi
- if [[ "$KSP_ksp_forceversion" = "32" ]]; then
- KSP_bin="./KSP.x86"
- elif [[ "$KSP_ksp_forceversion" = "64" ]]; then
- KSP_bin="./KSP.x86_64"
- else
- if [[ "$(uname -m)" = "x86_64" ]]; then
- KSP_bin="./KSP.x86_64"
- else
- KSP_bin="./KSP.x86"
- fi
- fi
- if [[ "$KSP_mesa_vsync" = "off" ]]; then
- export vblank_mode=0
- KSP_env_debug+="export vblank_mode=0\n"
- fi
- if [[ "$KSP_nv_vsync" = "off" ]]; then
- nvidia-settings --load-config-only --assign="SyncToVBlank=0"
- KSP_nvcorrect="yes"
- KSP_env_debug+="execute: nvidia-settings --load-config-only --assign=\"SyncToVBlank=0\"\n"
- fi
- ## options can be extracted with "GALLIUM_HUD=help glxgears"
- ## each option consumes cycles, so stat sparingly!
- if [[ ! "$KSP_gallium_bench" = "off" ]]; then
- export GALLIUM_HUD="VRAM-usage+temperature+fps+cpu+GPU-load,cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7"
- KSP_env_debug+="export GALLIUM_HUD=\"VRAM-usage+temperature+fps+cpu+GPU-load,cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7\"\n"
- fi
- if [[ ! "$KSP_mesa_noerror" = "off" ]]; then
- export MESA_NO_ERROR=1
- KSP_env_debug+="export MESA_NO_ERROR=1\n"
- fi
- if [[ "$KSP_ksp_cleanprefs" = "on" ]]; then
- rm -f "${HOME}/.config/unity3d/Squad/Kerbal Space Program/prefs"
- KSP_env_debug+="execute: rm -f \"${HOME}/.config/unity3d/Squad/Kerbal Space Program/prefs\"\n"
- fi
- if [[ "$KSP_unity_forceLC" = "on" ]]; then
- export LC_ALL=C
- KSP_env_debug+="export LC_ALL=C\n"
- fi
- if [[ ! "$KSP_mesa_disableDRI3" = "off" ]]; then
- export LIBGL_DRI3_DISABLE=1
- KSP_env_debug+="export LIBGL_DRI3_DISABLE=1\n"
- fi
- if [[ ! "$KSP_mesa_software" = "off" ]]; then
- export LIBGL_ALWAYS_SOFTWARE=1
- KSP_env_debug+="export LIBGL_ALWAYS_SOFTWARE=1\n"
- fi
- if [[ ! "$KSP_unity_fullscreen" = "off" ]]; then
- KSP_params+=" -screen-fullscreen 1 "
- fi
- if [[ ! "$KSP_radeon_R600_DEBUG" = "off" ]]; then
- if [[ "$KSP_radeon_R600_DEBUG" = "clear" ]]; then
- unset R600_DEBUG
- KSP_env_debug+="unset R600_DEBUG\n"
- else
- unset R600_DEBUG
- export R600_DEBUG="${KSP_radeon_R600_DEBUG}"
- KSP_env_debug+="unset R600_DEBUG\n"
- KSP_env_debug+="export R600_DEBUG=\"${KSP_radeon_R600_DEBUG}\"\n"
- fi
- fi
- if [[ ! "$KSP_unity_forceX" = "off" ]]; then
- KSP_params+=" -screen-width ${KSP_unity_forceX} "
- fi
- if [[ ! "$KSP_unity_forceY" = "off" ]]; then
- KSP_params+=" -screen-height ${KSP_unity_forceY} "
- fi
- if [[ ! "$KSP_unity_gl_old" = "off" ]]; then
- KSP_params+=" -force-opengl "
- fi
- if [[ ! "$KSP_unity_glthread" = "off" ]]; then
- KSP_params+=" -force-gfx-direct "
- fi
- if [[ ! "$KSP_unity_glcore" = "off" ]]; then
- if [[ "$KSP_unity_glcore" = "on" ]]; then
- KSP_params+=" -force-glcore "
- else
- KSP_params+=" -force-glcore${KSP_unity_glcore} "
- fi
- fi
- if [[ ! "$KSP_unity_glclamp" = "off" ]]; then
- KSP_params+=" -force-clamped "
- fi
- if [[ ! "$KSP_unity_gles" = "off" ]] && [[ "$KSP_unity_glcore" = "off" ]] && [[ "$KSP_unity_gl_old" == "off" ]]; then
- if [[ "$KSP_unity_gles" = "on" ]]; then
- KSP_params+=" -force-gles "
- else
- KSP_params+=" -force-gles${KSP_unity_gles} "
- fi
- fi
- if [[ ! "$KSP_nv_preload" = "off" ]]; then
- export LD_PRELOAD="libpthread.so.0 libGL.so.1"
- KSP_env_debug+="export LD_PRELOAD=\"libpthread.so.0 libGL.so.1\"\n"
- fi
- if [[ ! "$KSP_nv_opts" = "off" ]]; then
- export __GL_THREADED_OPTIMIZATIONS=1
- KSP_env_debug+="export __GL_THREADED_OPTIMIZATIONS=1\n"
- fi
- if [[ ! "$KSP_ksp_protect" = "off" ]]; then
- if [[ ! "$KSP_debuglauncher" = "off" ]]; then
- KSP_env_debug+="Would increase KSP binary naughtiness value.\n"
- else
- if [[ "$KSP_bin" = "./KSP.x86" ]]; then
- sh -c 'sleep 3 ; echo 15 > "/proc/$(pgrep KSP.x86)/oom_adj"' &
- sh -c 'sleep 2 ; echo 15 > "/proc/$(pgrep KSP.x86)/oom_adj"' &
- sh -c 'sleep 1 ; echo 15 > "/proc/$(pgrep KSP.x86)/oom_adj"' &
- else
- sh -c 'sleep 3 ; echo 15 > "/proc/$(pgrep KSP.x86_64)/oom_adj"' &
- sh -c 'sleep 2 ; echo 15 > "/proc/$(pgrep KSP.x86_64)/oom_adj"' &
- sh -c 'sleep 1 ; echo 15 > "/proc/$(pgrep KSP.x86_64)/oom_adj"' &
- fi
- fi
- fi
- ####### executing KSP if debug is off, otherwise just spill the parameters into shell
- if [[ ! "$KSP_debuglauncher" = "off" ]]; then
- echo -e "${KSP_env_debug}"
- echo ''
- echo -e "Would finally execute: ${KSP_bin} ${KSP_params}"
- else
- exec "$KSP_bin" "$KSP_params"
- fi
- #######
- ## will restore vsync for nvidia after game exit, if the script enabled it.
- if [[ $KSP_nvcorrect = "yes" ]]; then
- nvidia-settings --load-config-only --assign="SyncToVBlank=1"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement