mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-24 18:18:50 -04:00
Triforce v0.7.1
Crash fixes (a load crash from the virtual cores' escape, the upscaler-before-the-bloom crash, out of memory at a file's open), slow motion after a movie fixed, three save files with per-save achievements (ZakyPew), ten more achievements and their own menu group, N64 Classic, native ultrawide output (Kaefergeneral), the community AMD frame-time fixes, the helper threads' calm-scene tuner and benchmark test, update and Linux launcher fixes.
This commit is contained in:
@@ -38,6 +38,14 @@ static int said(const char *text) { /* how often the log has it */
|
||||
return n;
|
||||
}
|
||||
#include "achievements_constants.inc"
|
||||
/* (host/save_files.c: off but for the "file1" and "file2" runs, which play a save file of that folder under the game's) */
|
||||
static char files_dir[440];
|
||||
static int files_first;
|
||||
const char *hos_save_files_dir(int *first) {
|
||||
if (!files_dir[0]) return NULL;
|
||||
*first = files_first;
|
||||
return files_dir;
|
||||
}
|
||||
static int sounds;
|
||||
static int64_t sound_at;
|
||||
static void hos_menu_sound_play(int id, int64_t now_ns) {
|
||||
@@ -49,7 +57,10 @@ static void hos_menu_sound_play(int id, int64_t now_ns) {
|
||||
static int renderer; /* 0: no renderer yet (rx_option answers what it is given) */
|
||||
static char incoming[600], row_text[160][400], notice_day[16][32];
|
||||
static int incoming_n, row_bits[160], rows_added, rows_shown = -1, notices[16], nnotices;
|
||||
static int row_on = 1, row_notices = 1; /* (the System tab's Achievements and Achievement notices rows) */
|
||||
int rx_option(int id, int otherwise) {
|
||||
if (id == HOS_OPT_ACH_ON) return renderer ? row_on : otherwise;
|
||||
if (id == HOS_OPT_ACH_NOTICES) return renderer ? row_notices : otherwise;
|
||||
if (!renderer) return otherwise;
|
||||
CHECK(id == HOS_OPT_ACH_ASK);
|
||||
return 1;
|
||||
@@ -126,25 +137,68 @@ int main(int argc, char **argv) {
|
||||
renderer = 1;
|
||||
hos_achievements_frame(), at(10), hos_achievements_frame(), at(100);
|
||||
CHECK(!asked && !logged[0] && !rows_added && rows_shown < 0 && !nnotices && !sounds && !ready && !file("triforce_achievements.txt")[0]);
|
||||
} else if (!strcmp(argv[2], "rows")) { /* the System tab's two rows, in a game folder of its own without a list of the player's */
|
||||
renderer = 1, row_on = 0;
|
||||
hos_achievements_frame(); /* (the list is named all the same: its page shows what was earned) */
|
||||
CHECK(rows_shown == 35);
|
||||
at(10), at(20); /* Achievements Off: nothing asked of the save data, nothing earned or written */
|
||||
CHECK(!asked && !said("earned \"") && !nnotices && !file("triforce_achievements.txt")[0]);
|
||||
row_on = 1, row_notices = 0; /* On again, the notices Off: earned at the next check, told to the list one a check, no sound */
|
||||
at(30);
|
||||
CHECK(asked && said("achievements: earned \"") == 5 && lines(file("triforce_achievements.txt")) == 6 && nnotices == 1);
|
||||
at(31), at(32), at(33), at(34), at(35); /* (a tenth of a second apart: no notice's time between them) */
|
||||
CHECK(nnotices == 5 && !sounds && notices[4] == row_of("Three Stones"));
|
||||
row_notices = 1; /* the notices On again: the next one earned has its sound */
|
||||
set(ACH_ITEM, "Item_Medal_Light", 1);
|
||||
at(40);
|
||||
CHECK(nnotices == 6 && sounds == 1 && notices[5] == row_of("Sage of Light"));
|
||||
} else if (!strcmp(argv[2], "file2")) { /* the save files on, File 2 played: none of what the game folder earned is its */
|
||||
snprintf(files_dir, sizeof files_dir, "%s/user-2", game_dir);
|
||||
const int lines_before = lines(file("triforce_achievements.txt"));
|
||||
renderer = 1;
|
||||
hos_achievements_frame();
|
||||
CHECK(said("achievements: 36 (1 of achievements.txt), 0 earned so far") == 1 && rows_shown == 36 && !(row_bits[0] & HOS_ACH_EARNED));
|
||||
at(20);
|
||||
CHECK(said("achievements: earned \"") == 6 && said("earned \"Mine\" (6 of 36)") == 1 && !said("could not be written"));
|
||||
CHECK(lines(file("user-2/triforce_achievements.txt")) == 7 && strstr(file_text, " Mine\n") && !strstr(file_text, "Spider Hunter"));
|
||||
CHECK(lines(file("triforce_achievements.txt")) == lines_before && strstr(file_text, " Spider Hunter\n")); /* (the game folder's as it was) */
|
||||
} else if (!strcmp(argv[2], "file1")) { /* File 1, never played with files: it starts from what the game folder earned */
|
||||
snprintf(files_dir, sizeof files_dir, "%s/user", game_dir), files_first = 1;
|
||||
renderer = 1;
|
||||
hos_achievements_frame();
|
||||
CHECK(said("achievements: 36 (1 of achievements.txt), 7 earned so far") == 1 && (row_bits[row_of("Spider Hunter")] & HOS_ACH_EARNED));
|
||||
at(10);
|
||||
CHECK(!said("earned \"") && !file("user/triforce_achievements.txt")[0]); /* (nothing new: nothing written yet) */
|
||||
set(ACH_ITEM, "Item_Medal_Light", 1);
|
||||
at(20);
|
||||
CHECK(said("earned \"Sage of Light\" (8 of 36)") == 1);
|
||||
/* its own file from here: the eight, and the line no list has, kept; the game folder's without the eighth */
|
||||
CHECK(lines(file("user/triforce_achievements.txt")) == 10 && strstr(file_text, " Sage of Light\n") && strstr(file_text, "\ndeadbeef 5 Gone\n"));
|
||||
CHECK(lines(file("triforce_achievements.txt")) == 9 && !strstr(file_text, "Sage of Light"));
|
||||
} else if (!strcmp(argv[2], "again1")) { /* File 1's next start: its own file now, not the game folder's */
|
||||
snprintf(files_dir, sizeof files_dir, "%s/user", game_dir), files_first = 1;
|
||||
renderer = 1;
|
||||
hos_achievements_frame();
|
||||
CHECK(said("achievements: 36 (1 of achievements.txt), 8 earned so far") == 1);
|
||||
} else if (!strcmp(argv[2], "first")) {
|
||||
CHECK(hos_achievements_on());
|
||||
hos_achievements_frame(); /* the first present, before the renderer answers: the lists are read, nothing is named */
|
||||
CHECK(said("achievements: 26 (1 of achievements.txt), 0 earned so far") == 1 && said("achievements: 2 left out") == 1);
|
||||
CHECK(said("achievements: 36 (1 of achievements.txt), 0 earned so far") == 1 && said("achievements: 2 left out") == 1);
|
||||
CHECK(!rows_added && rows_shown < 0);
|
||||
at(20); /* six earned before the menu has the list: written and said at once, shown only once it has */
|
||||
CHECK(said("achievements: earned \"") == 6 && said("earned \"A Sword of Your Own\" (1 of 26)") == 1 && said("earned \"Mine\" (6 of 26)") == 1);
|
||||
CHECK(said("achievements: earned \"") == 6 && said("earned \"A Sword of Your Own\" (1 of 36)") == 1 && said("earned \"Mine\" (6 of 36)") == 1);
|
||||
CHECK(said("earned \"Three Stones\"") == 1 && !said("Spider Hunter") && !said("could not be written"));
|
||||
CHECK(lines(file("triforce_achievements.txt")) == 7 && strstr(file_text, " A Sword of Your Own\n") && strstr(file_text, " Mine\n"));
|
||||
CHECK(!nnotices && !sounds);
|
||||
renderer = 1;
|
||||
hos_achievements_frame(); /* the list named, whole, in its order: name, the line about it, the day; the icon and earned */
|
||||
CHECK(rows_added == 26 && rows_shown == 26 && !nnotices);
|
||||
CHECK(rows_added == 36 && rows_shown == 36 && !nnotices);
|
||||
CHECK(!strncmp(row_text[0], "A Sword of Your Own\nFind a blade in the forest.\n", 48) && is_day(row_text[0] + 48));
|
||||
CHECK(row_bits[0] == (1 | 1 << 4 | HOS_ACH_EARNED)); /* (sword green, earned) */
|
||||
CHECK(!strcmp(row_text[1], "First Melody\nLearn the royal family's song.\n") && row_bits[1] == 4); /* (a note, gold; not earned: no day) */
|
||||
CHECK(row_of("Mine") == 25 && row_bits[25] == (2 | 3 << 4 | HOS_ACH_EARNED) && row_bits[row_of("Twice as Tough")] == (6 | 7 << 4));
|
||||
CHECK(row_of("Mine") == 35 && row_bits[35] == (2 | 3 << 4 | HOS_ACH_EARNED) && row_bits[row_of("Twice as Tough")] == (6 | 7 << 4));
|
||||
hos_achievements_frame(), hos_achievements_frame();
|
||||
CHECK(rows_added == 26); /* (named once) */
|
||||
CHECK(rows_added == 36); /* (named once) */
|
||||
/* shown one at a time, each for its 4.5 s, in the list's order, with the sound and the day */
|
||||
at(30);
|
||||
CHECK(nnotices == 1 && sounds == 1 && sound_at == 3 * S && notices[0] == 0 && is_day(notice_day[0]));
|
||||
@@ -153,18 +207,18 @@ int main(int argc, char **argv) {
|
||||
at(75);
|
||||
CHECK(nnotices == 2 && sounds == 2 && notices[1] == row_of("Forest's Thanks"));
|
||||
for (int t = 120; t <= 400; t += 10) at(t);
|
||||
CHECK(nnotices == 6 && sounds == 6 && notices[5] == 25);
|
||||
CHECK(said("achievements: earned \"") == 6 && said("achievements: 26 (") == 1 && lines(file("triforce_achievements.txt")) == 7);
|
||||
CHECK(nnotices == 6 && sounds == 6 && notices[5] == 35);
|
||||
CHECK(said("achievements: earned \"") == 6 && said("achievements: 36 (") == 1 && lines(file("triforce_achievements.txt")) == 7);
|
||||
} else {
|
||||
renderer = 1;
|
||||
hos_achievements_frame(); /* the next start: what was earned is, and is neither said nor shown again */
|
||||
CHECK(said("achievements: 26 (1 of achievements.txt), 6 earned so far") == 1 && rows_shown == 26);
|
||||
CHECK(said("achievements: 36 (1 of achievements.txt), 6 earned so far") == 1 && rows_shown == 36);
|
||||
at(10);
|
||||
CHECK(!said("earned \"") && !nnotices && !sounds);
|
||||
CHECK((row_bits[0] & HOS_ACH_EARNED) && !(row_bits[row_of("Spider Hunter")] & HOS_ACH_EARNED));
|
||||
have[5].value = 10; /* (the tenth token) */
|
||||
at(20);
|
||||
CHECK(said("earned \"Spider Hunter\" (7 of 26)") == 1 && nnotices == 1 && notices[0] == row_of("Spider Hunter") && is_day(notice_day[0]));
|
||||
CHECK(said("earned \"Spider Hunter\" (7 of 36)") == 1 && nnotices == 1 && notices[0] == row_of("Spider Hunter") && is_day(notice_day[0]));
|
||||
/* the file whole again: the seven, and the line of an achievement no list has now, as it was */
|
||||
CHECK(lines(file("triforce_achievements.txt")) == 9 && strstr(file_text, " Spider Hunter\n") && strstr(file_text, "\ndeadbeef 5 Gone\n"));
|
||||
CHECK(!file("triforce_achievements.txt.new")[0]);
|
||||
|
||||
@@ -52,7 +52,7 @@ static void built_in(int print) {
|
||||
for (int k = 0; k < list.a[i].nconds; k++) printf("%c %s %d\n", list.a[i].conds[k].kind, list.a[i].conds[k].what, list.a[i].conds[k].least);
|
||||
return;
|
||||
}
|
||||
CHECK(n == 25 && list.n == 25 && refused == 0);
|
||||
CHECK(n == 35 && list.n == 35 && refused == 0);
|
||||
for (int i = 0; i < list.n; i++) {
|
||||
const Ach *a = &list.a[i];
|
||||
CHECK(a->name[0] && a->about[0] && a->nconds >= 1 && !a->earned && a->key == ach_key(a->name));
|
||||
@@ -61,6 +61,7 @@ static void built_in(int print) {
|
||||
}
|
||||
CHECK(ach_key("") == 2166136261u && ach_key("a") == 0xe40c292cu);
|
||||
CHECK(list.a[0].icon == (1 | 1 << 4) && list.a[1].icon == 4 && list.a[24].icon == (6 | 7 << 4)); /* (sword green, a note, shield silver) */
|
||||
CHECK(list.a[28].nconds == 4 && list.a[31].nconds == 2 && list.a[31].conds[1].least == 50 && list.a[34].icon == (6 | 3 << 4)); /* (the tunics and boots; the bombs; shield blue) */
|
||||
}
|
||||
|
||||
static void form(void) {
|
||||
|
||||
@@ -51,6 +51,8 @@ static int hos_sdl_init(unsigned flags) {
|
||||
return mode != "init_failure";
|
||||
}
|
||||
static int hos_sdl_desktop_size(int* w, int* h) { *w = 2560; *h = 1440; return 1; }
|
||||
// ((Triforce) hos_display_init reads every display for the Output resolution: tests/test_screen_size.py)
|
||||
static void screens_read(int, int) {}
|
||||
static void* hos_sdl_window(const char*, int w, int h) {
|
||||
require(w == 1280 && h == 720, "changed default window size");
|
||||
++windows;
|
||||
|
||||
@@ -22,6 +22,8 @@ Host* host = &host_object;
|
||||
VkImage framegen_scale(VkCommandBuffer,VkImageView,VkImage,uint32_t,uint32_t,const int*,uint32_t,uint32_t) {
|
||||
return VK_NULL_HANDLE; // This GPU fixture exercises direct blits; filtered routing is covered by L1.
|
||||
}
|
||||
void n64_screen_begin(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) {} // ((Triforce, 11-22) N64 Classic's TV's screen: vk_n64.h)
|
||||
void n64_screen_end() {}
|
||||
// @PRODUCTION_HELPERS@
|
||||
void record_actual(VkCommandBuffer command,VkImage src,uint32_t sw,uint32_t sh,const int* crop,VkImage dst) {
|
||||
struct { VkCommandBuffer cmd; } f{command};
|
||||
|
||||
@@ -45,6 +45,8 @@ VkImage framegen_hdr(int, VkImageView, uint32_t, uint32_t, const int*, uint32_t,
|
||||
++hdr_calls; return encoded ? 29 : VK_NULL_HANDLE;
|
||||
}
|
||||
VkImage framegen_scale(int, VkImageView, VkImage, uint32_t, uint32_t, const int*, uint32_t, uint32_t) { return scaled ? 9 : 0; }
|
||||
void n64_screen_begin(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) {} // ((Triforce, 11-22) N64 Classic's TV's screen: vk_n64.h)
|
||||
void n64_screen_end() {}
|
||||
void blit_crop_to_rect(int, VkImage, uint32_t, uint32_t, const int*, VkImage, int, PresentRect rect) { ++blits; drawn = rect; }
|
||||
void present(VkImage src = 1, uint32_t sw = 3440, uint32_t sh = 1440, const int* crop = nullptr, VkImageView view = 2) {
|
||||
struct { int cmd = 1; } f; VkImage dst = 3;
|
||||
|
||||
@@ -407,6 +407,9 @@ F(vkCmdSetCheckpointNV, (VkCommandBuffer cb, const void* m), handle(cb), handle(
|
||||
F(vkCmdWriteTimestamp2, (VkCommandBuffer cb, VkPipelineStageFlags2 s, VkQueryPool p, uint32_t q), handle(cb), put(s), handle(p), put(q);
|
||||
fx(cb, 1, (uint64_t)(uintptr_t)p << 16 | q);)
|
||||
F(vkCmdResetQueryPool, (VkCommandBuffer cb, VkQueryPool p, uint32_t f, uint32_t n), handle(cb), handle(p), put(f), put(n);)
|
||||
// ((Triforce, 11-23) RX_VK_QUERY_RING)
|
||||
F(vkCmdCopyQueryPoolResults, (VkCommandBuffer cb, VkQueryPool p, uint32_t f, uint32_t n, VkBuffer b, VkDeviceSize o, VkDeviceSize s,
|
||||
VkQueryResultFlags fl), handle(cb), handle(p), put(f), put(n), handle(b), put(o), put(s), put(fl);)
|
||||
|
||||
static VkResult VKAPI_CALL fake_vkBeginCommandBuffer(VkCommandBuffer cb, const VkCommandBufferBeginInfo* bi) {
|
||||
Guard g_(cb, "vkBeginCommandBuffer", false);
|
||||
@@ -725,6 +728,7 @@ static void frame() {
|
||||
const VkPipelineLayout layout = H<VkPipelineLayout>(0x300);
|
||||
vkCmdResetQueryPool(up, H<VkQueryPool>(0x400), 0, 64);
|
||||
vkCmdWriteTimestamp2(cmd, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, H<VkQueryPool>(0x400), 0);
|
||||
vkCmdCopyQueryPoolResults(cmd, H<VkQueryPool>(0x400), 0, 2, H<VkBuffer>(0x410), 64, 8, VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT); // ((Triforce, 11-23))
|
||||
copy_runs(up, 0);
|
||||
copy_runs(up, 2);
|
||||
{
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
// cuttable) gets no verdict, nor the first window after it; a settled heavy scene where the helpers win still turns them on
|
||||
// without a trial, a window after it settled; a trial the scene changed under changes nothing and the next comes soon
|
||||
// after the scene settles. With settled off, each as before.
|
||||
// "calm": (Triforce, 11-22) Tuner::settled's calm scene between trials: no trial on a loading screen (nothing cut), a trial
|
||||
// due during an arrival waits for the calm scene, a scene that never calms still has its trials; the rule's "on" in the
|
||||
// Market's steady texture load (this PC's, fix one's A/B) withdrawn when the area comes down to its settled frames, and kept
|
||||
// where the scene stays; where the helpers win, on again two windows after a withdrawal.
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@@ -283,13 +287,13 @@ void rule_case() {
|
||||
CHECK(v.gain == v.saved && v.gain < 1.0 && v.kind != Verdict::kOn);
|
||||
}
|
||||
// the tuner on each scene, 20,000 presents
|
||||
// (Triforce, 11-22: settled. On at the second window, the first with one before it to tell the scene settled; with
|
||||
// (Triforce, 11-22: settled. On at the third window, the scene held kOnWindows windows (11-23; the second before); with
|
||||
// settled off at the first, as before)
|
||||
const Run heavy = run_scene(test4_heavy, 20000, true, 1);
|
||||
CHECK(heavy.first_on == 2 * Tuner::kWindow); // (on at the second window, without a trial)
|
||||
CHECK(heavy.first_on == Tuner::kOnWindows * Tuner::kWindow); // (on at the third window, without a trial)
|
||||
CHECK(heavy.first_trial > heavy.first_on); // (a trial came after, kEvery later)
|
||||
CHECK(heavy.changes == 0 && heavy.trials >= 6); // (and kept them, 12% shorter frames: no trial took them off)
|
||||
CHECK(heavy.on_frames > 20000 - 240 - (heavy.trials + 1) * (Tuner::kSettle + Tuner::kTake)); // (but in the trials' serial parts)
|
||||
CHECK(heavy.on_frames > 20000 - 360 - (heavy.trials + 1) * (Tuner::kSettle + Tuner::kTake)); // (but in the trials' serial parts)
|
||||
{
|
||||
const Run was = run_scene(test4_heavy, 20000, true, 1, nullptr, false, false);
|
||||
CHECK(was.first_on == Tuner::kWindow && was.first_trial > was.first_on && was.changes == 0 && was.trials >= 6);
|
||||
@@ -312,7 +316,7 @@ void rule_case() {
|
||||
// cannot pay, nothing at the title), the trials fewer where they decide, and none changed the way where it held
|
||||
{
|
||||
const Run h = run_scene(test4_heavy, 20000, true, 1, nullptr, true);
|
||||
CHECK(h.first_on == 2 * Tuner::kWindow && h.first_trial > h.first_on && h.changes == 0);
|
||||
CHECK(h.first_on == Tuner::kOnWindows * Tuner::kWindow && h.first_trial > h.first_on && h.changes == 0);
|
||||
CHECK(h.trials >= 2 && h.trials < heavy.trials);
|
||||
CHECK(h.on_frames > heavy.on_frames); // (fewer frames the other way)
|
||||
const Run g = run_scene(gpu_bound, 20000, true, 2, nullptr, true);
|
||||
@@ -648,7 +652,7 @@ const Scene kokiri{11.66, 7.4, 5.8, 2000, 1900, 4.0, 1.06};
|
||||
|
||||
struct Arrival {
|
||||
int on_verdicts = 0, trials = 0, changes = 0;
|
||||
long long first_on = -1, on_frames = 0;
|
||||
long long first_on = -1, on_frames = 0, first_in_use = -1; // (first_in_use: by the rule or a trial)
|
||||
std::vector<long long> unsettled; // (the presents of the windows the rule did not judge, before the first trial)
|
||||
};
|
||||
/// Kokiri for two windows, the load's window, then `to` (each window the rule's: the first trial comes at present 600)
|
||||
@@ -666,6 +670,7 @@ Arrival run_arrival(const Scene& to, bool settled, uint32_t seed) {
|
||||
if (s.unsettled && !s.trial && !out.trials) out.unsettled.push_back(t.frames());
|
||||
if (s.trial) out.trials++, out.changes += s.better;
|
||||
if (s.flip) on = !on;
|
||||
if (on && out.first_in_use < 0) out.first_in_use = t.frames();
|
||||
out.on_frames += on;
|
||||
}
|
||||
return out;
|
||||
@@ -718,14 +723,17 @@ void settled_case() {
|
||||
"windows not judged before the first trial; the helper threads in %lld of 6,000 frames (%lld)\n",
|
||||
n.on_verdicts, o.on_verdicts, o.first_on, (int)n.unsettled.size(), n.on_frames, o.on_frames);
|
||||
}
|
||||
// a settled heavy scene where the helpers win (test4's): on without a trial, a window after it settled, and kept
|
||||
// a settled heavy scene where the helpers win (test4's): on by its first trial, due at present 600, a window before the
|
||||
// rule's third (11-23: kOnWindows; the rule turned them on at 600 before), and kept
|
||||
{
|
||||
const Arrival n = run_arrival(test4_heavy, true, 62), o = run_arrival(test4_heavy, false, 62);
|
||||
CHECK(n.first_on == 5 * Tuner::kWindow); // (the heavy scene's second window: the first with one like it before)
|
||||
CHECK(n.changes == 0 && n.on_frames > 6000 - 600 - (n.trials + 1) * (Tuner::kSettle + Tuner::kTake));
|
||||
const long long trial_end = 600 + Tuner::kTake + 2 * (Tuner::kSettle + Tuner::kTake);
|
||||
CHECK(n.first_in_use > 0 && n.first_in_use <= trial_end);
|
||||
CHECK(n.changes <= 1 && n.on_frames > 6000 - trial_end - (n.trials + 1) * (Tuner::kSettle + Tuner::kTake));
|
||||
CHECK(o.first_on == 3 * Tuner::kWindow);
|
||||
std::printf("settled: the load's window into test4's heavy scene: the helper threads on at present %lld without a trial "
|
||||
"(%lld with settled off), kept by %d trials\n", n.first_on, o.first_on, n.trials);
|
||||
std::printf("settled: the load's window into test4's heavy scene: the helper threads on at present %lld (%s; %lld with "
|
||||
"settled off, by the rule), kept by %d trials\n", n.first_in_use, n.first_on > 0 ? "by the rule" : "by a trial",
|
||||
o.first_on, n.trials - n.changes);
|
||||
}
|
||||
// a trial the scene changed under: nothing changes, and the next comes soon after the scene settles
|
||||
{
|
||||
@@ -743,6 +751,143 @@ void settled_case() {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- (Triforce, 11-22) "calm": the calm scene between trials, the trial gate and the rule's "on" withdrawn ----
|
||||
|
||||
/// A run of stretches through a tuner with the rule, the back-off and settled (or not): (scene, presents) each; a scene whose
|
||||
/// draws and times slide from one to the next is a stretch of `mix` steps. Counts per stretch index
|
||||
struct Calm {
|
||||
int trials = 0, withdrawn = 0, rule_on = 0;
|
||||
std::vector<int> trials_in, on_in; // (per stretch: trials that ended in it, presents with the helper threads on)
|
||||
std::vector<long long> trial_ends;
|
||||
long long first_on_after_withdrawal = -1, withdrawn_at = -1;
|
||||
};
|
||||
Scene mix(const Scene& a, const Scene& b, double k) {
|
||||
return {a.frame + (b.frame - a.frame) * k, a.replay + (b.replay - a.replay) * k, a.gpu + (b.gpu - a.gpu) * k,
|
||||
a.draws + (b.draws - a.draws) * k, a.cut + (b.cut - a.cut) * k, a.op + (b.op - a.op) * k,
|
||||
a.par_factor + (b.par_factor - a.par_factor) * k};
|
||||
}
|
||||
struct Stretch {
|
||||
Scene from, to; // (to: the scene it slides to over its presents; the same as from for a steady one)
|
||||
int n;
|
||||
};
|
||||
Calm run_calm(const std::vector<Stretch>& stretches, bool settled, uint32_t seed) {
|
||||
Tuner t;
|
||||
t.use_rule = true, t.backoff = true, t.settled = settled, t.threads = 4;
|
||||
std::mt19937 r(seed);
|
||||
bool on = false;
|
||||
Calm out;
|
||||
for (size_t k = 0; k < stretches.size(); k++) {
|
||||
out.trials_in.push_back(0), out.on_in.push_back(0);
|
||||
const Stretch& st = stretches[k];
|
||||
for (int i = 0; i < st.n; i++) {
|
||||
const Scene sc = mix(st.from, st.to, st.n > 1 ? (double)i / (st.n - 1) : 0.0);
|
||||
const Tuner::Step s = t.step(sample(sc, on, r), on, false);
|
||||
if (s.trial) out.trials++, out.trials_in[k]++, out.trial_ends.push_back(t.frames());
|
||||
if (s.withdrawn) out.withdrawn++, out.withdrawn_at = t.frames();
|
||||
if (s.ruled && s.flip) {
|
||||
out.rule_on++;
|
||||
if (out.withdrawn_at >= 0 && out.first_on_after_withdrawal < 0) out.first_on_after_withdrawal = t.frames();
|
||||
}
|
||||
if (s.flip) on = !on;
|
||||
out.on_in[k] += on;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void calm_case() {
|
||||
// (a loading screen: nothing to cut; this PC's settled Market from fix one's A/B, the helpers 12% slower; the arrival's
|
||||
// texture load there, as its log has it: 21.5 ms frames, the replay 17.3 ms of them, 2,174 to 2,537 draws nearly all cut)
|
||||
const Scene loading{4.71, 0.6, 0.9, 6, 0, 0.1, 1.0};
|
||||
const Scene market_here{13.66, 8.44, 6.87, 798, 269, 3.6, 1.12};
|
||||
const Scene market_load{21.5, 17.3, 9.9, 2400, 2200, 12.0, 0.88};
|
||||
CHECK(rule(mean_of(market_load), 4).kind == Verdict::kOn); // (as the log's window at present 13080 has it)
|
||||
// a loading screen after the helper threads went on in a heavy scene: no trial there (both ways the same work)
|
||||
{
|
||||
const std::vector<Stretch> run{{test4_heavy, test4_heavy, 4000}, {loading, loading, 20000}};
|
||||
const Calm n = run_calm(run, true, 71), o = run_calm(run, false, 71);
|
||||
CHECK(n.rule_on == 1 && n.trials_in[1] == 0);
|
||||
CHECK(o.trials_in[1] >= 3);
|
||||
std::printf("calm: a loading screen after the helper threads went on: %d trials in 20,000 presents (%d with settled off)\n",
|
||||
n.trials_in[1], o.trials_in[1]);
|
||||
}
|
||||
// a trial due during an arrival waits for the calm scene: none ends on the arrival's sliding frames
|
||||
{
|
||||
// (test7's busy scene, the trials decide; then 600 presents of an area coming in, its draws and times sliding to the
|
||||
// settled Market's, the next trial due in them; then the Market)
|
||||
const std::vector<Stretch> run{{test7_busy, test7_busy, 1300}, {test7_busy, market_here, 600}, {market_here, market_here, 6000}};
|
||||
const Calm n = run_calm(run, true, 72);
|
||||
CHECK(n.trials_in[0] >= 1 && n.trials_in[1] == 0 && n.trials_in[2] >= 1);
|
||||
std::printf("calm: an arrival with a trial due: %d trials on its sliding frames, %d in the settled scene after it\n",
|
||||
n.trials_in[1], n.trials_in[2]);
|
||||
}
|
||||
// a scene that never calms (two scenes swapped every 60 to 359 presents) still has its trials, kEvery late at most
|
||||
{
|
||||
const Scene a{12.0, 9.6, 8.4, 1500, 1400, 3.4, 1.08}, b{12.0, 9.6, 8.4, 2400, 2250, 3.4, 1.08};
|
||||
std::vector<Stretch> run{{test7_busy, test7_busy, 1000}};
|
||||
std::mt19937 r(73);
|
||||
for (int i = 0, alt = 0; i < 23000; alt = !alt) {
|
||||
const int len = 60 + (int)(r() % 300);
|
||||
run.push_back({alt ? a : b, alt ? a : b, len}), i += len;
|
||||
}
|
||||
const Calm n = run_calm(run, true, 73);
|
||||
long long gap = 0;
|
||||
for (size_t i = 1; i < n.trial_ends.size(); i++) gap = std::max(gap, n.trial_ends[i] - n.trial_ends[i - 1]);
|
||||
// (the longest back-off, its wait for a calm scene and the trial's own frames)
|
||||
CHECK(n.trials >= 10 && gap <= Tuner::kBackoffMax + Tuner::kEvery + Tuner::kTake + 2 * (Tuner::kSettle + Tuner::kTake));
|
||||
std::printf("calm: a scene that never settles: %d trials in 24,000 presents, at most %lld presents apart\n", n.trials, gap);
|
||||
}
|
||||
// the Market's arrival: the rule's "on" in the texture load's steady stretch is withdrawn when the area comes down to its
|
||||
// settled frames, and the settled Market runs on the replay thread alone
|
||||
{
|
||||
const std::vector<Stretch> run{{test7_busy, test7_busy, 3000}, {loading, loading, 300}, {market_load, market_load, 240},
|
||||
{market_load, market_here, 480}, {market_here, market_here, 1200}};
|
||||
const Calm n = run_calm(run, true, 74);
|
||||
CHECK(n.rule_on == 1 && n.withdrawn == 1);
|
||||
// (the settled Market's 1,200 presents: the helper threads off but in a trial's other way at most)
|
||||
CHECK(n.on_in[4] <= Tuner::kSettle + Tuner::kTake);
|
||||
CHECK(n.on_in[3] < 480); // (off during the area's coming down)
|
||||
std::printf("calm: the Market's arrival: the rule's \"on\" in the texture load withdrawn at present %lld, the helper threads "
|
||||
"in %d of the 480 presents coming down and %d of the settled Market's 1,200\n", n.withdrawn_at, n.on_in[3],
|
||||
n.on_in[4]);
|
||||
}
|
||||
// (11-23) the Market's arrival on 0.7 (testq #973, 3 launches): the texture load comes down a window at a time, two windows
|
||||
// alike at ~2,300 draws (the rule's "on" there, 16.6 ms frames, the replay 12.8 ms, 3.6 us a draw), then 1,634, then ~870,
|
||||
// then the settled Market (12.4 ms, the replay 5.6, 652 draws, 138 cut; the helpers ~18% slower, trial 1 of the stock run).
|
||||
// Three windows alike to the first: no "on" in that slide; two alike (kOnWindows 2, the gate before): "on" in it
|
||||
{
|
||||
const Scene field7{11.5, 5.2, 6.0, 700, 150, 2.5, 1.10};
|
||||
const Scene load7{16.6, 12.8, 9.2, 2300, 2200, 8.3, 0.92}, mid7{14.6, 9.9, 8.0, 1634, 1450, 6.0, 1.0},
|
||||
low7{13.4, 6.6, 6.7, 870, 420, 3.4, 1.12}, market7{12.4, 5.6, 6.2, 652, 138, 2.5, 1.18};
|
||||
CHECK(rule(mean_of(load7), 4).kind == Verdict::kOn && rule(mean_of(market7), 4).kind == Verdict::kOff);
|
||||
int on_runs = 0, on_frames = 0;
|
||||
for (uint32_t seed = 0; seed < 20; seed++) {
|
||||
const std::vector<Stretch> run{{field7, field7, 2000}, {loading, loading, 300}, {load7, load7, 240},
|
||||
{mid7, mid7, 120}, {low7, low7, 120}, {market7, market7, 1400}};
|
||||
const Calm n = run_calm(run, true, 80 + seed);
|
||||
on_runs += n.rule_on > 0;
|
||||
for (size_t k = 2; k < n.on_in.size(); k++) on_frames += n.on_in[k];
|
||||
}
|
||||
CHECK(on_runs == 0 && on_frames == 0);
|
||||
std::printf("calm: the Market's arrival on 0.7 (its texture load coming down a window at a time): the rule's \"on\" in %d "
|
||||
"of 20 runs, the helper threads in %d of their arrival and Market frames\n", on_runs, on_frames);
|
||||
}
|
||||
// where the helpers win (test4's): a steady scene keeps the rule's "on" (nothing withdrawn); a change to another heavy scene
|
||||
// where they win withdraws it, and the rule turns them on again kOnWindows windows on
|
||||
{
|
||||
const Calm steady = run_calm({{test4_heavy, test4_heavy, 20000}}, true, 75);
|
||||
CHECK(steady.withdrawn == 0 && steady.on_in[0] > 20000 - Tuner::kOnWindows * Tuner::kWindow - (steady.trials + 1) * (Tuner::kSettle + Tuner::kTake));
|
||||
const Scene heavier{14.5, 12.0, 7.4, 3900, 3700, 9.9, 0.86};
|
||||
CHECK(rule(mean_of(heavier), 4).kind == Verdict::kOn);
|
||||
const Calm n = run_calm({{test4_heavy, test4_heavy, 700}, {heavier, heavier, 3000}}, true, 76);
|
||||
CHECK(n.withdrawn == 1 && n.first_on_after_withdrawal > n.withdrawn_at);
|
||||
CHECK(n.first_on_after_withdrawal - n.withdrawn_at <= Tuner::kOnWindows * Tuner::kWindow);
|
||||
std::printf("calm: test4's heavy scene: %d withdrawn in 20,000 presents; a change to a heavier one: withdrawn at %lld, the "
|
||||
"rule's \"on\" again %lld presents later\n", steady.withdrawn, n.withdrawn_at,
|
||||
n.first_on_after_withdrawal - n.withdrawn_at);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const std::string c = argc > 1 ? argv[1] : "";
|
||||
if (c == "same") same_case();
|
||||
@@ -750,6 +895,7 @@ int main(int argc, char** argv) {
|
||||
else if (c == "rule") rule_case();
|
||||
else if (c == "backoff") backoff_case();
|
||||
else if (c == "settled") settled_case();
|
||||
else if (c == "calm") calm_case();
|
||||
else return std::printf("which case?\n"), 2;
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
|
||||
175
tests/save_file_rows_test.cpp
Normal file
175
tests/save_file_rows_test.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
// gpu/vk/save_file_rows.h alone (tests/test_save_files.py): the files as the host names them, the file chosen and what the
|
||||
// host says of it, and the choice under the keys.
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "save_file_rows.h"
|
||||
|
||||
static int fails;
|
||||
#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0)
|
||||
|
||||
namespace sf = save_file_rows;
|
||||
|
||||
static void say(sf::List& list, const char* text) {
|
||||
for (const char* p = text; *p; p++) list.text((unsigned char)*p);
|
||||
}
|
||||
|
||||
int main() {
|
||||
static sf::List list;
|
||||
// nothing shown, asked or chosen until the list is whole
|
||||
say(list, "Spanky\n2026-11-18 08:41");
|
||||
list.add(sf::kSaved);
|
||||
say(list, "Bukwheat\n");
|
||||
list.add(sf::kSaved | sf::kCurrent | 64);
|
||||
list.add(0); // (no name, no save)
|
||||
CHECK(list.shown() == 0 && !list.asks() && list.current() == -1 && !list.choose(0) && list.take_ask() == 0);
|
||||
list.done(3);
|
||||
CHECK(list.shown() == 3 && list.asks() && list.current() == 1);
|
||||
CHECK(!strcmp(list.names[0], "Spanky") && !strcmp(list.whens[0], "2026-11-18 08:41") && list.saved(0));
|
||||
CHECK(!strcmp(list.names[1], "Bukwheat") && !list.whens[1][0] && list.saved(1) && list.bits[1] == (sf::kSaved | sf::kCurrent));
|
||||
CHECK(!strcmp(list.names[2], "(no name)") && !list.saved(2) && !list.saved(3) && !list.saved(-1));
|
||||
// a list sent again changes nothing
|
||||
say(list, "Again\n");
|
||||
list.add(sf::kCurrent);
|
||||
list.done(1);
|
||||
CHECK(list.shown() == 3 && list.current() == 1 && !strcmp(list.names[0], "Spanky"));
|
||||
|
||||
// the file this run plays: played at once, nothing asked of the host
|
||||
CHECK(list.choose(1) && list.take_ask() == 0);
|
||||
// another: asked of the host, once; its word taken once
|
||||
CHECK(!list.choose(0) && list.take_ask() == 1 && list.take_ask() == 0 && list.take_said() == sf::kNothing);
|
||||
list.said(1);
|
||||
CHECK(list.take_said() == sf::kRestart && list.take_said() == sf::kNothing);
|
||||
CHECK(!list.choose(2) && list.take_ask() == 3);
|
||||
list.said(2);
|
||||
CHECK(list.take_said() == sf::kFailed);
|
||||
list.said(7);
|
||||
CHECK(list.take_said() == sf::kNothing);
|
||||
list.said(1);
|
||||
CHECK(!list.choose(0) && list.take_said() == sf::kNothing); // (a word that came before this ask is not its answer)
|
||||
CHECK(!list.choose(3) && !list.choose(-1) && list.take_ask() == 1 && list.take_ask() == 0); // (no such file: nothing more asked)
|
||||
|
||||
// the start that follows a choice: the title asks there too; fewer files than named, and more than there is room for
|
||||
static sf::List after;
|
||||
say(after, "One\n");
|
||||
after.add(sf::kCurrent);
|
||||
say(after, "Two\n");
|
||||
after.add(0);
|
||||
after.done(2 | sf::kChosen);
|
||||
CHECK(after.shown() == 2 && after.asks() && after.chosen() && after.current() == 0 && !list.chosen());
|
||||
static sf::List many;
|
||||
for (int i = 0; i < 6; i++) many.text('a' + i), many.add(0);
|
||||
many.done(6);
|
||||
CHECK(many.shown() == sf::kSlots && many.asks() && many.current() == -1 && !many.choose(0) && many.take_ask() == 1);
|
||||
// a name longer than its room: cut, never inside a letter
|
||||
static sf::List wide;
|
||||
for (int i = 0; i < 23; i++) wide.text('n');
|
||||
wide.text(0xC3), wide.text(0xA9), wide.text('\n');
|
||||
for (int i = 0; i < 60; i++) wide.text('w');
|
||||
wide.add(0);
|
||||
wide.done(1);
|
||||
CHECK(strlen(wide.names[0]) == 23 && strlen(wide.whens[0]) <= (size_t)sf::kWhen - 1);
|
||||
|
||||
// a file's picture and its card: the file the picture is in; where it was played last, its stones and medallions, its hearts
|
||||
static sf::List cards;
|
||||
say(cards, "One\n11/18/2026 1:40 a.m.\nC:\\Games\\Triforce\\user\\save\\0123\\slot_03\\caption.sav\nKokiri Forest|1c9|7");
|
||||
cards.add(sf::kSaved | sf::kCurrent);
|
||||
say(cards, "Two\n\n\n|0|0");
|
||||
cards.add(0);
|
||||
say(cards, "Three\n\n\nLake Hylia|ffff|21"); // (bits that are no item's, and more hearts than there are: not kept)
|
||||
cards.add(0);
|
||||
cards.done(3);
|
||||
CHECK(!strcmp(cards.pictures[0], "C:\\Games\\Triforce\\user\\save\\0123\\slot_03\\caption.sav") && !strcmp(cards.whens[0], "11/18/2026 1:40 a.m."));
|
||||
CHECK(!strcmp(cards.places[0], "Kokiri Forest") && cards.items[0] == 0x1c9 && cards.hearts[0] == 7);
|
||||
CHECK(cards.slots[0] == -1 && !cards.made[0][0] && cards.slots[1] == -1 && cards.slots[2] == -1); // (a card without the slot saved in last)
|
||||
static sf::List slotted; // (the slot the game saved in last, and when: a slot that is none is not known)
|
||||
say(slotted, "A\n\n\nKokiri Forest|1c9|7|3|11/18/2026 1:43 a.m.");
|
||||
slotted.add(sf::kSaved);
|
||||
say(slotted, "B\n\n\nLake Hylia|0|3|-1|");
|
||||
slotted.add(sf::kSaved);
|
||||
say(slotted, "C\n\n\nLake Hylia|0|3|12|11/18/2026 1:43 a.m.");
|
||||
slotted.add(sf::kSaved);
|
||||
slotted.done(3);
|
||||
CHECK(slotted.slots[0] == 3 && !strcmp(slotted.made[0], "11/18/2026 1:43 a.m.") && slotted.hearts[0] == 7 && !strcmp(slotted.places[0], "Kokiri Forest"));
|
||||
CHECK(slotted.slots[1] == -1 && !slotted.made[1][0] && slotted.hearts[1] == 3 && slotted.slots[2] == -1 && !slotted.made[2][0]);
|
||||
CHECK(!cards.pictures[1][0] && !cards.places[1][0] && !cards.items[1] && !cards.hearts[1] && !strcmp(cards.names[1], "Two"));
|
||||
CHECK(!strcmp(cards.places[2], "Lake Hylia") && cards.items[2] == 0x1ff && cards.hearts[2] == 0);
|
||||
static sf::List bare; // (a host that sends no card, and one whose card has no bars: nothing of it)
|
||||
say(bare, "Old\n\n");
|
||||
bare.add(0);
|
||||
say(bare, "Odd\n\n\nno bars here");
|
||||
bare.add(0);
|
||||
bare.done(2);
|
||||
CHECK(!bare.places[0][0] && !bare.items[0] && !bare.places[1][0] && !bare.hearts[1] && bare.shown() == 2);
|
||||
// a save's picture among a file's bytes: from the first FF D8 FF to the last FF D9 after it
|
||||
{
|
||||
const unsigned char file[] = {1, 2, 0xFF, 0xD9, 3, 0xFF, 0xD8, 0xFF, 0xE0, 9, 9, 0xFF, 0xD9, 9, 0xFF, 0xD9, 7, 7};
|
||||
size_t at = 0, len = 0;
|
||||
CHECK(sf::jpeg_in(file, sizeof file, &at, &len) && at == 5 && len == 11);
|
||||
CHECK(!sf::jpeg_in(file, 7, &at, &len) && !sf::jpeg_in(file, 12, &at, &len) && sf::jpeg_in(file, 13, &at, &len) && at == 5 && len == 8);
|
||||
const unsigned char none[] = {0xFF, 0xD9, 0xFF, 0xD8, 0, 0xFF, 0xD8};
|
||||
CHECK(!sf::jpeg_in(none, sizeof none, &at, &len) && !sf::jpeg_in(none, 0, &at, &len) && !sf::jpeg_in(file + 5, 3, &at, &len));
|
||||
}
|
||||
|
||||
// when a save was made, as its caption has it: a calendar time outside the picture, the latest of those found
|
||||
{
|
||||
unsigned char file[96] = {};
|
||||
const unsigned char early[] = {0xEA, 0x07, 11, 18, 1, 28, 9}, late[] = {0xEA, 0x07, 11, 18, 1, 43, 5}; // (2026-11-18 01:28:09, 01:43:05)
|
||||
memcpy(file + 4, early, 7), memcpy(file + 80, late, 7);
|
||||
sf::SaveTime t = sf::caption_time(file, sizeof file, 20, 40, 2026, 4102444800LL); // (the picture: bytes 20 to 59)
|
||||
CHECK(t.kind == 1 && t.year == 2026 && t.month == 11 && t.day == 18 && t.hour == 1 && t.minute == 43 && t.second == 5);
|
||||
memcpy(file + 30, "\xEA\x07\x0C\x1F\x17\x3B\x3B", 7); // (a later one inside the picture: not a time)
|
||||
t = sf::caption_time(file, sizeof file, 20, 40, 2026, 4102444800LL);
|
||||
CHECK(t.kind == 1 && t.minute == 43);
|
||||
t = sf::caption_time(file, 40, 20, 20, 2026, 4102444800LL); // (cut short of the later one)
|
||||
CHECK(t.kind == 1 && t.minute == 28);
|
||||
// what is no time: a year, month, day, hour, minute or second out of range
|
||||
const unsigned char bad[][7] = {{0xE0, 0x07, 11, 18, 1, 28, 9}, {0x35, 0x08, 1, 1, 0, 0, 0}, {0xEA, 0x07, 0, 18, 1, 28, 9}, {0xEA, 0x07, 13, 18, 1, 28, 9},
|
||||
{0xEA, 0x07, 11, 0, 1, 28, 9}, {0xEA, 0x07, 11, 32, 1, 28, 9}, {0xEA, 0x07, 11, 18, 24, 28, 9},
|
||||
{0xEA, 0x07, 11, 18, 1, 60, 9}, {0xEA, 0x07, 11, 18, 1, 28, 60}};
|
||||
for (const auto& b : bad) {
|
||||
unsigned char one[16] = {};
|
||||
memset(one, 0xFF, sizeof one), memcpy(one + 3, b, 7);
|
||||
CHECK(sf::caption_time(one, sizeof one, sizeof one, 0, 2026, 4102444800LL).kind == 0);
|
||||
}
|
||||
// a time that cannot be a save's: of a year to come (2093, among a caption's other bytes), or before this game
|
||||
{
|
||||
unsigned char one[16] = {};
|
||||
memcpy(one + 2, "\x2D\x08\x09\x19\x09\x15\x00", 7); // (2093-09-25 09:21:00)
|
||||
CHECK(sf::caption_time(one, sizeof one, sizeof one, 0, 2026, 4102444800LL).kind == 0 && sf::caption_time(one, sizeof one, sizeof one, 0, 2093, 4102444800LL).kind == 1);
|
||||
memcpy(one + 2, "\xE8\x07\x09\x19\x09\x15\x00", 7); // (2024)
|
||||
CHECK(sf::caption_time(one, sizeof one, sizeof one, 0, 2026, 4102444800LL).kind == 0);
|
||||
const unsigned char later[] = {0x16, 0xCD, 0x5B, 0x69, 0, 0, 0, 0};
|
||||
unsigned char two[16];
|
||||
memset(two, 0xFF, sizeof two), memcpy(two + 4, later, 8);
|
||||
CHECK(sf::caption_time(two, sizeof two, sizeof two, 0, 2026, 0x695BCD15).kind == 0 && sf::caption_time(two, sizeof two, sizeof two, 0, 2026, 0x695BCD16).kind == 2);
|
||||
}
|
||||
// no calendar time: a count of seconds since 1970, 64 bits, its upper half 0; the latest; none outside 2017 to 2100
|
||||
unsigned char secs[64];
|
||||
memset(secs, 0xFF, sizeof secs);
|
||||
const unsigned char a[] = {0x15, 0xCD, 0x5B, 0x69, 0, 0, 0, 0}, b2[] = {0x16, 0xCD, 0x5B, 0x69, 0, 0, 0, 0}, old[] = {0x00, 0x00, 0x00, 0x40, 0, 0, 0, 0};
|
||||
memcpy(secs + 8, a, 8), memcpy(secs + 24, b2, 8), memcpy(secs + 40, old, 8);
|
||||
t = sf::caption_time(secs, sizeof secs, sizeof secs, 0, 2026, 4102444800LL);
|
||||
CHECK(t.kind == 2 && t.seconds == 0x695BCD16);
|
||||
CHECK(sf::caption_time(secs, 8, 8, 0, 2026, 4102444800LL).kind == 0 && sf::caption_time(secs, 0, 0, 0, 2026, 4102444800LL).kind == 0);
|
||||
// which of two saves is the later; one that tells a time is later than one that tells none
|
||||
sf::SaveTime x, y, none;
|
||||
x.kind = y.kind = 1, x.year = y.year = 2026, x.month = y.month = 11, x.day = 18, y.day = 17, y.hour = 23;
|
||||
CHECK(x.after(y) && !y.after(x) && !x.after(x) && x.after(none) && !none.after(x) && !none.after(none));
|
||||
char text[32];
|
||||
sf::game_time(text, sizeof text, 2026, 11, 18, 1, 40);
|
||||
CHECK(!strcmp(text, "11/18/2026 1:40 a.m."));
|
||||
sf::game_time(text, sizeof text, 2026, 1, 5, 0, 5); CHECK(!strcmp(text, "1/5/2026 12:05 a.m."));
|
||||
sf::game_time(text, sizeof text, 2026, 1, 5, 12, 0); CHECK(!strcmp(text, "1/5/2026 12:00 p.m."));
|
||||
sf::game_time(text, sizeof text, 2026, 1, 5, 23, 59); CHECK(!strcmp(text, "1/5/2026 11:59 p.m."));
|
||||
}
|
||||
|
||||
// the choice: Up and Down, Home and End, kept to the files
|
||||
int choice = 0;
|
||||
CHECK(!sf::move(choice, -1, false, false, 3) && choice == 0 && sf::move(choice, 1, false, false, 3) && choice == 1);
|
||||
CHECK(sf::move(choice, 5, false, false, 3) && choice == 2 && !sf::move(choice, 1, false, false, 3));
|
||||
CHECK(sf::move(choice, 0, true, false, 3) && choice == 0 && sf::move(choice, 0, false, true, 3) && choice == 2);
|
||||
CHECK(!sf::move(choice, 1, false, false, 0) && choice == 2);
|
||||
|
||||
if (!fails) printf("PASS\n");
|
||||
return fails != 0;
|
||||
}
|
||||
216
tests/save_files_host_test.c
Normal file
216
tests/save_files_host_test.c
Normal file
@@ -0,0 +1,216 @@
|
||||
/* Save files on the host's side: host/save_files.c's own text (save_files_actual.inc, cut by tests/test_save_files.py)
|
||||
against a stand-in menu, a stand-in for the files' folders and a game folder of the test's. Run four times: "off"
|
||||
with HOS_SAVE_FILES=0, then "first" without it (on by default since 11-23), then "first", "second" and "third" with it on the same folder, each a start of the game. */
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
static int fails;
|
||||
#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0)
|
||||
|
||||
/* ---- what host/save_files.c takes from hos.h, hos_paths.h and windows.h ---- */
|
||||
#define MAX_PATH 260
|
||||
typedef unsigned long DWORD;
|
||||
typedef void *HANDLE;
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE)(intptr_t)-1)
|
||||
#define MOVEFILE_REPLACE_EXISTING 1
|
||||
#define S 1000000000LL
|
||||
typedef struct { DWORD dwLowDateTime, dwHighDateTime; } FILETIME;
|
||||
typedef struct { FILETIME ftLastWriteTime; char cFileName[MAX_PATH]; } WIN32_FIND_DATAA;
|
||||
static int MoveFileExA(const char *from, const char *to, int flags) {
|
||||
(void)flags;
|
||||
remove(to);
|
||||
return rename(from, to) == 0;
|
||||
}
|
||||
/* the files' folders: which have a save, when its account.sav was written (unix time; 0: the time is not told), and
|
||||
when each of its slots' caption.sav was (0: no such slot) */
|
||||
static int has_save[3];
|
||||
static int64_t save_time[3], slot_time[3][12];
|
||||
static int finds;
|
||||
static int file_of(const char *pattern) { return strstr(pattern, "user-3\\save\\") ? 2 : strstr(pattern, "user-2\\save\\") ? 1 : strstr(pattern, "user\\save\\") ? 0 : -1; }
|
||||
static HANDLE FindFirstFileA(const char *pattern, WIN32_FIND_DATAA *fd) {
|
||||
const int file = file_of(pattern);
|
||||
finds++;
|
||||
CHECK(file >= 0);
|
||||
memset(fd, 0, sizeof *fd);
|
||||
if (file < 0 || !has_save[file]) return INVALID_HANDLE_VALUE;
|
||||
if (strstr(pattern, "\\save\\*")) {
|
||||
snprintf(fd->cFileName, sizeof fd->cFileName, "."); /* (the folder itself first, as a listing has it) */
|
||||
return (HANDLE)(intptr_t)(100 + file);
|
||||
}
|
||||
const char *slot = strstr(pattern, "\\save\\0123456789abcdef0123456789abcdef\\slot_");
|
||||
CHECK(slot || strstr(pattern, "\\save\\0123456789abcdef0123456789abcdef\\account.sav") != NULL);
|
||||
CHECK(!slot || !strcmp(slot + 46, "\\caption.sav")); /* (a slot's caption is named, never opened here; its progress never) */
|
||||
const int64_t at = slot ? slot_time[file][atoi(slot + 44) % 12] : save_time[file];
|
||||
if (slot && !at) return INVALID_HANDLE_VALUE;
|
||||
const uint64_t ft = at ? (uint64_t)at * 10000000ULL + 116444736000000000ULL : 0;
|
||||
fd->ftLastWriteTime.dwLowDateTime = (DWORD)(ft & 0xffffffffu), fd->ftLastWriteTime.dwHighDateTime = (DWORD)(ft >> 32);
|
||||
return (HANDLE)(intptr_t)(200 + file);
|
||||
}
|
||||
static int FindNextFileA(HANDLE h, WIN32_FIND_DATAA *fd) {
|
||||
if ((intptr_t)h < 100 || (intptr_t)h >= 200 || fd->cFileName[0] != '.') return 0;
|
||||
snprintf(fd->cFileName, sizeof fd->cFileName, "0123456789abcdef0123456789abcdef");
|
||||
return 1;
|
||||
}
|
||||
static int FindClose(HANDLE h) { (void)h; return 1; }
|
||||
static char logged[1 << 14];
|
||||
static void hos_log(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
const size_t at = strlen(logged);
|
||||
vsnprintf(logged + at, sizeof logged - at - 2, fmt, ap);
|
||||
va_end(ap);
|
||||
strcat(logged, "\n");
|
||||
}
|
||||
static int said(const char *text) { return strstr(logged, text) != NULL; }
|
||||
|
||||
/* ---- the menu's side of HOS_OPT_FILES_* (gpu/vk/save_file_rows.h is tested by itself) ---- */
|
||||
#include "save_files_constants.inc"
|
||||
static int renderer, asked, ask_next; /* renderer 0: none yet (rx_option answers what it is given) */
|
||||
static char incoming[1200], row_text[8][1200];
|
||||
static int incoming_n, row_bits[8], rows_added, rows_count = -1, answers[8], nanswers;
|
||||
int rx_option(int id, int otherwise) {
|
||||
asked++;
|
||||
CHECK(id == HOS_OPT_FILES_ASK);
|
||||
if (!renderer) return otherwise;
|
||||
const int ask = ask_next;
|
||||
ask_next = 0;
|
||||
return ask;
|
||||
}
|
||||
void rx_option_set(int id, int value) {
|
||||
CHECK(renderer);
|
||||
if (id == HOS_OPT_FILES_TEXT) {
|
||||
CHECK(value > 0 && value < 256 && incoming_n + 1 < (int)sizeof incoming);
|
||||
incoming[incoming_n++] = (char)value;
|
||||
} else if (id == HOS_OPT_FILES_ADD) {
|
||||
incoming[incoming_n] = 0, incoming_n = 0;
|
||||
CHECK(rows_count < 0 && rows_added < 8);
|
||||
snprintf(row_text[rows_added], sizeof row_text[0], "%s", incoming);
|
||||
row_bits[rows_added++] = value;
|
||||
} else if (id == HOS_OPT_FILES_COUNT) {
|
||||
CHECK(rows_count < 0 && !incoming_n);
|
||||
rows_count = value;
|
||||
} else if (id == HOS_OPT_FILES_SAID) {
|
||||
CHECK(rows_count >= 0 && nanswers < 8);
|
||||
answers[nanswers++] = value;
|
||||
} else CHECK(!"an option of another feature set");
|
||||
}
|
||||
|
||||
#include "save_files.h"
|
||||
#include "save_files_actual.inc"
|
||||
|
||||
static char file_text[2048];
|
||||
static const char *file(const char *dir, const char *name) { /* a file of the game folder as it is now ("" when there is none) */
|
||||
char path[600];
|
||||
snprintf(path, sizeof path, "%s/%s", dir, name);
|
||||
FILE *f = fopen(path, "rb");
|
||||
file_text[f ? fread(file_text, 1, sizeof file_text - 1, f) : 0] = 0;
|
||||
if (f) fclose(f);
|
||||
return file_text;
|
||||
}
|
||||
static const char *file_at(const char *path) { /* a file by its whole path, as the host names it */
|
||||
FILE *f = fopen(path, "rb");
|
||||
file_text[f ? fread(file_text, 1, sizeof file_text - 1, f) : 0] = 0;
|
||||
if (f) fclose(f);
|
||||
return file_text;
|
||||
}
|
||||
static int ends(const char *text, const char *end) { return strlen(text) >= strlen(end) && !strcmp(text + strlen(text) - strlen(end), end); }
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 3) return 2;
|
||||
const char *game = argv[1], *mode = argv[2];
|
||||
char base[400];
|
||||
snprintf(base, sizeof base, "%s\\user", game);
|
||||
has_save[0] = 1, save_time[0] = 1763456789;
|
||||
slot_time[0][0] = 1763456000, slot_time[0][3] = 1763456789, slot_time[0][5] = 1763456789; /* (slots 3 and 5 written together, last) */
|
||||
const char *dir = hos_save_files_start(game, base);
|
||||
if (!strcmp(mode, "off")) { /* HOS_SAVE_FILES=0: the game's own folder, nothing read, written, said or asked of the menu */
|
||||
renderer = 1, ask_next = 2;
|
||||
CHECK(!hos_save_files_on() && dir == base);
|
||||
hos_save_files_frame(), hos_save_files_frame();
|
||||
hos_save_card_note("KokiriForest", 1, 12, 100 * S); /* (and no card kept) */
|
||||
CHECK(!asked && !finds && !logged[0] && !rows_added && rows_count < 0 && !nanswers && !file(game, "triforce_files.txt")[0]);
|
||||
} else if (!strcmp(mode, "first")) { /* no triforce_files.txt yet: file 1, the game's own folder, and no file made for that */
|
||||
CHECK(hos_save_files_on() && !strcmp(dir, base) && said("save files: file 1 of 3, \"File 1\": its saves are in ") && !said("chosen at the title"));
|
||||
CHECK(!file(game, "triforce_files.txt")[0]);
|
||||
hos_save_files_frame(); /* (no renderer yet: nothing named) */
|
||||
CHECK(asked == 1 && !rows_added && !finds);
|
||||
renderer = 1;
|
||||
hos_save_files_frame(); /* the files named, whole: name, when last saved; which has a save, which is this run's */
|
||||
CHECK(rows_added == 3 && rows_count == 3 && !nanswers);
|
||||
/* (when it was last saved, as the game's load list writes a time: 11/18/2025 1:06 a.m.) */
|
||||
const char *when_end = strstr(row_text[0], ".m.\n");
|
||||
CHECK(!strncmp(row_text[0], "File 1\n1", 8) && when_end && strstr(row_text[0], "/2025 ") && row_bits[0] == (HOS_FILE_SAVED | HOS_FILE_CURRENT));
|
||||
/* (where its slots are, up to a slot's number: the menu reads each one's picture and time itself; no card kept for it yet) */
|
||||
CHECK(when_end && !strncmp(when_end + 4, base, strlen(base)) && ends(row_text[0], "\\user\\save\\0123456789abcdef0123456789abcdef\\slot_\n|0|0|-1|"));
|
||||
CHECK(!strcmp(row_text[1], "File 2\n\n\n|0|0|-1|") && row_bits[1] == 0 && !strcmp(row_text[2], "File 3\n\n\n|0|0|-1|") && row_bits[2] == 0);
|
||||
hos_save_files_frame();
|
||||
CHECK(rows_added == 3); /* (named once) */
|
||||
/* a file that is none, and this run's own: nothing kept, nothing said */
|
||||
ask_next = 9, hos_save_files_frame(), ask_next = 1, hos_save_files_frame();
|
||||
CHECK(!nanswers && !file(game, "triforce_files.txt")[0]);
|
||||
/* another file: kept as the next start's, with the time, and the menu told */
|
||||
ask_next = 2, hos_save_files_frame();
|
||||
CHECK(nanswers == 1 && answers[0] == 1 && said("save files: file 2, \"File 2\", chosen: the game starts again on it"));
|
||||
CHECK(strstr(file(game, "triforce_files.txt"), "\ncurrent=2\n") && strstr(file_text, "\nchosen=1") && !file(game, "triforce_files.txt.new")[0]);
|
||||
/* this run goes on with its own file: the same choice again is asked for again (the restart had not come yet) */
|
||||
ask_next = 2, hos_save_files_frame();
|
||||
CHECK(nanswers == 2 && answers[1] == 1);
|
||||
} else if (!strcmp(mode, "second")) { /* the start that follows the choice: file 2's folder, and the menu told that it is that restart */
|
||||
has_save[1] = 1, save_time[1] = 0;
|
||||
CHECK(ends(dir, "\\user-2") && !strncmp(dir, base, strlen(base)) && said("file 2 of 3, \"File 2\"") && said("(chosen at the title: the game restarted for it)"));
|
||||
CHECK(strstr(file(game, "triforce_files.txt"), "\ncurrent=2\n") && !strstr(file_text, "chosen")); /* (the choice is taken) */
|
||||
renderer = 1;
|
||||
hos_save_files_frame();
|
||||
/* (file 2: started on, its account.sav made, nothing saved in it yet: no save, as its card says) */
|
||||
CHECK(rows_count == (3 | HOS_FILES_CHOSEN) && row_bits[0] == HOS_FILE_SAVED && row_bits[1] == HOS_FILE_CURRENT);
|
||||
CHECK(!strcmp(row_text[1], "File 2\n\n\n|0|0|-1|")); /* (a save whose time is not told: no time shown; no slot found: no picture) */
|
||||
} else { /* a later start: the same file, the names the player gave, and the title asks again (an old choice is none) */
|
||||
CHECK(ends(dir, "\\user-2") && said("file 2 of 3, \"Bukwheat\"") && !said("chosen at the title"));
|
||||
CHECK(!strstr(file(game, "triforce_files.txt"), "chosen") && strstr(file_text, "\n1=Spanky\n2=Bukwheat\n3=File 3\n"));
|
||||
renderer = 1;
|
||||
hos_save_files_frame();
|
||||
/* (file 2's card, as its folder kept it when it was last played: its place, its stones and medallions, its hearts) */
|
||||
CHECK(rows_count == 3 && !strncmp(row_text[0], "Spanky\n", 7) && strstr(row_text[0], ".m.\n") && row_bits[1] == HOS_FILE_CURRENT);
|
||||
CHECK(!strcmp(row_text[1], "Bukwheat\n\n\nKokiri Forest|1c9|7|-1|") && ends(row_text[0], "\\slot_\n|0|0|-1|") && !strcmp(row_text[2], "File 3\n\n\n|0|0|-1|"));
|
||||
/* the file played: what the game tells of it is kept in its folder when it is not what is kept there already, and
|
||||
not more often than every five seconds; a map with no name (no save loaded) is not a place */
|
||||
char card[700];
|
||||
snprintf(card, sizeof card, "%s\\user-2\\triforce_card.txt", game);
|
||||
hos_save_card_note("KokiriForest", 0x1c9, 28, 10 * S);
|
||||
CHECK(strstr(file_at(card), "place=Kokiri Forest\r\nitems=1c9\r\nhearts=7")); /* (as it was: the test's own bytes, not written again) */
|
||||
hos_save_card_note("", 0, 0, 11 * S), hos_save_card_note(NULL, 0, 0, 11 * S);
|
||||
hos_save_card_note("DeathMountain_Crater", 0x1cb, 32, 12 * S);
|
||||
CHECK(strstr(file_at(card), "\nplace=Death Mountain Crater\nitems=1cb\nhearts=8\n") && file_text[0] == '#');
|
||||
hos_save_card_note("LakeHylia", 0x1cb, 32, 13 * S); /* (too soon after the last) */
|
||||
CHECK(strstr(file_at(card), "place=Death Mountain Crater\n"));
|
||||
hos_save_card_note("LakeHylia", 0xffff, 33, 18 * S); /* (bits that are no item's are not kept; a life that is no count of hearts: none) */
|
||||
CHECK(strstr(file_at(card), "\nplace=Lake Hylia\nitems=1ff\nhearts=0\n"));
|
||||
/* the game saves: a slot's file opened to be written is the slot saved in last, kept with the card and its time; a
|
||||
path that names no slot is none */
|
||||
hos_save_card_wrote("save:/option.sav"), hos_save_card_wrote("save:/slot_12/caption.sav"), hos_save_card_wrote(NULL);
|
||||
hos_save_card_note("LakeHylia", 0x1ff, 33, 24 * S);
|
||||
CHECK(!strstr(file_at(card), "slot="));
|
||||
/* (kept at once, with what was last told: a save made in the pause menu, where Link is not updated, and the game closed) */
|
||||
hos_save_card_note("ZoraDomain", 0x1ff, 16, 22 * S); /* (told, under five seconds after the last write: not kept by itself) */
|
||||
CHECK(strstr(file_at(card), "place=Lake Hylia\n"));
|
||||
hos_save_card_wrote("save:/slot_03/caption.sav");
|
||||
CHECK(strstr(file_at(card), "\nplace=Zora Domain\nitems=1ff\nhearts=4\nslot=3\nsaved=1"));
|
||||
const size_t once = strlen(file_text);
|
||||
hos_save_card_wrote("save:/slot_03/progress.sav"); /* (the same save's other file: the same time) */
|
||||
CHECK(strlen(file_at(card)) == once);
|
||||
hos_save_card_note("LakeHylia", 0x1ff, 33, 30 * S);
|
||||
CHECK(strstr(file_at(card), "\nplace=Lake Hylia\nitems=1ff\nhearts=0\nslot=3\nsaved=1") && !said("could not be written"));
|
||||
hos_save_card_wrote("save:/slot_01/caption.sav"); /* (another slot: that one, with the place as last told) */
|
||||
CHECK(strstr(file_at(card), "\nplace=Lake Hylia\nitems=1ff\nhearts=0\nslot=1\nsaved=1"));
|
||||
snprintf(card, sizeof card, "%s\\user-2\\triforce_card.txt.new", game);
|
||||
CHECK(!file_at(card)[0] && !said("could not be written"));
|
||||
ask_next = 1, hos_save_files_frame(); /* back to file 1 */
|
||||
CHECK(nanswers == 1 && answers[0] == 1 && strstr(file(game, "triforce_files.txt"), "\ncurrent=1\n") && strstr(file_text, "\n2=Bukwheat\n"));
|
||||
}
|
||||
if (!fails) printf("PASS\n");
|
||||
return fails != 0;
|
||||
}
|
||||
115
tests/save_files_test.c
Normal file
115
tests/save_files_test.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/* host/save_files.h alone (tests/test_save_files.py): the form of triforce_files.txt and what is not taken from it, the
|
||||
files' folders, and the start that follows a choice. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "save_files.h"
|
||||
|
||||
static int fails;
|
||||
#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0)
|
||||
|
||||
int main(void) {
|
||||
SaveFiles f, g;
|
||||
char text[512], dir[64];
|
||||
|
||||
/* no file, or an empty one: file 1, and the names "File N" */
|
||||
save_files_parse(&f, "");
|
||||
CHECK(f.current == 0 && f.chosen == 0 && !strcmp(f.names[0], "File 1") && !strcmp(f.names[1], "File 2") && !strcmp(f.names[2], "File 3"));
|
||||
|
||||
/* its three lines, in any order, with Windows' line ends; what is none of them is passed over */
|
||||
save_files_parse(&f, "# a note\r\n2=Bukwheat\r\ncurrent=2\r\nchosen=1763456789\r\nsomething else\r\n1=Spanky \r\n=x\n4=No such file\n0=Nor this\n");
|
||||
CHECK(f.current == 1 && f.chosen == 1763456789 && !strcmp(f.names[0], "Spanky") && !strcmp(f.names[1], "Bukwheat") && !strcmp(f.names[2], "File 3"));
|
||||
|
||||
/* a file's number that is none: file 1; a time that is none: no choice; a name that is empty or has a control: not taken */
|
||||
save_files_parse(&f, "current=0\nchosen=-5\n1=\n2=a\tb\n3=Last line, no line feed");
|
||||
CHECK(f.current == 0 && f.chosen == 0 && !strcmp(f.names[0], "File 1") && !strcmp(f.names[1], "File 2") && !strcmp(f.names[2], "Last line, no line feed"));
|
||||
save_files_parse(&f, "current=4\n");
|
||||
CHECK(f.current == 0);
|
||||
save_files_parse(&f, "current=3\ncurrent=x\n");
|
||||
CHECK(f.current == 2);
|
||||
|
||||
/* a name cut at SAVE_FILE_NAME bytes, never inside a letter */
|
||||
save_files_parse(&f, "1=abcdefghijklmnopqrstuvwxyz\n2=abcdefghijklmnopqrstuvw\xc3\xa9z\n");
|
||||
CHECK(!strcmp(f.names[0], "abcdefghijklmnopqrstuvwx") && strlen(f.names[0]) == SAVE_FILE_NAME);
|
||||
CHECK(!strcmp(f.names[1], "abcdefghijklmnopqrstuvw")); /* (23 letters and a letter of two bytes: 25, one too many) */
|
||||
|
||||
/* written and read back */
|
||||
save_files_parse(&f, "current=3\nchosen=1700000000\n1=Spanky\n3=Third one\n");
|
||||
const size_t n = save_files_write(&f, text, sizeof text);
|
||||
CHECK(n == strlen(text) && text[0] == '#' && strstr(text, "\ncurrent=3\n") && strstr(text, "\nchosen=1700000000\n") && strstr(text, "\n1=Spanky\n2=File 2\n3=Third one\n"));
|
||||
save_files_parse(&g, text);
|
||||
CHECK(!memcmp(&f, &g, sizeof f));
|
||||
f.chosen = 0;
|
||||
CHECK(save_files_write(&f, text, sizeof text) && !strstr(text, "chosen")); /* (no choice: no line) */
|
||||
CHECK(save_files_write(&f, text, 20) == 0 && save_files_write(&f, text, 100) == 0);
|
||||
|
||||
/* the folders: file 1 the game's own, the others its name with their number */
|
||||
CHECK(save_files_folder("C:\\Games\\Triforce\\user", 0, dir, sizeof dir) && !strcmp(dir, "C:\\Games\\Triforce\\user"));
|
||||
CHECK(save_files_folder("C:\\Games\\Triforce\\user", 1, dir, sizeof dir) && !strcmp(dir, "C:\\Games\\Triforce\\user-2"));
|
||||
CHECK(save_files_folder("/home/me/.local/share/hookshot/", 2, dir, sizeof dir) && !strcmp(dir, "/home/me/.local/share/hookshot-3"));
|
||||
CHECK(save_files_folder("user\\", 0, dir, sizeof dir) && !strcmp(dir, "user"));
|
||||
CHECK(!save_files_folder("user", 3, dir, sizeof dir) && !save_files_folder("user", -1, dir, sizeof dir));
|
||||
CHECK(!save_files_folder("user", 1, dir, 6) && save_files_folder("user", 1, dir, 7) && !save_files_folder("user", 0, dir, 4));
|
||||
|
||||
/* the start that follows a choice: within SAVE_FILES_CHOSEN_S of it, and not before it */
|
||||
f.chosen = 1000;
|
||||
CHECK(save_files_chosen_now(&f, 1000) && save_files_chosen_now(&f, 1000 + SAVE_FILES_CHOSEN_S) && !save_files_chosen_now(&f, 1001 + SAVE_FILES_CHOSEN_S));
|
||||
CHECK(!save_files_chosen_now(&f, 999));
|
||||
f.chosen = 0;
|
||||
CHECK(!save_files_chosen_now(&f, 5));
|
||||
|
||||
/* a file's card: a map's own name as words */
|
||||
char place[SAVE_CARD_PLACE + 1], small[8];
|
||||
save_card_place("KokiriForest", place, sizeof place);
|
||||
CHECK(!strcmp(place, "Kokiri Forest"));
|
||||
save_card_place("Inside_GanonCastle01", place, sizeof place);
|
||||
CHECK(!strcmp(place, "Inside Ganon Castle 01"));
|
||||
save_card_place("HyruleField", place, sizeof place); CHECK(!strcmp(place, "Hyrule Field"));
|
||||
save_card_place("DekuTree_B1F", place, sizeof place); CHECK(!strcmp(place, "Deku Tree B1F"));
|
||||
save_card_place("Area2Boss", place, sizeof place); CHECK(!strcmp(place, "Area 2 Boss"));
|
||||
save_card_place("__Lost__Woods__", place, sizeof place); CHECK(!strcmp(place, "Lost Woods"));
|
||||
save_card_place("", place, sizeof place); CHECK(!place[0]);
|
||||
/* (a map that says Link's age at its name's end: the place without it, as the game's own load list has it) */
|
||||
save_card_place("KokiriForest_Adult", place, sizeof place); CHECK(!strcmp(place, "Kokiri Forest"));
|
||||
save_card_place("KokiriForestChild", place, sizeof place); CHECK(!strcmp(place, "Kokiri Forest"));
|
||||
save_card_place("Adult", place, sizeof place); CHECK(!strcmp(place, "Adult"));
|
||||
save_card_place("ChildhoodHome", place, sizeof place); CHECK(!strcmp(place, "Childhood Home"));
|
||||
save_card_place("KokiriForest", small, sizeof small); CHECK(!strcmp(small, "Kokiri") && strlen(small) < sizeof small);
|
||||
/* hearts: the game's count of Link's life, in quarters of a heart; what is no such count: none */
|
||||
CHECK(save_card_hearts(12) == 3 && save_card_hearts(28) == 7 && save_card_hearts(80) == 20 && save_card_hearts(84) == 0);
|
||||
CHECK(save_card_hearts(0) == 0 && save_card_hearts(8) == 0 && save_card_hearts(13) == 0 && save_card_hearts(-12) == 0 && save_card_hearts(7) == 0);
|
||||
/* triforce_card.txt: read, written and read back; what is none of its lines passed over, numbers that are none 0 */
|
||||
SaveCard c, d;
|
||||
save_card_parse(&c, "# a note\r\nplace=Kokiri Forest\r\nitems=1c9\r\nhearts=7\r\nwhat=this\r\n");
|
||||
CHECK(!strcmp(c.place, "Kokiri Forest") && c.items == 0x1c9 && c.hearts == 7);
|
||||
const size_t cn = save_card_write(&c, text, sizeof text);
|
||||
CHECK(cn == strlen(text) && text[0] == '#' && strstr(text, "\nplace=Kokiri Forest\nitems=1c9\nhearts=7\n"));
|
||||
save_card_parse(&d, text);
|
||||
CHECK(save_card_same(&c, &d) && save_card_write(&c, text, 40) == 0);
|
||||
d.hearts = 8; CHECK(!save_card_same(&c, &d));
|
||||
d = c, d.items ^= 1; CHECK(!save_card_same(&c, &d));
|
||||
d = c, d.place[0] = 'L'; CHECK(!save_card_same(&c, &d));
|
||||
save_card_parse(&c, "items=fffff\nhearts=21\nplace=A|B\tC\n");
|
||||
CHECK(c.items == 0x1ff && c.hearts == 0 && !strcmp(c.place, "A B C")); /* (the bar and a control are the list's own: spaces) */
|
||||
save_card_parse(&c, "");
|
||||
CHECK(!c.place[0] && !c.items && !c.hearts && !c.slot1 && !c.saved);
|
||||
/* the slot the game saved in last, and when: kept with the card; a slot that is none is not known */
|
||||
save_card_parse(&c, "place=Kokiri Forest Adult\nitems=1\nhearts=3\nslot=3\nsaved=1763456789\n");
|
||||
CHECK(c.slot1 == 4 && c.saved == 1763456789 && !strcmp(c.place, "Kokiri Forest")); /* (and a place kept with its age: without) */
|
||||
CHECK(save_card_write(&c, text, sizeof text) && strstr(text, "\nhearts=3\nslot=3\nsaved=1763456789\n"));
|
||||
save_card_parse(&d, text);
|
||||
CHECK(save_card_same(&c, &d));
|
||||
d.slot1 = 1; CHECK(!save_card_same(&c, &d));
|
||||
d = c; d.saved++; CHECK(!save_card_same(&c, &d));
|
||||
save_card_parse(&c, "slot=12\nsaved=-4\n"); CHECK(!c.slot1 && !c.saved);
|
||||
save_card_parse(&c, "slot=0\n"); CHECK(c.slot1 == 1);
|
||||
save_card_parse(&c, "slot=\nslot=x\n"); CHECK(!c.slot1);
|
||||
CHECK(save_card_slot_of("save:/slot_03/caption.sav") == 3 && save_card_slot_of("save:/slot_11/progress.sav") == 11 && save_card_slot_of("save:\\slot_00\\x") == 0);
|
||||
CHECK(save_card_slot_of("save:/slot_12/caption.sav") < 0 && save_card_slot_of("save:/option.sav") < 0 && save_card_slot_of("save:/slot_3/x") < 0);
|
||||
CHECK(save_card_slot_of("save:/slot_03") < 0 && save_card_slot_of("") < 0 && save_card_slot_of(NULL) < 0);
|
||||
save_card_parse(&c, "hearts=x\nitems=\nplace=\n");
|
||||
CHECK(!c.place[0] && !c.items && !c.hearts);
|
||||
|
||||
if (!fails) printf("PASS\n");
|
||||
return fails != 0;
|
||||
}
|
||||
@@ -50,7 +50,10 @@ def build(cxx, work, headers="", opt="-O2"):
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
logo_rgba.write(str(work / "hookshot_logo.h"))
|
||||
win = os.name == "nt"
|
||||
target = ["--target=x86_64-pc-windows-msvc", "-fms-extensions", "-D_CRT_SECURE_NO_WARNINGS"] if win and "clang" in cxx else []
|
||||
# (the game's own target: llvm-mingw's GNU one with HOOKSHOT_MINGW, as the builds have it, else MSVC; the a64 kit's toolchain)
|
||||
sys.path.insert(0, str(ROOT / "third_party" / "a64-kit" / "tools"))
|
||||
import toolchain
|
||||
target = toolchain.native_target() if win and "clang" in cxx else []
|
||||
includes = ["-I" + str(ROOT / "gpu" / "vk"), "-I" + str(IMGUI), "-I" + str(ZSTD), "-I" + str(work),
|
||||
"-I" + header_dir("vulkanheaders", "vulkan/vulkan.h", headers)]
|
||||
if os.name != "nt": # (the Win32 names the back end's headers use, as its own build has them on POSIX)
|
||||
|
||||
@@ -81,6 +81,8 @@ static bool before_bloom = false; // (the Upscale before bloom row: the upscal
|
||||
bool temporal_before_bloom() { return before_bloom; }
|
||||
bool fsr3_wanted() { return false; }
|
||||
bool fsr3_native() { return false; }
|
||||
static int n64_front = 0; // ((Triforce, N64 Classic) vk_n64.cpp n64_in_front: the preset while its 3D pass draws, 0 none)
|
||||
int n64_in_front() { return n64_front; }
|
||||
static uint64_t frame_no = 10;
|
||||
uint64_t texture_frame_no() { return frame_no; }
|
||||
VkResult shared_cache_compute(const VkComputePipelineCreateInfo* ci, VkPipeline* out) {
|
||||
@@ -157,6 +159,9 @@ static int logic(const char* env) {
|
||||
}
|
||||
upscaling = ur::DLAA, frame_no++;
|
||||
CHECK(aa_mode() == ar::FXAA); // (the switch over an upscaler too: a lab's A/B of the game's SMAA under it)
|
||||
n64_front = 1, frame_no++;
|
||||
CHECK(aa_mode() == ar::FXAA); // ((Triforce, N64 Classic) and over N64 Classic's Off)
|
||||
n64_front = 0;
|
||||
std::puts("aa passes: RX_VK_AA is the run's choice");
|
||||
return 0;
|
||||
}
|
||||
@@ -229,6 +234,16 @@ static int logic(const char* env) {
|
||||
CHECK(!aa_asked() && aa_state() == ar::QUIET);
|
||||
frame_no++;
|
||||
CHECK(!aa_asked() && !aa_leave_out(ar::kWeightsKey));
|
||||
// ((Triforce, 11-22, N64 Classic) its 3D pass draws: the game's SMAA is left out with the game's own chosen, its edge and
|
||||
// weight passes too once a composition is replaced; and the game's own again when it stops, as after any other choice
|
||||
n64_front = 1, frame_no++;
|
||||
CHECK(aa_asked() && aa_mode() == ar::OFF);
|
||||
aa_composed(true, nullptr);
|
||||
frame_no++;
|
||||
CHECK(aa_leave_out(ar::kEdgesKey) && aa_leave_out(ar::kWeightsKey));
|
||||
n64_front = 0, frame_no++;
|
||||
CHECK(aa_asked() && !aa_leave_out(ar::kEdgesKey) && aa_mode() == ar::GAME);
|
||||
CHECK(!aa_asked() && aa_state() == ar::QUIET);
|
||||
// FXAA with none of the game's compositions met for a minute (another game version): said once in the log, and to the row
|
||||
opts.aa = ar::FXAA;
|
||||
const size_t before = said.size();
|
||||
|
||||
@@ -248,6 +248,7 @@ int main() {
|
||||
'''
|
||||
|
||||
MENU = r'''#include "@ROOT@/gpu/vk/aa_rows.h"
|
||||
#include "@ROOT@/gpu/vk/n64_rules.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
@@ -267,11 +268,20 @@ int aa_env_choice() { return env_now; }
|
||||
int aa_state() { return state_now; }
|
||||
bool reflex_available() { return true; }
|
||||
namespace mkwvk::dlssg { bool reflex_on() { return false; } } /* ((Triforce) Reflex through Streamline: row_fixed asks it) */
|
||||
/* ((Triforce) what else sets the picture's shape and Custom's size, tests/test_output_resolution.py: row_fixed asks them) */
|
||||
int shape_owner() { return 0; }
|
||||
bool custom_env(long* = nullptr, long* = nullptr) { return false; }
|
||||
bool antilag_available() { return true; }
|
||||
unsigned upscalers_available() { return ~0u; }
|
||||
bool filter_needed() { return true; }
|
||||
const char* dlss_preset_env() { return nullptr; }
|
||||
int output_choice(int v) { return v; }
|
||||
/* ((Triforce, 11-22, N64 Classic) its 3D pass drawing in the upscaler's place (vk_n64.cpp n64_in_front), RX_VK_N64, and the
|
||||
Remembered page's rows (none here) */
|
||||
int n64_front = mkwvk::n64_rules::OFF;
|
||||
int n64_in_front() { return n64_front; }
|
||||
bool n64_env_set() { return false; }
|
||||
int n64_rem_row(const int*) { return -1; }
|
||||
@TEXT@
|
||||
@HINT@
|
||||
@FIXED@
|
||||
@@ -317,10 +327,11 @@ int main() {
|
||||
opts.aa = v, up_now = ur::GAME, env_now = -1, state_now = aa_rows::QUIET;
|
||||
CHECK(!std::strcmp(tx_aa(v), names[v]) && !row_fixed(&opts.aa));
|
||||
CHECK(hn_aa(v, -1) && hn_aa(v, -1) == hn_aa(v, 0));
|
||||
/* every line a value can have, for the help's height: its own, DLSS's, FSR's, the switch's, the missing passes' */
|
||||
/* every line a value can have, for the help's height: its own, DLSS's, FSR's, the switch's, the missing passes', N64
|
||||
Classic's */
|
||||
int n = 0;
|
||||
while (hn_aa(v, n)) n++;
|
||||
CHECK(n == 5 && !hn_aa(v, 5) && !hn_aa(v, 6));
|
||||
CHECK(n == 6 && !hn_aa(v, 6) && !hn_aa(v, 7));
|
||||
for (int w = 0; w < v; w++) CHECK(std::strcmp(hn_aa(v, 0), hn_aa(w, 0)));
|
||||
/* replaced: nothing more to say */
|
||||
state_now = aa_rows::REPLACED;
|
||||
@@ -353,6 +364,14 @@ int main() {
|
||||
state_now = aa_rows::MISSING;
|
||||
CHECK(hn_aa(v, -1) == hn_aa(v, env == aa_rows::GAME ? 3 : 4));
|
||||
}
|
||||
/* ((Triforce, 11-22, N64 Classic) while its 3D pass draws: the row says so, has nothing to choose, keeps the choice, and
|
||||
its line says why; RX_VK_AA's run is vk_aa.cpp's to take over it (tests/test_aa_passes.py) */
|
||||
for (int v = 0; v < aa_rows::kValues; v++) {
|
||||
opts.aa = v, up_now = ur::GAME, env_now = -1, state_now = aa_rows::MISSING, n64_front = mkwvk::n64_rules::FAITHFUL;
|
||||
CHECK(!std::strcmp(tx_aa(v), "N64 Classic") && row_fixed(&opts.aa) && opts.aa == v);
|
||||
CHECK(hn_aa(v, -1) == hn_aa(v, 5) && std::strstr(hn_aa(v, -1), "N64 Classic") && std::strstr(hn_aa(v, -1), "kept"));
|
||||
}
|
||||
n64_front = mkwvk::n64_rules::OFF;
|
||||
/* the other rows' fixing is theirs: the row's own value does not fix another. ((Triforce, options_version 7) DLAA is the
|
||||
Render resolution's Native (100%) step: that row has its steps) */
|
||||
up_now = ur::DLAA, env_now = -1;
|
||||
@@ -395,8 +414,13 @@ def main():
|
||||
|
||||
# the renderer's side: what is in effect is the row's rule, asked with what upscales as the menu's Upscaler row shows it
|
||||
mode = definition(aa, "int aa_mode")
|
||||
check("ar::chosen(opts.aa, env_choice())" in mode and "ar::effective(choice, upscaler_now(), temporal_before_bloom(), env_choice() >= 0)" in mode,
|
||||
choice = definition(aa, "int choice_now")
|
||||
check("const int choice = choice_now();" in mode and "ar::chosen(opts.aa, env_choice())" in choice and
|
||||
"ar::effective(choice, upscaler_now(), temporal_before_bloom(), env_choice() >= 0)" in mode,
|
||||
"aa_mode does not take the row's choice (RX_VK_AA over it) through aa_rows.h's effective")
|
||||
# ((Triforce, 11-22, N64 Classic) Off while its 3D pass draws the gameplay upscale; RX_VK_AA still over it)
|
||||
check("return env_choice() >= 0 ? choice : n64_rules::anti_aliasing(n64_in_front(), choice);" in choice,
|
||||
"the row's choice no longer gives way to N64 Classic's 3D pass, or RX_VK_AA no longer goes over that")
|
||||
check("frame_read.load(std::memory_order_acquire) == frame" in mode and "std::lock_guard lk(s.mu);" in mode,
|
||||
"aa_mode no longer takes the choice once a frame")
|
||||
check(re.sub(r"\s+", " ", definition(aa, "int upscaler_now")).endswith(
|
||||
@@ -407,7 +431,7 @@ def main():
|
||||
check('getenv("RX_VK_AA")' in aa and 'getenv("RX_VK_AA_KEEP")' in aa, "vk_aa.cpp no longer reads its two switches")
|
||||
# the game's own chosen and nothing left to free: a dispatch asks a comparison and nothing else
|
||||
check(re.sub(r"\s+", " ", definition(aa, "bool aa_asked")) ==
|
||||
"bool aa_asked() { return ar::chosen(opts.aa, env_choice()) != ar::GAME || engaged.load(std::memory_order_relaxed) || upscaler_asks(); }",
|
||||
"bool aa_asked() { return choice_now() != ar::GAME || engaged.load(std::memory_order_relaxed) || upscaler_asks(); }",
|
||||
"aa_asked is no longer the row's choice, whether anything is left to free and whether an upscaler leaves the SMAA out")
|
||||
asks = definition(aa, "bool upscaler_asks")
|
||||
check("ar::effective(ar::GAME, upscaler_now(), temporal_before_bloom(), env_choice() >= 0) != ar::GAME" in asks and
|
||||
|
||||
@@ -124,8 +124,25 @@ def check_sources():
|
||||
"ach_list.done(value);", "if (ach_list.earn(value)) menu_refresh = true;"):
|
||||
check(line in setter, "the menu does not take the host's achievements: " + line)
|
||||
table = menu[menu.index("Row rows[] = {"):]
|
||||
check(table.index('"Bug capture (F8)"') < table.index('{TAB_SYSTEM, "Achievements", nullptr, 0, 0, 0, nullptr,') < table.index('MENU_HEADING(TAB_SYSTEM, "Mod cheats")')
|
||||
and 'constexpr char kAchRow[] = "Achievements";' in menu, "the Achievements row is not on the System tab after Bug capture (F8)")
|
||||
# (11-23) a group of their own, the System tab's first: the list's page, then the two switches
|
||||
system = [m.start() for m in re.finditer(r"TAB_SYSTEM", table)]
|
||||
order = [table.index(part) for part in ('MENU_HEADING(TAB_SYSTEM, "Achievements"),', '{TAB_SYSTEM, "View achievements", nullptr, 0, 0, 0, nullptr,',
|
||||
'{TAB_SYSTEM, "Achievements", &opts.achievements, 0, 1, 1, tx_onoff,',
|
||||
'{TAB_SYSTEM, "Achievement notices", &opts.achievement_notices, 0, 1, 1, tx_onoff,',
|
||||
'MENU_HEADING(TAB_SYSTEM, "Game"),')]
|
||||
check(order == sorted(order) and system[0] > order[0] and system[0] - order[0] < 40 and 'constexpr char kAchRow[] = "View achievements";' in menu,
|
||||
"the Achievements group is not the System tab's first, with its page's row and its two switches")
|
||||
check(re.search(r"\bint achievements = 1;", read("gpu", "vk", "vk_menu.h")) and re.search(r"\bint achievement_notices = 1;", read("gpu", "vk", "vk_menu.h")),
|
||||
"the Achievements rows are not On unless set")
|
||||
check("if (id == HOS_OPT_ACH_ON) return opts.achievements != 0;" in replay and "if (id == HOS_OPT_ACH_NOTICES) return opts.achievement_notices != 0;" in replay,
|
||||
"the renderer does not tell the host the Achievements rows")
|
||||
check("if (!hos_achievements_on() || !rx_option(HOS_OPT_ACH_ON, 1)) return;" in own and "if (!quiet) hos_menu_sound_play(HOS_MENU_SOUND_SYS_DECIDE, now_ns);" in own,
|
||||
"the host earns with the Achievements row Off, or plays the notice's sound with the notices Off")
|
||||
tick = block(menu, "void menu_tick() {")
|
||||
check("earned >= 0 && opts.achievement_notices) ach_notice = earned, ach_notice_at = prof_now();" in tick, "a notice shows with the Achievement notices row Off")
|
||||
notice = block(menu, "void draw_ach_notice(ui::Ctx& c) {")
|
||||
check('constexpr char kAchWhere[] = "See all: Options > System";' in menu and "ui::kSoft, kAchWhere);" in notice and "ui::size_of(c.f.body, 12 * s, kAchWhere).x" in notice,
|
||||
"the notice does not say where the list is, or is not as wide as that line")
|
||||
check("(strcmp(rows[i].name, kAchRow) || rows[i].tab != TAB_SYSTEM || ach_list.shown() > 0) &&" in block(menu, "bool row_shown("),
|
||||
"the Achievements row shows before the host named them")
|
||||
press = menu[menu.index("else if (press[7] && is_ach_row(r)) page = kAchPage"):]
|
||||
@@ -134,10 +151,13 @@ def check_sources():
|
||||
check("else if (page == kAchPage) draw_achievements(k);" in block(menu, "void draw_menu(ui::Ctx& c, bool perf_under) {"), "the Achievements page is not drawn")
|
||||
page = number(menu, "kAchPage")
|
||||
check(page not in (0, 1, 3, 4, 5, 6, number(menu, "kModsPage"), number(menu, "kModsRowPage")), "kAchPage is another page's number")
|
||||
for record in ("void menu_record(", "void menu_record_image("):
|
||||
body = block(menu, record)
|
||||
check("ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000" in body and "&& !earned)" in body
|
||||
and "if (earned) draw_ach_notice(c);" in body, "%s an achievement's notice is not drawn, or not while nothing else shows" % record)
|
||||
body = block(menu, "void menu_record_image(")
|
||||
check("ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000" in body and "&& !earned)" in body
|
||||
and "if (earned) draw_ach_notice(c);" in body, "menu_record_image: an achievement's notice is not drawn, or not while nothing else shows")
|
||||
# ((Triforce, 11-23) N64 Classic split menu_record: what shows (showing_now) and the drawing (draw_overlays), the notice in both)
|
||||
check("s.earned = !s.start && ach_notice >= 0 && prof_now() - ach_notice_at < kAchNoticeMs * 1000000" in block(menu, "Showing showing_now(")
|
||||
and "if (s.earned) draw_ach_notice(c);" in block(menu, "void draw_overlays(")
|
||||
and "&& !s.earned)" in block(menu, "void menu_record("), "menu_record: an achievement's notice is not drawn, or not while nothing else shows")
|
||||
check(number(own, "SHOWN_MS") > int(re.search(r"kAchNoticeMs = (\d+);", menu).group(1)), "the host shows the next notice before this one is gone")
|
||||
return api, own
|
||||
|
||||
@@ -181,7 +201,7 @@ def main():
|
||||
check(own.count(marker) == 1, "host/achievements.c no longer includes menu_sound.h last")
|
||||
(tmp / "achievements_actual.inc").write_text(own[own.index(marker) + len(marker):], encoding="utf-8")
|
||||
(tmp / "achievements_constants.inc").write_text(
|
||||
"".join(block(api, start) + ";\n" for start in ("enum { HOS_OPT_ACH_TEXT = 165", "enum { HOS_ACH_EARNED = 256", "enum { HOS_MENU_SOUND_OPEN = 1")),
|
||||
"".join(block(api, start) + ";\n" for start in ("enum { HOS_OPT_ACH_TEXT = 165", "enum { HOS_OPT_ACH_ON = 185", "enum { HOS_ACH_EARNED = 256", "enum { HOS_MENU_SOUND_OPEN = 1")),
|
||||
encoding="utf-8")
|
||||
exe = tmp / "host.exe"
|
||||
run([a.cc] + warnings + ["-Wno-unused-function", "-I" + str(ROOT / "host"), "-I" + str(tmp), str(ROOT / "tests" / "achievements_host_test.c"),
|
||||
@@ -204,6 +224,20 @@ def main():
|
||||
f.write(b"deadbeef 5 Gone\n")
|
||||
run([str(exe), str(game), "second"], says="PASS", cwd=str(tmp), env=on)
|
||||
check(sorted(f.name for f in game.iterdir()) == ["achievements.txt", "triforce_achievements.txt"], "the game folder has other files now")
|
||||
# (11-23) the System tab's two rows, in a game folder of its own
|
||||
rows_game = tmp / "rows game"
|
||||
rows_game.mkdir()
|
||||
run([str(exe), str(rows_game), "rows"], says="PASS", cwd=str(tmp), env=on)
|
||||
# the save files on (host/save_files.c): what a file earned is kept in its own folder, and is no other file's.
|
||||
# File 1 starts from what the game folder earned before; the game folder's own is left as it was
|
||||
before = earned.read_bytes()
|
||||
(game / "user").mkdir(), (game / "user-2").mkdir()
|
||||
run([str(exe), str(game), "file2"], says="PASS", cwd=str(tmp), env=on)
|
||||
run([str(exe), str(game), "file1"], says="PASS", cwd=str(tmp), env=on)
|
||||
run([str(exe), str(game), "again1"], says="PASS", cwd=str(tmp), env=on)
|
||||
check(earned.read_bytes() == before, "the game folder's earned achievements were changed by a save file's")
|
||||
check(sorted(f.name for f in (game / "user-2").iterdir()) == ["triforce_achievements.txt"] and
|
||||
sorted(f.name for f in (game / "user").iterdir()) == ["triforce_achievements.txt"], "a save file's folder has other files now")
|
||||
check((game / "achievements.txt").read_bytes() == OWN_LIST.encode("utf-8"), "the player's own list was changed")
|
||||
print("PASS: achievements: the list and what it refuses, earning, the file of the earned ones, the host's naming and notices, "
|
||||
"the menu's list and page, and on unless HOS_ACHIEVEMENTS=0")
|
||||
|
||||
90
tests/test_acquire_ahead.py
Normal file
90
tests/test_acquire_ahead.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""(Triforce, 11-23) The next swapchain image acquired ahead on the present thread (RX_VK_ACQUIRE_AHEAD, gpu/vk/vk_replay.cpp
|
||||
acquire_ahead; no game, no GPU).
|
||||
|
||||
On AMD's Windows driver an acquired image comes back with the compositor's next refresh, and present_image waited for it
|
||||
(the acquire's fence, RX_VK_ACQUIRE_FENCE) on the thread that replays the frame: 2.4 to 4.2 ms of every frame on an RX 6700
|
||||
XT, 16% of that thread in a profile. The present thread now acquires the next image right after its present and waits for it
|
||||
there, while the frame is replayed; present_image finds it held and free.
|
||||
|
||||
Read from the source, as the rest of the present's rules are (tests/test_present_thread.py):
|
||||
- when: only on the present thread, after present_out and before it says it is done; with the acquire's fence, without DLSS
|
||||
frame generation, on AMD's Windows driver unless RX_VK_ACQUIRE_AHEAD says otherwise; and the present thread is wanted for it;
|
||||
- what: nothing while an image is held, with no swapchain, or while a resize or a lost surface waits for present_image; the
|
||||
acquire signals the fence and no semaphore; the image waited for at most 250 ms; held, marked free when it was;
|
||||
- no present_image_mu: present_image holds it while it settles this thread's work, and would wait for itself;
|
||||
- present_image takes a held image marked free without waiting, and every other held image as before.
|
||||
|
||||
python -I -B tests/test_acquire_ahead.py
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def block(text, marker):
|
||||
start = text.index(marker)
|
||||
end = text.index('{', start) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (text[end] == '{') - (text[end] == '}')
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
def before(text, *parts):
|
||||
at = -1
|
||||
for p in parts:
|
||||
i = text.find(p, at + 1)
|
||||
if i < 0:
|
||||
return False
|
||||
at = i
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
replay = (ROOT / "gpu/vk/vk_replay.cpp").read_text(encoding="utf-8")
|
||||
fails = []
|
||||
|
||||
def check(ok, why):
|
||||
if not ok:
|
||||
fails.append(why)
|
||||
|
||||
wanted = block(replay, "bool acquire_ahead_wanted() {")
|
||||
check("#ifdef _WIN32" in wanted and 'getenv("RX_VK_ACQUIRE_AHEAD")' in wanted, "the switch is not read, or not on Windows alone")
|
||||
check("if (asked == 0 || !acquire_fence_on() || dlssg::active()) return false;" in wanted,
|
||||
"it runs without the acquire's fence, with DLSS frame generation, or with the switch at 0")
|
||||
check("return asked > 0 || dev.props.vendorID == 0x1002;" in wanted, "it is not AMD's by default, or =1 does not turn it on")
|
||||
|
||||
ahead = block(replay, "void acquire_ahead() {")
|
||||
check("present_image_mu" not in ahead.split("//")[0] and "std::lock_guard lk(present_image_mu)" not in ahead,
|
||||
"it takes present_image_mu, which present_image holds while it waits for this thread")
|
||||
check(before(ahead, "if (held_image.on || !dev.swapchain || dev.swap_resize.load(std::memory_order_acquire) ||",
|
||||
"surface_lost_noted.load(std::memory_order_acquire)", "return;", "vkAcquireNextImageKHR("),
|
||||
"it acquires while an image is held, with no swapchain, or before present_image made the swapchain again")
|
||||
check("vkAcquireNextImageKHR(dev.device, dev.swapchain, UINT64_MAX, VK_NULL_HANDLE, fence, &index);" in ahead,
|
||||
"the acquire does not signal the fence alone")
|
||||
check(before(ahead, "if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) {", "return;", "image_free(250000000ull)",
|
||||
"held_image = {true, index, dev.swap_generation, 0, false, ready == VK_SUCCESS};"),
|
||||
"the image is not waited for at most 250 ms and held, marked free when it was")
|
||||
|
||||
main_ = block(replay, "void present_thread_main() {")
|
||||
check(before(main_, "present_out(o, qk, true);", "}", "acquire_ahead();", "present_hand.done();"),
|
||||
"it does not run on the present thread after its present, with the queue's lock let go, before the thread is done")
|
||||
ptw = block(replay, "bool present_thread_wanted() {")
|
||||
check("acquire_ahead_wanted()" in ptw, "the present thread is not wanted for it")
|
||||
|
||||
pi = block(replay, "void present_image(VkImage src, uint32_t sw, uint32_t sh, const int crop[4], VkImageView view) {")
|
||||
check(before(pi, "present_thread_settle();", "held_image.on && held_image.free ? VK_SUCCESS : image_free("),
|
||||
"present_image does not settle the present thread first, or waits again for an image waited free")
|
||||
held = block(replay, "struct HeldImage {")
|
||||
check("bool free = false;" in held, "a held image has no mark for having been waited free")
|
||||
|
||||
if fails:
|
||||
for f in fails:
|
||||
print("FAIL: " + f)
|
||||
raise SystemExit(1)
|
||||
print("acquire ahead: ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
84
tests/test_bench_helpers.py
Normal file
84
tests/test_bench_helpers.py
Normal file
@@ -0,0 +1,84 @@
|
||||
"""(Triforce, 11-22) The benchmark's helper-thread test (host/hos_bench.c HOS_BENCH_HELPERS, gpu/vk/vk_replay.cpp par_forced,
|
||||
launcher/Logic/Benchmark.cs). The source read: no game, no GPU.
|
||||
|
||||
- the renderer: HOS_OPT_HELPERS_FORCE's option_set holds the way (0 off, 1 on, -1 the tuner again), par_tune_present applies
|
||||
it before the tuner is told the frame (so a held frame is neither a trial's nor a window's), and its option says the helper
|
||||
threads a test can use (0 without the tuner: the row's Off, RX_VK_PARALLEL);
|
||||
- the host: the test asks once what it can use, holds a scene's first way during that scene's settling, turns the order from
|
||||
scene to scene, measures both halves, settles again after the switch, writes both halves and the threads used, and gives
|
||||
the way back to the tuner once the run ends;
|
||||
- the launcher: it sets HOS_BENCH_HELPERS=1 and the row's Automatic for the run (the row's Off has no helper threads), and
|
||||
the start dialog has the choice.
|
||||
|
||||
python -I -B tests/test_bench_helpers.py
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def check(ok, what):
|
||||
if not ok:
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
|
||||
def function(text, head):
|
||||
start = text.find(head)
|
||||
check(start >= 0, "%s is missing" % head.rstrip(" {("))
|
||||
return text[start:text.index("\n}\n", start) + 3]
|
||||
|
||||
|
||||
def in_order(text, steps, what):
|
||||
at = 0
|
||||
for s in steps:
|
||||
i = text.find(s, at)
|
||||
check(i >= 0, "%s: %r is missing or out of order" % (what, s))
|
||||
at = i + len(s)
|
||||
|
||||
|
||||
def main():
|
||||
api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8")
|
||||
check("enum { HOS_OPT_HELPERS_FORCE = 170 };" in api, "HOS_OPT_HELPERS_FORCE is not option 170 (165 to 169 are the achievements')")
|
||||
replay = (ROOT / "gpu" / "vk" / "vk_replay.cpp").read_text(encoding="utf-8")
|
||||
check("std::atomic<int> par_forced{-1};" in replay, "par_forced: the tuner decides unless the benchmark holds a way")
|
||||
in_order(function(replay, "void par_tune_present() {"),
|
||||
["if (!par_auto()) return;", "const replay_threads::Frame fr = par_frame_now(ms);",
|
||||
"if (const int forced = par_forced.load(std::memory_order_relaxed); forced >= 0) {", "par_auto_on = forced == 1;",
|
||||
"return;", "tuner.step(fr, par_auto_on, par_stream_order_only());"],
|
||||
"par_tune_present: a held way before the tuner")
|
||||
check("if (id == HOS_OPT_HELPERS_FORCE) return par_forced.store(value < 0 ? -1 : value ? 1 : 0, std::memory_order_relaxed);"
|
||||
in replay, "option_set HOS_OPT_HELPERS_FORCE no longer holds the way")
|
||||
check("if (id == HOS_OPT_HELPERS_FORCE) return par_auto() ? par_threads_max() : 0;" in replay,
|
||||
"option HOS_OPT_HELPERS_FORCE no longer says the threads a test can use")
|
||||
|
||||
bench = (ROOT / "host" / "hos_bench.c").read_text(encoding="utf-8")
|
||||
check('getenv("HOS_BENCH_HELPERS")' in bench and "B.helper_threads = -1;" in bench, "HOS_BENCH_HELPERS is not read")
|
||||
present = function(bench, "void hos_bench_present(int64_t now) {")
|
||||
in_order(present, ["case MKWVK_BENCH_SETTLE:", "B.helper_threads = rx_option(HOS_OPT_HELPERS_FORCE, 0);",
|
||||
"if (helper_test() && !B.way_set) {", "B.way = B.scene % 2, B.way_set = 1, B.t_phase = now;",
|
||||
"rx_option_set(HOS_OPT_HELPERS_FORCE, B.way);", "if (now - B.t_phase >= SETTLE_NS) {"],
|
||||
"the settling: the scene's first way held, the order turned from scene to scene")
|
||||
in_order(present, ["case MKWVK_BENCH_MEASURE:", "if (helper_test()) {", "stats_of(&B.halves[B.way]);", "if (B.half == 0) {",
|
||||
"B.half = 1, B.way ^= 1;", "rx_option_set(HOS_OPT_HELPERS_FORCE, B.way);",
|
||||
"B.phase = MKWVK_BENCH_SETTLE, B.t_phase = now;", "scene_done();"],
|
||||
"the measurement: both halves, settled again after the switch")
|
||||
in_order(present, ["if (helper_test() && B.phase >= MKWVK_BENCH_DONE", "rx_option_set(HOS_OPT_HELPERS_FORCE, -1);"],
|
||||
"the run's end: the tuner decides again")
|
||||
check("B.half = 0, B.way_set = 0;" in function(bench, "static void go_scene(int64_t now) {"), "a new scene's halves")
|
||||
results = function(bench, "static void write_results(int stopped) {")
|
||||
in_order(results, ['if (r->tested) {', '\\"helpers\\":{\\"first\\":\\"%s\\",\\"off\\":', "json_half(f, &r->way[0]);",
|
||||
'\\"on\\":', "json_half(f, &r->way[1]);"], "the results: both halves")
|
||||
check('if (B.helpers) fprintf(f, ",\\"helper_test\\":{\\"threads\\":%d}"' in results, "the results: the threads used")
|
||||
|
||||
launcher = (ROOT / "launcher" / "Logic" / "Benchmark.cs").read_text(encoding="utf-8")
|
||||
check('if (helperTest) si.Environment["HOS_BENCH_HELPERS"] = "1";' in launcher, "the launcher does not ask for the test")
|
||||
check("keys[KHelpers] = HelpersAutomatic;" in launcher, "the launcher does not give the test Automatic's helper threads")
|
||||
backend = (ROOT / "launcher" / "App" / "Backend.Bench.cs").read_text(encoding="utf-8")
|
||||
check('("helpers", "With the helper-thread test", false)' in backend and '"helpers" => RunBench(compare: false, helperTest: true)'
|
||||
in backend, "the start dialog has no helper-thread test")
|
||||
print("PASS: the benchmark's helper-thread test holds each way past the tuner, measures both halves in turned order, "
|
||||
"writes them, and gives the way back; the launcher asks for it and suggests the row")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -86,9 +86,16 @@ def check_sources():
|
||||
check("InterlockedCompareExchange(&capture_state, 2, 1) != 1" in work, "a capture can be written twice at once")
|
||||
# the picture: before the overlays, not during the start-up screen, three presents before it is read
|
||||
record = block(menu, "void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {")
|
||||
call = "if (!start) bugshot_record(cmd, index, w, h);"
|
||||
check(call in record and record.index(call) < min(record.index(s) for s in ("ui::begin(", "ui::idle()", "draw_menu(", "draw_fps(", "ui::record(")),
|
||||
call = "if (!s.start) bugshot_record(cmd, index, w, h);"
|
||||
check(call in record and record.index(call) < min(record.index(s) for s in ("ui::begin(", "ui::idle()", "draw_overlays(", "ui::record(")),
|
||||
"the capture's picture is not taken before the overlays are drawn (or is taken of the start-up screen)")
|
||||
# ((Triforce, 11-22, N64 Classic) the options drawn under its TV before the window pass: never while a capture waits for
|
||||
# this frame's picture; a copy under way goes on at menu_record all the same)
|
||||
layer = block(menu, "VkImageView menu_tv_layer(VkCommandBuffer cmd) {")
|
||||
check("bugshot_state() == 1" in layer and layer.index("bugshot_state() == 1") < layer.index("draw_overlays("),
|
||||
"the options are drawn under N64 Classic's TV, into the picture, while a capture waits for it")
|
||||
check(record.index("bugshot_record(cmd, index, w, h);") < record.index("ui::record_rest(cmd, index, w, h);"),
|
||||
"menu_record does not go on with a capture's copy when the options were drawn under the TV")
|
||||
rec = block(shot, "void bugshot_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {")
|
||||
order = [rec.index(s) for s in ("barrier(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);",
|
||||
"vkCmdCopyImageToBuffer(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &c);",
|
||||
|
||||
@@ -163,7 +163,7 @@ def main():
|
||||
action = function(menu, "void action_cell(")
|
||||
check("choice_cell(c, a, b, word, sel, false, !fixed, fixed);" in action, "action_cell is not the orange plate with its arrow")
|
||||
check("else action_cell(c, va, vb, v.empty() ? buttons[r.cheat] : v, selected, r.cheat == 9);" in draw
|
||||
and 'else action_cell(c, va, vb, ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open", selected);' in draw,
|
||||
and 'else action_cell(c, va, vb, r.name == kUseWindowSize ? "Copy" : ends ? r.name : share_row(r) ? share_label(share_row(r)) : "Open", selected);' in draw,
|
||||
"the Debug tab's buttons and the page, save, Restart and Quit rows are not one style")
|
||||
check(", false, true, false, true)" not in draw, "a row still draws its button as the dark panel")
|
||||
# the rows clipped as the other tabs': none under the header
|
||||
@@ -176,6 +176,10 @@ def main():
|
||||
# a still is drawn settled: only menu_record, a window's frames, steps the easing
|
||||
image = function(menu, "void menu_record_image(")
|
||||
record = function(menu, "void menu_record(VkCommandBuffer cmd, uint32_t index")
|
||||
# ((Triforce, 11-22) the window's frames are drawn by draw_overlays, for menu_record and N64 Classic's menu_tv_layer alike)
|
||||
overlays = function(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under)")
|
||||
check("draw_overlays(w, h, s, nullptr);" in record and "draw_overlays(" not in image, "menu_record does not draw by draw_overlays")
|
||||
record = overlays
|
||||
check("if (!ease_live) ease_step = 1.0f;" in image and image.index("if (!ease_live) ease_step = 1.0f;") < image.index("draw_menu(c"),
|
||||
"a still does not draw the lists where the selection asks")
|
||||
check("ease_live = true;" in record and "ease_live = true" not in image, "the window's frames do not keep their easing")
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
window pixel (inside the same picture pixel when the window is the larger, so Sharpness did next to nothing), and its
|
||||
per-pixel math, the shader's own sharpen() compiled as C++, is the picture unchanged at 0, never past the lightest or
|
||||
darkest pixel around it nor outside 0..1 (no halos, no clipping) at any setting, and steeper edges as the setting rises.
|
||||
The shader's side_outside() is compiled too: full side fill outside the middle, with both soft edges wholly inside it.
|
||||
fg_scale_comp_spv.h names the hash of the fg_scale.comp it was made from (its first line), checked against the shader as it
|
||||
is now with or without glslang; with glslangValidator the shader compiles, and with the version the header names, the rest of
|
||||
the header is its output byte for byte. --write makes the header: glslang's output with that line on top.
|
||||
@@ -80,6 +81,10 @@ static float min(float a, float b) { return std::min(a, b); }
|
||||
static float max(float a, float b) { return std::max(a, b); }
|
||||
static float clamp(float v, float lo, float hi) { return std::min(std::max(v, lo), hi); }
|
||||
static vec3 clamp(vec3 v, vec3 lo, vec3 hi) { return min(max(v, lo), hi); }
|
||||
static float smoothstep(float lo, float hi, float x) {
|
||||
const float t = clamp((x - lo) / (hi - lo), 0.0f, 1.0f);
|
||||
return t * t * (3.0f - 2.0f * t);
|
||||
}
|
||||
'''
|
||||
|
||||
FIXTURE = r'''
|
||||
@@ -90,7 +95,36 @@ static vec3 rnd3() { return {rnd(), rnd(), rnd()}; }
|
||||
static float ch(vec3 v, int i) { return i == 0 ? v.r : i == 1 ? v.g : v.b; }
|
||||
// a blurred edge (the picture as it reaches the window pass), sampled one picture pixel apart around x
|
||||
static float edge(float x) { return 0.1f + 0.8f / (1.0f + std::exp(-2.0f * x)); }
|
||||
static void check_sides() {
|
||||
// Player's 3840x1600, both fixed wide pictures, and the normalized pixel-cap picture.
|
||||
const int pictures[][2] = {{3840, 2848}, {5120, 2560}, {5120, 3840}, {7224, 3616}};
|
||||
const float feather = 0.006f;
|
||||
for (const auto& picture : pictures) {
|
||||
const int width = picture[0];
|
||||
const float x0 = float(width - picture[1]) / (2.0f * width), x1 = 1.0f - x0;
|
||||
float previous = 1.0f;
|
||||
for (int pixel = 0; pixel < width; ++pixel) {
|
||||
const float x = (pixel + 0.5f) / width;
|
||||
const float outside = side_outside(x, x0, x1);
|
||||
CHECK(outside >= 0.0f && outside <= 1.0f);
|
||||
if (x <= x0 || x >= x1) CHECK(outside == 1.0f);
|
||||
else if (x >= x0 + feather && x <= x1 - feather) CHECK(outside == 0.0f);
|
||||
else CHECK(outside > 0.0f && outside < 1.0f);
|
||||
if (x < 0.5f) CHECK(outside <= previous);
|
||||
else CHECK(outside >= previous);
|
||||
previous = outside;
|
||||
}
|
||||
CHECK(side_outside(x0, x0, x1) == 1.0f);
|
||||
CHECK(side_outside(x1, x0, x1) == 1.0f);
|
||||
CHECK(side_outside(x0 + feather, x0, x1) == 0.0f);
|
||||
CHECK(side_outside(x1 - feather, x0, x1) == 0.0f);
|
||||
CHECK(std::abs(side_outside(x0 + feather * 0.5f, x0, x1) - 0.5f) < 1e-4f);
|
||||
CHECK(std::abs(side_outside(x1 - feather * 0.5f, x0, x1) - 0.5f) < 1e-4f);
|
||||
}
|
||||
std::puts("PASS: side fill is whole outside the middle; monotonic 0.006 soft edges stay inside at 3840, 5120 and 7224");
|
||||
}
|
||||
int main() {
|
||||
check_sides();
|
||||
const float amounts[] = {0.0f, 0.1f, 0.4f, 0.8f, 1.0f};
|
||||
for (int i = 0; i < 200000; i++) {
|
||||
const vec3 c = rnd3(), n = rnd3(), s = rnd3(), w = rnd3(), e = rnd3();
|
||||
@@ -159,7 +193,11 @@ def main():
|
||||
raise SystemExit("missing the neighbour at %s" % tap)
|
||||
lobe = re.search(r"const float kMaxLobe = [^;]*;", text).group(0)
|
||||
fn = block(text, "vec3 sharpen(")
|
||||
fixture = SHIM + lobe.replace("const float", "static const float") + "\nstatic " + fn + FIXTURE
|
||||
sides = block(text, "float side_outside(")
|
||||
side_branch = block(body, "if (pc.side != 0 && pc.x1 > pc.x0)")
|
||||
if "outside = side_outside(uv.x, pc.x0, pc.x1);" not in side_branch:
|
||||
raise SystemExit("the side pass does not use the tested side_outside rule")
|
||||
fixture = SHIM + lobe.replace("const float", "static const float") + "\nstatic " + fn + "\nstatic " + sides + FIXTURE
|
||||
with tempfile.TemporaryDirectory(prefix="fg-sharpen-") as tmp:
|
||||
cpp = Path(tmp) / "fixture.cpp"
|
||||
exe = Path(tmp) / "fixture"
|
||||
|
||||
@@ -163,8 +163,9 @@ def main():
|
||||
check("1000000000LL / fps_max()" in loop, "the vsync event's period is taken once, before Monitor's rate is known")
|
||||
presented = block(vi, "void hos_vi_native_presented(void) {")
|
||||
# ((Triforce, 11-22, PRESENT-30) the period is pace_fps()'s, which is the cap unless a movie plays at a cap of 60)
|
||||
check("const int interval = fps_max() < 60 ? 1 : present_interval;" in presented and "pace_fps() * interval" in presented
|
||||
and "return movie_pace_fps(movie_raise, fps_max());" in block(vi, "static int pace_fps(void) {"),
|
||||
# ((Triforce, 11-22, N64 Classic, step 7) and N64 Classic's rate, which paces by itself too (host/n64_pace.h; tests/test_n64_pace.py)
|
||||
check("const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval);" in presented and "pace_fps() * interval" in presented
|
||||
and "return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max()));" in block(vi, "static int pace_fps(void) {"),
|
||||
"a cap under 60 that settles late is paced with the game's own interval on top")
|
||||
readme = (ROOT / "readme.md").read_text(encoding="utf-8")
|
||||
check("| Frame rate cap | 30, 40, 45, 60, 90, 120, 144, 165, 240, Monitor's rate" in readme,
|
||||
|
||||
@@ -53,9 +53,11 @@ FIXTURE = r'''#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <string.h>
|
||||
#include "step_steady.h"
|
||||
#include "movie_pace.h" /* ((Triforce, 11-22, PRESENT-30) realtime_step goes by pace_fps: the cap here, no movie plays) */
|
||||
#include "n64_pace.h" /* ((Triforce, N64 Classic) and no rate of N64 Classic's: n64_rate stays 0 */
|
||||
#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); exit(1); } } while (0)
|
||||
static int64_t pace_period_ns; /* (the period the presents are paced by: hos_vi_native_presented) */
|
||||
static int movie_raise; /* (nn_vi.c's, set once a present by movie_pace_decide: tests/test_movie_pace.py) */
|
||||
static int n64_rate; /* ((Triforce, N64 Classic) nn_vi.c's, set beside it: tests/test_n64_pace.py) */
|
||||
static uint8_t guest[0x4000];
|
||||
#define GP(a) ((void *)(guest + (a)))
|
||||
#define MOD 0x1000u
|
||||
|
||||
@@ -71,7 +71,8 @@ void restart_values(int*) {}
|
||||
struct { void note(const int*) {} } restart_state;
|
||||
bool can_mic() { return false; }
|
||||
void mic_chosen() {}
|
||||
int step_output_choice(int id, int dir) { return id + dir; }
|
||||
struct { unsigned w, h; } remembered_custom{};
|
||||
bool output_step(int, bool) { return false; }
|
||||
const char* tx_framegen_row(int) { return ""; }
|
||||
const char* hn_framegen_row(int, int) { return ""; }
|
||||
const char* tx_fps_cap(int) { return ""; }
|
||||
|
||||
93
tests/test_gpu_busy.py
Normal file
93
tests/test_gpu_busy.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""(Triforce, 11-23) The dynamic resolution's GPU time as the union of the recordings' intervals (gpu/vk/gpu_busy.h; no game, no GPU).
|
||||
|
||||
The clock summed each recording's interval; with AMD's early first timestamps a frame's intervals overlap and the sum
|
||||
counted the overlaps again (14.9 ms against a 7.8 ms span on an RX 6700 XT), so Resolution Auto drew the 3D at its smallest
|
||||
on a card half idle. Run here: intervals apart, overlapping, inside one another, touching, empty or backwards, read back out
|
||||
of order; and a frame of overlapping recordings, whose sum is near twice its span and whose union is the span. The source
|
||||
is read for the two places that collect the intervals, the clock that uses the union, and its switch.
|
||||
|
||||
python -I -B tests/test_gpu_busy.py [--cxx g++]
|
||||
"""
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "g++"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
FIXTURE = r'''
|
||||
#include <cstdio>
|
||||
#include "gpu_busy.h"
|
||||
using mkwvk::gpu_busy::Union;
|
||||
static int fails;
|
||||
#define CHECK(c, what) do { if (!(c)) { fails++; std::printf("FAIL line %d: %s\n", __LINE__, what); } } while (0)
|
||||
int main() {
|
||||
{ Union u; u.add(0, 10); u.add(20, 30); CHECK(u.ticks == 20 && u.end == 30, "apart: both counted"); }
|
||||
{ Union u; u.add(0, 10); u.add(5, 15); CHECK(u.ticks == 15, "overlapping: the overlap once"); }
|
||||
{ Union u; u.add(0, 10); u.add(2, 8); CHECK(u.ticks == 10 && u.end == 10, "inside: nothing more"); }
|
||||
{ Union u; u.add(0, 10); u.add(10, 12); CHECK(u.ticks == 12, "touching: both"); }
|
||||
{ Union u; u.add(5, 5); u.add(9, 3); CHECK(u.ticks == 0 && u.end == 0, "empty or backwards: nothing"); }
|
||||
{ Union u; u.add(10, 20); u.add(0, 15); CHECK(u.ticks == 10, "out of order: only what lies past the end, never over"); }
|
||||
{ /* a frame: 24 recordings of 0.6 ms each, each begun 0.3 ms after the last (its first timestamp while the last still
|
||||
runs): their sum is twice the span, their union the span */
|
||||
Union u;
|
||||
unsigned long long sum = 0;
|
||||
for (int i = 0; i < 24; i++) {
|
||||
const unsigned long long a = 300ull * i, b = a + 600;
|
||||
u.add(a, b), sum += b - a;
|
||||
}
|
||||
CHECK(sum == 14400 && u.ticks == 7500, "a frame of overlapping recordings: the union is its span");
|
||||
/* the next frame after an idle gap counts on from there */
|
||||
u.add(20000, 21000);
|
||||
CHECK(u.ticks == 8500, "after a gap: the next frame's on top");
|
||||
}
|
||||
if (!fails) std::printf("all checks passed\n");
|
||||
return fails != 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def check_source():
|
||||
rep = (ROOT / "gpu/vk/vk_replay.cpp").read_text(encoding="utf-8")
|
||||
for needle, why in (
|
||||
('#include "gpu_busy.h"', "the header is not included"),
|
||||
("gpu_busy_add(t[0], t[1]);", "the uploads' intervals are not in the union"),
|
||||
("gpu_busy_add(t[0], t[tn - 1]);", "the recordings' intervals are not in the union"),
|
||||
('getenv("RX_VK_DYNRES_UNION")', "RX_VK_DYNRES_UNION is not read"),
|
||||
("const int64_t g = ts_dyn_union() ? gpu_busy_ns() : st_gpu_ns + st_gpu_up_ns;",
|
||||
"the dynamic resolution's clock does not take the union"),
|
||||
("const double dw = (double)(st_wait_ns - waited_last) + (double)host_waits.take(nullptr, nullptr);",
|
||||
"the clock does not count the host's other waits for the GPU"),
|
||||
("const ::gpu_wait_kinds::Exclude compositor;", "the compositor's image counts as a wait for the GPU"),
|
||||
("if (ts_ema_behind_ns >= 2e6) ts_gpu_limited = true;\n else if (ts_ema_behind_ns < 1e6) ts_gpu_limited = false;",
|
||||
"the card is not called the limit at 2 ms of waits a frame, and let go of it under 1 ms"),
|
||||
("const bool gpu_limit = !ts_dyn_union() || ts_gpu_limited;",
|
||||
"the clock does not tell a card that holds the replay back from one that does not"),
|
||||
("ts_dyn_scale = std::clamp(ts_ema_gpu_ns / ts_ema_span_ns, 0.02, gpu_limit ? 8.0 : 1.0);",
|
||||
"the clock is not held to the span while the card is not the frame's limit")):
|
||||
if needle not in rep:
|
||||
raise SystemExit("gpu/vk/vk_replay.cpp: " + why)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cxx", default="g++")
|
||||
args = parser.parse_args()
|
||||
check_source()
|
||||
with tempfile.TemporaryDirectory(prefix="gpu-busy-") as d:
|
||||
tmp = Path(d)
|
||||
(tmp / "t.cpp").write_text(FIXTURE, encoding="utf-8")
|
||||
exe = tmp / ("t.exe" if sys.platform == "win32" else "t")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-O1", "-I", str(ROOT / "gpu/vk"),
|
||||
str(tmp / "t.cpp"), "-o", str(exe)], check=True)
|
||||
run = subprocess.run([str(exe)], text=True, capture_output=True, timeout=60)
|
||||
sys.stdout.write(run.stdout)
|
||||
if run.returncode or "all checks passed" not in run.stdout:
|
||||
raise SystemExit("the union's checks failed" + run.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -87,7 +87,9 @@ def main():
|
||||
check(min(order) >= 0 and order == sorted(order), "status_tick: the trace's gpu_waits_ms is not this frame's, from a reader of its own, before lab")
|
||||
check('if (f) fputs(",lab\\n", f);' in tick and tick.index("frame_trace::kColumns);") < tick.index('if (f) fputs(",lab\\n", f);'),
|
||||
"status_tick: lab is no longer the trace's last column")
|
||||
check(rep.count("gpu_wait_kinds::Reader") == 2, "vk_replay.cpp: the readers of the waits are not the line's and the trace's")
|
||||
# ((Triforce, 11-23) and the dynamic resolution's clock's, ts_dyn_present: tests/test_gpu_busy.py)
|
||||
check(rep.count("gpu_wait_kinds::Reader") == 3 and "static ::gpu_wait_kinds::Reader host_waits;" in rep,
|
||||
"vk_replay.cpp: the readers of the waits are not the line's, the trace's and the dynamic resolution's clock's")
|
||||
trace_h = (VK / "frame_trace.h").read_text(encoding="utf-8")
|
||||
check('wb_held_ms,qs_bg_ms,"\n "gpu_waits_ms";' in trace_h and "s.qs_bg, s.gpu_waits);" in trace_h, "frame_trace.h: gpu_waits_ms is not the split's last column")
|
||||
kinds = (VK / "gpu_wait_kinds.h").read_text(encoding="utf-8")
|
||||
|
||||
213
tests/test_l3_home.py
Normal file
213
tests/test_l3_home.py
Normal file
@@ -0,0 +1,213 @@
|
||||
"""(Triforce, 11-23) One L3 for the game's main thread, its presenting thread and the replay's core (host/hos_l3_home.h,
|
||||
host/hos_thread.c; no game, no CPU of the kind).
|
||||
|
||||
On a processor with two or more L3 caches of the same size (AMD's two-die Ryzen 9 parts), the die of the lowest
|
||||
logical processor the process may use is the home: the core kept for the replay is its last core, and the main and
|
||||
presenting threads are kept on its other cores, so that what the main thread writes is in the L3 the replay reads it
|
||||
from. Run here on authored topologies:
|
||||
|
||||
- a 5900X (2 dies of 6 cores, SMT on and off), a 5950X (2 of 8), a 7950X: the first die; the kept core its last; the two
|
||||
threads on its other cores, the other threads as before;
|
||||
- a 5600X, a 7800X3D, an Intel processor of two kinds (one L3): nothing;
|
||||
- a 7950X3D (L3 caches of different sizes): nothing here (host/hos_x3d.h has it);
|
||||
- a 3900X (four 3-core CCXs), a 3700X (two 4-core CCXs): nothing, too few cores;
|
||||
- a process held to one die, or without logical processor 0: the die of its lowest processor, or nothing;
|
||||
- more than one processor group, a list that puts a processor under two L3 caches: nothing.
|
||||
|
||||
The source is read for what cannot run here: HOS_L3_HOME=0 turns it off, the cache die goes first, the log says what was
|
||||
found, the kept core is chosen among the home's cores, and hos_thread_pin keeps the two threads there.
|
||||
|
||||
python -I -B tests/test_l3_home.py [--cc gcc]
|
||||
"""
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cc", "gcc"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def block(text, marker):
|
||||
start = text.index(marker)
|
||||
end = text.index('{', start) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (text[end] == '{') - (text[end] == '}')
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
FIXTURE = r'''
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "hos_l3_home.h"
|
||||
|
||||
static int fails;
|
||||
#define CHECK(cond, what) do { if (!(cond)) { fails++; printf("FAIL line %d: %s\n", __LINE__, what); } } while (0)
|
||||
|
||||
@PICK_RESERVED@
|
||||
|
||||
#define MB(n) ((uint64_t)(n) << 20)
|
||||
#define KB(n) ((uint64_t)(n) << 10)
|
||||
static HosCache caches[512];
|
||||
static uint64_t cores[256];
|
||||
static unsigned char classes[256];
|
||||
static int ncaches, ncores;
|
||||
static void fresh(void) { ncaches = ncores = 0; }
|
||||
static void add_cores(int n, int per, int first, uint64_t l2, unsigned char cls) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
const uint64_t m = ((1ull << per) - 1) << (first + i * per);
|
||||
cores[ncores] = m, classes[ncores++] = cls;
|
||||
caches[ncaches++] = (HosCache){1, m, KB(32)};
|
||||
caches[ncaches++] = (HosCache){2, m, l2};
|
||||
}
|
||||
}
|
||||
static void add_l3(uint64_t mask, uint64_t bytes) { caches[ncaches++] = (HosCache){3, mask, bytes}; }
|
||||
static HosL3Home h;
|
||||
static uint64_t pick(uint64_t allowed, int groups) { return hos_l3_home_pick(caches, ncaches, cores, ncores, allowed, groups, &h); }
|
||||
/* the replay's core as hos_thread.c picks it: among the home's cores when there is one */
|
||||
static uint64_t reserved(uint64_t home) {
|
||||
uint64_t m[256];
|
||||
unsigned char c[256];
|
||||
int n = 0;
|
||||
for (int i = 0; i < ncores; i++)
|
||||
if (!home || (cores[i] & home)) m[n] = cores[i], c[n++] = classes[i];
|
||||
return pick_reserved_core(m, c, n);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* Ryzen 9 5900X: 12 cores with SMT, two dies of 6, an L3 of 32 MB each */
|
||||
fresh();
|
||||
add_cores(12, 2, 0, KB(512), 0);
|
||||
add_l3(0xFFF, MB(32)), add_l3(0xFFF000, MB(32));
|
||||
CHECK(pick(0xFFFFFF, 1) == 0xFFF && h.why == HOS_L3_HOME_USED && h.cores == 6 && h.domains == 2, "5900X: the first die");
|
||||
CHECK(reserved(0xFFF) == 0xC00, "5900X: the kept core is the first die's last (it was the processor's last, 0xC00000)");
|
||||
CHECK(reserved(0) == 0xC00000, "5900X: without a home, the processor's last core, as before");
|
||||
CHECK(hos_l3_home_thread_mask(0xFFFFFF, 0xFFF, 0xC00) == 0x3FF, "5900X: the two threads on the first die's other five cores");
|
||||
CHECK(hos_l3_home_thread_mask(0xFFFFFF, 0, 0xC00000) == 0, "no home: the two threads get nothing of their own");
|
||||
/* (the same, the process without logical processor 0: the die of its lowest) */
|
||||
CHECK(pick(0xFFFFFE, 1) == 0xFFE && h.cores == 6, "5900X without LP 0: the first die, what is left of it");
|
||||
CHECK(pick(0xFFFFFC, 1) == 0 && h.home == 0xFFC && h.why == HOS_L3_HOME_FEW && h.cores == 5, "5900X without core 0: five cores, too few");
|
||||
CHECK(pick(0xFFF000, 1) == 0 && h.why == HOS_L3_HOME_ONE, "5900X held to the second die: one L3, nothing");
|
||||
CHECK(pick(0xFFFFFF, 2) == 0 && h.why == HOS_L3_HOME_GROUPS, "more than one processor group: nothing");
|
||||
|
||||
/* Ryzen 9 5900X with SMT off: 12 logical processors */
|
||||
fresh();
|
||||
add_cores(12, 1, 0, KB(512), 0);
|
||||
add_l3(0x3F, MB(32)), add_l3(0xFC0, MB(32));
|
||||
CHECK(pick(0xFFF, 1) == 0x3F && h.cores == 6, "5900X, SMT off: the first die");
|
||||
/* (6 logical processors on the die: pick_reserved_core keeps none under 8, so the two threads have all six) */
|
||||
CHECK(reserved(0x3F) == 0, "5900X, SMT off: no core kept on the die");
|
||||
CHECK(hos_l3_home_thread_mask(0xFFF, 0x3F, 0) == 0x3F, "5900X, SMT off: the two threads on the whole first die");
|
||||
|
||||
/* Ryzen 9 5950X / 7950X: 16 cores with SMT, two dies of 8 */
|
||||
fresh();
|
||||
add_cores(16, 2, 0, MB(1), 0);
|
||||
add_l3(0xFFFF, MB(32)), add_l3(0xFFFF0000, MB(32));
|
||||
CHECK(pick(0xFFFFFFFF, 1) == 0xFFFF && h.cores == 8, "5950X: the first die");
|
||||
CHECK(reserved(0xFFFF) == 0xC000, "5950X: the first die's last core");
|
||||
|
||||
/* Ryzen 5 5600X: 6 cores, one L3 */
|
||||
fresh();
|
||||
add_cores(6, 2, 0, KB(512), 0);
|
||||
add_l3(0xFFF, MB(32));
|
||||
CHECK(pick(0xFFF, 1) == 0 && h.why == HOS_L3_HOME_ONE, "5600X: one L3, nothing");
|
||||
|
||||
/* Ryzen 7 7800X3D: one L3 of 96 MB */
|
||||
fresh();
|
||||
add_cores(8, 2, 0, MB(1), 0);
|
||||
add_l3(0xFFFF, MB(96));
|
||||
CHECK(pick(0xFFFF, 1) == 0 && h.why == HOS_L3_HOME_ONE, "7800X3D: nothing");
|
||||
|
||||
/* Ryzen 9 7950X3D: L3 caches of 96 and 32 MB: hos_x3d.h's */
|
||||
fresh();
|
||||
add_cores(16, 2, 0, MB(1), 0);
|
||||
add_l3(0xFFFF, MB(96)), add_l3(0xFFFF0000, MB(32));
|
||||
CHECK(pick(0xFFFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_MIXED, "7950X3D: nothing here");
|
||||
|
||||
/* Ryzen 9 3900X: four CCXs of 3 cores, 16 MB each; Ryzen 7 3700X: two of 4 */
|
||||
fresh();
|
||||
add_cores(12, 2, 0, KB(512), 0);
|
||||
add_l3(0x3F, MB(16)), add_l3(0xFC0, MB(16)), add_l3(0x3F000, MB(16)), add_l3(0xFC0000, MB(16));
|
||||
CHECK(pick(0xFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_FEW && h.cores == 3 && h.domains == 4, "3900X: too few cores");
|
||||
fresh();
|
||||
add_cores(8, 2, 0, KB(512), 0);
|
||||
add_l3(0xFF, MB(16)), add_l3(0xFF00, MB(16));
|
||||
CHECK(pick(0xFFFF, 1) == 0 && h.why == HOS_L3_HOME_FEW, "3700X: too few cores");
|
||||
|
||||
/* Intel Core i7-13700K: 8 performance cores with SMT, 8 efficiency cores, one L3 */
|
||||
fresh();
|
||||
add_cores(8, 2, 0, MB(2), 1);
|
||||
add_cores(8, 1, 16, MB(4), 0);
|
||||
add_l3(0xFFFFFF, MB(30));
|
||||
CHECK(pick(0xFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_ONE, "13700K: one L3, nothing");
|
||||
|
||||
/* a list that puts a processor under two L3 caches */
|
||||
fresh();
|
||||
add_cores(12, 2, 0, KB(512), 0);
|
||||
add_l3(0xFFF, MB(32)), add_l3(0xFF0FF0, MB(32));
|
||||
CHECK(pick(0xFFFFFF, 1) == 0 && h.why == HOS_L3_HOME_NONE, "overlapping L3 caches: nothing");
|
||||
fresh();
|
||||
add_cores(4, 2, 0, KB(512), 0);
|
||||
CHECK(pick(0xFF, 1) == 0 && h.why == HOS_L3_HOME_NONE, "no L3 listed: nothing");
|
||||
|
||||
/* the two threads, by name */
|
||||
CHECK(hos_l3_home_thread("sead::MainThread") && hos_l3_home_thread("MainThread") && hos_l3_home_thread("Presentation Thread"),
|
||||
"the main and presenting threads");
|
||||
CHECK(!hos_l3_home_thread("OptimizeChangeBank") && !hos_l3_home_thread("AudioThread") && !hos_l3_home_thread("") &&
|
||||
!hos_l3_home_thread(0), "no other thread");
|
||||
|
||||
if (!fails) printf("all checks passed\n");
|
||||
return fails != 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def check_source(thread):
|
||||
detect = block(thread, "static uint64_t x3d_detect(")
|
||||
cpus = block(thread, "static uint64_t hos_x3d_cpus(")
|
||||
last = block(thread, "static uint64_t last_fastest_core(")
|
||||
pin = block(thread, "void hos_thread_pin(")
|
||||
for text, needle, why in (
|
||||
(thread, '#include "hos_l3_home.h"', "the header is not included"),
|
||||
(detect, "hos_l3_home_pick(caches, ncaches, cores, ncores, (uint64_t)proc, (int)GetActiveProcessorGroupCount(), home);",
|
||||
"the home is not picked from the caches the cache die's rule reads"),
|
||||
(cpus, 'getenv("HOS_L3_HOME")', "HOS_L3_HOME is not read"),
|
||||
(cpus, "if (!mask && h.why == HOS_L3_HOME_USED && !home_off) l3_home_mask = h.home;",
|
||||
"the home is used with a cache die, with HOS_L3_HOME=0, or when the rule did not fire"),
|
||||
(cpus, 'hos_log("cpu: logical processors %#llx share one of %d L3 caches', "what was found is not logged"),
|
||||
(last, "const uint64_t home = die ? 0 : l3_home_mask;", "the kept core is not chosen with the home"),
|
||||
(last, "(!home || ((uint64_t)e->Processor.GroupMask[0].Mask & home))", "the kept core is not among the home's cores"),
|
||||
(pin, "if (l3_home_mask && hos_l3_home_thread(name)) {", "the two threads are not kept on the home"),
|
||||
(pin, "hos_l3_home_thread_mask((uint64_t)proc, l3_home_mask, reserved)", "the two threads' affinity is not the header's")):
|
||||
if needle not in text:
|
||||
raise SystemExit("host/hos_thread.c: " + why)
|
||||
# (the reserved core first: hos_reserved_cpus reads the caches before the home is looked at)
|
||||
if pin.index("hos_reserved_cpus()") > pin.index("if (l3_home_mask && hos_l3_home_thread(name)) {"):
|
||||
raise SystemExit("host/hos_thread.c: hos_thread_pin reads the home before the caches are read")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cc", default="gcc")
|
||||
args = parser.parse_args()
|
||||
thread = (ROOT / "host/hos_thread.c").read_text(encoding="utf-8")
|
||||
check_source(thread)
|
||||
fixture = FIXTURE.replace("@PICK_RESERVED@", block(thread, "static uint64_t pick_reserved_core("))
|
||||
with tempfile.TemporaryDirectory(prefix="l3home-") as d:
|
||||
tmp = Path(d)
|
||||
(tmp / "t.c").write_text(fixture, encoding="utf-8")
|
||||
exe = tmp / ("t.exe" if sys.platform == "win32" else "t")
|
||||
subprocess.run([args.cc, "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-O1", "-I", str(ROOT / "host"),
|
||||
str(tmp / "t.c"), "-o", str(exe)], check=True)
|
||||
run = subprocess.run([str(exe)], text=True, capture_output=True, timeout=60)
|
||||
sys.stdout.write(run.stdout)
|
||||
if run.returncode or "all checks passed" not in run.stdout:
|
||||
raise SystemExit("the home's checks failed" + run.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -37,6 +37,10 @@ ALLOWED = {
|
||||
("achievements.c", "read_text", "fread"): "into a buffer it mallocs",
|
||||
("achievements.c", "earned_save", "fwrite"): "from a static buffer of its own, the earned achievements' text",
|
||||
("bug_capture.c", "read_part", "fread"): "into a buffer it mallocs",
|
||||
("save_files.c", "files_read", "fread"): "into a static buffer of its own, triforce_files.txt's text",
|
||||
("save_files.c", "files_save", "fwrite"): "from a static buffer of its own, triforce_files.txt's text",
|
||||
("save_files.c", "card_of", "fread"): "into a buffer on its stack, a file's triforce_card.txt",
|
||||
("save_files.c", "card_keep", "fwrite"): "from a buffer on its stack, this file's triforce_card.txt",
|
||||
("nn_fs.c", "hos_fs_rom_file", "ReadFile"): "a RomFS file for the menu sounds (host/menu_sound.c), into a buffer it mallocs",
|
||||
("bug_capture.c", "write_file", "fwrite"): "the report's own files: the options file and a log read into host memory",
|
||||
("discord_rpc.c", "ipc_write", "WriteFile"): "Discord's pipe: a JSON message the host built",
|
||||
|
||||
@@ -18,7 +18,7 @@ def main():
|
||||
table = table[:table.index("\n};")]
|
||||
restart = []
|
||||
for entry in re.split(r"\n \{TAB_", table)[1:]:
|
||||
name = re.match(r'\w+, "([^"]+)"', entry).group(1)
|
||||
name = re.match(r'\w+, ("[^"]+"|\w+),', entry).group(1).strip('"')
|
||||
flags = re.findall(r"\b(true|false)\b", entry)
|
||||
if flags and flags[0] == "true":
|
||||
restart.append(name)
|
||||
|
||||
@@ -10,6 +10,11 @@ volume) is cut out of vk_menu.cpp with its label and the options file's reading,
|
||||
hooks in menu_tick (the state before and after, nothing put with the row at 0), the renderer's two options, and the
|
||||
row's lines in readme.md and docs/development.md. tests/test_menu_sound.py has the host's side.
|
||||
|
||||
((Triforce, 11-22, N64 Classic) The Remembered page, opened from Graphics' Remembered settings row: a page of its own to the
|
||||
ear, as the Motion page is (its row and its Back take their press for themselves): opened with decide, left with cancel, its
|
||||
Copy Faithful and Reset to defaults a decide. Read in vk_menu.cpp: sound_state gives it its own page, and those two rows keep
|
||||
their press for the sound.)
|
||||
|
||||
python -I -B tests/test_menu_sound_events.py [--cxx g++]
|
||||
"""
|
||||
import argparse
|
||||
@@ -128,6 +133,13 @@ int main() {
|
||||
CHECK(sound_of(on_page(rows(3, 4), 1, 6), rows(3, 4), In().back_()) == kCancel);
|
||||
CHECK(sound_of(rows(3, 2), on_page(rows(3, 2), 7), In()) == kDecide);
|
||||
CHECK(sound_of(on_page(rows(3, 2), 7, 1), rows(3, 2), In()) == kCancel);
|
||||
/* ((Triforce, N64 Classic) the Remembered page, likewise (its page, 10, under Graphics' tab): even onto the same row number
|
||||
and value, opening is a decide and Back a cancel; its two action rows a decide; Up and Down on it the cursor */
|
||||
CHECK(sound_of(rows(2, 2), on_page(rows(2, 2), 10, 2), In()) == kDecide);
|
||||
CHECK(sound_of(on_page(rows(2, 2), 10, 2), rows(2, 2), In()) == kCancel);
|
||||
CHECK(sound_of(on_page(rows(2, 2), 10, 23), on_page(rows(2, 2), 10, 23), In().confirm_()) == kDecide);
|
||||
CHECK(sound_of(on_page(rows(2, 2), 10, 3), on_page(rows(2, 2), 10, 4), In().move_()) == kCursor);
|
||||
CHECK(sound_of(rows(2, 2), rows(2, 2), In()) == kNone); /* (as Graphics' rows alone: nothing, which was the silence) */
|
||||
/* out of a mode by Back: an amount, a flag's On and Off, a Restart waiting for its second press */
|
||||
CHECK(sound_of(on_page(rows(5, 0), 4, 3, 0, kModeEdit), on_page(rows(5, 0), 4, 3), In().back_()) == kCancel);
|
||||
CHECK(sound_of(with_mode(rows(4, 1), kModeConfirm), rows(4, 1), In().back_()) == kCancel);
|
||||
@@ -269,6 +281,16 @@ def main():
|
||||
check("menu_sound::kSysCursor == HOS_MENU_SOUND_SYS_CURSOR" in menu and "menu_sound::kSysDecide == HOS_MENU_SOUND_SYS_DECIDE" in menu
|
||||
and "menu_sound::kFanfare == HOS_MENU_SOUND_FANFARE" in menu and "menu_sound::kLast + 1 == HOS_MENU_SOUND_N" in menu,
|
||||
"vk_menu.cpp does not hold the Mods entry's sounds (the fanfare, the system menu's cursor and decide) against vk_api.h's")
|
||||
# ((Triforce, 11-22, N64 Classic) the Remembered page: its own page to the ear, and its two actions' press kept for the sound
|
||||
check("constexpr int kSoundPageN64 = 10;" in menu, "vk_menu.cpp: the Remembered page has no page of its own to the ear (10)")
|
||||
state = block(menu, "static menu_sound::State sound_state() {")
|
||||
check("const bool n64_page = page == 0 && cur_tab == TAB_N64;" in state and
|
||||
"s.page = motion ? kSoundPageMotion : n64_page ? kSoundPageN64 : page;" in state and
|
||||
"cur_tab == TAB_N64 ? (int)TAB_GRAPHICS : cur_tab" in state,
|
||||
"sound_state: the Remembered page is not its own page under Graphics' tab")
|
||||
check("else if (press[7] && n64_action(r)) n64_act(n64_action(r)), changed = true;" in tick and
|
||||
"else if (press[7] && is_n64_page_row(r)) cur_tab = TAB_N64," in tick,
|
||||
"menu_tick: Copy Faithful and Reset to defaults do not keep their press for the sound (decide)")
|
||||
events = (vk / "menu_sound_events.h").read_text(encoding="utf-8")
|
||||
check("if (sound <= kNone || sound > kLast) return false;" in events,
|
||||
"the sounds' queue does not take every sound up to kLast (the Mods entry's are dropped)")
|
||||
|
||||
@@ -222,6 +222,7 @@ LOAD = r"""
|
||||
#include "@VK@/framegen_rows.h"
|
||||
#include "@VK@/merged_rows.h"
|
||||
#include "@VK@/ultrawide_rows.h"
|
||||
#include "@VK@/output_sizes.h"
|
||||
#include "@VK@/replay_threads.h"
|
||||
#include "@VK@/ini_merge.h"
|
||||
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); return 1; } } while (0)
|
||||
@@ -247,7 +248,7 @@ constexpr int kRows = sizeof rows / sizeof rows[0];
|
||||
std::string path;
|
||||
std::string ini_path() { return path; }
|
||||
ini_merge::Map ini_base;
|
||||
std::string mic_want;
|
||||
std::string mic_want, gpu_want;
|
||||
std::string mic_key(const char* name) { return name; }
|
||||
void refresh_mics() {}
|
||||
void mic_tell_host() {}
|
||||
@@ -318,7 +319,7 @@ int main(int argc, char** argv) {
|
||||
FILE* w = std::fopen(argv[2], "w");
|
||||
for (const Row& r : rows)
|
||||
if (ini_row(r)) std::fprintf(w, "%s=%d\n", ini_key(r), *r.value);
|
||||
std::fprintf(w, "options_version=%d\n", mr7::kVersion);
|
||||
std::fprintf(w, "options_version=%d\n", OUTPUT_OPTIONS_VERSION);
|
||||
std::fclose(w);
|
||||
}
|
||||
opts = Options{};
|
||||
@@ -393,10 +394,12 @@ def load_fixture():
|
||||
stubs = "\n".join("const char* %s(int%s) { return nullptr; }" % (n, ", int" if n.startswith("hn_") else "") for n in names)
|
||||
mod_rows = menu[menu.index("#define MOD_CHEAT_ROW(i)"):menu.index("static_assert(mod_cheat_rows::kSlots")]
|
||||
merged = menu[menu.index("struct Merged {"):menu.index("Row rows[] = {")]
|
||||
out = menu[menu.index("struct Out {"):menu.index("int step_output_choice(int id, int dir) {")]
|
||||
out = menu[menu.index("struct Out {"):menu.index("// The connected screens as the host found them")]
|
||||
out += "\nOut remembered_custom{};\nOut main_screen() { return {2560, 1440}; }\n"
|
||||
out += definition(menu, "void custom_rows_read") + "\n" + definition(menu, "void read_remembered_custom")
|
||||
init = definition(menu, "void menu_init")
|
||||
reading = block(init, init.index('if (FILE* f = fopen(ini_path().c_str(), "r")) {'))
|
||||
check("merged_rows::migrate(version, before7, opts.output_res, opts.lstick_dead_zone, opts.rstick_dead_zone);" in reading,
|
||||
check("merged_rows::migrate(legacy_output && version == 8 ? 7 : version, before7," in reading,
|
||||
"menu_init's reading of the file does not migrate an older one")
|
||||
sync = definition(menu, "void merged_sync")
|
||||
fixture = LOAD
|
||||
@@ -415,7 +418,7 @@ def main():
|
||||
parser.add_argument("--cxx", default="g++")
|
||||
args = parser.parse_args()
|
||||
menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
|
||||
check('out += "options_version=8\\n";' in definition(menu, "void save"), "save does not write options_version=8")
|
||||
check('out += "options_version=9\\n";' in definition(menu, "void save"), "save does not write options_version=9")
|
||||
check("for (const char* dropped : merged_rows::kDropped) mine |= key == dropped;" in definition(menu, "void save"),
|
||||
"save writes back the lines of the rows that went")
|
||||
with tempfile.TemporaryDirectory(prefix="merged-rows-") as tmp:
|
||||
|
||||
@@ -538,7 +538,7 @@ def main():
|
||||
check("my < e[1] && my > e[1] - (quit_here ? 6 : 4) * e[4]) mods_row_sel = 0, press[1] = true;" in tick,
|
||||
"the mouse moving up off the title's entry does not give the cursor back")
|
||||
check(tick.count("(mods_list_fresh() || mods_title_fading())") == 0 and
|
||||
menu.count("mods_row = !open && !start && (mods_list_fresh() || mods_title_fading());") == 1 and
|
||||
menu.count("s.mods_row = !s.open && !s.start && (mods_list_fresh() || mods_title_fading());") == 1 and
|
||||
menu.count("mods_row = !open && (mods_list_fresh() || mods_title_fading());") == 1,
|
||||
"the title's entry is not drawn on while it fades after its list (menu_record, menu_record_image)")
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ FIXTURE = r'''#define _CRT_SECURE_NO_WARNINGS
|
||||
#include "step_steady.h"
|
||||
#include "pace_steady.h"
|
||||
#include "movie_pace.h"
|
||||
#include "n64_pace.h" /* ((Triforce, N64 Classic) pace_fps and movie_pace_decide take its rate: none here (rx_option says 0)) */
|
||||
static int fails = 0;
|
||||
#define CHECK(x) do { if (!(x)) { printf("FAIL:%d %s\n", __LINE__, #x); fails++; } } while (0)
|
||||
typedef long long LONG64;
|
||||
@@ -124,6 +125,7 @@ int rx_option(int id, int otherwise) { (void)id; return otherwise; }
|
||||
static int steady_row; /* (the options file's steady_frame_rate) */
|
||||
int hos_ini_option(const char *key, int otherwise) { return strcmp(key, "steady_frame_rate") ? otherwise : steady_row; }
|
||||
enum { HOS_OPT_DISPLAY_CAP = 60 };
|
||||
enum { HOS_OPT_N64_FPS = 61 };
|
||||
static volatile long long presents;
|
||||
volatile uint64_t hos_gfx_module = MOD;
|
||||
volatile int hos_fixed_resolution, hos_dynres_runs;
|
||||
@@ -240,7 +242,8 @@ def main():
|
||||
vi = (HOST / "nn_vi.c").read_text(encoding="utf-8")
|
||||
|
||||
check('#include "movie_pace.h"' in vi, "nn_vi.c does not take movie_pace.h")
|
||||
check("return movie_pace_fps(movie_raise, fps_max());" in block(vi, "static int pace_fps(void) {"), "pace_fps is not the rule's")
|
||||
check("return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max()));" in block(vi, "static int pace_fps(void) {"),
|
||||
"pace_fps is not the rule's (N64 Classic's rate over it: tests/test_n64_pace.py)")
|
||||
decide = block(vi, "static void movie_pace_decide(void) {")
|
||||
check('if (on < 0) on = !(getenv("HOS_MOVIE_PACE") && *getenv("HOS_MOVIE_PACE") && atoi(getenv("HOS_MOVIE_PACE")) == 0);' in decide,
|
||||
"HOS_MOVIE_PACE is not read once, on unless 0")
|
||||
@@ -255,7 +258,7 @@ def main():
|
||||
check("movie_seen();" in block(vi, "uint32_t hos_movie_frames(uint64_t player) {")[:400], "a movie player's update is not noted")
|
||||
|
||||
presented = block(vi, "void hos_vi_native_presented(void) {")
|
||||
order = [presented.index(s) for s in ("const int interval = fps_max() < 60 ? 1 : present_interval;", "movie_pace_decide();",
|
||||
order = [presented.index(s) for s in ("const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval);", "movie_pace_decide();",
|
||||
"const int64_t period = steady_period(1000000000LL / pace_fps() * interval, now);",
|
||||
"pace_period_ns = period;", "realtime_step(now);")]
|
||||
check(order == sorted(order) and presented.count("movie_pace_decide();") == 1,
|
||||
@@ -278,7 +281,8 @@ def main():
|
||||
|
||||
movie = vi[vi.index("static volatile LONG64 movie_seen_ns;"):vi.index("static int pace_handed(void) {")]
|
||||
host = "\n".join([block(vi, "static int fps_cap_of("), block(vi, "static int fps_max(void) {"), movie, "static int movie_raise;",
|
||||
block(vi, "static int pace_fps(void) {"), decide, block(vi, "static float text_scale("),
|
||||
"static int n64_rate;", block(vi, "static int pace_fps(void) {"), block(vi, "static void n64_pace_decide(void) {"),
|
||||
decide, block(vi, "static float text_scale("),
|
||||
block(vi, "static int realtime_rate("), step])
|
||||
with tempfile.TemporaryDirectory(prefix="movie-pace-") as tmp:
|
||||
src, exe = Path(tmp) / "rules.c", Path(tmp) / "rules.exe"
|
||||
|
||||
191
tests/test_n64_3d.py
Normal file
191
tests/test_n64_3d.py
Normal file
@@ -0,0 +1,191 @@
|
||||
"""N64 Classic's 3D pass (gpu/vk/shaders/n64_3d.comp; vk_draw.cpp n64_upscale and taau_stand_in) and what steps aside for
|
||||
it while it draws: DLSS and FSR 4 (vk_temporal.cpp temporal_mode), FSR 3.1 (vk_fsr3.cpp fsr3_wanted) and the game's SMAA
|
||||
(vk_aa.cpp). Step 2 of n64-classic-mode-plan.md, behind RX_VK_N64 (vk_n64.cpp). No game, no GPU.
|
||||
|
||||
n64_3d_comp_spv.h names the hash of the sources it was compiled from (n64_3d.comp and n64_common.glsl, its first line),
|
||||
checked against the files as they are, with or without glslang; with glslangValidator of the version the header names,
|
||||
the rest of the header is the pass compiled now, byte for byte. --write makes the header.
|
||||
|
||||
Read in the sources: the shader includes n64_common.glsl and keeps each channel with it on the grid's own pixels, takes
|
||||
the square root encoding off the network's input, drops a texel that is not a number, and shows each output pixel from
|
||||
its grid row whole and a place along it; n64_upscale's push constants are the shader's, in its order, its grid image is
|
||||
RGBA16F storage made again at a new size, and its two dispatches have a barrier between; taau_stand_in asks n64_3d_now,
|
||||
hands it to upscale_off.h, looks at the input for the grid's size, draws under the recording lock and still takes the
|
||||
picture before the HUD; temporal_mode, fsr3_wanted and the Anti-aliasing row's choice ask n64_rules.h with
|
||||
n64_in_front; vk_n64.cpp reads the switches and leaves a RenoDX run's RGBA16F scene alone; the development guide names
|
||||
the switches. The rule each of these asks is run by tests/test_n64_rules.py and tests/test_upscale_off.py.
|
||||
|
||||
python -I -B tests/test_n64_3d.py [--glslang glslangValidator] [--write]
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
SHADERS = VK / "shaders"
|
||||
PARTS = ("n64_3d.comp", "n64_common.glsl")
|
||||
HEADER = SHADERS / "n64_3d_comp_spv.h"
|
||||
FLAGS = ["-V", "--target-env", "vulkan1.2", "--vn", "N64_3D_COMP_SPV"]
|
||||
|
||||
|
||||
def fail(what):
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
|
||||
def source_line():
|
||||
"""the header's first line: the hash of the pass's sources (each by its name and its bytes, line ends as LF) and how it is made"""
|
||||
digest = hashlib.sha256()
|
||||
for part in PARTS:
|
||||
digest.update(part.encode() + b"\0" + (SHADERS / part).read_bytes().replace(b"\r\n", b"\n") + b"\0")
|
||||
return ("// %s sha256 %s (tests/test_n64_3d.py --write: glslangValidator %s)\n"
|
||||
% (" + ".join(PARTS), digest.hexdigest(), " ".join(FLAGS))).encode()
|
||||
|
||||
|
||||
def compiled(glslang, tmp):
|
||||
out = Path(tmp) / "n64_3d.h"
|
||||
r = subprocess.run([glslang, *FLAGS, "-o", str(out), str(SHADERS / "n64_3d.comp")], capture_output=True, text=True)
|
||||
if r.returncode:
|
||||
fail("n64_3d.comp does not compile:\n%s%s" % (r.stdout, r.stderr))
|
||||
return out.read_bytes().replace(b"\r\n", b"\n")
|
||||
|
||||
|
||||
def glslang_version(glslang):
|
||||
got = subprocess.run([glslang, "--version"], capture_output=True, text=True).stdout
|
||||
m = re.search(r"Glslang Version: \d+:(\d+)\.(\d+)\.(\d+)", got)
|
||||
return m and "11%02d.%s.%s" % (int(m.group(1)), m.group(2), m.group(3))
|
||||
|
||||
|
||||
def function(src, head):
|
||||
at = src.index(head)
|
||||
return src[at:src.index("\n}\n", at)]
|
||||
|
||||
|
||||
def in_order(text, parts, what):
|
||||
at = [text.find(p) for p in parts]
|
||||
if min(at) < 0 or at != sorted(at):
|
||||
fail("%s: %s" % (what, [p for p, a in zip(parts, at) if a < 0] or at))
|
||||
|
||||
|
||||
def check_shader():
|
||||
comp = (SHADERS / "n64_3d.comp").read_text(encoding="utf-8")
|
||||
in_order(comp, ['#extension GL_GOOGLE_include_directive : require', '#include "n64_common.glsl"', "void make(ivec2 g)",
|
||||
"void show(ivec2 o)", "void main()"], "n64_3d.comp no longer includes n64_common.glsl before its two passes")
|
||||
make = function(comp, "void make(ivec2 g)")
|
||||
for need in ("for (int j = 0; j < 4; j++)", "for (int i = 0; i < 4; i++)", "vec3 c = s * s;",
|
||||
"if (any(isnan(c)) || any(isinf(c))) c = vec3(0.0);", "n64_keep(c.r, pc.bits, pc.dither, g.x, g.y)",
|
||||
"n64_keep(c.g, pc.bits, pc.dither, g.x, g.y)", "n64_keep(c.b, pc.bits, pc.dither, g.x, g.y)",
|
||||
"imageStore(grid_img, g,"):
|
||||
if need not in make:
|
||||
fail("make: %s is gone (16 taps in linear light, no NaN, each channel kept on the grid's own pixel)" % need)
|
||||
show = function(comp, "void show(ivec2 o)")
|
||||
for need in ("n64_row(o.y, pc.grid.y, pc.size.y)", "n64_column(o.x, pc.grid.x, pc.size.x)", "imageLoad(grid_img,",
|
||||
"mix(a, b, t)", "imageStore(dst, o,"):
|
||||
if need not in show:
|
||||
fail("show: %s is gone (a grid row whole, linear along it)" % need)
|
||||
push = re.search(r"layout\(push_constant\) uniform P \{(.*?)\} pc;", comp, re.S)
|
||||
fields = re.findall(r"^\s*(\w+) (\w+);", push.group(1), re.M) if push else []
|
||||
if fields != [("ivec2", "grid"), ("ivec2", "size"), ("int", "pass"), ("int", "bits"), ("float", "dither")]:
|
||||
fail("n64_3d.comp's push constants are not grid, size, pass, bits, dither: %s" % fields)
|
||||
for b in ("layout(binding = 0) uniform sampler2D src;", "layout(binding = 1, rgba16f) uniform image2D grid_img;",
|
||||
"layout(binding = 2, r11f_g11f_b10f) uniform writeonly image2D dst;"):
|
||||
if b not in comp:
|
||||
fail("n64_3d.comp: %s is not its binding" % b)
|
||||
|
||||
|
||||
def check_draw():
|
||||
draw = (VK / "vk_draw.cpp").read_text(encoding="utf-8")
|
||||
for inc in ('#include "vk_n64.h"', '#include "shaders/n64_3d_comp_spv.h"'):
|
||||
if inc not in draw:
|
||||
fail("vk_draw.cpp does not %s" % inc)
|
||||
up = function(draw, "static bool n64_upscale(")
|
||||
for need in ("struct Push {\n int32_t grid[2], size[2];\n int32_t pass, bits;\n float dither;\n };",
|
||||
"mi.codeSize = sizeof N64_3D_COMP_SPV, mi.pCode = N64_3D_COMP_SPV;",
|
||||
"const VkPushConstantRange pr{VK_SHADER_STAGE_COMPUTE_BIT, 0, (uint32_t)sizeof(Push)};",
|
||||
"const n64_rules::Grid g = n64_rules::grid(look.lines, ow, oh);",
|
||||
"ic.format = VK_FORMAT_R16G16B16A16_SFLOAT", "ic.usage = VK_IMAGE_USAGE_STORAGE_BIT",
|
||||
"if (texture_frame_no() - old[i].frame < 120)",
|
||||
"Push pc{{(int32_t)g.w, (int32_t)g.h}, {(int32_t)ow, (int32_t)oh}, 0, look.colour_bits, look.dither};",
|
||||
"descriptors_disturbed();"):
|
||||
if need not in up:
|
||||
fail("n64_upscale: %s is gone" % need.split("\n")[0])
|
||||
in_order(up, ["vkCmdDispatch(cmd, (g.w + 7) / 8, (g.h + 7) / 8, 1);", 'full_barrier(cmd, "barrier (N64 Classic\'s grid)");',
|
||||
"pc.pass = 1;", "vkCmdDispatch(cmd, (ow + 7) / 8, (oh + 7) / 8, 1);"],
|
||||
"n64_upscale: the grid, a barrier, then the picture from it")
|
||||
stand = function(draw, "bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {")
|
||||
in_order(stand, ["const bool n64 = n64_3d_now();", "const bool shaped = (off || n64) &&",
|
||||
"upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped, n64);",
|
||||
"if (ch.by_shape || ch.n64) {", "ParLock lk;",
|
||||
"if (ch.n64) done = n64_upscale(cmd, dw().imgs[0].imageView, in, dw().imgs[ntex].imageView, out, level);",
|
||||
"if (done) hudless_after_dispatch(cmd, p.key);"],
|
||||
"taau_stand_in no longer asks n64_3d_now, looks at the input, draws N64 Classic's pass under the lock and takes the picture")
|
||||
|
||||
|
||||
def check_asides():
|
||||
temporal = (VK / "vk_temporal.cpp").read_text(encoding="utf-8")
|
||||
mode = function(temporal, "int temporal_mode() {")
|
||||
in_order(mode, ["v = n64_rules::upscaler(n64_in_front(), v);", "if (!ur::is_dlss(v) && !ur::is_fsr4(v)) return ur::GAME;"],
|
||||
"temporal_mode: DLSS and FSR 4 no longer step aside for N64 Classic's 3D pass, over the switches too")
|
||||
fsr3 = function((VK / "vk_fsr3.cpp").read_text(encoding="utf-8"), "bool fsr3_wanted() {")
|
||||
in_order(fsr3, ["if (env == 0) return false;",
|
||||
"if (n64_rules::upscaler(n64_in_front(), upscaler_rows::FSR3) != upscaler_rows::FSR3) return false;",
|
||||
"return (env > 0 ||"], "fsr3_wanted: FSR 3.1 no longer steps aside for N64 Classic's 3D pass")
|
||||
aa = (VK / "vk_aa.cpp").read_text(encoding="utf-8")
|
||||
choice = function(aa, "int choice_now() {")
|
||||
if "return env_choice() >= 0 ? choice : n64_rules::anti_aliasing(n64_in_front(), choice);" not in choice:
|
||||
fail("vk_aa.cpp choice_now: the game's SMAA is no longer left out for N64 Classic's 3D pass, or RX_VK_AA no longer goes over it")
|
||||
if "const int choice = choice_now();" not in function(aa, "int aa_mode() {") or "bool aa_asked() { return choice_now() != ar::GAME ||" not in aa:
|
||||
fail("vk_aa.cpp: aa_mode and aa_asked no longer ask choice_now")
|
||||
n64 = (VK / "vk_n64.cpp").read_text(encoding="utf-8")
|
||||
for need in ('env_number("RX_VK_N64", -1)', 'env_number("RX_VK_N64_LINES", -1)', 'getenv("RX_VK_N64_LOD")',
|
||||
'env_number("RX_VK_N64_TV", -1)', 'env_number("RX_VK_N64_MASK", -1)', 'env_number("RX_VK_N64_FPS", -1)',
|
||||
"temporal_scene_format(VK_FORMAT_R16G16B16A16_SFLOAT)", "return n64_rules::three_d_runs(l, rgba16f);",
|
||||
"int n64_in_front() { return n64_3d_now() ? n64_shown() : (int)n64_rules::OFF; }"):
|
||||
if need not in n64:
|
||||
fail("vk_n64.cpp: %s is gone" % need)
|
||||
docs = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
|
||||
if "`RX_VK_N64=<0..2>`" not in docs or "`RX_VK_N64_LINES=<n>`" not in docs:
|
||||
fail("docs/development.md: RX_VK_N64 and the lab's switches are not in the switches table")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument("--glslang", default=None)
|
||||
parser.add_argument("--write", action="store_true")
|
||||
args = parser.parse_args()
|
||||
glslang = args.glslang or shutil.which("glslangValidator")
|
||||
if args.write:
|
||||
if not glslang:
|
||||
fail("--write needs glslangValidator")
|
||||
with tempfile.TemporaryDirectory(prefix="n64-3d-") as tmp:
|
||||
HEADER.write_bytes(source_line() + compiled(glslang, tmp))
|
||||
print("wrote %s" % HEADER.relative_to(ROOT))
|
||||
check_shader()
|
||||
check_draw()
|
||||
check_asides()
|
||||
if not HEADER.exists():
|
||||
fail("n64_3d_comp_spv.h is missing: run with --write")
|
||||
header = HEADER.read_bytes().replace(b"\r\n", b"\n")
|
||||
first, _, rest = header.partition(b"\n")
|
||||
if first + b"\n" != source_line():
|
||||
fail("n64_3d_comp_spv.h was not made from n64_3d.comp and n64_common.glsl as they are now: run with --write")
|
||||
if glslang:
|
||||
named = rest.split(b"\n", 1)[0].decode("ascii", "replace").strip().lstrip("/ ").strip()
|
||||
if glslang_version(glslang) == named:
|
||||
with tempfile.TemporaryDirectory(prefix="n64-3d-") as tmp:
|
||||
if compiled(glslang, tmp) != rest:
|
||||
fail("n64_3d_comp_spv.h is not n64_3d.comp compiled: run with --write")
|
||||
print("(the SPIR-V header is its source compiled, byte for byte)")
|
||||
else:
|
||||
print("(glslangValidator is not version %s: the header was not compiled again)" % named)
|
||||
else:
|
||||
print("(glslangValidator is not on the PATH: the header's hash was checked, not its bytes)")
|
||||
print("PASS: N64 Classic's 3D pass, its place in the gameplay upscale, and what steps aside for it")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
198
tests/test_n64_pace.py
Normal file
198
tests/test_n64_pace.py
Normal file
@@ -0,0 +1,198 @@
|
||||
"""N64 Classic's frame rate (host/n64_pace.h; host/nn_vi.c n64_pace_decide and pace_fps; gpu/vk/vk_replay.cpp's answer to
|
||||
HOS_OPT_N64_FPS). Step 7 of n64-classic-mode-plan.md. No game.
|
||||
|
||||
Compiles n64_pace.h alone, as tests/test_movie_pace.py does movie_pace.h: the switch read as HOS_MOVIE_PACE is; the rate
|
||||
taken only under the cap, at 15 and up, with no movie playing and the switch on; the pace N64 Classic's where it has one,
|
||||
else the cap's and a movie's; the present's interval 1 at its rate.
|
||||
|
||||
Runs nn_vi.c's own fps_cap_of, fps_max, movie_seen, movie_plays, pace_fps, movie_pace_decide and n64_pace_decide, cut out of
|
||||
the file, on a clock of its own, with the renderer's answer stood in for: at caps of 60, 45, 120 and 30 and rates of 20,
|
||||
17, 60, 30, 10 and none, a stretch of play, a movie, play again and the renderer's rate gone; with HOS_N64_PACE=0 too.
|
||||
At the 60 cap a movie still raises the pace to 240 over N64 Classic's 20, and the 20 is back a quarter second after the
|
||||
movie's last picture; each change is said once in the log.
|
||||
|
||||
Reads the sources: nn_vi.c takes n64_pace.h, its pace_fps is the rule's over the movie's, movie_pace_decide asks
|
||||
n64_pace_decide once a present, the present's interval is 1 at the rate, and the vsync event and fps_max still go by the
|
||||
cap; vk_api.h's HOS_OPT_N64_FPS is a number of its own; vk_replay.cpp answers it with n64_rules.h's rate while the 3D
|
||||
pass draws; the development guide names HOS_N64_PACE.
|
||||
|
||||
python -I -B tests/test_n64_pace.py [--cc clang]
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
HOST = ROOT / "host"
|
||||
RUN_ALL_ARGS = ["--cc", "clang"]
|
||||
|
||||
|
||||
def check(ok, why):
|
||||
if not ok:
|
||||
raise SystemExit("FAIL: " + why)
|
||||
|
||||
|
||||
def block(source, marker):
|
||||
"""From marker to the first line that starts with a closing brace"""
|
||||
start = source.index(marker)
|
||||
return source[start:start + re.search(r"^}", source[start:], re.M).end()]
|
||||
|
||||
|
||||
RULES = r"""
|
||||
#include <stdio.h>
|
||||
#include "n64_pace.h"
|
||||
static int fails = 0;
|
||||
#define CHECK(x) do { if (!(x)) { printf("FAIL:%d %s\n", __LINE__, #x); fails++; } } while (0)
|
||||
int main(void) {
|
||||
CHECK(n64_pace_on(NULL) && n64_pace_on("") && n64_pace_on("1") && !n64_pace_on("0") && !n64_pace_on("off"));
|
||||
CHECK(N64_PACE_LOWEST == 15);
|
||||
/* n64_pace_rate(on, asked, movie, cap) */
|
||||
CHECK(n64_pace_rate(1, 20, 0, 60) == 20 && n64_pace_rate(1, 17, 0, 60) == 17 && n64_pace_rate(1, 30, 0, 60) == 30);
|
||||
CHECK(n64_pace_rate(1, 20, 1, 60) == 0); /* a movie plays */
|
||||
CHECK(n64_pace_rate(0, 20, 0, 60) == 0); /* HOS_N64_PACE=0 */
|
||||
CHECK(n64_pace_rate(1, 60, 0, 60) == 0 && n64_pace_rate(1, 60, 0, 45) == 0); /* never at or above the cap */
|
||||
CHECK(n64_pace_rate(1, 60, 0, 120) == 60 && n64_pace_rate(1, 30, 0, 30) == 0);
|
||||
CHECK(n64_pace_rate(1, 14, 0, 60) == 0 && n64_pace_rate(1, 15, 0, 60) == 15 && n64_pace_rate(1, 0, 0, 60) == 0);
|
||||
for (int cap = 30; cap <= 240; cap++)
|
||||
for (int asked = 0; asked <= 250; asked++) {
|
||||
const int r = n64_pace_rate(1, asked, 0, cap);
|
||||
CHECK(r == 0 || (r == asked && r < cap && r >= 15)); /* only ever lower, and the step's to take */
|
||||
}
|
||||
/* n64_pace_fps(rate, paced) */
|
||||
CHECK(n64_pace_fps(20, 60) == 20 && n64_pace_fps(0, 240) == 240 && n64_pace_fps(0, 60) == 60 && n64_pace_fps(17, 45) == 17);
|
||||
/* n64_pace_interval(rate, interval) */
|
||||
CHECK(n64_pace_interval(20, 2) == 1 && n64_pace_interval(20, 1) == 1 && n64_pace_interval(0, 2) == 2 && n64_pace_interval(0, 1) == 1);
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
"""
|
||||
|
||||
FIXTURE = r'''#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "pace_steady.h"
|
||||
#include "movie_pace.h"
|
||||
#include "n64_pace.h"
|
||||
typedef long long LONG64;
|
||||
static int64_t clock_ns = 1000000000LL;
|
||||
int64_t hos_now_ns(void) { return clock_ns; }
|
||||
static char log_text[1 << 15];
|
||||
static void hos_log(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
const size_t n = strlen(log_text);
|
||||
va_start(ap, fmt);
|
||||
if (n + 600 < sizeof log_text) vsnprintf(log_text + n, 500, fmt, ap), strcat(log_text, "\n");
|
||||
va_end(ap);
|
||||
}
|
||||
static int logged(const char *text) {
|
||||
int n = 0;
|
||||
for (const char *p = log_text; (p = strstr(p, text)) != NULL; p += strlen(text)) n++;
|
||||
return n;
|
||||
}
|
||||
enum { HOS_OPT_DISPLAY_CAP = 60 };
|
||||
enum { HOS_OPT_N64_FPS = 61 };
|
||||
static int n64_asked; /* (the renderer's answer: vk_replay.cpp, n64_rules.h fps) */
|
||||
int rx_option(int id, int otherwise) { return id == HOS_OPT_N64_FPS ? n64_asked : otherwise; }
|
||||
int hos_ini_option(const char *key, int otherwise) { (void)key; return otherwise; }
|
||||
static volatile long long presents;
|
||||
@HOST@
|
||||
/* a present: the clock on by a frame, the decision as hos_vi_native_presented takes it */
|
||||
static int present(void) {
|
||||
clock_ns += 16666667;
|
||||
movie_pace_decide();
|
||||
return pace_fps();
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) return 2;
|
||||
n64_asked = atoi(argv[1]);
|
||||
int play = 0, movie = 0, after = 0, gone = 0;
|
||||
for (int i = 0; i < 30; i++) play = present();
|
||||
for (int i = 0; i < 30; i++) movie_seen(), movie = present(); /* a movie: its player updates every frame */
|
||||
clock_ns += 260000000LL; /* a quarter second after its last picture */
|
||||
for (int i = 0; i < 30; i++) after = present();
|
||||
n64_asked = 0; /* the renderer asks none: N64 Classic off */
|
||||
for (int i = 0; i < 30; i++) gone = present();
|
||||
printf("%d %d %d %d %d %d %d\n", fps_max(), play, movie, after, gone, logged("vi: N64 Classic: frames paced at "),
|
||||
logged("vi: N64 Classic: frames paced at the cap again"));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
# (the cap, by HOS_FPS_MAX; the rate the renderer asks; HOS_N64_PACE) -> the cap, the pace in play, in the movie, after it,
|
||||
# with the rate gone; the changes said, those back to the cap said
|
||||
CASES = (
|
||||
((60, 20, None), "60 20 240 20 60 4 2"), # (a movie at the 60 cap: 240 over the 20, and back)
|
||||
((60, 17, None), "60 17 240 17 60 4 2"),
|
||||
((45, 20, None), "45 20 45 20 45 4 2"), # (no movie raise at 45: the cap's while it plays)
|
||||
((120, 60, None), "120 60 120 60 120 4 2"),
|
||||
((30, 30, None), "30 30 30 30 30 0 0"), # (at the cap: nothing to lower)
|
||||
((60, 10, None), "60 60 240 60 60 0 0"), # (under the step's floor: not taken)
|
||||
((60, 0, None), "60 60 240 60 60 0 0"), # (N64 Classic off)
|
||||
((60, 20, "0"), "60 60 240 60 60 0 0"), # (HOS_N64_PACE=0)
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cc", default="clang")
|
||||
args = parser.parse_args()
|
||||
vi = (HOST / "nn_vi.c").read_text(encoding="utf-8")
|
||||
check('#include "n64_pace.h"' in vi, "nn_vi.c does not take n64_pace.h")
|
||||
check("return n64_pace_fps(n64_rate, movie_pace_fps(movie_raise, fps_max()));" in block(vi, "static int pace_fps(void) {"),
|
||||
"pace_fps is not N64 Classic's rate over the cap's and the movie's")
|
||||
decide = block(vi, "static void movie_pace_decide(void) {")
|
||||
check(decide.rstrip().endswith("n64_pace_decide(); /* ((Triforce, N64 Classic, step 7) its rate, beside the movie's */\n}"),
|
||||
"movie_pace_decide does not ask n64_pace_decide once a present, after the movie's decision")
|
||||
n64 = block(vi, "static void n64_pace_decide(void) {")
|
||||
for need in ('n64_pace_on(getenv("HOS_N64_PACE"))', "n64_rate = n64_pace_rate(on, on ? rx_option(HOS_OPT_N64_FPS, 0) : 0, movie_plays(), fps_max());"):
|
||||
check(need in n64, "n64_pace_decide: %s is gone" % need)
|
||||
presented = block(vi, "void hos_vi_native_presented(void) {")
|
||||
check("const int interval = n64_pace_interval(n64_rate, fps_max() < 60 ? 1 : present_interval);" in presented and
|
||||
presented.index("const int interval =") < presented.index("movie_pace_decide();") < presented.index("pace_fps() * interval"),
|
||||
"the present's interval is not 1 at N64 Classic's rate, or the period is not taken after the decision")
|
||||
check("1000000000LL / fps_max()" in block(vi, "static DWORD WINAPI vsync_main(void *p) {"), "the vsync event no longer goes by the cap")
|
||||
api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8")
|
||||
check("enum { HOS_OPT_N64_FPS = 61 };" in api and "enum { HOS_OPT_DISPLAY_CAP = 60 };" in api,
|
||||
"vk_api.h: HOS_OPT_N64_FPS is not 61, beside HOS_OPT_DISPLAY_CAP")
|
||||
taken = [int(v) for v in re.findall(r"HOS_OPT_\w+ = (\d+)", api)]
|
||||
check(taken.count(61) == 1 and not re.search(r"HOS_OPT_DISPLAY_CAP = 60, ", api), "vk_api.h: another option has 61")
|
||||
replay = (ROOT / "gpu" / "vk" / "vk_replay.cpp").read_text(encoding="utf-8")
|
||||
check("if (id == HOS_OPT_N64_FPS) return n64_3d_now() ? n64_rules::fps(n64_look()) : 0;" in replay and '#include "vk_n64.h"' in replay,
|
||||
"vk_replay.cpp does not answer HOS_OPT_N64_FPS with n64_rules.h's rate while the 3D pass draws")
|
||||
dev = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
|
||||
check("`HOS_N64_PACE=0`" in dev and "`HOS_OPT_N64_FPS`" in dev, "docs/development.md: HOS_N64_PACE and HOS_OPT_N64_FPS are not said")
|
||||
|
||||
movie = vi[vi.index("static volatile LONG64 movie_seen_ns;"):vi.index("static int pace_handed(void) {")]
|
||||
host = "\n".join([block(vi, "static int fps_cap_of("), block(vi, "static int fps_max(void) {"), movie, "static int movie_raise;",
|
||||
"static int n64_rate;", block(vi, "static int pace_fps(void) {"), n64, decide])
|
||||
with tempfile.TemporaryDirectory(prefix="n64-pace-") as tmp:
|
||||
src, exe = Path(tmp) / "rules.c", Path(tmp) / "rules.exe"
|
||||
src.write_text(RULES, encoding="utf-8")
|
||||
subprocess.run([args.cc, "-std=gnu11", "-O1", "-Wall", "-Wextra", "-Werror", "-I", str(HOST), str(src), "-o", str(exe)], check=True)
|
||||
r = subprocess.run([str(exe)], capture_output=True, text=True)
|
||||
check(r.returncode == 0, "the rules:\n" + r.stdout)
|
||||
src, exe = Path(tmp) / "fixture.c", Path(tmp) / "fixture.exe"
|
||||
src.write_text(FIXTURE.replace("@HOST@", host), encoding="utf-8")
|
||||
subprocess.run([args.cc, "-std=gnu11", "-O1", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I", str(HOST), str(src),
|
||||
"-o", str(exe), "-lm"], check=True)
|
||||
bad = []
|
||||
for (cap, asked, pace_env), expect in CASES:
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith(("HOS_", "RX_"))}
|
||||
env["HOS_FPS_MAX"] = str(cap)
|
||||
if pace_env is not None:
|
||||
env["HOS_N64_PACE"] = pace_env
|
||||
got = subprocess.run([str(exe), str(asked)], capture_output=True, text=True, env=env).stdout.strip()
|
||||
if got != expect:
|
||||
bad.append("cap %d, asked %d, HOS_N64_PACE %s: %s, expected %s" % (cap, asked, pace_env, got, expect))
|
||||
if bad:
|
||||
raise SystemExit("FAIL:\n " + "\n ".join(bad))
|
||||
print("PASS: N64 Classic's frame rate paces the game under the cap, gives way to movies, and goes with the mode")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
214
tests/test_n64_row.py
Normal file
214
tests/test_n64_row.py
Normal file
@@ -0,0 +1,214 @@
|
||||
"""N64 Classic in the Insert menu (gpu/vk/vk_menu.cpp, vk_menu.h; vk_n64.cpp): the Graphics tab's N64 Classic row, the
|
||||
Remembered page its Remembered settings row opens, F7, and the rows it stands in front of. Step 5 of n64-classic-mode-plan.md.
|
||||
No game, no GPU.
|
||||
|
||||
Read in the sources:
|
||||
|
||||
- vk_menu.h: the row Off by default, F7's last preset Faithful, the Remembered page's values n64_rules.h's defaults;
|
||||
- the rows: a heading and the N64 Classic row after the Anti-aliasing row on the Graphics tab, Off to Remembered, taken at
|
||||
once; Remembered settings, a row with no value; the Remembered page (TAB_N64, a page of its own after the Controls page,
|
||||
before the hidden rows) with a row for each of n64_rules.h's Rows, the frame rate first under Pace, each from
|
||||
N64_ROW, which takes its range and step from n64_rules.h kSpec, and Copy Faithful and Reset to defaults; F7's last preset a
|
||||
hidden row, saved under its name's key, n64_classic_last;
|
||||
- each row's value names, as many as its range has values;
|
||||
- the page's values a plain array in Options (n64_rules.h's defaults), so the tests that cut Options out compile it as it
|
||||
is; ini_key's table of names gives each page row kSpec's key (its saturation is Colour saturation: RenoDX has Saturation);
|
||||
- row_shown: Remembered settings with Remembered chosen; row_fixed: the Upscaler and the Anti-aliasing while the 3D pass
|
||||
draws in their place, the row with RX_VK_N64 set, a page row with nothing to do (n64_rules.h row_fixed); the Upscaler and
|
||||
the Anti-aliasing then say N64 Classic, and the Anti-aliasing's line says why;
|
||||
- menu_tick: Remembered settings opens its page and Copy Faithful and Reset to defaults act on a press, before a row with no
|
||||
value opens the Controls page; back and the tab keys leave the page for Graphics, and the Motion page's lines are as they
|
||||
were; F7 turns the row between Off and the last preset, saves it, says so at the foot of the screen, and does nothing
|
||||
while RX_VK_N64 is set;
|
||||
- the page is drawn under Graphics, its actions' guide says Apply and its Back; the tab strip, the sounds and the tab step
|
||||
take it as Graphics; every slot array has a slot for it;
|
||||
- vk_n64.cpp: the mode from the row, RX_VK_N64 over it, Remembered's look from the page;
|
||||
- the readme and the development guide name the row, the page, F7 and the switch.
|
||||
|
||||
The rules themselves (the presets, the page's ranges, the rows with nothing to do, F7) are run by tests/test_n64_rules.py.
|
||||
|
||||
python -I -B tests/test_n64_row.py
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
|
||||
|
||||
def fail(what):
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
|
||||
def check(cond, what):
|
||||
if not cond:
|
||||
fail(what)
|
||||
|
||||
|
||||
def block(text, head):
|
||||
at = text.index(head)
|
||||
end = text.index("{", at) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (text[end] == "{") - (text[end] == "}")
|
||||
end += 1
|
||||
return text[at:end]
|
||||
|
||||
|
||||
def in_order(text, parts, what):
|
||||
at = [text.find(p) for p in parts]
|
||||
check(min(at) >= 0 and at == sorted(at), "%s: %s" % (what, [p for p, a in zip(parts, at) if a < 0] or at))
|
||||
|
||||
|
||||
def spec():
|
||||
"""n64_rules.h's Row names in order and kSpec's (lo, hi, step) for each"""
|
||||
rules = (VK / "n64_rules.h").read_text(encoding="utf-8")
|
||||
names = re.search(r"enum Row \{ (.*?), kRows \};", rules).group(1).split(", ")
|
||||
global defaults, keys
|
||||
table = re.search(r"constexpr RowSpec kSpec\[kRows\] = \{(.*?)\n\};", rules, re.S).group(1)
|
||||
entries = re.findall(r'\{"(\w+)", (-?\d+), (-?\d+), (\d+), (-?\d+)\}', table)
|
||||
check(len(entries) == len(names), "n64_rules.h: kSpec has not one entry for each Row")
|
||||
defaults = {n: int(e[4]) for n, e in zip(names, entries)}
|
||||
keys = {n: e[0] for n, e in zip(names, entries)}
|
||||
return names, {n: (int(e[1]), int(e[2]), int(e[3])) for n, e in zip(names, entries)}
|
||||
|
||||
|
||||
def main():
|
||||
header = (VK / "vk_menu.h").read_text(encoding="utf-8")
|
||||
menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
|
||||
n64 = (VK / "vk_n64.cpp").read_text(encoding="utf-8")
|
||||
names, ranges = spec()
|
||||
|
||||
for need in ("int n64_classic = 0;", "int n64_last = 1;"):
|
||||
check(need in header, "vk_menu.h: %s is gone (Off by default, F7's Faithful)" % need)
|
||||
# (the page's values a plain array, so the tests that cut Options out compile it as it is: n64_rules.h's defaults)
|
||||
arr = re.search(r"int n64_rem\[(\d+)\] = \{([^}]*)\};", header)
|
||||
check(arr and int(arr.group(1)) == len(names) and [int(v) for v in arr.group(2).split(",")] == [defaults[n] for n in names],
|
||||
"vk_menu.h: Options's n64_rem is not n64_rules.h kSpec's defaults, one for each Row")
|
||||
|
||||
# ---- the rows ----
|
||||
check("TAB_N64 = TAB_PAGE + 1," in menu and "TAB_HIDDEN = TAB_N64 + 1" in menu,
|
||||
"TAB_N64 is not a page of its own after the Controls page and before the hidden rows")
|
||||
in_order(menu, ['MENU_HEADING(TAB_GRAPHICS, "Anti-aliasing"),', 'MENU_HEADING(TAB_GRAPHICS, "N64 Classic"),',
|
||||
'{TAB_GRAPHICS, "N64 Classic", &opts.n64_classic, 0, n64_rules::kPresets - 1, 1, tx_n64,',
|
||||
'{TAB_GRAPHICS, "Remembered settings", nullptr, 0, 0, 0, nullptr,',
|
||||
'MENU_HEADING(TAB_GRAPHICS, "Frame generation"),'],
|
||||
"the N64 Classic row and Remembered settings are not after the Anti-aliasing on the Graphics tab")
|
||||
row = menu[menu.index('{TAB_GRAPHICS, "N64 Classic", &opts.n64_classic'):]
|
||||
row = row[:row.index("},") + 2]
|
||||
check("hn_n64, false, true}," in row and "F7" in row and "Changes at once" in row,
|
||||
"the N64 Classic row: its help says F7 and at once, its hint is hn_n64, it takes no restart")
|
||||
macro = menu[menu.index("#define N64_ROW(row, title, text, help)"):]
|
||||
macro = macro[:macro.index("false, true}") + 12]
|
||||
for part in ("{TAB_N64, title, &opts.n64_rem[n64_rules::row],", "n64_rules::kSpec[n64_rules::row].lo",
|
||||
"n64_rules::kSpec[n64_rules::row].hi", "n64_rules::kSpec[n64_rules::row].step", "text, help, nullptr, false, true}"):
|
||||
check(part in macro, "N64_ROW no longer takes %s" % part)
|
||||
page = re.findall(r"N64_ROW\((\w+), \"([^\"]+)\", (\w+),", menu)
|
||||
check([p[0] for p in page] == names, "the Remembered page's rows are not n64_rules.h's Rows, in order: %s" % [p[0] for p in page])
|
||||
in_order(menu, ['MENU_HEADING(TAB_N64, "Pace"),', 'N64_ROW(FPS, "Frame rate", tx_n64_fps,', 'MENU_HEADING(TAB_N64, "The 3D"),'],
|
||||
"the Remembered page does not open with its Pace, the frame rate")
|
||||
for need in ('{TAB_N64, "Copy Faithful", nullptr, 0, 0, 0, nullptr,', '{TAB_N64, "Reset to defaults", nullptr, 0, 0, 0, nullptr,',
|
||||
'{TAB_HIDDEN, "N64 Classic last", &opts.n64_last, n64_rules::FAITHFUL, n64_rules::REMEMBERED, 1, nullptr, nullptr},'):
|
||||
check(need in menu, "the rows: %s is gone" % need)
|
||||
# (each value's name: as many as its range has values)
|
||||
for row_name, title, text in page:
|
||||
lo, hi, step = ranges[row_name]
|
||||
if text in ("tx_percent", "tx_onoff"):
|
||||
continue
|
||||
fn = block(menu, "const char* %s(int v) {" % text)
|
||||
if text == "tx_n64_blur":
|
||||
check('if (v <= 0) return "Off";' in fn and "v * n64_rules::kBlurStep" in fn, "Texture blur's names are not Off, then +0.5 a step")
|
||||
continue
|
||||
count = len(re.findall(r'"[^"]*"', fn.split("};")[0]))
|
||||
check(count == (hi - lo) // step + 1 and "std::clamp(v, 0, %d)" % hi in fn,
|
||||
"%s has %d names for %d values" % (text, count, (hi - lo) // step + 1))
|
||||
check(ranges["TV"] == (0, 1, 1) and ranges["SCANLINES"][2] == 5 and ranges["SATURATION"] == (50, 150, 5),
|
||||
"a page row named by tx_onoff or tx_percent no longer has the range those names suit")
|
||||
|
||||
# ---- the saved keys, shown, fixed ----
|
||||
key = block(menu, "const char* ini_key(const Row& r) {")
|
||||
kept = dict(re.findall(r'\{"([^"]+)", "([^"]+)"\}', key[:key.index("for (const auto& k : kept)")]))
|
||||
for row_name, title, _ in page:
|
||||
check(kept.get(title) == keys[row_name], "ini_key: the page's %s is not saved under %s" % (title, keys[row_name]))
|
||||
check(sum(1 for t in kept if t in [p[1] for p in page]) == len(page) and "Saturation" not in [p[1] for p in page],
|
||||
"ini_key: a page row's name is another row's (RenoDX has Saturation)")
|
||||
check("return value && value >= first && value < first + n64_rules::kRows ? (int)(value - first) : -1;" in block(menu, "int n64_rem_row(const int* value) {"),
|
||||
"n64_rem_row is not the place of a value among opts.n64_rem's")
|
||||
shown = block(menu, "bool row_shown(int i) {")
|
||||
check("(!is_n64_page_row(rows[i]) || n64_preset() == n64_rules::REMEMBERED) &&" in shown,
|
||||
"row_shown: Remembered settings is not shown with Remembered alone")
|
||||
fixed = block(menu, "bool row_fixed(const int* value) {")
|
||||
for need in ("((value == &opts.dlss || value == &opts.aa) && n64_in_front() != n64_rules::OFF)",
|
||||
"(value == &opts.n64_classic && n64_env_set())",
|
||||
"(n64_rem_row(value) >= 0 && n64_rules::row_fixed(n64_rules::rows_of(opts.n64_rem), n64_rem_row(value)))"):
|
||||
check(need in fixed, "row_fixed: %s is gone" % need)
|
||||
for fn in ("const char* tx_upscaler(int) {", "const char* tx_aa(int v) {"):
|
||||
body = block(menu, fn)
|
||||
check(body.split("{", 1)[1].lstrip().startswith('if (n64_in_front() != n64_rules::OFF) return "N64 Classic";'),
|
||||
"%s does not say N64 Classic while its 3D pass draws" % fn)
|
||||
hint = block(menu, "const char* hn_aa(int v, int variant) {")
|
||||
check("variant = n64_in_front() != n64_rules::OFF ? 5 :" in hint and "case 5: return n64;" in hint,
|
||||
"the Anti-aliasing's line does not say N64 Classic smooths the edges")
|
||||
check("return t[v >= 0 && v < n64_rules::kPresets ? v : 0];" in block(menu, "const char* hn_n64(int v, int variant) {") and
|
||||
"return n64_rules::name(n64_env_set() ? n64_preset() : v);" in block(menu, "const char* tx_n64(int v) {"),
|
||||
"the N64 Classic row's text or line is not its value's, RX_VK_N64's over it")
|
||||
act = block(menu, "void n64_act(int action) {")
|
||||
check("const n64_rules::Rows to = action == 1 ? n64_rules::kFaithful : n64_rules::defaults();" in act and
|
||||
"std::copy(std::begin(to.v), std::end(to.v), opts.n64_rem);" in act and "save();" in act,
|
||||
"Copy Faithful and Reset to defaults do not set the page from Faithful or the defaults, and save")
|
||||
|
||||
# ---- the keys ----
|
||||
tick = block(menu, "void menu_tick() {")
|
||||
in_order(tick, ["else if (press[7] && is_motion_row(r)) cur_tab = TAB_MOTION",
|
||||
"else if (press[7] && is_n64_page_row(r)) cur_tab = TAB_N64, tab_selected[TAB_N64] = 0, press[7] = false, changed = true;",
|
||||
"else if (press[7] && n64_action(r)) n64_act(n64_action(r)), changed = true;", # ((11-22) its press the sound's)
|
||||
"else if (press[7] && !r.value && can_bind()) page = 1"],
|
||||
"menu_tick: Remembered settings and the page's actions are not taken before a row with no value opens the Controls page")
|
||||
for need in ("if (press[5] && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS, press[5] = false, changed = true;",
|
||||
"else if (press[5] && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS, press[5] = false, changed = true;",
|
||||
"if ((tab_left || tab_right) && cur_tab == TAB_N64) cur_tab = TAB_GRAPHICS;",
|
||||
"if (press[5] && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS, press[5] = false, changed = true;",
|
||||
"if ((tab_left || tab_right) && cur_tab == TAB_MOTION) cur_tab = TAB_CONTROLS;"):
|
||||
check(need in tick, "menu_tick: %s is gone" % need)
|
||||
f7 = tick[tick.index("static bool f7_held = false;"):tick.index("f7_held = f7_down;")]
|
||||
in_order(f7, ["opts.n64_last = opts.n64_classic;", "const bool f7_down = mine && (GetAsyncKeyState(VK_F7) & 0x8000) != 0;",
|
||||
"if (f7_down && !f7_held && !n64_env_set()) {", "toggle.last = opts.n64_last;",
|
||||
"opts.n64_classic = toggle.pressed(opts.n64_classic);", "opts.n64_last = toggle.last;", "save();",
|
||||
'snprintf(notice_text, sizeof notice_text, "N64 Classic: %s", n64_rules::name(opts.n64_classic));'],
|
||||
"F7: the last preset kept, a press turns the row (not with RX_VK_N64), saves it and says so")
|
||||
|
||||
# ---- the page drawn, its slots ----
|
||||
check("draw_tabs(c, cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab == TAB_N64 ? TAB_GRAPHICS : cur_tab, embed_open, true);" in menu,
|
||||
"the Remembered page is not drawn under Graphics")
|
||||
check('if (n64_action(selr)) prompt_list[0] = {ui::kConfirm, "Apply"};' in menu and
|
||||
'if (cur_tab == TAB_N64) prompt_list[1] = {ui::kBack, "Back"}, prompts_n = 2;' in menu,
|
||||
"the Remembered page's guides do not say Apply and Back")
|
||||
check("s.tab = motion ? (int)TAB_CONTROLS : cur_tab == TAB_N64 ? (int)TAB_GRAPHICS : cur_tab;" in menu and
|
||||
"cur_tab == TAB_MOTION ? TAB_CONTROLS : cur_tab == TAB_N64 ? TAB_GRAPHICS : cur_tab;" in block(menu, "void tab_move(int dir) {"),
|
||||
"the sounds or the tab step do not take the Remembered page as Graphics")
|
||||
for arr in ("int tab_selected[TAB_N64 + 1]", "float scroll_at[TAB_N64 + 1];", "int wheel_rows[TAB_N64 + 1];",
|
||||
"int scrolled_to[TAB_N64 + 1] = {-1, -1, -1, -1, -1, -1, -1, -1, -1};", "float scroll_want[TAB_N64 + 1];",
|
||||
'static_assert(TAB_N64 + 1 == 9,'):
|
||||
check(arr in menu, "a slot array has no slot for the Remembered page: %s" % arr)
|
||||
|
||||
# ---- vk_n64.cpp, the readme, the guide ----
|
||||
# ((step 8) the look is the preset shown, which follows the row through the TV's switch, and is the row's before a present)
|
||||
for need in ("int n64_preset() { return n64_rules::chosen(opts.n64_classic, env_n64()); }", "bool n64_env_set() { return env_n64() >= 0; }",
|
||||
"n64_rules::look_of(n64_shown(), n64_rules::rows_of(opts.n64_rem))", "return s >= 0 ? s : n64_preset();",
|
||||
'#include "vk_menu.h"'):
|
||||
check(need in n64, "vk_n64.cpp: %s is gone" % need)
|
||||
readme = (ROOT / "readme.md").read_text(encoding="utf-8")
|
||||
entry = readme[readme.index("| N64 Classic |"):]
|
||||
entry = entry[:entry.index("\n")]
|
||||
for need in ("Off, Faithful, Remembered", "**F7**", "**Remembered settings**", "at 20 frames a second", "Frame rate (Frame rate cap",
|
||||
"Colour saturation", "Copy Faithful",
|
||||
"Reset to defaults", "`RX_VK_N64=0`"):
|
||||
check(need in entry, "readme.md: the N64 Classic row does not say %s" % need)
|
||||
check("Upscaling, Anti-aliasing, N64 Classic, Frame generation" in readme, "readme.md: the Graphics tab's groups leave N64 Classic out")
|
||||
docs = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
|
||||
check("over the Insert menu's N64 Classic row and its Remembered page" in docs, "docs/development.md: RX_VK_N64 is not said to go over the row")
|
||||
print("PASS: N64 Classic's row, the Remembered page, F7, and the rows it stands in front of")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
469
tests/test_n64_rules.py
Normal file
469
tests/test_n64_rules.py
Normal file
@@ -0,0 +1,469 @@
|
||||
"""N64 Classic's rules (gpu/vk/n64_rules.h) and its 3D pass's per-pixel maths (gpu/vk/shaders/n64_common.glsl). No game,
|
||||
no GPU. Step 1 of n64-classic-mode-plan.md: nothing in the renderer calls them yet.
|
||||
|
||||
Compiled and run:
|
||||
|
||||
- the N64 Classic row (Off, Faithful, Remembered) and RX_VK_N64 over it;
|
||||
- the Remembered page's rows: their keys (unique, n64_rem_), ranges, steps and defaults, a saved value brought back to its
|
||||
row, the rows shown fixed while they have nothing to do (Dither with full colour, the TV's rows with the TV off, Mask
|
||||
strength with no mask);
|
||||
- the looks: Faithful's fixed values (20 frames a second, 240 lines, 15-bit colour with the full dither, +2.5 texture
|
||||
blur, the TV), Remembered's defaults, Faithful ignoring the page, Copy Faithful giving Remembered exactly Faithful's
|
||||
look, Reset giving the defaults, the lab's switches over either;
|
||||
- the 3D grid's size for the host's 4:3, 16:9 and 21:9 pictures; the TV's colour bleed in the picture's widths by its
|
||||
shape; the texture blur under a card's limit, and the draws
|
||||
that are the scene for it (a scene's size and shape for the picture: the dynamic resolution's sizes, not the shadow maps,
|
||||
the HUD or a quarter-size buffer); the scanlines' strength and the mask's Auto by the picture's height on the screen;
|
||||
- what the mode stands in front of while it is on (the Upscaler, the Anti-aliasing, Sharpness) and when each pass runs
|
||||
(no 3D pass on RenoDX's RGBA16F scene, no TV on HDR Native's PQ picture or under DLSS frame generation);
|
||||
- the frame rate the host is told and the rate the frames are then paced by under every cap;
|
||||
- F7 between Off and the last preset, and the TV's half-second switch with the change at its middle: the preset shown
|
||||
through a switch (none at a start, a new choice while it closes, another after the middle, at once where none can be
|
||||
drawn), and the TV pass drawing it over any look;
|
||||
- n64_common.glsl, compiled as C++ over a small GLSL stand-in (it is written in what the two share, as aa_common.glsl is):
|
||||
the 4 x 4 Bayer cell is each of 0 to 15 once, its thresholds centred; every level of 5 and 6 bits comes back exactly at
|
||||
any dither strength; a value between levels averages to itself over a cell; the output is always a level, inside 0..1;
|
||||
and for step 2's pass (shaders/n64_3d.comp): the sRGB curve both ways, a channel kept at 15-bit colour on a display
|
||||
level (white, HDR's highlights and full colour as they are, below black and NaN black), every grid row in order with 4
|
||||
to 6 output rows each, and the column's place along a line.
|
||||
|
||||
With glslangValidator on the PATH, n64_common.glsl also compiles as GLSL inside a stand-in compute shader.
|
||||
|
||||
python -I -B tests/test_n64_rules.py [--cxx clang++]
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
SHADERS = VK / "shaders"
|
||||
|
||||
DRIVER = r'''
|
||||
#include "n64_rules.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
|
||||
// (just enough of GLSL for n64_common.glsl, in a namespace of its own)
|
||||
namespace glsl {
|
||||
static float floor(float a) { return std::floor(a); }
|
||||
static float clamp(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; }
|
||||
#include "shaders/n64_common.glsl"
|
||||
} // namespace glsl
|
||||
|
||||
using namespace mkwvk::n64_rules;
|
||||
namespace ur = mkwvk::upscaler_rows;
|
||||
namespace ar = mkwvk::aa_rows;
|
||||
|
||||
static int checks, fails;
|
||||
static void want(bool ok, const char* what) {
|
||||
checks++;
|
||||
if (!ok) fails++, std::printf("FAIL %s\n", what);
|
||||
}
|
||||
static bool near(float a, float b, float eps = 1e-6f) { return std::fabs(a - b) <= eps; }
|
||||
|
||||
static void row_and_rows() {
|
||||
want(chosen(0, -1) == OFF && chosen(1, -1) == FAITHFUL && chosen(2, -1) == REMEMBERED, "the row's own values");
|
||||
want(chosen(7, -1) == OFF && chosen(-3, -1) == OFF, "a value past the row is Off");
|
||||
want(chosen(0, 2) == REMEMBERED && chosen(2, 0) == OFF && chosen(1, 9) == OFF, "RX_VK_N64 over the row");
|
||||
want(!std::strcmp(name(OFF), "Off") && !std::strcmp(name(FAITHFUL), "Faithful") &&
|
||||
!std::strcmp(name(REMEMBERED), "Remembered") && !std::strcmp(name(5), "Off"), "the row's names");
|
||||
|
||||
bool keys = true;
|
||||
for (int i = 0; i < kRows; i++) {
|
||||
if (std::strncmp(kSpec[i].key, "n64_rem_", 8)) keys = false;
|
||||
for (int j = 0; j < i; j++)
|
||||
if (!std::strcmp(kSpec[i].key, kSpec[j].key)) keys = false;
|
||||
const RowSpec& s = kSpec[i];
|
||||
if (s.lo > s.hi || s.step <= 0 || s.def < s.lo || s.def > s.hi || (s.def - s.lo) % s.step || (s.hi - s.lo) % s.step)
|
||||
keys = false;
|
||||
}
|
||||
want(keys, "each row's key is its own and n64_rem_, its default on its steps inside its range");
|
||||
want(std::strncmp(kLastKey, "n64_rem_", 8) != 0, "F7's last preset has a key of its own");
|
||||
|
||||
const Rows d = defaults();
|
||||
bool defs = true;
|
||||
for (int i = 0; i < kRows; i++) defs &= d.v[i] == kSpec[i].def;
|
||||
want(defs, "Reset: every row at its default");
|
||||
const Rows f = clamped(kFaithful);
|
||||
bool on_rows = true;
|
||||
for (int i = 0; i < kRows; i++) on_rows &= f.v[i] == kFaithful.v[i];
|
||||
want(on_rows, "Faithful's values are values the page's rows can hold (Copy Faithful copies them as they are)");
|
||||
|
||||
want(clamp_row(FPS, 9) == 4 && clamp_row(FPS, -2) == 0, "the frame rate brought back to its row");
|
||||
want(clamp_row(SCANLINES, 37) == 35 && clamp_row(SCANLINES, 200) == 80 && clamp_row(SCANLINES, -5) == 0,
|
||||
"scanlines: on a step of 5, inside 0..80");
|
||||
want(clamp_row(MASK_STRENGTH, 0) == 5 && clamp_row(SATURATION, 151) == 150 && clamp_row(SATURATION, 52) == 50,
|
||||
"mask strength and saturation inside their rows, on their steps");
|
||||
want(clamp_row(-1, 3) == 0 && clamp_row(kRows, 3) == 0, "no row: 0");
|
||||
Rows wild{};
|
||||
for (int i = 0; i < kRows; i++) wild.v[i] = 999;
|
||||
const Look w = look_of(REMEMBERED, wild);
|
||||
want(w.on && w.fps == 17 && w.lines == 720 && w.colour_bits == 0 && near(w.lod_bias, 3.0f) && w.tv &&
|
||||
near(w.scanlines, 0.8f) && w.mask == MASK_SHADOW && near(w.saturation, 1.5f),
|
||||
"a file's values past every row: each row's last value, nothing read past a table");
|
||||
|
||||
Rows r = d;
|
||||
want(row_fixed(r, DITHER), "Dither fixed while Colour is Full");
|
||||
r.v[COLOUR] = 0;
|
||||
want(!row_fixed(r, DITHER), "Dither changeable with 15-bit colour");
|
||||
r.v[TV] = 0;
|
||||
bool tv_rows = true;
|
||||
for (int i = SCANLINES; i <= SATURATION; i++) tv_rows &= row_fixed(r, i);
|
||||
want(tv_rows, "the TV's rows fixed while CRT TV is off");
|
||||
want(!row_fixed(r, FPS) && !row_fixed(r, LINES) && !row_fixed(r, COLOUR) && !row_fixed(r, BLUR) && !row_fixed(r, TV),
|
||||
"the frame rate, the 3D's rows and CRT TV itself never fixed");
|
||||
r.v[TV] = 1, r.v[MASK] = MASK_OFF;
|
||||
want(row_fixed(r, MASK_STRENGTH) && !row_fixed(r, MASK), "Mask strength fixed with no mask");
|
||||
}
|
||||
|
||||
static void looks() {
|
||||
const Look f = look_of(FAITHFUL, defaults());
|
||||
want(f.on && f.fps == 20 && f.lines == 240 && f.colour_bits == 5 && near(f.dither, 1.0f) && near(f.lod_bias, 2.5f),
|
||||
"Faithful's 3D: 20 frames a second, 240 lines, 15-bit colour, the full dither, +2.5 blur");
|
||||
want(f.tv && near(f.scanlines, 0.6f) && f.mask == MASK_AUTO && near(f.mask_strength, 0.3f) && near(f.bleed, 3.0f) &&
|
||||
near(f.glow, 0.1f) && near(f.curvature, 0.03f) && near(f.saturation, 1.0f),
|
||||
"Faithful's TV: 60% scanlines, Auto's mask at 30%, a composite cable's bleed, 10% glow, curved, the game's colour");
|
||||
const Look m = look_of(REMEMBERED, defaults());
|
||||
want(m.on && m.fps == 0 && m.lines == 480 && m.colour_bits == 0 && m.dither == 0.0f && near(m.lod_bias, 1.5f),
|
||||
"Remembered's 3D: the cap's rate, 480 lines, full colour, no dither, +1.5 blur");
|
||||
want(m.tv && near(m.scanlines, 0.35f) && m.mask == MASK_AUTO && near(m.mask_strength, 0.15f) && near(m.bleed, 1.5f) &&
|
||||
near(m.glow, 0.25f) && near(m.curvature, 0.015f) && near(m.saturation, 1.1f), "Remembered's TV defaults");
|
||||
|
||||
Rows odd = defaults();
|
||||
odd.v[FPS] = 1, odd.v[LINES] = 3, odd.v[TV] = 0, odd.v[BLUR] = 0;
|
||||
want(same(look_of(FAITHFUL, odd), f), "Faithful ignores the Remembered page");
|
||||
want(!same(look_of(REMEMBERED, odd), m), "Remembered follows its page");
|
||||
Rows copied = kFaithful; // (Copy Faithful)
|
||||
want(same(look_of(REMEMBERED, copied), f), "after Copy Faithful, Remembered looks exactly as Faithful does, rate and all");
|
||||
want(same(look_of(REMEMBERED, defaults()), m), "after Reset, Remembered's defaults");
|
||||
|
||||
Rows full = defaults();
|
||||
full.v[COLOUR] = 2, full.v[DITHER] = 2;
|
||||
want(look_of(REMEMBERED, full).dither == 0.0f, "full colour: no dither, whatever the Dither row holds");
|
||||
Rows notv = defaults();
|
||||
notv.v[TV] = 0;
|
||||
const Look n = look_of(REMEMBERED, notv);
|
||||
want(!n.tv && n.scanlines == 0.0f && n.mask == MASK_OFF && n.mask_strength == 0.0f && n.bleed == 0.0f && n.glow == 0.0f &&
|
||||
n.curvature == 0.0f && n.saturation == 1.0f && n.lines == 480 && near(n.lod_bias, 1.5f),
|
||||
"CRT TV off: none of the TV, the 3D as it was");
|
||||
const Look off = look_of(OFF, defaults());
|
||||
want(!off.on && fps(off) == 0 && lod_bias(off, 16.0f) == 0.0f && !three_d_runs(off, false) && !tv_runs(off, false, false),
|
||||
"Off: nothing at all");
|
||||
|
||||
Env e;
|
||||
want(same(with_env(f, e), f), "no switch set: the look as it is");
|
||||
e.lines = 360, e.tv = 0, e.fps = 0, e.lod = 0.0f, e.mask = MASK_APERTURE;
|
||||
const Look fe = with_env(f, e);
|
||||
want(fe.lines == 360 && !fe.tv && fe.fps == 0 && fe.lod_bias == 0.0f && fe.mask == MASK_APERTURE,
|
||||
"the lab's switches over Faithful's fixed look");
|
||||
want(!with_env(off, e).on, "the switches do not turn the mode on");
|
||||
}
|
||||
|
||||
static void grid_and_screen() {
|
||||
const auto is = [](Grid g, uint32_t w, uint32_t h) { return g.w == w && g.h == h; };
|
||||
want(is(grid(240, 1920, 1440), 320, 240), "4:3 at 240 lines: 320 x 240");
|
||||
want(is(grid(240, 2560, 1440), 427, 240) && is(grid(240, 2048, 1152), 427, 240), "16:9 at 240 lines: 427 x 240");
|
||||
want(is(grid(240, 3416, 1440), 569, 240), "the host's 21:9 picture (3416 x 1440) at 240 lines: 569 x 240");
|
||||
want(is(grid(480, 1920, 1440), 640, 480) && is(grid(480, 2560, 1440), 853, 480) && is(grid(480, 3416, 1440), 1139, 480),
|
||||
"480 lines: 640, 853, 1139");
|
||||
want(is(grid(720, 1280, 400), 1280, 400), "never more lines than the picture");
|
||||
want(is(grid(240, 0, 1440), 0, 0) && is(grid(0, 2560, 1440), 0, 0) && is(grid(240, 2560, 0), 0, 0), "a size not known: none");
|
||||
|
||||
const Look f = look_of(FAITHFUL, defaults());
|
||||
want(near(lod_bias(f, 16.0f), 2.5f) && near(lod_bias(f, 2.0f), 2.0f) && lod_bias(f, 0.0f) == 0.0f,
|
||||
"the blur under the card's limit (Vulkan's least, 2, cuts Faithful's 2.5)");
|
||||
want(near(scanline_strength(0.6f, 1440), 0.6f) && near(scanline_strength(0.6f, 2160), 0.6f), "1440 and 2160: full");
|
||||
want(near(scanline_strength(0.6f, 720), 0.6f) && near(scanline_strength(0.6f, 800), 0.6f),
|
||||
"the Steam Deck's 720 and 800: 3 a line and more, full");
|
||||
want(near(scanline_strength(0.6f, 600), 0.3f) && scanline_strength(0.6f, 360) == 0.0f && scanline_strength(0.6f, 0) == 0.0f,
|
||||
"2.5 pixels a line: half; 1.5: none");
|
||||
want(mask_shown(MASK_AUTO, 800) == MASK_OFF && mask_shown(MASK_AUTO, 1080) == MASK_OFF, "Auto: no mask at 800 or 1080");
|
||||
want(mask_shown(MASK_AUTO, 1440) == MASK_SLOT && mask_shown(MASK_AUTO, 2160) == MASK_SLOT, "Auto: the slot mask at 1440 and up");
|
||||
want(mask_shown(MASK_APERTURE, 800) == MASK_APERTURE && mask_shown(MASK_SHADOW, 1080) == MASK_SHADOW,
|
||||
"a picked mask on any screen");
|
||||
want(mask_shown(MASK_OFF, 2160) == MASK_OFF && mask_shown(9, 2160) == MASK_OFF, "Off and a value past the row: none");
|
||||
|
||||
// (step 4) the colour bleed in the picture's widths: a pixel of the 240-line grid, 1/427 of a 16:9 picture, 1/320 of 4:3
|
||||
want(near(tv_bleed_uv(3.0f, 1920, 1440), 3.0f / 320.0f) && near(tv_bleed_uv(3.0f, 2560, 1440), 3.0f * 1440.0f / (240.0f * 2560.0f)) &&
|
||||
near(tv_bleed_uv(1.5f, 3416, 1440), 1.5f * 1440.0f / (240.0f * 3416.0f)), "the bleed in the picture's widths, by its shape");
|
||||
want(tv_bleed_uv(0.0f, 2560, 1440) == 0.0f && tv_bleed_uv(3.0f, 0, 1440) == 0.0f && tv_bleed_uv(3.0f, 2560, 0) == 0.0f,
|
||||
"no bleed, or a size not known: none");
|
||||
|
||||
// (step 3) the draws that are the scene for the texture blur, by their size and shape for the picture the pass drew
|
||||
want(scene_draw(1536, 864, 2048, 1152) && scene_draw(2048, 1152, 2560, 1440) && scene_draw(1707, 960, 2560, 1440),
|
||||
"the game's dynamic resolution's sizes for the picture: the scene");
|
||||
want(scene_draw(854, 480, 2560, 1440), "a third of the picture (Ultra Performance's share): the scene");
|
||||
want(scene_draw(1440, 1080, 1920, 1440) && scene_draw(2560, 1080, 3416, 1440), "the host's 4:3 and 21:9 pictures' scenes");
|
||||
want(!scene_draw(2560, 1440, 2560, 1440), "the picture's own size (the HUD, the output's passes): not the scene");
|
||||
want(!scene_draw(1024, 1024, 2560, 1440) && !scene_draw(2048, 2048, 2560, 1440) && !scene_draw(1024, 1024, 1920, 1440),
|
||||
"square shadow maps: not the scene, at 16:9 or at 4:3");
|
||||
want(!scene_draw(640, 360, 2560, 1440), "a quarter of the picture, past a third: not the scene");
|
||||
want(!scene_draw(1280, 540, 2560, 1440), "half its width, another shape: not the scene");
|
||||
want(!scene_draw(2600, 1440, 2560, 1440), "wider than the picture: not the scene");
|
||||
want(!scene_draw(1536, 864, 0, 0) && !scene_draw(0, 864, 2048, 1152), "a size not known: not the scene");
|
||||
}
|
||||
|
||||
static void in_front_and_passes() {
|
||||
want(upscaler(FAITHFUL, ur::DLSS) == ur::GAME && upscaler(REMEMBERED, ur::FSR4_AA) == ur::GAME &&
|
||||
upscaler(OFF, ur::DLSS) == ur::DLSS, "DLSS and FSR step aside while the mode is on, and only then");
|
||||
want(anti_aliasing(FAITHFUL, ar::SMAA) == ar::OFF && anti_aliasing(OFF, ar::FXAA) == ar::FXAA,
|
||||
"the game's SMAA left out while the mode is on");
|
||||
want(sharpness(REMEMBERED, 50) == 0 && sharpness(OFF, 50) == 50, "no window Sharpness while the mode is on");
|
||||
want(fixes_rows(FAITHFUL) && fixes_rows(REMEMBERED) && !fixes_rows(OFF), "the overridden rows fixed while it is on");
|
||||
const Look f = look_of(FAITHFUL, defaults());
|
||||
want(three_d_runs(f, false) && !three_d_runs(f, true), "the 3D pass: not on RenoDX's RGBA16F scene");
|
||||
want(tv_runs(f, false, false) && !tv_runs(f, true, false) && !tv_runs(f, false, true),
|
||||
"the TV: not on HDR Native's PQ picture, not under DLSS frame generation");
|
||||
Rows notv = defaults();
|
||||
notv.v[TV] = 0;
|
||||
want(!tv_runs(look_of(REMEMBERED, notv), false, false) && three_d_runs(look_of(REMEMBERED, notv), false),
|
||||
"CRT TV off: the 3D pass alone");
|
||||
}
|
||||
|
||||
static void frame_rate() {
|
||||
const Look f = look_of(FAITHFUL, defaults());
|
||||
bool twenty = true;
|
||||
for (int cap : {30, 40, 45, 60, 90, 120, 144, 165, 240}) twenty &= paced(fps(f), cap) == 20;
|
||||
want(fps(f) == 20 && twenty, "Faithful: 20 under every cap the game offers");
|
||||
const Look m = look_of(REMEMBERED, defaults());
|
||||
want(fps(m) == 0 && paced(fps(m), 60) == 60 && paced(fps(m), 144) == 144, "Remembered's default: the cap's own rate");
|
||||
Rows r = defaults();
|
||||
r.v[FPS] = 1; // (60)
|
||||
want(paced(fps(look_of(REMEMBERED, r)), 45) == 45 && paced(fps(look_of(REMEMBERED, r)), 120) == 60,
|
||||
"a Remembered 60: 45 under a cap of 45, 60 under 120");
|
||||
r.v[FPS] = 4;
|
||||
want(fps(look_of(REMEMBERED, r)) == 17 && paced(17, 60) == 17, "17, the cartridge on a 50 Hz TV");
|
||||
r.v[FPS] = 2;
|
||||
want(fps(look_of(REMEMBERED, r)) == 30, "30");
|
||||
want(paced(fps(look_of(OFF, defaults())), 60) == 60, "Off: the cap's");
|
||||
}
|
||||
|
||||
static void toggle_and_anim() {
|
||||
Toggle t;
|
||||
want(t.pressed(OFF) == FAITHFUL, "F7 from Off the first time: Faithful");
|
||||
want(t.pressed(FAITHFUL) == OFF, "F7 with a preset on: Off");
|
||||
t.noted(REMEMBERED);
|
||||
want(t.pressed(OFF) == REMEMBERED, "F7 from Off: the last preset chosen on the row");
|
||||
want(t.pressed(REMEMBERED) == OFF && t.pressed(OFF) == REMEMBERED, "and back again");
|
||||
t.noted(OFF);
|
||||
want(t.last == REMEMBERED, "Off chosen on the row is no preset to come back to");
|
||||
|
||||
want(anim(-0.1f).done && !anim(-0.1f).after, "before a switch: the picture as it is");
|
||||
const AnimFrame start = anim(0.0f), end = anim(kAnimSeconds);
|
||||
want(!start.done && near(start.scale_x, 1.0f) && near(start.scale_y, 1.0f) && start.flash == 0.0f && !start.after,
|
||||
"the switch starts from the whole picture");
|
||||
want(end.done && end.after && near(end.scale_x, 1.0f) && near(end.scale_y, 1.0f) && end.flash == 0.0f,
|
||||
"and is over at half a second, with the new look whole");
|
||||
want(!anim(kAnimSeconds / 2 - 0.001f).after && anim(kAnimSeconds / 2).after, "the new look from the middle on");
|
||||
const AnimFrame mid = anim(kAnimSeconds / 2);
|
||||
want(near(mid.scale_x, kAnimDot) && near(mid.scale_y, kAnimLine) && near(mid.flash, 1.0f), "a bright dot at the middle");
|
||||
bool closing = true, opening = true;
|
||||
AnimFrame prev = start;
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
const AnimFrame a = anim(kAnimSeconds / 2 * i / 100.0f);
|
||||
closing &= a.scale_y <= prev.scale_y + 1e-6f && a.scale_x <= prev.scale_x + 1e-6f;
|
||||
prev = a;
|
||||
}
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
const AnimFrame a = anim(kAnimSeconds / 2 + kAnimSeconds / 2 * i / 100.0f);
|
||||
opening &= a.scale_y + 1e-6f >= prev.scale_y && a.scale_x + 1e-6f >= prev.scale_x;
|
||||
prev = a;
|
||||
}
|
||||
want(closing && opening, "it closes to the dot, then opens from it, never back and forth");
|
||||
|
||||
// (step 8) the switch, once a present: the preset shown, and the TV's frame of it
|
||||
Switch sw;
|
||||
Switch::Now n = sw.at(10.0, FAITHFUL, true);
|
||||
want(n.shown == FAITHFUL && n.frame.done, "the first present: the preset as it is, no switch (a start does not switch the TV on)");
|
||||
want(sw.at(10.1, FAITHFUL, true).frame.done, "nothing chosen anew: nothing runs");
|
||||
n = sw.at(11.0, OFF, true);
|
||||
want(n.shown == FAITHFUL && !n.frame.done && !n.frame.after, "F7 off: the switch begins, Faithful still shown");
|
||||
want(sw.at(11.2, OFF, true).shown == FAITHFUL && sw.at(11.25, OFF, true).shown == OFF, "Off from the middle on");
|
||||
n = sw.at(11.5, OFF, true);
|
||||
want(n.shown == OFF && n.frame.done, "over at half a second: Off, nothing running");
|
||||
sw.at(12.0, REMEMBERED, true);
|
||||
n = sw.at(12.1, FAITHFUL, true);
|
||||
want(n.shown == OFF && !n.frame.done && sw.to == FAITHFUL && sw.t0 == 12.0,
|
||||
"a new choice while the picture still closes: what opens instead, the same switch");
|
||||
want(sw.at(12.3, FAITHFUL, true).shown == FAITHFUL, "and it opens on it");
|
||||
n = sw.at(12.4, REMEMBERED, true);
|
||||
want(n.shown == FAITHFUL && sw.from == FAITHFUL && sw.to == REMEMBERED && sw.t0 == 12.4,
|
||||
"a new choice after the middle: a new switch from what is shown");
|
||||
want(sw.at(12.9, REMEMBERED, true).shown == REMEMBERED && sw.at(12.9, REMEMBERED, true).frame.done, "and over");
|
||||
n = sw.at(13.0, OFF, false);
|
||||
want(n.shown == OFF && n.frame.done, "no switch to draw (RX_VK_N64_TV_ANIM=0, HDR Native, DLSS frame generation): at once");
|
||||
Look off = look_of(OFF, defaults());
|
||||
want(!tv_draws(off, AnimFrame{}, false, false) && tv_draws(off, anim(0.1f), false, false),
|
||||
"the TV pass draws the switch over an Off look, and nothing once it is over");
|
||||
want(!tv_draws(off, anim(0.1f), true, false) && !tv_draws(off, anim(0.1f), false, true) &&
|
||||
tv_draws(look_of(FAITHFUL, defaults()), AnimFrame{}, false, false), "never on HDR Native's picture nor under DLSS frame generation");
|
||||
}
|
||||
|
||||
static void glsl_maths() {
|
||||
using namespace glsl;
|
||||
bool perm = true;
|
||||
int seen = 0;
|
||||
float sum = 0.0f, lo = 1.0f, hi = -1.0f;
|
||||
for (int y = 0; y < 4; y++)
|
||||
for (int x = 0; x < 4; x++) {
|
||||
const int b = n64_bayer4(x, y);
|
||||
if (b < 0 || b > 15 || (seen & (1 << b))) perm = false;
|
||||
seen |= 1 << (b & 15);
|
||||
const float d = n64_dither_offset(x, y);
|
||||
sum += d, lo = d < lo ? d : lo, hi = d > hi ? d : hi;
|
||||
}
|
||||
want(perm && seen == 0xffff, "the 4 x 4 cell holds each of 0 to 15 once");
|
||||
want(near(sum, 0.0f, 1e-5f) && near(lo, -15.0f / 32.0f) && near(hi, 15.0f / 32.0f), "its thresholds centred, -15/32 to 15/32");
|
||||
want(n64_bayer4(0, 0) == 0 && n64_bayer4(1, 0) == 8 && n64_bayer4(0, 1) == 12 && n64_bayer4(1, 1) == 4 &&
|
||||
n64_bayer4(2, 2) == 1, "the Bayer matrix's own order");
|
||||
want(n64_dither_offset(4, 0) == n64_dither_offset(0, 0) && n64_dither_offset(5, 6) == n64_dither_offset(1, 2),
|
||||
"the cell repeats every 4 grid pixels");
|
||||
|
||||
bool levels = true;
|
||||
for (int bits : {5, 6}) {
|
||||
const int top = (1 << bits) - 1;
|
||||
for (int k = 0; k <= top; k++)
|
||||
for (float s : {0.0f, 0.5f, 1.0f})
|
||||
for (int y = 0; y < 4; y++)
|
||||
for (int x = 0; x < 4; x++)
|
||||
levels &= n64_quantize((float)k / (float)top, bits, s, x, y) == (float)k / (float)top;
|
||||
}
|
||||
want(levels, "every level of 5 and of 6 bits comes back exactly, at any dither strength, in every cell");
|
||||
|
||||
bool mean = true, on_level = true, nearest = true;
|
||||
for (int i = 0; i <= 1000; i++) {
|
||||
const float v = i / 1000.0f;
|
||||
float total = 0.0f;
|
||||
for (int y = 0; y < 4; y++)
|
||||
for (int x = 0; x < 4; x++) {
|
||||
const float q = n64_quantize(v, 5, 1.0f, x, y);
|
||||
total += q;
|
||||
on_level &= near(q * 31.0f, std::round(q * 31.0f), 1e-4f) && q >= 0.0f && q <= 1.0f;
|
||||
}
|
||||
mean &= std::fabs(total / 16.0f - v) <= 1.0f / 16.0f / 31.0f + 1e-6f;
|
||||
const float q0 = n64_quantize(v, 5, 0.0f, 3, 1);
|
||||
nearest &= std::fabs(q0 - v) <= 0.5f / 31.0f + 1e-6f && near(q0 * 31.0f, std::round(q0 * 31.0f), 1e-4f);
|
||||
}
|
||||
want(mean, "a value between levels averages to itself over a cell, within a 16th of a step");
|
||||
want(on_level, "the output is always one of the 32 levels, inside 0..1");
|
||||
want(nearest, "no dither: the nearest level");
|
||||
want(n64_quantize(-0.2f, 5, 1.0f, 0, 0) == 0.0f && n64_quantize(1.3f, 5, 1.0f, 3, 3) == 1.0f, "below 0 and past 1: the ends");
|
||||
want(n64_quantize(0.123f, 0, 1.0f, 2, 1) == 0.123f && n64_quantize(1.7f, 0, 1.0f, 2, 1) == 1.7f,
|
||||
"full colour: the value as it is");
|
||||
|
||||
// (step 2's pass: the sRGB curve both ways, a channel as the grid keeps it, where an output pixel finds the grid)
|
||||
bool round = true;
|
||||
for (int i = 0; i <= 1000; i++) {
|
||||
const float v = i / 1000.0f;
|
||||
round &= near(n64_decode(n64_encode(v)), v, 2e-5f) && near(n64_encode(n64_decode(v)), v, 2e-5f);
|
||||
}
|
||||
want(round && near(n64_encode(0.5f), 0.735357f, 1e-4f), "the sRGB curve, both ways");
|
||||
bool kept = true;
|
||||
for (int i = 0; i <= 200; i++) {
|
||||
const float v = i / 200.0f * 0.999f;
|
||||
const float k = n64_keep(v, 5, 1.0f, i & 3, (i >> 2) & 3);
|
||||
kept &= near(n64_encode(k) * 31.0f, std::round(n64_encode(k) * 31.0f), 2e-3f) && k >= 0.0f && k <= 1.0f;
|
||||
}
|
||||
want(kept, "kept at 15-bit colour: every channel on one of the 32 display levels");
|
||||
want(n64_keep(0.42f, 0, 1.0f, 1, 1) == 0.42f && n64_keep(1.0f, 5, 1.0f, 1, 1) == 1.0f && n64_keep(3.5f, 5, 1.0f, 0, 0) == 3.5f,
|
||||
"full colour, white and light above it (HDR's highlights) as they are");
|
||||
want(n64_keep(-0.3f, 5, 1.0f, 0, 0) == 0.0f && n64_keep(std::nanf(""), 5, 1.0f, 0, 0) == 0.0f, "below black, or not a number: black");
|
||||
bool bands = true;
|
||||
for (int y = 0; y < 1440; y++) bands &= n64_row(y, 240, 1440) == y / 6;
|
||||
want(bands, "1440 output rows on 240 grid rows: 6 each, hard edges");
|
||||
int first = 0, last = 0, shortest = 99, tallest = 0, height = 0;
|
||||
bool climbs = true;
|
||||
for (int y = 0; y < 1152; y++) {
|
||||
const int r = n64_row(y, 240, 1152);
|
||||
if (y == 0) first = r;
|
||||
if (y && r != last) {
|
||||
climbs &= r == last + 1;
|
||||
shortest = height < shortest ? height : shortest, tallest = height > tallest ? height : tallest, height = 0;
|
||||
}
|
||||
last = r, height++;
|
||||
}
|
||||
want(first == 0 && last == 239 && climbs && shortest >= 4 && tallest <= 5, "1152 rows on 240: every grid row, in order, 4 or 5 output rows each");
|
||||
want(n64_row(2159, 240, 2160) == 239 && n64_row(0, 240, 2160) == 0, "the first and the last output row: the first and the last grid row");
|
||||
want(near(n64_column(3, 427, 427), 3.0f) && near(n64_column(0, 320, 1920), -5.0f / 12.0f) &&
|
||||
near(n64_column(1919, 320, 1920), 319.0f + 5.0f / 12.0f), "the column: the grid pixel's centre at the same size, inside the grid's edges at 6x");
|
||||
}
|
||||
|
||||
int main() {
|
||||
row_and_rows();
|
||||
looks();
|
||||
grid_and_screen();
|
||||
in_front_and_passes();
|
||||
frame_rate();
|
||||
toggle_and_anim();
|
||||
glsl_maths();
|
||||
if (fails) std::printf("n64 rules: FAILED (%d of %d checks)\n", fails, checks);
|
||||
else std::printf("n64 rules: all %d checks passed\n", checks);
|
||||
return fails != 0;
|
||||
}
|
||||
'''
|
||||
|
||||
STAND_IN_SHADER = '''#version 450
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
#include "n64_common.glsl"
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
layout(binding = 0, rgba8) uniform writeonly image2D dst;
|
||||
void main() {
|
||||
const ivec2 g = ivec2(gl_GlobalInvocationID.xy);
|
||||
imageStore(dst, g, vec4(n64_quantize(0.4, 5, 1.0, g.x, g.y), 0.0, 0.0, 1.0));
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def check_sources():
|
||||
rules = (VK / "n64_rules.h").read_text(encoding="utf-8")
|
||||
if re.search(r'#include\s*[<"](vulkan|vk_)', rules):
|
||||
raise SystemExit("FAIL: n64_rules.h includes Vulkan or the renderer: its rules are to stay plain")
|
||||
common = (SHADERS / "n64_common.glsl").read_text(encoding="utf-8")
|
||||
code = "\n".join(line.split("//", 1)[0] for line in common.splitlines())
|
||||
if "#version" in code or "[" in code or re.search(r"\.\s*[xyzwrgba]{2,4}\b", code):
|
||||
raise SystemExit("FAIL: n64_common.glsl is an include in what GLSL and C++ share: no #version, no arrays, no swizzles")
|
||||
|
||||
|
||||
def check_glsl(tmp):
|
||||
glslang = shutil.which("glslangValidator")
|
||||
if not glslang:
|
||||
print("(glslangValidator is not on the PATH: n64_common.glsl was not compiled as GLSL)")
|
||||
return
|
||||
comp = Path(tmp) / "stand_in.comp"
|
||||
comp.write_text(STAND_IN_SHADER, encoding="utf-8")
|
||||
r = subprocess.run([glslang, "-V", "--target-env", "vulkan1.3", "-I" + str(SHADERS), str(comp), "-o", str(Path(tmp) / "s.spv")],
|
||||
capture_output=True, text=True)
|
||||
if r.returncode:
|
||||
raise SystemExit("FAIL: n64_common.glsl does not compile as GLSL:\n" + r.stdout + r.stderr)
|
||||
print("(n64_common.glsl compiles as GLSL in a stand-in compute shader)")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument("--cxx", default="clang++")
|
||||
args = parser.parse_args()
|
||||
check_sources()
|
||||
with tempfile.TemporaryDirectory(prefix="n64-rules-") as tmp:
|
||||
cpp, exe = Path(tmp) / "n64_rules_test.cpp", Path(tmp) / "n64-rules.exe"
|
||||
cpp.write_text(DRIVER, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I" + str(VK), str(cpp),
|
||||
"-o", str(exe)], check=True)
|
||||
r = subprocess.run([str(exe)], capture_output=True, text=True)
|
||||
print(r.stdout.rstrip())
|
||||
if r.returncode:
|
||||
raise SystemExit("FAIL: N64 Classic's rules")
|
||||
check_glsl(tmp)
|
||||
print("PASS: N64 Classic's rules and its 3D pass's per-pixel maths")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
463
tests/test_n64_tv.py
Normal file
463
tests/test_n64_tv.py
Normal file
@@ -0,0 +1,463 @@
|
||||
"""N64 Classic's TV (gpu/vk/shaders/n64_tv.comp and n64_tv.glsl; vk_framegen.cpp framegen_scale, init_tv; upscaler_rows.h
|
||||
kTvFilter, tv_filter; vk_menu.cpp menu_note_present_sizes; vk_n64.cpp n64_tv_now). Step 4 of n64-classic-mode-plan.md, behind
|
||||
RX_VK_N64 as the steps before. No game, no GPU.
|
||||
|
||||
Compiled and run: n64_tv.glsl, written in what GLSL and C++ share, over a small GLSL stand-in (as aa_common.glsl is): no
|
||||
scanlines leave every channel as it is; the beam never takes light below 0 nor more than doubles it, its mean over a line by
|
||||
its closed form is the mean summed, a flat picture keeps its brightness within 15% at the presets' scanlines at any level,
|
||||
and a bright line is wider; the aperture grille and the shadow mask light one channel a pixel, the grille repeats every 3
|
||||
pixels and the slot mask every 6 by 4 with one dark row in 4, neighbouring triads' 2 apart, each mask lights the three
|
||||
colours alike and dims the picture less than a fifth at 30%; the colour to the composite signal and back, grey carrying no
|
||||
colour, the bleed's weights; the screen's curve, which keeps the picture in order and loses its corners, the vignette and
|
||||
the rounded corners only on a curved screen. And upscaler_rows.h's tv_filter: the TV's value while it runs, past the filters
|
||||
RX_VK_UPSCALE names.
|
||||
|
||||
n64_tv_comp_spv.h names the hash of the sources it was compiled from (n64_tv.comp, n64_common.glsl, n64_tv.glsl), checked
|
||||
with or without glslang; with glslangValidator of the version the header names, the rest of the header is the pass compiled
|
||||
now, byte for byte. --write makes the header.
|
||||
|
||||
Read in the sources: the shader's bindings and push constants, and the C++ struct framegen_scale pushes, field for field; the
|
||||
shader decodes the picture and encodes it again, warps it, takes the beam and the mask per channel at the window's own
|
||||
pixels; framegen_scale runs the TV before AMD FSR 1 and the filter, only with n64_tv_now and its pipeline made, makes the
|
||||
picture at 1/8 for the glow, draws ultrawide's menu sides first into an image of the window's size, and gives the TV the
|
||||
screen's scanline strength and mask (n64_rules.h), the bleed in the picture's widths and (step 8) the switch's frame (the
|
||||
squash to a line and a dot, the flash), ticked once a present from vk_replay.cpp; init_tv's pipeline; the filter the
|
||||
present takes is tv_filter's over window_filter's; n64_tv_now asks n64_rules.h tv_runs with DLSS frame generation; the
|
||||
development guide names the switches.
|
||||
|
||||
(11-22, after the owner's test: "None of the classic visual effects apply to any of the custom UI") The options' own screens
|
||||
under the TV: the shader lays their layer over the picture where it reads the picture (every tap, the bleed's too), before
|
||||
the TV's steps; framegen_scale says the TV drew (vk_n64.h n64_screen_drawn) and asks vk_menu.cpp menu_tv_layer for the layer
|
||||
before its pass, binding it fourth; the present says where the picture goes before the window pass and is done after it;
|
||||
menu_tv_layer draws the options into ImGui's background list and the layer (vk_imgui.cpp record_layer, cleared, GENERAL
|
||||
for the pass), menu_record the rest over the window (record_rest). Compiled: n64_rules.h screen_point, the mouse's, takes a
|
||||
window pixel to the very place of the picture n64_tv.comp samples for it (its squash and n64_warp), and leaves points
|
||||
beside the place as they are.
|
||||
|
||||
python -I -B tests/test_n64_tv.py [--cxx clang++] [--glslang glslangValidator] [--write]
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
SHADERS = VK / "shaders"
|
||||
PARTS = ("n64_tv.comp", "n64_common.glsl", "n64_tv.glsl")
|
||||
HEADER = SHADERS / "n64_tv_comp_spv.h"
|
||||
FLAGS = ["-V", "--target-env", "vulkan1.2", "--vn", "N64_TV_COMP_SPV"]
|
||||
|
||||
DRIVER = r'''
|
||||
#include "n64_rules.h"
|
||||
#include "upscaler_rows.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <initializer_list>
|
||||
|
||||
// (just enough of GLSL for n64_common.glsl and n64_tv.glsl, in a namespace of its own)
|
||||
namespace glsl {
|
||||
static float floor(float a) { return std::floor(a); }
|
||||
static float clamp(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; }
|
||||
static float pow(float a, float b) { return std::pow(a, b); }
|
||||
static float exp(float a) { return std::exp(a); }
|
||||
static float sqrt(float a) { return std::sqrt(a); }
|
||||
static float max(float a, float b) { return a < b ? b : a; }
|
||||
static float abs(float a) { return std::fabs(a); }
|
||||
#include "shaders/n64_common.glsl"
|
||||
#include "shaders/n64_tv.glsl"
|
||||
} // namespace glsl
|
||||
|
||||
using namespace glsl;
|
||||
static int checks, fails;
|
||||
static void want(bool ok, const char* what) {
|
||||
checks++;
|
||||
if (!ok) fails++, std::printf("FAIL %s\n", what);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// ---- the beam ----
|
||||
bool flat = true, bounded = true;
|
||||
for (int i = 0; i <= 100; i++)
|
||||
for (int l = 0; l <= 10; l++) {
|
||||
const float f = -0.5f + i / 100.0f, level = l / 10.0f;
|
||||
flat &= n64_scan(f, level, 0.0f) == 1.0f;
|
||||
for (float s : {0.35f, 0.6f, 0.8f, 1.0f}) {
|
||||
const float m = n64_scan(f, level, s);
|
||||
bounded &= m >= 0.0f && m <= 2.0f;
|
||||
}
|
||||
}
|
||||
want(flat, "no scanlines: every channel as it is");
|
||||
want(bounded, "the beam never takes light below 0 nor more than doubles it");
|
||||
bool means = true, kept = true;
|
||||
float worst = 1.0f;
|
||||
for (int l = 0; l <= 20; l++) {
|
||||
const float level = l / 20.0f;
|
||||
double sum = 0.0;
|
||||
const int n = 4000;
|
||||
for (int i = 0; i < n; i++) sum += n64_beam(-0.5f + (i + 0.5f) / n, level);
|
||||
means &= std::fabs(sum / n - n64_beam_mean(level)) < 2e-3;
|
||||
for (float s : {0.35f, 0.6f, 0.8f}) {
|
||||
double a = 0.0;
|
||||
for (int i = 0; i < n; i++) a += n64_scan(-0.5f + (i + 0.5f) / n, level, s);
|
||||
a /= n;
|
||||
kept &= a >= 0.85 && a <= 1.1;
|
||||
worst = (float)a < worst ? (float)a : worst;
|
||||
}
|
||||
}
|
||||
want(means, "the beam's mean over a line, by its closed form, within two thousandths");
|
||||
want(kept, "a flat picture keeps its brightness within 15% at the presets' scanlines, any level");
|
||||
std::printf("(the darkest flat picture through the scanlines: %.3f of its light)\n", worst);
|
||||
want(n64_beam(0.4f, 1.0f) > n64_beam(0.4f, 0.2f) && n64_beam(0.0f, 0.5f) == 1.0f, "a bright line is wider; the line's middle is its peak");
|
||||
|
||||
// ---- the mask ----
|
||||
bool one = true, repeats = true, breaks = true, none_off = true;
|
||||
for (int y = 0; y < 12; y++)
|
||||
for (int x = 0; x < 12; x++) {
|
||||
for (int type : {2, 4}) {
|
||||
float lit = 0.0f;
|
||||
for (int c = 0; c < 3; c++) lit += n64_mask_lit(x, y, type, c);
|
||||
one &= lit == 1.0f;
|
||||
}
|
||||
for (int c = 0; c < 3; c++) {
|
||||
repeats &= n64_mask_lit(x, y, 2, c) == n64_mask_lit(x + 3, y + 1, 2, c);
|
||||
repeats &= n64_mask_lit(x, y, 3, c) == n64_mask_lit(x + 6, y + 4, 3, c);
|
||||
none_off &= n64_mask(x, y, 1, c, 0.5f) == 1.0f && n64_mask(x, y, 2, c, 0.0f) == 1.0f;
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < 12; x++) {
|
||||
int dark = 0, row = -1;
|
||||
for (int y = 0; y < 4; y++) {
|
||||
float lit = 0.0f;
|
||||
for (int c = 0; c < 3; c++) lit += n64_mask_lit(x, y, 3, c);
|
||||
if (lit == 0.0f) dark++, row = y;
|
||||
else breaks &= lit == 1.0f;
|
||||
}
|
||||
breaks &= dark == 1 && row == ((x / 3) % 2 ? 2 : 0);
|
||||
}
|
||||
want(one, "the aperture grille and the shadow mask light one channel a pixel");
|
||||
want(repeats, "the grille repeats every 3 pixels, the slot mask every 6 by 4");
|
||||
want(breaks, "the slot mask: one dark row in 4, neighbouring triads' 2 rows apart");
|
||||
want(none_off, "no mask, or no strength: every channel as it is");
|
||||
bool even = true;
|
||||
for (int type : {2, 3, 4}) {
|
||||
double sum[3] = {0, 0, 0};
|
||||
for (int y = 0; y < 4; y++)
|
||||
for (int x = 0; x < 6; x++)
|
||||
for (int c = 0; c < 3; c++) sum[c] += n64_mask(x, y, type, c, 0.3f);
|
||||
even &= std::fabs(sum[0] - sum[1]) < 1e-4 && std::fabs(sum[1] - sum[2]) < 1e-4 && sum[0] / 24.0 > 0.8 && sum[0] / 24.0 < 1.0;
|
||||
}
|
||||
want(even, "each mask lights the three colours alike (no cast), dimming the picture less than a fifth at 30%");
|
||||
|
||||
// ---- the composite signal ----
|
||||
bool round = true, grey = true;
|
||||
for (int i = 0; i <= 10; i++)
|
||||
for (int j = 0; j <= 10; j++) {
|
||||
const float r = i / 10.0f, g = j / 10.0f, b = (i * j % 11) / 10.0f;
|
||||
const float y = n64_y(r, g, b), ii = n64_i(r, g, b), q = n64_q(r, g, b);
|
||||
round &= std::fabs(n64_red(y, ii, q) - r) < 2e-3f && std::fabs(n64_green(y, ii, q) - g) < 2e-3f &&
|
||||
std::fabs(n64_blue(y, ii, q) - b) < 2e-3f;
|
||||
grey &= std::fabs(n64_i(r, r, r)) < 1e-6f && std::fabs(n64_q(r, r, r)) < 1e-6f;
|
||||
}
|
||||
want(round, "the colour to the signal and back, within two thousandths");
|
||||
want(grey, "grey carries no colour: the bleed leaves it grey");
|
||||
float wsum = 0.0f;
|
||||
for (int t = -2; t <= 2; t++) wsum += n64_bleed_weight(t);
|
||||
want(std::fabs(wsum - 1.0f) < 1e-6f && n64_bleed_weight(-1) == n64_bleed_weight(1) && n64_bleed_weight(0) > n64_bleed_weight(2),
|
||||
"the bleed's weights: symmetric, the middle heaviest, one in all");
|
||||
|
||||
// ---- the screen ----
|
||||
want(n64_warp(0.3f, -0.7f, 0.0f) == 0.3f && n64_warp(0.0f, 0.9f, 0.05f) == 0.0f, "a flat screen, and the middle: as they are");
|
||||
want(n64_warp(1.0f, 1.0f, 0.03f) > 1.0f && n64_warp(0.98f, 0.98f, 0.015f) > 1.0f, "a curved screen loses the picture's corners");
|
||||
bool outward = true;
|
||||
for (int i = 1; i <= 100; i++) outward &= n64_warp(i / 100.0f, 0.5f, 0.03f) > n64_warp((i - 1) / 100.0f, 0.5f, 0.03f);
|
||||
want(outward, "the warp keeps the picture in order");
|
||||
bool vig = true;
|
||||
for (int i = 0; i <= 10; i++)
|
||||
for (int j = 0; j <= 10; j++) {
|
||||
vig &= n64_vignette(i / 10.0f, j / 10.0f, 0.0f) == 1.0f;
|
||||
vig &= n64_vignette(i / 10.0f, j / 10.0f, 0.05f) >= 0.399f;
|
||||
}
|
||||
want(vig && n64_vignette(0.5f, 0.5f, 0.03f) == 1.0f && n64_vignette(0.02f, 0.02f, 0.03f) < 0.8f,
|
||||
"the vignette: none on a flat screen, darker corners on a curved one, never below 0.4");
|
||||
want(n64_corner(0.0f, 0.0f, 0.03f) == 1.0f && n64_corner(1.0f, 1.0f, 0.03f) == 0.0f && n64_corner(1.0f, 1.0f, 0.0f) == 1.0f &&
|
||||
n64_corner(0.99f, 0.0f, 0.03f) == 1.0f, "the rounded corners: only at the corners, only on a curved screen");
|
||||
|
||||
// ---- (11-22) the mouse: the place of the picture the TV samples for a window pixel, as n64_tv.comp finds it ----
|
||||
namespace nr = mkwvk::n64_rules;
|
||||
bool same_place = true, beside = true;
|
||||
const float px0 = 240.0f, py0 = 0.0f, pw = 1440.0f, ph = 1080.0f; // (a 4:3 picture in a 16:9 window)
|
||||
for (float curve : {0.0f, 0.015f, 0.03f, 0.05f})
|
||||
for (float ax : {1.0f, 0.5f})
|
||||
for (int gy = 0; gy < 1080; gy += 27)
|
||||
for (int gx = 0; gx < 1440; gx += 31) {
|
||||
// (n64_tv.comp: the pixel's middle in -1..1 of the place, the squash, the warp, the picture's uv)
|
||||
float a = (gx + 0.5f) / pw * 2.0f - 1.0f, b = (gy + 0.5f) / ph * 2.0f - 1.0f;
|
||||
a /= ax, b /= 1.0f;
|
||||
const float u = n64_warp(a, b, curve) * 0.5f + 0.5f, v = n64_warp(b, a, curve) * 0.5f + 0.5f;
|
||||
const nr::ScreenPoint s = nr::screen_point(px0 + gx + 0.5f, py0 + gy + 0.5f, px0, py0, pw, ph, curve, ax, 1.0f);
|
||||
same_place &= std::fabs(s.x - (px0 + u * pw)) < 1e-2f && std::fabs(s.y - (py0 + v * ph)) < 1e-2f;
|
||||
}
|
||||
for (float x : {0.0f, 100.0f, 239.0f, 1681.0f, 1919.0f}) {
|
||||
const nr::ScreenPoint s = nr::screen_point(x, 500.0f, px0, py0, pw, ph, 0.03f, 1.0f, 1.0f);
|
||||
beside &= s.x == x && s.y == 500.0f;
|
||||
}
|
||||
const nr::ScreenPoint none = nr::screen_point(700.0f, 300.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.03f, 1.0f, 1.0f);
|
||||
want(same_place, "the mouse: a window pixel taken to the place of the picture n64_tv.comp samples for it, at every curve and squash");
|
||||
want(beside && none.x == 700.0f && none.y == 300.0f, "the mouse: beside the picture's place, or with no place, the point as it is");
|
||||
const nr::ScreenPoint mid = nr::screen_point(960.0f, 540.0f, px0, py0, pw, ph, 0.03f, 1.0f, 1.0f);
|
||||
const nr::ScreenPoint edge = nr::screen_point(px0 + 10.0f, 540.0f, px0, py0, pw, ph, 0.03f, 1.0f, 1.0f);
|
||||
want(mid.x == 960.0f && mid.y == 540.0f && edge.x < px0 + 10.0f, "the mouse: the middle as it is; near an edge, out toward it, as the curve drew it");
|
||||
|
||||
// ---- the window's filter with the TV ----
|
||||
namespace ur = mkwvk::upscaler_rows;
|
||||
want(ur::tv_filter(3, true) == ur::kTvFilter && ur::tv_filter(0, true) == ur::kTvFilter && ur::tv_filter(3, false) == 3 &&
|
||||
ur::tv_filter(0, false) == 0, "the TV's filter while it runs, at 1:1 too; else the filter as it was chosen");
|
||||
want(ur::kTvFilter > 3 && ur::window_filter(2560, 1440, 3840, 2160, false) != ur::kTvFilter,
|
||||
"the TV's value is past the filters RX_VK_UPSCALE names and window_filter gives");
|
||||
|
||||
if (fails) std::printf("n64 tv: FAILED (%d of %d checks)\n", fails, checks);
|
||||
else std::printf("n64 tv: all %d checks passed\n", checks);
|
||||
return fails != 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def fail(what):
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
|
||||
def source_line():
|
||||
"""the header's first line: the hash of the pass's sources (each by its name and its bytes, line ends as LF) and how it is made"""
|
||||
digest = hashlib.sha256()
|
||||
for part in PARTS:
|
||||
digest.update(part.encode() + b"\0" + (SHADERS / part).read_bytes().replace(b"\r\n", b"\n") + b"\0")
|
||||
return ("// %s sha256 %s (tests/test_n64_tv.py --write: glslangValidator %s)\n"
|
||||
% (" + ".join(PARTS), digest.hexdigest(), " ".join(FLAGS))).encode()
|
||||
|
||||
|
||||
def compiled(glslang, tmp):
|
||||
out = Path(tmp) / "n64_tv.h"
|
||||
r = subprocess.run([glslang, *FLAGS, "-o", str(out), str(SHADERS / "n64_tv.comp")], capture_output=True, text=True)
|
||||
if r.returncode:
|
||||
fail("n64_tv.comp does not compile:\n%s%s" % (r.stdout, r.stderr))
|
||||
return out.read_bytes().replace(b"\r\n", b"\n")
|
||||
|
||||
|
||||
def glslang_version(glslang):
|
||||
got = subprocess.run([glslang, "--version"], capture_output=True, text=True).stdout
|
||||
m = re.search(r"Glslang Version: \d+:(\d+)\.(\d+)\.(\d+)", got)
|
||||
return m and "11%02d.%s.%s" % (int(m.group(1)), m.group(2), m.group(3))
|
||||
|
||||
|
||||
def block(src, head):
|
||||
at = src.index(head)
|
||||
end = src.index("{", at) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (src[end] == "{") - (src[end] == "}")
|
||||
end += 1
|
||||
return src[at:end]
|
||||
|
||||
|
||||
def in_order(text, parts, what):
|
||||
at = [text.find(p) for p in parts]
|
||||
if min(at) < 0 or at != sorted(at):
|
||||
fail("%s: %s" % (what, [p for p, a in zip(parts, at) if a < 0] or at))
|
||||
|
||||
|
||||
def check_sources():
|
||||
comp = (SHADERS / "n64_tv.comp").read_text(encoding="utf-8")
|
||||
in_order(comp, ['#extension GL_GOOGLE_include_directive : require', '#include "n64_common.glsl"', '#include "n64_tv.glsl"',
|
||||
"void main()"], "n64_tv.comp no longer includes n64_common.glsl and n64_tv.glsl")
|
||||
for b in ("layout(binding = 0) uniform sampler2D src;", "layout(binding = 1, rgba8) uniform writeonly image2D dst;",
|
||||
"layout(binding = 2) uniform sampler2D small;", "layout(binding = 3) uniform sampler2D menu;"):
|
||||
if b not in comp:
|
||||
fail("n64_tv.comp: %s is not its binding" % b)
|
||||
push = re.search(r"layout\(push_constant\) uniform P \{(.*?)\} pc;", comp, re.S)
|
||||
fields = re.findall(r"^\s*(\w+) (\w+);", push.group(1), re.M) if push else []
|
||||
want = [("float", "lines"), ("float", "scan"), ("float", "mask"), ("float", "bleed"), ("float", "glow"), ("float", "curve"),
|
||||
("float", "saturation"), ("int", "mask_type"), ("float", "anim_x"), ("float", "anim_y"), ("float", "flash"),
|
||||
("int", "menu")]
|
||||
if fields != want:
|
||||
fail("n64_tv.comp's push constants are not %s: %s" % (want, fields))
|
||||
# ((11-22) the options' layer over the picture wherever the picture is read, before main's steps)
|
||||
read = block(comp, "vec3 encoded(vec2 uv) {")
|
||||
in_order(read, ["vec3 c = clamp(textureLod(src, uv, 0.0).rgb, 0.0, 1.0);", "if (pc.menu != 0) {",
|
||||
"const vec4 m = clamp(textureLod(menu, uv, 0.0), 0.0, 1.0);", "c = m.rgb + c * (1.0 - m.a);",
|
||||
"return clamp(c, 0.0, 1.0);"],
|
||||
"n64_tv.comp: encoded no longer lays the options' layer (premultiplied) over the picture")
|
||||
if comp.index("vec3 encoded(vec2 uv) {") > comp.index("void main()") or "textureLod(src," in block(comp, "void main()"):
|
||||
fail("n64_tv.comp: main reads the picture past encoded (the options' layer would be left out of a tap)")
|
||||
# ((11-22, the owner's second look) the glow's 1/8 copy made again with the options over the picture: the block's mean of
|
||||
# encoded, before the TV's own steps; else the glow blurred the game's own panes through the options' plates)
|
||||
in_order(block(comp, "void main()"), ["if (pc.menu == 2) {", "for (int x = 0; x < 4; x++) sum += encoded(at + (vec2(x, y) - 1.5) * 0.25 * block);",
|
||||
"imageStore(dst, g, vec4(sum / 16.0, 1.0));\n return;", "vec2 p = (vec2(g) + 0.5) / vec2(d) * 2.0 - 1.0;"],
|
||||
"n64_tv.comp: menu 2 does not make the 1/8 copy from the picture with the options over it, before the TV's steps")
|
||||
main = block(comp, "void main()")
|
||||
in_order(main, ["if (abs(p.x) > pc.anim_x || abs(p.y) > pc.anim_y) {", "imageStore(dst, g, vec4(0.0, 0.0, 0.0, 1.0));",
|
||||
"p /= vec2(pc.anim_x, pc.anim_y);", "n64_warp(p.x, p.y, pc.curve)", "if (abs(w.x) > 1.0 || abs(w.y) > 1.0) {",
|
||||
"n64_bleed_weight(t)",
|
||||
"vec3 c = decode3(e);", "mix(vec3(luma), c, pc.saturation)", "fract(uv.y * pc.lines) - 0.5",
|
||||
"n64_scan(f, c.r, pc.scan)", "n64_mask(g.x, g.y, pc.mask_type, 0, pc.mask)", "pc.glow * decode3(",
|
||||
"n64_vignette(uv.x, uv.y, pc.curve) * n64_corner(w.x, w.y, pc.curve)",
|
||||
"c = mix(c, vec3(0.9, 0.95, 1.0), clamp(pc.flash, 0.0, 1.0) * 0.8);", "encode3(clamp(c, 0.0, 1.0)) + dither(g)"],
|
||||
"n64_tv.comp's steps are no longer the switch's squash, the curve, the bleed, linear light, the beam, the mask, the glow, "
|
||||
"the vignette, the switch's flash")
|
||||
for ch in ("n64_scan(f, c.g, pc.scan)", "n64_scan(f, c.b, pc.scan)", "n64_mask(g.x, g.y, pc.mask_type, 1, pc.mask)",
|
||||
"n64_mask(g.x, g.y, pc.mask_type, 2, pc.mask)"):
|
||||
if ch not in main:
|
||||
fail("n64_tv.comp: the beam and the mask are not each channel's (%s)" % ch)
|
||||
|
||||
framegen = (VK / "vk_framegen.cpp").read_text(encoding="utf-8")
|
||||
for inc in ('#include "vk_n64.h"', '#include "shaders/n64_tv_comp_spv.h"'):
|
||||
if inc not in framegen:
|
||||
fail("vk_framegen.cpp does not %s" % inc)
|
||||
init = block(framegen, "bool init_tv() {")
|
||||
if "make_pipe(scale.tv, N64_TV_COMP_SPV, sizeof N64_TV_COMP_SPV, {S, I, S, S}, 48)" not in init or "init_scale()" not in init:
|
||||
fail("init_tv: the TV's pipeline is not n64_tv.comp's, with its four bindings and 48 bytes of push constants")
|
||||
scale = block(framegen, "VkImage framegen_scale(")
|
||||
tv = block(scale, "if (!pq && n64_tv_now(pq) && init_tv()) {")
|
||||
in_order(scale, ["if (!pq && n64_tv_now(pq) && init_tv()) {", "const bool fsr1 = opts.upscale == 3"],
|
||||
"framegen_scale: the TV no longer runs before AMD FSR 1 and the filter")
|
||||
in_order(tv, ["const n64_rules::AnimFrame f = n64_anim();", "const uint32_t smw = std::max(1u, source.w / 8), smh = std::max(1u, source.h / 8);",
|
||||
"pass(cmd, filter, {{src, scale.linear}, {scale.small.view, VK_NULL_HANDLE}, {src, scale.linear}}, smw, smh, &sp, sizeof sp);",
|
||||
"if (wide.side) {", "picture = scale.tv_img.view;", "const int mask = n64_rules::mask_shown(look.mask, dh);",
|
||||
"n64_screen_drawn(look.curvature, f.scale_x, f.scale_y);", "const VkImageView menu = menu_tv_layer(cmd);",
|
||||
"struct { float lines, scan, mask, bleed, glow, curve, saturation; int mask_type; float anim_x, anim_y, flash; int menu; } tp{",
|
||||
"(float)n64_rules::kTvLines, n64_rules::scanline_strength(look.scanlines, dh), look.mask_strength,",
|
||||
"n64_rules::tv_bleed_uv(look.bleed, source.w, source.h), look.glow, look.curvature, look.saturation, mask,",
|
||||
"f.scale_x, f.scale_y, f.flash, menu ? 1 : 0};",
|
||||
"if (menu) {", "tp.menu = 2;",
|
||||
"pass(cmd, scale.tv, {{picture, scale.linear}, {scale.small.view, VK_NULL_HANDLE}, {picture, scale.linear}, {menu, scale.linear}},",
|
||||
"smw, smh, &tp, sizeof tp);", "tp.menu = 1;",
|
||||
"pass(cmd, scale.tv, {{picture, scale.linear}, {scale.scaled.view, VK_NULL_HANDLE}, {scale.small.view, scale.linear},",
|
||||
"{menu ? menu : scale.small.view, scale.linear}}, dw, dh, &tp, sizeof tp);",
|
||||
"if (f.done && now != told) {",
|
||||
"return scale.scaled.image;"],
|
||||
"framegen_scale's TV: the 1/8 copy, the menu sides first, the screen's scanlines and mask, the bleed, the pass, its image")
|
||||
menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
|
||||
# ((11-22) the options under the TV: drawn into ImGui's background list and the layer; the rest over the window after)
|
||||
layer = block(menu, "VkImageView menu_tv_layer(VkCommandBuffer cmd) {")
|
||||
in_order(layer, ["if (!on || !n64_screen_place(&x, &y, &pw, &ph, &w, &h)) return VK_NULL_HANDLE;",
|
||||
"if (s.start || !(s.open || s.game_tab || s.mods_row) || bugshot_state() == 1 || dev.hdr || !ui::begin(w, h))",
|
||||
"draw_overlays(w, h, s, ImGui::GetBackgroundDrawList());", "ui::record_layer(cmd, x, y, pw, ph);",
|
||||
"tv_drawn = true, tv_layer = layer != VK_NULL_HANDLE"],
|
||||
"menu_tv_layer: the options are not drawn under the TV only while they show, into the background list and the layer")
|
||||
record = block(menu, "void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {")
|
||||
in_order(record, ["if (tv_drawn) {", "bugshot_record(cmd, index, w, h);", "ui::record_rest(cmd, index, w, h);", "return;",
|
||||
"draw_overlays(w, h, s, nullptr);"],
|
||||
"menu_record: the rest of a frame drawn under the TV is not drawn over the window, or the frame as before is gone")
|
||||
tail = record.rstrip()[-400:]
|
||||
if not record.rstrip().endswith("ui::record(cmd, index, w, h);\n}") or tail.find("draw_overlays(w, h, s, nullptr);") < 0:
|
||||
fail("menu_record: the frame as before no longer ends drawn over the window")
|
||||
overlays = block(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {")
|
||||
for need in ("if (under) m.d = under;", "if (s.open) draw_menu(m, full && !over_row);", "if (s.game_tab) draw_game_tab(m);",
|
||||
"else if (s.mods_row) draw_mods_row_shut(m);", "draw_fps(c, ", "if (s.note) draw_notice(c);"):
|
||||
if need not in overlays:
|
||||
fail("draw_overlays: %s is gone (the options under the TV, the counter and the notice over it)" % need)
|
||||
imgui = (VK / "vk_imgui.cpp").read_text(encoding="utf-8")
|
||||
rl = block(imgui, "VkImageView record_layer(VkCommandBuffer cmd, uint32_t x, uint32_t y, uint32_t w, uint32_t h) {")
|
||||
in_order(rl, ["part_of({ImGui::GetBackgroundDrawList()}, (float)x, (float)y, w, h);", "ca.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;",
|
||||
"ImGui_ImplVulkan_RenderDrawData(&d, cmd);", "VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT",
|
||||
"return layer.sample;"],
|
||||
"record_layer: the background list is not drawn into a cleared layer at the picture's place, GENERAL for the TV's pass")
|
||||
if "ii.ImageCount = 8;" not in imgui:
|
||||
fail("vk_imgui.cpp: the backend's vertex buffers are not enough for two draws a frame over three frames in flight")
|
||||
# ((11-22) the game's own menus' mouse under the curve: the renderer's screen_point, last of its table, at version 19 (16-18 ultrawide's on next/update))
|
||||
api = (VK / "vk_api.h").read_text(encoding="utf-8")
|
||||
if not re.search(r"void \(\*screen_point\)\(int \*x, int \*y, int w, int h\);\s*\} MkwVkRenderer;", api) or \
|
||||
"#define MKWVK_API_VERSION 19" not in api:
|
||||
fail("vk_api.h: MkwVkRenderer has no screen_point last, at version 19")
|
||||
if "void rx_screen_point(int *x, int *y, int w, int h) { if (vk && vk->screen_point) vk->screen_point(x, y, w, h); }" not in \
|
||||
(ROOT / "host" / "rx_backend.c").read_text(encoding="utf-8"):
|
||||
fail("host/rx_backend.c: rx_screen_point does not ask the renderer")
|
||||
oot = block((ROOT / "host" / "oot_menu.c").read_text(encoding="utf-8"), "static void mouse_tick_locked(Ctx *c, uint64_t screen) {")
|
||||
in_order(oot, ["const int got = hos_mouse_game_pointer(&px, &py, &w, &h, &pressed, &wheel);", "if (!got) return;",
|
||||
"rx_screen_point(&px, &py, w, h);", "hit.x = (float)(px - w / 2) * scale"],
|
||||
"host/oot_menu.c: the game's menus' cursor is not taken through the TV's curve before it is tested")
|
||||
present = block((VK / "vk_replay.cpp").read_text(encoding="utf-8"), "void present_image(")
|
||||
in_order(present, ["n64_screen_begin(rect.x, rect.y, rect.w, rect.h, dev.swap_extent.width, dev.swap_extent.height);",
|
||||
"framegen_scale(f.cmd, view, src, sw, sh, crop, rect.w, rect.h)", "n64_screen_end();",
|
||||
"menu_record(f.cmd, index, dev.swap_extent.width, dev.swap_extent.height);"],
|
||||
"present_image: the TV's screen is not begun before the window pass and ended after it, before the overlays")
|
||||
note = block(menu, "void menu_note_present_sizes(")
|
||||
if "const int filter = ur::tv_filter(ur::window_filter(picture_w, picture_h, place.w, place.h, native_hdr), n64_tv_now(native_hdr));" not in note:
|
||||
fail("menu_note_present_sizes: the filter the present takes is not tv_filter's over window_filter's")
|
||||
if "opts.upscale = std::min(std::max(atoi(e), 0), 3);" not in menu:
|
||||
fail("RX_VK_UPSCALE can name the TV's filter value (it stops at 3)")
|
||||
rows = (VK / "upscaler_rows.h").read_text(encoding="utf-8")
|
||||
if "constexpr int kTvFilter = 4;" not in rows or "inline int tv_filter(int filter, bool tv) { return tv ? kTvFilter : filter; }" not in rows:
|
||||
fail("upscaler_rows.h: kTvFilter or tv_filter is gone")
|
||||
n64 = (VK / "vk_n64.cpp").read_text(encoding="utf-8")
|
||||
if "bool n64_tv_now(bool native_pq) { return n64_rules::tv_draws(n64_look(), n64_anim(), native_pq, dlssg::active()); }" not in n64:
|
||||
fail("vk_n64.cpp: n64_tv_now does not ask n64_rules.h tv_draws with the switch and DLSS frame generation")
|
||||
# ((step 8) the switch: ticked once a present beside the texture blur's, with HDR Native's picture; the look the preset shown)
|
||||
tick = block(n64, "void n64_tick(bool native_pq) {")
|
||||
for need in ("switch_rule.at(t, n64_preset(), anim_on() && !native_pq && !dlssg::active());", "anim_now = now.frame;",
|
||||
"shown_now.store(now.shown, std::memory_order_relaxed);"):
|
||||
if need not in tick:
|
||||
fail("n64_tick: %s is gone" % need)
|
||||
if 'env_number("RX_VK_N64_TV_ANIM", 1) != 0' not in n64 or "n64_rules::look_of(n64_shown()," not in n64:
|
||||
fail("vk_n64.cpp: RX_VK_N64_TV_ANIM is not read, or the look is not the preset shown")
|
||||
replay = (VK / "vk_replay.cpp").read_text(encoding="utf-8")
|
||||
if " upscale_lod_tick();" not in replay or "n64_tick(present_native_pq.load(std::memory_order_relaxed));" not in replay or \
|
||||
replay.index(" upscale_lod_tick();") > replay.index("n64_tick(present_native_pq.load("):
|
||||
fail("vk_replay.cpp: the switch is not ticked once a present, after the texture blur's tick")
|
||||
docs = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
|
||||
if "`RX_VK_N64_TV=0` leaves it out" not in docs or "`RX_VK_N64_MASK=<0..4>`" not in docs or "`RX_VK_N64_TV_ANIM=0`" not in docs or \
|
||||
"`RX_VK_N64_TV_MENU=0`" not in docs:
|
||||
fail("docs/development.md: the TV's switches are not in the switches table")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument("--cxx", default="clang++")
|
||||
parser.add_argument("--glslang", default=None)
|
||||
parser.add_argument("--write", action="store_true")
|
||||
args = parser.parse_args()
|
||||
glslang = args.glslang or shutil.which("glslangValidator")
|
||||
if args.write:
|
||||
if not glslang:
|
||||
fail("--write needs glslangValidator")
|
||||
with tempfile.TemporaryDirectory(prefix="n64-tv-") as tmp:
|
||||
HEADER.write_bytes(source_line() + compiled(glslang, tmp))
|
||||
print("wrote %s" % HEADER.relative_to(ROOT))
|
||||
check_sources()
|
||||
with tempfile.TemporaryDirectory(prefix="n64-tv-") as tmp:
|
||||
cpp, exe = Path(tmp) / "n64_tv_test.cpp", Path(tmp) / "n64-tv.exe"
|
||||
cpp.write_text(DRIVER, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-I" + str(VK), str(cpp),
|
||||
"-o", str(exe)], check=True)
|
||||
r = subprocess.run([str(exe)], capture_output=True, text=True)
|
||||
print(r.stdout.rstrip())
|
||||
if r.returncode:
|
||||
fail("N64 Classic's TV, per pixel")
|
||||
if not HEADER.exists():
|
||||
fail("n64_tv_comp_spv.h is missing: run with --write")
|
||||
header = HEADER.read_bytes().replace(b"\r\n", b"\n")
|
||||
first, _, rest = header.partition(b"\n")
|
||||
if first + b"\n" != source_line():
|
||||
fail("n64_tv_comp_spv.h was not made from n64_tv.comp, n64_common.glsl and n64_tv.glsl as they are now: run with --write")
|
||||
if glslang:
|
||||
named = rest.split(b"\n", 1)[0].decode("ascii", "replace").strip().lstrip("/ ").strip()
|
||||
if glslang_version(glslang) == named:
|
||||
with tempfile.TemporaryDirectory(prefix="n64-tv-") as tmp:
|
||||
if compiled(glslang, tmp) != rest:
|
||||
fail("n64_tv_comp_spv.h is not n64_tv.comp compiled: run with --write")
|
||||
print("(the SPIR-V header is its source compiled, byte for byte)")
|
||||
else:
|
||||
print("(glslangValidator is not version %s: the header was not compiled again)" % named)
|
||||
else:
|
||||
print("(glslangValidator is not on the PATH: the header's hash was checked, not its bytes)")
|
||||
print("PASS: N64 Classic's TV, per pixel and in the window pass")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -85,6 +85,8 @@ uint8_t *fake_heap;
|
||||
static uint64_t heap_top = FAKE_BASE + 0x1000;
|
||||
int64_t hos_now_ns(void) { return 1000000000LL; }
|
||||
void hos_log(const char *fmt, ...) { (void)fmt; }
|
||||
static uint64_t menu_class;
|
||||
void oot_menu_screen_tick(uint64_t vt) { menu_class = vt; }
|
||||
void rx_option_set(int id, int value) { (void)id, (void)value; }
|
||||
void hos_oot_menu_tick(Ctx *c, uint64_t screen);
|
||||
static int bench, asked, asked_entry, asked_entries;
|
||||
@@ -128,11 +130,11 @@ int main(void) {
|
||||
const uint64_t title_vt = 0x84c106e8ULL, title = screen_of(title_vt, 4);
|
||||
bench = 1;
|
||||
hos_oot_menu_tick(&ctx, title); /* (no button focused yet: the title still fading in) */
|
||||
CHECK(asked == 0 && !taps[0]);
|
||||
CHECK(asked == 0 && !taps[0] && menu_class == title_vt);
|
||||
*(uint8_t *)GP(button[2] + 56) = 1;
|
||||
bench = 0;
|
||||
hos_oot_menu_tick(&ctx, title); /* (benchmark mode off: a player's menus, nothing pressed) */
|
||||
CHECK(asked == 0 && !taps[0]);
|
||||
CHECK(asked == 0 && !taps[0] && menu_class == title_vt);
|
||||
bench = 1;
|
||||
hos_oot_menu_tick(&ctx, title);
|
||||
CHECK(asked == 1 && asked_screen == title && asked_vt == title_vt && asked_entry == 2 && asked_entries == 4);
|
||||
@@ -170,6 +172,7 @@ class OotMenuBenchOtherHalfTest(unittest.TestCase):
|
||||
(tmp / "gpu" / "vk" / "vk_api.h").write_text(VK_API_H, encoding="utf-8")
|
||||
(tmp / "host" / "hos_bench.h").write_text(BENCH_H, encoding="utf-8")
|
||||
shutil.copy(SRC, tmp / "host" / "oot_menu.c")
|
||||
shutil.copy(ROOT / "host/oot_title_movie.h", tmp / "host/oot_title_movie.h")
|
||||
shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h")
|
||||
(tmp / "host" / "t.c").write_text(FIXTURE, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
|
||||
@@ -97,12 +97,15 @@ void rx_option_set(int id, int value) {
|
||||
if (id == HOS_OPT_GAME_OPTIONS) game_options_said = value;
|
||||
}
|
||||
int rx_option(int id, int otherwise) { return id == HOS_OPT_MODS_SELECTED ? mods_selected : otherwise; }
|
||||
int hos_save_files_on(void) { return 0; } /* ((Triforce) no save files here: no Save Select under Mods (tests/test_save_files.py)) */
|
||||
int hos_mouse_wheel_take(void) { const int w = wheel_next; wheel_next = 0; return w; } /* (the wheel only, mouse kept) */
|
||||
int hos_mouse_game_pointer(int *x, int *y, int *w, int *h, uint32_t *pressed, int *wheel) {
|
||||
*x = ptr_x, *y = ptr_y, *w = 3840, *h = 2160, *pressed = pressed_next, *wheel = wheel_next;
|
||||
pressed_next = 0, wheel_next = 0;
|
||||
return pointer_hidden ? 2 : 1;
|
||||
}
|
||||
/* ((Triforce, 11-22) N64 Classic's TV's curve (rx_backend.c): no TV here, the point as it is */
|
||||
void rx_screen_point(int *x, int *y, int w, int h) { (void)x, (void)y, (void)w, (void)h; }
|
||||
static char taps[1024];
|
||||
void hos_hid_tap(const char *press) { strncat(taps, press, sizeof taps - strlen(taps) - 2), strcat(taps, ";"); }
|
||||
void hos_hid_stick(int lx, int ly, int rx, int ry, int hold_ms) { (void)lx, (void)ly, (void)rx, (void)ry, (void)hold_ms; }
|
||||
@@ -609,7 +612,8 @@ class OotOptionsScreenTests(unittest.TestCase):
|
||||
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")
|
||||
shutil.copy(ROOT / "host" / "oot_title_movie.h", tmp / "host" / "oot_title_movie.h") # (oot_menu_screen_tick)
|
||||
(tmp / "host" / "t.c").write_text(OPTIONS_FIXTURE + MENU_TICK, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] if sys.platform == "win32" else []
|
||||
build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", str(tmp / "host" / "t.c")] +
|
||||
@@ -624,6 +628,9 @@ class OotOptionsScreenTests(unittest.TestCase):
|
||||
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
|
||||
|
||||
|
||||
# ((Triforce) host/oot_title_movie.c's, which every menu screen's update tells its class: tests/test_oot_title_movie.py has
|
||||
# what is made of it; here only taken)
|
||||
MENU_TICK = "\nvoid oot_menu_screen_tick(unsigned long long screen_class) { (void)screen_class; }\n"
|
||||
# ((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>
|
||||
@@ -653,7 +660,8 @@ class OotMenuMouseTests(unittest.TestCase):
|
||||
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")
|
||||
shutil.copy(ROOT / "host" / "oot_title_movie.h", tmp / "host" / "oot_title_movie.h") # (oot_menu_screen_tick)
|
||||
(tmp / "host" / "t.c").write_text(FIXTURE + MENU_TICK, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", "-D_WIN32_WINNT=0x0601",
|
||||
str(tmp / "host" / "t.c"), str(tmp / "host" / "oot_menu.c"), "-o", str(binary)],
|
||||
|
||||
216
tests/test_oot_title_movie.py
Normal file
216
tests/test_oot_title_movie.py
Normal file
@@ -0,0 +1,216 @@
|
||||
"""Exercise the lifted movie and viewport sites with open movie handles and synthetic presents.
|
||||
|
||||
And the menu sides beside the filled title movie (host/oot_title_movie.h, host/rx_backend.c host_wide_menus): none while
|
||||
the movie alone shows; the picture's own margin while a menu opened over it runs (the file select, the file's box, the
|
||||
Options, the system menus' backdrop: host/oot_menu.c tells each menu screen's class every frame it runs), and for
|
||||
OOT_MENU_PRESENTS presents after its last update; none again after that. The title's own list is a menu screen too and is
|
||||
no menu over the title. In play (no filled movie) the margin is the picture's whatever runs.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "nx2"))
|
||||
import oot_wide
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
SOURCE = r"""
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <initializer_list>
|
||||
#include <thread>
|
||||
extern "C" {
|
||||
#include "oot_title_movie.h"
|
||||
volatile int64_t hos_present_count;
|
||||
int logs;
|
||||
void hos_log(const char *, ...) { ++logs; }
|
||||
}
|
||||
volatile float hos_wide_ratio = 2.4f;
|
||||
volatile float hos_wide_margin = (1 - (16.f / 9) / 2.4f) / 2;
|
||||
struct Ctx { uint64_t x[32]; };
|
||||
uint32_t recomp_load32(Ctx *, uintptr_t p) { uint32_t v; memcpy(&v, (void *)p, 4); return v; }
|
||||
void recomp_store32(Ctx *, uintptr_t p, uint32_t v) { memcpy((void *)p, &v, 4); }
|
||||
void movie(Ctx *c) { MOVIE_SITE }
|
||||
void viewport(Ctx *c) { VIEWPORT_SITE }
|
||||
void playback() {
|
||||
Ctx c{};
|
||||
float bounds[10]{};
|
||||
c.x[29] = (uintptr_t)bounds + 40;
|
||||
auto draw = [&](bool cover) {
|
||||
bounds[2] = 0;
|
||||
bounds[4] = 3840;
|
||||
movie(&c);
|
||||
if (cover) assert(bounds[2] == 0 && bounds[4] == 3840);
|
||||
else assert(bounds[2] > 0 && bounds[4] < 3840);
|
||||
c.x[2] = 0;
|
||||
c.x[4] = 1600;
|
||||
std::thread other([&] { viewport(&c); });
|
||||
other.join();
|
||||
assert(c.x[2] == 0 && c.x[4] == 1600);
|
||||
viewport(&c);
|
||||
assert((int32_t)c.x[2] == (cover ? -280 : 0));
|
||||
assert(c.x[4] == (cover ? 2160 : 1600));
|
||||
c.x[2] = 0;
|
||||
c.x[4] = 1600;
|
||||
viewport(&c);
|
||||
assert(c.x[2] == 0 && c.x[4] == 1600);
|
||||
};
|
||||
auto title = oot_movie_file("rom:/Event/Movie/Dm_Title_0005.webm");
|
||||
auto story = oot_movie_file("rom:/Event/Movie/Dm_Story_0010.WEBM");
|
||||
assert(title == OOT_MOVIE_TITLE && story == OOT_MOVIE_OTHER);
|
||||
assert(oot_movie_file("rom:/Else/Dm_Title_0005.webm") == OOT_MOVIE_OTHER);
|
||||
assert(oot_movie_file("rom:/Event/Movie/Dm_Title_0005.webm.bak") == OOT_MOVIE_NONE);
|
||||
draw(false);
|
||||
oot_movie_file_change(title, 1);
|
||||
oot_movie_file_change(title, 1);
|
||||
assert(!oot_movie_cover_recent() && logs == 0);
|
||||
draw(true);
|
||||
assert(oot_movie_cover_recent() && logs == 1);
|
||||
oot_movie_file_change(story, 1);
|
||||
draw(false);
|
||||
hos_present_count = 2;
|
||||
assert(oot_movie_cover_recent() && logs == 1);
|
||||
hos_present_count = 3;
|
||||
assert(!oot_movie_cover_recent() && logs == 2);
|
||||
oot_movie_file_change(title, -1);
|
||||
draw(false);
|
||||
oot_movie_file_change(story, -1);
|
||||
hos_wide_ratio = 32.f / 9;
|
||||
draw(false);
|
||||
hos_wide_ratio = 2.4f;
|
||||
draw(true);
|
||||
oot_movie_file_change(title, -1);
|
||||
draw(false);
|
||||
}
|
||||
// The menu sides' margin as host/rx_backend.c host_wide_menus gives it to the renderer
|
||||
volatile uint32_t hos_wide_keep_mask;
|
||||
static int mods_mode;
|
||||
enum { HOS_OPT_MODS_MUSIC = 161 };
|
||||
int rx_option(int id, int otherwise) { return id == HOS_OPT_MODS_MUSIC ? mods_mode : otherwise; }
|
||||
BACKEND_SITES
|
||||
static float margin_now() { return host_wide_menus(0xd); }
|
||||
void menus() {
|
||||
const uint64_t title_list = 0x84c106e8, files = 0x84c0eba0, file_box = 0x84c0f840, options = 0x84c0f108,
|
||||
backdrop = 0x84c04fb0, pause = 0x84c0baa8, hud = 0x84c08300;
|
||||
const float margin = hos_wide_margin;
|
||||
assert(margin > 0.1f);
|
||||
assert(!oot_title_menu_class(title_list) && !oot_title_menu_class(pause) && !oot_title_menu_class(hud) && !oot_title_menu_class(0));
|
||||
for (uint64_t c : {files, file_box, options, backdrop}) assert(oot_title_menu_class(c));
|
||||
Ctx c{};
|
||||
float bounds[10]{};
|
||||
c.x[29] = (uintptr_t)bounds + 40;
|
||||
auto frame = [&](bool title_movie, std::initializer_list<uint64_t> screens) { // (one frame of the game: its screens, its draw, its present)
|
||||
for (uint64_t s : screens) oot_menu_screen_tick(s);
|
||||
if (title_movie) {
|
||||
bounds[2] = 0, bounds[4] = 3840;
|
||||
movie(&c);
|
||||
c.x[2] = 0, c.x[4] = 1600;
|
||||
viewport(&c);
|
||||
assert(c.x[4] == 2160); // (the movie still fills the picture under a menu: the sides blur it)
|
||||
}
|
||||
hos_present_count = hos_present_count + 1;
|
||||
};
|
||||
hos_present_count = 100;
|
||||
auto title = oot_movie_file("rom:/Event/Movie/Dm_Title_0005.webm");
|
||||
oot_movie_file_change(title, 1);
|
||||
// the title alone, its own list running: no sides, and no menu's backdrop for the renderer
|
||||
for (int i = 0; i < 10; i++) frame(true, {title_list}), assert(margin_now() == 0.0f && !oot_menu_backdrop_runs());
|
||||
// 0.7's renderer-owned Mods page has no guest class. The title list alone does not request sides.
|
||||
mods_mode = 1;
|
||||
assert(margin_now() == 0.0f && !host_wide_backdrop());
|
||||
mods_mode = 2;
|
||||
for (int i = 0; i < 10; i++) frame(true, {title_list}), assert(margin_now() == margin && host_wide_backdrop());
|
||||
mods_mode = 1;
|
||||
assert(margin_now() == 0.0f && !host_wide_backdrop());
|
||||
mods_mode = 0;
|
||||
// the file select opened over it, with the backdrop or without, the title's list still running or not: the row's sides
|
||||
for (int i = 0; i < 10; i++) frame(true, {title_list, files}), assert(margin_now() == margin && oot_menu_backdrop_runs());
|
||||
for (int i = 0; i < 5; i++) frame(true, {files, file_box}), assert(margin_now() == margin);
|
||||
for (int i = 0; i < 5; i++) frame(true, {backdrop}), assert(margin_now() == margin);
|
||||
for (int i = 0; i < 5; i++) frame(true, {title_list, options}), assert(margin_now() == margin);
|
||||
// closed: the menu's last pictures keep the sides, then the title alone has none again
|
||||
for (int i = 0; i < OOT_MENU_PRESENTS - 1; i++) frame(true, {title_list}), assert(margin_now() == margin);
|
||||
assert(oot_menu_backdrop_runs());
|
||||
frame(true, {title_list});
|
||||
assert(margin_now() == 0.0f && !oot_menu_backdrop_runs());
|
||||
for (int i = 0; i < 10; i++) frame(true, {title_list}), assert(margin_now() == 0.0f);
|
||||
// screens that are no menu over the title change nothing there
|
||||
frame(true, {title_list, pause, hud}), assert(margin_now() == 0.0f);
|
||||
// in play, no filled movie: the picture's margin with a menu and without
|
||||
oot_movie_file_change(title, -1);
|
||||
for (int i = 0; i < 6; i++) frame(false, {hud});
|
||||
assert(margin_now() == margin && !oot_menu_backdrop_runs()); // (play, the item wheel's too: its blur is the wheel's)
|
||||
frame(false, {pause, backdrop}), assert(margin_now() == margin);
|
||||
assert(oot_wide_menu_margin(0.25f, 0, 0) == 0.25f && oot_wide_menu_margin(0.25f, 0, 1) == 0.25f);
|
||||
assert(oot_wide_menu_margin(0.25f, 1, 0) == 0.0f && oot_wide_menu_margin(0.25f, 1, 1) == 0.25f);
|
||||
assert(oot_menu_recent(10, 7) && !oot_menu_recent(10, 6) && !oot_menu_recent(10, -1));
|
||||
}
|
||||
int main() {
|
||||
playback();
|
||||
menus();
|
||||
int32_t y = 0, height = 1600;
|
||||
assert(oot_title_movie_cover(3840.f / 1600, &y, &height));
|
||||
assert(y == -280 && height == 2160);
|
||||
// Offset viewport, with an odd number of cropped rows.
|
||||
y = 13;
|
||||
height = 1440;
|
||||
assert(oot_title_movie_cover(3440.f / 1440, &y, &height));
|
||||
assert(height == 1935 && y == 13 - 247);
|
||||
// Near 12:5, rounding to a multiple of eight can land on either side.
|
||||
for (float ratio : {872.f/362, 864.f/361, 3848.f/1603}) {
|
||||
y = 0;
|
||||
height = 1080;
|
||||
assert(oot_title_movie_cover(ratio, &y, &height) && y < 0 && height > 1080);
|
||||
}
|
||||
for (float ratio : {16.f/10, 16.f/9, 2.425f, 32.f/9}) {
|
||||
y = 7;
|
||||
height = 1080;
|
||||
assert(!oot_title_movie_cover(ratio, &y, &height));
|
||||
assert(y == 7 && height == 1080);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cxx", required=True)
|
||||
args = parser.parse_args()
|
||||
# the renderer's margin is the header's rule, and every menu screen's update tells its class, in both halves of
|
||||
# host/oot_menu.c (the Windows one with the mouse, the other without)
|
||||
backend = (ROOT / "host/rx_backend.c").read_text(encoding="utf-8")
|
||||
sites = backend[backend.index("static float host_wide_menus("):backend.index("int hos_mouse_pointer(")]
|
||||
menu = (ROOT / "host/oot_menu.c").read_text(encoding="utf-8")
|
||||
windows, other = menu.split("#else\n/* Not Windows:", 1)
|
||||
assert "oot_menu_screen_tick(peek64(screen));" in windows and "oot_menu_screen_tick(vt);" in other, \
|
||||
"host/oot_menu.c: a half does not tell the menu screens' classes"
|
||||
for name, value in (("OPTIONS_SCREEN_VTABLE", "0x84c0f108ULL"),):
|
||||
assert f"#define {name} {value}" in menu, "host/oot_menu.c: the Options screen's class is another"
|
||||
bench = (ROOT / "host/hos_bench.c").read_text(encoding="utf-8")
|
||||
assert "#define FILES_VT 0x84c0eba0ULL" in bench and "#define FILE_BOX_VT 0x84c0f840ULL" in bench and \
|
||||
"#define TITLE_VT 0x84c106e8ULL" in bench, "host/hos_bench.c: the start's screens' classes are others"
|
||||
assert " 0x84c04fb0ULL, /* the pause and system menus' background */" in (ROOT / "host/oot_wide_hud.h").read_text(encoding="utf-8"), \
|
||||
"host/oot_wide_hud.h: the system menus' backdrop's class is another"
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
source = Path(tmp, "geometry.cpp")
|
||||
source.write_text(SOURCE.replace("MOVIE_SITE", oot_wide.MOVIE).replace("VIEWPORT_SITE", oot_wide.THUMB).replace("BACKEND_SITES", sites))
|
||||
exe = Path(tmp, "geometry.exe")
|
||||
host = ROOT / "host"
|
||||
obj = Path(tmp, "movie.o")
|
||||
includes = [] if os.name == "nt" else ["-I", str(host / "posix")]
|
||||
subprocess.run([args.cxx, "-x", "c", *includes, "-c", str(host / "oot_title_movie.c"),
|
||||
"-o", str(obj)], check=True)
|
||||
subprocess.run([args.cxx, "-I", str(host), str(source), str(obj), "-pthread", "-o", str(exe)], check=True)
|
||||
env = os.environ.copy()
|
||||
env.pop("HOS_WIDE_KEEP", None)
|
||||
subprocess.run([str(exe)], env=env, check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -26,6 +26,7 @@ FIXTURE = r"""
|
||||
#include <string.h>
|
||||
typedef struct { uint64_t x[32]; } Ctx;
|
||||
volatile float hos_wide_ratio;
|
||||
int hos_movie_cover_viewport(uint64_t *y, uint64_t *h) { (void)y; (void)h; return 0; } /* no movie drew */
|
||||
#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); exit(1); } } while (0)
|
||||
static void site(Ctx *c) {
|
||||
SITE_C
|
||||
|
||||
@@ -78,6 +78,7 @@ struct Host { int (*binding)(int set, int i, int k); };
|
||||
const Host host_v{[](int set, int i, int k) { return binds[set][i][k]; }};
|
||||
const Host* host = &host_v;
|
||||
bool can_bind() { return true; }
|
||||
struct { unsigned w, h; } remembered_custom{};
|
||||
std::string mic_want;
|
||||
std::string the_path;
|
||||
std::string ini_path() { return the_path; }
|
||||
@@ -128,6 +129,8 @@ int main(int argc, char** argv) {
|
||||
const std::string key = colon == std::string::npos ? "" : step.substr(colon + 1, eq - colon - 1);
|
||||
const std::string value = eq == std::string::npos ? "" : step.substr(eq + 1);
|
||||
if (what == "load") load();
|
||||
else if (what == "remember") remembered_custom = {3437, 1440};
|
||||
else if (what == "clear") remembered_custom = {};
|
||||
else if (what == "save") save();
|
||||
else if (what == "outside") outside(key, value);
|
||||
else if (what == "game") {
|
||||
@@ -194,6 +197,12 @@ def main():
|
||||
return lines(path)
|
||||
|
||||
start = "alpha=1\nbeta=1\ngamma=1\noptions_version=6\ndiscord_app_id=42\npad_a=3\nkey_a=65,0\nkey_up=87,0\n"
|
||||
key = "output_custom_size"
|
||||
check(key not in run("absent", start, ["load", "save", "save"]), "no empty Custom line added")
|
||||
check(run("remember", start, ["load", "remember", "save"]).get(key) == "3437x1440", "entered Custom written")
|
||||
check(run("clear", start, ["load", "remember", "save", "clear", "save"]).get(key) == "", "existing Custom cleared")
|
||||
check(run("external", start, ["load", "outside:output_custom_size=800x600", "save", "save"]).get(key) == "800x600",
|
||||
"Custom added outside survives unrelated saves")
|
||||
got = run("both", start, ["load", "outside:beta=7", "game:alpha=2", "save"])
|
||||
check(got.get("alpha") == "2" and got.get("beta") == "7",
|
||||
"a row changed outside and another in the game within a second: both survive (%s)" % got)
|
||||
|
||||
58
tests/test_output_migration.py
Normal file
58
tests/test_output_migration.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Keep stock 0.6 and native 0.5.2 options distinct despite their shared version 8."""
|
||||
import argparse
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--cxx", default="clang++")
|
||||
args = parser.parse_args()
|
||||
source = r'''
|
||||
#include "gpu/vk/output_sizes.h"
|
||||
#include "gpu/vk/merged_rows.h"
|
||||
#include <cassert>
|
||||
int main() {
|
||||
static_assert(OUTPUT_SCREEN == 8 && OUTPUT_CUSTOM == 9);
|
||||
static_assert(OUTPUT_OPTIONS_VERSION == 9);
|
||||
// Stock 0.6's handheld, and fixed sizes with a different aspect row.
|
||||
assert(output_file_read(7, 8, 2, 0) == 7);
|
||||
assert(output_file_read(4, 8, 2, 0) == 1);
|
||||
assert(output_file_read(6, 8, 3, 0) == 2);
|
||||
// Native files always wrote size fields, including under fixed choices.
|
||||
assert(output_file_read(7, 8, 2, 1) == OUTPUT_SCREEN);
|
||||
assert(output_file_read(8, 8, 2, 1) == OUTPUT_CUSTOM);
|
||||
assert(output_file_read(4, 8, 2, 1) == 4);
|
||||
assert(output_file_read(6, 8, 3, 1) == 6);
|
||||
assert(output_file_read(7, 7, 2, 0) == OUTPUT_SCREEN);
|
||||
assert(output_file_read(8, 7, 2, 0) == OUTPUT_CUSTOM);
|
||||
for (int v = 0; v <= OUTPUT_LAST; ++v)
|
||||
for (int row = 0; row != 4; ++row)
|
||||
assert(output_file_read(v, 9, row, 1) == v);
|
||||
// The player's active pair remains the native 12:5 picture.
|
||||
unsigned w, h;
|
||||
assert(output_size_used(3840, 1600, &w, &h));
|
||||
assert(w == 3840 && h == 1600 && output_frame_width(h) == 2848);
|
||||
// Native v8 predates stock's merged rows: retain handheld and stick meaning.
|
||||
mkwvk::merged_rows::Before7 old;
|
||||
old.handheld = 1; old.stick_shared = 3;
|
||||
int out = OUTPUT_CUSTOM, left = -1, right = 30;
|
||||
mkwvk::merged_rows::migrate(7, old, out, left, right);
|
||||
assert(out == 7 && left == 15 && right == 30);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
cpp = Path(tmp) / "migration.cpp"
|
||||
exe = Path(tmp) / "migration.exe"
|
||||
cpp.write_text(source, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++17", "-I", str(ROOT), str(cpp), "-o", str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True)
|
||||
print("PASS: stock/native migration and version-9 round trip")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,4 +1,18 @@
|
||||
"""Exercise the host and menu's docked output sizes without a game dump."""
|
||||
"""Exercise the host and menu's docked output sizes without a game dump.
|
||||
|
||||
The rule (gpu/vk/output_sizes.h): the Output resolution is the picture's size, the game's frame 16:9 at its height. A size
|
||||
that is not 16:9 (5120x1440, 5120x2160, a screen's or a Custom one of such a shape) is a picture of exactly that size,
|
||||
whatever the Ultrawide row says; a 16:9 size takes the row's shape.
|
||||
|
||||
The row offers the fixed sizes and the size of every connected screen, by the monitor's name. A screen's size is saved as
|
||||
a size (Custom's, output_width= and output_height=), never as a place in the list of screens: the same options file gives
|
||||
the same picture whichever screens are connected, in whatever order, and a size whose screen is gone is Custom. An old
|
||||
file's output_res=7 (Screen) is the screen the window opens on, as it was, and the menu keeps it as that size.
|
||||
|
||||
host/nn_applet.c's own code (the size, the frame, the shape, the render target pool) and gpu/vk/vk_menu.cpp's (the row's
|
||||
choices, their texts and order, the picture shown), cut out and run on the same options file and the same screens, must
|
||||
agree.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
@@ -9,6 +23,49 @@ RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
FIXED = ((2048, 1152), (2560, 1440), (3840, 2160), (1920, 1080), (5120, 1440), (5120, 2880), (5120, 2160), (1536, 864))
|
||||
|
||||
|
||||
def size(text):
|
||||
"""'3840x1600' as (w, h)"""
|
||||
w, h = text.split("x")
|
||||
return int(w), int(h)
|
||||
|
||||
|
||||
def names(screens, at):
|
||||
"""The screens of a size by name: once each, counted where several share one; one without a name is 'Screen'"""
|
||||
seen = []
|
||||
for used, name in screens:
|
||||
if size(used) == at:
|
||||
seen.append(name or "Screen")
|
||||
return ", ".join(("%dx " % seen.count(n) if seen.count(n) > 1 else "") + n for n in dict.fromkeys(seen))
|
||||
|
||||
|
||||
def row_labels(screens, custom, env=False, legacy=None, remembered=None):
|
||||
"""The row's choices in its order, by this file's own rule: the fixed sizes (a screen of one of them named there, but not
|
||||
at the game's own 2048x1152), each other screen size once, the old Screen while it is still chosen, and Custom unless a
|
||||
screen has its size. Smallest to largest by width then height, of one size in that order, one with no size at the end.
|
||||
screens: (the size the game takes it at, name); custom: its size, None for none; legacy: the old Screen's size or ''"""
|
||||
entries = []
|
||||
for v, at in enumerate(FIXED):
|
||||
who = "handheld" if v == 7 else names(screens, at) if v else ""
|
||||
entries.append((at, "%dx%d" % at + (" (%s)" % who if who else "")))
|
||||
own = []
|
||||
for used, _ in screens:
|
||||
if not env and size(used) not in FIXED[1:7] and size(used) not in own:
|
||||
own.append(size(used))
|
||||
entries.append((size(used), "%s (%s)" % (used, names(screens, size(used)))))
|
||||
if legacy is not None:
|
||||
who = names(screens, size(legacy)) if legacy else ""
|
||||
entries.append((size(legacy) if legacy else None, ("%s (%s)" % (legacy, who) if who else "Screen (%s)" % legacy) if legacy
|
||||
else "Screen (not known)"))
|
||||
if custom is None or size(custom) not in own:
|
||||
entries.append((size(custom) if custom else None, "Custom (%s)" % (custom or "not set")))
|
||||
if remembered and remembered != custom and size(remembered) not in own:
|
||||
entries.append((size(remembered), "Custom (%s)" % remembered))
|
||||
entries.sort(key=lambda e: (e[0] is None, e[0] or (0, 0))) # (stable: of one size as added)
|
||||
return "|".join(label for _, label in entries)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
@@ -17,22 +74,117 @@ def main():
|
||||
|
||||
host = (ROOT / "host/nn_applet.c").read_text(encoding="utf-8")
|
||||
menu = (ROOT / "gpu/vk/vk_menu.cpp").read_text(encoding="utf-8")
|
||||
|
||||
def check(cond, what):
|
||||
if not cond:
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
# the Custom size's rows: output_width= and output_height= by their names, with a restart, shown while Custom or a screen's
|
||||
# size is chosen, fixed while HOS_OUTPUT_SIZE sets the size; the file's version says that the 5120-wide sizes are pictures
|
||||
for name, value, lo, hi in (("Output width", "output_width", "OUTPUT_MIN_W", "OUTPUT_MAX_W"),
|
||||
("Output height", "output_height", "OUTPUT_MIN_H", "OUTPUT_MAX_H")):
|
||||
row = menu.find('{TAB_DISPLAY, "%s", &opts.%s, %s, %s, 8, ' % (name, value, lo, hi))
|
||||
check(row > menu.find('{TAB_DISPLAY, "Output resolution", &opts.output_res') > 0, "the menu has no %s row under Output resolution" % name)
|
||||
check(menu[row:menu.index("},", row)].rstrip().endswith("nullptr, true"), "the %s row is not read at the start (a restart)" % name)
|
||||
shown = menu[menu.index("bool row_shown(int i) {"):menu.index("\n}\n", menu.index("bool row_shown(int i) {"))]
|
||||
check("((rows[i].value != &opts.output_width && rows[i].value != &opts.output_height) ||" in shown
|
||||
and "output_choice(opts.output_res) == OUTPUT_CUSTOM) &&" in shown, "the Custom size's rows show without Custom chosen")
|
||||
check("if ((value == &opts.output_width || value == &opts.output_height) && custom_env()) return true;" in menu,
|
||||
"the Custom size's rows can be changed while HOS_OUTPUT_SIZE sets the size")
|
||||
check('out += "options_version=9\\n";' in menu, "the options file is not written as version 8 (output_sizes.h OUTPUT_OPTIONS_VERSION)")
|
||||
check("#define OUTPUT_OPTIONS_VERSION 9" in (ROOT / "gpu/vk/output_sizes.h").read_text(encoding="utf-8"),
|
||||
"output_sizes.h: the 5120-wide sizes are not pictures from options_version 8")
|
||||
check("rows[i].name != kUseWindowSize || (opts.output_res == OUTPUT_CUSTOM && !custom_env())" in shown
|
||||
and "use_window_size(dev.swap_extent.width, dev.swap_extent.height);" in menu,
|
||||
"the Custom copy action must use the drawable size and respect the environment override")
|
||||
# the row walks its choices, a screen's size among them, and menu_init takes the screens and an old file's Screen
|
||||
check('custom_rows_read(side("output_width"), side("output_height"));' in menu[menu.index("void menu_init() {"):],
|
||||
"menu_init does not read Custom's size from the file's own two numbers (custom_rows_read)")
|
||||
sizes_h = (ROOT / "gpu/vk/output_sizes.h").read_text(encoding="utf-8")
|
||||
used = sizes_h[sizes_h.index("static inline int output_size_used("):sizes_h.index("/* output_width= and output_height= as an options file")]
|
||||
check("output_width_range(uh, wide, &lo, &hi);" in used and "for (" not in used and "while (" not in used,
|
||||
"output_sizes.h: output_size_used does not choose the width in one step from the widths its height allows")
|
||||
check("output_custom_read(&w, &h);" in host, "nn_applet.c does not read Custom's size as the menu does (output_custom_read)")
|
||||
check("if (!output_step(dir, true)) return;" in menu[menu.index("void set_row(Row& r, int v, int dir, bool keep"):],
|
||||
"set_row does not walk the Output resolution row's choices (output_step)")
|
||||
init = menu[menu.index("void menu_init() {"):]
|
||||
check("screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0);" in init and
|
||||
init.index("output_adopt_screen();") > init.index("screen_add(list[i].w"), "menu_init does not take the host's screens, then an old file's Screen")
|
||||
# (walking the row past a screen's size leaves that size in the Custom rows: no restart is asked for them under a fixed size)
|
||||
check("restart_inert(rows[i]) ? restart_state.start[restart_slot[i]] : restart_value_of(rows[i])" in menu,
|
||||
"the Custom size's rows ask for a restart while a fixed size is chosen")
|
||||
# the screens go from the host to the menu through MkwVkHost, at its end (the interface's version with it)
|
||||
api = (ROOT / "gpu/vk/vk_api.h").read_text(encoding="utf-8")
|
||||
check(" int (*screens)(MkwVkScreen *out, int cap);\n" in api and api.index("int (*screens)(") > api.index("int (*bench)("),
|
||||
"vk_api.h: MkwVkHost has no screens after bench")
|
||||
backend = (ROOT / "host/rx_backend.c").read_text(encoding="utf-8")
|
||||
check("host_romfs_dir, host_wide_menus, hos_bench_state, hos_prompts_pad_face, host_screens, " in backend,
|
||||
"rx_backend.c does not give the menu the host's screens")
|
||||
|
||||
fixture = r'''
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gpu/vk/output_sizes.h"
|
||||
#include "gpu/vk/ultrawide_rows.h"
|
||||
#include "host/hos_screens.h"
|
||||
|
||||
using DWORD = unsigned long;
|
||||
constexpr int MAX_PATH = 260;
|
||||
constexpr int SM_CXSCREEN = 0, SM_CYSCREEN = 1;
|
||||
// (the connected screens: TEST_SCREENS=<w>x<h>=<name>;..., a '*' before the size of the one the window opens on, else the
|
||||
// first; none set: no screen known)
|
||||
int hos_screens(HosScreen *out, int cap) {
|
||||
const char *e = getenv("TEST_SCREENS");
|
||||
int n = 0, opens = -1;
|
||||
std::string all = e ? e : "";
|
||||
while (!all.empty() && n < cap) {
|
||||
std::string one = all.substr(0, all.find(';'));
|
||||
all = all.find(';') == std::string::npos ? "" : all.substr(all.find(';') + 1);
|
||||
const bool star = one[0] == '*';
|
||||
if (star) one = one.substr(1), opens = n;
|
||||
long w = 0, h = 0;
|
||||
if (!output_parse_size(one.substr(0, one.find('=')).c_str(), &w, &h)) abort();
|
||||
out[n] = HosScreen{(int)w, (int)h, 0, {}};
|
||||
snprintf(out[n].name, sizeof out[n].name, "%s", one.find('=') == std::string::npos ? "" : one.substr(one.find('=') + 1).c_str());
|
||||
n++;
|
||||
}
|
||||
if (n) out[opens < 0 ? 0 : opens].opens = 1;
|
||||
return n;
|
||||
}
|
||||
void hos_screen_size(int *w, int *h) { // (host/display.c: the one the window opens on)
|
||||
HosScreen list[16];
|
||||
const int n = hos_screens(list, 16);
|
||||
*w = *h = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (list[i].opens) *w = list[i].w, *h = list[i].h;
|
||||
}
|
||||
int GetSystemMetrics(int i) { // (the main monitor, for an old file's Monitor's shape: the first screen)
|
||||
HosScreen list[16];
|
||||
return hos_screens(list, 16) ? (i == SM_CYSCREEN ? list[0].h : list[0].w) : 0;
|
||||
}
|
||||
DWORD hos_game_path_a(char *path, int size) { return snprintf(path, size, "./hookshot.exe"); }
|
||||
void hos_log(const char *, ...) {}
|
||||
#include <cstdarg>
|
||||
static std::string logged; // (the host's log lines of the run, each ended)
|
||||
void hos_log(const char *format, ...) {
|
||||
char line[600];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(line, sizeof line, format, args);
|
||||
va_end(args);
|
||||
logged += line, logged += '\n';
|
||||
}
|
||||
volatile uint64_t hos_wide_out = 0; // (host/hos_main.c: the widescreen picture, 0 = none; nn_applet.c reads it)
|
||||
int hos_scene_rgba16f(void) { return 0; } // (host/nn_vi.c: the scene's colour target, the game's own here; tests/test_rt_pool_minimum.py has the RGBA16F cases)
|
||||
struct { int handheld, output_res; } opts;
|
||||
struct { int handheld, output_res, output_width, output_height, ultrawide; } opts;
|
||||
namespace mkwvk {
|
||||
int up_now = 0; // (the Upscaler shown: 0 the game's own, 1 DLSS, 2 DLAA)
|
||||
int upscaler() { return up_now; }
|
||||
@@ -41,83 +193,401 @@ int upscaler() { return up_now; }
|
||||
#include "gpu/vk/merged_rows.h" // ((Triforce, options_version 7) the Output resolution's handheld profile, 7)
|
||||
using namespace mkwvk;
|
||||
namespace ur = upscaler_rows;
|
||||
#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); failed = 1; } } while (0)
|
||||
#define CHECK_STR(got, want) do { const std::string g_ = (got), w_ = (want); if (g_ != w_) { \
|
||||
fprintf(stderr, "FAIL:%d %s is \"%s\", expected \"%s\"\n", __LINE__, #got, g_.c_str(), w_.c_str()); failed = 1; } } while (0)
|
||||
static int failed;
|
||||
static std::string wxh(unsigned w, unsigned h) { return std::to_string(w) + "x" + std::to_string(h); }
|
||||
// (the second build: the menu's code as it is off Windows, whatever this PC is. After every system header)
|
||||
#ifdef FIXTURE_OFF_WINDOWS
|
||||
#undef _WIN32
|
||||
#endif
|
||||
''' + host[host.index("int hos_ini_option(const char *key, int otherwise);"):host.index("HLE(_ZN2nn2oe16GetOperationModeEv)")] + menu[
|
||||
menu.index("struct Out {"):menu.index("/// The Render resolution: the value chosen")] + menu[
|
||||
menu.index("const char* tx_output_res("):menu.index("const char* tx_speed(")] + r'''
|
||||
menu.index("const char* tx_output_res("):menu.index("const char* tx_speed(")] + menu[
|
||||
menu.index("const char* tx_ultrawide(int v) {"):menu.index("const char* tx_wide_hud(")] + r'''
|
||||
struct Row { int* value; };
|
||||
Row rows[] = {{&opts.output_width}, {&opts.output_height}};
|
||||
static int saves;
|
||||
void save() { ++saves; }
|
||||
void set_row(Row& row, int value, int, bool keep) { *row.value = value; if (keep) save(); }
|
||||
''' + menu[menu.index("void use_window_size("):menu.index("// ---- (hookshot) the Controls page:")] + r'''
|
||||
static std::string labels() {
|
||||
std::string all;
|
||||
for (const OutEntry& x : output_entries()) all += (all.empty() ? "" : "|") + output_label(x);
|
||||
return all;
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 5);
|
||||
assert(argc == 10);
|
||||
const int mode = atoi(argv[1]);
|
||||
const unsigned w = atoi(argv[2]), h = atoi(argv[3]);
|
||||
assert(output_mode() == mode);
|
||||
assert(hos_output_size(0) == w && hos_output_size(1) == h);
|
||||
assert(hos_rt_pool_size(305ull << 20) == ((mode == 2 ? 687ull : mode == 4 ? 610ull : mode == 5 || mode == 6 ? 900ull : 512ull) << 20)); // (512 MB at least: nn_applet.c)
|
||||
// ((Triforce, options_version 7) 7 is 1536x864, the handheld profile, the smallest: first in the row)
|
||||
assert(kLastOutput == 7 && merged_rows::kHandheldOutput == 7);
|
||||
assert(output_choice(-1) == 0 && output_choice(4) == 4 && output_choice(5) == 5 && output_choice(6) == 6 && output_choice(7) == 7 &&
|
||||
output_choice(8) == 0);
|
||||
assert(step_output_choice(7, -1) == 7 && step_output_choice(7, 1) == 3 && step_output_choice(3, -1) == 7);
|
||||
assert(strcmp(tx_output_res(7), "1536x864 (handheld)") == 0);
|
||||
assert(step_output_choice(3, 1) == 0 && step_output_choice(0, -1) == 3);
|
||||
assert(step_output_choice(0, 1) == 1 && step_output_choice(1, -1) == 0);
|
||||
assert(step_output_choice(1, 1) == 2 && step_output_choice(2, -1) == 1);
|
||||
assert(step_output_choice(2, 1) == 4);
|
||||
assert(step_output_choice(4, -1) == 2 && step_output_choice(4, 1) == 6); // ((Triforce) 5120x2160 between 5120x1440 and 5120x2880)
|
||||
assert(step_output_choice(6, -1) == 4 && step_output_choice(6, 1) == 5);
|
||||
assert(step_output_choice(5, -1) == 6 && step_output_choice(5, 1) == 5);
|
||||
opts.output_res = mode;
|
||||
// ---- the host: the size chosen, the game's frame, the size's own shape
|
||||
CHECK(output_mode() == mode);
|
||||
CHECK_STR(wxh(hos_output_size(0), hos_output_size(1)), argv[2]);
|
||||
CHECK_STR(std::to_string((int)(hos_output_ratio() * 10000.0f + 0.5f)), argv[5]);
|
||||
// (the picture as host/hos_main.c makes it: the size's own shape, else the Ultrawide row's; tests/test_ultrawide_shapes.py
|
||||
// runs that block itself)
|
||||
const int version = hos_ini_option("options_version", 0);
|
||||
const int row = ultrawide_row_read(hos_ini_option("ultrawide", 0), version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
|
||||
unsigned pw = 0, ph = 0;
|
||||
const float own = hos_output_ratio();
|
||||
if (output_picture(hos_output_size(1), own > 0.0f ? own : ultrawide_row_ratio(row), own > 0.0f, &pw, &ph))
|
||||
hos_wide_out = (uint64_t)ph << 32 | pw;
|
||||
const std::string picture = pw ? wxh(pw, ph) : std::string(mode ? argv[2] : "2048x1152");
|
||||
if (mode) CHECK_STR(picture, argv[8]);
|
||||
CHECK_STR(std::to_string(hos_rt_pool_size(305ull << 20) >> 20), argv[4]); // (512 MB at least: nn_applet.c)
|
||||
// (TEST_LOG pins the explanation of an older file's migrated choice or picture)
|
||||
if (const char* want = getenv("TEST_LOG")) {
|
||||
if (logged.find(want) == std::string::npos) fprintf(stderr, "FAIL: the log has no \"%s\":\n%s", want, logged.c_str()), failed = 1;
|
||||
}
|
||||
|
||||
// ---- the menu, as menu_init has it from the same file and the same screens
|
||||
opts.handheld = handheld();
|
||||
assert(strcmp(tx_output_res(mode), argv[4]) == 0);
|
||||
if (opts.handheld) opts.output_res = 7; // (the menu's row: the handheld profile, as menu_init reads it, merged_rows.h migrate)
|
||||
// (Custom's rows from the file's own two numbers, 0 with no line: menu_init)
|
||||
custom_rows_read(hos_ini_option("output_width", 0), hos_ini_option("output_height", 0));
|
||||
HosScreen list[16];
|
||||
const int n = hos_screens(list, 16);
|
||||
for (int i = 0; i < n; i++) screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0);
|
||||
// (an old file's Ultrawide row by the main monitor, the host's on every system: main_screen)
|
||||
opts.ultrawide = ultrawide_row_read(std::min(std::max(hos_ini_option("ultrawide", 0), 0), 3), version, (int)main_screen().w, (int)main_screen().h);
|
||||
CHECK(opts.ultrawide == std::min(std::max(row, 0), 3));
|
||||
opts.output_res = output_file_read(hos_ini_option("output_res", 0), version, opts.ultrawide, output_size_fields());
|
||||
if (const char* e = getenv("HOS_OUTPUT_RES")) opts.output_res = output_choice(atoi(e));
|
||||
if (opts.handheld) opts.output_res = 7;
|
||||
output_adopt_screen();
|
||||
CHECK(kLastOutput == 9);
|
||||
CHECK(output_choice(-1) == 0 && output_choice(4) == 4 && output_choice(6) == 6 && output_choice(7) == 7 && output_choice(8) == 8 && output_choice(9) == 9 && output_choice(10) == 0);
|
||||
// (the row's choices, smallest to largest: the fixed sizes, the screens' among them by name, Custom; and the one chosen)
|
||||
CHECK_STR(labels(), argv[6]);
|
||||
CHECK_STR(tx_output_res(opts.output_res), argv[3]);
|
||||
// (the menu's choice runs what the host runs: its frame and its picture, the Render resolution's 100%)
|
||||
if (!opts.handheld) {
|
||||
CHECK_STR(wxh(output_frame(opts.output_res).w, output_frame(opts.output_res).h), mode ? argv[2] : "2048x1152");
|
||||
CHECK(output_shaped(opts.output_res) == (own > 0.0f));
|
||||
}
|
||||
unsigned scene_w, scene_h;
|
||||
game_size(1.0f, scene_w, scene_h);
|
||||
assert(scene_w == (opts.handheld ? 1536 : mode ? w : 2048));
|
||||
assert(scene_h == (opts.handheld ? 864 : mode ? h : 1152));
|
||||
if (mode == 3) assert(strcmp(tx_resolution(2), "75% (1440x810)") == 0);
|
||||
if (mode == 3) { // (DLSS at 1080p: its modes' render sizes, each a twelfth of the output, exact; DLAA the full size)
|
||||
CHECK_STR(wxh(scene_w, scene_h), argv[8]);
|
||||
CHECK_STR(tx_shape(opts.ultrawide), argv[7]); // (the Ultrawide row: its choice, or the size's own shape)
|
||||
CHECK(shape_owner() == (own > 0.0f ? 1 : 0));
|
||||
// (the Custom rows: their sides as chosen, HOS_OUTPUT_SIZE's while it is set; the size the game makes of them is the row's)
|
||||
CHECK_STR(std::string(tx_custom_width(opts.output_width)) + "x" + tx_custom_height(opts.output_height), argv[9]);
|
||||
if (mode == 3 && !pw) CHECK_STR(tx_resolution(2), "75% (1440x810)");
|
||||
if (mode == 3 && !pw) { // (DLSS at 1080p: its modes' render sizes, each a twelfth of the output, exact; DLAA the full size)
|
||||
up_now = ur::DLSS;
|
||||
assert(strcmp(tx_resolution(3), "Quality (67%)") == 0 && strcmp(tx_resolution(6), "Ultra Performance (33%)") == 0);
|
||||
CHECK(strcmp(tx_resolution(3), "Quality (67%)") == 0 && strcmp(tx_resolution(6), "Ultra Performance (33%)") == 0);
|
||||
const unsigned want[][3] = {{3, 1280, 720}, {5, 1120, 630}, {4, 960, 540}, {6, 640, 360}};
|
||||
for (const auto& m : want) {
|
||||
game_size(ur::percent(m[0]) / 100.0f, scene_w, scene_h);
|
||||
assert(scene_w == m[1] && scene_h == m[2] && scene_w * 1080 == scene_h * 1920);
|
||||
CHECK(scene_w == m[1] && scene_h == m[2] && scene_w * 1080 == scene_h * 1920);
|
||||
}
|
||||
up_now = ur::DLAA; // ((Triforce, options_version 7) the Render resolution's Native (100%) step)
|
||||
assert(strcmp(tx_resolution(1), "Native (100%)") == 0);
|
||||
CHECK(strcmp(tx_resolution(1), "Native (100%)") == 0);
|
||||
up_now = ur::GAME;
|
||||
}
|
||||
if (pw == 3840 && ph == 1600) CHECK_STR(tx_resolution(2), "75% (2880x1200)"); // (the 3D's size is the picture's share)
|
||||
|
||||
// ---- a size from outside keeps its shape (5:4 to 32:9) whatever its sides, stays within every limit and on its side of
|
||||
// 16:9, and what comes out is taken as itself when given again (the menu saves it and the host reads it back): at once,
|
||||
// by how its width is chosen (output_width_range), with no second try
|
||||
for (long w = 200; w <= 12000; w += 61)
|
||||
for (long h = 120; h <= 6000; h += 37) {
|
||||
unsigned uw = 0, uh = 0, vw = 0, vh = 0;
|
||||
CHECK(output_size_used(w, h, &uw, &uh) && output_size_used(uw, uh, &vw, &vh));
|
||||
const double in = std::min(std::max((double)w / h, OUTPUT_SHAPE_MIN), OUTPUT_SHAPE_MAX), out = (double)uw / uh;
|
||||
const bool side = output_shape_is_game(in) ? output_shape_is_game(out)
|
||||
: !output_shape_is_game(out) && (in > 16.0 / 9.0) == (out > 16.0 / 9.0);
|
||||
if (uw != vw || uh != vh || uw % 8 || uw < OUTPUT_MIN_W || uw > OUTPUT_MAX_W || uh < OUTPUT_MIN_H || uh > OUTPUT_MAX_H ||
|
||||
(double)uw * uh > OUTPUT_MAX_PIXELS || std::fabs(out / in - 1.0) > 0.011 || // (8 pixels of width, or 16:9's 1%)
|
||||
out > OUTPUT_SHAPE_MAX || out < OUTPUT_SHAPE_MIN || !side) {
|
||||
fprintf(stderr, "FAIL: %ldx%ld is taken as %ux%u (again: %ux%u)\n", w, h, uw, uh, vw, vh);
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned uw = 0, uh = 0;
|
||||
CHECK(output_size_used(7680, 4320, &uw, &uh) && uw == 5120 && uh == 2880); // (not 7680x2880's 2.67:1)
|
||||
CHECK(output_size_used(3840, 1600, &uw, &uh) && uw == 3840 && uh == 1600);
|
||||
CHECK(!output_size_used(0, 1440, &uw, &uh) && !output_size_used(2560, -1, &uw, &uh));
|
||||
}
|
||||
|
||||
// ---- walking the row: each step is the next choice of the row as it is then, to both ends; a screen's size is taken as
|
||||
// Custom's size (a size, not a place among the screens), a fixed size as its number
|
||||
for (int dir = -1; dir <= 1; dir += 2) {
|
||||
for (int guard = 0; guard < 64; guard++) {
|
||||
const std::vector<OutEntry> before = output_entries();
|
||||
const int at = output_entry_now(before);
|
||||
CHECK(output_step(dir, false) == (dir < 0 ? at > 0 : at + 1 < (int)before.size()));
|
||||
if (!output_step(dir, true)) break;
|
||||
const OutEntry& to = before[at + dir];
|
||||
CHECK_STR(tx_output_res(opts.output_res), output_label(to));
|
||||
CHECK(opts.output_res == to.id);
|
||||
if (to.native.h) {
|
||||
CHECK(opts.output_res == OUTPUT_CUSTOM && custom_size().w == to.size.w && custom_size().h == to.size.h);
|
||||
// (saved as the game takes it: what the rows hold is the picture, and reads back as itself)
|
||||
CHECK(opts.output_width == (int)to.size.w && opts.output_height == (int)to.size.h);
|
||||
}
|
||||
}
|
||||
CHECK(!output_step(dir, false));
|
||||
}
|
||||
// A non-rounded input survives a screen selection, restart and unplug. The disconnected
|
||||
// picture continues to use the saved screen size until the player chooses Custom again.
|
||||
if (!custom_env()) {
|
||||
screens.clear();
|
||||
screen_add(3840, 1600, "Monitor", true);
|
||||
opts.output_res = OUTPUT_CUSTOM;
|
||||
remembered_custom = {};
|
||||
custom_rows_read(3437, 1440);
|
||||
CHECK(output_step(1, true));
|
||||
CHECK(opts.output_width == 3840 && opts.output_height == 1600);
|
||||
CHECK(remembered_custom.w == 3437 && remembered_custom.h == 1440);
|
||||
remembered_custom = {};
|
||||
opts.output_res = 2;
|
||||
read_remembered_custom("3437x1440");
|
||||
CHECK(remembered_custom.w == 3437 && remembered_custom.h == 1440);
|
||||
screens.clear();
|
||||
CHECK(labels().find("Custom (3840x1600)") == std::string::npos);
|
||||
CHECK(labels().find("Custom (3440x1440)") != std::string::npos);
|
||||
opts.output_res = OUTPUT_CUSTOM;
|
||||
screens.clear();
|
||||
CHECK_STR(tx_output_res(opts.output_res), "Custom (3840x1600)");
|
||||
CHECK(output_step(-1, true));
|
||||
CHECK(opts.output_width == 3437 && opts.output_height == 1440 && !remembered_custom.h);
|
||||
use_window_size(0, 1080);
|
||||
CHECK(!saves && opts.output_width == 3437 && opts.output_height == 1440);
|
||||
use_window_size(7680, 4320);
|
||||
CHECK(saves == 1 && opts.output_width == 5120 && opts.output_height == 2880);
|
||||
use_window_size(3840, 1600);
|
||||
CHECK(saves == 2 && opts.output_width == 3840 && opts.output_height == 1600);
|
||||
}
|
||||
return failed;
|
||||
}
|
||||
'''
|
||||
v8 = "options_version=9\n"
|
||||
lg, dell = "LG ULTRAGEAR", "DELL U2720Q"
|
||||
|
||||
def case(saved, mode, frame, now, pool, *, picture=None, shape=0, row="16:9", ini="", handheld=0, res=None, screens=(),
|
||||
env_size=None, custom="2560x1440", rows=None, legacy=None, log=None, remembered="2560x1440"):
|
||||
"""saved, handheld, HOS_OUTPUT_RES, the screens ((native size, name) or (native, name, the size the game takes it
|
||||
at), a '*' before the native size of the one the window opens on), the ini's other lines, HOS_OUTPUT_SIZE -> the
|
||||
host's mode and frame, the row's text now, the pool in MB, the size's own shape x 10000, the Ultrawide row's text,
|
||||
the picture, Custom's size as the game takes it (None: none), the Custom rows' texts, the old Screen still chosen,
|
||||
and an optional migration log expectation; remembered is Custom's saved size before adopting Screen"""
|
||||
# Cases retain the audited branch's numbering in their declarations.
|
||||
# Current fixtures use 8/9; old-version fixtures exercise migration from 7/8.
|
||||
old_screen = res == "7" or res is None and saved == 7
|
||||
if ini.startswith("options_version=9") and saved in (7, 8): saved += 1
|
||||
if mode in (7, 8): mode += 1
|
||||
if res in ("7", "8"): res = str(int(res) + 1)
|
||||
if handheld: now, custom = "1536x864 (handheld)", "2560x1440"
|
||||
used = [(s[2] if len(s) > 2 else s[0].lstrip("*"), s[1]) for s in screens]
|
||||
return (saved, handheld, res, ";".join(s[0] + ("=" + s[1] if s[1] else "") for s in screens), ini, env_size, mode, frame, now,
|
||||
pool, shape, row_labels(used, custom, env_size is not None, legacy,
|
||||
remembered if old_screen and not handheld and env_size is None
|
||||
and now.split(" (")[0] not in ("%dx%d" % f for f in FIXED[1:7]) and screens else None), row,
|
||||
picture or ("2048x1152" if mode == 0 else frame), rows or custom or "Not setxNot set", log)
|
||||
|
||||
cases = (
|
||||
(0, 0, None, 0, 2560, 1440, "2048x1152"),
|
||||
(1, 0, None, 1, 2560, 1440, "2560x1440"),
|
||||
(2, 0, None, 2, 3840, 2160, "3840x2160"),
|
||||
(3, 0, None, 3, 1920, 1080, "1920x1080"),
|
||||
(1, 0, "3", 3, 1920, 1080, "1920x1080"),
|
||||
(3, 1, "3", 0, 2560, 1440, "2048x1152"),
|
||||
(4, 1, None, 0, 2560, 1440, "2048x1152"),
|
||||
(7, 0, None, 0, 2560, 1440, "2048x1152"),
|
||||
(5, 0, None, 5, 5120, 2880, "5120x2880"),
|
||||
(4, 0, None, 4, 5120, 1440, "5120x1440"),
|
||||
(6, 0, None, 6, 5120, 2160, "5120x2160"),
|
||||
(1, 0, "6", 6, 5120, 2160, "5120x2160"),
|
||||
# ((Triforce, options_version 7) the handheld profile as the Output resolution's 7, saved or for a run)
|
||||
(1, 0, "7", 0, 2560, 1440, "2048x1152"),
|
||||
(8, 0, None, 0, 2560, 1440, "2048x1152"),
|
||||
# ---- the fixed 16:9 sizes: the game's frame, and its picture with Ultrawide on 16:9
|
||||
case(0, 0, "2560x1440", "2048x1152", 512, ini=v8),
|
||||
# A monitor at the handheld profile's size is still a docked Custom picture.
|
||||
case(7, 7, "1536x864", "1536x864 (Screen)", 512, ini=v8,
|
||||
screens=[("1536x864", "")], custom="1536x864"),
|
||||
case(1, 1, "2560x1440", "2560x1440", 512, ini=v8),
|
||||
case(2, 2, "3840x2160", "3840x2160", 687, ini=v8),
|
||||
case(3, 3, "1920x1080", "1920x1080", 512, ini=v8),
|
||||
case(1, 3, "1920x1080", "1920x1080", 512, ini=v8, res="3"),
|
||||
# (the handheld profile runs the game's own output; the row keeps the choice for docked)
|
||||
case(3, 0, "2560x1440", "1920x1080", 512, ini=v8, res="3", handheld=1, picture="1536x864"),
|
||||
case(4, 0, "2560x1440", "5120x1440", 512, ini=v8, handheld=1, picture="1536x864"),
|
||||
case(10, 0, "2560x1440", "2048x1152", 512, ini=v8),
|
||||
case(5, 5, "5120x2880", "5120x2880", 900, ini=v8),
|
||||
# (a 16:9 size takes the Ultrawide row's shape at its height: 21:9 is 64:27 in whole multiples of 8 pixels; at the 4K
|
||||
# output a 32:9 picture is kept to 3840x2160's pixels, as before)
|
||||
case(1, 1, "2560x1440", "2560x1440", 512, ini=v8 + "ultrawide=2\n", picture="3416x1440", row="21:9"),
|
||||
case(3, 3, "1920x1080", "1920x1080", 512, ini=v8 + "ultrawide=1\n", picture="1728x1080", row="16:10"),
|
||||
case(2, 2, "3840x2160", "3840x2160", 687, ini=v8 + "ultrawide=3\n", picture="5400x1520", row="32:9"),
|
||||
case(0, 0, "2560x1440", "2048x1152", 610, ini=v8 + "ultrawide=3\n", picture="4096x1152", row="32:9"),
|
||||
# ---- the fixed sizes that are not 16:9: the picture itself, the frame 16:9 at its height, whatever the row says
|
||||
case(4, 4, "2560x1440", "5120x1440", 610, ini=v8, picture="5120x1440", shape=35556, row="32:9 (5120x1440)"),
|
||||
case(6, 6, "3840x2160", "5120x2160", 900, ini=v8, picture="5120x2160", shape=23704, row="21:9 (5120x2160)"),
|
||||
case(1, 6, "3840x2160", "5120x2160", 900, ini=v8, res="6", picture="5120x2160", shape=23704, row="21:9 (5120x2160)"),
|
||||
case(4, 4, "2560x1440", "5120x1440", 610, ini=v8 + "ultrawide=2\n", picture="5120x1440", shape=35556,
|
||||
row="32:9 (5120x1440)"),
|
||||
# (a file from before options_version 8, where they were the game's frame: with the row on their own shape or on 16:9
|
||||
# they stay, the picture theirs; with the row on another shape the 16:9 size of their height, the same picture)
|
||||
case(4, 4, "2560x1440", "5120x1440", 610, ini="options_version=7\nultrawide=3\n", picture="5120x1440", shape=35556,
|
||||
row="32:9 (5120x1440)"),
|
||||
case(4, 4, "2560x1440", "5120x1440", 610, ini="options_version=7\n", picture="5120x1440", shape=35556,
|
||||
row="32:9 (5120x1440)"),
|
||||
case(4, 1, "2560x1440", "2560x1440", 512, ini="options_version=7\nultrawide=2\n", picture="3416x1440", row="21:9",
|
||||
log="oe: output resolution 5120x1440 with Ultrawide on another shape, from before options_version 9: "
|
||||
"2560x1440 now, the same picture"),
|
||||
case(6, 6, "3840x2160", "5120x2160", 900, ini="options_version=7\nultrawide=2\n", picture="5120x2160", shape=23704,
|
||||
row="21:9 (5120x2160)"),
|
||||
case(6, 2, "3840x2160", "3840x2160", 687, ini="options_version=7\nultrawide=3\n", picture="5400x1520", row="32:9"),
|
||||
case(6, 2, "3840x2160", "3840x2160", 687, ini="options_version=7\nultrawide=1\n", picture="3456x2160", row="16:10"),
|
||||
# (before options_version 6 the row's 1 was the monitor's shape: on a 5120x1440 monitor 32:9, 5120x1440's own; the
|
||||
# screen of a fixed size is named at that size)
|
||||
case(4, 4, "2560x1440", "5120x1440 (Screen)", 610, ini="options_version=5\nultrawide=1\n", screens=[("5120x1440", "")],
|
||||
picture="5120x1440", shape=35556, row="32:9 (5120x1440)"),
|
||||
# (the same row at a 16:9 size, on a 3440x1440 monitor: 21:9 for the host and for the menu, on every system)
|
||||
case(1, 1, "2560x1440", "2560x1440", 512, ini="options_version=5\nultrawide=1\n", screens=[("3440x1440", lg)],
|
||||
picture="3416x1440", row="21:9"),
|
||||
|
||||
# Stock 0.7 ignores the retired profile line at version 8; native 0.6's version 9 still carries it.
|
||||
case(1, 1, "2560x1440", "2560x1440", 512, ini="options_version=8\nhandheld_profile=1\n"),
|
||||
# Native 0.5.2's numbers move past stock 0.6's handheld without changing the choice or picture.
|
||||
case(8, 8, "2848x1600", "Custom (3840x1600)", 512,
|
||||
ini="options_version=8\noutput_width=3840\noutput_height=1600\n", picture="3840x1600", shape=24000,
|
||||
row="2.40:1 (3840x1600)", custom="3840x1600",
|
||||
log="oe: output resolution Custom (8) from native 0.5.2: now 9 under options_version 9, the same choice"),
|
||||
case(7, 7, "2848x1600", "3840x1600 (Screen)", 512,
|
||||
ini="options_version=8\noutput_width=3840\noutput_height=1600\n", screens=[("3840x1600", "")],
|
||||
picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600",
|
||||
log="oe: output resolution Screen (7) from native 0.5.2: now 8 under options_version 9, the same choice",
|
||||
remembered="3840x1600"),
|
||||
|
||||
# ---- the connected screens: each one's size is a choice, by its name; choosing it saves that size (Custom's)
|
||||
case(8, 8, "2848x1600", "3840x1600 (2x %s)" % lg, 512, ini=v8 + "output_width=3840\noutput_height=1600\n",
|
||||
screens=[("3840x1600", lg), ("3840x1600", lg), ("2560x1440", dell)], picture="3840x1600", shape=24000,
|
||||
row="2.40:1 (3840x1600)", custom="3840x1600"), # (two of one size: one choice; the 2560x1440 one names the fixed size)
|
||||
# (the same file with the screens in another order, with one of them gone, and with none: the same picture)
|
||||
case(8, 8, "2848x1600", "3840x1600 (2x %s)" % lg, 512, ini=v8 + "output_width=3840\noutput_height=1600\n",
|
||||
screens=[("2560x1440", dell), ("3840x1600", lg), ("3840x1600", lg)], picture="3840x1600", shape=24000,
|
||||
row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
case(8, 8, "2848x1600", "3840x1600 (%s)" % lg, 512, ini=v8 + "output_width=3840\noutput_height=1600\n",
|
||||
screens=[("3840x1600", lg)], picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
case(8, 8, "2848x1600", "Custom (3840x1600)", 512, ini=v8 + "output_width=3840\noutput_height=1600\n",
|
||||
screens=[("2560x1440", dell)], picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
case(8, 8, "2848x1600", "Custom (3840x1600)", 512, ini=v8 + "output_width=3840\noutput_height=1600\n",
|
||||
picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
# (screens of different names at one size, one with no name, and one whose size the game takes smaller)
|
||||
case(1, 1, "2560x1440", "2560x1440", 512, ini=v8,
|
||||
screens=[("3440x1440", dell), ("3440x1440", lg), ("1920x1200", ""), ("7680x2160", "Odyssey", "7224x2032")]),
|
||||
|
||||
# ---- an old file's Screen (output_res=7): the screen the window opens on, as it was; the menu keeps it as that size
|
||||
case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini=v8, screens=[("3840x1600", "")], picture="3840x1600", shape=24000,
|
||||
row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini=v8 + "ultrawide=2\n", screens=[("3840x1600", "")],
|
||||
picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"), # (not the row's 21:9, 3792x1600)
|
||||
case(7, 7, "2560x1440", "3440x1440 (%s)" % lg, 512, ini=v8, screens=[("3440x1440", lg)], picture="3440x1440", shape=23889,
|
||||
row="2.39:1 (3440x1440)", custom="3440x1440"),
|
||||
case(7, 7, "1920x1080", "2560x1080 (Screen)", 512, ini=v8, screens=[("2560x1080", "")], picture="2560x1080", shape=23704,
|
||||
row="21:9 (2560x1080)", custom="2560x1080"),
|
||||
# (an old-version file with Screen or Custom and an Ultrawide row still gets the size's own picture)
|
||||
case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini="options_version=7\nultrawide=2\n", screens=[("3840x1600", "")],
|
||||
picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini="options_version=7\noutput_width=3440\noutput_height=1440\nultrawide=3\n",
|
||||
picture="3440x1440", shape=23889, row="2.39:1 (3440x1440)", custom="3440x1440"),
|
||||
case(7, 7, "1920x1080", "2560x1080 (Screen)", 512, ini="options_version=7\nultrawide=2\n", screens=[("2560x1080", "")],
|
||||
picture="2560x1080", shape=23704, row="21:9 (2560x1080)", custom="2560x1080"),
|
||||
# (an old-version size above the pixel cap keeps its own shape when reduced)
|
||||
case(8, 8, "3616x2032", "Custom (7224x2032)", 900, ini="options_version=7\noutput_width=7680\noutput_height=2160\nultrawide=1\n",
|
||||
picture="7224x2032", shape=35551, row="32:9 (7224x2032)", custom="7224x2032", rows="7680x2160"),
|
||||
# (the one the window opens on, not the first of the list)
|
||||
case(7, 7, "2848x1600", "3840x1600 (%s)" % lg, 512, ini=v8, screens=[("2560x1440", dell), ("*3840x1600", lg)],
|
||||
picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="3840x1600"),
|
||||
# (a screen of a fixed size: that fixed choice, the same picture)
|
||||
case(7, 7, "2560x1440", "5120x1440 (Screen)", 610, ini=v8, screens=[("5120x1440", "")], picture="5120x1440", shape=35556,
|
||||
row="32:9 (5120x1440)"),
|
||||
case(7, 7, "3840x2160", "5120x2160 (Screen)", 900, ini=v8, screens=[("5120x2160", "")], picture="5120x2160", shape=23704,
|
||||
row="21:9 (5120x2160)"),
|
||||
case(7, 7, "2560x1440", "2560x1440 (Screen)", 512, ini=v8, screens=[("2560x1440", "")]),
|
||||
case(7, 7, "2560x1440", "2560x1440 (Screen)", 512, ini=v8 + "ultrawide=2\n", screens=[("2560x1440", "")],
|
||||
picture="3416x1440", row="21:9"),
|
||||
case(1, 7, "2136x1200", "1920x1200 (Screen)", 512, ini=v8, res="7", screens=[("1920x1200", "")], picture="1920x1200",
|
||||
shape=16000, row="16:10 (1920x1200)", custom="1920x1200"),
|
||||
case(7, 7, "1824x1024", "1280x1024 (Screen)", 512, ini=v8, screens=[("1280x1024", "")], picture="1280x1024", shape=12500,
|
||||
row="1.25:1 (1280x1024)", custom="1280x1024"),
|
||||
# (a 16:9 screen 1366 wide: the game's frame at its height; more pixels than 5120x2880's: smaller in its shape)
|
||||
# (saved as the size the game takes, which reads back as itself)
|
||||
case(7, 7, "1368x768", "1368x768 (Screen)", 512, ini=v8, screens=[("1366x768", "", "1368x768")], custom="1368x768"),
|
||||
case(7, 7, "3616x2032", "7224x2032 (Screen)", 900, ini=v8, screens=[("7680x2160", "", "7224x2032")], picture="7224x2032",
|
||||
shape=35551, row="32:9 (7224x2032)", custom="7224x2032"),
|
||||
# (a screen taller than 2880 keeps its shape: 7680x4320 is 16:9, the fixed 5120x2880, not 7680x2880's 2.67:1; a
|
||||
# 5120x3200 one stays 16:10)
|
||||
case(7, 7, "5120x2880", "5120x2880 (8K)", 900, ini=v8, screens=[("7680x4320", "8K", "5120x2880")]),
|
||||
case(7, 7, "5120x2880", "4608x2880 (Screen)", 900, ini=v8, screens=[("5120x3200", "", "4608x2880")], picture="4608x2880",
|
||||
shape=16000, row="16:10 (4608x2880)", custom="4608x2880"),
|
||||
case(7, 1, "2560x1440", "2560x1440", 512, ini=v8), # (no screen known: 2560x1440)
|
||||
case(7, 0, "2560x1440", "3840x1600 (Screen)", 512, ini=v8, handheld=1, screens=[("3840x1600", "")], picture="1536x864",
|
||||
custom="3840x1600"),
|
||||
# (HOS_OUTPUT_SIZE is Custom's size for the run: the old Screen stays what it is, and no screen's size can be chosen)
|
||||
case(7, 7, "2848x1600", "3840x1600 (Screen)", 512, ini=v8, screens=[("3840x1600", "")], env_size="1920x1080",
|
||||
picture="3840x1600", shape=24000, row="2.40:1 (3840x1600)", custom="1920x1080", legacy="3840x1600"),
|
||||
|
||||
# ---- Custom: the ini's size (the Output width and Output height rows), HOS_OUTPUT_SIZE over it
|
||||
case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini=v8 + "output_width=3440\noutput_height=1440\n",
|
||||
screens=[("3840x1600", "")], picture="3440x1440", shape=23889, row="2.39:1 (3440x1440)", custom="3440x1440"),
|
||||
case(8, 8, "1920x1080", "Custom (1920x1080)", 512, ini=v8 + "output_width=3440\noutput_height=1440\n",
|
||||
env_size="1920x1080", custom="1920x1080"),
|
||||
case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini=v8 + "output_width=3437\noutput_height=1440\n",
|
||||
picture="3440x1440", shape=23889, row="2.39:1 (3440x1440)", custom="3440x1440", rows="3437x1440"),
|
||||
# (a size past the limits keeps its shape and is made smaller or larger in it, for the host as for the menu, whose
|
||||
# rows then hold the size taken: 10000x5000 is 2:1 at 5120x2880's pixels, 100x100 the squarest picture, 5:4)
|
||||
case(8, 8, "4824x2712", "Custom (5424x2712)", 900, ini=v8 + "output_width=10000\noutput_height=5000\n",
|
||||
picture="5424x2712", shape=20000, row="2.00:1 (5424x2712)", custom="5424x2712"),
|
||||
case(8, 8, "5120x2880", "Custom (5120x2880)", 900, ini=v8 + "output_width=7680\noutput_height=4320\n",
|
||||
custom="5120x2880"),
|
||||
case(8, 8, "5120x2880", "Custom (5120x2880)", 900, ini=v8, env_size="7680x4320", custom="5120x2880", rows="7680x4320"),
|
||||
case(8, 8, "912x512", "Custom (640x512)", 512, ini=v8 + "output_width=100\noutput_height=100\n", picture="640x512",
|
||||
shape=12500, row="1.25:1 (640x512)", custom="640x512"),
|
||||
# (the rows' own ends, as the rows can be set: 7680x2880 is 8:3, at 5120x2880's pixels)
|
||||
case(8, 8, "4168x2344", "Custom (6248x2344)", 900, ini=v8 + "output_width=7680\noutput_height=2880\n",
|
||||
picture="6248x2344", shape=26655, row="2.67:1 (6248x2344)", custom="6248x2344", rows="7680x2880"),
|
||||
case(8, 8, "2560x1440", "Custom (2560x1440)", 512,
|
||||
ini=v8 + "output_width=0\noutput_height=-3\n"), # (a side that is not a size: the row's default)
|
||||
case(8, 8, "3840x2160", "Custom (5120x2160)", 900, ini=v8 + "output_width=5120\noutput_height=2160\n",
|
||||
picture="5120x2160", shape=23704, row="21:9 (5120x2160)", custom="5120x2160"),
|
||||
case(8, 8, "1920x1080", "Custom (3840x1080)", 512, ini=v8 + "output_width=7680\noutput_height=1080\n",
|
||||
picture="3840x1080", shape=35556, row="32:9 (3840x1080)", custom="3840x1080", rows="7680x1080"), # (32:9 at most)
|
||||
# (a 16:9 Custom takes the Ultrawide row's shape, as a fixed 16:9 size does)
|
||||
case(8, 8, "2560x1440", "Custom (2560x1440)", 610, ini=v8 + "output_width=2560\noutput_height=1440\nultrawide=3\n",
|
||||
picture="5120x1440", row="32:9"),
|
||||
# (no lines yet: the rows' defaults, 2560x1440, for the host as for the menu; one line: the other side's default)
|
||||
case(8, 8, "2560x1440", "Custom (2560x1440)", 512, ini=v8),
|
||||
case(8, 8, "2560x1440", "Custom (3440x1440)", 512, ini=v8 + "output_width=3440\n", picture="3440x1440", shape=23889,
|
||||
row="2.39:1 (3440x1440)", custom="3440x1440"),
|
||||
case(8, 1, "2560x1440", "Custom (not set)", 512, ini=v8 + "output_width=3440\noutput_height=1440\n", env_size="3440",
|
||||
custom=None), # (HOS_OUTPUT_SIZE not WxH: not taken, and not the ini's either: the host's 2560x1440)
|
||||
)
|
||||
with tempfile.TemporaryDirectory(prefix="output-resolution-") as tmp:
|
||||
work = Path(tmp)
|
||||
source, exe = work / "fixture.cpp", work / "fixture.exe"
|
||||
source.write_text(fixture, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++17", "-I", str(ROOT), str(source), "-o", str(exe)], check=True)
|
||||
for saved, handheld, override, mode, w, h, label in cases:
|
||||
(work / "triforce_options.ini").write_text(f"output_res={saved}\nhandheld_profile={handheld}\n", encoding="ascii")
|
||||
# (twice: as this system builds the menu, and as a system that is not Windows does, where it takes the main monitor
|
||||
# from the host's screens; every case must hold for both)
|
||||
exes = (exe, work / "fixture_off_windows.exe")
|
||||
subprocess.run([args.cxx, "-std=c++17", "-I", str(ROOT), str(source), "-o", str(exes[0])], check=True)
|
||||
subprocess.run([args.cxx, "-std=c++17", "-DFIXTURE_OFF_WINDOWS", "-I", str(ROOT), str(source), "-o", str(exes[1])], check=True)
|
||||
bad = 0
|
||||
for (saved, handheld, override, screens, ini, env_size, mode, frame, now, pool, shape, labels, row, picture,
|
||||
rows, log) in cases:
|
||||
(work / "triforce_options.ini").write_text(f"output_res={saved}\nhandheld_profile={handheld}\n{ini}", encoding="ascii")
|
||||
env = os.environ.copy()
|
||||
for key in ("HOS_OUTPUT_RES", "HOS_HANDHELD", "HOS_RT_POOL_MB"):
|
||||
for key in ("HOS_OUTPUT_RES", "HOS_HANDHELD", "HOS_RT_POOL_MB", "HOS_OUTPUT_SIZE", "HOS_ASPECT", "TEST_SCREENS", "TEST_LOG"):
|
||||
env.pop(key, None)
|
||||
if log is not None:
|
||||
env["TEST_LOG"] = log
|
||||
if override is not None:
|
||||
env["HOS_OUTPUT_RES"] = override
|
||||
subprocess.run([str(exe), str(mode), str(w), str(h), label], cwd=work, env=env, check=True)
|
||||
print("PASS: output sizes, menu order, 1080p override, handheld, render-target budgets and DLSS sizes at 1080p, 5120x1440, 5120x2160 and 5120x2880")
|
||||
if screens:
|
||||
env["TEST_SCREENS"] = screens
|
||||
if env_size is not None:
|
||||
env["HOS_OUTPUT_SIZE"] = env_size
|
||||
for built in exes:
|
||||
run = subprocess.run([str(built), str(mode), frame, now, str(pool), str(shape), labels, row, picture, rows],
|
||||
cwd=work, env=env, capture_output=True, text=True)
|
||||
if run.returncode:
|
||||
bad += 1
|
||||
print(f"{built.name}: output_res={saved} handheld={handheld} HOS_OUTPUT_RES={override} screens={screens} "
|
||||
f"HOS_OUTPUT_SIZE={env_size} {ini!r}:\n{run.stderr}")
|
||||
break
|
||||
if bad:
|
||||
raise SystemExit(f"FAIL: {bad} of {len(cases)} cases")
|
||||
print("PASS: output sizes as pictures (fixed, the connected screens' by name, Custom: frame, shape, limits, the old Screen "
|
||||
"and the old 5120-wide frames), the row's choices and their order, the Ultrawide row's shape for 16:9 sizes, 1080p "
|
||||
"override, handheld, render-target budgets and DLSS sizes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -171,12 +171,16 @@ def main():
|
||||
"draw_quit_ask(k);" in dm and dm.index("menu_window_w = c.w, menu_window_h = c.h;") < dm.index("draw_quit_ask(k);"),
|
||||
"the dialog is not drawn through its Out, or its dim is not the whole window's")
|
||||
# ((11-19) the performance panel over the dialog's dim, as over the game's own dialogs: drawn after the menu on Mods' page)
|
||||
for fn in ("void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {",
|
||||
"void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {"):
|
||||
rec = function(menu, fn)
|
||||
check("const bool over_row = open && page == kModsRowPage;" in rec and "if (open) draw_menu(c, full && !over_row);" in rec and
|
||||
rec.index("if (open) draw_menu(c, full && !over_row);") < rec.index("if (full && over_row) draw_perf(c);"),
|
||||
"the performance panel is under Quit's dim (" + fn.split("(")[0] + ")")
|
||||
# ((Triforce, 11-22) the window's frames by draw_overlays (menu_record's, and N64 Classic's menu_tv_layer's: m the options'
|
||||
# own screens' context, under its TV when it takes them), the stills by menu_record_image)
|
||||
rec = function(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {")
|
||||
check("const bool over_row = s.open && page == kModsRowPage;" in rec and "if (s.open) draw_menu(m, full && !over_row);" in rec and
|
||||
rec.index("if (s.open) draw_menu(m, full && !over_row);") < rec.index("if (full && over_row) draw_perf(c);"),
|
||||
"the performance panel is under Quit's dim (void draw_overlays)")
|
||||
rec = function(menu, "void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {")
|
||||
check("const bool over_row = open && page == kModsRowPage;" in rec and "if (open) draw_menu(c, full && !over_row);" in rec and
|
||||
rec.index("if (open) draw_menu(c, full && !over_row);") < rec.index("if (full && over_row) draw_perf(c);"),
|
||||
"the performance panel is under Quit's dim (void menu_record_image)")
|
||||
# ((11-19) the mouse over the dialog: its buttons only, Mods and Quit under the dim gone from the hit map; none on its Out)
|
||||
check("hits.clear(0, 0, c.w, c.h);" in ask and ask.index("hits.clear(0, 0, c.w, c.h);") < ask.index("for (int i = 0; i < 3; i++) {"),
|
||||
"Mods and Quit under the dialog's dim still take clicks (a second click on Quit's place is A on Quit Game)")
|
||||
@@ -185,7 +189,7 @@ def main():
|
||||
# the input
|
||||
tick = function(menu, "void menu_tick() {")
|
||||
enter = tick[tick.index("bool entered_by_down = false;"):tick.index("if (!open_now.load() || page != kModsPage) {")]
|
||||
check("entered_by_down = enter == 1 || enter == 5;" in enter and "if (enter == 3) quit_open();" in enter,
|
||||
check("entered_by_down = enter == 1 || enter == 5;" in enter and "if (enter == 3 && !mods_title_list()) quit_open();" in enter,
|
||||
"the enter word does not tell of a Down, or a click on Quit does not open its dialog with its In")
|
||||
check("mods_row_sel = enter == 3 || enter == 4 ? 1 : 0," in enter and "const bool clicked = enter == 2 || enter == 3;" in enter and
|
||||
"mods_sound(clicked ? HOS_MENU_SOUND_SYS_DECIDE : HOS_MENU_SOUND_SYS_CURSOR);" in enter,
|
||||
|
||||
@@ -83,8 +83,19 @@ def check_source():
|
||||
# an open menu (its BringWindowToDisplayBack): draw_menu draws it over its dim, before its pages; the game tab's header over
|
||||
# it; (Triforce, 11-19) over the Mods entry's Quit dialog and its dim instead. tests/test_fps_overlay_order.py runs
|
||||
# menu_record for the order)
|
||||
for name in ("void menu_record(VkCommandBuffer cmd, uint32_t index, uint32_t w, uint32_t h) {",
|
||||
"void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {"):
|
||||
# ((Triforce, 11-22) the window's frames by draw_overlays, what shows asked by showing_now (menu_record's, and N64 Classic's
|
||||
# menu_tv_layer's: m the options' own screens' context, under its TV when it takes them; the panel with them under the game
|
||||
# tab's header and the Mods entry, the counter over it all)
|
||||
showing = block(menu, "Showing showing_now() {")
|
||||
check("s.fps = opts.show_fps && !s.start;" in showing, "the counter's and the panel's switch is not the row (showing_now)")
|
||||
record = block(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {")
|
||||
check("const bool full = s.fps && opts.show_fps == 2;" in record and "if (s.open) draw_menu(m, full && !over_row);" in record and
|
||||
"if (full) draw_perf(s.game_tab || s.mods_row ? m : c);" in record and "if (full && over_row) draw_perf(c);" in record and
|
||||
"if (s.fps && !full) draw_fps(c, (s.open && page != kModsRowPage) || s.game_tab);" in record,
|
||||
"Full does not draw the panel alone, under the menu (draw_overlays)")
|
||||
check(record.index("if (full) draw_perf(") < record.index("if (s.game_tab) draw_game_tab(m);"), "the game tab's header is not over the panel")
|
||||
check(record.count("draw_perf(") == 2, "the panel is drawn more than under the menu and over the Mods entry's dialog")
|
||||
for name in ("void menu_record_image(VkCommandBuffer cmd, VkImage image, VkImageView view, uint32_t w, uint32_t h) {",):
|
||||
record = block(menu, name)
|
||||
check("const bool fps = opts.show_fps && !start;" in record or "const bool fps = opts.show_fps && !startup_on.load(std::memory_order_acquire);" in record,
|
||||
"the counter's and the panel's switch is not the row")
|
||||
@@ -157,7 +168,7 @@ def check_source():
|
||||
'cell(v.frame[3], "%.2f ms", f.shader_ms);', 'cell(v.frame[4], "%.1f per frame", f.uploads);',
|
||||
'c.dim = perf_machine::cell_text(c.t, sizeof c.t, fmt, x);',
|
||||
'present_sizes.load(std::memory_order_relaxed)', 'set(2, perf_upscaling_text(t, sizeof t));', 'set(3, tx_aa(opts.aa));',
|
||||
'perf_rate_text(tx_fps_cap(opts.fps_cap), t, sizeof t);', 'set(5, tx_onoff(opts.vsync));', 'set(6, tx_ultrawide(opts.ultrawide));',
|
||||
'perf_rate_text(tx_fps_cap(opts.fps_cap), t, sizeof t);', 'set(5, tx_onoff(opts.vsync));', 'set(6, shape_now(opts.ultrawide));',
|
||||
'sscanf(tx_output_res(opts.output_res), "%ux%u", &ow, &oh) == 2 && oh) snprintf(t, sizeof t, "%up", oh);', 'set(8, tx_hdr(opts.hdr));',
|
||||
'set(9, perf_framegen_text(t, sizeof t));', 'perf_title(v.title, sizeof v.title);'):
|
||||
check(needle in sample, "the panel's text is not NX2navi's, or not from where it is measured: " + needle)
|
||||
@@ -291,7 +302,8 @@ def check_source():
|
||||
"the panel's text size is not baked at once when it changes")
|
||||
check("ImFont* font = c.f.body ? c.f.body : c.f.strong; // (draw_perf's)" in block(menu, "void bake_perf(const ui::Ctx& c, float px) {") and
|
||||
"ImFont* font = c.f.body ? c.f.body : c.f.strong;" in draw, "the panel's glyphs are baked in another font than draw_perf's")
|
||||
check(record.index("prebake(c);") < record.index("if (open) draw_menu(c, full && !over_row);"), "the bake is not before the drawing")
|
||||
overlays = block(menu, "void draw_overlays(uint32_t w, uint32_t h, const Showing& s, ImDrawList* under) {") # ((11-22) the drawing's)
|
||||
check(overlays.index("prebake(c);") < overlays.index("if (s.open) draw_menu(m, full && !over_row);"), "the bake is not before the drawing")
|
||||
check("if (r == kPerfFG && !v.fg) continue;" in draw, "the FG row shows without frame generation")
|
||||
check("if (v.setting[i][0]) label(kPerfSetting[i])" in draw, "a setting without a value is not left out")
|
||||
# (no panel of its own making: the options' plate, separator and font; the game's art read at run time from the player's
|
||||
|
||||
@@ -72,6 +72,8 @@ VkImage framegen_scale(int, VkImageView, VkImage, uint32_t, uint32_t, const int*
|
||||
++scales; scale_w = w; scale_h = h;
|
||||
return filtered ? 99 : VK_NULL_HANDLE;
|
||||
}
|
||||
void n64_screen_begin(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) {} // ((Triforce, 11-22) N64 Classic's TV's screen: vk_n64.h)
|
||||
void n64_screen_end() {}
|
||||
void blit_crop_to_rect(int, VkImage src, uint32_t, uint32_t, const int* crop, VkImage, int, PresentRect rect) {
|
||||
++blits; drawn = rect; drawn_crop = crop; drawn_source = src;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ struct {
|
||||
std::atomic<uint64_t> swap_resize{0};
|
||||
} dev;
|
||||
namespace dlssg { bool on = false; bool active() { return on; } }
|
||||
namespace gpu_wait_kinds { struct Exclude {}; } // ((Triforce, 11-23) image_free's compositor wait, not counted)
|
||||
// (PRESENT-45: a lost surface's handling at the acquire; none is lost here, tests/test_present_surface_lost.py runs it)
|
||||
bool surface_recover(VkResult) { return false; }
|
||||
void invalidate_lost_surface() {}
|
||||
|
||||
@@ -65,6 +65,10 @@ static int fps_max(void) { return 240; }
|
||||
static int64_t steady_period(int64_t base, int64_t now) { (void)now; return base; } /* ((Triforce) the Steady frame rate row off) */
|
||||
static void movie_pace_decide(void) {} /* ((Triforce, 11-22, PRESENT-30) no movie plays here: paced by the cap) */
|
||||
static int pace_fps(void) { return fps_max(); }
|
||||
/* ((Triforce, 11-22, N64 Classic, step 7) its rate (nn_vi.c's, host/n64_pace.h's rule): none here, so the interval is as it
|
||||
was; tests/test_n64_pace.py runs it */
|
||||
static int n64_rate;
|
||||
static int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; }
|
||||
void hos_bench_present(int64_t now) { (void)now; } /* (benchmark mode's note of each present: not on here) */
|
||||
'''
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ bool vk_ft_on() { return false; }
|
||||
template <class... A> void vk_ft(const char*, A...) {}
|
||||
bool dlssg_active = false;
|
||||
namespace dlssg { bool active() { return dlssg_active; } }
|
||||
namespace gpu_wait_kinds { struct Exclude {}; } // ((Triforce, 11-23) image_free's compositor wait, not counted)
|
||||
namespace pace {
|
||||
int64_t steady_floor_ns() { return 0; }
|
||||
void steady_held(int64_t) {}
|
||||
|
||||
@@ -101,7 +101,7 @@ int main() {
|
||||
const int64_t ns = h.settle();
|
||||
if (ns >= 0) waited += ns, waits++;
|
||||
h.hand({k, 0});
|
||||
for (volatile int spin = 0; spin < (k % 3) * 2000; spin = spin + 1) {} /* (the next frame's build) */
|
||||
for (volatile int spin = 0; spin < (k % 3) * 2000;) { spin = spin + 1; } /* (the next frame's build) */
|
||||
}
|
||||
h.settle();
|
||||
t.join();
|
||||
@@ -193,7 +193,9 @@ def check_source():
|
||||
"the pacing's wait lets go of a lock the present thread never took")
|
||||
# the rule and the switch
|
||||
wanted = block(replay, "bool present_thread_wanted() {")
|
||||
check("present_thread_use(present_thread_on(), smooth_mine, framegen_on(), dlssg::active(), antilag_running())" in wanted,
|
||||
# ((Triforce, 11-23) the switch, or the next image acquired ahead (tests/test_acquire_ahead.py))
|
||||
check("present_thread_use(on, smooth_mine, framegen_on(), dlssg::active(), antilag_running())" in wanted and
|
||||
"const bool on = present_thread_on() || (!never && acquire_ahead_wanted());" in wanted,
|
||||
"the present thread is not limited to the game's pictures without frame generation, DLSS frame generation or Anti-Lag 2")
|
||||
on = block(replay, "bool present_thread_on() {")
|
||||
check('getenv("RX_VK_PRESENT_THREAD")' in on and "e && *e && atoi(e) == 1" in on, "RX_VK_PRESENT_THREAD is not off unless =1 (off by default since 11-16)")
|
||||
@@ -208,8 +210,13 @@ def check_source():
|
||||
check("vkQueuePresentKHR(" not in text and "vkAcquireNextImageKHR(" not in text, f.name + " presents or acquires itself")
|
||||
if f.name not in ("vk_replay.cpp", "vk_main.cpp"):
|
||||
check("create_swapchain(" not in text, f.name + " makes the swapchain")
|
||||
check(replay.count("vkQueuePresentKHR(") == 2 and out.count("vkQueuePresentKHR(") == 2 and replay.count("vkAcquireNextImageKHR(") == 1,
|
||||
"vk_replay.cpp presents or acquires outside present_out and present_image")
|
||||
# ((Triforce, 11-23) and acquire_ahead, on the present thread after its present_out: RX_VK_ACQUIRE_AHEAD, tests/test_acquire_ahead.py)
|
||||
ahead = block(replay, "void acquire_ahead() {")
|
||||
check(replay.count("vkQueuePresentKHR(") == 2 and out.count("vkQueuePresentKHR(") == 2 and replay.count("vkAcquireNextImageKHR(") == 2
|
||||
and ahead.count("vkAcquireNextImageKHR(") == 1,
|
||||
"vk_replay.cpp presents or acquires outside present_out, present_image and acquire_ahead")
|
||||
check(before(main, "present_out(o, qk, true);", "acquire_ahead();", "present_hand.done();"),
|
||||
"the next image is not acquired ahead on the present thread, after its present and before it says so")
|
||||
# NVIDIA Reflex: the present's id and markers are the frame's whose submit ended, not the next frame's
|
||||
reflex = (vk / "vk_reflex.cpp").read_text(encoding="utf-8")
|
||||
ends = block(reflex, "void reflex_submit_ends() {")
|
||||
|
||||
@@ -51,6 +51,10 @@ static int fps_max(void) { return 60; } /* (nn_vi.c's Frame rate cap: the cons
|
||||
static int64_t steady_period(int64_t base, int64_t now) { (void)now; return base; } /* ((Triforce) the Steady frame rate row off) */
|
||||
static void movie_pace_decide(void) {} /* ((Triforce, 11-22, PRESENT-30) no movie plays here: paced by the cap) */
|
||||
static int pace_fps(void) { return fps_max(); }
|
||||
/* ((Triforce, 11-22, N64 Classic, step 7) its rate (nn_vi.c's, host/n64_pace.h's rule): none here, so the interval is as it
|
||||
was; tests/test_n64_pace.py runs it */
|
||||
static int n64_rate;
|
||||
static int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; }
|
||||
void hos_bench_present(int64_t now) { (void)now; } /* (benchmark mode's note of each present: not on here) */
|
||||
'''
|
||||
|
||||
|
||||
@@ -293,9 +293,10 @@ def main():
|
||||
check('snprintf(out, cap, "%s/prompts_auto.txt", hos_user_dir ? hos_user_dir : "user");' in block(prompts, "static void auto_path(")
|
||||
and "auto_path(path, sizeof path);" in block(prompts, "static int remembered_face(") and "auto_path(path, sizeof path);" in follow
|
||||
and "prompts/auto.txt" not in follow, "Auto's device used last is kept in prompts/, which Setup makes again at an update")
|
||||
check(re.search(r"int \(\*prompt_pad_face\)\(void\);\s*\} MkwVkHost;", api) is not None and
|
||||
"#define MKWVK_API_VERSION 15" in api, "gpu/vk/vk_api.h has no prompt_pad_face last, at version 15")
|
||||
check("hos_bench_state, hos_prompts_pad_face,\n};" in (ROOT / "host/rx_backend.c").read_text(encoding="utf-8"),
|
||||
check(re.search(r"int \(\*prompt_pad_face\)\(void\);", api) is not None and
|
||||
"#define MKWVK_API_VERSION 19" in api, "gpu/vk/vk_api.h has no prompt_pad_face, at version 19 (15 had it; 16-18 ultrawide's "
|
||||
"screens and wide_backdrop, 19 the renderer's screen_point, N64 Classic's)")
|
||||
check("hos_bench_state, hos_prompts_pad_face, host_screens, host_wide_backdrop,\n};" in (ROOT / "host/rx_backend.c").read_text(encoding="utf-8"),
|
||||
"host/rx_backend.c does not give the back end hos_prompts_pad_face")
|
||||
imgui = (ROOT / "gpu/vk/vk_imgui.cpp").read_text(encoding="utf-8")
|
||||
check('"prompts/External.pad." + std::to_string(pad) + ".bfotf.zs"' in imgui and
|
||||
|
||||
85
tests/test_query_ring.py
Normal file
85
tests/test_query_ring.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""(Triforce, 11-23) The recordings' timestamps through a ring the GPU copies them into (RX_VK_QUERY_RING, gpu/vk/vk_replay.cpp;
|
||||
no game, no GPU).
|
||||
|
||||
vkGetQueryPoolResults cost about 0.6 ms a frame on AMD's Windows driver on the thread that replays the frame, and with the recorder
|
||||
thread each call is a boundary that waits for it. A slot's next use copies its last use's timestamps into a mapped, host-coherent
|
||||
ring before it resets them; the slot's turn after that reads them from memory. Read from the source:
|
||||
- the ring: made with the pools, host-coherent or not used (an invalidate would be a recorder boundary), the switch;
|
||||
- the copy: in the command buffer just begun (no pass open), before the reset (query commands run in submission order), each
|
||||
value with its availability word, never waiting on the GPU (a use that was never submitted would hang it), behind a
|
||||
transfer-to-host barrier, through vk_work.h (the recorder's list, so the recorder thread keeps it in order);
|
||||
- the read: only what was copied, only when the copying use was submitted, each value's availability checked; the old path kept
|
||||
when there is no ring; the upload command buffer's timestamps as before.
|
||||
|
||||
python -I -B tests/test_query_ring.py
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def block(text, marker):
|
||||
start = text.index(marker)
|
||||
end = text.index('{', start) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (text[end] == '{') - (text[end] == '}')
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
def before(text, *parts):
|
||||
at = -1
|
||||
for p in parts:
|
||||
i = text.find(p, at + 1)
|
||||
if i < 0:
|
||||
return False
|
||||
at = i
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
vk = ROOT / "gpu/vk"
|
||||
replay = (vk / "vk_replay.cpp").read_text(encoding="utf-8")
|
||||
rec = (vk / "vk_recorder.h").read_text(encoding="utf-8")
|
||||
work = (vk / "vk_work.h").read_text(encoding="utf-8")
|
||||
fails = []
|
||||
|
||||
def check(ok, why):
|
||||
if not ok:
|
||||
fails.append(why)
|
||||
|
||||
check("V(vkCmdCopyQueryPoolResults)" in rec, "the copy is not in the recorder's list of calls")
|
||||
check("#define vkCmdCopyQueryPoolResults(...) (::mkwvk::rec::rx_vkCmdCopyQueryPoolResults(RX_WORK_ON(__VA_ARGS__)))" in work,
|
||||
"vk_work.h does not send the copy through the recorder")
|
||||
make = block(replay, "void query_ring_make() {")
|
||||
check('getenv("RX_VK_QUERY_RING")' in block(replay, "bool query_ring_on() {"), "RX_VK_QUERY_RING is not read")
|
||||
check(before(make, "create_buffer_cached(", "VK_MEMORY_PROPERTY_HOST_COHERENT_BIT", "destroy_buffer(ts_ring, ts_ring_alloc);",
|
||||
"ts_ring_map = "), "the ring is used without host-coherent memory")
|
||||
begin = block(replay, "void gpu_time_begin(Recording& r) {")
|
||||
check(before(begin, "query_ring_make();", "if (ts_ring_map && ts_pending[r.slot]) {", "vkCmdCopyQueryPoolResults(r.cmd, ts_pool,",
|
||||
"VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT", "VK_PIPELINE_STAGE_2_HOST_BIT",
|
||||
"vkCmdPipelineBarrier2(r.cmd, &di);", "ts_ring_copied[r.slot] = true;",
|
||||
"vkCmdResetQueryPool(r.cmd, ts_pool, ts_count() * r.slot, ts_count());"),
|
||||
"the copy is not made before the reset, with availability, behind a host barrier")
|
||||
copy = begin[begin.index("vkCmdCopyQueryPoolResults("):begin.index("VkMemoryBarrier2")]
|
||||
check("WAIT_BIT" not in copy, "the copy waits on the GPU for queries a use that was never submitted would never write")
|
||||
collect = block(replay, "void gpu_time_collect(Recording& r) {")
|
||||
check(before(collect, "if (ts_ring_map) {", "if (!ts_ring_copied[r.slot] || !r.submitted) return;", "ts_ring_copied[r.slot] = false;",
|
||||
"got = got && w[2 * i + 1] != 0;", "} else {", "vkGetQueryPoolResults(dev.device, ts_pool,"),
|
||||
"the ring is read without its copy, its submit or the availability words, or the old read is gone")
|
||||
check(collect.index("ts_up_pool && ts_up_pending[r.slot]") < collect.index("if (ts_ring_map) {"),
|
||||
"the upload command buffer's timestamps are no longer read as before")
|
||||
for f in sorted(vk.glob("*.cpp")):
|
||||
text = f.read_text(encoding="utf-8", errors="replace")
|
||||
if "vkCmdCopyQueryPoolResults(" in text and f.name != "vk_replay.cpp" and '#include "vk_work.h"' not in text:
|
||||
check(False, f.name + " copies query results outside the recorder")
|
||||
if fails:
|
||||
for f in fails:
|
||||
print("FAIL: " + f)
|
||||
raise SystemExit(1)
|
||||
print("query ring: ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,4 +1,5 @@
|
||||
"""Game-free checks of recomplauncher.json: it parses, and every settings key is a row of the in-game menu.
|
||||
"""Game-free checks of recomplauncher.json: it parses, every settings key is a row of the in-game menu, and no value it
|
||||
writes means something else under another options_version.
|
||||
|
||||
Run with: python -I tests/test_recomplauncher_json.py
|
||||
"""
|
||||
@@ -26,6 +27,29 @@ class RecompLauncherJsonTests(unittest.TestCase):
|
||||
self.assertTrue(keys)
|
||||
self.assertEqual(keys - rows, set())
|
||||
|
||||
def test_values_mean_the_same_in_every_options_version(self):
|
||||
"""The manifest writes key=value lines and never options_version (it has no way to: a line it wrote into an older
|
||||
file would also switch off that file's other rules). So a value it writes is read by the rules of whatever
|
||||
version the file has, or of none in a file it makes. It may only offer values no rule changes:
|
||||
- ultrawide=1 was "Monitor's shape" before options_version 6 and is 16:10 from 6 on (gpu/vk/ultrawide_rows.h);
|
||||
- output_res=4 and 6 (5120x1440, 5120x2160) are read as 2560x1440 and 3840x2160 before 8 when ultrawide is on
|
||||
another shape than theirs (gpu/vk/output_sizes.h output_res_read)."""
|
||||
manifest = json.loads((ROOT / "recomplauncher.json").read_text(encoding="utf-8"))
|
||||
written = {(key, value) for setting in manifest["settings"] for choice in setting["choices"]
|
||||
for key, value in choice["set"].items()}
|
||||
self.assertNotIn("options_version", {key for key, _ in written})
|
||||
moved = {("ultrawide", "1"), ("output_res", "4"), ("output_res", "6"), ("output_res", "7"), ("output_res", "8")}
|
||||
self.assertEqual(written & moved, set())
|
||||
rows_h = (ROOT / "gpu" / "vk" / "ultrawide_rows.h").read_text(encoding="utf-8")
|
||||
sizes_h = (ROOT / "gpu" / "vk" / "output_sizes.h").read_text(encoding="utf-8")
|
||||
# (the rules those three come from, as the headers have them: a new rule there is a new value to leave out here)
|
||||
self.assertIn("return version < 6 && row == 1 ? ultrawide_row_nearest(screen_w, screen_h) : row;", rows_h)
|
||||
self.assertIn(" if (v == 4 && ultrawide_row != 0 && ultrawide_row != 3) return 1;\n"
|
||||
" if (v == 6 && ultrawide_row != 0 && ultrawide_row != 2) return 2;\n return v;", sizes_h)
|
||||
# (what it still offers of the two rows: the 16:9 sizes and Screen, and the shapes 16:9, 21:9 and 32:9)
|
||||
self.assertEqual({value for key, value in written if key == "output_res"}, {"0", "1", "2", "3", "5"})
|
||||
self.assertEqual({value for key, value in written if key == "ultrawide"}, {"0", "2", "3"})
|
||||
|
||||
def test_appimage_carries_it(self):
|
||||
self.assertIn('cp recomplauncher.json "$APPDIR/recomplauncher.json"',
|
||||
(ROOT / "scripts" / "linux" / "appimage.sh").read_text(encoding="utf-8"))
|
||||
|
||||
@@ -19,6 +19,11 @@ par_tune_present at each present). No game, no GPU.
|
||||
"settled": (11-22) the rule gives an area's load window, and the first after it, no verdict (with settled off: on at the
|
||||
load, as Kaefergeneral's log had it); a settled heavy scene like test4's still turns the helpers on without a trial, a
|
||||
window after it settled; a trial the scene changed under changes nothing and the next comes once the scene settles.
|
||||
"calm": (11-22) no trial on a loading screen, a trial due during an arrival waits for the calm scene, one that never calms
|
||||
still has its trials; the rule's "on" in the Market's steady texture load withdrawn when the area comes down, kept where
|
||||
the scene stays, and given again three windows after a withdrawal where the helpers win; (11-23) the rule's "on" needs
|
||||
three windows alike to the first of them, so 0.7's Market arrival, its texture load coming down a window at a time, gets
|
||||
none (with two alike, the gate before: in 20 of 20 runs).
|
||||
2. The source read: par_tune_present returns at once unless the tuner decides (the Debug row's Off, RX_VK_PARALLEL), hands
|
||||
each frame to Tuner::step with the way in use, and applies its change; the rule is RX_VK_PARALLEL_RULE's to turn off, and
|
||||
counts the replay thread among the threads that record segments only where it does (RX_VK_PARALLEL_OWN); the back-off is
|
||||
@@ -86,20 +91,22 @@ def main():
|
||||
check("`RX_VK_PARALLEL_RULE=0`" in guide, "docs/development.md does not say what RX_VK_PARALLEL_RULE=0 does")
|
||||
check("`RX_VK_PARALLEL_BACKOFF=0`" in guide, "docs/development.md does not say what RX_VK_PARALLEL_BACKOFF=0 does")
|
||||
check("`RX_VK_TUNER_SETTLED=0`" in guide, "docs/development.md does not say what RX_VK_TUNER_SETTLED=0 does")
|
||||
# ((Triforce) 11-22) the rule's "on" withdrawn is logged, as its "on" is
|
||||
check("if (s.withdrawn) {" in tune and "withdrawn at present %lld: its scene changed" in tune, "par_tune_present does not log a withdrawn \"on\"")
|
||||
with tempfile.TemporaryDirectory(prefix="replay-tuner-") as tmp:
|
||||
exe = Path(tmp) / "tuner.exe"
|
||||
built = subprocess.run([args.cxx, "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror", "-I", str(VK),
|
||||
str(ROOT / "tests" / "replay_threads_tuner_test.cpp"), "-o", str(exe)], capture_output=True, text=True)
|
||||
check(built.returncode == 0, "the fixture did not build:\n" + built.stderr[-4000:])
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith("RX_VK_")}
|
||||
for case in ("same", "prev", "rule", "backoff", "settled"):
|
||||
for case in ("same", "prev", "rule", "backoff", "settled", "calm"):
|
||||
r = subprocess.run([str(exe), case], env=env, capture_output=True, text=True, timeout=300)
|
||||
print((r.stdout + r.stderr).strip())
|
||||
check(r.returncode == 0, "replay_threads_tuner_test %s" % case)
|
||||
print("PASS: the helper threads' tuner decides as it did inline with the rule off; with it, on without a trial where the "
|
||||
"replay is plainly the frame's limit, no trial where the GPU or the game's threads are, trials in between; the "
|
||||
"back-off makes them rarer and shorter once the way holds, early where the scene changes, off as before; both judge "
|
||||
"settled scenes only")
|
||||
"settled scenes only, no trial where nothing is cut, and the rule's \"on\" holds for its scene")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
The 305 MiB default crashed in Castle Town's guard house; 512 MiB resolved the
|
||||
reported conversation/camera reproduction. Keep existing 4K/ultrawide growth
|
||||
and explicit HOS_RT_POOL_MB overrides, including overrides below the floor; the 5120x2880
|
||||
output's pool is kept to 900 MiB.
|
||||
output's pool is kept to 900 MiB, and so is that of every output of more pixels than
|
||||
3840x2160's, whether they are the frame's or the widescreen picture's.
|
||||
"""
|
||||
import argparse
|
||||
import importlib.util
|
||||
@@ -56,7 +57,15 @@ static const struct {
|
||||
{3840, 2160, 0, 305, NULL, 687},
|
||||
{2560, 1440, WIDE(3440, 1440), 305, NULL, 512},
|
||||
{2560, 1440, WIDE(5120, 1440), 305, NULL, 610},
|
||||
{3840, 2160, WIDE(7680, 2160), 305, NULL, 1373},
|
||||
/* ((Triforce) a 7680 x 2160 picture: the 1373 MiB it scales to failed the game's reservation at boot (host/hos_main.c),
|
||||
as every pool over 900 MiB has; host/hos_main.c no longer makes that picture either) */
|
||||
{3840, 2160, WIDE(7680, 2160), 305, NULL, 900},
|
||||
/* ((Triforce) a 5120 x 2160 picture with the frame 3840 x 2160, the Output resolution 5120x2160: 915 MiB scaled, kept to
|
||||
900 as the 5120 x 2160 frame before it; 3840 x 1600 and 5120 x 1440 pictures keep their scaled pools) */
|
||||
{3840, 2160, WIDE(5120, 2160), 305, NULL, 900},
|
||||
{3840, 2160, WIDE(5120, 2160), 305, "1000", 1000},
|
||||
{2848, 1600, WIDE(3840, 1600), 305, NULL, 512},
|
||||
{5120, 2880, WIDE(7224, 2032), 305, NULL, 900},
|
||||
{2560, 1440, WIDE(1920, 1080), 305, NULL, 512},
|
||||
{2560, 1440, 0, 305, "256", 256},
|
||||
{3840, 2160, WIDE(7680, 2160), 305, "768", 768},
|
||||
@@ -81,6 +90,18 @@ int main(void) {
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
/* TEX-85: a cap reached by a widescreen picture pins storage just like a fixed 5K output.
|
||||
A picture over 4K whose scaled pool still has room is not pinned. Explicit budgets always are. */
|
||||
output_width = 3840; output_height = 2160; hos_wide_out = WIDE(5120, 2160); override = NULL;
|
||||
if (hos_rt_pool_size(305 * MIB) != 900 * MIB || rt_pool_pinned != 1) return 3;
|
||||
hos_wide_out = WIDE(4096, 2160);
|
||||
if (hos_rt_pool_size(305 * MIB) >= 900 * MIB || rt_pool_pinned != 0) return 4;
|
||||
scene_rgba16f = 1; hos_wide_out = WIDE(4608, 2160);
|
||||
if (hos_rt_pool_size(305 * MIB) != 900 * MIB || rt_pool_pinned != 1) return 5;
|
||||
scene_rgba16f = 0; hos_wide_out = WIDE(3840, 2400);
|
||||
if (hos_rt_pool_size(360 * MIB) != 900 * MIB || rt_pool_pinned != 1) return 7; /* exactly at the cap */
|
||||
hos_wide_out = 0; override = "512";
|
||||
if (hos_rt_pool_size(305 * MIB) != 512 * MIB || rt_pool_pinned != 1) return 6;
|
||||
/* (local, RenoDX port) an RGBA16F scene: 128 MiB more, but not over an explicit HOS_RT_POOL_MB */
|
||||
scene_rgba16f = 1;
|
||||
output_width = 2560; output_height = 1440; hos_wide_out = 0;
|
||||
@@ -111,7 +132,7 @@ int main(void) {
|
||||
source.write_text(fixture)
|
||||
subprocess.run([compiler, "-std=c11", "-O2", str(source), "-o", str(binary)], check=True)
|
||||
subprocess.run([str(binary)], check=True, timeout=5)
|
||||
print("PASS: 512 MiB floor, 4K/ultrawide growth and explicit overrides, the 5120-wide outputs' 900 MiB (16 cases), "
|
||||
print("PASS: 512 MiB floor, 4K/ultrawide growth and explicit overrides, the 900 MiB of the outputs over 3840x2160's pixels, frame or picture (20 cases), "
|
||||
"an RGBA16F scene's 128 MiB more, and the 5K output's 900 MiB with it")
|
||||
|
||||
|
||||
|
||||
@@ -87,8 +87,9 @@ bool can_mic() { return false; }
|
||||
/* (the Upscaler row's choices, which set_row steps through: the game's own only, here) */
|
||||
unsigned upscalers_available() { return 1; }
|
||||
void mic_chosen() {}
|
||||
// (set_row steps the Output row through vk_menu.cpp's step_output_choice (#1144): not what this checks)
|
||||
int step_output_choice(int id, int dir) { return id + dir; }
|
||||
// (set_row steps the Output row through vk_menu.cpp's output_step, its choices (#1144): not what this checks)
|
||||
struct { unsigned w, h; } remembered_custom{};
|
||||
bool output_step(int, bool) { return false; }
|
||||
%(set_row)s
|
||||
/* (menu_tick's arrows: Left, Right, and Enter as Right; a click on the value's left or right half presses them) */
|
||||
void arrow(Row& r, bool right) { %(arrow)s }
|
||||
|
||||
250
tests/test_save_files.py
Normal file
250
tests/test_save_files.py
Normal file
@@ -0,0 +1,250 @@
|
||||
"""Save files (host/save_files.h, host/save_files.c, host/hos_main.c, gpu/vk/save_file_rows.h, gpu/vk/vk_menu.cpp; no game).
|
||||
|
||||
As the Nintendo 64 game had them: the title asks which file to play, and the game's saves and autosaves live in that
|
||||
file. A file is a folder the game saves in; the game reads its saves once, at its start, so another file is another
|
||||
start. On unless HOS_SAVE_FILES=0 (11-23). Compiled and run here:
|
||||
|
||||
- tests/save_files_test.c: host/save_files.h alone. triforce_files.txt's three lines and what is not taken from it,
|
||||
written and read back; the files' folders; the start that follows a choice; a file's card (a map's name as words,
|
||||
hearts from the game's count of life, triforce_card.txt read and written);
|
||||
- tests/save_files_host_test.c: host/save_files.c's own text against a stand-in menu, a stand-in for the files'
|
||||
folders and a game folder of the test's, four starts. Without the switch the game's own folder, and nothing read,
|
||||
written or asked; with it file 1 without a triforce_files.txt, the files named to the menu once, whole; a file chosen
|
||||
kept as the next start's and the menu told; the next start on that file's folder, saying that it follows a choice;
|
||||
and a later start on the same file, with the player's names, asking again;
|
||||
- tests/save_file_rows_test.cpp: gpu/vk/save_file_rows.h alone. Nothing shown or asked until the list is whole; this
|
||||
run's file played at once and another asked of the host once; the host's word taken once; the choice under the keys.
|
||||
|
||||
Read in the sources: the folder is chosen at the start, before the game's memory is made, and not when --user named
|
||||
one; the files are named at the game's present; the host and the menu have the same ids, the same room; the title's
|
||||
list has Save Select under Mods, which alone opens the file select there (nothing opens by itself); the menu restarts
|
||||
the game on the host's word as Restart now does, has the row and the page; and no save is opened by the host.
|
||||
|
||||
python -I -B tests/test_save_files.py [--cc gcc] [--cxx g++]
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
RUN_ALL_ARGS = ["--cc", "gcc", "--cxx", "g++"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def check(cond, what):
|
||||
if not cond:
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
|
||||
def block(text, marker):
|
||||
start = text.index(marker)
|
||||
end = text.index("{", start) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (text[end] == "{") - (text[end] == "}")
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
def run(command, says=None, **more):
|
||||
"""A compiler or a fixture run; a fixture must say `says`"""
|
||||
flags = (subprocess.CREATE_NO_WINDOW | subprocess.BELOW_NORMAL_PRIORITY_CLASS) if os.name == "nt" else 0
|
||||
result = subprocess.run(command, creationflags=flags, capture_output=True, text=True, encoding="utf-8", errors="replace", **more)
|
||||
check(result.returncode == 0 and (says is None or says in result.stdout),
|
||||
"%s:\n%s%s" % (" ".join(str(c) for c in command[:1] + command[-2:]), result.stdout, result.stderr))
|
||||
return result.stdout
|
||||
|
||||
|
||||
def number_of(text, name):
|
||||
return int(re.search(r"\b%s = (\d+)\b" % name, text).group(1))
|
||||
|
||||
|
||||
def check_sources():
|
||||
read = lambda *parts: ROOT.joinpath(*parts).read_text(encoding="utf-8")
|
||||
host, own, header, api = read("host", "hos_main.c"), read("host", "save_files.c"), read("host", "save_files.h"), read("gpu", "vk", "vk_api.h")
|
||||
native, rows, menu, replay = read("host", "nvn_native.c"), read("gpu", "vk", "save_file_rows.h"), read("gpu", "vk", "vk_menu.cpp"), read("gpu", "vk", "vk_replay.cpp")
|
||||
# the folder: chosen at the start, in a game folder, before the game's memory is made; a folder named with --user stays
|
||||
check("const int user_given = hos_user_dir != NULL; /* (--user) */" in host
|
||||
and "if (!user_given) hos_user_dir = hos_save_files_start(dir, hos_user_dir);" in host and host.count("hos_save_files_start(") == 1,
|
||||
"host/hos_main.c does not take the file's folder at the start, or takes it over --user")
|
||||
check(host.index("const int user_given = hos_user_dir != NULL;") < host.index("hos_save_files_start(dir, hos_user_dir)")
|
||||
< host.index('if (!hos_user_dir) hos_user_dir = "user";') < host.index("if (!reserve_guest())"),
|
||||
"the file's folder is not chosen before the game's memory is made")
|
||||
start = block(own, "const char *hos_save_files_start(")
|
||||
check(start.index("if (!hos_save_files_on()) return base_user;") < start.index("files_read();"), "triforce_files.txt is read with the save files off")
|
||||
check("on = !(e && e[0] == '0' && !e[1]);" in block(own, "int hos_save_files_on("), "the save files are not on unless HOS_SAVE_FILES=0")
|
||||
frame = block(own, "void hos_save_files_frame(")
|
||||
check(frame.index("if (!started) return;") < frame.index("rx_option("), "the menu is asked with the save files off")
|
||||
check("files.current = was, files.chosen = 0;" in frame, "a run does not go on with the file it started on")
|
||||
# no save is opened: a file's folder is listed, its files are not read
|
||||
# the game saves: a slot's file opened to be written tells the card which slot, from the game's file call and nowhere else
|
||||
fs = read("host", "nn_fs.c")
|
||||
opened = block(fs, "HLE(_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci) {")
|
||||
check("if (want_write) { void hos_save_card_wrote(const char *guest_path); hos_save_card_wrote(g); }" in opened
|
||||
and opened.index("if (want_write && !writable)") < opened.index("hos_save_card_wrote(g)") and fs.count("hos_save_card_wrote(g)") == 1,
|
||||
"host/nn_fs.c does not tell the slot the game saves in")
|
||||
check("const int slot = started ? save_card_slot_of(guest_path) : -1;" in block(own, "void hos_save_card_wrote("), "a slot is noted with the save files off")
|
||||
# (a slot's caption.sav is named for the menu, which reads the save's picture out of it; triforce_progress.txt is host/achievements.c's)
|
||||
for word in ("recomp_", "A64_PTR", "GP(", "a64_lookup", "CreateFileA", "ReadFile", "progress.sav"):
|
||||
check(word not in own, "host/save_files.c reaches into the game or a save: " + word)
|
||||
check(own.count("fopen(") == 4 and own.count("fread(") == 2 and own.count("files_path") >= 4 and own.count("card_path(") == 3,
|
||||
"host/save_files.c opens a file that is neither triforce_files.txt nor a file's triforce_card.txt")
|
||||
# a file's card: told from the running game at Link's update, not read out of a save; the switch first, a save loaded, nothing written
|
||||
update = block(host, "static void oot_update_player_cheats(")
|
||||
check("oot_save_card_tick(c, now);" in update and host.count("oot_save_card_tick(") == 2 and host.count("hos_save_card_note(") == 1,
|
||||
"host/hos_main.c does not tell a file's card at Link's update, from one place")
|
||||
card = block(host, "static void oot_save_card_tick(")
|
||||
check("if (!hos_save_files_on() || now < next) return;" in card and card.index("hos_save_files_on()") < card.index("oot_pouch_count(")
|
||||
and "if (oot_pouch_count(c, oot_item_names[0]) < 0) return;" in card and card.index("oot_pouch_count(") < card.index("hos_save_card_note("),
|
||||
"the game is asked for a file's card before the switch is, or while no save is loaded")
|
||||
life = block(host, "static int oot_max_life(")
|
||||
for word in ("recomp_store", "oot_gd_set", "oot_item_give", "oot_flag_set", "A64_PTR"):
|
||||
check(word not in card and word not in life, "telling a file's card writes into the game: " + word)
|
||||
items = dict(re.findall(r'OOT_ITEM\("[^"]+", "([^"]+)", ([01])\)', read("gpu", "vk", "oot_cheat_items.h")))
|
||||
held = re.findall(r'"((?:Item|Weapon|Armor)_\w+)"', card)
|
||||
check(len(held) == number_of(header, "SAVE_CARD_STONES") + number_of(header, "SAVE_CARD_MEDALS") == 9 and all(name in items for name in held)
|
||||
and [name.split("_")[1] for name in held] == ["Stone"] * 3 + ["Medal"] * 6,
|
||||
"the card's stones and medallions are not nine items gpu/vk/oot_cheat_items.h names, the stones first: %s" % held)
|
||||
check(number_of(header, "SAVE_CARD_STONES") == number_of(rows, "kStones") and number_of(header, "SAVE_CARD_MEDALS") == number_of(rows, "kMedals")
|
||||
and number_of(header, "SAVE_CARD_HEARTS") == number_of(rows, "kHearts") and number_of(header, "SAVE_CARD_PLACE") + 1 == number_of(rows, "kPlace"),
|
||||
"the host's card and the menu's have not the same room")
|
||||
load = block(menu, "void files_pictures_load(")
|
||||
check("save_file_rows::jpeg_in(" in load and "save_file_rows::caption_time(" in load and "mods::decode_image(" in load and load.index("if (p.state) continue;") < load.index("fopen(")
|
||||
and "if (from >= 0 && !t.after(latest)) continue;" in load and "if (known >= 0 && slot != known) continue;" in load
|
||||
and "fwrite" not in load and '"rb"' in load, "the menu does not read a save's picture once, from the file the host named, without writing")
|
||||
# named at the game's present, from one place
|
||||
present = block(native, "NV(nvnQueuePresentTexture) {")
|
||||
check("hos_save_files_frame();" in present and native.count("hos_save_files_frame();") == 1, "the save files are not named to the menu at the game's present")
|
||||
# the host and the menu: the same ids, bits and room
|
||||
enum = block(api, "enum { HOS_OPT_FILES_TEXT")
|
||||
names = re.findall(r"\bHOS_OPT_\w+", enum)
|
||||
check("HOS_OPT_FILES_TEXT = 180" in enum and names == ["HOS_OPT_FILES_TEXT", "HOS_OPT_FILES_ADD", "HOS_OPT_FILES_COUNT", "HOS_OPT_FILES_ASK", "HOS_OPT_FILES_SAID"],
|
||||
"the option ids are not 180 to 184")
|
||||
others = re.sub(r"enum \{ HOS_OPT_FILES_TEXT[^}]*\}", "", api)
|
||||
for value in range(180, 185):
|
||||
check(not re.search(r"= %d\b" % value, others), "another option has the id %d" % value)
|
||||
check("enum { HOS_FILE_SAVED = 1, HOS_FILE_CURRENT = 2, HOS_FILES_CHOSEN = 256 };" in api and "constexpr int kSaved = 1, kCurrent = 2;" in rows
|
||||
and "constexpr int kChosen = 256;" in rows, "the files' bits are not the same on both sides")
|
||||
number = lambda text, name: int(re.search(r"\b%s = (\d+)\b" % name, text).group(1))
|
||||
check(number(header, "SAVE_FILES") == number(rows, "kSlots") and number(header, "SAVE_FILE_NAME") + 1 == number(rows, "kName"),
|
||||
"the host's files and the menu's have not the same room")
|
||||
# the menu: told by the host, asks at the title once, restarts on the host's word, the row and the page
|
||||
check("if (id == HOS_OPT_FILES_ASK) return menu_take_file_ask();" in replay and "int menu_take_file_ask() { return save_files.take_ask(); }" in menu,
|
||||
"the renderer does not hand the file chosen to the host")
|
||||
setter = block(menu, "void menu_option_set(")
|
||||
for line in ("if (id == HOS_OPT_FILES_TEXT) return save_files.text(value);", "if (id == HOS_OPT_FILES_ADD) return save_files.add(value);",
|
||||
"save_files.done(value);", "save_files.said(value);"):
|
||||
check(line in setter, "the menu does not take the host's files: " + line)
|
||||
tick = block(menu, "void menu_tick() {")
|
||||
# the title: no page opens by itself; Save Select, an entry under Mods on the title's list, opens the file select
|
||||
check("files_offered" not in menu and tick.count("files_open(true)") == 2, "the file select opens by itself, or not from Save Select alone")
|
||||
shown = block(menu, "bool files_row_shown(")
|
||||
check("save_files.shown() > 0" in shown and "HOS_MODS_LIST_TITLE" in shown, "Save Select shows off the title, or before the host named the files")
|
||||
# (0.7.0: the title's entries are the game's own part, and the System list has Quit under Mods. Save Select is that second
|
||||
# entry on the title: the same part a pitch lower, mods_row_sel 1, the host's words 3 and 4)
|
||||
entry = block(menu, "void draw_title_files(")
|
||||
check(entry.index("std::swap(title_anim, files_title_anim);") < entry.index('title_label = "Save Select", title_entry = 1;') < entry.index("draw_title_mods(c, sel, cx, cy, k, pitch);")
|
||||
< entry.index('title_label = "Mods", title_entry = 0;') and entry.count("std::swap(title_anim, files_title_anim);") == 2,
|
||||
"Save Select is not the title's own entry with its own label and animation, or leaves Mods' changed")
|
||||
part = block(menu, "void draw_title_mods(ui::Ctx& c, bool sel, float cx, float cy, float k, float pitch) {")
|
||||
check("const char* const label = title_label;" in part and "menu_hit::kButton, title_entry);" in part
|
||||
and part.index("if (title_entry) return;") < part.index("mods_entry_px[0] ="), "Save Select has Mods' label, hit or place")
|
||||
row = block(menu, "void draw_mods_row(ui::Ctx& c, bool sel) {")
|
||||
check("if (files_row_shown()) draw_title_files(c, sel && mods_row_sel == 1, cx, cy - pitch, k, pitch), sel = sel && mods_row_sel == 0;" in row
|
||||
and row.index("draw_title_files(") < row.index("draw_title_mods(c, sel, cx, cy, k, pitch);"),
|
||||
"Save Select is not drawn a pitch under the title's Mods, the cursor on one of the two")
|
||||
cursor = tick[tick.index("} else if (open_now.load() && page == kModsRowPage) {"):tick.index("} else if (open_now.load() && page == kModsPage) {")]
|
||||
a_files, down_files = "} else if (press[7] && files_here && mods_row_sel == 1) {", "} else if (press[2] && files_here && mods_row_sel == 0) {"
|
||||
check("const bool files_here = files_row_shown();" in cursor and "if (!quit_here && !files_here) mods_row_sel = 0;" in cursor
|
||||
and cursor.index(a_files) < cursor.index(down_files) < cursor.index("} else if (press[7]) { // (A: Mods opens; on Quit its dialog)")
|
||||
and cursor.index(down_files) < cursor.index("} else if (press[1] && mods_row_sel == 1) {") < cursor.index("} else if (press[1] || press[5]"),
|
||||
"the cursor does not move between Mods and Save Select, or A on Save Select opens Mods or Quit's dialog")
|
||||
# (the Down that brought the cursor onto Mods is not also the entries' own: 0.7.0's entered_by_down)
|
||||
check(tick.index("if (entered_by_down) press[2] = false;") < tick.index("} else if (open_now.load() && page == kModsRowPage) {"),
|
||||
"the Down that comes onto Mods goes on to Save Select at once")
|
||||
enter = tick[tick.index("bool entered_by_down = false;"):tick.index("if (!open_now.load() || page != kModsPage) {")]
|
||||
check(enter.index("if (enter == 3 && !mods_title_list()) quit_open();") < enter.index("if (enter == 3 && files_row_shown()) files_open(true);"),
|
||||
"a click on Save Select does not open the file select, or opens Quit's dialog on the title")
|
||||
mouse = read("host", "oot_menu.c")
|
||||
list_tick = block(mouse, "static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {")
|
||||
check(list_tick.index("quit_entry = title ? (Rect){0, 0, 0, 0} :") < list_tick.index("if (title && hos_save_files_on()) {")
|
||||
< list_tick.index("quit_entry = (Rect){mx - 550, my - pitch / 2, mx + 550, my + pitch / 2};")
|
||||
and "my = (r.y0 + r.y1) / 2 - 2 * pitch;" in list_tick and "files_entry" not in mouse,
|
||||
"the host has no box for Save Select under the title's Mods, or has one with the save files off")
|
||||
check("(page == kFilesPage && files_at_title)" in block(menu, "int menu_mods_selected("), "the game is given input while the title's file select is open")
|
||||
word = tick[tick.index("if (const int said = save_files.take_said()) {"):]
|
||||
word = word[:word.index("if (!open_now.load() || page != kModsPage)")]
|
||||
check("if (said == save_file_rows::kRestart) {" in word and word.index("save();") < word.index("PostMessageA(window, WM_APP + 9, 0, 0);")
|
||||
and "pipeline_cache_save(true);" in word and "else files_failed = true;" in word,
|
||||
"the game is not restarted on the host's word as Restart now restarts it")
|
||||
page = tick[tick.index("} else if (open_now.load() && page == kFilesPage) {"):tick.index("} else if (open_now.load() && page == kAchPage) {")]
|
||||
check("if (files_wait >= 0) {}" in page and page.index("if (files_wait >= 0) {}") < page.index("else if (press[7]) {")
|
||||
and "if (save_files.choose(files_choice)) leave(true);" in page and "else files_wait = files_choice, changed = true;" in page,
|
||||
"a file can be chosen again while the host is asked, or this run's file is not played at once")
|
||||
table = menu[menu.index("Row rows[] = {"):]
|
||||
check(table.index('"Bug capture (F8)"') < table.index('{TAB_SYSTEM, "Save files", nullptr, 0, 0, 0, nullptr,') < table.index('MENU_HEADING(TAB_SYSTEM, "Mod cheats")')
|
||||
and 'constexpr char kFilesRow[] = "Save files";' in menu, "the Save files row is not on the System tab after Bug capture (F8)")
|
||||
check("(strcmp(rows[i].name, kFilesRow) || rows[i].tab != TAB_SYSTEM || save_files.shown() > 0) &&" in block(menu, "bool row_shown("),
|
||||
"the Save files row shows before the host named the files")
|
||||
press = tick[tick.index("else if (press[7] && is_files_row(r)) files_open(false)"):]
|
||||
check(press.index("is_files_row(r)") < press.index("else if (press[7] && !r.value && can_bind()) page = 1"),
|
||||
"the Save files row opens the Controls page: it is asked after the rows without a value")
|
||||
check("else if (page == kFilesPage) draw_files(k);" in block(menu, "void draw_menu(ui::Ctx& c, bool perf_under) {"), "the file select is not drawn")
|
||||
pages = [number(menu, name) for name in ("kFilesPage", "kAchPage", "kModsPage", "kModsRowPage")]
|
||||
check(len(set(pages + [0, 1, 3, 4, 5, 6])) == len(pages) + 6, "kFilesPage is another page's number")
|
||||
return api, own
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument("--cc", default="cc")
|
||||
p.add_argument("--cxx", default="c++")
|
||||
a = p.parse_args()
|
||||
api, own = check_sources()
|
||||
with tempfile.TemporaryDirectory(prefix="triforce-save-files-") as tmp:
|
||||
tmp = Path(tmp)
|
||||
warnings = ["-std=c11", "-Wall", "-Wextra", "-Werror"]
|
||||
exe = tmp / "form.exe"
|
||||
run([a.cc] + warnings + ["-I" + str(ROOT / "host"), str(ROOT / "tests" / "save_files_test.c"), "-o", str(exe)])
|
||||
run([str(exe)], says="PASS")
|
||||
exe = tmp / "rows.exe"
|
||||
run([a.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-I" + str(ROOT / "gpu" / "vk"), str(ROOT / "tests" / "save_file_rows_test.cpp"),
|
||||
"-o", str(exe)])
|
||||
run([str(exe)], says="PASS")
|
||||
# the host's side: host/save_files.c from after its includes on, with the menu's ids from vk_api.h
|
||||
marker = '#include "save_files.h"\n'
|
||||
check(own.count(marker) == 1, "host/save_files.c no longer includes save_files.h last")
|
||||
(tmp / "save_files_actual.inc").write_text(own[own.index(marker) + len(marker):], encoding="utf-8")
|
||||
(tmp / "save_files_constants.inc").write_text(
|
||||
"".join(block(api, start) + ";\n" for start in ("enum { HOS_OPT_FILES_TEXT = 180", "enum { HOS_FILE_SAVED = 1")), encoding="utf-8")
|
||||
exe = tmp / "host.exe"
|
||||
run([a.cc] + warnings + ["-Wno-unused-function", "-I" + str(ROOT / "host"), "-I" + str(tmp), str(ROOT / "tests" / "save_files_host_test.c"),
|
||||
"-o", str(exe)])
|
||||
game = tmp / "game folder"
|
||||
game.mkdir()
|
||||
kept = game / "triforce_files.txt"
|
||||
env = {k: v for k, v in os.environ.items() if k != "HOS_SAVE_FILES"}
|
||||
# ((Triforce) 11-23: on by default: off only with HOS_SAVE_FILES=0; the first start runs with it not set at all)
|
||||
run([str(exe), str(game), "off"], says="PASS", cwd=str(tmp), env=dict(env, HOS_SAVE_FILES="0"))
|
||||
check(not kept.exists(), "a file was written with the save files off")
|
||||
on = dict(env, HOS_SAVE_FILES="1")
|
||||
run([str(exe), str(game), "first"], says="PASS", cwd=str(tmp), env=env)
|
||||
run([str(exe), str(game), "second"], says="PASS", cwd=str(tmp), env=on)
|
||||
check(kept.read_text(encoding="utf-8").splitlines()[1:] == ["current=2", "1=File 1", "2=File 2", "3=File 3"], "triforce_files.txt after a choice was taken: %r" % kept.read_text(encoding="utf-8"))
|
||||
kept.write_bytes(b"current=2\r\nchosen=1000\r\n1=Spanky\r\n2=Bukwheat\r\n") # (the player's names, and a choice long past)
|
||||
# (file 2's card, as the host kept it in the file's folder, which it names with Windows' separator)
|
||||
if os.name == "nt":
|
||||
(game / "user-2").mkdir()
|
||||
with open(str(game) + "\\user-2\\triforce_card.txt", "wb") as f:
|
||||
f.write(b"# a note\r\nplace=Kokiri Forest\r\nitems=1c9\r\nhearts=7\r\n")
|
||||
run([str(exe), str(game), "third"], says="PASS", cwd=str(tmp), env=on)
|
||||
check(sorted(f.name for f in game.iterdir() if f.name != "user-2") == ["triforce_files.txt"], "the game folder has other files now: no folder is made for a file here")
|
||||
print("PASS: save files: triforce_files.txt, the files' folders, the host's naming and a file chosen for the next start, "
|
||||
"the menu's list and its file select, and off unless asked for")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -140,9 +140,9 @@ int main(int argc, char **argv) {
|
||||
/* a Commit killed before each of its steps, then the next start */
|
||||
int reached_end = 0;
|
||||
for (int at = 1; at <= 12 && !reached_end; at++) {
|
||||
char sub[32];
|
||||
snprintf(sub, sizeof sub, "%s\\k%d", argv[1], at);
|
||||
snprintf(user, sizeof user, "%s", sub);
|
||||
/* (each step its own folder: a 32-byte name cut every temporary path to the same C:\Users\<name>\AppData\Local\T,
|
||||
so the steps shared one folder there, and test runs at the same time wrote into each other's) */
|
||||
snprintf(user, sizeof user, "%s\\k%d", argv[1], at);
|
||||
save_tx_paths(&p, user, "0123456789abcdef0000000000000001");
|
||||
new_run();
|
||||
CHECK(save_tx_mount(&p, NULL, 0) == 1);
|
||||
|
||||
220
tests/test_screen_size.py
Normal file
220
tests/test_screen_size.py
Normal file
@@ -0,0 +1,220 @@
|
||||
"""The connected screens as the Windows host finds them (host/display.c hos_screens, hos_screen_size), for the Output
|
||||
resolution: every monitor's size in pixels, its own name, and which one the game's window opens on.
|
||||
|
||||
The window is made at CW_USEDEFAULT, after the game has taken its output size. Windows names the monitor it was started
|
||||
from in STARTUPINFO's hStdOutput when the shell started it from a taskbar or a jump list (and no standard handles are
|
||||
passed there): that monitor then, else the main one. A monitor's name is its EDID's, through the display configuration;
|
||||
one that has none (a laptop's panel) has an empty name. The functions themselves, cut out and run against stand-ins for
|
||||
the Windows calls they make, so the check runs on every OS:
|
||||
|
||||
python -I -B tests/test_screen_size.py [--cc gcc]
|
||||
"""
|
||||
import argparse
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cc", "gcc"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
FIXTURE = r'''
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "host/hos_screens.h"
|
||||
|
||||
/* ---- stand-ins for what host/display.c takes from windows.h ---- */
|
||||
typedef void *HANDLE, *HMONITOR, *HDC;
|
||||
typedef unsigned long DWORD;
|
||||
typedef long LONG;
|
||||
typedef int BOOL;
|
||||
typedef unsigned int UINT32, UINT;
|
||||
typedef intptr_t LPARAM;
|
||||
typedef uint16_t WCHAR;
|
||||
typedef struct { LONG left, top, right, bottom; } RECT, *LPRECT;
|
||||
typedef struct { DWORD cbSize; RECT rcMonitor, rcWork; DWORD dwFlags; } MONITORINFO;
|
||||
typedef struct { DWORD cbSize; RECT rcMonitor, rcWork; DWORD dwFlags; char szDevice[32]; } MONITORINFOEXA;
|
||||
typedef struct { DWORD cb; DWORD dwFlags; HANDLE hStdInput, hStdOutput, hStdError; } STARTUPINFOW;
|
||||
typedef struct { uint32_t LowPart; int32_t HighPart; } LUID;
|
||||
typedef struct { LUID adapterId; UINT32 id; } DISPLAYCONFIG_PATH_SOURCE_INFO, DISPLAYCONFIG_PATH_TARGET_INFO;
|
||||
typedef struct { DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo; DISPLAYCONFIG_PATH_TARGET_INFO targetInfo; UINT32 flags; } DISPLAYCONFIG_PATH_INFO;
|
||||
typedef struct { UINT32 infoType; } DISPLAYCONFIG_MODE_INFO;
|
||||
typedef struct { int type; UINT32 size; LUID adapterId; UINT32 id; } DISPLAYCONFIG_DEVICE_INFO_HEADER;
|
||||
typedef struct { DISPLAYCONFIG_DEVICE_INFO_HEADER header; WCHAR viewGdiDeviceName[32]; } DISPLAYCONFIG_SOURCE_DEVICE_NAME;
|
||||
typedef struct {
|
||||
DISPLAYCONFIG_DEVICE_INFO_HEADER header;
|
||||
struct { UINT32 friendlyNameFromEdid : 1; } flags;
|
||||
WCHAR monitorFriendlyDeviceName[64];
|
||||
} DISPLAYCONFIG_TARGET_DEVICE_NAME;
|
||||
#define CALLBACK
|
||||
#define TRUE 1
|
||||
#define STARTF_USESTDHANDLES 0x100
|
||||
#define MONITORINFOF_PRIMARY 1
|
||||
#define SM_CXSCREEN 0
|
||||
#define SM_CYSCREEN 1
|
||||
#define ERROR_SUCCESS 0
|
||||
#define QDC_ONLY_ACTIVE_PATHS 2
|
||||
#define CP_UTF8 65001
|
||||
enum { DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1, DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2 };
|
||||
|
||||
/* ---- the system: three monitors. The main one is second in the system's order; one has no name of its own ---- */
|
||||
static const struct {
|
||||
RECT at;
|
||||
int primary;
|
||||
const char *device, *name; /* (name NULL: none in its EDID) */
|
||||
} monitors[3] = {
|
||||
{{-3440, 160, 0, 1600}, 0, "\\\\.\\DISPLAY2", "LG ULTRAGEAR"},
|
||||
{{0, 0, 3840, 1600}, 1, "\\\\.\\DISPLAY1", "38GN950"},
|
||||
{{3840, 0, 5760, 1200}, 0, "\\\\.\\DISPLAY3", NULL},
|
||||
};
|
||||
static HMONITOR handle(int i) { return (HMONITOR)(uintptr_t)(0x10001 + i * 2); }
|
||||
static int monitor_of(HMONITOR m) {
|
||||
for (int i = 0; i < 3; i++)
|
||||
if (m == handle(i)) return i;
|
||||
return -1;
|
||||
}
|
||||
static STARTUPINFOW started;
|
||||
static int no_configuration; /* (1: the display configuration says nothing, as in a remote session) */
|
||||
static void GetStartupInfoW(STARTUPINFOW *si) { *si = started; }
|
||||
static BOOL GetMonitorInfoA(HMONITOR m, MONITORINFO *mi) {
|
||||
const int i = monitor_of(m);
|
||||
if (i < 0 || (mi->cbSize != sizeof(MONITORINFO) && mi->cbSize != sizeof(MONITORINFOEXA))) return 0;
|
||||
mi->rcMonitor = monitors[i].at, mi->dwFlags = monitors[i].primary ? MONITORINFOF_PRIMARY : 0;
|
||||
if (mi->cbSize == sizeof(MONITORINFOEXA)) snprintf(((MONITORINFOEXA *)mi)->szDevice, 32, "%s", monitors[i].device);
|
||||
return 1;
|
||||
}
|
||||
static int GetSystemMetrics(int i) { return i == SM_CXSCREEN ? 3840 : i == SM_CYSCREEN ? 1600 : -1; }
|
||||
static BOOL EnumDisplayMonitors(HDC dc, LPRECT clip, BOOL (*each)(HMONITOR, HDC, LPRECT, LPARAM), LPARAM param) {
|
||||
(void)dc, (void)clip;
|
||||
for (int i = 0; i < 3; i++)
|
||||
if (!each(handle(i), NULL, NULL, param)) break;
|
||||
return 1;
|
||||
}
|
||||
/* (the display configuration's paths: in another order than the monitors, each source with its GDI device) */
|
||||
static const int path_monitor[3] = {2, 0, 1};
|
||||
static LONG GetDisplayConfigBufferSizes(UINT32 flags, UINT32 *paths, UINT32 *modes) {
|
||||
if (flags != QDC_ONLY_ACTIVE_PATHS || no_configuration) return 1;
|
||||
*paths = 3, *modes = 6;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
static LONG QueryDisplayConfig(UINT32 flags, UINT32 *np, DISPLAYCONFIG_PATH_INFO *paths, UINT32 *nm, DISPLAYCONFIG_MODE_INFO *modes, void *topology) {
|
||||
(void)modes, (void)topology;
|
||||
if (flags != QDC_ONLY_ACTIVE_PATHS || *np < 3 || *nm < 6) return 1;
|
||||
for (UINT32 i = 0; i < 3; i++) {
|
||||
paths[i].sourceInfo.adapterId.LowPart = 7, paths[i].sourceInfo.id = 100 + i;
|
||||
paths[i].targetInfo.adapterId.LowPart = 7, paths[i].targetInfo.id = 200 + i;
|
||||
}
|
||||
*np = 3;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
static void widen(WCHAR *out, int cap, const char *text) {
|
||||
int i = 0;
|
||||
for (; text[i] && i + 1 < cap; i++) out[i] = (unsigned char)text[i];
|
||||
out[i] = 0;
|
||||
}
|
||||
static LONG DisplayConfigGetDeviceInfo(DISPLAYCONFIG_DEVICE_INFO_HEADER *h) {
|
||||
if (h->adapterId.LowPart != 7) return 1;
|
||||
if (h->type == DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME && h->size == sizeof(DISPLAYCONFIG_SOURCE_DEVICE_NAME) && h->id >= 100 && h->id < 103) {
|
||||
widen(((DISPLAYCONFIG_SOURCE_DEVICE_NAME *)h)->viewGdiDeviceName, 32, monitors[path_monitor[h->id - 100]].device);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
if (h->type == DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME && h->size == sizeof(DISPLAYCONFIG_TARGET_DEVICE_NAME) && h->id >= 200 && h->id < 203) {
|
||||
DISPLAYCONFIG_TARGET_DEVICE_NAME *t = (DISPLAYCONFIG_TARGET_DEVICE_NAME *)h;
|
||||
const char *name = monitors[path_monitor[h->id - 200]].name;
|
||||
t->flags.friendlyNameFromEdid = name != NULL;
|
||||
widen(t->monitorFriendlyDeviceName, 64, name ? name : "Generic PnP Monitor");
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
static int WideCharToMultiByte(UINT page, DWORD flags, const WCHAR *wide, int n, char *out, int cap, const char *dflt, BOOL *used) {
|
||||
int i = 0;
|
||||
(void)flags, (void)dflt, (void)used;
|
||||
if (page != CP_UTF8 || n != -1) abort(); /* (UTF-8, never the system's code page: tests/test_utf8_paths.py) */
|
||||
for (; wide[i]; i++) {
|
||||
if (i + 1 >= cap) return 0;
|
||||
out[i] = (char)wide[i];
|
||||
}
|
||||
out[i] = 0;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
@FUNCTIONS@
|
||||
|
||||
#define CHECK(x) do { if (!(x)) { fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); failed = 1; } } while (0)
|
||||
int main(void) {
|
||||
int failed = 0, w, h;
|
||||
HosScreen s[8];
|
||||
/* started from another program, or a shortcut on the main monitor: every monitor, the main one the window's */
|
||||
memset(&started, 0, sizeof started);
|
||||
CHECK(hos_screens(s, 8) == 3);
|
||||
CHECK(s[0].w == 3440 && s[0].h == 1440 && !s[0].opens && !strcmp(s[0].name, "LG ULTRAGEAR"));
|
||||
CHECK(s[1].w == 3840 && s[1].h == 1600 && s[1].opens && !strcmp(s[1].name, "38GN950"));
|
||||
CHECK(s[2].w == 1920 && s[2].h == 1200 && !s[2].opens && !strcmp(s[2].name, "")); /* (no name of its own: none) */
|
||||
w = h = -1, hos_screen_size(&w, &h);
|
||||
CHECK(w == 3840 && h == 1600);
|
||||
/* started from the first monitor's taskbar: the window opens there, whatever its place on the desktop */
|
||||
started.hStdOutput = handle(0);
|
||||
CHECK(hos_screens(s, 8) == 3 && s[0].opens && !s[1].opens && !s[2].opens);
|
||||
w = h = -1, hos_screen_size(&w, &h);
|
||||
CHECK(w == 3440 && h == 1440);
|
||||
/* standard handles passed (a console, a pipe): hStdOutput is one of them, not a monitor */
|
||||
started.dwFlags = STARTF_USESTDHANDLES;
|
||||
CHECK(hos_screens(s, 8) == 3 && !s[0].opens && s[1].opens);
|
||||
w = h = -1, hos_screen_size(&w, &h);
|
||||
CHECK(w == 3840 && h == 1600);
|
||||
/* a handle there that is no monitor: the main monitor */
|
||||
started.dwFlags = 0, started.hStdOutput = (HANDLE)&started;
|
||||
CHECK(hos_screens(s, 8) == 3 && s[1].opens);
|
||||
w = h = -1, hos_screen_size(&w, &h);
|
||||
CHECK(w == 3840 && h == 1600);
|
||||
/* fewer asked for than there are; and no display configuration: the sizes all the same, without names */
|
||||
memset(&started, 0, sizeof started);
|
||||
CHECK(hos_screens(s, 2) == 2 && s[1].opens);
|
||||
no_configuration = 1;
|
||||
CHECK(hos_screens(s, 8) == 3 && s[0].w == 3440 && !s[0].name[0] && !s[1].name[0] && s[1].opens);
|
||||
if (!failed) puts("screens: every monitor's size and name, and the one the window opens on");
|
||||
return failed;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cc", default="gcc")
|
||||
args = parser.parse_args()
|
||||
source = (ROOT / "host/display.c").read_text(encoding="utf-8")
|
||||
start = source.index("static HMONITOR shell_monitor(void) {")
|
||||
end = source.index("int hos_screens(HosScreen *out, int cap) {")
|
||||
functions = source[start:source.index("\n}\n", end) + 3]
|
||||
# the window is still made at the default position, which is what puts it on that monitor
|
||||
create = source[source.index("hwnd = CreateWindowA("):]
|
||||
if "WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,\n CW_USEDEFAULT," not in create[:create.index(";")]:
|
||||
raise SystemExit("FAIL: host/display.c no longer makes the window at CW_USEDEFAULT: hos_screen_size names another monitor")
|
||||
# the Linux window: SDL's displays, read on the main thread before the game; the main one is the window's
|
||||
sdl = (ROOT / "host/posix/display_sdl.c").read_text(encoding="utf-8")
|
||||
if "void hos_screen_size(int *w, int *h) { *w = hos_posix_window[1], *h = hos_posix_window[2]; }" not in sdl:
|
||||
raise SystemExit("FAIL: host/posix/display_sdl.c: hos_screen_size is not the desktop size hos_display_init read")
|
||||
init = sdl[sdl.index("int hos_display_init(void) {"):sdl.index("void hos_display_start(void) {")]
|
||||
if "screens_read(w, h);" not in init or "int hos_screens(HosScreen *out, int cap) {" not in sdl or "hos_sdl_displays(d, 16)" not in sdl:
|
||||
raise SystemExit("FAIL: host/posix/display_sdl.c does not read SDL's displays in hos_display_init for hos_screens")
|
||||
lib = (ROOT / "host/hos_sdl.c").read_text(encoding="utf-8")
|
||||
if 'three ? "SDL_GetDisplays" : "SDL_GetNumVideoDisplays"' not in lib or '"SDL_GetDisplayName"' not in lib:
|
||||
raise SystemExit("FAIL: host/hos_sdl.c does not list the displays with SDL3's and SDL2's own calls")
|
||||
applet = (ROOT / "host/nn_applet.c").read_text(encoding="utf-8")
|
||||
if "hos_screen_size(&sw, &sh);" not in applet:
|
||||
raise SystemExit("FAIL: host/nn_applet.c does not take the old Screen's size from hos_screen_size")
|
||||
with tempfile.TemporaryDirectory(prefix="screen-size-") as tmp:
|
||||
work = Path(tmp)
|
||||
c_file, exe = work / "fixture.c", work / "fixture.exe"
|
||||
c_file.write_text(FIXTURE.replace("@FUNCTIONS@", functions), encoding="utf-8")
|
||||
subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-I", str(ROOT), str(c_file), "-o", str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True)
|
||||
print("PASS: the connected screens: each monitor's size and name, and the one the window opens on (the shell's, else the "
|
||||
"main one)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -93,9 +93,9 @@ def main():
|
||||
"the storage alignment is not the larger of the texture's own and its slot's")
|
||||
applet = (HOST / "nn_applet.c").read_text(encoding="utf-8")
|
||||
pool = block(applet, "uint64_t hos_rt_pool_size(uint64_t game) {")
|
||||
check("__atomic_store_n(&rt_pool_pinned, e != NULL || v != asked || (is_five_k && scaled > five_k)," in pool and
|
||||
check("__atomic_store_n(&rt_pool_pinned, e != NULL || (is_five_k && v == five_k)," in pool and
|
||||
"static int rt_pool_pinned = -1;" in applet and "int hos_rt_pool_pinned(void) {" in applet,
|
||||
"the target heap does not say whether it is pinned (HOS_RT_POOL_MB, the 5120-wide cap), or not that it is not known yet")
|
||||
"the target heap does not say whether it is pinned (HOS_RT_POOL_MB, the picture pixel cap), or not that it is not known yet")
|
||||
dev = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
|
||||
check("`HOS_SHADOW_BUCKET=<step>`" in dev, "docs/development.md: HOS_SHADOW_BUCKET is not in the switches table")
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ no GPU.
|
||||
ultrawide sides, and HDR Native's picture goes through RGBA16F images; the bias is in the sampler's key and follows the
|
||||
upscaler each present, only in the draws into the scene (the flag from the draw's targets through build_descriptors,
|
||||
kept_texture's key and sampler_for's table to sampler_make; never a dispatch); the Sharpness row's text and default.
|
||||
((Triforce, 11-22, N64 Classic, step 3) And N64 Classic's texture blur: its look's positive bias while its 3D pass
|
||||
draws, taken as it is, never past the card's limit; with it, a draw of a scene's size and shape for the picture the
|
||||
pass drew is the scene (its pass notes both sizes), after the upscalers' own test of the scene.)
|
||||
The old lines fail.
|
||||
|
||||
python -I -B tests/test_sharpen_rules.py [--cxx g++]
|
||||
@@ -387,6 +390,22 @@ def checks(t):
|
||||
'sharpen_rules::lod_bias_switch(getenv("RX_VK_UPSCALE_LOD_BIAS"), &fixed)' in tick and
|
||||
"want = sharpen_rules::lod_bias_want(mode, fixed, upscale_lod_render.load(" in tick,
|
||||
"the bias does not follow the upscaler or RX_VK_UPSCALE_LOD_BIAS, or the samplers are not made anew")
|
||||
# ((Triforce, 11-22, N64 Classic, step 3) its texture blur: the look's positive bias while its 3D pass draws, taken as it is,
|
||||
# never past the card's limit; the scene by its size and shape for the picture its pass drew, which n64_upscale notes
|
||||
# with the scene's size; the upscalers' own path as it was
|
||||
check("const bool n64 = n64_3d_now();" in tick and
|
||||
"want = n64_rules::lod_bias(n64_look(), dev.props.limits.maxSamplerLodBias);" in tick and
|
||||
"const float next = n64 ? want : sharpen_rules::lod_bias_step(mode, now, want);" in tick and
|
||||
tick.index("const bool n64 = n64_3d_now();") < tick.index("} else if (!off && (temporal_wanted() || fsr3_wanted())) {"),
|
||||
"N64 Classic's blur is not the tick's while its 3D pass draws, or is not taken as it is")
|
||||
check("if (upscale_lod_bias.load(std::memory_order_relaxed) > 0.0f) {" in scene and
|
||||
"return n64_rules::scene_draw(w, h, (uint32_t)o, (uint32_t)(o >> 32));" in scene and
|
||||
scene.index("sharpen_rules::lod_scene_now(") < scene.index("n64_rules::scene_draw("),
|
||||
"with N64 Classic's blur, a draw of a scene's size and shape for its picture is not the scene")
|
||||
n64_up = function(draw, "static bool n64_upscale(")
|
||||
check("upscale_lod_note(in->width, in->height, ow);" in n64_up and
|
||||
"n64_lod_output.store((uint64_t)oh << 32 | ow, std::memory_order_relaxed);" in n64_up,
|
||||
"N64 Classic's pass does not note the scene's size and its picture's for the blur")
|
||||
check("upscale_lod_tick();" in t["replay"], "the bias is not taken at each present")
|
||||
check("void sampler_bias_changed() { samp_gen.fetch_add(1, std::memory_order_acq_rel); }" in t["bank"],
|
||||
"a change of the bias does not move the samplers' generation")
|
||||
@@ -425,6 +444,13 @@ MUTATIONS = [
|
||||
"color[i] = {at.width, at.height, 0};"),
|
||||
("descriptors across passes", "draw", " if (last_desc_scene != scene) last_desc_valid = false;\n", ""),
|
||||
("dispatch biased", "draw", " build_descriptors(s, p);\n", " build_descriptors(s, p, false, draw_in_scene(at));\n"),
|
||||
("N64 blur in the upscalers' quarters", "draw", "const float next = n64 ? want : sharpen_rules::lod_bias_step(mode, now, want);",
|
||||
"const float next = sharpen_rules::lod_bias_step(mode, now, want);"),
|
||||
("N64 blur never the scene", "draw", " return n64_rules::scene_draw(w, h, (uint32_t)o, (uint32_t)(o >> 32));\n",
|
||||
" return false;\n"),
|
||||
("N64 scene size not noted", "draw", " upscale_lod_note(in->width, in->height, ow);\n", ""),
|
||||
("N64 blur past the card", "draw", "want = n64_rules::lod_bias(n64_look(), dev.props.limits.maxSamplerLodBias);",
|
||||
"want = n64_look().lod_bias;"),
|
||||
("DLSS unsharpened", "temporal", "s.pre_picture = {picture,", "s.pre_picture = {s.output.view,"),
|
||||
("RCAS over HDR", "temporal", "temporal_sharpness() > 0.0f && sharpen_rules::lone_rcas(pre != nullptr, scene_rgba16f) &&\n",
|
||||
"temporal_sharpness() > 0.0f &&\n"),
|
||||
@@ -470,7 +496,8 @@ def main():
|
||||
subprocess.run([a.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-I", str(VK), str(cpp), "-o", str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True, timeout=60)
|
||||
print("PASS: Sharpness before the HUD (FSR 3.1's RCAS with its boost, FSR 4's own, RCAS over DLSS), none at the window "
|
||||
"then; FSR 1 only where it enlarges and off at 0; HDR Native through RGBA16F; the texture LOD bias under DLSS and FSR")
|
||||
"then; FSR 1 only where it enlarges and off at 0; HDR Native through RGBA16F; the texture LOD bias under DLSS and FSR, "
|
||||
"and N64 Classic's texture blur")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -128,6 +128,10 @@ int hos_ini_option(const char *key, int otherwise) { return strcmp(key, "steady_
|
||||
static int fps_max(void) { return 240; }
|
||||
static void movie_pace_decide(void) {} /* ((Triforce, 11-22, PRESENT-30) no movie plays here: paced by the cap) */
|
||||
static int pace_fps(void) { return fps_max(); }
|
||||
/* ((Triforce, 11-22, N64 Classic, step 7) its rate (nn_vi.c's, host/n64_pace.h's rule): none here, so the interval is as it
|
||||
was; tests/test_n64_pace.py runs it */
|
||||
static int n64_rate;
|
||||
static int n64_pace_interval(int rate, int interval) { return rate > 0 ? 1 : interval; }
|
||||
void hos_bench_present(int64_t now) { (void)now; } /* (benchmark mode's note of each present: not on here) */
|
||||
/* ---- host/nn_vi.c's state these functions use, and the rest of hos_vi_native_presented's stand-ins ---- */
|
||||
static volatile LONG64 presents;
|
||||
|
||||
@@ -87,7 +87,7 @@ def main():
|
||||
merged = (ROOT / "gpu" / "vk" / "merged_rows.h").read_text(encoding="utf-8")
|
||||
check('"stick_dead_zone"' in merged[merged.index("constexpr const char* kDropped[]"):], "an old stick_dead_zone= line is kept")
|
||||
check('if (!strcmp(line, "stick_dead_zone")) before7.stick_shared = atoi(eq + 1);' in menu and
|
||||
"merged_rows::migrate(version, before7, opts.output_res, opts.lstick_dead_zone, opts.rstick_dead_zone);" in menu,
|
||||
"merged_rows::migrate(legacy_output && version == 8 ? 7 : version, before7," in menu,
|
||||
"menu_init does not move an older file's shared dead zone into each stick's own")
|
||||
check("\n| Left stick dead zone, Right stick dead zone | Default (24%), or 0% to 50%" in readme,
|
||||
"readme.md's settings table has no Left and Right stick dead zone row")
|
||||
|
||||
@@ -100,6 +100,18 @@ static bool typed_upscale(VkCommandBuffer cmd,VkImageView input,VkImageView outp
|
||||
++upscale_calls;forwarded_cmd=cmd;forwarded_input=input;forwarded_output=output;forwarded_texture=out;
|
||||
forwarded_level=level;forwarded_key=key;forwarded_text=text;forwarded_temporal=temporal;return upscale_result;
|
||||
}
|
||||
/* ((Triforce, 11-22, N64 Classic) its 3D pass on (vk_n64.cpp n64_3d_now), and the pass itself (vk_draw.cpp n64_upscale),
|
||||
spied as typed_upscale is: it too is refused outside the recording lock */
|
||||
static bool n64_now;
|
||||
static bool n64_3d_now(){return n64_now;}
|
||||
static int n64_calls, n64_lock_depth=-1;
|
||||
static const Texture* n64_input;
|
||||
static VkImageView n64_in_view, n64_out_view;
|
||||
static bool n64_upscale(VkCommandBuffer,VkImageView input,const Texture* in,VkImageView output,Texture* out,uint32_t level){
|
||||
if(lock_depth<=0) return false;
|
||||
++n64_calls;n64_lock_depth=lock_depth;n64_input=in;n64_in_view=input;n64_out_view=output;forwarded_texture=out;
|
||||
forwarded_level=level;return upscale_result;
|
||||
}
|
||||
'''
|
||||
|
||||
SUFFIX = r'''
|
||||
@@ -147,6 +159,41 @@ int main(int argc,char** argv){
|
||||
printf("%s failures=%u eligible=%d\n",argv[1],failures,upscale_calls);
|
||||
return failures?1:0;
|
||||
}
|
||||
else if(!strcmp(argv[1],"n64")){
|
||||
/* ((Triforce, 11-22, N64 Classic) its 3D pass on, on a card that runs the networks: every gameplay network, by key or
|
||||
by its shape, is drawn by it and not by the stretch, over the upscaler Off too; its input is looked at for the
|
||||
grid's size; the picture is still taken for frame generation; a program that is no network is left alone */
|
||||
Shader::Backend::SPIRV::mma_software=false;
|
||||
dev.push_descriptor=true;dw().imgs={{11},{44}};
|
||||
NvnState state{};Stage stage;stage.info.texture_descriptors={{1,23}};stage.info.image_descriptors={{1,23}};
|
||||
auto run=[&](uint64_t key,bool matrix){Program q{key,{}};stage.info.uses_cooperative_matrix=matrix;q.stages.push_back(stage);
|
||||
return taau_stand_in(19,state,q);};
|
||||
const uint64_t networks[]={0xfd029a317a9a4b94ull,0x9dc98871eb7fc101ull};
|
||||
const uint64_t shares[]={0x6676619641320ba7ull,0xf10782f9e58b6a7cull,0x72ba090c70fe2614ull,0x0775215f8da720e6ull};
|
||||
check(!run(networks[0],true) && !n64_calls && !upscale_calls,"N64 Classic off: none of it");
|
||||
n64_now=true;
|
||||
int calls=0;
|
||||
for(uint64_t k:networks){
|
||||
const int hud=hudless_calls;
|
||||
check(run(k,true) && n64_calls==++calls && !upscale_calls,"N64 Classic: a gameplay network by key is drawn by its 3D pass, not the stretch");
|
||||
check(n64_lock_depth==1 && n64_in_view==11 && n64_out_view==44 && n64_input==&scene_texture && forwarded_texture==&texture &&
|
||||
forwarded_level==7,"N64 Classic: the network's input view and texture and its output, under the recording lock");
|
||||
check(hudless_calls==hud+1 && hudless_key==k && hudless_lock_depth==0,"N64 Classic: the picture is still taken for frame generation, outside the lock");
|
||||
}
|
||||
check(sample_view_calls==2,"N64 Classic: a network known by key has its input looked at, for the grid's size");
|
||||
for(uint64_t k:shares)check(run(k,true) && n64_calls==++calls && !upscale_calls,"N64 Classic: a share's network (by its shape) is drawn by its 3D pass");
|
||||
check(!run(0x1111111111111111ull,false) && n64_calls==calls,"N64 Classic: a program that is no network is left alone");
|
||||
scene_texture.format=VK_FORMAT_B10G11R11_UFLOAT_PACK32;
|
||||
check(!run(shares[0],true) && n64_calls==calls,"N64 Classic: a network of that shape whose input is not the scene's format is left alone");
|
||||
check(run(networks[0],true) && n64_calls==++calls,"N64 Classic: a network known by key is taken whatever its input's format");
|
||||
off_now=true;
|
||||
check(run(networks[1],true) && n64_calls==++calls && !upscale_calls,"N64 Classic over the upscaler Off");
|
||||
upscale_result=false;
|
||||
const int hud=hudless_calls;
|
||||
check(!run(networks[1],true) && hudless_calls==hud,"N64 Classic: when its pass draws nothing, nothing is taken and the game's network runs");
|
||||
printf("%s failures=%u eligible=%d\n",argv[1],failures,n64_calls);
|
||||
return failures?1:0;
|
||||
}
|
||||
else if(!strcmp(argv[1],"off-software")){
|
||||
/* (Off where the first network is already stood in for: Off's plain stretch, not the stand-in's FXAA) */
|
||||
dev.push_descriptor=true;dw().imgs={{11},{44}};off_now=true;
|
||||
@@ -228,13 +275,13 @@ def main():
|
||||
command = [args.cxx, '-std=c++17', '-Wall', '-Wextra', '-Werror', *args.cxx_arg, str(source), '-o', str(exe)]
|
||||
subprocess.run(command, cwd=folder, check=True)
|
||||
failed = False
|
||||
for case in ('software', 'hardware', 'no-f16', 'empty', 'disabled', 'custom', 'prefixes', 'off', 'off-software'):
|
||||
for case in ('software', 'hardware', 'no-f16', 'empty', 'disabled', 'custom', 'prefixes', 'off', 'off-software', 'n64'):
|
||||
result = subprocess.run([str(exe), case], cwd=folder)
|
||||
print(case, 'exit', result.returncode, flush=True)
|
||||
failed |= result.returncode != 0
|
||||
if failed:
|
||||
raise SystemExit(1)
|
||||
print('PASS: seven key configurations; rejected lookups removed, eligible per-call forwarding preserved; the upscaler Off')
|
||||
print('PASS: seven key configurations; rejected lookups removed, eligible per-call forwarding preserved; the upscaler Off; N64 Classic\'s 3D pass')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -81,7 +81,7 @@ void vkCmdBeginRendering(VkCommandBuffer, const VkRenderingInfo* ri) {
|
||||
calls += "[";
|
||||
}
|
||||
void vkCmdEndRendering(VkCommandBuffer) { calls += "]"; }
|
||||
''' + block(src, "void layout(VkCommandBuffer cmd,") + "\n" + block(src, "void record_to(VkCommandBuffer cmd,") + "\n" + block(src, "void record(VkCommandBuffer cmd,") + r'''
|
||||
''' + block(src, "void layout(VkCommandBuffer cmd,") + "\n" + block(src, "bool textures(VkCommandBuffer cmd, ImDrawData* dd) {") + "\n" + block(src, "void render_over(VkCommandBuffer cmd, VkImage image,") + "\n" + block(src, "void record_to(VkCommandBuffer cmd,") + "\n" + block(src, "void record(VkCommandBuffer cmd,") + r'''
|
||||
int main() {
|
||||
VkCommandBuffer cmd = (VkCommandBuffer)0x10;
|
||||
dev.swap_images = {(VkImage)0x100, (VkImage)0x101, (VkImage)0x102};
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
"""The Ultrawide row's shapes by name: the game's own 16:9, and a fixed 16:10, 21:9 or 32:9 for a screen or a window of that
|
||||
shape (the owner, 11-16: "remove monitors shape as a option keep 16:9 16:10 21:9 32:9"). An options file from before
|
||||
shape (the owner, 11-16: "remove monitors shape as a option keep 16:9 16:10 21:9 32:9"), and ((Triforce, 11-22, N64 Classic) a
|
||||
fixed 4:3, a TV's of 1998: the host's path for a shape narrower than 16:9, the HUD across the width). An options file from before
|
||||
options_version 6 whose row is 1 had the main monitor's shape, no longer a choice: it is read as the shape nearest the main
|
||||
monitor's (gpu/vk/ultrawide_rows.h). host/hos_main.c's own ultrawide_ratio and its widescreen sizes (the block
|
||||
tests/test_widescreen_shapes.py checks with screen ratios), cut out and run: the row's value, the file's version and the main
|
||||
monitor's size in, the picture, the scene, the camera's ratio and the HUD's share out. And the menu's side: the row's range, what
|
||||
it says for each value, and the old row's 1 read the same way in menu_init (gpu/vk/vk_menu.cpp).
|
||||
|
||||
The row is the shape of a 16:9 Output resolution. One that is not 16:9 (5120x1440, 5120x2160, a Screen or Custom of such a
|
||||
shape) is the picture by itself (gpu/vk/output_sizes.h): the host takes its shape before the row's, and the row then shows
|
||||
that shape with nothing to choose, instead of a value the game does not run. tests/test_output_resolution.py runs those.
|
||||
|
||||
python -I -B tests/test_ultrawide_shapes.py [--cc gcc] [--cxx g++]
|
||||
"""
|
||||
import argparse
|
||||
@@ -42,6 +47,7 @@ HOST = r'''
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gpu/vk/output_sizes.h"
|
||||
|
||||
volatile uint64_t hos_wide_out, hos_wide_scene;
|
||||
volatile float hos_wide_ratio, hos_wide_squeeze, hos_wide_margin;
|
||||
@@ -51,7 +57,7 @@ uint32_t hos_output_size(int height) { return height ? out_h : out_h * 16 / 9; }
|
||||
static void hos_log(const char *f, ...) { (void)f; }
|
||||
@ROWS@
|
||||
@RATIO@
|
||||
static void wide(float want) {
|
||||
static void wide(float want, int sized) {
|
||||
@SIZES@
|
||||
}
|
||||
|
||||
@@ -59,7 +65,7 @@ int main(int argc, char **argv) {
|
||||
if (argc < 6) return 2;
|
||||
out_h = (unsigned)atoi(argv[5]);
|
||||
const float want = ultrawide_ratio(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
|
||||
wide(want);
|
||||
wide(want, 0); /* (the row's shape, at a 16:9 Output resolution) */
|
||||
printf("%.4f %llux%llu %llux%llu %.4f %.4f %.4f %.4f\n", (double)want,
|
||||
(unsigned long long)(hos_wide_out & 0xffffffffu), (unsigned long long)(hos_wide_out >> 32),
|
||||
(unsigned long long)(hos_wide_scene & 0xffffffffu), (unsigned long long)(hos_wide_scene >> 32),
|
||||
@@ -80,23 +86,27 @@ MENU = r'''
|
||||
@HINT@
|
||||
int main() {
|
||||
CHECK(!std::strcmp(tx_ultrawide(0), "16:9") && !std::strcmp(tx_ultrawide(1), "16:10"));
|
||||
CHECK(!std::strcmp(tx_ultrawide(2), "21:9") && !std::strcmp(tx_ultrawide(3), "32:9"));
|
||||
CHECK(!std::strcmp(tx_ultrawide(2), "21:9") && !std::strcmp(tx_ultrawide(3), "32:9") && !std::strcmp(tx_ultrawide(4), "4:3"));
|
||||
CHECK(ultrawide_row_ratio(0) == 0.0f && ultrawide_row_ratio(1) == 1.6f && ultrawide_row_ratio(-2) == 0.0f); /* (the shapes' ratios) */
|
||||
/* (wider than 16:9, where the HUD position and the menu sides have sides to act on: 21:9 and 32:9, not 16:10) */
|
||||
CHECK(ultrawide_row_ratio(4) == (float)(4.0 / 3.0) && ultrawide_row_ratio(9) == (float)(4.0 / 3.0)); /* (4:3, the row's last) */
|
||||
/* (wider than 16:9, where the HUD position and the menu sides have sides to act on: 21:9 and 32:9, not 16:10 nor 4:3) */
|
||||
CHECK(!ultrawide_row_wider(0) && !ultrawide_row_wider(1) && ultrawide_row_wider(2) && ultrawide_row_wider(3));
|
||||
CHECK(!ultrawide_row_wider(-1) && ultrawide_row_wider(4));
|
||||
CHECK(!std::strcmp(tx_ultrawide(-1), "16:9") && !std::strcmp(tx_ultrawide(4), "32:9")); /* (past the row: its nearest end) */
|
||||
for (int v = 0; v <= 3; v++) CHECK(hn_ultrawide(v, -1) && hn_ultrawide(v, 0) == hn_ultrawide(v, -1) && !hn_ultrawide(v, 1));
|
||||
CHECK(!ultrawide_row_wider(-1) && !ultrawide_row_wider(4) && !ultrawide_row_wider(7));
|
||||
CHECK(!std::strcmp(tx_ultrawide(-1), "16:9") && !std::strcmp(tx_ultrawide(7), "4:3")); /* (past the row: its nearest end) */
|
||||
for (int v = 0; v <= 4; v++) CHECK(hn_ultrawide(v, -1) && hn_ultrawide(v, 0) == hn_ultrawide(v, -1) && !hn_ultrawide(v, 1));
|
||||
CHECK(std::strstr(hn_ultrawide(1, -1), "16:10") && std::strstr(hn_ultrawide(2, -1), "21:9") && std::strstr(hn_ultrawide(3, -1), "32:9"));
|
||||
for (int v = 1; v <= 3; v++) CHECK(std::strstr(hn_ultrawide(v, -1), "black bars"));
|
||||
CHECK(!hn_ultrawide(4, -1) && !hn_ultrawide(-1, -1));
|
||||
for (int v = 0; v <= 3; v++) CHECK(!std::strstr(tx_ultrawide(v), "onitor") && !std::strstr(hn_ultrawide(v, -1), "onitor"));
|
||||
CHECK(std::strstr(hn_ultrawide(4, -1), "4:3") && std::strstr(hn_ultrawide(4, -1), "HUD across"));
|
||||
for (int v = 1; v <= 4; v++) CHECK(std::strstr(hn_ultrawide(v, -1), "black bars"));
|
||||
CHECK(!hn_ultrawide(5, -1) && !hn_ultrawide(-1, -1));
|
||||
for (int v = 0; v <= 4; v++) CHECK(!std::strstr(tx_ultrawide(v), "onitor") && !std::strstr(hn_ultrawide(v, -1), "onitor"));
|
||||
/* (the old row's 1, Monitor's shape, read by the main monitor's shape before options_version 6; as chosen from 6 on) */
|
||||
CHECK(ultrawide_row_read(1, 5, 2560, 1440) == 0 && ultrawide_row_read(1, 5, 1920, 1200) == 1 && ultrawide_row_read(1, 5, 2560, 1600) == 1);
|
||||
CHECK(ultrawide_row_read(1, 5, 3440, 1440) == 2 && ultrawide_row_read(1, 5, 2560, 1080) == 2 && ultrawide_row_read(1, 5, 5120, 1440) == 3);
|
||||
CHECK(ultrawide_row_read(1, 5, 1024, 768) == 1 && ultrawide_row_read(1, 5, 0, 0) == 0 && ultrawide_row_read(1, 0, 3440, 1440) == 2);
|
||||
CHECK(ultrawide_row_read(1, 6, 3440, 1440) == 1 && ultrawide_row_read(1, 7, 2560, 1440) == 1);
|
||||
for (int r = 0; r <= 3; r++) if (r != 1) CHECK(ultrawide_row_read(r, 5, 3440, 1440) == r && ultrawide_row_read(r, 6, 1920, 1200) == r);
|
||||
for (int r = 0; r <= 4; r++) if (r != 1) CHECK(ultrawide_row_read(r, 5, 3440, 1440) == r && ultrawide_row_read(r, 6, 1920, 1200) == r);
|
||||
/* (an old file's Monitor's shape on a 4:3 monitor: still the nearest of the first four, as before the row had 4:3) */
|
||||
CHECK(ultrawide_row_read(1, 5, 1600, 1200) == 1);
|
||||
std::puts("ultrawide row: all checks passed");
|
||||
return 0;
|
||||
}
|
||||
@@ -120,24 +130,54 @@ def main():
|
||||
"hos_main.c does not take the picture's shape from the Ultrawide row")
|
||||
env = host.index('const char *e = getenv("HOS_ASPECT");')
|
||||
check("if (!e) {" in host[env:host.index("want = ultrawide_ratio(", env)], "HOS_ASPECT no longer goes over the Ultrawide row")
|
||||
# the Output resolution's own shape goes before the row's (the size is the picture), and the row is read only without one
|
||||
own = host[env:host.index("want = ultrawide_ratio(", env)]
|
||||
check("want = hos_output_ratio();" in own and "sized = want > 0.0f;" in own and "if (!e && !sized) {" in own,
|
||||
"hos_main.c does not take the Output resolution's own shape before the Ultrawide row's")
|
||||
check("if (output_picture(hos_output_size(1), want, sized, &ow, &oh)) {" in host,
|
||||
"hos_main.c does not make the picture with output_sizes.h's output_picture")
|
||||
menu = (ROOT / "gpu/vk/vk_menu.cpp").read_text(encoding="utf-8")
|
||||
# ((Triforce, options_version 7) the Ultrawide group's Aspect ratio row; its key is still ultrawide, which hos_main.c reads)
|
||||
row = re.search(r'\{TAB_DISPLAY, "Aspect ratio", &opts\.ultrawide, 0, 3, 1, tx_ultrawide,.*?hn_ultrawide, true\},', menu, re.S)
|
||||
check(row, "the Aspect ratio row is not 16:9, 16:10, 21:9, 32:9 with a restart")
|
||||
row = re.search(r'\{TAB_DISPLAY, "Aspect ratio", &opts\.ultrawide, 0, 4, 1, tx_shape,.*?hn_shape, true\},', menu, re.S)
|
||||
check(row, "the Aspect ratio row is not 16:9, 16:10, 21:9, 32:9, 4:3 with a restart")
|
||||
check('{"Aspect ratio", "ultrawide"}' in function(menu, "const char* ini_key(const Row& r) {"),
|
||||
"the Aspect ratio row is not kept as ultrawide=")
|
||||
# (its text and its line are the four shapes' while the row decides; what decides in its place is said, and the row fixed)
|
||||
check("if (owner == 0) return tx_ultrawide(v);" in function(menu, "const char* tx_shape(int v) {"),
|
||||
"the Ultrawide row does not show its own choice while it decides the shape")
|
||||
check("case 0: return hn_ultrawide(v, 0);" in function(menu, "const char* hn_shape(int v, int variant) {"),
|
||||
"the Ultrawide row's line is not its value's while it decides the shape")
|
||||
check('int shape_owner() { return getenv("HOS_ASPECT") ? 2 : output_shaped(opts.output_res) ? 1 : 0; }' in menu,
|
||||
"the menu does not take the shape's owner as the host does: HOS_ASPECT, the Output resolution's own shape, the row")
|
||||
check("if (value == &opts.ultrawide && shape_owner() != 0) return true;" in function(menu, "bool row_fixed(const int* value) {"),
|
||||
"the Ultrawide row can be changed while the Output resolution's own shape or HOS_ASPECT decides the picture's")
|
||||
check("Monitor's shape" not in function(menu, "const char* tx_ultrawide(int v) {"), "the Ultrawide row still offers Monitor's shape")
|
||||
# (the HUD position and the menu sides shown with a shape wider than 16:9 alone: 16:10, the row's 1, is narrower)
|
||||
shown = function(menu, "bool row_shown(int i) {")
|
||||
check("((rows[i].value != &opts.wide_hud && rows[i].value != &opts.wide_menus) || ultrawide_row_wider(opts.ultrawide))" in shown,
|
||||
check("((rows[i].value != &opts.wide_hud && rows[i].value != &opts.wide_menus) || (output_picture_of(opts.output_res, opts.ultrawide).w > output_picture_of(opts.output_res, opts.ultrawide).h * (16.0 / 9.0) * 1.01))" in shown,
|
||||
"row_shown does not show the HUD position and the menu sides with 21:9 and 32:9 alone")
|
||||
init = function(menu, "void menu_init() {")
|
||||
check("opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));"
|
||||
in init, "menu_init does not read an old file's Monitor's shape as the nearest shape, as the host does")
|
||||
# (with the main monitor the host reads it by, on every system: off Windows the renderer has no GetSystemMetrics and takes
|
||||
# the screen the window opens on from the host's list, which is what the host's GetSystemMetrics is there; it read 0 x 0,
|
||||
# and the menu showed 16:9 for a picture the host made 21:9)
|
||||
check("opts.ultrawide = ultrawide_row_read(opts.ultrawide, version, (int)main_screen().w, (int)main_screen().h);" in init,
|
||||
"menu_init does not read an old file's Monitor's shape as the nearest shape, as the host does")
|
||||
main_screen = function(menu, "Out main_screen() {")
|
||||
check("#ifdef _WIN32\n return Out{(uint32_t)std::max(GetSystemMetrics(SM_CXSCREEN), 0), (uint32_t)std::max(GetSystemMetrics(SM_CYSCREEN), 0)};\n"
|
||||
"#else\n return screen_opening() ? screen_opening()->native : Out{0, 0};\n#endif" in main_screen,
|
||||
"the menu's main monitor is not the host's: GetSystemMetrics on Windows, the screen the window opens on elsewhere")
|
||||
check(init.index("screen_add(list[i].w, list[i].h, list[i].name, list[i].opens != 0);") < init.index("opts.ultrawide = ultrawide_row_read("),
|
||||
"menu_init reads an old Ultrawide row before it has the host's screens")
|
||||
posix = (ROOT / "host/posix/win32_posix.c").read_text(encoding="utf-8")
|
||||
check("if (index == SM_CXSCREEN) return window_state()[1];" in posix and "if (index == SM_CYSCREEN) return window_state()[2];" in posix,
|
||||
"host/posix/win32_posix.c: GetSystemMetrics is no longer the desktop's main display, which the menu takes it to be")
|
||||
check(init.index("opts.output_res = output_file_read(opts.output_res, version, opts.ultrawide,") >
|
||||
init.index("opts.ultrawide = ultrawide_row_read("),
|
||||
"menu_init does not read an old file's 5120-wide output with the Ultrawide row as that file had it")
|
||||
readme = (ROOT / "readme.md").read_text(encoding="utf-8")
|
||||
check("| Aspect ratio | 16:9 (the game's own), 16:10, 21:9, 32:9" in readme, "readme.md's settings table does not list the Aspect ratio row's four shapes")
|
||||
check("| Aspect ratio | 16:9 (the game's own), 16:10, 21:9, 32:9, 4:3" in readme, "readme.md's settings table does not list the Aspect ratio row's five shapes")
|
||||
guide = (ROOT / "docs/development.md").read_text(encoding="utf-8")
|
||||
check("| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9 (before `options_version` 6, 1 was the monitor's shape" in guide,
|
||||
check("| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9, 4 4:3 (before `options_version` 6, 1 was the monitor's shape" in guide,
|
||||
"docs/development.md's options table has no ultrawide")
|
||||
|
||||
# (row, the options file's version, the main monitor, the output's height) -> the shape asked, the picture, the scene, the
|
||||
@@ -165,9 +205,14 @@ def main():
|
||||
# 32:9 by name
|
||||
((3, 6, 1920, 1080, 1440), "3.5556 5120x1440 3840x1080 3.5556 0.5000 0.2500 3.5556"),
|
||||
((3, 5, 2560, 1440, 1080), "3.5556 3840x1080 2880x810 3.5556 0.5000 0.2500 3.5556"),
|
||||
# ((Triforce, N64 Classic) 4:3 by name: the game's height, narrower, its cameras 4:3, the HUD across the whole width
|
||||
((4, 6, 1920, 1080, 1440), "1.3333 1920x1440 1440x1080 1.3333 1.0000 0.0000 1.3333"),
|
||||
((4, 6, 3440, 1440, 1440), "1.3333 1920x1440 1440x1080 1.3333 1.0000 0.0000 1.3333"),
|
||||
((4, 5, 1920, 1080, 1080), "1.3333 1440x1080 1080x810 1.3333 1.0000 0.0000 1.3333"),
|
||||
((4, 6, 1920, 1080, 1152), "1.3333 1536x1152 1152x864 1.3333 1.0000 0.0000 1.3333"),
|
||||
# a value past the row: its nearest end, as the menu reads it
|
||||
((-1, 6, 3440, 1440, 1440), "0.0000 0x0 0x0 0.0000 0.0000 0.0000 0.0000"),
|
||||
((7, 6, 1920, 1080, 1440), "3.5556 5120x1440 3840x1080 3.5556 0.5000 0.2500 3.5556"),
|
||||
((7, 6, 1920, 1080, 1440), "1.3333 1920x1440 1440x1080 1.3333 1.0000 0.0000 1.3333"),
|
||||
)
|
||||
with tempfile.TemporaryDirectory(prefix="ultrawide-") as tmp:
|
||||
work = Path(tmp)
|
||||
@@ -175,9 +220,8 @@ def main():
|
||||
source.write_text(HOST.replace("@ROWS@", rows_h)
|
||||
.replace("@RATIO@", function(host, "static float ultrawide_ratio(int row, int version, int screen_w, int screen_h) {"))
|
||||
.replace("@SIZES@", sizes(host)), encoding="utf-8")
|
||||
# (the header is pasted in, not included: the menu's own helpers in it, ultrawide_row_wider, go unused by the host's side)
|
||||
subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-variable", "-Wno-unused-function", str(source),
|
||||
"-o", str(exe), "-lm"], check=True)
|
||||
subprocess.run([args.cc, "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-variable", "-Wno-unused-function", "-I", str(ROOT),
|
||||
str(source), "-o", str(exe), "-lm"], check=True)
|
||||
bad = []
|
||||
for case, expect in cases:
|
||||
got = subprocess.run([str(exe)] + [str(v) for v in case], capture_output=True, text=True, check=True).stdout.strip()
|
||||
@@ -186,7 +230,7 @@ def main():
|
||||
if bad:
|
||||
raise SystemExit("FAIL:\n " + "\n ".join(bad))
|
||||
# at the 4K output the fixed shapes stay within 3840 x 2160's pixels (the render targets' pool)
|
||||
for r in (1, 2, 3):
|
||||
for r in (1, 2, 3, 4):
|
||||
got = subprocess.run([str(exe), str(r), "6", "1920", "1080", "2160"], capture_output=True, text=True, check=True).stdout.split()
|
||||
w, h = (int(v) for v in got[1].split("x"))
|
||||
check(w * h <= 3840 * 2160 and w % 8 == 0 and h % 8 == 0 and abs(w / h - float(got[0])) < 0.02,
|
||||
@@ -203,7 +247,7 @@ def main():
|
||||
.replace("@HINT@", hint.group(0)), encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", str(source), "-o", str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True)
|
||||
print("PASS: the Ultrawide row's 16:9, 16:10, 21:9 and 32:9, and an old file's monitor's shape read as the nearest of them")
|
||||
print("PASS: the Ultrawide row's 16:9, 16:10, 21:9, 32:9 and 4:3, and an old file's monitor's shape read as the nearest of the first four")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -47,6 +47,30 @@ int main() {
|
||||
want("Off, the listed network", choose(true, true, true, true), true, false, false);
|
||||
want("Off, a listed other program", choose(true, true, false, false), true, true, false);
|
||||
want("Off, a listed program of the shape", choose(true, true, false, true), true, true, false);
|
||||
// ((Triforce, 11-22, N64 Classic) its 3D pass on: every gameplay network, by key or by its shape, is its pass's, over Off and
|
||||
// over the list; anything else as without it, and without it every answer as the four-input rule's
|
||||
using upscale_off::Choice;
|
||||
const auto n64 = [](const char* what, Choice c, bool stand_in, bool by_shape, bool is_n64) {
|
||||
checks++;
|
||||
if (c.stand_in != stand_in || (stand_in && (c.temporal == is_n64 && is_n64)) || c.by_shape != by_shape || c.n64 != is_n64)
|
||||
fails++, printf("FAIL %s: stand_in %d temporal %d by_shape %d n64 %d\n", what, c.stand_in, c.temporal, c.by_shape, c.n64);
|
||||
};
|
||||
// listed off by_key shaped n64
|
||||
n64("N64, a network by key", choose(false, false, true, true, true), true, false, true);
|
||||
n64("N64, a network by key, any shape", choose(false, false, true, false, true), true, false, true);
|
||||
n64("N64, a share's network", choose(false, false, false, true, true), true, true, true);
|
||||
n64("N64, the listed network", choose(true, false, true, true, true), true, false, true);
|
||||
n64("N64, a listed program of the shape", choose(true, false, false, true, true), true, true, true);
|
||||
n64("N64 and Off, a network by key", choose(false, true, true, true, true), true, false, true);
|
||||
n64("N64, a program that is neither", choose(false, false, false, false, true), false, false, false);
|
||||
n64("N64, a listed other program", choose(true, false, false, false, true), true, false, false);
|
||||
bool same = true;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
const Choice a = choose(i & 1, i & 2, i & 4, i & 8), b = choose(i & 1, i & 2, i & 4, i & 8, false);
|
||||
same &= a.stand_in == b.stand_in && a.temporal == b.temporal && a.by_shape == b.by_shape && !a.n64 && !b.n64;
|
||||
}
|
||||
checks++;
|
||||
if (!same) fails++, printf("FAIL without N64 Classic the five-input rule is not the four-input one\n");
|
||||
if (fails) printf("upscale off: FAILED (%d of %d checks)\n", fails, checks);
|
||||
else printf("upscale off: all %d checks passed\n", checks);
|
||||
return fails != 0;
|
||||
@@ -69,7 +93,7 @@ def check_source():
|
||||
stand = function(draw, "bool taau_stand_in(VkCommandBuffer cmd, const NvnState& s, const Program& p) {")
|
||||
order = [stand.find(n) for n in (
|
||||
"const bool off = upscale_off_on();",
|
||||
"upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped);",
|
||||
"upscale_off::choose(taau_key(p.key), off, gameplay_network(p.key), shaped, n64);",
|
||||
"if (!ch.stand_in) return false;",
|
||||
"if (ch.by_shape) {",
|
||||
"if (!in || in->format != VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) return false;",
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
"""The HUD on a picture wider than 16:9 (host/oot_wide_hud.h, host/oot_wide_hud.c, nx2/prompt_assets.py HUD_SIDE_PANES).
|
||||
|
||||
With the Insert menu's Ultrawide HUD row on Screen edges the hearts and the item slot sit in the picture's top corners
|
||||
and the small map at its right edge; on Middle everything keeps the middle 16:9, as before. The rules checked here,
|
||||
Screen edges moves the side-anchored HUD panes and animation states. Middle keeps the HUD in the middle 16:9. The rules checked here,
|
||||
without the game:
|
||||
|
||||
- A layout in the middle: its projection times the squeeze, nothing moved. A kept one (a fade, a menu's background):
|
||||
untouched. A 16:9 picture (squeeze 1) or no squeeze: untouched.
|
||||
- A layout at an edge (the lab's switch): a point at the 16:9 grid's right edge lands on the picture's right edge, one
|
||||
at its left edge on the picture's left edge, and the layout keeps its shape.
|
||||
- A pane moved in a layout (the hearts', the item slot's, the small map's) goes as far as a whole layout moved by its
|
||||
- A pane moved in a layout goes as far as a whole layout moved by its
|
||||
projection: a corner pane lands on the picture's corner through the middle projection.
|
||||
- prompts/wide.bin: one entry per pane and copy of each layout, and one per animation key that puts a pane at the small
|
||||
map's place (the keys at 0 and other curves are left); a layout that is not the one known gives none.
|
||||
- prompts/wide.bin: one entry per pane and copy of each layout, and one per bound x key at an edge, with the endpoint delta
|
||||
adjusted where needed. A changed layout is skipped independently.
|
||||
|
||||
python -I -B tests/test_wide_hud.py
|
||||
"""
|
||||
from contextlib import redirect_stderr
|
||||
from io import StringIO
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
@@ -109,20 +110,49 @@ def layout(name, panes, curves=()):
|
||||
for k in range(n):
|
||||
struct.pack_into("<Q", b, names_at + 8 * k, offs[k])
|
||||
struct.pack_into("<Q", b, recs_at + 8 * k, rec0 + 0x44 * k)
|
||||
struct.pack_into("<f", b, rec0 + 0x44 * k + 0x10, 1.)
|
||||
struct.pack_into("<i", b, rec0 + 0x44 * k + 0x28, 0 if k else -1)
|
||||
struct.pack_into("<f", b, rec0 + 0x44 * k + 0x1c, xs[k])
|
||||
for last, keys in curves:
|
||||
bindings = {"DoCommand_00": [("PosType", 0x01600f7f)], "MapMenu_00": [("MapType", 0x0165177f), ("DungeonMiniMapPattern", 0x0165377f)],
|
||||
"SaveLoadIcon_00": [("EnableText", 0x01600f7f)]}
|
||||
for i, (last, keys) in enumerate(curves):
|
||||
b += bytes(-len(b) % 8)
|
||||
values = len(b)
|
||||
b += struct.pack("<ff", last, 0.0)
|
||||
b += struct.pack("<QII", len(b) + 16, 2 * len(keys), 4)
|
||||
for value, slope in keys:
|
||||
b += struct.pack("<ff", value, slope)
|
||||
if i < len(bindings.get(name, [])):
|
||||
anim, path = bindings[name][i]
|
||||
if name == "MapMenu_00":
|
||||
path = 0x01605f7f if anim == "MapType" else 0x0160677f
|
||||
b += b"\0"
|
||||
text = len(b)
|
||||
b += anim.encode() + b"\0"
|
||||
token = len(b)
|
||||
b += path.to_bytes(6, "little")
|
||||
b += bytes(-len(b) % 8)
|
||||
desc = len(b)
|
||||
channels = 1 if name == "SaveLoadIcon_00" else 2
|
||||
b += struct.pack("<Q4H", token, 0, 65535, channels, 14)
|
||||
curve = len(b)
|
||||
b += struct.pack("<QQ", 0, values)
|
||||
curves_at = [curve]
|
||||
if channels == 2:
|
||||
y_curve = len(b)
|
||||
b += struct.pack("<QQ", 0, y_curve + 16)
|
||||
b += struct.pack("<ffQIIff", 0, 0, y_curve + 40, 2, 4, -690, 0)
|
||||
curves_at.append(y_curve)
|
||||
tables = len(b)
|
||||
b += struct.pack("<Q", desc) + struct.pack(f"<{channels}Q", *curves_at)
|
||||
b += struct.pack("<QQIIQII", text, tables, 1, 8, tables+8, channels, 8)
|
||||
return bytes(b)
|
||||
|
||||
|
||||
GOOD = [("N_VRS_00", 1626.0), ("N_ScaleL_00", -1920.0), ("N_ScaleR_00", 1920.0), ("N_SubItemBaseFishing_00", 1270.0)]
|
||||
MAP = [("N_VRS_00", 1536.0), ("N_MiniMapCap_00", 1470.0), ("N_LocalMap_00", 0.0), ("N_ItemIcon_00", 1666.0),
|
||||
("N_Field_01", 1490.0), ("N_Dungeon_01", 1536.0), ("N_MiniMapReplace_00", 1470.0), ("P_MiniMapFrame_00", 1536.0),
|
||||
("S_Floor_00", 1706.0), ("P_CapDungeon_00", 1536.0), ("N_PatternFieldMini_01", 0.0)]
|
||||
("S_Floor_00", 1706.0), ("P_CapDungeon_00", 1536.0), ("N_MapIcon_00", 0.0), ("N_PatternDungeonMini_01", 0.0)]
|
||||
# (the icons' layers: at 0 for the whole-screen map's patterns, at the small map's place for its own; then two curves that
|
||||
# are not places: one with a slope, one with another value)
|
||||
MAP_CURVES = [(0.0, [(0.0, 0.0), (0.0, 0.0), (1490.0, 0.0), (1490.0, 0.0), (0.0, 0.0)]),
|
||||
@@ -134,7 +164,16 @@ MAP_CURVES = [(0.0, [(0.0, 0.0), (0.0, 0.0), (1490.0, 0.0), (1490.0, 0.0), (0.0,
|
||||
def archive(status=None, the_map=None):
|
||||
one = layout("PlayerStatus_00", GOOD) if status is None else status
|
||||
two = layout("MapMenu_00", MAP, MAP_CURVES) if the_map is None else the_map
|
||||
return b"SARC" + bytes(60) + layout("Other_00", [("N_ScaleL_00", -1920.0)]) + one + two + one + two
|
||||
extra = (layout("ActionGuideTips_00", [("N_Guide_00", -1140)]) +
|
||||
layout("Location_00", [("N_SmallDisplay_00", -1720), ("N_Large_00", 0)]) +
|
||||
layout("EventSkip_00", [("W_GuideBg_00", 2110), ("Pa_Skip_00", 1796)]) +
|
||||
layout("ChallengeAttention_00", [("N_Challenge_00", 660), ("T_Guide_00", 1716), ("T_Icon_00", 1770)]) +
|
||||
layout("PaNumDisplay_00", [("P_NumBase_00", 1360), ("P_NumBaseLine_00", 1360), ("P_BaseDecide_00", 1360),
|
||||
("N_IconPos_00", 1454), ("A_Num_00", 1482), ("N_PlusMinus_00", 1528)]) +
|
||||
layout("NumDisplay_00", [("Pa_Parts_00", 0), ("Pa_Parts_01", 0), ("A_Bottle_00", 1300)]) +
|
||||
layout("DoCommand_00", [("N_PosType_00", 234)], [(232, [(234, 0), (724, 0), (724, 0), (466, 0)])]) +
|
||||
layout("SaveLoadIcon_00", [("N_InOut_00", -1720)], [(-3460, [(1740, 0), (1740, 0), (-1720, 0)])]))
|
||||
return b"SARC" + bytes(60) + layout("Other_00", [("N_ScaleL_00", -1920.0)]) + one + two + extra + one + two + extra
|
||||
|
||||
|
||||
class WideHudTest(unittest.TestCase):
|
||||
@@ -158,12 +197,12 @@ class WideHudTest(unittest.TestCase):
|
||||
got = prompt_assets.wide_panes(blarc)
|
||||
# (the hearts' layout: four panes; the map's: eight panes, the two keys at 1490, the two at 1536 and that curve's
|
||||
# value past its last key; two copies of each)
|
||||
self.assertEqual(len(got), 2 * (4 + 8 + 2 + 2 + 1))
|
||||
self.assertEqual(len(got), 2 * (4 + 8 + 2 + 2 + 1 + 17))
|
||||
for off, side, x in got:
|
||||
self.assertEqual(struct.unpack_from("<f", blarc, off)[0], x)
|
||||
self.assertNotEqual(x, 0.0)
|
||||
self.assertEqual({x for _, side, x in got if side < 0}, {-1920.0})
|
||||
self.assertEqual({x for _, side, x in got if side > 0}, {1920.0, 1626.0, 1270.0, 1536.0, 1470.0, 1490.0, 1706.0})
|
||||
|
||||
self.assertEqual({x for _, side, x in got if side < 0}, {-1920.0, -1720.0, -1140.0, -3460})
|
||||
self.assertEqual({x for _, side, x in got if side > 0}, {1920.0, 1626.0, 1270.0, 1536.0, 1470.0, 1490.0, 1706.0, 2110, 1796, 660, 1716, 1770, 1740, 0, 724, 1300})
|
||||
first = blarc.index(layout("PlayerStatus_00", GOOD))
|
||||
self.assertTrue(all(off >= first for off, _, _ in got)) # (the other layout's pane of the same name: left)
|
||||
self.assertNotIn(1666.0, {x for _, _, x in got}) # (the whole-screen map's own pane: left)
|
||||
@@ -177,25 +216,99 @@ class WideHudTest(unittest.TestCase):
|
||||
self.assertEqual(len(raw), 8 + 12 * len(got))
|
||||
self.assertEqual(struct.unpack_from("<Ib3xf", raw, 8), got[0])
|
||||
|
||||
def test_parent_grid(self):
|
||||
lay = bytearray(layout("HUD", [("Parent", 1520), ("Child", -130)]))
|
||||
records = list(prompt_assets.layout_panes(lay).values())
|
||||
struct.pack_into("<i", lay, records[2] + 0x28, 1)
|
||||
self.assertEqual(prompt_assets.hud_grid_x(lay, records, records[2]), 1390)
|
||||
self.assertIsNone(prompt_assets.hud_grid_x(lay, records, records[2], {records[1]}))
|
||||
struct.pack_into("<f", lay, records[1] + 0x10, 2.)
|
||||
self.assertIsNone(prompt_assets.hud_grid_x(lay, records, records[2]))
|
||||
|
||||
def test_keys(self):
|
||||
lay = layout("MapMenu_00", MAP, MAP_CURVES)
|
||||
keys = prompt_assets.layout_keys(lay, {1490.0, 1536.0})
|
||||
self.assertEqual(sorted(struct.unpack_from("<f", lay, o)[0] for o in keys), [1490.0, 1490.0, 1536.0, 1536.0, 1536.0])
|
||||
self.assertEqual(prompt_assets.layout_keys(lay, {1.0, 2.0}), []) # (a curve with a slope is no place)
|
||||
self.assertEqual(prompt_assets.layout_keys(lay, {1.0}), []) # (nor one with another value among them)
|
||||
self.assertEqual(prompt_assets.hud_translation_path(82), 0x0165177f)
|
||||
self.assertEqual(prompt_assets.hud_translation_path(86), 0x0165377f)
|
||||
path = prompt_assets.hud_translation_path(list(prompt_assets.layout_panes(lay)).index("N_MapIcon_00"))
|
||||
keys = prompt_assets.hud_track_keys(lay, "MapType", path, {1490: 1}, 2)
|
||||
self.assertEqual(list(keys.values()), [(1, 1490)] * 2)
|
||||
self.assertIsNone(prompt_assets.hud_track_keys(lay, "MapType", 0x0165377f, {1490: 1}, 2))
|
||||
wrong_attr = lay.replace(struct.pack("<4H", 0, 65535, 2, 14), struct.pack("<4H", 0, 65535, 2, 15))
|
||||
self.assertIsNone(prompt_assets.hud_track_keys(wrong_attr, "MapType", path, {1490: 1}, 2))
|
||||
|
||||
def test_track_guards(self):
|
||||
name = "MapMenu_00"
|
||||
sides = prompt_assets.HUD_SIDE_PANES[name]
|
||||
def rows(blob):
|
||||
return prompt_assets.wide_layout(blob, name, sides)
|
||||
def parent(child, ancestor):
|
||||
lay = bytearray(layout(name, MAP, MAP_CURVES))
|
||||
panes = prompt_assets.layout_panes(lay)
|
||||
struct.pack_into("<i", lay, panes[child] + 0x28, list(panes).index(ancestor))
|
||||
return lay
|
||||
self.assertTrue(rows(parent("N_PatternDungeonMini_01", "N_MapIcon_00")))
|
||||
self.assertIsNone(rows(parent("N_MapIcon_00", "N_PatternDungeonMini_01")))
|
||||
self.assertIsNone(rows(parent("N_Field_01", "N_MapIcon_00")))
|
||||
lay = layout(name, MAP, MAP_CURVES)
|
||||
for fields in [(0, 0, 2, 14), (0, 65535, 1, 14), (1, 65535, 2, 14)]:
|
||||
self.assertIsNone(rows(lay.replace(struct.pack("<4H", 0, 65535, 2, 14), struct.pack("<4H", *fields))))
|
||||
self.assertTrue(rows(layout(name, MAP, [(0, [(0, 0), (1490, 0), (0, 0)]), *MAP_CURVES[1:]])))
|
||||
for slopes in [(1, 0), (0, 1)]:
|
||||
ramp = [(0, slopes[0]), (1490, slopes[1]), (0, 0)]
|
||||
self.assertIsNone(rows(layout(name, MAP, [(0, ramp), *MAP_CURVES[1:]])))
|
||||
|
||||
def test_static_guards(self):
|
||||
name = "ActionGuideTips_00"
|
||||
sides = prompt_assets.HUD_SIDE_PANES[name]
|
||||
def guide(x):
|
||||
return layout(name, [("N_Guide_00", x)])
|
||||
self.assertIsNone(prompt_assets.wide_layout(guide(-640), name, sides))
|
||||
self.assertTrue(prompt_assets.wide_layout(guide(-641), name, sides))
|
||||
self.assertIsNone(prompt_assets.wide_layout(guide(-641) + bytes.fromhex("7f0f60010000"), name, sides))
|
||||
duplicate = layout(name, [("N_Guide_00", -642), ("N_Guide_00", -641)])
|
||||
last = prompt_assets.layout_panes(duplicate)["N_Guide_00"]
|
||||
self.assertEqual(struct.unpack_from("<f", duplicate, last + 0x1c)[0], -641)
|
||||
self.assertIsNone(prompt_assets.wide_layout(duplicate, name, sides))
|
||||
good = archive()
|
||||
removed = prompt_assets.wide_layout(good, name, sides)
|
||||
expected = [entry for entry in prompt_assets.wide_panes(good) if entry not in removed]
|
||||
self.assertEqual(prompt_assets.wide_panes(good.replace(guide(-1140), guide(-640))), expected)
|
||||
|
||||
def test_ring_clash_and_independent_layout_failure(self):
|
||||
good = archive()
|
||||
def entries(name):
|
||||
return set(prompt_assets.wide_layout(good, name, prompt_assets.HUD_SIDE_PANES[name]))
|
||||
action = entries("DoCommand_00")
|
||||
tips = entries("ActionGuideTips_00")
|
||||
all_entries = prompt_assets.wide_panes(good)
|
||||
off = min(action)[0]
|
||||
ring = [(0, 0, 0, [(off + 3, b"x")])]
|
||||
bad = good.replace(layout("ActionGuideTips_00", [("N_Guide_00", -1140)]),
|
||||
layout("ActionGuideTips_00", [("N_Guide_00", -640)]))
|
||||
for blob, omitted in [(good, action), (bad, action | tips)]:
|
||||
log = StringIO()
|
||||
with redirect_stderr(log):
|
||||
self.assertEqual(prompt_assets.wide_panes(blob, ring), [e for e in all_entries if e not in omitted])
|
||||
self.assertIn("DoCommand_00: HUD edge position overlaps a Talk ring run", log.getvalue())
|
||||
self.assertEqual("ActionGuideTips_00: unknown HUD layout" in log.getvalue(), blob == bad)
|
||||
|
||||
def test_unknown_layout(self):
|
||||
self.assertIsNone(prompt_assets.wide_panes(b"SARC" + bytes(60))) # (no such layout)
|
||||
self.assertIsNone(prompt_assets.wide_panes(archive(status=layout("PlayerStatus_00", GOOD[:3])))) # (a pane missing)
|
||||
def status(blob):
|
||||
return prompt_assets.wide_layout(blob, "PlayerStatus_00", prompt_assets.HUD_SIDE_PANES["PlayerStatus_00"])
|
||||
def map_rows(blob):
|
||||
return prompt_assets.wide_layout(blob, "MapMenu_00", prompt_assets.HUD_SIDE_PANES["MapMenu_00"])
|
||||
self.assertTrue(prompt_assets.wide_panes(archive(the_map=b""))) # other layouts survive a missing map
|
||||
self.assertIsNone(status(archive(status=layout("PlayerStatus_00", GOOD[:3])))) # (a pane missing)
|
||||
moved = [(n, 1800.0 if n == "N_ScaleR_00" else x) for n, x in GOOD]
|
||||
self.assertIsNone(prompt_assets.wide_panes(archive(status=layout("PlayerStatus_00", moved)))) # (not at the corner)
|
||||
self.assertIsNone(status(archive(status=layout("PlayerStatus_00", moved)))) # (not at the corner)
|
||||
twice = layout("PlayerStatus_00", GOOD + [("N_Other_00", 1270.0)])
|
||||
self.assertIsNone(prompt_assets.wide_panes(archive(status=twice))) # (a place held elsewhere)
|
||||
self.assertIsNone(status(archive(status=twice))) # (a place held elsewhere)
|
||||
other = layout("MapMenu_00", MAP + [("N_Else_00", 1706.0)], MAP_CURVES)
|
||||
self.assertIsNone(prompt_assets.wide_panes(archive(the_map=other))) # (the same, the map's)
|
||||
self.assertIsNone(map_rows(archive(the_map=other))) # (the same, the map's)
|
||||
ramp = layout("MapMenu_00", MAP, MAP_CURVES + [(0.0, [(0.0, 0.0), (1536.0, 3.0)])])
|
||||
self.assertIsNone(prompt_assets.wide_panes(archive(the_map=ramp))) # (a key that moves there)
|
||||
self.assertIsNone(prompt_assets.wide_panes(archive(the_map=b""))) # (no map layout)
|
||||
self.assertIsNone(map_rows(archive(the_map=ramp))) # (a key that moves there)
|
||||
self.assertIsNone(map_rows(archive(the_map=b""))) # (no map layout)
|
||||
self.assertIsInstance(prompt_assets.WIDE, float) # (the icons' own constant: a table of this file once took its name)
|
||||
|
||||
def test_wired(self):
|
||||
|
||||
100
tests/test_wide_sides.py
Normal file
100
tests/test_wide_sides.py
Normal file
@@ -0,0 +1,100 @@
|
||||
"""Ultrawide's menu sides: when the renderer shows them (gpu/vk/wide_sides_rule.h, vk_framegen.cpp wide_sides).
|
||||
|
||||
Seen in the game at 3840x1600 with Ultrawide menus on Centred: the file select over the title showed its blurred backdrop
|
||||
in the middle 16:9 and the sharp title movie at both sides. The host gave the margin; the renderer turned its sides off two
|
||||
presents after turning them on, because the file select's backdrop is drawn by the program that also draws the item
|
||||
wheel's background, and a frame that draws that was taken for the item wheel, whose background keeps the whole picture
|
||||
and gets no sides. The rule, compiled alone and run:
|
||||
|
||||
- play (the world drawn): no sides; a menu with no world (the pause menu, the map): the row's sides;
|
||||
- the item wheel (the blur of the last picture drawn, no centred menu): none, as before;
|
||||
- the same blur drawn while the host says a menu with the centred backdrop runs (the file select): the row's sides;
|
||||
- the row on Full width, a 16:9 picture, or no margin from the host (the filled title movie alone): none, whatever is drawn.
|
||||
|
||||
And the wiring by the source: wide_sides asks the host (MkwVkHost.wide_backdrop, the interface's version with it) and
|
||||
decides by the rule; host/rx_backend.c answers with host/oot_title_movie.c's menu screens.
|
||||
|
||||
python -I -B tests/test_wide_sides.py [--cxx g++]
|
||||
"""
|
||||
import argparse
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
FIXTURE = r'''
|
||||
#include <cstdio>
|
||||
#include "gpu/vk/wide_sides_rule.h"
|
||||
using mkwvk::wide_sides_rule::show;
|
||||
static int failed;
|
||||
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL:%d %s\n", __LINE__, #x); failed = 1; } } while (0)
|
||||
int main() {
|
||||
const float margin = (1.0f - (16.0f / 9.0f) / 2.4f) / 2.0f; // (3840x1600)
|
||||
const int64_t never = 0;
|
||||
for (int row = 1; row <= 2; row++) { // (out of focus, black)
|
||||
// play: the world drawn this frame, or within the grace
|
||||
for (int64_t ago = 0; ago <= 3; ago++) CHECK(show(row, margin, 1000, 1000 - ago, never, false) == 0);
|
||||
CHECK(show(row, margin, 1000, 1000, never, true) == 0); // (whatever the host says of the menus)
|
||||
// a menu with no world: the pause menu, the map, a loading screen
|
||||
CHECK(show(row, margin, 1000, 996, never, false) == row);
|
||||
CHECK(show(row, margin, 1000, 996, 996, false) == row); // (a blur long ago)
|
||||
// the item wheel: the blur of the last picture, no centred menu
|
||||
for (int64_t ago = 0; ago <= 3; ago++) CHECK(show(row, margin, 1000, 900, 1000 - ago, false) == 0);
|
||||
// the file select over the title, as in the run: the sides on at present 3087, the blur drawn from 3089 on, the
|
||||
// world never drawn, the menu's screen running throughout
|
||||
for (int64_t now = 3087; now <= 4772; now += 5) CHECK(show(row, margin, now, never, now >= 3089 ? now : never, true) == row);
|
||||
// and what turned them off there: the same frames without the host's word
|
||||
CHECK(show(row, margin, 3087, never, never, false) == row && show(row, margin, 3089, never, 3089, false) == 0);
|
||||
// the title alone: no margin from the host
|
||||
CHECK(show(row, 0.0f, 3000, never, never, false) == 0 && show(row, 0.0f, 3000, never, 3000, true) == 0);
|
||||
}
|
||||
// the row on Full width, and a 16:9 picture
|
||||
CHECK(show(0, margin, 1000, 900, never, false) == 0 && show(0, margin, 1000, 900, 1000, true) == 0);
|
||||
CHECK(show(1, 0.0f, 1000, 900, never, false) == 0 && show(1, -0.1f, 1000, 900, never, false) == 0);
|
||||
if (!failed) std::puts("wide sides: play, a menu, the item wheel, a centred backdrop drawn by the wheel's program");
|
||||
return failed;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def check(cond, what):
|
||||
if not cond:
|
||||
raise SystemExit("FAIL: " + what)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cxx", default="g++")
|
||||
args = parser.parse_args()
|
||||
framegen = (ROOT / "gpu/vk/vk_framegen.cpp").read_text(encoding="utf-8")
|
||||
start = framegen.index("WideSides wide_sides() {")
|
||||
sides = framegen[start:framegen.index("\n}\n", start)]
|
||||
check("const bool centred_menu = host->wide_backdrop && host->wide_backdrop() != 0;" in sides,
|
||||
"wide_sides does not ask the host whether a menu with the centred backdrop runs")
|
||||
check("wide_sides_rule::show(opts.wide_menus, margin, presents_now, world_drawn_at.load(std::memory_order_relaxed),\n"
|
||||
" wheel_drawn_at.load(std::memory_order_relaxed), centred_menu);" in sides,
|
||||
"wide_sides does not decide by wide_sides_rule.h")
|
||||
check("presents_now - wheel_drawn_at" not in sides, "wide_sides still takes every blur of the last picture for the item wheel")
|
||||
draw = (ROOT / "gpu/vk/vk_draw.cpp").read_text(encoding="utf-8")
|
||||
check("if (cp->key == 0x02ff9920c2571cc2ULL) wheel_drawn_at.store(presents_now, std::memory_order_relaxed);" in draw,
|
||||
"vk_draw.cpp no longer notes the blur of the last picture")
|
||||
api = (ROOT / "gpu/vk/vk_api.h").read_text(encoding="utf-8")
|
||||
check(" int (*wide_backdrop)(void);\n} MkwVkHost;" in api and "#define MKWVK_API_VERSION 18" in api,
|
||||
"vk_api.h: MkwVkHost does not end with wide_backdrop at version 18")
|
||||
backend = (ROOT / "host/rx_backend.c").read_text(encoding="utf-8")
|
||||
check("return oot_menu_backdrop_runs() || rx_option(HOS_OPT_MODS_MUSIC, 0) == 2;" in backend and
|
||||
"hos_bench_state, hos_prompts_pad_face, host_screens, host_wide_backdrop,\n};" in backend,
|
||||
"rx_backend.c does not answer wide_backdrop with the menu screens that run, at the table's end")
|
||||
with tempfile.TemporaryDirectory(prefix="wide-sides-") as tmp:
|
||||
source, exe = Path(tmp) / "fixture.cpp", Path(tmp) / "fixture.exe"
|
||||
source.write_text(FIXTURE, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++17", "-Wall", "-Wextra", "-Werror", "-I", str(ROOT), str(source), "-o", str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True)
|
||||
print("PASS: ultrawide's menu sides for play, a menu, the item wheel, and a centred backdrop the wheel's program draws")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,5 +1,7 @@
|
||||
"""host/hos_main.c's widescreen sizes, game-free: the picture, scene, camera ratio and HUD for screens wider and
|
||||
narrower than 16:9 (a 4:3 CRT, 16:10, 5:4 and narrower, 21:9, 32:9), and the game's own picture for 16:9.
|
||||
narrower than 16:9 (a 4:3 CRT, 16:10, 5:4 and narrower, 21:9, 32:9), and the game's own picture for 16:9. A shape of the
|
||||
Ultrawide row's or HOS_ASPECT's is kept to 3840x2160's pixels; an Output resolution of its own shape (3840x1600, 5120x2160)
|
||||
is the picture, pixel for pixel (gpu/vk/output_sizes.h output_picture).
|
||||
|
||||
python -I -B tests/test_widescreen_shapes.py [--cc gcc]
|
||||
"""
|
||||
@@ -32,6 +34,7 @@ def main():
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gpu/vk/output_sizes.h"
|
||||
|
||||
volatile uint64_t hos_wide_out, hos_wide_scene;
|
||||
volatile float hos_wide_ratio, hos_wide_squeeze, hos_wide_margin;
|
||||
@@ -40,13 +43,13 @@ static unsigned out_h = 1440;
|
||||
uint32_t hos_output_size(int height) { return height ? out_h : out_h * 16 / 9; }
|
||||
static void hos_log(const char *f, ...) { (void)f; }
|
||||
|
||||
static void wide(float want) {
|
||||
static void wide(float want, int sized) { /* (as host/hos_main.c has them: a float shape) */
|
||||
''' + block() + r'''
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
out_h = (unsigned)atoi(argv[2]);
|
||||
wide((float)atof(argv[1]));
|
||||
wide((float)atof(argv[1]), argc > 3 && atoi(argv[3]));
|
||||
printf("%llux%llu %llux%llu %.4f %.4f %.4f\n",
|
||||
(unsigned long long)(hos_wide_out & 0xffffffffu), (unsigned long long)(hos_wide_out >> 32),
|
||||
(unsigned long long)(hos_wide_scene & 0xffffffffu), (unsigned long long)(hos_wide_scene >> 32),
|
||||
@@ -66,20 +69,37 @@ int main(int argc, char **argv) {
|
||||
("2.3889", 1440, "3440x1440 2584x1080 2.3889 0.7442 0.1279"), # 21:9 (3440 x 1440), as before
|
||||
("3.5556", 1440, "5120x1440 3840x1080 3.5556 0.5000 0.2500"), # 32:9, as before
|
||||
("0", 1440, "0x0 0x0 0.0000 0.0000 0.0000"), # Ultrawide off
|
||||
# a shape of the row's or HOS_ASPECT's at the 4K output: at most 3840x2160's pixels, the shape kept
|
||||
("2.3704", 2160, "4416x1864 3312x1398 2.3691 0.7504 0.1248"),
|
||||
("3.5556", 2160, "5400x1520 4048x1140 3.5526 0.5004 0.2498"),
|
||||
)
|
||||
# (the Output resolution's own shape, its width over its height: the picture is that size)
|
||||
sized = (
|
||||
(3840, 1600, "3840x1600 2880x1200 2.4000 0.7407 0.1296"),
|
||||
(3440, 1440, "3440x1440 2584x1080 2.3889 0.7442 0.1279"),
|
||||
(2560, 1080, "2560x1080 1920x810 2.3704 0.7500 0.1250"),
|
||||
(5120, 1440, "5120x1440 3840x1080 3.5556 0.5000 0.2500"),
|
||||
(5120, 2160, "5120x2160 3840x1620 2.3704 0.7500 0.1250"), # (more than 3840x2160's pixels: not made smaller)
|
||||
(1920, 1200, "1920x1200 1440x900 1.6000 1.0000 0.0000"),
|
||||
(7224, 2032, "7224x2032 5416x1524 3.5551 0.5001 0.2500"), # (a 7680x2160 screen as output_size_used takes it)
|
||||
)
|
||||
with tempfile.TemporaryDirectory(prefix="widescreen-") as tmp:
|
||||
work = Path(tmp)
|
||||
source, exe = work / "fixture.c", work / "fixture.exe"
|
||||
source.write_text(fixture, encoding="utf-8")
|
||||
subprocess.run([args.cc, "-std=c11", str(source), "-o", str(exe), "-lm"], check=True)
|
||||
subprocess.run([args.cc, "-std=c11", "-I", str(ROOT), str(source), "-o", str(exe), "-lm"], check=True)
|
||||
bad = []
|
||||
for want, height, expect in cases:
|
||||
got = subprocess.run([str(exe), want, str(height)], capture_output=True, text=True, check=True).stdout.strip()
|
||||
if got != expect:
|
||||
bad.append("ratio %s at %u: %s, expected %s" % (want, height, got, expect))
|
||||
for w, h, expect in sized:
|
||||
got = subprocess.run([str(exe), repr(w / h), str(h), "1"], capture_output=True, text=True, check=True).stdout.strip()
|
||||
if got != expect:
|
||||
bad.append("the output size %ux%u: %s, expected %s" % (w, h, got, expect))
|
||||
if bad:
|
||||
raise SystemExit("FAIL:\n " + "\n ".join(bad))
|
||||
print("PASS: widescreen sizes for 4:3, 16:10, 5:4, 16:9, 21:9 and 32:9 screens")
|
||||
print("PASS: widescreen sizes for 4:3, 16:10, 5:4, 16:9, 21:9 and 32:9 screens, and for output sizes of their own shape")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user