Add NX2NAVI_GEN_SEED, a test switch that starts the page write generations at a given value, so a play-test can cross 2^32 in seconds instead of 15 to 66 hours.

Whether the 64-bit generations hold past 2^32 in the game, with every texture check, mirror sync and shadow copy of a
real scene, could not be seen in play: reaching 2^32 takes 15 to 66 hours. gen_wrap_check shows it for the generation
code alone. NX2NAVI_GEN_SEED=<n> (nx2navi.ini gen_seed, diagnostics, default 0) makes the run's first generation
n + 1: with 4294966000 a run passes 2^32 within its first seconds, and with 1099511627000 the low 32 bits pass
through 0 again.

The first gen_next, before anything is stamped, reads the value (gen_seed). It is parsed with strtoull, decimal or
0x hexadecimal: strtoul stops at 2^32 - 1 where unsigned long is 32 bits, as on Windows, and would turn a seed past
32 bits into 4294967295 without a word. It is capped at 2^62, far from the 64-bit end, and only ever raises the
counter, since a lower value would leave stamps newer than it that read as written at every check. A value that is
no number, or negative, is logged and ignored; a seed in use is logged as "mem: page generations start at <n>
(NX2NAVI_GEN_SEED, a test switch)". Without the switch the only cost is one compare a generation that is true once.

cfg.c gets its metas row (0, 0..4611686018427387904, read at start), its known[] name and its sections[] entry, each
on a line of its own next to the other memory test switches (STAGING_FAIL_AT, VRAM_BALLAST_MB); nx2navi.ini.example
gets a commented gen_seed entry under [diagnostics]. The settings menu does not show it.

tests/gen_wrap_check runs the generation code a second way: the counter left at 0 and the seed taken from
NX2NAVI_GEN_SEED, for 4294967288, 0xfffffffff8, 0x7ffffffffffffff8 (capped), 12abc, -8, 0 and unset, each with the
start and the log line expected of it, then the same compares across the boundary. With strtoul in place of strtoull
two of those runs fail. Checks that passed: gen_wrap_check, gen_width_check, cfg_rows_check (0 problems),
pass_cc_check on vk_memory.c and cfg.c, no new -Wall -Wextra warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:01:05 -05:00
parent 028a6ce128
commit 5ee960f811
6 changed files with 106 additions and 26 deletions

View File

@@ -759,7 +759,8 @@ census" banner, and the readers of its tables `cpu_wrote_since`, `shadow_pool_cl
passes `python tests\gen_wrap_check.py`, which builds those parts of the file alone and runs the generations across
2^32 (where 32-bit generations wrapped), 2^40 and 2^63: texture checks, the snapshot path and the region check, the
CPU-side tables, and mirror and shadow cleanliness answer as below the boundary, and one line is logged when the count
reaches 2^32. No GPU, no game files.
reaches 2^32. It also takes the start from `NX2NAVI_GEN_SEED` (`gen_seed`): read as 64 bits, decimal or `0x`, capped
at 2^62, a value that is no number ignored, each with its log line. No GPU, no game files.
A change to `runtime/vk_memory.c`, `runtime/vk_texture.c` or `runtime/tex_probe.c` passes
`python tests\gen_width_check.py`, which compiles the three files with the build's flags and `-Wshorten-64-to-32`,

View File

@@ -1079,6 +1079,11 @@
# this number is not made and is taken as one the driver refused with a lost device. The log then holds one report and
# one FATAL line, and the game ends with exit code 72. 0: never. Default: 0.
# device_lost_at = 0
# A test of the page write generations (how the renderer tells which game memory changed since it last looked): they
# start after this number instead of 0, so a run reaches 4294967296, where the 32-bit generations of versions before
# 0.10.2 ran out, within its first seconds (4294966000 does that). Decimal, or hexadecimal with 0x; at most
# 4611686018427387904. The log says where they start. Nothing else changes. Read at start. Default: 0.
# gen_seed = 0
# Once a second, puts the crash report's exception filter back if a GPU driver or an overlay loaded after the start set
# its own in its place, and says so in the log. Without it, a crash in such a DLL can end the game with no FATAL line in
# the log. 0: off.

View File

