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:
@@ -56,6 +56,8 @@ struct World {
|
||||
Texture textures[16];
|
||||
thread_local bool view_slot_known = true;
|
||||
thread_local bool upload_defer_ok = false;
|
||||
thread_local bool draw_may_defer = true; // ((Triforce, redrawn.h) set by vk_draw.cpp draw: may this draw leave textures)
|
||||
bool texture_owes(const Texture*) { return false; } // ((Triforce) no texture here still owes bytes)
|
||||
uint32_t texture_slot_version(int slot) { return w.version[(uint32_t)slot]; }
|
||||
uint64_t sampler_registrations_generation() { return w.samp; }
|
||||
uint64_t texture_destroy_generation() { return w.destroy; }
|
||||
@@ -64,7 +66,7 @@ uint32_t texture_epoch() { return (uint32_t)w.epoch; }
|
||||
uint64_t gpu_bind_stamp() { return w.stamp; }
|
||||
uint64_t ub_generation() { return w.ub; }
|
||||
VkImageView texture_view_of(uint32_t h, VkImageViewType vt, ViewUse use, VkFormat f, Texture** tex) {
|
||||
CHECK(use == ViewUse::Sample && f == VK_FORMAT_UNDEFINED && upload_defer_ok == (test != "compute"));
|
||||
CHECK(use == ViewUse::Sample && f == VK_FORMAT_UNDEFINED && upload_defer_ok == (test != "compute" && draw_may_defer));
|
||||
w.views++;
|
||||
const uint32_t slot = h & 0xFFFFF;
|
||||
view_slot_known = w.known;
|
||||
@@ -231,6 +233,24 @@ int run() {
|
||||
CHECK(tex_resolved(h, &a) && a.known && !a.view && !tex_resolved(h, &b) && a == b);
|
||||
return 0;
|
||||
}
|
||||
if (test == "texture-dummy-redrawn") { // ((Triforce, redrawn.h) a registered slot's kept dummy: taken by a draw that may
|
||||
// leave textures for later, looked up again by one that may not, so that its texture is made now)
|
||||
w.dummy_slot = true, w.known = true;
|
||||
Tex a, b;
|
||||
CHECK(tex_resolved(h, &a) && a.known && !a.view && !a.tex);
|
||||
CHECK(!tex_resolved(h, &b) && a == b); // (a draw into the scene: the kept dummy stands for the frame)
|
||||
draw_may_defer = false; // (a draw into a text box composed for the first time)
|
||||
CHECK(tex_resolved(h, &b) && a == b); // (looked up, not taken)
|
||||
CHECK(tex_resolved(h, &b)); // (again: never taken by such a draw)
|
||||
draw_may_defer = true;
|
||||
w.dummy_slot = false; // (the texture there now: a real view, which any draw may take)
|
||||
w.version[0x123]++;
|
||||
CHECK(tex_resolved(h, &a) && a.view);
|
||||
draw_may_defer = false;
|
||||
CHECK(!tex_resolved(h, &b) && a == b);
|
||||
draw_may_defer = true;
|
||||
return 0;
|
||||
}
|
||||
if (test == "texture-no-sampler") { // (a failed sampler is not kept: the draw is left out and the next one tries again)
|
||||
w.sampler_fail = true;
|
||||
CHECK(tex_resolved(h) && tex_resolved(h));
|
||||
|
||||
@@ -100,6 +100,8 @@ struct World {
|
||||
Texture textures[16];
|
||||
thread_local bool view_slot_known = true;
|
||||
thread_local bool upload_defer_ok = false;
|
||||
thread_local bool draw_may_defer = true; // ((Triforce, redrawn.h) set by vk_draw.cpp draw: may this draw leave textures)
|
||||
bool texture_owes(const Texture*) { return false; } // ((Triforce) no texture here still owes bytes)
|
||||
uint32_t texture_slot_version(int slot) { return w.version[(uint32_t)slot]; }
|
||||
uint64_t sampler_registrations_generation() { return w.samp; }
|
||||
uint64_t texture_destroy_generation() { return w.destroy; }
|
||||
|
||||
@@ -75,6 +75,9 @@ bool sampler_of(int id, nvn_samp_par* p) {
|
||||
if (policy == "standard-border") std::fill(std::begin(p->border), std::end(p->border), 1.0f);
|
||||
if (policy == "reduction" || policy == "compare-reduction" || policy == "custom-reduction") p->reduction = 1;
|
||||
if (policy == "wrap") p->ws = NVN_WRAP_MODE_REPEAT, p->wt = NVN_WRAP_MODE_MIRRORED_REPEAT, p->wr = NVN_WRAP_MODE_CLAMP_TO_BORDER;
|
||||
// ((Triforce, 11-18) anisotropy is raised only on samplers whose U and V repeat (EstebanGGM's aniso_tiled): a tiled one, and
|
||||
// a clamped one that stays as the game has it)
|
||||
if (policy == "anisotropy") p->ws = NVN_WRAP_MODE_REPEAT, p->wt = NVN_WRAP_MODE_MIRRORED_REPEAT;
|
||||
if (policy == "lod-clamp") p->lod_bias = 100, p->lod_min = -3, p->lod_max = -1;
|
||||
return true;
|
||||
}
|
||||
@@ -83,7 +86,7 @@ const char* getenv(const char* name) {
|
||||
if (!std::strcmp(name, "RX_VK_PUSH_ALL") && descriptor_policy == "descriptor-whole") return "1";
|
||||
if (!std::strcmp(name, "RX_VK_SAMPLER_CACHE") && cache_off) return "0";
|
||||
if (!std::strcmp(name, "RX_VK_SHADOW_PCF") && policy == "compare-pcf-off") return "0";
|
||||
if (!std::strcmp(name, "RX_VK_ANISO") && policy == "anisotropy") return "16";
|
||||
if (!std::strcmp(name, "RX_VK_ANISO") && (policy == "anisotropy" || policy == "anisotropy-clamped")) return "16";
|
||||
if (!std::strcmp(name, "RX_VK_FORCE_LINEAR") && policy == "force-linear") return "1";
|
||||
return nullptr;
|
||||
}
|
||||
@@ -290,6 +293,7 @@ void run(const std::string& test) {
|
||||
if (test == "reduction" || test == "custom-reduction") assert(saved.reduced && saved.reduction == VK_SAMPLER_REDUCTION_MODE_MIN);
|
||||
if (test == "compare-reduction") assert(!saved.reduced);
|
||||
if (test == "anisotropy") assert(ci.anisotropyEnable && ci.maxAnisotropy == 8);
|
||||
if (test == "anisotropy-clamped") assert(!ci.anisotropyEnable);
|
||||
}
|
||||
} // namespace fixture
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
168
tests/setup_tools_parts_test.cs
Normal file
168
tests/setup_tools_parts_test.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
// tests/test_setup_tools_parts.py: setup/Setup.cs's Tools (cut out of it, the production code) with the tools in two parts:
|
||||
// the base list read, a base held checked, the tools made again from the code part and the base kept or fetched, and every
|
||||
// failure leaving the tools that were there whole. Authored files in a temporary folder; no Setup runs, nothing is fetched.
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TriforceSetup;
|
||||
|
||||
// (stand-in for Setup.cs's Install: everything is allowed here, the tools go beside the test folder)
|
||||
static class Install
|
||||
{
|
||||
public static string? InstalledDir = null, TestRoot = null;
|
||||
public static string SelfDir = "";
|
||||
public static string TestOnly => "a test run";
|
||||
public static bool Allowed(string dir) => true;
|
||||
}
|
||||
|
||||
static class PartsTest
|
||||
{
|
||||
static int checks;
|
||||
static void Check(bool ok, string what)
|
||||
{
|
||||
if (!ok) throw new Exception(what);
|
||||
checks++;
|
||||
}
|
||||
static T? Throws<T>(Action a) where T : Exception
|
||||
{
|
||||
try { a(); } catch (T e) { return e; }
|
||||
return null;
|
||||
}
|
||||
static void Put(string file, string text)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
|
||||
File.WriteAllText(file, text);
|
||||
}
|
||||
static string Sha(string text) => Sha(Encoding.UTF8.GetBytes(text));
|
||||
static string Sha(byte[] b)
|
||||
{
|
||||
using var s = System.Security.Cryptography.SHA256.Create();
|
||||
return string.Concat(s.ComputeHash(b).Select(x => x.ToString("x2")));
|
||||
}
|
||||
// (the base's files, as setup/pack_tools.ps1 lists them)
|
||||
static readonly (string Path, string Text)[] BaseFiles =
|
||||
{
|
||||
("llvm-mingw/bin/clang.exe", "the compiler"), ("llvm-mingw/lib/libc.a", "its library"),
|
||||
("python/python.exe", "the python"), ("python/Lib/os.py", "a module"),
|
||||
};
|
||||
static string List((string Path, string Text)[] files, string? header = null)
|
||||
{
|
||||
var rows = files.Select(f => "file\t" + Encoding.UTF8.GetByteCount(f.Text) + "\t" + Sha(f.Text) + "\t" + f.Path)
|
||||
.OrderBy(x => x, StringComparer.Ordinal);
|
||||
var body = string.Join("\n", new[] { "dir\tllvm-mingw", "dir\tpython" }.Concat(rows)) + "\n";
|
||||
return (header ?? "triforce-tools-base\t1") + "\nid\t" + Sha(body) + "\n" + body;
|
||||
}
|
||||
static void Zip(string file, params (string Name, string Text)[] entries)
|
||||
{
|
||||
if (File.Exists(file)) File.Delete(file);
|
||||
using var z = ZipFile.Open(file, ZipArchiveMode.Create);
|
||||
foreach (var (name, text) in entries)
|
||||
{
|
||||
using var w = new StreamWriter(z.CreateEntry(name).Open());
|
||||
w.Write(text);
|
||||
}
|
||||
}
|
||||
static string Read(string file) => File.Exists(file) ? File.ReadAllText(file) : "";
|
||||
|
||||
static int Main()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "triforce-parts-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(root);
|
||||
try
|
||||
{
|
||||
Install.SelfDir = Path.Combine(root, "setup");
|
||||
var tools = Tools.Folder;
|
||||
var list = List(BaseFiles);
|
||||
|
||||
// ---- the list: read as written, refused when it is not one
|
||||
var b = Tools.ParseBaseList(list);
|
||||
Check(b != null && b.Dirs.SequenceEqual(new[] { "llvm-mingw", "python" }) && b.Files.Count == 4 && b.Id.Length == 64, "the base list was not read");
|
||||
Check(Tools.ParseBaseList(List(BaseFiles, "triforce-tools-base\t2")) == null, "a list of another format was taken");
|
||||
Check(Tools.ParseBaseList(List(new[] { ("../outside.txt", "x") })) == null, "a list with a path out of the folder was taken");
|
||||
Check(Tools.ParseBaseList(list + "something\telse\n") == null, "a list with a line it does not know was taken");
|
||||
|
||||
// ---- tools there now: v1 with the base
|
||||
void Tools1()
|
||||
{
|
||||
if (Directory.Exists(tools)) Directory.Delete(tools, true);
|
||||
foreach (var (p, t) in BaseFiles) Put(Path.Combine(tools, p), t);
|
||||
Put(Path.Combine(tools, "nx2", "make_game.py"), "v1 builder");
|
||||
Put(Path.Combine(tools, "nx2", "old_only.py"), "gone in v2");
|
||||
Put(Path.Combine(tools, "version.txt"), "v1\n");
|
||||
}
|
||||
Tools1();
|
||||
Check(Tools.HasBase(b!, tools, _ => { }), "the base there was not taken for the list's");
|
||||
Check(Read(Path.Combine(tools, Tools.BaseHave)).Trim() == b!.Id, "a base read whole was not remembered (base.have)");
|
||||
Check(Tools.HasBase(b, tools, _ => throw new Exception("read again")), "a remembered base was read again");
|
||||
File.WriteAllText(Path.Combine(tools, "python", "python.exe"), "the pythoX"); // (same size, other bytes)
|
||||
File.Delete(Path.Combine(tools, Tools.BaseHave));
|
||||
Check(!Tools.HasBase(b, tools, _ => { }), "a base file with other bytes was taken");
|
||||
Tools1();
|
||||
File.WriteAllText(Path.Combine(tools, "python", "python.exe"), "longer than it was");
|
||||
Check(!Tools.HasBase(b, tools, _ => { }), "a base file of another size was taken");
|
||||
Tools1();
|
||||
File.Delete(Path.Combine(tools, "llvm-mingw", "lib", "libc.a"));
|
||||
Check(!Tools.HasBase(b, tools, _ => { }), "a base with a file gone was taken");
|
||||
|
||||
// ---- the code part alone, the base kept: v2's code, v1's base moved over, v1's other files gone
|
||||
Tools1();
|
||||
Put(Path.Combine(tools, "python", "Lib", "__pycache__", "os.pyc"), "made by a run"); // (a file the list does not name)
|
||||
var code = Path.Combine(root, "code.zip");
|
||||
Zip(code, ("tools/nx2/make_game.py", "v2 builder"), ("tools/gpu/new.cpp", "v2 renderer"), ("tools/base.list", list), ("tools/version.txt", "v2\n"));
|
||||
Check(Tools.BaseListIn(code)?.Id == b.Id, "the code part's base list was not read");
|
||||
Tools.UnpackParts(code, null, b, "v2", _ => { });
|
||||
Check(Tools.InstalledVersion == "v2" && Read(Path.Combine(tools, "nx2", "make_game.py")) == "v2 builder" &&
|
||||
Read(Path.Combine(tools, "gpu", "new.cpp")) == "v2 renderer", "the code part was not unpacked");
|
||||
Check(!File.Exists(Path.Combine(tools, "nx2", "old_only.py")), "a file of the old code stayed");
|
||||
Check(BaseFiles.All(f => Read(Path.Combine(tools, f.Path)) == f.Text) && File.Exists(Path.Combine(tools, "python", "Lib", "__pycache__", "os.pyc")),
|
||||
"the base was not kept whole");
|
||||
Check(Read(Path.Combine(tools, Tools.BaseHave)).Trim() == b.Id && !Directory.Exists(tools + ".part") && !Directory.Exists(tools + ".old"),
|
||||
"the new tools do not remember their base, or a partial or old folder was left");
|
||||
|
||||
// ---- the base fetched: tools whose base is another
|
||||
Tools1();
|
||||
File.WriteAllText(Path.Combine(tools, "python", "python.exe"), "an older python");
|
||||
var baseZip = Path.Combine(root, "base.zip");
|
||||
Zip(baseZip, BaseFiles.Select(f => ("tools/" + f.Path, f.Text)).ToArray());
|
||||
Tools.UnpackParts(code, baseZip, b, "v2", _ => { });
|
||||
Check(Tools.InstalledVersion == "v2" && Read(Path.Combine(tools, "python", "python.exe")) == "the python", "the fetched base was not unpacked");
|
||||
|
||||
// ---- failures leave the tools that were there
|
||||
Tools1();
|
||||
var bad = Path.Combine(root, "bad.zip");
|
||||
Zip(bad, ("tools/nx2/make_game.py", "v3"), ("tools/con.txt", "a device's name"));
|
||||
Check(Throws<InvalidDataException>(() => Tools.UnpackParts(bad, null, b, "v3", _ => { })) != null, "a code part with a device's name was unpacked");
|
||||
Check(Tools.InstalledVersion == "v1" && BaseFiles.All(f => Read(Path.Combine(tools, f.Path)) == f.Text) && !Directory.Exists(tools + ".part"),
|
||||
"a refused code part changed the tools");
|
||||
// (the base moved over, then found short of a file the list names: the base folders go back)
|
||||
var longer = Tools.ParseBaseList(List(BaseFiles.Concat(new[] { ("python/missing.py", "not there") }).ToArray()))!;
|
||||
Check(Throws<InvalidDataException>(() => Tools.UnpackParts(code, null, longer, "v2", _ => { })) != null, "a base short of a listed file was taken");
|
||||
Check(Tools.InstalledVersion == "v1" && BaseFiles.All(f => Read(Path.Combine(tools, f.Path)) == f.Text) &&
|
||||
Read(Path.Combine(tools, "nx2", "make_game.py")) == "v1 builder" && !Directory.Exists(tools + ".part"),
|
||||
"the base folders moved over did not go back after a failure");
|
||||
|
||||
// ---- the whole zip (a first install, an older release's way): the base it unpacks is remembered
|
||||
if (Directory.Exists(tools)) Directory.Delete(tools, true);
|
||||
var whole = Path.Combine(root, "whole.zip");
|
||||
Zip(whole, BaseFiles.Select(f => ("tools/" + f.Path, f.Text)).Concat(new[] { ("tools/nx2/make_game.py", "v2 builder"), ("tools/base.list", list) }).ToArray());
|
||||
Tools.Unpack(whole, "v2", _ => { });
|
||||
Check(Read(Path.Combine(tools, Tools.BaseHave)).Trim() == b.Id, "the whole zip's base was not remembered");
|
||||
Check(Tools.HasBase(b, tools, _ => throw new Exception("read again")), "the whole zip's base was read again at the next update");
|
||||
|
||||
Console.WriteLine("PASS: " + checks + " checks: the tools in parts, the base kept or fetched, failures leave the tools there");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("FAIL: " + e.Message);
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { Directory.Delete(root, true); } catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
60
tests/test_amd_older_fixes.py
Normal file
60
tests/test_amd_older_fixes.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""(Triforce, 11-18) EstebanGGM's RX 580 fixes, ported from NX2navi, as this branch takes them: the source's rules.
|
||||
|
||||
- vk_main.cpp: alpha to coverage leaves the dynamic state only on AMD's older compiler where the driver has no fast-linking
|
||||
pipeline libraries (the RX 580's), so fast pipeline link (gpl_wanted, which needs the dynamic state) is never turned off
|
||||
by it; RX_VK_DYN_A2C decides outright.
|
||||
- vk_texture.cpp: on AMD only a cubemap's image is made cube compatible (RX_VK_CUBE_ONLY decides outright).
|
||||
- vk_shader.cpp: the water/shadow PCF rewrite is outside the translation stamp, on by default only on the same cards.
|
||||
usage: python -I -B tests/test_amd_older_fixes.py"""
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
|
||||
|
||||
def between(text, start, end):
|
||||
a = text.index(start)
|
||||
return text[a:text.index(end, a)]
|
||||
|
||||
|
||||
def main():
|
||||
main_cpp = (VK / "vk_main.cpp").read_text(encoding="utf-8")
|
||||
a2c = between(main_cpp, "const bool eds3_a2c = dev.dynamic_state3", "dev.vk12 = f12;")
|
||||
if "bool want = !(amd_older && !dev.graphics_pipeline_library);" not in a2c:
|
||||
raise SystemExit("alpha to coverage leaves the dynamic state on more than AMD's older compiler without pipeline libraries")
|
||||
if 'getenv("RX_VK_DYN_A2C")' not in a2c or "dev.eds3_a2c = eds3_a2c && want;" not in a2c:
|
||||
raise SystemExit("RX_VK_DYN_A2C does not decide the dynamic alpha to coverage")
|
||||
gpl_at = main_cpp.index("dev.graphics_pipeline_library = dev.graphics_pipeline_library && gpl.graphicsPipelineLibrary;")
|
||||
if gpl_at > main_cpp.index("bool want = !(amd_older && !dev.graphics_pipeline_library);"):
|
||||
raise SystemExit("the alpha to coverage rule reads the pipeline libraries before they are known")
|
||||
draw = (VK / "vk_draw.cpp").read_text(encoding="utf-8")
|
||||
if "dev.eds3_a2c &&" not in between(draw, "bool gpl_wanted() {", "\n}\n"):
|
||||
raise SystemExit("fast pipeline link no longer needs the dynamic alpha to coverage: revisit the rule above")
|
||||
|
||||
tex = (VK / "vk_texture.cpp").read_text(encoding="utf-8")
|
||||
cube = between(tex, 'static const int cube_env = getenv("RX_VK_CUBE_ONLY")', "flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, x.cube = true;")
|
||||
if "cube_env >= 0 ? cube_env != 0 : dev.props.vendorID == 0x1002" not in cube:
|
||||
raise SystemExit("the cube-only rule is not AMD's by default")
|
||||
if "(!cube_only || cube_target)" not in cube or "NVN_TEXTURE_TARGET_CUBEMAP_ARRAY" not in cube:
|
||||
raise SystemExit("a non-cube 2D array is still made cube compatible where the rule applies")
|
||||
if "if (!tex->cube) return VK_NULL_HANDLE;" not in tex:
|
||||
raise SystemExit("a cube view of an image without the flag is no longer refused")
|
||||
|
||||
shader = (VK / "vk_shader.cpp").read_text(encoding="utf-8")
|
||||
out_at = shader.index("// ---- (Triforce) Outside the translation stamp, to the next mark")
|
||||
simplify_at = shader.index("bool spirv_water_simplify(")
|
||||
back_in = shader.index("// ---- (Triforce) Inside the translation stamp again", out_at)
|
||||
if not out_at < simplify_at < back_in:
|
||||
raise SystemExit("the water rewrite is inside the translation stamp: every player's caches would start again")
|
||||
if "return dev.fixes.nan_bits && !dev.graphics_pipeline_library ? 1 : 0;" not in between(shader, "int water_quality_mode() {", "\n}\n"):
|
||||
raise SystemExit("the water rewrite is on by default on more cards than the alpha to coverage rule")
|
||||
mm = between(shader, "VkShaderModule make_module(", "\n}\n")
|
||||
if not re.search(r"spirv_water_simplify\(spirv, water_quality_mode\(\), simplified\)", mm):
|
||||
raise SystemExit("make_module does not ask the water rewrite")
|
||||
print("PASS: the RX 580 fixes' rules (alpha to coverage, cube images, water PCF) as this branch takes them")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -36,7 +36,8 @@ def main():
|
||||
rearm = next(line.strip() for line in present.splitlines() if "pending = {true, value, presents" in line)
|
||||
read_at = present.index("auto take = [&]")
|
||||
read = present[read_at:present.index("// (RX_VK_DUMP_BLACK", read_at)]
|
||||
copy_at, submit_at, consume_at = present.index(copy), present.index("submit_recording(r);"), present.index(consume)
|
||||
# (the present's submit may name its timeline signal: submit_recording(r, signal, at); the fixture's stub takes r alone)
|
||||
copy_at, submit_at, consume_at = present.index(copy), present.index("submit_recording(r"), present.index(consume)
|
||||
assert copy_at < submit_at < read_at < consume_at
|
||||
state = "struct PendingShot { bool on=false; uint64_t value=0; int64_t presents=0; std::shared_ptr<std::vector<uint8_t>> pixels{}; };"
|
||||
helper = ""
|
||||
|
||||
@@ -38,7 +38,7 @@ def main():
|
||||
readme = (ROOT / "readme.md").read_text(encoding="utf-8")
|
||||
|
||||
# the rows: tools of the Debug tab (shown with Debug tools on), with no value of the options file
|
||||
rows = menu[menu.index("Row rows[] = {") if "Row rows[] = {" in menu else menu.index("{TAB_DISPLAY,"):menu.index("constexpr int kQuitRow")]
|
||||
rows = menu[menu.index("Row rows[] = {") if "Row rows[] = {" in menu else menu.index("{TAB_DISPLAY,"):menu.index("constexpr int kRowsEnd")]
|
||||
for name, tool in (("Game flags", 11), ("Cutscenes", 12), ("Scan amiibo", 13)):
|
||||
found = re.findall(r'\{(TAB_\w+), "%s", nullptr, 0, 0, 0, nullptr,\s*(?:"[^\n]*"\s*)+, nullptr, false, true, (\d+)\},' % name, rows)
|
||||
check(found == [("TAB_DEBUG", str(tool))], "the row %s is not one tool (%d) of the Debug tab: %s" % (name, tool, found))
|
||||
|
||||
@@ -27,7 +27,7 @@ from pathlib import Path
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}", "--headers", "{vulkan_headers}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CASES = ["header", "on", "off", "no-reuse", "sampler-cache-off", "late-defer", "texture", "compute", "texture-moved", "texture-dummy",
|
||||
CASES = ["header", "on", "off", "no-reuse", "sampler-cache-off", "late-defer", "texture", "compute", "texture-moved", "texture-dummy", "texture-dummy-redrawn",
|
||||
"texture-no-sampler", "uniform", "uniform-stream", "uniform-moved", "c1", "storage", "check", "check-bad"]
|
||||
|
||||
|
||||
|
||||
@@ -86,7 +86,8 @@ def check_source(source):
|
||||
need("const bool sig_hit = sig_walked && last_desc_valid && last_desc_prog == &p && pushed()[0].cmd == cmd &&\n"
|
||||
" pushed()[0].layout == p.layout && desc_sig::hit(sig_bound(), sig, &p);" in draw,
|
||||
"a hit does not need the last draw's program and its push at the bind point", fails)
|
||||
need("const int sig_mode = !same_gens && !no_reuse ? desc_sig_mode() : 0;" in draw, "the walk runs where the draw keeps them anyway",
|
||||
need("const int sig_mode = !same_gens && !no_reuse && !strict ? desc_sig_mode() : 0;" in draw,
|
||||
"the walk runs where the draw keeps them anyway (or a draw that may not defer in a frame that left textures: redrawn.h)",
|
||||
fails)
|
||||
need("const bool same_desc = same_gens || (sig_hit && sig_mode == 1);" in draw, "a checked hit is not built", fails)
|
||||
build = draw[draw.index("if (!same_desc) {"):]
|
||||
|
||||
@@ -103,6 +103,33 @@ class FrameWholeTests(unittest.TestCase):
|
||||
hot = LIFTED[0].replace(old0, " _v=a64_fpx_hot_mul32_fma32(c,_a,_b,_z);\n a64_vset64(c->vreg[0],_v);}\n" + old0)
|
||||
self.assertEqual(oot_patches.patch_whole_frames(hot)[1], 1)
|
||||
|
||||
def test_battle_steps_patch_their_two_cuts(self):
|
||||
# ((Triforce, 11-18) Link's two state steps in f_804caa80: each found by its page constant, the constant's load and the
|
||||
# cut; other cuts of the same text in the function stay the game's, a negative amount keeps the game's cut)
|
||||
P = oot_patches
|
||||
mul = (" {uint64_t _a=0,_b=0,_z,_v;memcpy(&_a,c->vreg[0],4);memcpy(&_b,c->vreg[1],4);_z=(_a^_b)&0x80000000ULL;\n"
|
||||
" _v=a64_fpx_mul32_fma32(c,_a,_b,_z);\n a64_vset64(c->vreg[0],_v);}\n")
|
||||
site = lambda anchor, extra="": (anchor + " c->x[10] = 0x8ULL;\n c->x[10] &= 0xFFFFFFFFULL;\n" + extra
|
||||
+ P.BATTLE_LOAD + mul + P.BATTLE_CUT + " c->x[9]=c->x[8];\n")
|
||||
lifted = ('#include "a64.h"\n' + P.BATTLE_HEAD + P.BATTLE_CUT + site(P.BATTLE_SITES[0][0])
|
||||
+ site(P.BATTLE_SITES[1][0], " c->x[11] = 0x20ULL;\n c->x[11] &= 0xFFFFFFFFULL;\n")
|
||||
+ "return;\n}\nvoid f_804cfb00(Ctx *__restrict A64_NOESC c) {\n" + P.BATTLE_CUT + "return;\n}\n")
|
||||
out, n = P.patch_battle_steps(lifted)
|
||||
self.assertEqual(n, 2)
|
||||
self.assertEqual(out.count(P.BATTLE_MARK), 2)
|
||||
self.assertIn("hos_frame_whole(c->x[19] + 145, (uint32_t)c->vreg[0][0])", out)
|
||||
self.assertIn("hos_frame_whole(c->x[19] + 147, (uint32_t)c->vreg[0][0])", out)
|
||||
self.assertIn("((int32_t)(uint32_t)c->vreg[0][0] > 0)", out) # (a negative amount: the game's cut)
|
||||
self.assertEqual(out.count(P.BATTLE_CUT), 2) # (the function's other cut and the next function's stay)
|
||||
self.assertIn(P.WHOLE_DECL, out)
|
||||
self.assertEqual(P.patch_battle_steps(out), (out, 2)) # (patched before: as it is)
|
||||
hot = lifted.replace("a64_fpx_mul32_fma32", "a64_fpx_hot_mul32_fma32")
|
||||
self.assertEqual(P.patch_battle_steps(hot)[1], 2)
|
||||
other = lifted.replace("+2952ULL", "+2956ULL") # (another game version's code)
|
||||
self.assertEqual(P.patch_battle_steps(other), (other, 0))
|
||||
twice = lifted.replace(site(P.BATTLE_SITES[0][0]), site(P.BATTLE_SITES[0][0]) * 2)
|
||||
self.assertEqual(P.patch_battle_steps(twice)[1], 1) # (a place found twice is left as it is)
|
||||
|
||||
def test_clock_patches_its_seconds_alone(self):
|
||||
# (f_803edf70 cuts into x8 the same way once more, in the branch that sets the time from another source: that cut
|
||||
# stays the game's)
|
||||
|
||||
@@ -59,6 +59,13 @@ def main():
|
||||
raise SystemExit("behind another window the pads are never read")
|
||||
if "key(" in behind or "mouse" in behind:
|
||||
raise SystemExit("behind another window the keyboard or mouse would reach the game")
|
||||
# ((Triforce, 11-18) the Insert menu reads the pads in the background as the game does, and while it is open there the
|
||||
# pads are its own, not the game's too)
|
||||
if "if (!rx_option(1, 0)) {" not in behind or "*buttons |= pb;" not in behind:
|
||||
raise SystemExit("behind another window the pads reach the game while the Insert menu is open")
|
||||
if "const bool pads_ok = mine || (pad_bg_env ? atoi(pad_bg_env) != 0 : opts.pad_background != 0);" not in menu or \
|
||||
"const uint32_t raw = pads_ok && host && host->pad_raw ? host->pad_raw() : 0" not in menu:
|
||||
raise SystemExit("the Insert menu takes the pads only from the window in front, while the game takes them behind it")
|
||||
option = replay[replay.index("t.option = "):]
|
||||
option = option[:option.index("};") + 2]
|
||||
if "id == 4 ? opts.pad_background" not in option:
|
||||
|
||||
@@ -70,6 +70,26 @@ def main():
|
||||
return real_open(path, *a, **k)
|
||||
with mock.patch("builtins.open", host_edited):
|
||||
check("other host/ code does not change the key", make_game.lift_key(str(exefs), str(work), env) == key)
|
||||
# ((Triforce) the chunk boundaries a lift writes into a work folder that had none (nx2/chunks.py save): the key kept
|
||||
# for that lift is the one the next build takes, so the next build skips the lift)
|
||||
unchunked = make_game.lift_key(str(exefs), str(work), env, chunks=False)
|
||||
check("chunks=False leaves the boundaries out", unchunked != key and unchunked ==
|
||||
make_game.lift_key(str(exefs), str(work), env, chunks=False))
|
||||
(work / "image" / "chunks.txt").unlink()
|
||||
fresh = make_game.lift_key(str(exefs), str(work), env)
|
||||
before = make_game.lift_key(str(exefs), str(work), env, chunks=False)
|
||||
check("without chunks.txt the key is the one without boundaries", fresh == before == unchunked)
|
||||
(work / "image" / "chunks.txt").write_text("# first guest address of each lifted C chunk after the first\n80001000\n")
|
||||
after = make_game.key_after_lift(str(exefs), str(work), env, fresh, before, False)
|
||||
check("the key kept for a lift that wrote chunks.txt is the next build's", after != fresh and
|
||||
after == make_game.lift_key(str(exefs), str(work), env))
|
||||
check("boundaries copied in from the source keep the key from before the lift",
|
||||
make_game.key_after_lift(str(exefs), str(work), env, fresh, before, True) == fresh)
|
||||
(work / "hot_funcs.txt").write_text("f_80000008\n")
|
||||
check("tools or inputs changed during the lift keep the key from before it",
|
||||
make_game.key_after_lift(str(exefs), str(work), env, fresh, before, False) == fresh)
|
||||
(work / "hot_funcs.txt").write_text("f_80000000\n")
|
||||
(work / "image" / "chunks.txt").write_text("80001000\n")
|
||||
|
||||
gen, image = work / "sa" / "gen", work / "sa" / "image"
|
||||
check("no lift yet: not lifted before", not make_game.lifted_before(str(work), key))
|
||||
|
||||
@@ -179,6 +179,19 @@ class FakeVar:
|
||||
self.value = value
|
||||
|
||||
|
||||
class SetupUpdateKeepsDlssTests(unittest.TestCase):
|
||||
"""(Triforce, 11-18, #bug-tracker "Update & merge removes NVIDIA DLSS") Setup's Run: an update of a folder built with DLSS
|
||||
(its ngx/nvngx_dlss.dll) runs with the NGX flags whatever the stored choice, and stores the choice again; the flags follow"""
|
||||
def test_update_of_a_dlss_folder_keeps_it(self):
|
||||
shell = (ROOT / "setup" / "Shell.cs").read_text(encoding="utf-8")
|
||||
run = shell[shell.index(" void Run(Tools tools, List<string> args, bool keepRows = false)"):]
|
||||
run = run[:run.index("\n }\n")]
|
||||
self.assertIn('args.IndexOf("--update")', run)
|
||||
self.assertIn('File.Exists(System.IO.Path.Combine(updated, "ngx", "nvngx_dlss.dll"))', run)
|
||||
self.assertIn('Install.Set("Dlss", "1");', run)
|
||||
self.assertLess(run.index('"nvngx_dlss.dll"'), run.index('args.AddRange(new[] { "--fetch-ngx-sdk", "--accept-nvidia-license" })'))
|
||||
|
||||
|
||||
class LinuxBuilderDlssTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.builder = load_linux_builder()
|
||||
|
||||
@@ -209,6 +209,14 @@ int main() {
|
||||
CHECK(keep_all_pipelines(32 * GB, 20 * GB, 2 * GB) && !keep_all_pipelines(32 * GB, 13 * GB, 5 * GB));
|
||||
CHECK(!keep_all_pipelines(16 * GB, 30 * GB, 0) && keep_all_pipelines(64 * GB, 40 * GB, 1 * GB));
|
||||
CHECK(!keep_all_pipelines(32 * GB, 18455 * MB, 1 * GB)); // (v0.4.0-test9's start)
|
||||
// (11-18: the pipeline cache's read is not the game's room, but on AMD's driver. Panda: 18165 MB available, 7048 held, the
|
||||
// read 4747; Swampy: 19121, 7696, 4874. Both were kept and ran short; without the read neither is)
|
||||
CHECK(own_for_keep(7048 * MB, 4747 * MB, false) == 2301 * MB && own_for_keep(7048 * MB, 4747 * MB, true) == 7048 * MB);
|
||||
CHECK(own_for_keep(1 * GB, 2 * GB, false) == 0 && own_for_keep(3 * GB, 0, false) == 3 * GB);
|
||||
CHECK(keep_all_pipelines(32 * GB, 18165 * MB, 7048 * MB) && !keep_all_pipelines(32 * GB, 18165 * MB, own_for_keep(7048 * MB, 4747 * MB, false)));
|
||||
CHECK(keep_all_pipelines(32 * GB, 19121 * MB, 7696 * MB) && !keep_all_pipelines(32 * GB, 19121 * MB, own_for_keep(7696 * MB, 4874 * MB, false)));
|
||||
CHECK(keep_all_pipelines(32 * GB, 19121 * MB, own_for_keep(7696 * MB, 4874 * MB, true))); // (AMD: as before)
|
||||
CHECK(keep_all_pipelines(64 * GB, 40 * GB, own_for_keep(6 * GB, 5 * GB, false))); // (a 64 GB PC keeps all still)
|
||||
// (the RAM's rules)
|
||||
CHECK(short_now(1535 * MB) && !short_now(1536 * MB) && short_now(0));
|
||||
CHECK(low_now(3 * GB - 1, 16 * GB) && !low_now(3 * GB, 16 * GB) && !low_now(3 * GB, 30 * GB));
|
||||
@@ -254,8 +262,13 @@ def check_source():
|
||||
if "if (guest.empty() || lines++ % 8 == 0) {" not in parts or "glo, ghi, &c->other_regions" not in parts:
|
||||
raise SystemExit("the guest window is walked at every line, or the rest's walk does not step over it")
|
||||
keep = between(draw, "bool precompile_keeps_all() {", "\n}\n")
|
||||
if "mem_parts::keep_all_pipelines(ms.ullTotalPhys, ms.ullAvailPhys, ws)" not in keep:
|
||||
if "mem_parts::keep_all_pipelines(ms.ullTotalPhys, ms.ullAvailPhys, own)" not in keep:
|
||||
raise SystemExit("the precompile's keep goes by the PC's total RAM, not the RAM the game can have")
|
||||
if "mem_parts::own_for_keep(ws, cache_read, amd)" not in keep or "pcache_read_ws.load()" not in keep:
|
||||
raise SystemExit("the precompile's keep counts the pipeline cache's read as room for the pipelines")
|
||||
init = between(draw, "void pcache_init() {", "\n}\n")
|
||||
if "pcache_read_ws = ws1 > ws0 ? ws1 - ws0 : 0;" not in init:
|
||||
raise SystemExit("pcache_init does not record what the cache's read added to the working set")
|
||||
save = between(draw, "void pipeline_cache_save(bool force) {", "\n}\n")
|
||||
if "if (!force && !memory_ram_fits(n)) {" not in save or save.index("memory_ram_fits(n)") > save.index("std::vector<uint8_t> data(n);"):
|
||||
raise SystemExit("the save in play fetches the cache before it asks whether a copy fits in the RAM")
|
||||
|
||||
@@ -161,11 +161,19 @@ def main():
|
||||
if "mesh_fallback_task_threads" not in block(get_set, "Id EmitWorkgroupId(EmitContext& ctx)"):
|
||||
raise SystemExit("a fallback mesh workgroup's id is its slot, not its index in its task")
|
||||
# (the records' header is reset after a barrier: the shared pair's last draw, of any program, has read it)
|
||||
reset = record[record.index("end_pass(cmd);"):record.index("vkCmdFillBuffer(cmd, f->records")]
|
||||
# ((Triforce, 11-18) one 32-byte update of the header now, not four fills: EstebanGGM's)
|
||||
reset = record[record.index("end_pass(cmd);"):record.index("vkCmdUpdateBuffer(cmd, f->records, 0, sizeof hdr, hdr);")]
|
||||
if "full_barrier(cmd);" not in reset:
|
||||
raise SystemExit("a fallback draw resets the shared records before the last draw has read them")
|
||||
if "vkCmdFillBuffer(cmd, f->records, 4, 4, 1);" not in record:
|
||||
raise SystemExit("the draw's instance count is not set to one")
|
||||
if "const uint32_t hdr[8] = {0u, 1u, 0u, 0u, 0u, 0u, 1u, 1u};" not in record:
|
||||
raise SystemExit("the draw's instance count is not set to one, or the mesh dispatch's y and z")
|
||||
after = record[record.index("vkCmdUpdateBuffer(cmd, f->records, 0, sizeof hdr, hdr);"):]
|
||||
if "fb_barrier(VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT);" \
|
||||
not in after[:400]:
|
||||
raise SystemExit("the task and the mesh dispatch read the header before its update is done")
|
||||
if not record.rstrip().endswith("full_barrier(cmd); // (the records and the draw's command, which the draw reads as indirect arguments)\n return true;") \
|
||||
and "full_barrier(cmd); // (the records and the draw's command, which the draw reads as indirect arguments)" not in record:
|
||||
raise SystemExit("the draw reads its records before the mesh stage wrote them")
|
||||
if "VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT" not in block(draw, "bool fallback_buffers_of(const Program& p, FallbackBuffers*& out) {"):
|
||||
raise SystemExit("the records buffer cannot be read as indirect arguments")
|
||||
# (every fallback program a recording thread draws shares one pair of buffers: per-program pairs were ~2.2 GB of VRAM
|
||||
|
||||
@@ -161,7 +161,7 @@ int main() {
|
||||
|
||||
|
||||
def check_sources(menu, header, api, replay, readme):
|
||||
table = menu[menu.index("Row rows[] = {"):menu.index("constexpr int kQuitRow")]
|
||||
table = menu[menu.index("Row rows[] = {"):menu.index("constexpr int kRowsEnd")]
|
||||
# a row for every slot, after Bug capture (F8) and its heading, before the Controls tab's rows
|
||||
slots = int(re.search(r"constexpr int kSlots = (\d+);", (ROOT / "gpu/vk/mod_cheat_rows.h").read_text(encoding="utf-8")).group(1))
|
||||
starts = [int(n) for n in re.findall(r"MOD_CHEAT_ROWS8\((\d+)\)", table)]
|
||||
@@ -192,7 +192,7 @@ def check_sources(menu, header, api, replay, readme):
|
||||
"the guides do not say Change on a cheat's row")
|
||||
tick = block(menu, "void menu_tick() {")
|
||||
press = tick.index("else if (mod_cheat_slot(r.name) >= 0) changed |= mod_cheats.press(mod_cheat_slot(r.name), press[3], press[4], press[7]);")
|
||||
check(tick.index("} else if (r.cheat >= 0) cheat_press(") < press < tick.index("else if (press[7] && share_row(r))")
|
||||
check(tick.index("if (r.cheat >= 0) cheat_press(") < press < tick.index("else if (press[7] && share_row(r))")
|
||||
< tick.index("else if (press[7] && !r.value && can_bind()) page = 1"), "a press on a cheat's row is not taken before the rows that act by name or open a page")
|
||||
# the host's side of it
|
||||
ids = block(api, "enum { HOS_OPT_MODCHEAT_TEXT")
|
||||
|
||||
@@ -475,6 +475,7 @@ class OotOptionsScreenTests(unittest.TestCase):
|
||||
(tmp / "gpu" / "vk" / "vk_api.h").write_text(VK_API_H, encoding="utf-8")
|
||||
shutil.copy(ROOT / "host" / "oot_menu.c", tmp / "host" / "oot_menu.c")
|
||||
shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") # (set_item_key's buffer check)
|
||||
(tmp / "host" / "hos_bench.h").write_text(HOS_BENCH_H, encoding="utf-8") # ((Triforce, 11-19) benchmark mode: off here)
|
||||
(tmp / "host" / "t.c").write_text(OPTIONS_FIXTURE, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] if sys.platform == "win32" else []
|
||||
@@ -490,6 +491,18 @@ class OotOptionsScreenTests(unittest.TestCase):
|
||||
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
|
||||
|
||||
|
||||
# ((Triforce, 11-19) host/hos_bench.h's two calls oot_menu.c makes, benchmark mode off: the menus as a player has them)
|
||||
HOS_BENCH_H = """#pragma once
|
||||
#include <stdint.h>
|
||||
enum { HOS_BENCH_MENU_NONE, HOS_BENCH_MENU_PRESS_A };
|
||||
static inline int hos_bench_on(void) { return 0; }
|
||||
static inline int hos_bench_menu(uint64_t screen, uint64_t vt, int focus, int focused_entry, int entries, int *entry) {
|
||||
(void)screen, (void)vt, (void)focus, (void)focused_entry, (void)entries, (void)entry;
|
||||
return HOS_BENCH_MENU_NONE;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class OotMenuMouseTests(unittest.TestCase):
|
||||
def test_points_and_clicks_the_menus(self):
|
||||
if sys.platform != "win32":
|
||||
@@ -506,6 +519,7 @@ class OotMenuMouseTests(unittest.TestCase):
|
||||
(tmp / "gpu" / "vk" / "vk_api.h").write_text(VK_API_H, encoding="utf-8")
|
||||
shutil.copy(ROOT / "host" / "oot_menu.c", tmp / "host" / "oot_menu.c")
|
||||
shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") # (set_item_key's buffer check)
|
||||
(tmp / "host" / "hos_bench.h").write_text(HOS_BENCH_H, encoding="utf-8") # ((Triforce, 11-19) benchmark mode: off here)
|
||||
(tmp / "host" / "t.c").write_text(FIXTURE, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", "-D_WIN32_WINNT=0x0601",
|
||||
|
||||
@@ -69,6 +69,18 @@ int main(int, char** argv) {
|
||||
// (the answers the log names have words; the three that need no line have none)
|
||||
CHECK(*why(Read::OverBound) && *why(Read::Cut) && *why(Read::NoMemory) && *why(Read::Unsized) && *why(Read::Short));
|
||||
CHECK(!*why(Read::Ok) && !*why(Read::None));
|
||||
// ((Triforce, 11-18) the carry: a file for other shaders read all the same up to the limit (1536 MB unset, 0: never), and only
|
||||
// when it leaves room under the bound for as much again; one for these shaders is never "carried")
|
||||
CHECK(carry_limit(nullptr) == 1536 * MB && carry_limit("") == 1536 * MB && carry_limit("x") == 1536 * MB && carry_limit("0") == 0);
|
||||
CHECK(carry_limit("800") == 800 * MB);
|
||||
const uint64_t R32 = 32 * GB - 300 * MB, R16 = 16 * GB - 200 * MB; // (what such PCs report)
|
||||
CHECK(carried(false, 860 * MB, 1536 * MB, 4096 * MB, R32) && carried(false, 1536 * MB, 1536 * MB, 4096 * MB, R32));
|
||||
CHECK(!carried(false, 1537 * MB, 1536 * MB, 4096 * MB, R32)); // (over the limit: a file carried and saved again)
|
||||
CHECK(!carried(false, 1100 * MB, 1536 * MB, 2048 * MB, R32) && carried(false, 1024 * MB, 1536 * MB, 2048 * MB, R32)); // (room for as much again)
|
||||
CHECK(carried(false, 1400 * MB, 1536 * MB, 0, R32)); // (no bound)
|
||||
CHECK(!carried(false, 860 * MB, 1536 * MB, 4096 * MB, R16) && !carried(false, 860 * MB, 1536 * MB, 4096 * MB, 0)); // (16 GB, or RAM not known: never)
|
||||
CHECK(carried(false, 860 * MB, 1536 * MB, 8192 * MB, 64 * GB));
|
||||
CHECK(!carried(true, 860 * MB, 1536 * MB, 4096 * MB, R32) && !carried(false, 860 * MB, 0, 4096 * MB, R32) && !carried(false, 32, 1536 * MB, 4096 * MB, R32));
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
@@ -90,9 +102,12 @@ def check_source():
|
||||
raise SystemExit("pcache_init reads the cache's file past the bounded read")
|
||||
if "ci.initialDataSize = data.size();" not in init:
|
||||
raise SystemExit("the cache is not made from what the bounded read gave")
|
||||
# (what is for other shaders is still not read at all, whatever its size)
|
||||
if init.index("if (!pcache_same) {", init.index(setb)) > init.index(readb):
|
||||
raise SystemExit("a file for other shaders is read")
|
||||
# ((Triforce, 11-18) what is for other shaders is read only when carried (pcache_bound::carried, with the bound), else not at all)
|
||||
carry = "const bool carried = pcache_bound::carried(pcache_same, (uint64_t)std::max<int64_t>(sz, 0), carry, pcache_bound_bytes, ram);"
|
||||
if carry not in init or init.index(setb) > init.index(carry):
|
||||
raise SystemExit("pcache_init does not decide the carry with the bound set, or not by pcache_bound::carried")
|
||||
if init.index("if (!pcache_same && !carried) {", init.index(carry)) > init.index(readb):
|
||||
raise SystemExit("a file for other shaders that is not carried is read")
|
||||
save = between(draw, "void pipeline_cache_save(bool force) {", "\n}\n")
|
||||
ask = "if (!pcache_bound::within(n, pcache_bound_bytes)) {"
|
||||
if ask not in save or save.index(ask) > save.index("std::vector<uint8_t> data(n);"):
|
||||
|
||||
@@ -46,6 +46,15 @@ int main() {
|
||||
expect(count(4, 64 * GB, false, 1) == 1, "the switch: one");
|
||||
expect(count(8, 64 * GB, false, 1000) == 64, "the switch: 64 at most");
|
||||
expect(count(24, 26 * GB, false, -3) == 24 && count(24, 26 * GB, false, 0) == 24, "the switch not set, or not a count: the rule");
|
||||
// (the translation pass on AMD's Windows driver for RDNA 1 and 2: kAmdOlderMost at most, fewer where count gives fewer;
|
||||
// other drivers and the switch: count's number)
|
||||
using prepare_threads::translate;
|
||||
const unsigned most = prepare_threads::kAmdOlderMost;
|
||||
expect(translate(count(24, 26 * GB, false, 0), true, false) == most, "AMD's older driver, 24 processors: the cap");
|
||||
expect(translate(count(24, 64 * GB, true, 0), true, false) == most, "AMD's older driver, above normal: the cap over half");
|
||||
expect(translate(count(4, 64 * GB, false, 0), true, false) == 4 && translate(2, true, false) == 2, "AMD's older driver, few processors: count's");
|
||||
expect(translate(count(24, 26 * GB, false, 20), true, true) == 20, "AMD's older driver: the switch still decides");
|
||||
expect(translate(count(24, 26 * GB, false, 0), false, false) == 24, "other drivers: count's");
|
||||
if (failures) return EXIT_FAILURE;
|
||||
std::printf("prepare threads: all checks passed\n");
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -47,6 +47,13 @@ def check_source():
|
||||
['getenv("RX_VK_PREPARE_THREADS")', "GlobalMemoryStatusEx(&ms)", "ram_free = ms.ullAvailPhys;",
|
||||
"GetPriorityClass(GetCurrentProcess())", "cls == ABOVE_NORMAL_PRIORITY_CLASS || cls == HIGH_PRIORITY_CLASS",
|
||||
"prepare_threads::count(cpus, ram_free, above_normal, e ? atoi(e) : 0)", "MemAvailable"])
|
||||
# ((Triforce) the translation pass's workers: fewer on AMD's driver for RDNA 1 and 2, told apart as vk_vendor.h tells it)
|
||||
translate = block(draw, "unsigned prepare_translate_workers() {")
|
||||
need("vk_draw.cpp: prepare_translate_workers()", translate,
|
||||
["amd_older = amd_older_compiler(facts);", "facts.driver_info = drv.driverInfo;", "prepare_workers()",
|
||||
"prepare_threads::translate(all, amd_older, e && atoi(e) > 0)"])
|
||||
need("vk_draw.cpp: prepare_run()", block(draw, "bool prepare_run(void (*progress)(size_t done, size_t total), bool background) {"),
|
||||
["background ? std::clamp(cpus / 4, 2u, 4u) : prepare_translate_workers()"])
|
||||
# (the preparation before the title: the count is the rule's, and the workers stay below normal priority)
|
||||
for name, marker in [("state_list_prepare", "void state_list_prepare(void (*progress)(size_t done, size_t total)) {"),
|
||||
("warm_libraries", "bool warm_libraries(void (*progress)(size_t done, size_t total)) {")]:
|
||||
@@ -59,7 +66,7 @@ def check_source():
|
||||
prepare = block(draw, "bool prepare_run(void (*progress)(size_t done, size_t total), bool background) {")
|
||||
need("vk_draw.cpp: prepare_run()", prepare,
|
||||
# (behind the game: its own count and idle priority, as before)
|
||||
["const unsigned workers = background ? std::clamp(cpus / 4, 2u, 4u) : prepare_workers();",
|
||||
["const unsigned workers = background ? std::clamp(cpus / 4, 2u, 4u) : prepare_translate_workers();",
|
||||
"SetThreadPriority(GetCurrentThread(), background ? THREAD_PRIORITY_IDLE : THREAD_PRIORITY_BELOW_NORMAL);",
|
||||
"for (unsigned i = 0; i < workers; i++) threads.emplace_back(worker);"])
|
||||
if "cpus / 2" in prepare:
|
||||
|
||||
@@ -46,6 +46,12 @@ class CacheModuleCleanupTests(unittest.TestCase):
|
||||
crc = ('uint32_t spirv_crc32(',) if 'uint32_t spirv_crc32(' in source else ()
|
||||
functions = '\n'.join(block(source, marker) for marker in crc + (
|
||||
'VkShaderModule make_module(', 'uint64_t answers_hash(', 'bool answers_fit(', 'void idx_put('))
|
||||
# ((Triforce, 11-18) make_module asks the water/shadow PCF rewrite (EstebanGGM's spirv_water_simplify), which reads
|
||||
# the device: stubbed as off, the module as translated, as the fixture's device would have it)
|
||||
if 'bool spirv_water_simplify(' in source:
|
||||
functions = ('static int water_quality_mode() { return 0; }\n'
|
||||
'static bool spirv_water_simplify(const std::vector<uint32_t>&, int, std::vector<uint32_t>&) '
|
||||
'{ return false; }\n') + functions
|
||||
serialization = source[source.index('void put_bytes('):source.index('void program_cache_save(')]
|
||||
functions += '\n' + serialization + block(source, 'void program_cache_save(')
|
||||
functions += '\n' + block(source, 'void program_cache_read(')
|
||||
|
||||
@@ -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):
|
||||
|
||||
129
tests/test_redrawn.py
Normal file
129
tests/test_redrawn.py
Normal file
@@ -0,0 +1,129 @@
|
||||
"""(Triforce, 11-18) A draw may leave a texture it samples for the next frame (the new-texture budget) only when every target it
|
||||
writes was written in the frame before too and its program writes no memory (gpu/vk/redrawn.h; vk_draw.cpp draw_may_defer).
|
||||
|
||||
The game composes each text box once into a target of its own and keeps it: a compose in a frame over the budget kept the dummy
|
||||
for the whole session (empty title buttons, option values, dialogue boxes). The rule's cases: a scene target drawn every frame is
|
||||
redrawn before its pass's mark and after it (prev_written); a target composed for the first time is not, for its first draw nor
|
||||
its second in that frame (begin_pass marks it written before the second draw builds its descriptors); one composed again 300
|
||||
frames later is not; a two-frame gap is not; contents begun anew (released, or never the GPU's) have no frame before. And the
|
||||
source keeps every gate: kept_texture's look and its kept dummy, texture_view_of's handle cache, the whole-draw reuse and the
|
||||
signature hit.
|
||||
|
||||
python -I -B tests/test_redrawn.py
|
||||
"""
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
|
||||
FIXTURE = r"""
|
||||
#include "redrawn.h"
|
||||
#include <cstdio>
|
||||
static int fails;
|
||||
#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0)
|
||||
struct T { uint64_t prev = 0, last = 0; bool gpu = false, released = false; };
|
||||
static void write(T& t, uint64_t f) { // (as texture_written: prev before last, read before gpu/released are set)
|
||||
t.prev = redrawn::prev_on_write(t.prev, t.last, t.gpu && !t.released, f);
|
||||
t.last = f, t.gpu = true, t.released = false;
|
||||
}
|
||||
static bool redrawn_now(const T& t, uint64_t f) { return redrawn::drawn_before(t.prev, t.last, t.gpu && !t.released, f); }
|
||||
int main() {
|
||||
{ // (a scene target, drawn every frame from frame 10 on)
|
||||
T s;
|
||||
for (uint64_t f = 10; f < 20; f++) write(s, f);
|
||||
CHECK(redrawn_now(s, 20)); // (frame 20, its first draw: before begin_pass marks it)
|
||||
write(s, 20);
|
||||
CHECK(redrawn_now(s, 20)); // (its second draw in frame 20: after the mark)
|
||||
write(s, 20);
|
||||
CHECK(redrawn_now(s, 20));
|
||||
CHECK(redrawn_now(s, 21));
|
||||
}
|
||||
{ // (a text box composed for the first time at frame 50)
|
||||
T b;
|
||||
CHECK(!redrawn_now(b, 50)); // (its first draw)
|
||||
write(b, 50);
|
||||
CHECK(!redrawn_now(b, 50)); // (its second draw: marked written already, but not in the frame before)
|
||||
write(b, 50);
|
||||
CHECK(!redrawn_now(b, 50));
|
||||
CHECK(redrawn_now(b, 51)); // (were it drawn again in the next frame, that frame's draws could leave textures)
|
||||
// (composed again 300 frames later)
|
||||
CHECK(!redrawn_now(b, 350));
|
||||
write(b, 350);
|
||||
CHECK(!redrawn_now(b, 350));
|
||||
}
|
||||
{ // (a two-frame gap)
|
||||
T g;
|
||||
write(g, 100);
|
||||
CHECK(!redrawn_now(g, 102));
|
||||
write(g, 102);
|
||||
CHECK(!redrawn_now(g, 102));
|
||||
}
|
||||
{ // (released after its last write: its contents begin anew)
|
||||
T r;
|
||||
write(r, 200);
|
||||
r.released = true;
|
||||
CHECK(!redrawn_now(r, 201));
|
||||
write(r, 201);
|
||||
CHECK(!redrawn_now(r, 201));
|
||||
write(r, 202);
|
||||
CHECK(redrawn_now(r, 202) && redrawn_now(r, 203));
|
||||
}
|
||||
if (!fails) std::printf("PASS\n");
|
||||
return fails != 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class RedrawnTests(unittest.TestCase):
|
||||
def test_rule(self):
|
||||
compiler = shutil.which("g++") or shutil.which("clang++")
|
||||
if not compiler:
|
||||
self.skipTest("no C++ compiler")
|
||||
with tempfile.TemporaryDirectory(prefix="triforce-redrawn-") as tmp:
|
||||
tmp = Path(tmp)
|
||||
(tmp / "t.cpp").write_text(FIXTURE, encoding="utf-8")
|
||||
exe = tmp / "t.exe"
|
||||
build = subprocess.run([compiler, "-std=c++17", "-Wall", "-O1", "-I", str(VK), str(tmp / "t.cpp"), "-o", str(exe)],
|
||||
text=True, capture_output=True)
|
||||
self.assertEqual(build.returncode, 0, build.stderr)
|
||||
run = subprocess.run([str(exe)], text=True, capture_output=True, timeout=30)
|
||||
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
|
||||
|
||||
def test_gates_in_the_source(self):
|
||||
draw = (VK / "vk_draw.cpp").read_text(encoding="utf-8")
|
||||
tex = (VK / "vk_texture.cpp").read_text(encoding="utf-8")
|
||||
# (prev_written kept at every write, before last_written moves)
|
||||
self.assertRegex(tex, r"tex->prev_written = redrawn::prev_on_write\(tex->prev_written, tex->last_written, "
|
||||
r"tex->gpu_written && !tex->released, frame_no\);\n tex->last_written = frame_no;")
|
||||
# (the draw's decision: every colour target and the depth target redrawn, no memory written)
|
||||
self.assertIn("bool may = !program_writes_memory(p);", draw)
|
||||
self.assertIn("may = texture_redrawn(at.color[i]);", draw)
|
||||
self.assertIn("may = texture_redrawn(at.depth);", draw)
|
||||
# (the one gate every deferral path checks, set from it)
|
||||
self.assertIn("upload_defer_ok = !compute && draw_may_defer;", draw)
|
||||
self.assertEqual(len(re.findall(r"upload_defer_ok = !compute", draw)), 1)
|
||||
# (no kept dummy, nor a kept texture owed its bytes, for a draw that may not defer)
|
||||
self.assertIn("if (took && !compute && !draw_may_defer && (!e->out[1] || texture_owes(", draw)
|
||||
# (the handle cache's dummy only for a look that may defer; an owed texture looked at again by one that may not)
|
||||
self.assertIn("(it->second.tex_epoch == texture_dummy_generation() && upload_defer_ok)", draw)
|
||||
self.assertIn("if (it->second.tex && !upload_defer_ok && texture_owes(it->second.tex)) {", draw)
|
||||
# (no whole-draw reuse nor signature hit for such a draw in a frame that left textures)
|
||||
self.assertIn("const bool strict = !draw_may_defer && texture_frame_left_any();", draw)
|
||||
self.assertIn("const bool same_gens = !no_reuse && !strict &&", draw)
|
||||
self.assertIn("const int sig_mode = !same_gens && !no_reuse && !strict ? desc_sig_mode() : 0;", draw)
|
||||
# (the decision comes before the reuse checks read it)
|
||||
self.assertLess(draw.index("draw_may_defer = may;"), draw.index("const bool same_gens = !no_reuse"))
|
||||
# (every deferral path still checks the gate)
|
||||
for fn in ("bool new_texture_later(const Texture&) {", "bool new_texture_waits() {", "bool create_later(bool for_sampling) {",
|
||||
"bool upload_again_later(const Texture& tex) {", "bool upload_defer(const Texture& tex) {"):
|
||||
at = tex.index(fn)
|
||||
self.assertIn("upload_defer_ok", tex[at:at + 600], fn)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(unittest.main(verbosity=1))
|
||||
@@ -53,7 +53,7 @@ def main():
|
||||
"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",
|
||||
"unknown-id", "force-linear", "wrap", "lod-clamp", "custom-reduction",
|
||||
"anisotropy-clamped", "unknown-id", "force-linear", "wrap", "lod-clamp", "custom-reduction",
|
||||
"descriptor-push", "descriptor-pool", "descriptor-compute", "descriptor-old", "descriptor-whole"]
|
||||
with tempfile.TemporaryDirectory(prefix="sampler-admission-") as temp:
|
||||
cpp, exe = Path(temp) / "fixture.cpp", Path(temp) / "fixture.exe"
|
||||
|
||||
@@ -145,7 +145,7 @@ int main() {
|
||||
|
||||
|
||||
def check_sources(menu, api, replay, readme):
|
||||
table = menu[menu.index("Row rows[] = {"):menu.index("constexpr int kQuitRow")]
|
||||
table = menu[menu.index("Row rows[] = {"):menu.index("constexpr int kRowsEnd")]
|
||||
entries = re.findall(r'\{(TAB_\w+), "([^"]+)", ([^,]+),', table)
|
||||
# ((Triforce) 11-17) a section's heading (its entry ends "..., -1, true}") is not a row
|
||||
headings = set(re.findall(r'\{TAB_\w+, "([^"]+)", nullptr, 0, 0, 0, nullptr, nullptr, nullptr, false, true, -1, true\}', table))
|
||||
@@ -155,10 +155,10 @@ def check_sources(menu, api, replay, readme):
|
||||
check(tuple(names[at + 1:at + 1 + len(ALL_ROWS)]) == ALL_ROWS, "the save rows do not stand directly after Discord status: %r" % names[at + 1:at + 5])
|
||||
for tab, name, value in entries[at + 1:at + 1 + len(ALL_ROWS)]:
|
||||
check(tab == "TAB_SYSTEM" and value == "nullptr", "%s is not a row of the System tab that acts on a press" % name)
|
||||
check(names[-2:] == ["Restart", "Quit"], "Restart and Quit are no longer the table's last two")
|
||||
check("Restart" not in names and "Quit" not in names, "Restart and Quit are rows again (11-19: they are the pause menu's Quit)")
|
||||
tick = block(menu, "void menu_tick() {")
|
||||
press = tick.index("else if (press[7] && share_row(r)) share_press(share_row(r)), press[7] = false, changed = true;")
|
||||
check(tick.index("} else if (r.cheat >= 0) cheat_press(") < press < tick.index("else if (press[7] && !r.value && can_bind()) page = 1"),
|
||||
check(tick.index("if (r.cheat >= 0) cheat_press(") < press < tick.index("else if (press[7] && !r.value && can_bind()) page = 1"),
|
||||
"a press on a save row is not taken before the rows that open a page")
|
||||
draw = block(menu, "void draw_options(ui::Ctx& c) {")
|
||||
check('ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open"' in draw, "a save row's label is not drawn in its value's place")
|
||||
|
||||
60
tests/test_setup_tools_parts.py
Normal file
60
tests/test_setup_tools_parts.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""(Triforce, 11-18) Triforce Setup updates the tools in two parts (setup/Setup.cs Tools.ParseBaseList, HasBase, UnpackParts;
|
||||
setup/Shell.cs ToolsInParts; setup/pack_tools.ps1 base.list and the three zips).
|
||||
|
||||
Every update fetched the whole 284 MB Triforce-Tools.zip, 95 % of it the compiler, Python and the libraries, which do not
|
||||
change from one release to the next; at a release the download server's line was full and each player got 75 KB/s. Now an
|
||||
update of tools that hold the release's base fetches the code part alone and moves the base over.
|
||||
|
||||
Compiles Guard.cs, Mods.cs and Setup.cs's Tools class (cut out of it) with tests/setup_tools_parts_test.cs and runs it in a
|
||||
temporary folder: the base list read, and refused when it is another format, names a path out of the folder or has a line it
|
||||
does not know; a base held taken (and remembered, then not read again), one with a file of other bytes, another size or gone
|
||||
not; the code part with the base kept (the old code's files gone, a file a run added to the base kept), with the base
|
||||
fetched; a refused code part and a base found short after it was moved over leaving the tools that were there; the whole
|
||||
zip remembering its base. Reads the source: Merge tries the parts before the whole zip, the parts go through Guard.cs's
|
||||
Download, and the packer writes the list and all three zips.
|
||||
|
||||
python -I -B tests/test_setup_tools_parts.py
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_SKIP = {"linux": "Triforce Setup is a Windows program (.NET Framework 4.8)"}
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
import setup_cs # noqa: E402
|
||||
|
||||
|
||||
def check_source():
|
||||
shell = setup_cs.source("setup/Shell.cs")
|
||||
merge = shell[shell.index("async Task Merge()"):shell.index("void Ui(Action a)")]
|
||||
setup_cs.need(merge, "release.ToolsCodeUrl != null && release.ToolsBaseUrl != null &&", "setup/Shell.cs Merge: the parts are not tried")
|
||||
setup_cs.need(merge, "await ToolsInParts(http, release, have, cache, token);", "setup/Shell.cs Merge: the parts are not tried")
|
||||
if merge.index("await ToolsInParts(") > merge.index("await Download.ToFile(http, release.ToolsUrl, zip"):
|
||||
raise SystemExit("setup/Shell.cs Merge: the whole zip is fetched before the parts are tried")
|
||||
parts = shell[shell.index("async Task<bool> ToolsInParts("):]
|
||||
parts = parts[:parts.index("\n }\n")]
|
||||
for needle in ("await Download.ToFile(http, release.ToolsCodeUrl!, code, release.ToolsCodeSize,",
|
||||
"await Download.ToFile(http, release.ToolsBaseUrl!, baseZip, release.ToolsBaseSize,",
|
||||
"Tools.HasBase(b, Tools.Folder,", "Tools.UnpackParts(code, keep ? null : baseZip, b, release.Tag,"):
|
||||
setup_cs.need(parts, needle, "setup/Shell.cs ToolsInParts lacks: " + needle)
|
||||
if "GetAsync(" in parts:
|
||||
raise SystemExit("setup/Shell.cs ToolsInParts: a download goes past Guard.cs's Download")
|
||||
setup = setup_cs.source("setup/Setup.cs")
|
||||
for asset in ('ToolsCodeAsset = "Triforce-Tools-code.zip"', 'ToolsBaseAsset = "Triforce-Tools-base.zip"'):
|
||||
setup_cs.need(setup, asset, "setup/Setup.cs: no " + asset)
|
||||
pack = setup_cs.source("setup/pack_tools.ps1")
|
||||
for needle in ("'llvm-mingw', 'python', 'cpm', 'wgpu-native'", "triforce-tools-base`t1`nid`t$id`n",
|
||||
"Write-ToolsZip (Join-Path $Out 'Triforce-Tools.zip') $all",
|
||||
"Write-ToolsZip (Join-Path $Out 'Triforce-Tools-code.zip')", "Write-ToolsZip (Join-Path $Out 'Triforce-Tools-base.zip')"):
|
||||
setup_cs.need(pack, needle, "setup/pack_tools.ps1 lacks: " + needle)
|
||||
|
||||
|
||||
def main():
|
||||
check_source()
|
||||
tools = setup_cs.cut("setup/Setup.cs", "/// The Triforce tools beside the installed Setup", "/// nx2/make_game.py as a child process",
|
||||
using=("System", "System.IO", "System.IO.Compression", "System.Linq"))
|
||||
setup_cs.run_fixture("setup_tools_parts_test.cs", extra=tools, sources=("setup/Mods.cs",))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -161,19 +161,23 @@ bool gameplay_network(uint64_t key) {
|
||||
return key == 0xfd029a317a9a4b94ull || key == 0x9dc98871eb7fc101ull;
|
||||
}
|
||||
enum class ViewUse { Sample, Storage };
|
||||
constexpr VkImageView VK_NULL_HANDLE = 0;
|
||||
VkImageView texture_view(Texture *t, const nvn_tex *, const nvn_view *v, VkImageViewType type,
|
||||
ViewUse use, VkFormat *f, VkFormat forced = VK_FORMAT_UNDEFINED) {
|
||||
ViewUse use, VkFormat *f = nullptr, VkFormat forced = VK_FORMAT_UNDEFINED) {
|
||||
assert(!v && type == VK_IMAGE_VIEW_TYPE_2D && lock_depth > 0);
|
||||
views++;
|
||||
if (t == &src) {
|
||||
assert(use == ViewUse::Sample && forced == VK_FORMAT_UNDEFINED);
|
||||
*f = VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
|
||||
if (f) *f = VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
|
||||
return missing_input_view ? 0 : (VkImageView)101;
|
||||
}
|
||||
assert(t == &dst && use == ViewUse::Storage && forced == VK_FORMAT_B10G11R11_UFLOAT_PACK32);
|
||||
*f = VK_FORMAT_B10G11R11_UFLOAT_PACK32;
|
||||
if (f) *f = VK_FORMAT_B10G11R11_UFLOAT_PACK32;
|
||||
return missing_output_view ? 0 : (VkImageView)102;
|
||||
}
|
||||
// ((Triforce, 11-18) FSR 3.1 for a rejected network's pass, upscale_stub's, when it is the upscaler: not picked here)
|
||||
bool fsr3_wanted() { return false; }
|
||||
bool fsr3_upscale(VkCommandBuffer, uint64_t, bool, Texture *, VkImageView, Texture *, VkImageView, uint32_t) { return false; }
|
||||
static bool typed_upscale(VkCommandBuffer, VkImageView input, VkImageView output, Texture *t,
|
||||
uint32_t level, uint64_t, const char *, bool temporal) {
|
||||
assert(input == (VkImageView)101 && output == (VkImageView)102 && t == &dst && level == 0 &&
|
||||
|
||||
@@ -61,7 +61,10 @@ def check_source():
|
||||
"a submit other than the three parts' is a part's")
|
||||
finish = function(replay, "void finish_recording(uint64_t value) {")
|
||||
check("submit_recording(r, signal, at);" in finish, "finish_recording's submit does not end the recording")
|
||||
check("submit_recording(r); // (nothing is stopped at a present: drain)" in replay, "a present's submit does not end its recording")
|
||||
# (Triforce-dev: a present that leaves work stopped (RX_VK_PRESENT_DRAIN=2) names its timeline signal as finish_recording
|
||||
# does; it is still the submit that ends its recording, not a part's)
|
||||
present = function(replay, "void do_present(const nvn_tex* t, const int crop[4]) {")
|
||||
check("submit_recording(r, signal, at);" in present, "a present's submit does not end its recording")
|
||||
|
||||
wait = function(replay, "void vk_timeline_wait(uint64_t v) {")
|
||||
for needle, why in (
|
||||
|
||||
Reference in New Issue
Block a user