Commit bfaec426 authored by Snawoot's avatar Snawoot Committed by GitHub

Merge pull request #204 from Snawoot/fbc

linux: add patch for Nvidia FBC
parents 07991b9c 220f4596
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
# halt on any error for safety and proper pipe handling
set -euo pipefail ; # <- this semicolon and comment make options apply
# even when script is corrupt by CRLF line terminators (issue #75)
# empty line must follow this comment for immediate fail with CRLF newlines
backup_path="/opt/nvidia/libnvidia-fbc-backup"
silent_flag=''
print_usage() { printf '
SYNOPSIS
patch-fbc.sh [-s] [-r|-h|-c VERSION|-l]
DESCRIPTION
The patch for Nvidia drivers to allow FBC on consumer devices
-s Silent mode (No output)
-r Rollback to original (Restore lib from backup)
-h Print this help message
-c VERSION Check if version VERSION supported by this patch.
Returns true exit code (0) if version is supported.
-l List supported driver versions
'
}
# shellcheck disable=SC2209
opmode="patch"
while getopts 'rshc:l' flag; do
case "${flag}" in
r) opmode="${opmode}rollback" ;;
s) silent_flag='true' ;;
h) opmode="${opmode}help" ;;
c) opmode="${opmode}checkversion" ; checked_version="$OPTARG" ;;
l) opmode="${opmode}listversions" ;;
*) echo "Incorrect option specified in command line" ; exit 2 ;;
esac
done
if [[ $silent_flag ]]; then
exec 1> /dev/null
fi
declare -A patch_list=(
["440.36"]='s/\x85\xc0\x89\xc3\x0f\x85\xa9\xfa\xff\xff/\x31\xc0\x89\xc3\x0f\x85\xa9\xfa\xff\xff/'
)
declare -A object_list=(
["440.36"]='libnvidia-fbc.so'
)
check_version_supported () {
local ver="$1"
[[ "${patch_list[$ver]+isset}" && "${object_list[$ver]+isset}" ]]
}
get_supported_versions () {
for drv in "${!patch_list[@]}"; do
[[ "${object_list[$drv]+isset}" ]] && echo "$drv"
done | sort -t. -n
return 0
}
patch_common () {
NVIDIA_SMI="$(command -v nvidia-smi || true)"
if [[ ! "$NVIDIA_SMI" ]] ; then
echo 'nvidia-smi utility not found. Probably driver is not installed.'
exit 1
fi
if ! driver_version=$("$NVIDIA_SMI" --query-gpu=driver_version --format=csv,noheader,nounits | head -n 1) ; then
echo 'Something went wrong. Check nvidia driver'
exit 1
fi
echo "Detected nvidia driver version: $driver_version"
if ! check_version_supported "$driver_version" ; then
echo "Patch for this ($driver_version) nvidia driver not found."
echo "Patch is available for versions: "
get_supported_versions
exit 1
fi
patch="${patch_list[$driver_version]}"
object="${object_list[$driver_version]}"
declare -a driver_locations=(
'/usr/lib/x86_64-linux-gnu'
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
'/usr/lib64'
"/usr/lib/nvidia-${driver_version%%.*}"
)
dir_found=''
for driver_dir in "${driver_locations[@]}" ; do
if [[ -e "$driver_dir/$object.$driver_version" ]]; then
dir_found='true'
break
fi
done
[[ "$dir_found" ]] || { echo "ERROR: cannot detect driver directory"; exit 1; }
}
rollback () {
patch_common
if [[ -f "$backup_path/$object.$driver_version" ]]; then
cp -p "$backup_path/$object.$driver_version" \
"$driver_dir/$object.$driver_version"
echo "Restore from backup $object.$driver_version"
else
echo "Backup not found. Try to patch first."
exit 1
fi
}
patch () {
patch_common
if [[ -f "$backup_path/$object.$driver_version" ]]; then
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version" | cut -f1 -d\ )"
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
if [[ "$bkp_hash" != "$drv_hash" ]] ; then
echo "Backup exists and driver file differ from backup. Skipping patch."
return 0
fi
else
echo "Attention! Backup not found. Copying current $object to backup."
mkdir -p "$backup_path"
cp -p "$driver_dir/$object.$driver_version" \
"$backup_path/$object.$driver_version"
fi
sha1sum "$backup_path/$object.$driver_version"
sed "$patch" "$backup_path/$object.$driver_version" > \
"${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
sha1sum "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
ldconfig
echo "Patched!"
}
query_version_support () {
if check_version_supported "$checked_version" ; then
echo "SUPPORTED"
exit 0
else
echo "NOT SUPPORTED"
exit 1
fi
}
list_supported_versions () {
get_supported_versions
}
case "${opmode}" in
patch) patch ;;
patchrollback) rollback ;;
patchhelp) print_usage ; exit 2 ;;
patchcheckversion) query_version_support ;;
patchlistversions) list_supported_versions ;;
*) echo "Incorrect combination of flags. Use option -h to get help."
exit 2 ;;
esac
......@@ -187,6 +187,8 @@ def main():
else:
new_driver = {
"version": args.version,
"nvenc_patch": True,
"nvfbc_patch": True,
"driver_url": url,
}
key_fun = linux_driver_key
......
......@@ -59,15 +59,14 @@ def main():
with open(DATAFILE_PATH) as data_file:
data = json.load(data_file)
drivers = data[OSKind.Windows.value]['x86_64']['drivers']
drivers = data[OSKind.Linux.value]['x86_64']['drivers']
for d in drivers:
base, sep, tail = d['patch64_url'].rpartition('/')
assert sep
assert tail
d['patch64_url'] = base + '/' + 'nvencodeapi64.1337'
d['patch32_url'] = base + '/' + 'nvencodeapi.1337'
d['driver_url'] = d['driver_url']
validate_patch(d['patch64_url'], d['patch32_url'])
d['nvenc_patch'] = True
d['nvfbc_patch'] = False
if 'driver_url' in d:
driver_url = d['driver_url']
del d['driver_url']
d['driver_url'] = driver_url
with open(DATAFILE_PATH, 'w') as data_file:
json.dump(data, data_file, indent=4)
......
......@@ -23,15 +23,24 @@ WIN_SERIES_LABELS = {
def linux_readme(data):
master_tmpl = template('linux_readme_master.tmpl')
nolink_row_tmpl = template('linux_nolink_row.tmpl', True)
link_row_tmpl = template('linux_link_row.tmpl', True)
row_tmpl = template('linux_driver_row.tmpl', True)
link_tmpl = template('markdown_link.tmpl', True)
md_true = template('markdown_true.tmpl', True).substitute()
md_false = template('markdown_false.tmpl', True).substitute()
drivers = sorted(data['drivers'], key=linux_driver_key)
def row_gen():
for drv in drivers:
driver_url = drv.get('driver_url')
t = nolink_row_tmpl if driver_url is None else link_row_tmpl
yield t.substitute(driver_version=drv['version'],
driver_url=driver_url)
if driver_url:
driver_link = link_tmpl.substitute(text="Driver link", url=driver_url)
else:
driver_link = ''
nvenc_patch = md_true if drv['nvenc_patch'] else md_false
nvfbc_patch = md_true if drv['nvfbc_patch'] else md_false
yield row_tmpl.substitute(version=drv['version'],
nvenc_patch=nvenc_patch,
nvfbc_patch=nvfbc_patch,
driver_link=driver_link)
version_list = "\n".join(row_gen())
latest_version = drivers[-1]['version']
example_driver = find_driver(drivers,
......
| $version | $nvenc_patch | $nvfbc_patch | $driver_link |
......@@ -2,7 +2,7 @@
![GitHub last commit](https://img.shields.io/github/last-commit/keylase/nvidia-patch.svg) ![Latest version](https://img.shields.io/badge/latest%20linux%20driver%20version-${latest_version}-brightgreen.svg)
This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs.
This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs. Also there is experimental NvFBC patch available which allows to use NvFBC on consumer-grade GPUs. It should be applied same way as NVENC `patch.sh`, except you have to use `patch-fbc.sh` instead.
Main target operating system is **GNU/Linux**, but for **Windows** support see [**win**](win).
......@@ -10,7 +10,12 @@ Requirements:
- x86\_64 system architecture
- GNU/Linux operating system
- nvenc-compatible gpu (https://developer.nvidia.com/video-encode-decode-gpu-support-matrix#Encoder)
- Nvidia driver. Patch available for:
- Nvidia driver. Patch available for versions in version table below.
## Version Table
| Version | NVENC patch | NVFBC patch | Driver link |
| :--- | :---: | :---: | ---: |
$version_list
## Synopsis
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment