Files
Triforce-Source/tests/test_sampler_admission.py
ruckus7382sfgsgdf 4fa4f9188b 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.
2026-11-25 10:21:32 -06:00

93 lines
5.7 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")
# The samplers' section up to its first function: what owns the samplers made (the book, sampler_room and the rest)
head = source[source.index("// ---- samplers (by NVN sampler parameters) ----"):source.index("VkSamplerAddressMode wrap(")]
actual = head + "\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<SamplerInfo, Made, SamplerInfoHash> made", "FaultMap<SamplerInfo, Made, Owner, SamplerInfoHash> made"),
("std::unordered_map<uint64_t, Made*> keys", "FaultMap<uint64_t, Made*, Alias> keys"),
("std::vector<Retired> retired", "FaultVector<Retired, Retire> retired"),
("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",
"limit", "limit-full", "limit-reuse", "limit-alias-commit", "limit-retire-commit", "limit-held"]
failed = []
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:
r = subprocess.run([str(exe), route, case], timeout=20, capture_output=True, text=True)
if r.returncode:
last = (r.stderr.strip().splitlines() or ["exit %d" % r.returncode])[-1]
failed.append(f"{route} {case}: {last}")
for f in failed:
print("FAIL: " + f)
if failed:
raise SystemExit(f"{len(failed)} of {len(cases) * 3} sampler cache/admission/policy/limit cases failed")
print(f"{len(cases) * 3} sampler cache/admission/policy/limit cases passed")
if __name__ == "__main__":
main()