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
49 changes: 49 additions & 0 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The launcher sets these for a Proton or Wine launch. A value you set yourself is
| --- | --- | --- |
| `TUXBOX_RUNTIME_SHADERS` | on | `0` stops translating shaders during play |
| `TUXBOX_RUNTIME_SHADER_JOBS` | half the CPU cores, at least 2 where there are two, at most 32 | Compiler jobs during play, 1 to 32 |
| `TUXBOX_PROFILE_SHADERS` | `0` | Set to `1` for aggregate host shader-stage timing in the log (preparation and runtime). No title identifiers are included; `--profile-pipelines` enables runtime timing unless explicitly disabled. |
| `TUXBOX_SHADER_PREP_JOBS` | one per CPU core, at most 32 | Compiler jobs for ProjectScarlett preparation |
| `TUXBOX_SHADER_PREP` | `chase` | Frosty preparation: `0`, `1`, `menu` or `chase` |
| `TUXBOX_SHADER_PREP_UI` | on for ProjectScarlett | `1` shows a desktop progress window |
Expand Down Expand Up @@ -93,3 +94,51 @@ All are off by default. Capture variables write the game's data to disk, so don'
## Build and test tools

`TUXBOX_XSHADER` selects the shader compiler for launcher preparation and `DXC` selects the DirectX Shader Compiler. `TUXBOX_BLESS_PROFILES`, `TUXBOX_ORACLE_*`, `TUXBOX_TEST_*` and the probe and replay variables in `tools/` belong to individual checks. `TUXBOX_PROVIDER`, `TUXBOX_SHADER_SESSION` and `TUXBOX_WINE_*` are internal; don't set them.


### Reading host shader stage timings

For a cold and warm run, keep the same executable, prefix, compiler and settings,
and set `TUXBOX_PROFILE_SHADERS=1` for both launches. The aggregate JSON lines
labelled `Shader stage timings (preparation)` and `(runtime)` separate the
work done before the title starts from that done by the live compiler. The
runtime profile is also enabled by `--profile-pipelines`, unless explicitly
disabled. Keep the existing game log if the results need to be compared later.

`requests.compiled` counts newly published source entries (including reuse of
identical DXIL); `reuse.content` counts those that did not need DXC again.
`reuse.source` counts exact cached entries served by the host. A warm guest
can read its cache without sending a request at all, so an empty runtime
profile is valid. Refused, cached-refusal and failed requests stay separate.
Stage outcomes count tool attempts, not shaders: a timeout and its successful
fallback are separate calls. Stage totals sum concurrent worker wall times
and can exceed the elapsed session time; they are not CPU time. The existing
vkd3d-proton pipeline trace measures driver-side calls separately.

On Linux, when GNU `time` is installed, `process_memory` reports the
peak resident set size (RSS, in KiB) from child resource accounting.
`attempts` includes launch failures and timeouts; `measured` counts
completed measurements. A missing measurement is null, not zero.
The maximum is per CLI invocation, not the combined memory of simultaneous
compiles. Persistent DXC, combined descendant memory, guest/driver memory
and VRAM are not included. Other platforms and Linux without GNU time
retain timings without memory data. GNU time is optional, and is not
invoked when profiling is disabled.

These host measurements cover dispatched requests, not guest-side cache
lookups or compiler discovery. They contain no shader hashes, title names
or raw error text. A forcibly killed launcher may not finish writing its
summary.


