Keep an optional history of GPU address ranges, so the report of a lost graphics device can name what held the faulting address.

After a lost device the driver's fault report gives an address and nothing says what was there. With va_report = 1 (NX2NAVI_VA_REPORT, off by default) the game keeps every address range the driver binds to a buffer or image and every range it unbinds (VK_EXT_device_address_binding_report, runtime/vk_vaddr.c). The report of a lost device then names the ranges that covered each faulting page, or the nearest ones when none did, and vaddr-history.txt beside the log holds the whole history, also when the driver gives no fault report. With 2 the call stack behind each range of 1 MiB or more is kept too. A player sees nothing of this unless the setting is on: without it no extension is enabled and no callback runs.

From pull request #349. Its second part, which stops a frame dump from turning on mesh query statistics, is left out: it changes what a dump writes for everyone who uses one. Built for Windows; no device was lost to try it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Chris Toph
2026-11-10 12:50:56 -05:00
committed by chrg6
parent 541c4ff84c
commit 5374d04d0f
9 changed files with 69 additions and 5 deletions

View File

@@ -1567,6 +1567,22 @@ int plat_module_of(uintptr_t addr, char *name, size_t cap, uintptr_t *base) {
return snprintf(name, cap, "%s", n ? n + 1 : d.dli_fname) < (int)cap;
}
typedef struct { uintptr_t *pc; int n, max; } StackWalk;
static _Unwind_Reason_Code stack_step(struct _Unwind_Context *ctx, void *p) {
StackWalk *w = p;
uintptr_t ip = _Unwind_GetIP(ctx);
if (!ip || w->n == w->max) return _URC_END_OF_STACK;
w->pc[w->n++] = ip;
return _URC_NO_REASON;
}
int plat_stack(uintptr_t *pc, int max) {
StackWalk w = {pc, 0, max};
_Unwind_Backtrace(stack_step, &w);
return w.n;
}
int plat_exe_path(char *out, size_t cap) {
ssize_t n = readlink("/proc/self/exe", out, cap - 1);
if (n <= 0 || (size_t)n >= cap - 1) return 0;

View File

@@ -416,6 +416,8 @@ uintptr_t plat_exe_base(void); // where the executabl
// The module (executable or library) holding code address addr: its file name without directories into name, its load
// address into *base. 0 when none.
int plat_module_of(uintptr_t addr, char *name, size_t cap, uintptr_t *base);
// Return addresses of the calling thread's stack into pc, innermost first, at most max: their count.
int plat_stack(uintptr_t *pc, int max);
#define PLAT_PATH_MAX 1024 // path buffers of the runtime
#ifdef _WIN32
#define PLAT_EXE_SUFFIX ".exe" // of the programs the runtime starts (nx2navi_xlate)

View File

@@ -1562,6 +1562,13 @@ int plat_module_of(uintptr_t addr, char *name, size_t cap, uintptr_t *base) {
return WideCharToMultiByte(CP_UTF8, 0, n, -1, name, (int)cap, NULL, NULL) != 0;
}
int plat_stack(uintptr_t *pc, int max) {
void *f[62];
USHORT n = RtlCaptureStackBackTrace(1, max < 62 ? (DWORD)max : 62, f, NULL);
for (USHORT i = 0; i < n; i++) pc[i] = (uintptr_t)f[i];
return n;
}
int plat_exe_path(char *out, size_t cap) {
wchar_t w[WPATH];
DWORD n = GetModuleFileNameW(NULL, w, WPATH);