Files
Triforce-Source/tests/test_blended_motion.py
ruckus7382sfgsgdf b527e29adb Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
2026-11-28 10:54:41 -06:00

92 lines
4.3 KiB
Python

"""Draws blended over the scene keep the camera's motion for the temporal upscalers (gpu/vk/vk_draw.cpp own_motion and
push_capture; no game).
(2026-11-26) The owner's "white lines": thin white rings and trails round the fireflies of Kokiri Forest under AMD FSR 4,
caught with F8 and F9. The frame's steps were clean up to the scene's last particle draw and the rings were there right
after the upscaler. Every plain draw of triangles into the scene was given a motion of its own (capture_motion), blended
particles among them, so the upscaler moved what is behind each sprite as the sprite moved. A blended draw now gets no
capture slot (the camera's motion stays its motion, as reactive_policy.h has its pixels); RX_VK_DLSS_BLENDED_MOTION=1 gives
them one again, for comparing. This compiles own_motion, cut out as it is, against made-up states, and reads push_capture.
python -I -B tests/test_blended_motion.py [--cxx clang++]
"""
import argparse
import subprocess
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
VK = ROOT / "gpu" / "vk"
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
def check(ok, why):
if not ok:
raise SystemExit("FAIL: " + why)
def function(text, head):
start = text.index(head)
end = text.index("{", start) + 1
depth = 1
while depth:
depth += (text[end] == "{") - (text[end] == "}")
end += 1
return text[start:end]
PROGRAM = r"""
#include <atomic>
#include <cstdio>
#include <cstdlib>
#include <cstring>
struct NvnState { struct { unsigned blend_en = 0; } color; };
static int logged = 0;
static void logf(const char*, ...) { logged++; }
%(own)s
int main(int argc, char**) {
int fails = 0;
NvnState opaque, blended, other;
blended.color.blend_en = 1, other.color.blend_en = 2; // (target 1 blending, target 0 not: target 0 is the scene's)
if (argc > 1) { // (RX_VK_DLSS_BLENDED_MOTION=1 set by the caller: all of them, as before)
if (!own_motion(opaque) || !own_motion(blended) || logged) std::puts("FAIL: the switch does not give blended draws their own"), fails++;
return fails;
}
if (!own_motion(opaque)) std::puts("FAIL: an opaque draw has no motion of its own"), fails++;
if (own_motion(blended)) std::puts("FAIL: a draw blended over the scene has a motion of its own"), fails++;
if (!own_motion(other)) std::puts("FAIL: a draw blending only another target is taken for a blended one"), fails++;
own_motion(blended);
if (logged != 1) std::printf("FAIL: said %%d times, not once\n", logged), fails++;
return fails;
}
"""
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cxx", default="clang++")
args = parser.parse_args()
draw = (VK / "vk_draw.cpp").read_text(encoding="utf-8")
own = function(draw, "static bool own_motion(const NvnState& s) {")
cap = function(draw, "static void push_capture(")
check("if (capture && own_motion(s) && !d.mesh && !d.indirect" in cap, "push_capture gives blended draws a capture slot")
check("temporal_capture_draw(k, &slot);" in cap, "push_capture no longer asks for a slot")
check(draw.index("static bool own_motion(") < draw.index("static void push_capture("), "own_motion is not before push_capture")
guide = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
check("`RX_VK_DLSS_BLENDED_MOTION=1`" in guide, "docs/development.md has no row for RX_VK_DLSS_BLENDED_MOTION")
with tempfile.TemporaryDirectory(prefix="blended-motion-") as tmp:
src, exe = Path(tmp) / "own.cpp", Path(tmp) / "own.exe"
src.write_text(PROGRAM % {"own": own}, encoding="utf-8")
subprocess.run([args.cxx, "-std=c++20", "-O1", "-w", str(src), "-o", str(exe)], check=True)
env = {k: v for k, v in __import__("os").environ.items() if k != "RX_VK_DLSS_BLENDED_MOTION"}
r = subprocess.run([str(exe)], capture_output=True, text=True, env=env)
check(r.returncode == 0, "own_motion:\n" + r.stdout)
env["RX_VK_DLSS_BLENDED_MOTION"] = "1"
r = subprocess.run([str(exe), "switch"], capture_output=True, text=True, env=env)
check(r.returncode == 0, "own_motion with RX_VK_DLSS_BLENDED_MOTION=1:\n" + r.stdout)
print("PASS: draws blended over the scene keep the camera's motion; the switch gives them their own")
if __name__ == "__main__":
main()