Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/PROJECTSCARLETT.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,16 @@ The issue #39 log contains 262 failed driver allocation attempts and
131 host import failure messages, not a confirmed VRAM exhaustion or
a proven fault in these provider call sites. The opt-in trace is intended
to distinguish those possibilities in a subsequent authorized run.


### Comparing provider revisions

A run from a different checkout does not redeploy the title's DLLs.
The launcher logs SHA-256 of the staged D3D12 provider and of the local
`build/d3d12-smoke/d3d12_xs.dll` when available. It warns if they differ.
For an A/B test, build and deploy the intended provider explicitly, then
pass `--require-current-provider` before the title path to refuse a launch
unless the staged file matches the local build. This does not rebuild or
replace a DLL, prove which source revision produced the local build, or
inspect modules actually loaded by Wine. Record the build revision and
driver separately.
39 changes: 39 additions & 0 deletions project_tuxbox/launch_provenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Identify the staged graphics provider used as input to a launch.

This checks files, not the Windows loader's choice of module. Never deploy or
replace a DLL implicitly; a developer may deliberately run an older build.
"""
from pathlib import Path
from .inspect import digest

BUILT = Path(__file__).resolve().parents[1] / "build/d3d12-smoke/d3d12_xs.dll"


def report_provider(executable, report, *, require_current=False, built=BUILT):
def problem(message):
report(message)
if require_current:
raise ValueError(message)

try:
candidates = [p for p in executable.parent.iterdir()
if p.name.casefold() == "d3d12_xs.dll"]
if len(candidates) > 1:
return problem("D3D12 provider: ambiguous staged filenames")
if not candidates or not candidates[0].is_file():
if require_current:
return problem("D3D12 provider: staged DLL missing")
return
staged = candidates[0]
actual = digest(staged)
report(f"D3D12 staged provider: sha256={actual}")
if not built.is_file():
return problem("D3D12 provider: local build unavailable for comparison")
expected = digest(built)
report(f"D3D12 local build: sha256={expected}")
if actual != expected:
return problem("D3D12 provider mismatch: staged DLL differs from local build; "
"deploy deliberately before comparing revisions")
report("D3D12 staged provider matches local build")
except OSError as exc:
problem(f"D3D12 provider: could not read staged/build identity ({type(exc).__name__})")
82 changes: 82 additions & 0 deletions tests/test_launch_provenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""A checkout can launch a title staged with a different provider."""
from pathlib import Path
from tempfile import TemporaryDirectory
import hashlib
import unittest

from project_tuxbox.launch_provenance import report_provider


class ProviderProvenanceTests(unittest.TestCase):
def setUp(self):
tmp = TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.root = Path(tmp.name)
self.exe = self.root / "game" / "Lanes.exe"
self.exe.parent.mkdir()
self.built = self.root / "build" / "d3d12_xs.dll"
self.built.parent.mkdir()
self.staged = self.exe.with_name("D3D12_XS.dll")
self.messages = []

def report(self, required=False):
return report_provider(self.exe, self.messages.append, require_current=required, built=self.built)

def test_equal_binaries_match_even_with_case_difference(self):
self.staged.write_bytes(b"provider A")
self.built.write_bytes(b"provider A")
self.report(True)
self.assertIn(hashlib.sha256(b"provider A").hexdigest(), " ".join(self.messages))
self.assertIn("match", " ".join(self.messages).lower())

def test_stale_same_size_binary_warns_and_strict_refuses(self):
self.staged.write_bytes(b"provider A")
self.built.write_bytes(b"provider B")
self.report()
self.assertIn("mismatch", " ".join(self.messages).lower())
with self.assertRaisesRegex(ValueError, "mismatch"):
self.report(True)
self.assertEqual(self.staged.read_bytes(), b"provider A")

def test_missing_build_and_missing_staged_provider_are_not_matches(self):
self.staged.write_bytes(b"provider A")
self.report()
with self.assertRaisesRegex(ValueError, "build"):
self.report(True)
self.staged.unlink()
self.built.write_bytes(b"provider B")
self.report()
with self.assertRaisesRegex(ValueError, "staged"):
self.report(True)

def test_ambiguous_case_variants_fail_closed(self):
self.staged.write_bytes(b"provider A")
self.exe.with_name("d3d12_xs.dll").write_bytes(b"provider A")
self.built.write_bytes(b"provider A")
if len(list(self.exe.parent.iterdir())) != 2:
self.skipTest("case-insensitive filesystem")
self.report()
with self.assertRaisesRegex(ValueError, "ambiguous"):
self.report(True)

def test_strict_launch_stops_before_prepare_or_guest(self):
from argparse import Namespace
from contextlib import contextmanager
from unittest.mock import Mock, patch
import tuxbox
self.staged.write_bytes(b"provider A")
self.built.write_bytes(b"provider B")
log = Mock()
@contextmanager
def logging(*args):
yield log
args = Namespace(log_file=None, require_current_provider=True, prepare_only=False)
host = Mock(backend="native", version="test", offline=False)
def compare(exe, report, *, require_current):
return report_provider(exe, report, require_current=require_current, built=self.built)
with patch("tuxbox.game_log", logging), patch("tuxbox.report_provider", compare), \
patch("tuxbox.prepare_for_launch") as prepare:
with self.assertRaisesRegex(ValueError, "mismatch"):
tuxbox.run_game(args, self.exe, host, self.exe.parent)
prepare.assert_not_called()
host.run_game.assert_not_called()
4 changes: 4 additions & 0 deletions tuxbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from project_tuxbox.backend_log import check_log_path
from project_tuxbox.game_log import game_log
from project_tuxbox.launch_provenance import report_provider
from project_tuxbox.graphics_profile import PROFILES, graphics_profile
from project_tuxbox.host import Host, requires_offline
from project_tuxbox.inspect import binary_file, image, launch_target, package, package_root
Expand Down Expand Up @@ -59,6 +60,7 @@ def run_game(args, exe, host, package_dir, profile=None):
if host.offline:
log.status("Network: offline. The game cannot reach servers or upload crash reports.")
try:
report_provider(exe, log.status, require_current=args.require_current_provider)
# Project Scarlett's recorded archive blocks launch for many minutes.
# The runtime worker still compiles requests. --prepare-only keeps the archive pass.
scarlett = exe.name.casefold() == "game_scarlett_master.exe"
Expand Down Expand Up @@ -108,6 +110,8 @@ def main():
run.add_argument("--log-file", type=Path, metavar="PATH", help="also append the game log to this file; none is saved otherwise")
run.add_argument("--mangohud", action="store_true",
help="show Vulkan performance metrics and record frame times beside the log file on Linux")
run.add_argument("--require-current-provider", action="store_true",
help="refuse launch unless staged D3D12 DLL matches build/d3d12-smoke/d3d12_xs.dll")
run.add_argument("--profile-pipelines", action="store_true",
help="record vkd3d-proton pipeline creation times and keys beside the log file")
graphics = run.add_mutually_exclusive_group()
Expand Down
Loading