Triforce v0.8.0

Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-25 10:21:32 -06:00
parent 861702476a
commit 4fa4f9188b
881 changed files with 179428 additions and 15581 deletions

View File

@@ -4,6 +4,7 @@ triforce_pipeline_states_shipped.bin, whose pipelines the first start's shader p
python -I nx2/pipeline_states.py <list>... what they hold
python -I nx2/pipeline_states.py --out work/pipeline_states.bin <list>... merged, each pipeline once
python -I nx2/pipeline_states.py --v2 --out <file> <list>... the same, version 1 lists converted to version 2
python -I nx2/pipeline_states.py --check <list>... each list checked (exit 1 when one is not sound)
python -I nx2/pipeline_states.py --out work/pipeline_states.bin --contrib contrib <list>...
and the players' lists in contrib/ (*.bin.xz, a note each), checked one by one,
@@ -20,13 +21,39 @@ Point-list records are counted as suspect: --check refuses them and --contrib le
A list holds no game code: each record is a pipeline's stage code keys (hashes of the game's shaders, which the player's own
triforce_shaders.bin turns back into the shaders), the program variant's hash, and the formats and draw state baked into the pipeline.
Any list is read plain or xz-packed (told by its first bytes).
Version 2 (HKSTATE2, written by builds since it) holds what the game asked for, the same on every GPU and with any settings: the
targets' NVN formats, whether the draw was a mesh draw, the draw's own topology, and the program variant's texture answers with its
stages numbered without the mesh fallback's generated vertex stage. Each GPU's shader preparation maps them through the rules its
draws follow (the formats it makes of the NVN ones, its mesh shaders or the mesh fallback). Version 1 (HKSTATE1, older builds) held
the recording GPU's choices: the Vulkan formats it rendered in, and on a GPU with the mesh fallback the fallback's topology and
stage numbering; the game still reads it.
<list>: "HKSTATE2", u32 record size (552), then the records:
u64 code[4] (vertex or mesh, fragment, task, the header-only stage), u64 variant (of the answers below),
u32 mesh, topology (a mesh draw's: triangle list), targets, samples, has depth, depth NVN format,
u32 colour NVN texture formats[8] (0: none), u32 colour NVN view formats[8] (the format each is drawn in),
u64 blend[8], u32 vertex attributes[16], u32 attribute count, u32 strides[16], u32 divisors[16],
u32 blend enables, channel mask, polygon mode, depth clamp, alpha to coverage,
u32 answers, u32 questions, u32 answers[24] (stage, descriptor, image, type), u8 questions[32], u32 kind, u32 pad
(variant 0 with no answers and no questions: the variant nothing bound makes, each texture as its instruction
declares it; lists converted from records without texture answers hold those)
kind 0: a graphics or mesh pipeline, as above.
kind 1 (COMPUTE): a compute program, code[0] its compute stage's code key and every other field 0 (the game
writes one at a program's first dispatch; its pipelines' reader leaves them out, vk_draw.cpp state_list_computes
reads them)
<list>: "HKSTATE1", u32 record size (528), then the records:
u64 code[4] (vertex or mesh, fragment, task, the header-only stage), u64 variant,
u32 mesh, topology, targets, samples, depth format, has depth, u32 color formats[8], u8 color types[8],
u64 code[4], u64 variant,
u32 mesh, topology, targets, samples, depth format, has depth, u32 color formats[8] (Vulkan), u8 color types[8],
u64 blend[8], u32 vertex attributes[16], u32 attribute count, u32 strides[16], u32 divisors[16],
u32 blend enables, channel mask, polygon mode, depth clamp, alpha to coverage, pad,
u32 answers, u32 questions, u32 answers[24] (stage, descriptor, image, type), u8 questions[32] (each answer as asked)
Lists of both versions merge into version 2 (version 1 alone stays version 1; --v2 converts it too). A version 1 record is
converted: each Vulkan format back to an NVN format every GPU renders in it (V1_NVN: no format a GPU chooses itself), a mesh record
made with the mesh fallback numbered as the native one. A record that cannot be (a format the table lacks, a fallback record whose
answers were left out) is left out, and counted.
"""
import argparse
import collections
@@ -39,15 +66,147 @@ import zipfile
MAGIC = b"HKSTATE1"
SIZE = 528
MAGIC2 = b"HKSTATE2"
SIZE2 = 552
XZ_MAGIC = b"\xfd7zXZ\x00"
TRIANGLE_LIST = 3 # (VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: what a mesh draw is given, vk_draw.cpp kMeshDrawTopology)
# A version 1 record's Vulkan format -> an NVN format vk_format (gpu/vk/vk_formats.cpp) makes it on every GPU: the formats a
# target can be, ASTC and BC (no GPU renders into them) left out. tests/test_pipeline_states.py checks it against vk_formats.cpp,
# gpu/render/nvn_api.h and the Vulkan headers
V1_NVN = {
4: 0x95, 5: 0x3c, 7: 0x3a, 8: 0x3b, 9: 0x01, 10: 0x02, 13: 0x03, 14: 0x04, 16: 0x0d, 17: 0x0e, 20: 0x0f, 21: 0x10,
23: 0x19, 24: 0x1a, 27: 0x1b, 28: 0x1c, 37: 0x6d, 38: 0x6e, 41: 0x6f, 42: 0x70, 43: 0x37, 44: 0x99, 50: 0x9b,
64: 0x3d, 68: 0x3e, 70: 0x06, 71: 0x07, 74: 0x08, 75: 0x09, 76: 0x05, 77: 0x12, 78: 0x13, 81: 0x14, 82: 0x15,
83: 0x11, 91: 0x72, 92: 0x73, 95: 0x74, 96: 0x75, 97: 0x29, 98: 0x0b, 99: 0x0c, 100: 0x0a, 101: 0x17, 102: 0x18,
103: 0x16, 106: 0x22, 107: 0x77, 108: 0x78, 109: 0x76, 122: 0x3f, 123: 0x40, 124: 0x32, 125: 0x33, 126: 0x34,
127: 0x31, 129: 0x35, 130: 0x36, 1000340001: 0x39,
}
# the records as struct layouts (vk_draw.cpp StateRec, StateRec2)
_V1 = struct.Struct("<4QQ6I8I8s8Q16II16I16I6III24I32s4x")
_V2 = struct.Struct("<4QQ6I8I8I8Q16II16I16I5III24I32s2I")
assert _V1.size == SIZE and _V2.size == SIZE2
KIND_AT = SIZE2 - 8 # (a version 2 record's kind: vk_draw.cpp StateRec2::kind)
COMPUTE = 1 # (StateRec2::kCompute)
HEADS = {MAGIC: SIZE, MAGIC2: SIZE2}
def read_any(path):
"""A list's bytes, plain or xz-packed (told by its first bytes)"""
with open(path, "rb") as f:
data = f.read()
return lzma.decompress(data) if data[:6] == XZ_MAGIC else data
def head_size(data):
"""The record size a list's head names, None when its head is not one of a version this reads"""
if len(data) < 12 or HEADS.get(data[:8]) != struct.unpack_from("<I", data, 8)[0]:
return None
return HEADS[data[:8]]
def read(path):
with open(path, "rb") as f:
data = f.read()
if data[:8] != MAGIC or struct.unpack_from("<I", data, 8)[0] != SIZE:
raise SystemExit("%s: not a pipeline state list" % path)
data = read_any(path)
size = head_size(data)
if not size:
raise SystemExit("%s: not a pipeline state list (%s, %d-byte records, or %s, %d)" % (path, MAGIC2.decode(), SIZE2,
MAGIC.decode(), SIZE))
body = data[12:]
return [body[i:i + SIZE] for i in range(0, len(body) - SIZE + 1, SIZE)]
return [body[i:i + size] for i in range(0, len(body) - size + 1, size)]
def kind(r):
"""A record's kind: 0 a graphics or mesh pipeline (every version 1 record), COMPUTE a compute program"""
return struct.unpack_from("<I", r, KIND_AT)[0] if len(r) == SIZE2 else 0
def compute_record(key):
"""The record of a compute program: its compute stage's code key and nothing else"""
r = bytearray(SIZE2)
struct.pack_into("<Q", r, 0, key)
struct.pack_into("<I", r, KIND_AT, COMPUTE)
return bytes(r)
# ---- version 1 records as version 2
def answers_hash(answers):
"""Program::variant of packed answers (vk_shader.cpp answers_hash)"""
h = 0
for a in answers:
stage, desc, image, typ = a >> 28, a >> 12 & 0xFFFF, a >> 8 & 1, a & 0xFF
h = ((h ^ (stage << 32 | desc << 16 | typ << 1 | image)) * 1099511628211) & 0xFFFFFFFFFFFFFFFF
return h
def v1_to_v2(r):
"""A version 1 record as version 2, or None when it cannot be (vk_draw.cpp state_v1_portable does the same in the game)"""
f = list(_V1.unpack(r))
code, variant = f[0:4], f[4]
mesh, topo, n, samples, depth_format, has_depth = f[5:11]
colors = f[11:19]
blend, vattr, nvattr = f[20:28], f[28:44], f[44]
stride, divisor = f[45:61], f[61:77]
blend_en, chmask, poly, clamp, a2c = f[77:82]
nanswers, nquestions = f[83], f[84]
answers, questions = list(f[85:109]), f[109]
if nanswers > 24 or nquestions > 32 or n > 8:
return None
if mesh: # (made with the mesh fallback: its generated vertex stage after (task,) mesh, and the fallback's topology)
g = 2 if code[2] else 1
fallback = topo != TRIANGLE_LIST or any(a >> 28 > g for a in answers[:nanswers])
if fallback:
if not nanswers:
return None
for i in range(nanswers):
if answers[i] >> 28 > g:
answers[i] = (answers[i] & 0x0FFFFFFF) | ((answers[i] >> 28) - 1) << 28
variant, topo = answers_hash(answers[:nanswers]), TRIANGLE_LIST
nvn = []
for k in range(8):
if k >= n or not colors[k]:
nvn.append(0)
elif colors[k] in V1_NVN:
nvn.append(V1_NVN[colors[k]])
else:
return None
depth_nvn = 0
if has_depth and depth_format:
if depth_format not in V1_NVN:
return None
depth_nvn = V1_NVN[depth_format]
return _V2.pack(*code, variant, mesh, topo, n, samples, has_depth, depth_nvn, *nvn, *nvn, *blend, *vattr, nvattr,
*stride, *divisor, blend_en, chmask, poly, clamp, a2c, nanswers, nquestions, *answers, questions, 0, 0)
def as_v2(lists, force=False):
"""Lists of records of one version: as they are when all are version 1 (and not force), else each version 1 record converted
(those that cannot be left out). (lists, how many were left out from each)"""
if not force and all(len(r) == SIZE for recs in lists for r in recs):
return lists, [0] * len(lists)
out, lost = [], []
for recs in lists:
conv, n = [], 0
for r in recs:
r = v1_to_v2(r) if len(r) == SIZE else r
if r is None:
n += 1
else:
conv.append(r)
out.append(conv)
lost.append(n)
return out, lost
def pack(recs):
"""A list's bytes, unpacked: what the game reads. Version 2 when any record is (the version 1 ones converted)"""
(recs,), lost = as_v2([recs])
if lost[0]:
print("%d version 1 pipelines could not be converted to version 2: left out" % lost[0], file=sys.stderr)
if recs and len(recs[0]) == SIZE2:
return MAGIC2 + struct.pack("<I", SIZE2) + b"".join(recs)
return MAGIC + struct.pack("<I", SIZE) + b"".join(recs)
# ---- (Triforce, 11-22, PIPE-11) checking a list
@@ -57,12 +216,23 @@ POINT_LIST = 0 # (VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
def record_faults(r):
"""What is wrong with one record, as words (none: sound). Its counts within their arrays, a first stage, flags 0 or 1"""
"""What is wrong with one record of either version, as words (none: sound). Its counts within their arrays, a first stage,
flags 0 or 1; a version 2 record of a kind this knows (a compute program's: its key and nothing else)"""
faults = []
code0 = struct.unpack_from("<Q", r, 0)[0]
mesh, topo, n, samples, _depth, has_depth = struct.unpack_from("<6I", r, 40)
nvattr = struct.unpack_from("<I", r, 232)[0]
nanswers, nquestions = struct.unpack_from("<2I", r, 388)
if len(r) == SIZE2:
k = kind(r)
if k == COMPUTE:
return [] if code0 and r == compute_record(code0) else ["a compute program's record holding more than its key, or none"]
if k:
return ["kind %d" % k]
mesh, topo, n, samples, has_depth = struct.unpack_from("<5I", r, 40)
nvattr = struct.unpack_from("<I", r, 256)[0]
nanswers, nquestions = struct.unpack_from("<2I", r, 408)
else:
mesh, topo, n, samples, _depth, has_depth = struct.unpack_from("<6I", r, 40)
nvattr = struct.unpack_from("<I", r, 232)[0]
nanswers, nquestions = struct.unpack_from("<2I", r, 388)
if not code0:
faults.append("no vertex or mesh stage")
if mesh > 1 or has_depth > 1:
@@ -81,21 +251,24 @@ def record_faults(r):
def is_point(r):
return struct.unpack_from("<I", r, 44)[0] == POINT_LIST
"""A pipeline drawing point lists (the topology at the same place in both versions; a compute program is no pipeline)"""
return kind(r) == 0 and struct.unpack_from("<I", r, 44)[0] == POINT_LIST
def check_bytes(data, name="list"):
"""(records, faults, points): the records of a list's bytes, what is wrong with it (empty: sound), and how many records
draw point lists"""
if data[:8] != MAGIC:
return [], ["%s: not a pipeline state list (no %s head)" % (name, MAGIC.decode())], 0
if len(data) < 12 or struct.unpack_from("<I", data, 8)[0] != SIZE:
return [], ["%s: record size %s, not %d" % (name, struct.unpack_from("<I", data, 8)[0] if len(data) >= 12 else "?", SIZE)], 0
if data[:8] not in HEADS:
return [], ["%s: not a pipeline state list (no %s or %s head)" % (name, MAGIC2.decode(), MAGIC.decode())], 0
size = head_size(data)
if not size:
return [], ["%s: record size %s, not %d" % (name, struct.unpack_from("<I", data, 8)[0] if len(data) >= 12 else "?",
HEADS[data[:8]])], 0
body = data[12:]
faults = []
if len(body) % SIZE:
faults.append("%s: %d bytes past its last whole record (cut short)" % (name, len(body) % SIZE))
recs = [body[i:i + SIZE] for i in range(0, len(body) - SIZE + 1, SIZE)]
if len(body) % size:
faults.append("%s: %d bytes past its last whole record (cut short)" % (name, len(body) % size))
recs = [body[i:i + size] for i in range(0, len(body) - size + 1, size)]
bad = 0
for k, r in enumerate(recs):
f = record_faults(r)
@@ -108,13 +281,6 @@ def check_bytes(data, name="list"):
return recs, faults, sum(1 for r in recs if is_point(r))
def read_any(path):
"""A list's bytes, plain or xz-packed (.xz)"""
with open(path, "rb") as f:
data = f.read()
return lzma.decompress(data) if path.endswith(".xz") else data
def contrib_sources(folder):
"""The players' lists in a folder: (name, path, note), by name; a list's note is <name>.note beside it ("" without)"""
out = []
@@ -130,15 +296,20 @@ def contrib_sources(folder):
return out
def merge_sources(sources, keep_points=False):
def merge_sources(sources, keep_points=False, force_v2=False):
"""sources: (name, bytes, note) in order. The merged records (each once, in the order first met) and a report line a
source: its records, what it added, its repeats, the point-list records left out, or why it was left out whole"""
merged, seen, report = [], set(), []
for name, data, note in sources:
recs, faults, points = check_bytes(data, name)
source: its records, what it added, its repeats, the point-list records left out, or why it was left out whole. Version 2
when any sound source is (or force_v2): each version 1 record converted first, those that cannot be counted"""
checked, report = [], [None] * len(sources)
for i, (name, data, note) in enumerate(sources):
recs, faults, _points = check_bytes(data, name)
if faults:
report.append("%s: left out: %s" % (name, "; ".join(faults)))
report[i] = "%s: left out: %s" % (name, "; ".join(faults))
continue
checked.append((i, name, recs, note))
lists, lost = as_v2([recs for _i, _name, recs, _note in checked], force_v2)
merged, seen = [], set()
for (i, name, given, note), recs, gone in zip(checked, lists, lost):
added = repeats = dropped = 0
for r in recs:
if is_point(r) and not keep_points:
@@ -150,8 +321,9 @@ def merge_sources(sources, keep_points=False):
seen.add(r)
merged.append(r)
added += 1
report.append("%s: %d pipelines, %d added, %d already in, %d point-list records left out%s" %
(name, len(recs), added, repeats, dropped, (" (" + note + ")") if note else ""))
report[i] = "%s: %d pipelines, %d added, %d already in, %d point-list records left out%s%s" % (
name, len(given), added, repeats, dropped, (", %d not converted to version 2" % gone) if gone else "",
(" (" + note + ")") if note else "")
return merged, report
@@ -168,7 +340,7 @@ def export_zip(list_path, zip_path):
report.write("Triforce pipeline state list, for the shipped list (hashes and draw state only, no game code)\n")
report.write("%s\n" % describe(recs))
report.write("point-list records: %d\n" % points)
report.write("record size %d, %s\n" % (SIZE, MAGIC.decode()))
report.write("record size %d, %s\n" % (head_size(data), data[:8].decode()))
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_STORED) as z:
z.writestr("triforce_pipeline_states.bin.xz", lzma.compress(data))
z.writestr("report.txt", report.getvalue())
@@ -176,20 +348,30 @@ def export_zip(list_path, zip_path):
def describe(recs):
versions = collections.Counter(1 if len(r) == SIZE else 2 for r in recs)
programs = collections.Counter()
kinds = collections.Counter()
for r in recs:
code = struct.unpack_from("<4Q", r, 0)
mesh = struct.unpack_from("<I", r, 40)[0]
programs[(code, mesh)] += 1
kinds["mesh" if mesh else "graphics"] += 1
return "%d pipelines (%s) of %d programs" % (len(recs), ", ".join("%s %d" % kv for kv in sorted(kinds.items())), len(programs))
compute = kind(r) == COMPUTE
programs[(code, mesh, compute)] += 1
kinds["compute" if compute else "mesh" if mesh else "graphics"] += 1
return "%d pipelines (%s) of %d programs%s" % (len(recs), ", ".join("%s %d" % kv for kv in sorted(kinds.items())), len(programs),
"".join(", version %d" % v for v in sorted(versions)))
def write(path, recs):
data = pack(recs)
with open(path, "wb") as f:
f.write(lzma.compress(data) if path.endswith(".xz") else data)
def main():
p = argparse.ArgumentParser(description=__doc__.split("\n")[0])
p.add_argument("lists", nargs="*")
p.add_argument("--out")
p.add_argument("--v2", action="store_true", help="version 2 out even from version 1 lists alone (converted)")
p.add_argument("--check", action="store_true", help="check each list: exit 1 when one is not sound")
p.add_argument("--contrib", help="a folder of players' lists (*.bin.xz, a .note each), checked and merged after the lists")
p.add_argument("--keep-points", action="store_true", help="keep point-list records (refused by --check, left out by --contrib)")
@@ -209,27 +391,32 @@ def main():
if a.contrib:
sources = [(os.path.basename(x), read_any(x), "") for x in a.lists]
sources += [(name, read_any(path), note) for name, path, note in contrib_sources(a.contrib)]
merged, report = merge_sources(sources, a.keep_points)
merged, report = merge_sources(sources, a.keep_points, a.v2)
for line in report:
print(line)
if a.out:
with open(a.out, "wb") as f:
f.write(MAGIC + struct.pack("<I", SIZE) + b"".join(merged))
write(a.out, merged)
print("%s: %s" % (a.out, describe(merged)))
return 0
if not a.lists:
p.error("no list")
merged, seen = [], set()
lists = []
for path in a.lists:
recs = read(path)
print("%s: %s" % (path, describe(recs)))
for r in recs:
if r not in seen:
seen.add(r)
merged.append(r)
lists.append(recs)
if a.out:
with open(a.out, "wb") as f:
f.write(MAGIC + struct.pack("<I", SIZE) + b"".join(merged))
lists, lost = as_v2(lists, force=a.v2)
if sum(lost):
print("%d version 1 pipelines not converted (a format no table entry has, or a mesh fallback record without its "
"answers): left out" % sum(lost))
merged, seen = [], set()
for recs in lists:
for r in recs:
if r not in seen:
seen.add(r)
merged.append(r)
write(a.out, merged)
print("%s: %s" % (a.out, describe(merged)))