mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 03:59:59 -04:00
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:
@@ -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},
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user