diff --git a/app/build.gradle b/app/build.gradle index e4e0284b6..959a20ebd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -286,7 +286,13 @@ def stageRuntimeAssets = tasks.register('stageRuntimeAssets', Sync) { into(runtimeAssetsDir) } android.sourceSets.main.assets.setSrcDirs([runtimeAssetsDir]) +def fetchQualcommBuilds = tasks.register('fetchQualcommBuilds', Exec) { + workingDir rootProject.projectDir + commandLine pythonExecutable, 'tools/qualcomm/fetch_runtime.py', '--builds-only', + '--cache', rootProject.file('build/qualcomm-cache').absolutePath +} def stageQualcommRuntime = tasks.register('stageQualcommRuntime', Exec) { + dependsOn fetchQualcommBuilds workingDir rootProject.projectDir inputs.files(qualcommSources) if (qualcommRuntime.gamescope.build) { diff --git a/tools/qualcomm/README.md b/tools/qualcomm/README.md index 26ee372a1..4d8f1ff63 100644 --- a/tools/qualcomm/README.md +++ b/tools/qualcomm/README.md @@ -48,7 +48,7 @@ The controlled descriptor-mode test reproduced corruption with `ZINK_DESCRIPTORS The packaged APK was installed and checked without agent environment overrides or tracing preloads in session `2026-10-24-59-steam`. The game page, gear menu and Properties page rendered correctly. The browser's actual process environment contained `ZINK_DESCRIPTORS=auto`; its maps contained the imported v891.7 HAL and private Zink. Chromium reported GPU compositing and rasterization enabled on Adreno 840. Evidence is under `build/research/qualcomm/adreno840`, including `descriptors-auto*`, `nogeneral*` (a failing control), and `packaged-*`. Adreno 740 requires retesting; the underlying lazy-descriptor failure has not been reduced to a standalone Mesa test. -`runtime.json` pins the downloaded bridge and WSI archives, the locally built private Gamescope binary and corresponding source archive, and every private Mesa runtime file. `fetch_runtime.py` checks these pins before Gradle stages them. Missing local build outputs fail the build. Qualcomm's proprietary device libraries are loaded from the phone and are not included in these archives. The bridge archive includes its licenses, source snapshot and patches. +`runtime.json` pins the downloaded bridge and WSI archives, the locally built private Gamescope binary and corresponding source archive, and every private Mesa runtime file. `fetch_runtime.py` checks these pins before Gradle stages them. Missing or mismatched build outputs are downloaded from the pinned `builds` archive, which DroidDeck-Components builds from this tree on ARM64 CI (`tools/qualcomm-runtime`, Arch Linux ARM) and publishes as a `qualcomm-runtime` release. Qualcomm's proprietary device libraries are loaded from the phone and are not included in these archives. The bridge archive includes its licenses, source snapshot and patches. The same lock pins a vendor-neutral X11 WSI layer and upstream Gamescope shader source. `build_shaders.py` applies `constant-yuv-samplers.patch` and builds six replacement SPIR-V modules with the configured NDK's `glslc`. It builds a small ARM64 glibc Vulkan layer using the NDK compiler without Android runtime linkage. The layer matches the six original Gamescope module fingerprints before substituting a shader; ordinary applications use the WSI/compatibility layers instead. Source archives, patches and licenses are packaged with the runtime. The patch can also be applied during a full Gamescope source build. diff --git a/tools/qualcomm/fetch_runtime.py b/tools/qualcomm/fetch_runtime.py index 162f4e303..b89f419cc 100644 --- a/tools/qualcomm/fetch_runtime.py +++ b/tools/qualcomm/fetch_runtime.py @@ -4,14 +4,15 @@ import hashlib import json from pathlib import Path import shutil +import tarfile import urllib.request import zipfile -def fetch(cache, lock): +def fetch(cache, lock, suffix='.tzst'): expected = lock['sha256'] cache.mkdir(parents=True, exist_ok=True) - archive = cache / (expected + '.tzst') + archive = cache / (expected + suffix) def valid(path): return path.is_file() and path.stat().st_size == lock['size'] and hashlib.sha256(path.read_bytes()).hexdigest() == expected if not valid(archive): @@ -27,6 +28,42 @@ def fetch(cache, lock): return archive +def pinned_builds(root, lock): + pins = [] + built = lock['gamescope'].get('build') + if built: + pins.append((built['binary'], lock['gamescope']['member_sha256'], None)) + pins.append((built['source'], built['source_sha256'], built['source_size'])) + if 'mesa' in lock: + pins += [(lock['mesa']['directory'] + '/' + entry['path'], entry['sha256'], entry['size']) for entry in lock['mesa']['files']] + if 'build' in lock.get('wsi', {}): + pins += [(lock['wsi']['build']['directory'] + '/' + entry['name'], entry['sha256'], entry['size']) + for entry in lock['wsi']['files'] if entry.get('built')] + def matches(name, sha256, size): + path = root / name + return path.is_file() and (size is None or path.stat().st_size == size) and hashlib.sha256(path.read_bytes()).hexdigest() == sha256 + return all(matches(*pin) for pin in pins) + + +def unpack_builds(cache, lock): + builds = lock.get('builds') + root = Path(__file__).resolve().parents[2] + if not builds or pinned_builds(root, lock): + return + destination = root / 'build' + with tarfile.open(fetch(cache, builds, '.tar.xz'), 'r:xz') as package: + for member in package.getmembers(): + relative = Path(member.name) + if relative.is_absolute() or '..' in relative.parts or not (member.isfile() or member.isdir()): + raise ValueError('Invalid Qualcomm build member: ' + member.name) + if member.isfile(): + target = destination / relative + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(package.extractfile(member).read()) + if not pinned_builds(root, lock): + raise ValueError('Qualcomm builds failed SHA-256 verification') + + def stage(output, cache, lock, ndk=None): archive = fetch(cache, lock) output.mkdir(parents=True, exist_ok=True) @@ -110,8 +147,15 @@ def stage(output, cache, lock, ndk=None): if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--output', type=Path) parser.add_argument('--cache', type=Path, required=True) - parser.add_argument('--ndk', type=Path, required=True) + parser.add_argument('--ndk', type=Path) + parser.add_argument('--builds-only', action='store_true') args = parser.parse_args() - stage(args.output, args.cache, json.loads(Path(__file__).with_name('runtime.json').read_text()), args.ndk) + lock = json.loads(Path(__file__).with_name('runtime.json').read_text()) + if args.builds_only: + unpack_builds(args.cache, lock) + elif args.output is None or args.ndk is None: + parser.error('--output and --ndk are required') + else: + stage(args.output, args.cache, lock, args.ndk) diff --git a/tools/qualcomm/runtime.json b/tools/qualcomm/runtime.json index cbb5d58a8..c5371f39c 100644 --- a/tools/qualcomm/runtime.json +++ b/tools/qualcomm/runtime.json @@ -10,21 +10,26 @@ }, "gamescope": { "source_commit": "8f212644c46460549035971ab914421180f61a7c", - "member_sha256": "a7cce9f11bbb39da0543a14a6dcf56765117d2c577b3d7fac6caadda5039563c", + "member_sha256": "795f11c31adb1a1aa3447d913255c872626114c2713c6d80f8a82df10cf94185", "build": { "binary": "build/qualcomm-gamescope/gamescope", "source": "build/qualcomm-gamescope/source.tar.gz", - "source_sha256": "b9bec99913cebcd6d1a443f9b3263ff90a6f04574f116c8612d6f8ef86ab5f38", - "source_size": 10104476 + "source_sha256": "49e48fa2dc3b98c15633789d0a6c383630f34ed54e48649dcb46c55e446f0417", + "source_size": 10055262 } }, + "builds": { + "url": "https://github.com/Droid-Deck/DroidDeck-Components/releases/download/qualcomm-runtime-r2/qualcomm-builds.tar.xz", + "sha256": "f9db946db80b4db477cecfeae69eccb9496b1d6081550732a811f5d34a1772b6", + "size": 15138484 + }, "wsi": { "files": [ { "mode": 420, "name": "libVkLayer_window_system_integration.so", "path": "wsi/libVkLayer_window_system_integration.so", - "sha256": "5990b32d6e0ce8fe250214a6f07d71ebf6cfcc6f03c3a3c573495721510c5b3b", + "sha256": "4319d14947c6957ae4f58897a6adc8a4194e68728dee9ff386a87e6a93845706", "size": 397384, "built": true }, @@ -167,83 +172,83 @@ "files": [ { "path": "dri/zink_dri.so", - "sha256": "a65a4b895ebf49ec2841023fa550f50344574e1b68d574468365ea7857f577fa", + "sha256": "5f6c653df307d04451a70e3a2f086bee2f0c4a8cbeecd278e2b619b45ee0098f", "size": 133368 }, { "path": "egl-vendor.json", - "sha256": "aafac15b0a72b9b782d88729f3481c217b27f6e8664ffc9d6493df566ebb466a", - "size": 93 + "sha256": "5bb351d2e10383f865f5b67d44bfff9a6a8964c6cc969efb1d94a058ef11f48d", + "size": 92 }, { "path": "gbm/dri_gbm.so", - "sha256": "57e5aa8c3903c13db6a38e28cdc9160f2bd09cec04c88c90d6603d15b761b524", + "sha256": "5d99296fa5c898e43d104610f9a8cc78ed8d4776100a00a5dfc5de2c29d1993b", "size": 134024 }, { "path": "libEGL_droiddeck_qualcomm.so.0", - "sha256": "234d2041db7e87717c507ee90697058f646d1d9b61adc94f4a8cc52576fe733d", + "sha256": "f99c99b8edd380891bc18e276decb687b76e2dd249e7fe3fbded9aaf1f938d90", "size": 398632 }, { "path": "libgallium-26.2.3.so", - "sha256": "c2367279e61cad9d2fa16ff1bc247b565ff86e38f5a6b6aff5e63c5f1607e869", + "sha256": "f05580834e111df6f8ddaa8c96620f80317e40fb8032ee4eebb668c14c4cf401", "size": 21578352 }, { "path": "libgbm.so.1", - "sha256": "e9f131c50d423832eb947292b2a4f6405e51c272ce76906e3e31d5e5988334a9", + "sha256": "3a4018b5afea4de258c8b116e8e0f94bb2488a57ad2f63b0d5021d4cc922d91e", "size": 67840 }, { "path": "libGLX_droiddeck_qualcomm.so.0", - "sha256": "0c508865568327c98230c7ae5c241716715e70cc5b9dfc942cdb7bb79fc346a5", + "sha256": "bae86c5d5847e245f790174ff68646d5ab1c68224cbb55faf0c53d15ef152b5f", "size": 397704 }, { "path": "licenses/Apache-2.0", - "sha256": "aeae52465380b8b7959c940355e869cbbc277d4559a7ababa49cbc4818c051f5", - "size": 10232 + "sha256": "7e4d3fba250d15e9e0afa380d4b611828fa2560cc8fdebe95bcf2f01a487de12", + "size": 10045 }, { "path": "licenses/BSL-1.0", - "sha256": "cf7105f24feaf70f28b8de10074e4d37bef89b8f3ae0a5f1280237f027d77ec0", - "size": 1666 + "sha256": "9b9fea7520a816107fcac2598b7c0155222f16bc430e989706b22f4367f1df7d", + "size": 1649 }, { "path": "licenses/exceptions/Linux-Syscall-Note", - "sha256": "d3a16686cf8797fd8a7b35564b9de8586e6ed8e19c9447e16ab6dda0d411215d", - "size": 1281 + "sha256": "9b4084655174654608fd037e9ddb4feeadfada01cd042e9c17b05aa7105b2b9f", + "size": 1257 }, { "path": "licenses/GPL-1.0-or-later", - "sha256": "13ff2a162a56796d863de9373ea46860a0fc28da81c192e76da9704dc117c27b", - "size": 13307 + "sha256": "8ff76f1528e6e4e9400c0f6b1f2d19d4979aaac3bcc44bb707a55389132825c4", + "size": 13047 }, { "path": "licenses/GPL-2.0-only", - "sha256": "535fe49430f3098603b190f07040d5b0c65eb8ed5fe173108e26eb668e758c00", - "size": 18774 + "sha256": "6667ad4063569cd53b13500550d93fcd3dc11bcf82c5514296af013a0b720ba5", + "size": 18424 }, { "path": "licenses/Mesa-license.rst", - "sha256": "e272a136f6ce1b855afeef2fbe44f94f17d3b4d91cef29f8364af5800c5838a8", - "size": 1866 + "sha256": "0d1a0472ecc81830e75c20d59b0ea02841e3db21255e0ebad97ab682c54d6615", + "size": 1816 }, { "path": "licenses/MIT", - "sha256": "a1179eae4e8b0ef06cbad6b6a2e324bb1c1cd9281cf40b42c0b15b0e34df2683", - "size": 1402 + "sha256": "323c587d0ccf10e376f8bf9a7f31fb4ca6078105194b42e0b1e0ee2bc9bde71f", + "size": 1372 }, { "path": "licenses/SGI-B-2.0", - "sha256": "8299bbd83c4d77eb5ae767cf250e9b3b470218e863714cba2e5e7eaed51285f2", - "size": 1844 + "sha256": "686bf035a1fd22076416fd3b90370ac67771e884bf57f55693d51f8ce7c710a7", + "size": 1822 }, { "path": "licenses/source.json", - "sha256": "699c0d6096f573cb768ae2e3f625a65a34fef8cebb618f6a611d0f8b6ced787a", - "size": 890 + "sha256": "e1640432c0505d5464d14c593bda1ffc944eac5005da560bdea162efc23f1add", + "size": 860 }, { "path": "licenses/zink-optional-maintenance5.patch", diff --git a/tools/tests/test_qualcomm_runtime.py b/tools/tests/test_qualcomm_runtime.py index 192bc71f8..c38bd0cc3 100644 --- a/tools/tests/test_qualcomm_runtime.py +++ b/tools/tests/test_qualcomm_runtime.py @@ -3,6 +3,7 @@ import importlib.util import io import json from pathlib import Path +import tarfile import tempfile import unittest from unittest.mock import patch @@ -115,6 +116,45 @@ class QualcommRuntimeTest(unittest.TestCase): with self.assertRaisesRegex(FileNotFoundError, 'Build private Gamescope'): runtime.stage(output, cache, lock) + def builds_archive(self, files): + raw = io.BytesIO() + with tarfile.open(fileobj=raw, mode='w:xz') as package: + for name, data in files.items(): + info = tarfile.TarInfo(name) + info.size = len(data) + package.addfile(info, io.BytesIO(data)) + return raw.getvalue() + + def test_missing_builds_come_from_the_pinned_archive_once(self): + binary, source = b'ci gamescope', b'ci source' + archive = self.builds_archive({'qualcomm-gamescope/gamescope': binary, 'qualcomm-gamescope/source.tar.gz': source}) + with tempfile.TemporaryDirectory() as directory: + root, cache = Path(directory), Path(directory) / 'cache' + lock = dict(builds=self.lock(archive), gamescope=dict(member_sha256=hashlib.sha256(binary).hexdigest(), build=dict( + binary='build/qualcomm-gamescope/gamescope', source='build/qualcomm-gamescope/source.tar.gz', + source_sha256=hashlib.sha256(source).hexdigest(), source_size=len(source)))) + with patch.object(runtime, '__file__', str(root / 'tools/qualcomm/fetch_runtime.py')): + with patch.object(runtime.urllib.request, 'urlopen', return_value=io.BytesIO(archive)) as download: + runtime.unpack_builds(cache, lock) + self.assertEqual((root / 'build/qualcomm-gamescope/gamescope').read_bytes(), binary) + runtime.unpack_builds(cache, lock) + self.assertEqual(download.call_count, 1) + (root / 'build/qualcomm-gamescope/gamescope').write_bytes(b'stale') + runtime.unpack_builds(cache, lock) + self.assertEqual((root / 'build/qualcomm-gamescope/gamescope').read_bytes(), binary) + + def test_builds_archive_cannot_write_outside_build(self): + archive = self.builds_archive({'../escape': b'x'}) + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + lock = dict(builds=self.lock(archive), gamescope=dict(member_sha256='0', build=dict( + binary='build/g', source='build/s', source_sha256='0', source_size=1))) + with patch.object(runtime, '__file__', str(root / 'tools/qualcomm/fetch_runtime.py')): + with patch.object(runtime.urllib.request, 'urlopen', return_value=io.BytesIO(archive)): + with self.assertRaisesRegex(ValueError, 'Invalid Qualcomm build member'): + runtime.unpack_builds(root / 'cache', lock) + self.assertFalse((root / 'escape').exists()) + def test_built_wsi_members_come_from_the_pinned_local_build(self): bridge, binary, license_text, layer = b'bridge', b'gamescope', b'MIT', b'Wayland WSI layer' def package(members):