mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.5.2
The new launcher (Windows and Linux: the game's own look, music and settings, saves and mods pages, smaller updates in parts), benchmark mode (Find my best settings: the game tours four places by itself and writes its results), Quit and Restart in the pause menu under Mods, Squadala! in the Mods menu, battle music above 60 fps, menu text, the controller in the menus with the game in the background, the whole GameBanana list, RX 580 and RX 5000/6000 shader fixes, the pipeline cache kept through an update, async present black flashes, and faster builds.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""The program cache carried over an update of the translator (gpu/vk/program_carry.h has the rule; no game, no GPU).
|
||||
|
||||
A kept program is used by another build of the translator only when the two have the same translation stamp (nx2/build.py
|
||||
translation_stamp, HOOKSHOT_TRANSLATION_STAMP): the translator's files without vk_api.h, without the parts of vk_shader.cpp
|
||||
marked as outside it, and without comments, blank lines and the spaces at lines' ends. These checks hold that rule:
|
||||
translation_stamp, HOOKSHOT_TRANSLATION_STAMP): the translator's files without vk_api.h, without the parts of vk_shader.cpp and
|
||||
vk_bank.cpp marked as outside it, and without comments, blank lines and the spaces at lines' ends. These checks hold that rule:
|
||||
|
||||
- the stamp, by nx2/build.py's own functions run on authored files: every edit that can change a translation changes it (code
|
||||
anywhere else, a literal that looks like a comment, a number with digit separators, an #include's name, a raw string, the
|
||||
@@ -14,6 +14,12 @@ marked as outside it, and without comments, blank lines and the spaces at lines'
|
||||
the translation's thread state, a record's fields), the rest of the file taking from them only the names listed below with
|
||||
why each cannot change a translation, make_module taking its SPIR-V const; vk_api.h's names nowhere in the translator and the
|
||||
host's functions it calls only those whose answers are in a record's key or the stamp;
|
||||
- vk_bank.cpp's marked parts: the reviewed ones, each between definitions, defining nothing that stamped code names (vk_shader.cpp's
|
||||
and the other stamped files' calls, the stamped vk_bank.cpp functions' callees and shared state) and naming nothing a translation
|
||||
reaches (what those calls reach through vk_bank.cpp's stamped functions: texture_of's registrations, which texture_released
|
||||
and the registrations write, stay in the stamp); the check itself finds such parts in vk_bank.cpp edited so;
|
||||
- the build's record of the stamp: the build log names the stamped files that changed it against the last release's
|
||||
(nx2/released_translation_stamp.json, which this source's stamp equals) and, as a note, against the previous build's;
|
||||
- the stamp's code: disk_stamp takes the translation stamp with the carry, the whole one without it or in a build without the
|
||||
translation stamp; disk_init lists records only for a file of this very stamp; the switch is documented;
|
||||
- program_carry.h's verdicts, compiled and run, and disk_init cut out of vk_shader.cpp and run on cache files authored here: a
|
||||
@@ -25,6 +31,7 @@ marked as outside it, and without comments, blank lines and the spaces at lines'
|
||||
import argparse
|
||||
import ast
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
@@ -50,12 +57,13 @@ C_LIKE = (".c", ".cc", ".cpp", ".h", ".hpp", ".inc")
|
||||
def build_functions():
|
||||
"""nx2/build.py's stamp functions and its whole stamp's block, to run here"""
|
||||
tree = ast.parse(BUILD.read_text(encoding="utf-8"), filename=str(BUILD))
|
||||
names = {"strip_comments", "translation_text", "translation_stamp"}
|
||||
functions = [n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name in names]
|
||||
assert {n.name for n in functions} == names
|
||||
ns = {"os": os, "hashlib": hashlib}
|
||||
exec(compile(ast.Module(body=functions, type_ignores=[]), str(BUILD), "exec"), ns)
|
||||
names = {"strip_comments", "translation_text", "translation_stamp", "translation_files", "translation_record_read",
|
||||
"translation_changed", "translation_stamp_note", "translation_stamp_keep"}
|
||||
assigns = lambda n, name: isinstance(n, ast.Assign) and any(isinstance(t, ast.Name) and t.id == name for t in n.targets)
|
||||
functions = [n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name in names or assigns(n, "RELEASED_STAMP")]
|
||||
assert {n.name for n in functions if isinstance(n, ast.FunctionDef)} == names and len(functions) == len(names) + 1
|
||||
ns = {"os": os, "hashlib": hashlib, "json": json, "__file__": str(BUILD)}
|
||||
exec(compile(ast.Module(body=functions, type_ignores=[]), str(BUILD), "exec"), ns)
|
||||
branch = [n for n in ast.walk(tree) if isinstance(n, ast.If) and any(assigns(s, "translator") for s in n.body)]
|
||||
assert len(branch) == 1
|
||||
body = [n for n in branch[0].body if assigns(n, "stamp") or assigns(n, "translator") or isinstance(n, ast.For) and
|
||||
@@ -250,6 +258,114 @@ class StampTests(unittest.TestCase):
|
||||
_, after = self.stamps()
|
||||
self.assertNotEqual(before, after, "a second end mark was taken for a pair")
|
||||
|
||||
def test_the_record_names_the_files_that_moved_the_stamp(self):
|
||||
"""nx2/build.py translation_stamp_note against the last release's record and translation_stamp_keep's: kept, or the
|
||||
stamped files that changed it. The release's comes first and stays the reference: a build after one that moved the stamp
|
||||
still says it is not the release's"""
|
||||
record = str(Path(self.temp.name) / "translation_stamp.json")
|
||||
released = str(Path(self.temp.name) / "released_translation_stamp.json")
|
||||
|
||||
def now():
|
||||
eden, _ = translator_files(str(self.vk))
|
||||
return NS["translation_stamp"](str(self.vk), eden), NS["translation_files"](str(self.vk), eden)
|
||||
|
||||
def note():
|
||||
with mock.patch("builtins.print") as said:
|
||||
changed = NS["translation_stamp_note"](record, *now(), released=released)
|
||||
return changed, "\n".join(" ".join(map(str, c.args)) for c in said.call_args_list)
|
||||
|
||||
stamp, files = now()
|
||||
self.assertEqual(sorted(files), ["compat/c.h", "eden/a.cpp", "eden/raw.cpp", "sirit/b.h", "sirit/notes.txt", "vk_bank.cpp",
|
||||
"vk_shader.cpp", "vk_state.h"], "the record's files are not the translation stamp's")
|
||||
changed, said = note()
|
||||
self.assertEqual(changed, (None, None))
|
||||
self.assertIn("translation stamp %s (no record of the last release's" % stamp, said)
|
||||
self.assertIn("no record of the previous build's translation stamp in this folder", said)
|
||||
# (the release's record as the repository keeps it: translation_stamp_keep's, with the release's name)
|
||||
NS["translation_stamp_keep"](released, stamp, files)
|
||||
data = json.loads(Path(released).read_text(encoding="utf-8"))
|
||||
data["release"] = "v9.9.9"
|
||||
Path(released).write_text(json.dumps(data), encoding="utf-8")
|
||||
NS["translation_stamp_keep"](record, stamp, files)
|
||||
self.assertFalse(os.path.exists(record + ".tmp"))
|
||||
changed, said = note()
|
||||
self.assertEqual(changed, ([], []))
|
||||
self.assertIn("translation stamp %s, as v9.9.9's: the build's part of the shader caches' stamp is kept" % stamp, said)
|
||||
self.assertIn("the translation stamp is the previous build's in this folder", said)
|
||||
self.assertNotIn("carry over", said)
|
||||
# (what cannot change a translation: kept, and nothing named)
|
||||
self.write({"vk_shader.cpp": SHADER.replace("not_translation = 3", "not_translation = 9").replace("// (a note)", "// (b)"),
|
||||
"vk_api.h": "enum { HOS_OPT_X = 2 };\n", "vk_draw.cpp": "int draw2;\n"})
|
||||
changed, said = note()
|
||||
self.assertEqual(changed, ([], []))
|
||||
self.assertIn("as v9.9.9's", said)
|
||||
# (code: the files named, the stamp before too)
|
||||
self.write(self.files)
|
||||
self.write({"vk_bank.cpp": "int bank2;\n", "eden/a.cpp": "int a = 2;\n"})
|
||||
moved, _ = now()
|
||||
changed, said = note()
|
||||
self.assertEqual(changed, (["eden/a.cpp", "vk_bank.cpp"], ["eden/a.cpp", "vk_bank.cpp"]))
|
||||
self.assertIn("translation stamp %s, NOT v9.9.9's (%s): at this update a player's program and pipeline caches from "
|
||||
"v9.9.9 start again" % (moved, stamp), said)
|
||||
self.assertIn("Changed against it by: eden/a.cpp, vk_bank.cpp", said)
|
||||
self.assertIn("in this folder was %s; changed since by: eden/a.cpp, vk_bank.cpp" % stamp, said)
|
||||
# (the next build in the folder, nothing changed since: the previous build's, but still NOT the release's)
|
||||
NS["translation_stamp_keep"](record, *now())
|
||||
changed, said = note()
|
||||
self.assertEqual(changed, (["eden/a.cpp", "vk_bank.cpp"], []))
|
||||
self.assertIn("NOT v9.9.9's", said)
|
||||
self.assertIn("Changed against it by: eden/a.cpp, vk_bank.cpp", said)
|
||||
self.assertIn("the translation stamp is the previous build's in this folder", said)
|
||||
self.assertNotIn("as v9.9.9's", said)
|
||||
# (a file new to the translator, one gone)
|
||||
self.write(self.files)
|
||||
(self.vk / "eden" / "new.h").write_bytes(b"int n;\n")
|
||||
(self.vk / "sirit" / "notes.txt").unlink()
|
||||
changed, said = note()
|
||||
self.assertEqual(changed[0], ["eden/new.h", "sirit/notes.txt"])
|
||||
self.assertIn("Changed against it by: eden/new.h (new), sirit/notes.txt (gone)", said)
|
||||
# (more than 12: those and a count)
|
||||
_, named = NS["translation_changed"]({}, {"f%02d" % i: "x" for i in range(15)})
|
||||
self.assertEqual(named, ", ".join(["f%02d (new)" % i for i in range(12)] + ["3 more"]))
|
||||
# (a record cut short, or of something else: none to compare with)
|
||||
for text in ("{", "[]", '{"stamp": 1, "files": {}}', '{"files": {}}'):
|
||||
with self.subTest(record=text):
|
||||
Path(record).write_text(text, encoding="utf-8")
|
||||
Path(released).write_text(text, encoding="utf-8")
|
||||
self.assertEqual(note()[0], (None, None))
|
||||
|
||||
def test_the_repository_keeps_the_last_release_stamp(self):
|
||||
"""The translation stamp of this source is the last release's (nx2/released_translation_stamp.json, made from that
|
||||
release's source): moving it starts every player's program and pipeline caches again at the update. A change that has
|
||||
to move it changes this test with it, saying why; the record itself changes only when a release goes out"""
|
||||
record = NS["translation_record_read"](NS["RELEASED_STAMP"])
|
||||
self.assertIsNotNone(record, "no record of the last release's translation stamp in nx2")
|
||||
rel_stamp, rel_files, release = record
|
||||
self.assertEqual(release, "v0.5.1")
|
||||
self.assertEqual(rel_stamp, "f6b970031161afbe")
|
||||
eden, _ = translator_files(str(VK))
|
||||
files = NS["translation_files"](str(VK), eden)
|
||||
changed, named = NS["translation_changed"](rel_files, files)
|
||||
self.assertEqual(changed, [], "the translation's text differs from %s's in: %s" % (release, named))
|
||||
self.assertEqual(NS["translation_stamp"](str(VK), eden), rel_stamp,
|
||||
"this source's translation stamp is not %s's: every player's shader caches start again" % release)
|
||||
|
||||
def test_the_build_keeps_the_record_once_compiled(self):
|
||||
src = BUILD.read_text(encoding="utf-8")
|
||||
self.assertIn('translation_def = "-DHOOKSHOT_TRANSLATION_STAMP=0x%sull" % translation_now', src)
|
||||
self.assertIn("translation_now = translation_stamp(vk, translator)", src)
|
||||
self.assertIn("translation_record = (os.path.join(out, TRANSLATION_RECORD), translation_now, translation_files(vk, translator))",
|
||||
src)
|
||||
# (said after the back end's jobs are made, outside the branch that makes them: tests/test_shader_stamp_cache.py runs it)
|
||||
self.assertLess(src.index(" jobs += vk_jobs\n"), src.index("translation_stamp_note(*translation_record)"))
|
||||
# (written once this build's objects are compiled, not by a dry run nor a build that failed)
|
||||
keep = src.index(" if build_vk: # ((Triforce) the translation stamp this build compiled")
|
||||
self.assertIn("translation_stamp_keep(*translation_record)", src[keep:keep + 200])
|
||||
self.assertLess(src.index("if a.dry_run:"), keep)
|
||||
compiled = src.index('print("compiled in %.0fs, %d failed"')
|
||||
self.assertLess(src.index(" if still:\n return 1\n", compiled), keep)
|
||||
self.assertLess(keep, src.index(" if EARLY: # (nothing to link yet"))
|
||||
|
||||
|
||||
class TranslatorFilesTests(unittest.TestCase):
|
||||
def test_every_translator_file_lexes_as_before(self):
|
||||
@@ -329,6 +445,175 @@ DENIED = [r"\bShader::", r"\busing\s+namespace\b", r"\bEnv\b",
|
||||
r"fallback_task|stages)\s*(?:=[^=]|\+=|\.push_back|\.emplace_back|\.clear|\.resize)"]
|
||||
FIRSTS = ["spirv_crc32", "DiskRecord", "disk_init", "ra_mu", "program_cache_load_some"]
|
||||
HOST_CALLS = {"gpu_read", "gpu_guest", "gpu_ptr", "guest_base", "guest_size", "depth_minus_w"}
|
||||
# (vk_bank.cpp's marked parts, by the first name each defines. None on this branch: epicmemes46's 5df76bb marks the samplers'
|
||||
# generation for its texture LOD bias (sampler_bias_changed), which this branch has not taken; with it, ["sampler_bias_changed"])
|
||||
BANK_FIRSTS = []
|
||||
MARKED = {"vk_shader.cpp": FIRSTS, "vk_bank.cpp": BANK_FIRSTS}
|
||||
# (what a translation reaches in vk_bank.cpp, at the least: what vk_shader.cpp calls, and what those read)
|
||||
BANK_REACHED = {"seed_cs_control", "compute_ssbo_table", "seed_cs_buffer_word", "texture_slot_version", "registrations_generation",
|
||||
"texture_of", "driver_bank_word", "cs_layout", "cs_layout_of", "CsLayout", "pointer_table", "tex_regs", "TexReg",
|
||||
"reg_mu", "slot_versions", "kSlotVersions", "reg_gen"}
|
||||
|
||||
|
||||
def code_of(text):
|
||||
"""A file's code without comments, literals and preprocessor lines, its marks as @@OUT@@ and @@IN@@"""
|
||||
text = "\n".join("@@OUT@@" if l.strip().startswith(OUT_MARK) else "@@IN@@" if l.strip().startswith(IN_MARK) else l
|
||||
for l in text.replace("\r\n", "\n").split("\n"))
|
||||
lines, directive = [], False
|
||||
for line in blank_literals(NS["strip_comments"](text.encode())[0].decode()).split("\n"):
|
||||
directive = directive or line.lstrip().startswith("#")
|
||||
lines.append("" if directive else line)
|
||||
directive = directive and line.rstrip().endswith("\\")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def mark_scopes(text):
|
||||
"""For each mark of a file, whether it is at namespace scope (between definitions, never inside one)"""
|
||||
code, stack, last, scopes = code_of(text), [], 0, []
|
||||
for m in re.finditer(r"[{}]|@@OUT@@|@@IN@@", code):
|
||||
if m.group() == "{":
|
||||
stack.append(bool(re.search(r"\bnamespace\b[^;{}]*$", code[last:m.start()])))
|
||||
elif m.group() == "}":
|
||||
stack.pop()
|
||||
else:
|
||||
scopes.append(all(stack))
|
||||
last = m.end()
|
||||
return scopes
|
||||
|
||||
|
||||
def top_level_parts(text):
|
||||
"""A file's definitions at namespace scope, in order, each as (its code, whether it is in the translation stamp): what ends
|
||||
at a ';' or a closing brace at namespace scope; a mark and a namespace's braces end one too"""
|
||||
code, parts, stack, start, inside = code_of(text), [], [], 0, True
|
||||
|
||||
def part(end):
|
||||
if code[start:end].strip(" \t\n;}"):
|
||||
parts.append((code[start:end], inside))
|
||||
|
||||
for m in re.finditer(r"@@OUT@@|@@IN@@|[{};]", code):
|
||||
t = m.group()
|
||||
if t in ("@@OUT@@", "@@IN@@"):
|
||||
part(m.start())
|
||||
start, inside = m.end(), t == "@@IN@@"
|
||||
elif t == "{":
|
||||
namespace = all(stack) and bool(re.search(r"\bnamespace\b[^;{}]*$", code[start:m.start()]))
|
||||
stack.append(namespace)
|
||||
if namespace:
|
||||
start = m.end()
|
||||
elif t == "}":
|
||||
if stack.pop():
|
||||
part(m.start())
|
||||
start = m.end()
|
||||
elif all(stack):
|
||||
part(m.end())
|
||||
start = m.end()
|
||||
elif all(stack):
|
||||
part(m.end())
|
||||
start = m.end()
|
||||
part(len(code))
|
||||
return parts
|
||||
|
||||
|
||||
def part_names(part):
|
||||
"""The names a definition at namespace scope gives: a function's, a type's, each variable's of its declaration"""
|
||||
s = " ".join(part.split())
|
||||
m = re.match(r"(?:typedef )?(?:struct|class|union|enum(?: class| struct)?) (\w+)", s) or re.match(r"using (\w+) ?=", s)
|
||||
if m:
|
||||
return [m.group(1)]
|
||||
names, depth, angle, head, init = [], 0, 0, "", False
|
||||
for ch in s:
|
||||
if depth == 0 and angle == 0 and ch in "(=[{,;":
|
||||
if not init:
|
||||
words = re.findall(r"\w+", head)
|
||||
if words:
|
||||
names.append(words[-1])
|
||||
if ch == "(":
|
||||
return names[-1:] # (a function: the name before its parameters)
|
||||
if ch == ";":
|
||||
break
|
||||
if ch == ",":
|
||||
init, head = False, ""
|
||||
continue
|
||||
init = True
|
||||
if ch in "([{":
|
||||
depth += 1
|
||||
elif ch in ")]}":
|
||||
depth -= 1
|
||||
elif depth == 0 and not init:
|
||||
if ch == "<":
|
||||
angle += 1
|
||||
elif ch == ">":
|
||||
angle = max(angle - 1, 0)
|
||||
elif angle == 0:
|
||||
head += ch
|
||||
return list(dict.fromkeys(names))
|
||||
|
||||
|
||||
def stamped_words(vk=VK, leave_out="vk_bank.cpp"):
|
||||
"""The names the translation stamp's text of the translator's C and C++ files uses (but leave_out's, and vk_api.h): every
|
||||
name in it, but what a declaration without a body at namespace scope declares (vk_state.h's prototypes of vk_bank.cpp's
|
||||
functions use none of them)"""
|
||||
eden, files = translator_files(str(vk))
|
||||
words = set()
|
||||
for path in eden + files[:-1]:
|
||||
if path.endswith(C_LIKE) and os.path.basename(path) != leave_out:
|
||||
for code, _ in top_level_parts(stamped(path, vk)):
|
||||
used = set(re.findall(r"\b\w+\b", code))
|
||||
words |= used if "{" in code else used - set(part_names(code))
|
||||
return words
|
||||
|
||||
|
||||
def bank_check(text, outside_words):
|
||||
"""vk_bank.cpp's marked parts against the rule: (what a translation reaches in the file, what is wrong). Stamped code (the
|
||||
other files' words, outside_words, and vk_bank.cpp's own stamped parts) names nothing a marked part defines; a marked part names
|
||||
nothing a translation reaches: what the other files name of vk_bank.cpp, and what that names through its definitions, in turn"""
|
||||
parts = top_level_parts(text)
|
||||
defs = {}
|
||||
for code, inside in parts:
|
||||
for name in part_names(code):
|
||||
defs.setdefault(name, []).append(set(re.findall(r"\b\w+\b", code)))
|
||||
reached, todo = set(), sorted(set(defs) & outside_words)
|
||||
while todo:
|
||||
name = todo.pop()
|
||||
if name not in reached:
|
||||
reached.add(name)
|
||||
for words in defs[name]:
|
||||
todo += sorted((words & set(defs)) - reached)
|
||||
stamped_code = set(outside_words)
|
||||
for code, inside in parts:
|
||||
if inside:
|
||||
stamped_code |= set(re.findall(r"\b\w+\b", code))
|
||||
# (and what changes what a translation reaches through a call: the stamped definitions that name it, and in turn those that
|
||||
# name them. A marked part that calls texture_released writes texture_of's registrations as surely as one that names tex_regs)
|
||||
writers = set(reached)
|
||||
grew = True
|
||||
while grew:
|
||||
grew = False
|
||||
for code, inside in parts:
|
||||
if inside:
|
||||
own = set(part_names(code)) - writers
|
||||
if own and set(re.findall(r"\b\w+\b", code)) & writers:
|
||||
writers |= own
|
||||
grew = True
|
||||
problems = []
|
||||
for code, inside in parts:
|
||||
if inside:
|
||||
continue
|
||||
own, words = part_names(code), set(re.findall(r"\b\w+\b", code))
|
||||
first = own[0] if own else code.strip()[:40]
|
||||
problems += ["%s, outside the stamp (the part from %s), is named by stamped code" % (n, first) for n in own if n in stamped_code]
|
||||
problems += ["the part from %s, outside the stamp, names %s, which a translation reaches" % (first, n)
|
||||
for n in sorted((words & reached) - set(own))]
|
||||
problems += ["the part from %s, outside the stamp, names %s, which changes what a translation reaches" % (first, n)
|
||||
for n in sorted((words & writers) - reached - set(own))]
|
||||
return reached, problems
|
||||
|
||||
|
||||
def marked_out(text, head, end="\n}\n"):
|
||||
"""text with the definition that starts at head marked as outside the stamp (to see that bank_check finds it)"""
|
||||
at = text.index("\n" + head) + 1
|
||||
stop = text.index(end, at) + len(end)
|
||||
return (text[:at] + OUT_MARK + ", authored ----\n" + text[at:stop] + IN_MARK + " ----\n" + text[stop:])
|
||||
|
||||
|
||||
class RuleTests(unittest.TestCase):
|
||||
@@ -338,39 +623,80 @@ class RuleTests(unittest.TestCase):
|
||||
cls.sections = marked_sections(cls.shader)
|
||||
cls.stamped = stamped(VK / "vk_shader.cpp")
|
||||
|
||||
def test_marks_only_in_vk_shader_and_between_definitions(self):
|
||||
def test_marks_only_where_reviewed_and_between_definitions(self):
|
||||
eden, vk = translator_files(str(VK))
|
||||
for path in eden + vk:
|
||||
if not path.endswith("vk_shader.cpp"):
|
||||
if os.path.basename(path) not in MARKED or os.path.dirname(path) != str(VK):
|
||||
text = Path(path).read_text(encoding="utf-8", errors="replace")
|
||||
self.assertNotIn("Outside the translation stamp", text, path)
|
||||
self.assertNotIn("Inside the translation stamp again", text, path)
|
||||
self.assertEqual([defined_names(s)[0] for s in self.sections], FIRSTS,
|
||||
"the marked parts are not the reviewed ones: a new one is reviewed here (ALLOWED, DENIED, FIRSTS)")
|
||||
# (each mark at namespace scope: the marked parts are whole definitions, never part of a function)
|
||||
text = "\n".join("@@OUT@@" if l.strip().startswith(OUT_MARK) else "@@IN@@" if l.strip().startswith(IN_MARK) else l
|
||||
for l in self.shader.split("\n"))
|
||||
text = blank_literals(NS["strip_comments"](text.encode())[0].decode())
|
||||
stack, last, marks = [], 0, 0
|
||||
for m in re.finditer(r"[{}]|@@OUT@@|@@IN@@", text):
|
||||
if m.group() == "{":
|
||||
stack.append(bool(re.search(r"\bnamespace\b[^;{}]*$", text[last:m.start()])))
|
||||
elif m.group() == "}":
|
||||
stack.pop()
|
||||
else:
|
||||
marks += 1
|
||||
self.assertTrue(all(stack), "a mark inside a definition (at %d)" % m.start())
|
||||
last = m.end()
|
||||
self.assertEqual(marks, 2 * len(FIRSTS))
|
||||
for name, firsts in MARKED.items():
|
||||
with self.subTest(file=name):
|
||||
text = (VK / name).read_text(encoding="utf-8").replace("\r\n", "\n")
|
||||
self.assertEqual([defined_names(s)[0] for s in marked_sections(text)], firsts,
|
||||
"the marked parts are not the reviewed ones: a new one is reviewed here (vk_shader.cpp: ALLOWED, "
|
||||
"DENIED, FIRSTS; vk_bank.cpp: BANK_FIRSTS, bank_check)")
|
||||
# (each mark at namespace scope: the marked parts are whole definitions, never part of a function)
|
||||
scopes = mark_scopes(text)
|
||||
self.assertEqual(len(scopes), 2 * len(firsts))
|
||||
self.assertTrue(all(scopes), "a mark inside a definition (marks %s)" % scopes)
|
||||
self.assertFalse(all(mark_scopes("namespace a {\nvoid f() {\n" + OUT_MARK + "\n}\n" + IN_MARK + "\n}\n")),
|
||||
"the scope check does not see a mark inside a function")
|
||||
|
||||
def test_marked_parts_touch_nothing_of_a_translation(self):
|
||||
for section, first in zip(self.sections, FIRSTS):
|
||||
bank = (VK / "vk_bank.cpp").read_text(encoding="utf-8").replace("\r\n", "\n")
|
||||
for section, first in list(zip(self.sections, FIRSTS)) + list(zip(marked_sections(bank), BANK_FIRSTS)):
|
||||
code = blank_literals(NS["strip_comments"](section.encode())[0].decode())
|
||||
for pattern in DENIED:
|
||||
found = re.search(pattern, code)
|
||||
self.assertIsNone(found, "the marked part from %s names %r: that belongs in the translation stamp" %
|
||||
(first, found and found.group()))
|
||||
|
||||
def test_bank_marked_parts_hold_nothing_a_translation_reads(self):
|
||||
"""vk_bank.cpp's marked parts (bank_check): nothing stamped code names, nothing a translation reaches"""
|
||||
if not BANK_FIRSTS:
|
||||
self.skipTest("vk_bank.cpp has no marked parts on this branch (the texture LOD bias is not in it)")
|
||||
bank = (VK / "vk_bank.cpp").read_text(encoding="utf-8").replace("\r\n", "\n")
|
||||
outside = stamped_words()
|
||||
reached, problems = bank_check(bank, outside)
|
||||
self.assertEqual(problems, [])
|
||||
self.assertLessEqual(BANK_REACHED, reached, "the check no longer sees what a translation reaches in vk_bank.cpp")
|
||||
for name in ("sampler_bias_changed", "samp_gen", "register_texture_copy", "texture_released", "register_sampler_copy"):
|
||||
self.assertNotIn(name, reached, "a translation reaches %s: then what writes it stays in the stamp" % name)
|
||||
self.assertNotIn("sampler_bias_changed", stamped(VK / "vk_bank.cpp"))
|
||||
self.assertIn("bool texture_of(", stamped(VK / "vk_bank.cpp"))
|
||||
names = {n for code, _ in top_level_parts(bank) for n in part_names(code)}
|
||||
self.assertLessEqual({"slot_versions", "kPointerTable", "kPointerEntries", "regs_by_serial", "PointerEntry", "SampReg",
|
||||
"driver_bank_fill", "sampler_bias_changed"}, names, "the definitions are not all read")
|
||||
# (the check finds a part marked out that it should not be: what writes texture_of's registrations, what a translation
|
||||
# calls, what a stamped function calls or reads, what the marked part shares with stamped code)
|
||||
unmarked = bank.replace(OUT_MARK, "// ").replace(IN_MARK, "// ")
|
||||
self.assertEqual(bank_check(unmarked, outside)[1], [])
|
||||
for head, end, found in (
|
||||
("void texture_released(uint64_t serial) {", "\n}\n", "names tex_regs, which a translation reaches"),
|
||||
("void register_texture_copy(int id, const nvn_tex& tex, const nvn_view* v) {", "\n}\n", "names reg_gen"),
|
||||
("bool texture_of(int id,", "\n}\n", "texture_of, outside the stamp"),
|
||||
("CsLayout cs_layout(const NvnState& s) {", "\n}\n", "cs_layout, outside the stamp"),
|
||||
("std::atomic<uint64_t> reg_gen{1};", "\n", "reg_gen, outside the stamp"),
|
||||
("std::atomic<uint64_t> samp_gen{1};", "\n", "samp_gen, outside the stamp (the part from samp_gen), is named"),
|
||||
("uint64_t sampler_registrations_generation() {", "\n}\n", None)):
|
||||
with self.subTest(marked_out=head):
|
||||
problems = bank_check(marked_out(unmarked, head, end), outside)[1]
|
||||
if found is None: # (vk_draw.cpp's alone: no stamped code names it)
|
||||
self.assertEqual(problems, [])
|
||||
else:
|
||||
self.assertTrue(any(found in p for p in problems), problems)
|
||||
# (and a marked part that calls what writes texture_of's registrations, rather than naming them itself)
|
||||
bias = "void sampler_bias_changed() { samp_gen.fetch_add(1, std::memory_order_acq_rel); }"
|
||||
self.assertIn(bias, bank)
|
||||
for call, found in (("texture_released(0);", "names texture_released, which changes what a translation reaches"),
|
||||
("register_texture_copy(0, {}, nullptr);", "names register_texture_copy, which changes"),
|
||||
("register_texture(0, {}, nullptr);", "names register_texture, which changes")):
|
||||
with self.subTest(calls=call):
|
||||
edited = bank.replace(bias, bias[:-1] + call + " }")
|
||||
problems = bank_check(edited, outside)[1]
|
||||
self.assertTrue(any(found in p for p in problems), problems)
|
||||
|
||||
def test_the_rest_takes_only_what_is_listed(self):
|
||||
words = set(re.findall(r"\b\w+\b", blank_literals(self.stamped)))
|
||||
for section, first in zip(self.sections, FIRSTS):
|
||||
|
||||
Reference in New Issue
Block a user