Include NVIDIA's pinned DLSS library for Linux in the AppImage, and place it beside the built game.

On Linux the game looks for libnvidia-ngx-dlss.so.<version> beside the executable, and the driver brings
only NGX's core, so the DLSS modes did nothing in every Linux build. tools/dlss_pin.py pins the Linux
library of the DLSS version it pins for Windows, with its own size and SHA-256; tools/make_appimage.py
puts it in the kit's bin/ with its notice (downloaded from NVIDIA's DLSS SDK repository and checked, or
--dlss; --no-dlss leaves it out), and tools/make_game.py copies it beside the game on Linux as it copies
the DLL on Windows, keeping a library the player put there.

Pull request #297 by mooki000, taken as it is; the builder's description is merged with the button art
option that came with the release workflow. On Windows place_dlss does what it did. No NVIDIA file is in
the repository.

tests/launcher_test.py passes with its two new tests (112 tests, Python 3.12 on Windows); the AppImage
was not built here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 06:38:02 -05:00
parent ff4b6772f9
commit 32ee021905
6 changed files with 219 additions and 43 deletions

View File

@@ -1712,6 +1712,119 @@ class MakeGameTest(Tmp):
self.assertEqual(self.mg.notice_sha256(self.tmp / 'n.txt'), dlss_pin.SHA256)
self.assertEqual((dlss_pin.NAME, dlss_pin.NOTICE), (self.mg.DLSS_DLL, self.mg.DLSS_NOTICE))
def test_dlss_library_beside_the_game_on_linux(self):
"""The kit's libnvidia-ngx-dlss.so.<version> and its notice go beside the game. The name carries the DLSS
version, so a kit with another version replaces the file an earlier build placed under its old name, and a
library the player put there, of any version, is kept. Each platform places only its own library."""
from unittest import mock
kit, out = self.tmp / 'kit', self.tmp / 'game'
(kit / 'bin').mkdir(parents=True)
out.mkdir()
note = out / 'libnvidia-ngx-dlss-NOTICE.txt'
def kit_lib(version, data, when):
for old in (kit / 'bin').glob('libnvidia-ngx-dlss.so.*'):
old.unlink()
lib = kit / 'bin' / f'libnvidia-ngx-dlss.so.{version}'
lib.write_bytes(data)
os.utime(lib, (when, when))
(kit / 'bin' / 'libnvidia-ngx-dlss-NOTICE.txt').write_text(
f'NVIDIA DLSS {version}\n\nsha256 {hashlib.sha256(data).hexdigest()}\n')
def beside(folder=out):
return sorted(p.name for p in folder.iterdir())
with mock.patch.object(self.mg, 'KIT', kit):
self.assertIsNone(self.mg.place_dlss(out, linux=True)) # a kit without DLSS: nothing
self.assertEqual(beside(), [])
(kit / 'bin' / 'nvngx_dlss.dll').write_bytes(b'the Windows DLL')
self.assertIsNone(self.mg.place_dlss(out, linux=True)) # the Windows DLL is not a Linux build's
self.assertEqual(beside(), [])
kit_lib('310.9.1', b'dlss one', 1_700_000_000)
self.assertIsNone(self.mg.place_dlss(out, linux=True))
self.assertEqual(beside(), ['libnvidia-ngx-dlss-NOTICE.txt', 'libnvidia-ngx-dlss.so.310.9.1'])
self.assertEqual((out / 'libnvidia-ngx-dlss.so.310.9.1').read_bytes(), b'dlss one')
self.assertIn(hashlib.sha256(b'dlss one').hexdigest(), note.read_text())
self.assertIsNone(self.mg.place_dlss(out, linux=True)) # unchanged
self.assertEqual(len(beside()), 2)
kit_lib('310.10.0', b'dlss two', 1_700_100_000) # another version: the earlier build's file goes
self.assertIsNone(self.mg.place_dlss(out, linux=True))
self.assertEqual(beside(), ['libnvidia-ngx-dlss-NOTICE.txt', 'libnvidia-ngx-dlss.so.310.10.0'])
self.assertEqual((out / 'libnvidia-ngx-dlss.so.310.10.0').read_bytes(), b'dlss two')
self.assertIn(hashlib.sha256(b'dlss two').hexdigest(), note.read_text())
# a library the player put there first, of another version: kept, and the kit's is not placed beside it
mine = self.tmp / 'mine'
mine.mkdir()
(mine / 'libnvidia-ngx-dlss.so.310.4.0').write_bytes(b"the player's own DLSS")
self.assertIn('libnvidia-ngx-dlss.so.310.4.0 kept', self.mg.place_dlss(mine, linux=True))
self.assertEqual(beside(mine), ['libnvidia-ngx-dlss.so.310.4.0'])
# the same version with other bytes (the player's own build) is kept too
(mine / 'libnvidia-ngx-dlss.so.310.4.0').unlink()
(mine / 'libnvidia-ngx-dlss.so.310.10.0').write_bytes(b"the player's own build")
self.assertIn('kept', self.mg.place_dlss(mine, linux=True))
self.assertEqual((mine / 'libnvidia-ngx-dlss.so.310.10.0').read_bytes(), b"the player's own build")
# a player's library put beside a library an earlier build placed: both stay
(out / 'libnvidia-ngx-dlss.so.310.4.0').write_bytes(b"the player's own DLSS")
self.assertIn('kept', self.mg.place_dlss(out, linux=True))
self.assertEqual(len(beside()), 3)
# and a Windows build takes the DLL, not the library
win = self.tmp / 'win'
win.mkdir()
self.assertIsNone(self.mg.place_dlss(win))
self.assertEqual(beside(win), ['nvngx_dlss.dll'])
def test_dlss_pin_for_linux(self):
"""The Linux library is pinned beside the Windows DLL, at the same DLSS version with its own size and sha256.
A file on disk must be the pinned one, a missing one is downloaded into the cache under its own name, and the
notice names the library and carries the sha256 line make_game.py reads."""
import dlss_pin
from unittest import mock
p = dlss_pin.pin(linux=True)
self.assertEqual(p.name, f'libnvidia-ngx-dlss.so.{dlss_pin.VERSION}')
self.assertTrue(p.name.startswith(self.mg.DLSS_SO_PREFIX))
self.assertFalse(p.notice.startswith(self.mg.DLSS_SO_PREFIX)) # the runtime takes that prefix for the library
self.assertEqual(p.notice, self.mg.DLSS_SO_NOTICE)
self.assertEqual(dlss_pin.pin().name, dlss_pin.NAME) # the default is still the Windows DLL
self.assertNotEqual((p.size, p.sha256), (dlss_pin.SIZE, dlss_pin.SHA256))
(self.tmp / 'n.txt').write_text(dlss_pin.notice_text(linux=True), encoding='utf-8')
self.assertEqual(self.mg.notice_sha256(self.tmp / 'n.txt'), p.sha256)
self.assertIn(p.name, dlss_pin.notice_text(linux=True))
self.assertNotIn('nvngx_dlss.dll', dlss_pin.notice_text(linux=True))
data = b'a DLSS library'
lib, cache = self.tmp / 'file.so', self.tmp / 'dl'
lib.write_bytes(data)
fetched = []
def download(url, dest, sha256=None, size=None):
fetched.append((url, Path(dest).name, sha256, size))
Path(dest).parent.mkdir(parents=True, exist_ok=True)
Path(dest).write_bytes(data)
return dest
pinned = dict(LINUX_SIZE=len(data), LINUX_SHA256=hashlib.sha256(data).hexdigest(),
SIZE=len(data) + 1, SHA256=hashlib.sha256(data + b'!').hexdigest())
with mock.patch.multiple(dlss_pin, **pinned), mock.patch('launcher.net.download', download), \
contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(dlss_pin.resolve(lib, cache, linux=True), lib)
with self.assertRaises(SystemExit): # the Windows DLL's pin does not accept the Linux file
dlss_pin.resolve(lib, cache)
lib.write_bytes(b'another DLSS!')
with self.assertRaises(SystemExit):
dlss_pin.resolve(lib, cache, linux=True)
with self.assertRaises(SystemExit):
dlss_pin.resolve(self.tmp / 'missing.so', cache, linux=True)
self.assertEqual(fetched, [])
self.assertEqual(dlss_pin.resolve(None, cache, linux=True), cache / p.name)
self.assertEqual(fetched, [(p.url, p.name, hashlib.sha256(data).hexdigest(), len(data))])
self.assertEqual(dlss_pin.resolve(None, cache), cache / f'nvngx_dlss-{dlss_pin.VERSION}.dll')
self.assertEqual(fetched[1][:2], (dlss_pin.URL, f'nvngx_dlss-{dlss_pin.VERSION}.dll'))
bin_dir = self.tmp / 'bin'
bin_dir.mkdir()
dlss_pin.place(cache / p.name, bin_dir, linux=True)
self.assertEqual((bin_dir / p.notice).read_text(encoding='utf-8'), dlss_pin.notice_text(linux=True))
self.assertEqual(sorted(x.name for x in bin_dir.iterdir()), sorted([p.notice, p.name]))
self.assertEqual((bin_dir / p.name).read_bytes(), data)
def test_compile_key_ignores_file_time_and_sysroot(self):
"""The compiler's id leaves its file time out (a tool update that puts the same compiler back keeps every
object), and the key leaves --sysroot out (the fast compiler's objects are the UCRT64 compiler's)."""