Files
Triforce-Source/tests/test_sampler_admission.py
ruckus7382sfgsgdf 6c7117635c Triforce v0.6.0 "Sage Of Power"
Faster frames (the replay's memory work, held submits, helper threads, collection and capture cuts), the game letting old areas go (QueryMemoryInfo), the 0.5.2 stutter fixed, AMD RX 5000/6000 and integrated-GPU fixes, the GPU device chosen by name, the in-game menus and launcher reworked, controller, Linux and benchmark fixes.
2026-11-20 17:06:21 -06:00

79 lines
4.6 KiB
Python

"""Execute sampler creation and every handle-cache layer with authored failures."""
import argparse
from pathlib import Path
import re
import subprocess
import tempfile
RUN_ALL_ARGS = ["--cxx", "{cxx}", "--headers", "{vulkan_headers}"]
ROOT = Path(__file__).resolve().parents[1]
def block(source, marker):
start = source.index(marker)
end = source.index("{", start) + 1
depth = 1
while depth:
depth += (source[end] == "{") - (source[end] == "}")
end += 1
return source[start:end]
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("--sanitize", action="store_true")
a = p.parse_args()
source = (a.source / "gpu/vk/vk_draw.cpp").read_text(encoding="utf-8")
nvn = (a.source / "gpu/render/rx_nvn.h").read_text(encoding="utf-8")
actual = "\n".join(block(source, marker) for marker in [
"VkSamplerAddressMode wrap(", "uint32_t aniso_override() {", "VkCompareOp compare_op(",
"VkSampler sampler_make(int id, bool compare, bool scene) {", "VkSampler sampler_for(int id, bool compare, bool scene) {"])
# Keep standard-container behavior, replacing only the allocator to target an individual cache.
for old, new in [
("std::unordered_map<int, std::pair<uint32_t, nvn_samp_par>> seen", "FaultMap<int, std::pair<uint32_t, nvn_samp_par>, Seen> seen"),
("std::unordered_map<uint64_t, VkSampler> mine", "FaultMap<uint64_t, VkSampler, Mine> mine"),
("std::unordered_set<uint64_t> failed", "FaultSet<uint64_t, Failure> failed"),
]:
assert actual.count(old) == 1, old
actual = actual.replace(old, new)
start = nvn.rfind("typedef struct {", 0, nvn.index("} nvn_samp_par;"))
params = nvn[start:nvn.index("} nvn_samp_par;", start) + len("} nvn_samp_par;")]
symbols = sorted(set(re.findall(r"\bNVN_[A-Z0-9_]+", actual)))
enums = "enum { " + ", ".join(name + "=" + str(i + 1) for i, name in enumerate(symbols)) + " };"
fixture = (ROOT / "tests/sampler_admission_test.cpp").read_text(encoding="utf-8")
descriptors = block(source, "struct Pushed {") + ";\n" + "\n".join(block(source, marker) for marker in [
"void write_words(", "void words_append(", "int words_same_store(", "bool bind_descriptors("])
fixture = fixture.replace("/* DESCRIPTORS */", descriptors)
fixture = fixture.replace("/* PARAMS */", params).replace("/* ENUMS */", enums).replace("/* ACTUAL */", actual)
# ((Triforce, S8) sampler_make adds the upscaler's texture LOD bias by sharpen_rules.h's rule, in the scene's draws only:
# the real rule, the bias 0 here (no upscaler drawing) but in the scene cases, which set it)
fixture = fixture.replace("namespace fixture {", '#include "sharpen_rules.h"\nnamespace fixture {\n'
"namespace sharpen_rules = ::mkwvk::sharpen_rules;\n"
"std::atomic<float> upscale_lod_bias{0.0f};\n", 1)
cases = ["healthy", "host-oom", "device-oom", "unknown", "error-output", "generation-retry", "thread-retry",
"independent", "valid-after-failure", "owner-commit", "seen-commit", "mine-commit", "failure-commit",
"registration", "shared-thread", "concurrent", "nearest", "linear", "compare", "compare-explicit",
"compare-pcf-off", "custom-border", "standard-border", "reduction", "compare-reduction", "anisotropy", "anisotropy-clamped",
"unknown-id", "force-linear", "wrap", "lod-clamp", "custom-reduction",
"descriptor-push", "descriptor-pool", "descriptor-compute", "descriptor-old", "descriptor-whole",
"scene-bias", "scene-clamped", "scene-off"]
with tempfile.TemporaryDirectory(prefix="sampler-admission-") 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", "-Wall", "-Wextra", "-Werror", "-Wno-missing-field-initializers",
"-pthread", "-I" + str(a.headers), "-I" + str(a.source / "gpu/vk"),
*(["-fsanitize=address,undefined", "-fno-omit-frame-pointer", "-fno-pie", "-no-pie"] if a.sanitize else []),
str(cpp), "-o", str(exe)], check=True)
for route in ["id", "make", "cache-off"]:
for case in cases:
subprocess.run([str(exe), route, case], check=True, timeout=20)
print(f"{len(cases) * 3} sampler cache/admission/policy cases passed")
if __name__ == "__main__":
main()