@@ -84,6 +84,7 @@ static const char *const known[] = {
"TEXUP_LOG_MS", "DYN_RES", "DYN_RES_TARGET", "DYN_RES_STEP", "TEXTURE_DETAIL", "VRAM_USE", // vram_use: the removed Video memory use row, read by nothing
"RECORDER_CORE", "RECORDER_PRIO", "REPLAY_TIME", "LOCK_TIME", "POOL_CREATE_BUDGET", "POOL_CREATE_MS", "POOL_FINI_IDLE", "POOL_LOAD_BACKLOG", "POOL_LOAD_MS",
"VMA_BLOCK_MB", "SYNC_WAKE_ALL", "LOG_ASYNC", "DEVICE_LOST_AT", "STAGING_FAIL_AT", "VRAM_BALLAST_MB",
"GEN_SEED",
"COPY_RETIRE",
"MEM_BUDGET_TEST_VRAM_MB", "MEM_BUDGET_TEST_RAM_MB",
"TEX_COMPACT", "TEX_COMPACT_MIN_MB", "TEX_COMPACT_FRAME_MB", // texture compaction (vk_texture.c); no menu row
@@ -177,6 +178,7 @@ static const struct { const char *key, *section; } sections[] = {
{"HANDLE_CENSUS", "diagnostics"},
{"HANG_WATCH_S", "diagnostics"},
{"VMA_BLOCK_MB", "diagnostics"}, {"DEVICE_LOST_AT", "diagnostics"}, {"STAGING_FAIL_AT", "diagnostics"}, {"VRAM_BALLAST_MB", "diagnostics"},
{"GEN_SEED", "diagnostics"},
{"COPY_RETIRE", "diagnostics"},
{"MEM_BUDGET_TEST_VRAM_MB", "diagnostics"}, {"MEM_BUDGET_TEST_RAM_MB", "diagnostics"},
{"TEX_COMPACT", "performance"}, {"TEX_COMPACT_MIN_MB", "performance"}, {"TEX_COMPACT_FRAME_MB", "performance"},
@@ -449,6 +451,8 @@ static const CfgMeta metas[] = {
{"DRAW_CRUMBS", "0", "0|1", RESTART}, // vk_crumbs.c draw marks: a mark at each change of shaders inside a pass
{"STAGING_FAIL_AT", "0", "0..1000000000", RESTART}, // vk_memory.c staging_fail_now: a test of give_back
{"VRAM_BALLAST_MB", "0", "0..131072", RESTART}, // vk_memory.c vk_mem_ballast: a test of a smaller card
// vk_memory.c gen_seed: a test that starts the page write generations at this value (at most 2^62)
{"GEN_SEED", "0", "0..4611686018427387904", RESTART},
// mem_budget.h: a test that pretends the video memory or the system memory is that many MiB, for the levels the
// owners that give memory back go by; 0 as it is
{"MEM_BUDGET_TEST_VRAM_MB", "0", "0..1048576", RESTART},

View File

@@ -1189,10 +1189,37 @@ static void gen_mark(uint64_t g) {
(unsigned long long)g, (unsigned long long)frames, secs / 3600, frames ? (double)g / (double)frames : 0.0);
}
// NX2NAVI_GEN_SEED (a test; default 0): the run's generations start after this value, so a run reaches 2^32, where the
// 32-bit generations of earlier versions ran out, or the low 32 bits passing through 0 again (2^40 - a few), within
// seconds. The first gen_next reads it, before anything is stamped, and goes on from it or from gen_now, the larger.
// Parsed as 64 bits with strtoull (strtoul stops at 2^32 - 1 where unsigned long is 32 bits, as on Windows), decimal
// or 0x hexadecimal, and capped at GEN_SEED_MAX, far from the 64-bit end. It only ever raises the counter: a lower one
// would leave stamps newer than it, and they would read as written at every check. gen_lock held exclusively; cfg_get
// and the log take no lock of this file.
#define GEN_SEED_MAX (1ull << 62)
static uint64_t gen_seed(void) {
const char *e = cfg_get("NX2NAVI_GEN_SEED");
if (!e || !*e) return gen_now;
char *end;
uint64_t seed = strtoull(e, &end, 0);
if (end == e || *end || strchr(e, '-')) {
rt_log("mem: NX2NAVI_GEN_SEED=%s is not a number from 0 to %llu: the page generations start at %llu", e,
GEN_SEED_MAX, (unsigned long long)gen_now);
return gen_now;
}
int capped = seed > GEN_SEED_MAX;
if (capped) seed = GEN_SEED_MAX;
if (seed <= gen_now) return gen_now;
rt_log("mem: page generations start at %llu (NX2NAVI_GEN_SEED%s, a test switch)", (unsigned long long)seed,
capped ? " capped at 2^62" : "");
return seed;
}
// gen_lock held exclusively: the only place a generation is handed out. The store is atomic: vk_mem_sizes and
// verify_cb read gen_now without gen_lock.
static inline uint64_t gen_next(void) {
uint64_t g = gen_now + 1;
if (__builtin_expect(g == 1, 0)) g = gen_seed() + 1; // the run's first generation
if (__builtin_expect(g == 1ull << 32, 0)) gen_mark(g);
__atomic_store_n(&gen_now, g, __ATOMIC_RELAXED);
return g;

View File

@@ -5,10 +5,14 @@
// shadow storage and the verify mode make must answer as it does below the boundary. Seeds: 2^32 - 8 (where 32-bit
// generations wrapped), 2^40 - 8 (the low 32 bits pass through 0 again, so a truncation to 32 bits anywhere fails
// there too) and 2^63 - 8. gen_next must log one line when the count reaches 2^32, and no other.
// With --cfg the counter starts at 0 and the seed comes from NX2NAVI_GEN_SEED (vk_memory.c gen_seed), which the first
// generation reads: the run must go on from the start expected of that value (parsed as 64 bits, capped at 2^62, a
// value that is no number ignored), with the seed's log line expected of it ("-": none).
// Stubs: no-op locks; a write watch that reports the pages a check marks as written by the CPU; nothing frozen; no
// pools in the index.
// Usage: gen_wrap_check <seed>. Prints each failed check and "gen_wrap_check: seed ...: N of M checks failed"; exit 1
// on any.
// Usage: gen_wrap_check <seed>
// gen_wrap_check --cfg <NX2NAVI_GEN_SEED's value, or (unset)> <expected start> <expected seed line part, or ->
// Prints each failed check and "gen_wrap_check: seed ...: N of M checks failed"; exit 1 on any.
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
@@ -67,7 +71,8 @@ uint64_t mem_written_peek(uint64_t addr, uint64_t size, uint64_t *pages, uint64_
int mem_frozen(uint64_t a) { (void)a; return 0; }
int mem_watched(uint64_t addr, uint64_t size) { (void)addr, (void)size; return 1; }
int nvn_gpu_only(uint64_t a) { (void)a; return 0; }
static const char *cfg_get(const char *k) { (void)k; return NULL; }
static const char *cfg_seed; // --cfg: what NX2NAVI_GEN_SEED reads (NULL: unset)
static const char *cfg_get(const char *k) { return !strcmp(k, "NX2NAVI_GEN_SEED") ? cfg_seed : NULL; }
typedef struct { uintptr_t lo, hi, base; void *buf; } pidx_ent; // snap_widen's pool lookup: no pools
typedef struct { int n; } pidx;
static pidx pool_index;
@@ -75,7 +80,7 @@ static PlatMutex pool_lock;
static const pidx_ent *pidx_find(const pidx *x, uintptr_t a, uint64_t l) { (void)x, (void)a, (void)l; return NULL; }
enum { POOL_IMPORT = 1 };
// The log: the page generation lines are kept, the others dropped.
// The log: the page generation and NX2NAVI_GEN_SEED lines are kept, the others dropped.
static char gen_lines[16][512];
static int n_gen_lines;
static void rt_log(const char *fmt, ...) {
@@ -84,7 +89,7 @@ static void rt_log(const char *fmt, ...) {
va_start(ap, fmt);
vsnprintf(line, sizeof line, fmt, ap);
va_end(ap);
if (strncmp(line, "mem: page generations", 21)) return;
if (strncmp(line, "mem: page generations", 21) && strncmp(line, "mem: NX2NAVI_GEN_SEED", 21)) return;
if (n_gen_lines < 16) memcpy(gen_lines[n_gen_lines], line, sizeof line);
n_gen_lines++;
}
@@ -122,23 +127,40 @@ static void seen(gen_t now, const char *what) {
}
int main(int argc, char **argv) {
uint64_t seed = argc > 1 ? strtoull(argv[1], NULL, 0) : (1ull << 32) - 8;
int from_cfg = argc > 4 && !strcmp(argv[1], "--cfg");
const char *want_line = NULL; // --cfg: a part of the seed's log line
uint64_t seed; // the counter before the first generation
if (from_cfg) {
cfg_seed = strcmp(argv[2], "(unset)") ? argv[2] : NULL;
seed = strtoull(argv[3], NULL, 0);
want_line = strcmp(argv[4], "-") ? argv[4] : NULL;
} else {
seed = argc > 1 ? strtoull(argv[1], NULL, 0) : (1ull << 32) - 8;
}
uint64_t edge = seed + 8; // the boundary under test: 2^32 for the first seed
gen_t w_tex, w_oth, now, d;
rt_guest_start_ns = 1000000000ull;
fake_now = rt_guest_start_ns + 3600ull * 1000000000ull; // an hour in
gfx_counters.frames = 216000; // at 60 fps
gen_now = (gen_t)seed;
CHECK((uint64_t)gen_now == seed, "the seed %#llx does not fit the generations (%u bits)", (unsigned long long)seed,
(unsigned)(8 * sizeof(gen_t)));
if (failed) { // the generations cannot reach the boundary: nothing below can run
printf("gen_wrap_check: seed %#llx: 1 of 1 checks failed\n", (unsigned long long)seed);
return 1;
if (!from_cfg) {
gen_now = (gen_t)seed;
CHECK((uint64_t)gen_now == seed, "the seed %#llx does not fit the generations (%u bits)",
(unsigned long long)seed, (unsigned)(8 * sizeof(gen_t)));
}
last_now = (uint64_t)gen_now;
// Before the boundary: both textures loaded (written) and checked.
vk_guest_written(TEX, 0x4000);
// Before the boundary: both textures loaded (written) and checked. The first write takes the first generation,
// which goes on from the seed (with --cfg, the seed NX2NAVI_GEN_SEED gives).
if (!failed) {
vk_guest_written(TEX, 0x4000);
CHECK((uint64_t)gen_now == seed + 1, "%s%s: the first generation is %llu, not %llu",
from_cfg ? "NX2NAVI_GEN_SEED=" : "seeded directly", from_cfg ? (cfg_seed ? cfg_seed : "(unset)") : "",
(unsigned long long)gen_now, (unsigned long long)(seed + 1));
}
if (failed) { // the generations cannot reach the boundary: nothing below can run
printf("gen_wrap_check: seed %#llx: %d of %d checks failed\n", (unsigned long long)seed, failed, checks);
return 1;
}
vk_guest_written(OTHER, 0x4000);
CHECK(vk_mem_changed(TEX, 0x4000, 0, &w_tex) == 1, "TEX: its load is not seen");
seen(w_tex, "TEX first check");
@@ -229,18 +251,26 @@ int main(int argc, char **argv) {
CHECK(!page_dirty(TEX + 0x1000, p.mgen), "page_dirty: nothing written since the sync, yet dirty");
CHECK(shadow_pool_clean(&p, ep, 1) && shadow_pool_clean(&p, ep, 0), "shadow_pool_clean: synced, yet not clean");
// The log: one line where the count reached 2^32, none at any other boundary.
int reached = seed < (1ull << 32) && (uint64_t)gen_now >= (1ull << 32);
CHECK(n_gen_lines == reached, "%d page generation lines, not %d (first: %s)", n_gen_lines, reached,
n_gen_lines ? gen_lines[0] : "none");
if (reached && n_gen_lines)
CHECK(strstr(gen_lines[0], "reached 4294967296 at frame 216000 after 1.0 h of play (19884 a frame)"),
"the line at 2^32: %s", gen_lines[0]);
// The log: one line where the count reached 2^32, none at any other boundary; with --cfg, the seed's line.
int reached = seed < (1ull << 32) && (uint64_t)gen_now >= (1ull << 32), n_reached = 0, n_seed = 0;
for (int i = 0; i < n_gen_lines && i < 16; i++) {
if (strstr(gen_lines[i], "reached 4294967296")) {
n_reached++;
CHECK(strstr(gen_lines[i], "reached 4294967296 at frame 216000 after 1.0 h of play (19884 a frame)"),
"the line at 2^32: %s", gen_lines[i]);
}
if (strstr(gen_lines[i], "NX2NAVI_GEN_SEED")) {
n_seed++;
CHECK(want_line && strstr(gen_lines[i], want_line), "the seed's line is not \"%s\": %s",
want_line ? want_line : "(none)", gen_lines[i]);
}
CHECK(!strstr(gen_lines[i], "run out") && !strstr(gen_lines[i], "ran out at"), "a line of running out: %s",
gen_lines[i]);
printf(" %s\n", gen_lines[i]);
}
CHECK(n_reached == reached, "%d lines at 2^32, not %d", n_reached, reached);
CHECK(n_seed == (want_line != NULL), "%d lines of the seed, not %d", n_seed, want_line != NULL);
CHECK(n_gen_lines == n_reached + n_seed, "%d page generation lines, not %d", n_gen_lines, n_reached + n_seed);
printf("gen_wrap_check: seed %#llx, %u-bit generations, gen_now %#llx: %d of %d checks failed\n",
(unsigned long long)seed, (unsigned)(8 * sizeof(gen_t)), (unsigned long long)gen_now, failed, checks);

View File

@@ -7,7 +7,9 @@ From runtime/vk_memory.c it takes, verbatim, into build/test/gen_wrap/gen_sectio
- the readers of the tables outside that section: cpu_wrote_since, shadow_pool_clean, lazy_clean and page_dirty.
The program starts the generations just below each seed's boundary and checks that every compare answers across it as
below it (texture checks, the snapshot path, the region check, the CPU-side tables, mirror and shadow cleanliness),
and that gen_next logs one line when the count reaches 2^32 and no other.
and that gen_next logs one line when the count reaches 2^32 and no other. It then takes the seeds from
NX2NAVI_GEN_SEED (gen_seed) instead: decimal and 0x hexadecimal values past 32 bits, one past the cap of 2^62, values
that are no number, 0 and none.
No GPU, no game files, any Python.
@@ -28,6 +30,16 @@ END = '// ---------------------------------------------------------------- dirty
READERS = ('static int cpu_wrote_since(', 'static int shadow_pool_clean(', 'static int lazy_clean(',
'static int page_dirty(')
SEEDS = ((1 << 32) - 8, (1 << 40) - 8, (1 << 63) - 8) # the old wrap; low 32 bits through 0 again; near 2^63
# NX2NAVI_GEN_SEED's value, the start expected of it, and a part of the line it logs ('-': none)
CFG_SEEDS = (
('4294967288', (1 << 32) - 8, 'page generations start at 4294967288 (NX2NAVI_GEN_SEED, a test switch)'),
('0xfffffffff8', (1 << 40) - 8, 'start at 1099511627768 (NX2NAVI_GEN_SEED,'), # strtoul would stop at 2^32 - 1
('0x7ffffffffffffff8', 1 << 62, 'start at 4611686018427387904 (NX2NAVI_GEN_SEED capped at 2^62,'),
('12abc', 0, 'NX2NAVI_GEN_SEED=12abc is not a number'),
('-8', 0, 'NX2NAVI_GEN_SEED=-8 is not a number'),
('0', 0, '-'),
('(unset)', 0, '-'),
)
def compiler(cc):
@@ -97,11 +109,12 @@ def main():
subprocess.check_call([compiler(args.cc), '-std=gnu11', '-O1', '-Wall', '-Wno-unused-function',
'-Wno-unused-variable', '-I', str(work), str(ROOT / 'tests' / 'gen_wrap_check.c'), '-o',
str(exe)], env=env)
runs = [[str(seed)] for seed in SEEDS] + [['--cfg', v, str(start), line] for v, start, line in CFG_SEEDS]
bad = 0
for seed in SEEDS:
bad += subprocess.run([str(exe), str(seed)], env=env, timeout=120).returncode != 0
for run in runs:
bad += subprocess.run([str(exe)] + run, env=env, timeout=120).returncode != 0
if bad:
print(f'gen_wrap_check: {bad} of {len(SEEDS)} runs failed')
print(f'gen_wrap_check: {bad} of {len(runs)} runs failed')
return 1
print('gen_wrap_check: all checks passed')
return 0