mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.5.0
In-game mods (GameBanana browser, search and installs, with the Mask Salesman), code-patch and cheat mods, the devs' test18 to test45 work (full performance overlay, frame pacing on, steady frame rate, save export and import, bug capture, new options rows, Setup's Mods page and Add to Steam), occlusion queries and new defaults, Auto resolution that scales, replay helper threads and robust buffers off by default, the options in sections.
This commit is contained in:
180
scripts/frame_rank.py
Normal file
180
scripts/frame_rank.py
Normal file
@@ -0,0 +1,180 @@
|
||||
"""What made the slowest frames, from the per-frame trace (RX_VK_FRAME_TRACE=1: triforce_frames.csv; the lab's runs keep it as
|
||||
frames.csv beside log.txt). Standard library only.
|
||||
|
||||
python -I scripts/frame_rank.py <run folder or csv> [...] [--skip-s 6] [--last-s 0]
|
||||
|
||||
For each window the frame times (median, 99th percentile, the overlay's 1% low: 1000 / p99, and the mean of the slowest 1% as a
|
||||
rate), then the frames over the 99th percentile and those over 1.5x the median: their time over the median frame, split by what
|
||||
each part took over its own median. A run folder with log.txt is cut where the cheats' teleports came (the lab's scenarios):
|
||||
"market" the last stay, "tour areas" the stays before it, each after its first --skip-s seconds, and "loads" those first
|
||||
seconds; a csv alone (or a log without teleports) is one window, "run", after its first --skip-s seconds, or its last --last-s.
|
||||
Several runs: their windows summed by name.
|
||||
|
||||
The split, with a trace that has frame_trace.h's columns (gpu/vk/frame_trace.h): the frame is the replay (the submits and the
|
||||
present phase, every thread that replays), the present's own time, and what is outside them: the game's own update. Within the
|
||||
replay: memory sync, the dispatches, the queue submits, the waits for a recording slot and for the GPU, the replay thread's waits
|
||||
for its helpers' segments, and the draws (their parts sampled and summed over every thread that records: with the helper threads
|
||||
on, more than their share of the replay's time). Within outside: the game's fence waits and the captures at its submits. Across
|
||||
both: the waits for write-backs still on the GPU, their part after the writer's recording was done (the timeline held), the
|
||||
queue submits beside a background import. An older trace: the draws' parts, memory sync, the slot and GPU waits, and the rest.
|
||||
"""
|
||||
import argparse
|
||||
import csv
|
||||
import os
|
||||
import re
|
||||
import statistics
|
||||
import sys
|
||||
|
||||
# (name, column, the part it is in) - the wall split first: replay, present and outside add up to the frame
|
||||
SPLIT = [("replay", "replay_ms", None), ("present", "present_ms", None), ("outside (the game's update)", "outside_ms", None),
|
||||
("memory sync", "memsync_ms", "replay"), ("dispatch", "dispatch_ms", "replay"), ("queue submit", "qsubmit_ms", "replay"),
|
||||
("slot wait", "slot_wait_ms", "replay"), ("the GPU behind", "gpu_behind_ms", "replay"),
|
||||
("helpers' segments waited for", "par_wait_ms", "replay"), ("draws (all threads)", "draw_ms", "replay"),
|
||||
("game's fence waits", "game_wait_ms", "outside (the game's update)"),
|
||||
("captures at its submits", "captures_ms", "outside (the game's update)"),
|
||||
("write-back waits", "wb_wait_ms", "across"), ("of them the timeline held", "wb_held_ms", "across"),
|
||||
("queue submits beside an import", "qs_bg_ms", "across")]
|
||||
OLD = [("draws (all threads)", "draw_ms", None), ("memory sync", "memsync_ms", None), ("slot wait", "slot_wait_ms", None),
|
||||
("the GPU behind", "gpu_behind_ms", None)]
|
||||
DRAW = [("programs", "programs_ms"), ("pipelines", "pipelines_ms"), ("descriptors", "desc_ms"), ("texture lookups", "tex_lookup_ms"),
|
||||
("uploads", "uploads_ms"), ("commands", "cmds_ms")]
|
||||
|
||||
|
||||
def read_rows(path):
|
||||
rows = []
|
||||
with open(path, newline="") as f:
|
||||
for r in csv.DictReader(f):
|
||||
try:
|
||||
rows.append({k: float(v) for k, v in r.items() if k})
|
||||
except (TypeError, ValueError):
|
||||
pass # (a line cut at the end of a run)
|
||||
return rows
|
||||
|
||||
|
||||
def teleports(log):
|
||||
"""The presents at which the cheats' teleports were asked, in order (the lab's scenario_report.ps1 takes them so)"""
|
||||
marks, last = [], 0
|
||||
with open(log, encoding="utf-8", errors="replace") as f:
|
||||
for line in f:
|
||||
m = re.search(r"vk: (\d+) presents,", line)
|
||||
if m:
|
||||
last = int(m.group(1))
|
||||
continue
|
||||
if re.search(r"cheats: teleport (?:child|adult) to \S+", line):
|
||||
marks.append(last)
|
||||
return marks
|
||||
|
||||
|
||||
def windows(rows, marks, skip_s, last_s):
|
||||
out = {}
|
||||
if not rows:
|
||||
return out
|
||||
if not marks:
|
||||
if last_s > 0:
|
||||
t, k = 0.0, len(rows)
|
||||
while k > 0 and t < last_s * 1000.0:
|
||||
k -= 1
|
||||
t += rows[k]["ms"]
|
||||
out["run"] = rows[k:]
|
||||
else:
|
||||
t, w = 0.0, []
|
||||
for r in rows:
|
||||
t += r["ms"]
|
||||
if t >= skip_s * 1000.0:
|
||||
w.append(r)
|
||||
out["run"] = w
|
||||
return out
|
||||
f0 = int(rows[0]["frame"])
|
||||
for i, pres in enumerate(marks):
|
||||
a = max(0, pres + 120 - f0) # (the trace's frame is the present; scenario_report.ps1's 120)
|
||||
b = min(len(rows), marks[i + 1] + 120 - f0) if i + 1 < len(marks) else len(rows)
|
||||
t = 0.0
|
||||
for j in range(a, b):
|
||||
t += rows[j]["ms"]
|
||||
name = "loads" if t < skip_s * 1000.0 else "market" if i + 1 == len(marks) else "tour areas"
|
||||
out.setdefault(name, []).append(rows[j])
|
||||
return out
|
||||
|
||||
|
||||
def pct(sorted_values, q):
|
||||
return sorted_values[min(len(sorted_values) - 1, int(q * len(sorted_values)))]
|
||||
|
||||
|
||||
def split_of(window, slow, parts):
|
||||
"""Each part's time over its median in the slow frames, and the slow frames' time over the median frame"""
|
||||
med = statistics.median(r["ms"] for r in window)
|
||||
meds = {col: statistics.median(r.get(col, 0.0) for r in window) for _, col, *_ in parts}
|
||||
excess = sum(r["ms"] - med for r in slow)
|
||||
return excess, {col: sum(max(0.0, r.get(col, 0.0) - meds[col]) for r in slow) for _, col, *_ in parts}
|
||||
|
||||
|
||||
def report(name, windows_by_run, out):
|
||||
frames = [r for w in windows_by_run for r in w]
|
||||
if len(frames) < 100:
|
||||
return
|
||||
has_split = all("outside_ms" in w[0] for w in windows_by_run if w)
|
||||
parts = SPLIT if has_split else OLD
|
||||
ms = sorted(r["ms"] for r in frames)
|
||||
med, p99 = statistics.median(ms), pct(ms, 0.99)
|
||||
slowest = ms[-max(1, len(ms) // 100):]
|
||||
out.write("=== %s: %d frames, %.1f fps; median %.2f ms, p99 %.2f ms; 1%% low %.0f fps (1000 / p99), the slowest 1%% at %.0f fps\n"
|
||||
% (name, len(ms), 1000.0 * len(ms) / sum(ms), med, p99, 1000.0 / p99, 1000.0 / statistics.mean(slowest)))
|
||||
for sel in ("p99", "1.5x"):
|
||||
excess, total = 0.0, {}
|
||||
n = 0
|
||||
for w in windows_by_run: # (each run's own medians and thresholds: runs differ by up to 10%)
|
||||
if len(w) < 100:
|
||||
continue
|
||||
wm = sorted(r["ms"] for r in w)
|
||||
thr = pct(wm, 0.99) if sel == "p99" else 1.5 * statistics.median(wm)
|
||||
slow = [r for r in w if r["ms"] > thr]
|
||||
n += len(slow)
|
||||
e, s = split_of(w, slow, parts + [(None, c) for _, c in DRAW])
|
||||
excess += e
|
||||
for k, v in s.items():
|
||||
total[k] = total.get(k, 0.0) + v
|
||||
out.write(" frames over %s: %d, %.0f ms over the median frame in all\n" % ("the 99th percentile" if sel == "p99" else
|
||||
"1.5x the median", n, excess))
|
||||
if excess <= 0:
|
||||
continue
|
||||
share = lambda col: 100.0 * total.get(col, 0.0) / excess
|
||||
if not has_split:
|
||||
rest = excess - sum(total[c] for _, c, _ in parts)
|
||||
for label, col, within in parts:
|
||||
indent = " " if within is None else " "
|
||||
pre = "" if within is None else ("across: " if within == "across" else "in %s: " % within.split(" (")[0])
|
||||
out.write("%s%-44s %7.0f ms %5.1f%%\n" % (indent, pre + label, total.get(col, 0.0), share(col)))
|
||||
if col == "draw_ms":
|
||||
for dl, dc in DRAW:
|
||||
out.write(" %-42s %7.0f ms %5.1f%%\n" % ("in draws: " + dl, total.get(dc, 0.0), share(dc)))
|
||||
if not has_split:
|
||||
out.write(" %-44s %7.0f ms %5.1f%%\n" % ("the rest (the game's update, submits, present)", rest, 100.0 * rest / excess))
|
||||
|
||||
|
||||
def main(argv=None, out=sys.stdout):
|
||||
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
p.add_argument("paths", nargs="+", help="run folders (frames.csv, log.txt) or trace files")
|
||||
p.add_argument("--skip-s", type=float, default=6.0, help="seconds at each stay's start (or the run's) left out: the load")
|
||||
p.add_argument("--last-s", type=float, default=0.0, help="a run with no teleports: its last seconds only")
|
||||
a = p.parse_args(argv)
|
||||
by_name = {}
|
||||
for path in a.paths:
|
||||
csv_path, log = path, None
|
||||
if os.path.isdir(path):
|
||||
csv_path = next((os.path.join(path, n) for n in ("frames.csv", "triforce_frames.csv")
|
||||
if os.path.isfile(os.path.join(path, n))), None)
|
||||
log = os.path.join(path, "log.txt") if os.path.isfile(os.path.join(path, "log.txt")) else None
|
||||
if not csv_path:
|
||||
out.write("(%s: no frame trace)\n" % path)
|
||||
continue
|
||||
rows = read_rows(csv_path)
|
||||
for name, w in windows(rows, teleports(log) if log else [], a.skip_s, a.last_s).items():
|
||||
by_name.setdefault(name, []).append(w)
|
||||
for name in ("market", "tour areas", "loads", "run"):
|
||||
if name in by_name:
|
||||
report(name, by_name[name], out)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -9,6 +9,13 @@ They are AMD's, under the SDK's MIT license (third_party/fidelityfx/LICENSE.md,
|
||||
game runs as before and the Upscaler row does not offer AMD FSR 4; with them FSR 4 is offered where AMD's library says
|
||||
the card runs it (Radeon RX 6000, 7000 and 9000 cards with a current driver).
|
||||
|
||||
(Triforce) One more library of the same release, from the same folder of AMD's repository, for AMD FSR 4's frame
|
||||
generation (the Frame generation row's AMD FSR 4, gpu/vk/vk_fsr4.cpp fsr4fg):
|
||||
- amd_fidelityfx_framegeneration_vk.dll (35 MB)
|
||||
It is fetched after the two and is not required: when it cannot be had, or is not the pinned file, that is said (with
|
||||
the size and SHA-256 that came, for the table) and the game is built with FSR 4 as before, its Frame generation row
|
||||
without AMD FSR 4. The license text beside the game lists it among AMD's MIT files.
|
||||
|
||||
Usage: python -I scripts/fsr_sdk.py [--game <game folder>] [<folder>]
|
||||
<folder>: where the two files are kept between builds; default work/fsr-sdk
|
||||
--game: copied beside the game's exe too (nx2/make_game.py --fsr does the same for the folder it builds)
|
||||
@@ -30,6 +37,12 @@ RUNTIME = [
|
||||
("amd_fidelityfx_loader_vk.dll", 39184, "38a56a01fb3565c0757d9f5c1e4e69de4b65e5f2e5769b323b200dc1f142bab9"),
|
||||
("amd_fidelityfx_upscaler_vk.dll", 36135696, "4a7e895af6e0b615d40a84d59eb8c2b1054ad91cdd0c739567940270d51bdab7"),
|
||||
]
|
||||
# (Triforce) AMD FSR 4's frame generation library: wanted, not required (the docstring). Its size and SHA-256 are those of
|
||||
# the file as NX2navi's releases carried it from the same tag (v2.4.0), read from a copy on the build PC whose two
|
||||
# libraries above match their pins; a file of another size or SHA-256 from AMD's repository is refused and reported
|
||||
OPTIONAL = [
|
||||
("amd_fidelityfx_framegeneration_vk.dll", 36806928, "d002dabff8c5e71eaa715fc99438cd4dc81230262a7897b16bc402efec3498b4"),
|
||||
]
|
||||
LICENSE_SOURCE = os.path.join(ROOT, "third_party", "fidelityfx", "LICENSE.md")
|
||||
LICENSE_NAME = "amd-fidelityfx-LICENSE.md"
|
||||
|
||||
@@ -55,6 +68,12 @@ def complete(folder):
|
||||
return bool(folder) and os.path.isdir(folder) and not missing(folder)
|
||||
|
||||
|
||||
def have_optional(folder):
|
||||
"""(Triforce) The optional files that are in folder as pinned: AMD FSR 4's frame generation library"""
|
||||
return [name for name, _, digest in OPTIONAL
|
||||
if os.path.isfile(os.path.join(folder, name)) and sha256_file(os.path.join(folder, name)) == digest]
|
||||
|
||||
|
||||
def download(url):
|
||||
request = urllib.request.Request(url, headers={"User-Agent": "fsr-sdk-fetch"})
|
||||
with urllib.request.urlopen(request, timeout=300) as r:
|
||||
@@ -65,29 +84,49 @@ def fetch(folder, say=print, get=download):
|
||||
"""Every pinned file into folder that is not there yet. Raises OSError or ValueError; a file that is not the pinned
|
||||
one is never left in folder"""
|
||||
need = missing(folder) if os.path.isdir(folder) else [name for name, _, _ in RUNTIME]
|
||||
if not need:
|
||||
have = have_optional(folder) if os.path.isdir(folder) else []
|
||||
more = [name for name, _, _ in OPTIONAL if name not in have]
|
||||
if not need and not more:
|
||||
say("AMD's FSR 4 libraries are in %s already" % folder)
|
||||
return
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
table = {name: (size, digest) for name, size, digest in RUNTIME}
|
||||
for name in need:
|
||||
table = {name: (size, digest) for name, size, digest in RUNTIME + OPTIONAL}
|
||||
|
||||
def one(name):
|
||||
size, digest = table[name]
|
||||
say("AMD FSR 4: %s (%.1f MB) from AMD's repository" % (name, size / 1048576.0))
|
||||
data = get(BASE + name)
|
||||
if len(data) != size or hashlib.sha256(data).hexdigest() != digest:
|
||||
raise ValueError("%s is not the file of FidelityFX SDK %s (%d bytes, another SHA-256)" % (name, VERSION, len(data)))
|
||||
got = hashlib.sha256(data).hexdigest()
|
||||
if len(data) != size or got != digest:
|
||||
raise ValueError("%s is not the pinned file of FidelityFX SDK %s (it has %d bytes and the SHA-256 %s; pinned: %d "
|
||||
"bytes, %s)" % (name, VERSION, len(data), got, size, digest))
|
||||
tmp = os.path.join(folder, name + ".part")
|
||||
with open(tmp, "wb") as f:
|
||||
f.write(data)
|
||||
os.replace(tmp, os.path.join(folder, name))
|
||||
|
||||
for name in need:
|
||||
one(name)
|
||||
# (Triforce) the frame generation library, after the two: a failure here is said and leaves FSR 4 the upscaler as it is
|
||||
for name in more:
|
||||
try:
|
||||
one(name)
|
||||
except (OSError, ValueError) as e:
|
||||
say("AMD FSR 4 frame generation: %s could not be had (%s): the game is built without it, its Frame generation "
|
||||
"row without AMD FSR 4" % (name, e))
|
||||
|
||||
|
||||
def install_runtime(folder, game):
|
||||
"""AMD's two libraries and their license text from folder beside the game's exe. Returns what was placed"""
|
||||
"""AMD's two libraries and their license text from folder beside the game's exe, and (Triforce) the frame generation
|
||||
library when folder has the pinned one; a game folder that had it loses it when folder does not. Returns what was placed"""
|
||||
placed = []
|
||||
for name, _, _ in RUNTIME:
|
||||
optional = have_optional(folder)
|
||||
for name in [name for name, _, _ in RUNTIME] + optional:
|
||||
shutil.copyfile(os.path.join(folder, name), os.path.join(game, name))
|
||||
placed.append(os.path.join(game, name))
|
||||
for name, _, _ in OPTIONAL: # (not left from a build before, beside a loader it may not go with)
|
||||
if name not in optional and os.path.isfile(os.path.join(game, name)):
|
||||
os.remove(os.path.join(game, name))
|
||||
if os.path.isfile(LICENSE_SOURCE):
|
||||
shutil.copyfile(LICENSE_SOURCE, os.path.join(game, LICENSE_NAME))
|
||||
return placed
|
||||
@@ -96,7 +135,7 @@ def install_runtime(folder, game):
|
||||
def remove_runtime(game):
|
||||
"""A game folder built without FSR 4 after one built with it loses AMD's files. True when any was there"""
|
||||
gone = False
|
||||
for name in [name for name, _, _ in RUNTIME] + [LICENSE_NAME]:
|
||||
for name in [name for name, _, _ in RUNTIME + OPTIONAL] + [LICENSE_NAME]:
|
||||
path = os.path.join(game, name)
|
||||
if os.path.isfile(path):
|
||||
os.remove(path)
|
||||
|
||||
@@ -50,13 +50,16 @@ cp -a gpu/render/*.h "$T/gpu/render/"
|
||||
# (every gpu/vk header the host's sources include: v2.0.6 shipped without oot_cheat_items.h and no Linux build finished, issue 990.
|
||||
# tests/test_appimage_headers.py checks that this covers what host/ includes)
|
||||
for h in $(grep -rhoE 'gpu/vk/[A-Za-z0-9_]+[.]h' host | sort -u); do if [ -f "$h" ]; then cp -a "$h" "$T/gpu/vk/"; fi; done
|
||||
# ((Triforce) zstd's decoder here, with what host/ compiles: host/host_zstd.h includes its headers since the host's zstd
|
||||
# decoder for the game's files, and tests/test_appimage_source_headers.py checks the copy up to the next line)
|
||||
cp -a third_party/zstd "$T/third_party/"
|
||||
cp -a third_party/opus "$T/third_party/"
|
||||
cp -a third_party/kenney_input "$T/third_party/"
|
||||
# (NVIDIA DLSS, when ticked in the builder: scripts/ngx_sdk.py and the Vulkan back end's sources, compiled with HOOKSHOT_NGX_SDK)
|
||||
mkdir -p "$T/scripts"
|
||||
cp scripts/ngx_sdk.py "$T/scripts/"
|
||||
cp -a gpu/vk gpu/compat gpu/third_party "$T/gpu/"
|
||||
cp -a third_party/imgui third_party/zstd third_party/fonts "$T/third_party/"
|
||||
cp -a third_party/imgui third_party/fonts "$T/third_party/"
|
||||
mkdir -p "$T/third_party/zbic" "$T/third_party/a64-kit"
|
||||
cp -a third_party/zbic/zbic.so third_party/zbic/LICENSE third_party/zbic/PROVENANCE.md "$T/third_party/zbic/"
|
||||
cp -a third_party/a64-kit/* "$T/third_party/a64-kit/"
|
||||
|
||||
@@ -12,6 +12,11 @@ gives the same programs other bytes (its fragment NaN guard, its execution modes
|
||||
CRC-32 of the module Hookshot makes (RX_VK_DUMP_ALL_SPV=<folder> writes them, named by it). A change to Hookshot's emitter
|
||||
changes those: dump again and match by what the shader reads.
|
||||
|
||||
(Triforce) RenoDX's mod has two tone mappers, Vanilla and PsychoV35. RenoDRT, which RenoDX's library among the fetched
|
||||
sources has and the mod does not call, and the gamma correction come from three files of Triforce's own that are compiled
|
||||
together with RenoDX's scene shaders and its encoder (gpu/vk/shaders/renodx_glue; GLUE below). RenoDX's sources are compiled
|
||||
as fetched: nothing of them is changed or kept.
|
||||
|
||||
Usage: python -I scripts/renodx_shaders.py [--platform linux|windows] [<folder>]
|
||||
<folder>: default work/renodx. Then build with HOOKSHOT_RENODX=<folder> (nx2/make_game.py --renodx does both).
|
||||
python -I scripts/renodx_shaders.py --from <renodx checkout> <slangc> [<folder>]
|
||||
@@ -69,6 +74,15 @@ ALSO = {
|
||||
FLAGS = ["-stage", "fragment", "-O3", "-g0", "-entry", "main", "-Wno-30056", "-Wno-15205", "-Wno-30081", "-Wno-41035",
|
||||
"-DNDEBUG", "-target", "spirv"]
|
||||
|
||||
# (Triforce) What RenoDX's mod does not have and NX2navi's HDR does: RenoDRT as a third tone mapper and the gamma
|
||||
# correction. Triforce's own files in GLUE_DIR, with none of RenoDX's code in them, compiled in front of RenoDX's shader by
|
||||
# its part (the third entry of a SHADERS row): 2 the two scene shaders, 0 the output encoder; the fog (1) is compiled as
|
||||
# it is. Each says in its head how it meets RenoDX's source. GLUE_FILES: all of them, with the one the others include;
|
||||
# their bytes are in the header's stamp, so a change to one compiles the header again
|
||||
GLUE_DIR = os.path.join(ROOT, "gpu", "vk", "shaders", "renodx_glue")
|
||||
GLUE = {0: "triforce_output.slangi", 2: "triforce_scene.slangi"}
|
||||
GLUE_FILES = ("triforce_settings.slangi", "triforce_output.slangi", "triforce_scene.slangi")
|
||||
|
||||
# (path in RenoDX's repository, its SHA-256): its license, and what the four shaders read (slangc -depfile lists them)
|
||||
FILES = [
|
||||
("LICENSE", "e9e2da3991a48d9c09b710c9ddbf5673275b6d569c976bcffab3111d0c509d51"),
|
||||
@@ -229,10 +243,21 @@ def fetch(folder, platform, opener=urllib.request.urlopen, say=print):
|
||||
os.remove(archive)
|
||||
|
||||
|
||||
def glue_bytes():
|
||||
"""(Triforce) The glue files as the header's stamp takes them: each one's name and its bytes, line ends as LF (a
|
||||
checkout with CRLF is the same glue)"""
|
||||
out = []
|
||||
for name in GLUE_FILES:
|
||||
with open(os.path.join(GLUE_DIR, name), "rb") as f:
|
||||
out.append((name, f.read().replace(b"\r\n", b"\n")))
|
||||
return out
|
||||
|
||||
|
||||
def stamp():
|
||||
"""What a compiled header is made from: the commit, the compiler, the shaders and their flags. In the header's first line,
|
||||
so one made from something else is made again"""
|
||||
"""What a compiled header is made from: the commit, the compiler, the shaders and their flags, and (Triforce) the glue
|
||||
compiled with them. In the header's first line, so one made from something else is made again"""
|
||||
h = hashlib.sha256(repr((COMMIT, SLANG_VERSION, SHADERS, FLAGS, FILES, sorted(ALSO.items()))).encode())
|
||||
h.update(repr((sorted(GLUE.items()), glue_bytes())).encode())
|
||||
return "// renodx_shaders.py %s" % h.hexdigest()[:16]
|
||||
|
||||
|
||||
@@ -245,22 +270,50 @@ def current(folder):
|
||||
return f.readline().rstrip("\n") == stamp()
|
||||
|
||||
|
||||
def compile_header(renodx, compiler, out_path, say=print, first_line=None):
|
||||
def unit(name, kind):
|
||||
"""(Triforce) What is compiled for one of RenoDX's shaders that has glue (GLUE, by its part): the glue, then RenoDX's
|
||||
source as it is, both found by name in the folders compile_command gives the compiler. The two first lines are those
|
||||
RenoDX's shader opens with, which have to come before anything else. None: the shader is compiled alone"""
|
||||
if kind not in GLUE:
|
||||
return None
|
||||
return ('#version 450\n#extension GL_EXT_scalar_block_layout : require\n'
|
||||
'// scripts/renodx_shaders.py: Triforce\'s glue, then RenoDX\'s shader\n#include "%s"\n#include "%s"\n' % (GLUE[kind], name))
|
||||
|
||||
|
||||
def compile_command(compiler, name, kind, src, tmp, crc):
|
||||
"""The compiler's command for one shader, run in RenoDX's folder of them (src), and the SPIR-V file it writes. A shader
|
||||
with glue: its unit written into tmp and compiled from there, with RenoDX's folder and the glue's to find the two in"""
|
||||
spv = os.path.join(tmp, "%08X.spv" % crc)
|
||||
text = unit(name, kind)
|
||||
if text is None:
|
||||
return [compiler, name] + FLAGS + ["-o", spv], spv
|
||||
path = os.path.join(tmp, "%08X.frag.slang" % crc)
|
||||
with open(path, "w", newline="\n", encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
return [compiler, path, "-I", src, "-I", GLUE_DIR] + FLAGS + ["-o", spv], spv
|
||||
|
||||
|
||||
def compile_header(renodx, compiler, out_path, say=print, first_line=None, run=subprocess.run):
|
||||
"""renodx_spv.h from a RenoDX checkout (or the folder's renodx/) with slangc"""
|
||||
src = os.path.join(renodx, *GAME.split("/"))
|
||||
lines = ([first_line] if first_line else []) + [
|
||||
"// Generated by scripts/renodx_shaders.py from RenoDX (MIT, Carlos Lopez): do not edit, never commit.",
|
||||
"// Each array replaces the module of Hookshot's whose CRC-32 names it (vk_renodx.cpp).", "#pragma once",
|
||||
"#include <cstdint>", ""]
|
||||
"#include <cstdint>"]
|
||||
if GLUE: # (what vk_renodx.cpp looks for before it says the rows of the glue do something)
|
||||
lines += ["// (Triforce) the scene shaders and the encoder are compiled with gpu/vk/shaders/renodx_glue: RenoDRT, the gamma correction",
|
||||
"#define RENODX_SPV_GLUE 1"]
|
||||
lines.append("")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
for crc, name, kind, what in SHADERS:
|
||||
spv = os.path.join(tmp, "%08X.spv" % crc)
|
||||
r = subprocess.run([compiler, name] + FLAGS + ["-o", spv], cwd=src, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
command, spv = compile_command(compiler, name, kind, os.path.abspath(src), tmp, crc)
|
||||
r = run(command, cwd=src, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
if r.returncode or not os.path.isfile(spv):
|
||||
raise ValueError("renodx: %s did not compile (%s)" % (name, r.stdout.decode("utf-8", "replace").strip()[-400:]))
|
||||
data = open(spv, "rb").read()
|
||||
with open(spv, "rb") as f:
|
||||
data = f.read()
|
||||
words = struct.unpack("<%dI" % (len(data) // 4), data)
|
||||
lines.append("// %s: %s" % (name, what))
|
||||
lines.append("// %s: %s%s" % (name, what, ", with %s" % GLUE[kind] if kind in GLUE else ""))
|
||||
lines.append("static const uint32_t RENODX_%08X[] = {" % crc)
|
||||
for i in range(0, len(words), 12):
|
||||
lines.append(" " + ", ".join("0x%08x" % w for w in words[i:i + 12]) + ",")
|
||||
|
||||
@@ -30,8 +30,8 @@ STAGES = {0x1: "vertex", 0x2: "tesscontrol", 0x4: "tesseval", 0x8: "geometry", 0
|
||||
|
||||
def records(path, want):
|
||||
"""(key, kind, bytes) of each record want(key, kind) takes, in file order. The layout is disk_init's: a 16-byte head
|
||||
(magic, 0, stamp), then records of a u64 key, a u64 size and that many bytes, which start with the u32 kind. A record
|
||||
cut short ends the walk, as it does there"""
|
||||
(magic, the build of the translator that last opened it, stamp), then records of a u64 key, a u64 size and that many bytes,
|
||||
which start with the u32 kind. A record cut short ends the walk, as it does there"""
|
||||
with open(path, "rb") as f:
|
||||
head = f.read(16)
|
||||
if len(head) < 16 or struct.unpack_from("<I", head)[0] != CACHE_MAGIC:
|
||||
|
||||
Reference in New Issue
Block a user