Files
Triforce-Source/tests/test_draw_stream_visibility.py
ruckus7382sfgsgdf 6f338c8f56 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.
2026-11-17 22:40:50 -06:00

60 lines
2.9 KiB
Python

"""Execute production stream allocation/reset and serial/segment submission against host caches."""
import argparse
from pathlib import Path
import subprocess
import tempfile
RUN_ALL_ARGS = ["--cxx", "{cxx}", "--headers", "{vulkan_headers}"]
ROOT = Path(__file__).resolve().parents[1]
def block(text, marker):
start = text.index(marker)
at = text.index("{", start) + 1
depth = 1
while depth:
depth += (text[at] == "{") - (text[at] == "}")
at += 1
return text[start:at]
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--source", type=Path, default=ROOT)
p.add_argument("--headers", type=Path, required=True)
p.add_argument("--cxx", default="g++")
p.add_argument("--cache", choices=["all", "coherent", "noncoherent"], default="all")
p.add_argument("--case", default="all")
a = p.parse_args()
draw = (a.source / "gpu/vk/vk_draw.cpp").read_text(encoding="utf-8")
replay = (a.source / "gpu/vk/vk_replay.cpp").read_text(encoding="utf-8")
fixture = (ROOT / "tests/draw_stream_visibility_test.cpp").read_text(encoding="utf-8")
fixture = fixture.replace("/* RES */", block(draw, "struct RecordingRes {") + ";")
actual = "\n".join(block(draw, marker) for marker in ["bool stream_insert(", "bool stream_next(", "bool stream_reserve(", "uint64_t stream_alloc("])
actual += "\n" + block(draw, "BufferRef stream_copy(")
fixture = fixture.replace("/* STREAM */", actual)
flush = block(draw, "void draw_flush_recording(") if "void draw_flush_recording(" in draw else ""
fixture = fixture.replace("/* FLUSH */", flush).replace("/* BEGIN */", block(draw, "void draw_begin_recording("))
fixture = fixture.replace("/* SUBMIT */", block(replay, "void submit_recording("))
start = replay.index(" if (j->inits < 0) init_lost = true;")
end = replay.index(" if (res == VK_ERROR_DEVICE_LOST) device_lost();", start)
end += len(" if (res == VK_ERROR_DEVICE_LOST) device_lost();")
fixture = fixture.replace("/* SEGMENT */", replay[start:end])
cases = ["single", "grow", "reuse", "empty", "batch", "segments", "failed-segment", "allocation-failure"]
if a.case != "all":
assert a.case in cases
cases = [a.case]
with tempfile.TemporaryDirectory(prefix="draw-stream-visibility-") as temp:
cpp, exe = Path(temp) / "fixture.cpp", Path(temp) / "fixture.exe"
cpp.write_text(fixture, encoding="utf-8")
subprocess.run([a.cxx, "-std=c++20", "-O1", "-pthread", "-Wall", "-Wextra", "-Werror", "-Wno-missing-field-initializers",
"-I" + str(a.headers), "-I" + str(a.source / "gpu" / "vk"), str(cpp), "-o", str(exe)], check=True)
for cache in (["coherent", "noncoherent"] if a.cache == "all" else [a.cache]):
for case in cases:
subprocess.run([str(exe), case, cache], check=True, timeout=20)
if __name__ == "__main__":
main()