With `--profile-pipelines`, the capture directory also gets `stage-summary.json`
containing the host runtime compiler aggregate and the vkd3d-proton PSO event
aggregate from the same launch. The latter reports summed event durations,
wall-time coverage (the union of observed intervals), and peak overlapping
events. Overlap includes nesting and is not a worker count. These PSO events
can include translation, lookup and driver work; they do not isolate driver
compilation or measure GPU execution. Do not add host and PSO totals, since they
can overlap. Missing host profiling or a missing trace is represented by null,
not zero. The separate preparation aggregate remains in the launch log.
Keep the raw timeline and detailed pipeline summary local; the combined
aggregate does not include title or shader identifiers.
4 changes: 3 additions & 1 deletion project_tuxbox/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,11 @@ def run_game(self, executable, arguments, log, *, package=None, mangohud=False,
configure_console_cbv(self.backend, env, executable, log.status)
capture = performance_capture(self.backend, env, executable, log) if mangohud else nullcontext()
pipelines = pipeline_capture(self.backend, env, log) if profile_pipelines else nullcontext()
with capture, pipelines, runtime_shader_compiler(self.backend, env, executable, log.status), \
with capture, pipelines as timings, runtime_shader_compiler(self.backend, env, executable, log.status) as profile, \
game_diagnostics(self.backend, env, executable.parent, log.stderr_bytes,
log_path=log.path) as stderr:
if timings is not None:
timings["host_runtime"] = profile
return log.run([*self.command, str(executable), *arguments], cwd=executable.parent, env=env,
stderr_bytes=stderr)
finally:
Expand Down
59 changes: 53 additions & 6 deletions project_tuxbox/pipeline_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@
from .pipeline_prep import winpath


def event_activity(intervals):
"""Report summed event durations and their wall-time coverage separately.

Overlapping (including nested) vkd3d events do not imply separate
compiler threads. This is coverage of observed PSO events, not GPU
execution time or exclusively driver work.
"""
boundaries = []
for start, end in intervals:
if end > start:
boundaries.extend(((start, 1), (end, -1)))
active = peak = 0
covered = 0.0
previous = None
for at, delta in sorted(boundaries):
if previous is not None and active:
covered += at - previous
active += delta
peak = max(peak, active)
previous = at
return dict(event_count=len(intervals),
summed_ms=round(math.fsum(end - start for start, end in intervals) / 1000, 3),
covered_ms=round(covered / 1000, 3), peak_overlapping_events=peak)


def summarize(trace):
totals = {}
pipeline_kinds = {}
slowest = []
intervals = []
with trace.open(encoding="utf-8", errors="replace") as stream:
# vkd3d writes one event per line and can exit without closing the array.
for index, line in enumerate(stream):
Expand All @@ -36,12 +62,15 @@ def summarize(trace):
if any(type(value) not in (int, float) for value in (duration, timestamp)):
continue
try:
duration /= 1000
timestamp /= 1_000_000
duration, timestamp = float(duration), float(timestamp)
end = timestamp + duration
if duration < 0 or not all(math.isfinite(v) for v in (duration, timestamp, end)):
continue
except OverflowError:
continue
if not math.isfinite(duration) or not math.isfinite(timestamp):
continue
intervals.append((timestamp, end))
duration /= 1000
timestamp /= 1_000_000
key, operation = match.groups()
label = operation.split()[0]
if label in ("GFX", "COMP", "LINK"):
Expand All @@ -58,7 +87,8 @@ def summarize(trace):
heapq.heappop(slowest)
for group in totals.values():
group["total_ms"] = round(group["total_ms"], 3)
return dict(groups=totals, slowest=[item[2] for item in sorted(slowest, reverse=True)])
return dict(groups=totals, activity=event_activity(intervals),
slowest=[item[2] for item in sorted(slowest, reverse=True)])


@contextmanager
Expand All @@ -68,10 +98,13 @@ def pipeline_capture(backend, env, log):
directory = Path(mkdtemp(prefix="pipelines-", dir=log.capture_parent())).resolve()
trace = directory / "timeline.json"
env.update(VKD3D_QUEUE_PROFILE=winpath(trace), VKD3D_QUEUE_PROFILE_ABSOLUTE="1")
env.setdefault("TUXBOX_PROFILE_SHADERS", "1")
log.status(f"Pipeline timing capture: {trace}")
capture = {}
try:
yield
yield capture
finally:
result = None
if trace.is_file():
try:
result = summarize(trace)
Expand All @@ -82,6 +115,20 @@ def pipeline_capture(backend, env, log):
log.status(f"Could not summarize pipeline timings: {error}")
else:
log.status(f"The backend did not produce a pipeline trace at {trace}")
# Runtime workers are joined before this outer context exits. The
# report has no pipeline keys, raw names, paths, or game identifiers.
profile = capture.get("host_runtime")
try:
combined = directory / "stage-summary.json"
combined.write_text(json.dumps({
"schema": 1,
"host_runtime": profile.summary() if profile is not None else None,
"vkd3d_pipeline_events": ({k: result[k] for k in ("groups", "activity")}
if result is not None else None),
}, indent=2) + "\n")
log.status(f"Shader and pipeline stage timings: {combined}")
except (OSError, ValueError) as error:
log.status(f"Could not write stage timings: {error}")


if __name__ == "__main__":
Expand Down
Loading
Loading