mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 07:09:57 -04:00
Add diagnostics used to find these fixes, all off by default.
NX2NAVI_TRACE=audio logs voices starting, stopping and sharing a wave buffer; NX2NAVI_DUMP_MOVIE dumps movie frames; NX2NAVI_LOG_CS_BINDS says why the stand-in for an untranslated compute program skipped a dispatch; and NX2NAVI_TRACE=perf adds heap and commit census lines on their own thread, with VMA maps when write-combined memory grows by 2 GiB. From a tester's fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,10 @@ typedef struct Mixer {
|
||||
float voice_scratch[6][MAX_FRAME], filter_scratch[MAX_FRAME], output_scratch[MAX_FRAME * OUT_MAX];
|
||||
double level_sum, level_peak; uint64_t level_count, level_frames; int first_sound_logged;
|
||||
int prefill; // render blocks
|
||||
uint64_t trace_pass, trace_seen[1024]; // NX2NAVI_TRACE=audio: render passes; the pass each voice was last mixed in
|
||||
uint64_t trace_buf[1024]; // and the wave buffer address it read in that pass
|
||||
uint64_t trace_pair[1024]; // the last shared-buffer pair logged for each voice (other voice, address)
|
||||
unsigned trace_shared; // "voices share a buffer" lines written (capped)
|
||||
} Mixer;
|
||||
|
||||
static _Atomic float device_volume = 1.0f;
|
||||
@@ -820,6 +824,7 @@ void audio_mixer_render(AudioRenderer *r, double seconds) {
|
||||
if (at > m->nbuf) { rt_log("audio: mixes use %d buffers, renderer has %d", at, m->nbuf); rt_fatal("audio mix buffer layout"); }
|
||||
|
||||
float (*vs)[MAX_FRAME]=m->voice_scratch,*filtered=m->filter_scratch;
|
||||
m->trace_pass++;
|
||||
for (int i = 0; i < r->param.voice_count; i++) {
|
||||
ServerVoice *v = &r->voices[i];
|
||||
if (!v->in.in_use || v->state != SV_STARTED || !v->in.sample_rate || !v->valid[v->index]) continue;
|
||||
@@ -832,6 +837,18 @@ void audio_mixer_render(AudioRenderer *r, double seconds) {
|
||||
v->in.sample_format == FMT_ADPCM || fmt_bytes(v->in.sample_format) ? "decoded" : "NOT decoded: silent",
|
||||
cc, (unsigned)v->in.sample_rate);
|
||||
}
|
||||
if ((rt_trace & RT_TRACE_AUDIO) && i < 1024) { // mixed now and not in the last pass: what it plays and where to
|
||||
const AudrenWaveBuffer *wb = &v->buffers[v->index & 3];
|
||||
if (m->trace_seen[i] + 1 != m->trace_pass) // pass: 5 ms each at 48 kHz (frame samples per pass)
|
||||
rt_log("audio: voice %d plays at pass %llu: format %u, %d channel(s) at %u Hz, buffer %u at %#llx+%#llx "
|
||||
"(%s%s), volume %.3f, pitch %.3f, mix %d, splitter %u, priority %d", i,
|
||||
(unsigned long long)m->trace_pass, (unsigned)v->in.sample_format, cc, (unsigned)v->in.sample_rate,
|
||||
v->index, (unsigned long long)wb->address, (unsigned long long)wb->size,
|
||||
wb->loop ? "loop" : "once", wb->end_of_stream ? ", end of stream" : "", v->in.volume, v->in.pitch,
|
||||
(int)v->in.mix_id, (unsigned)v->in.splitter_id, (int)v->in.priority);
|
||||
m->trace_seen[i] = m->trace_pass;
|
||||
m->trace_buf[i] = wb->address;
|
||||
}
|
||||
voice_render(r, v, vs, frames);
|
||||
for (int f = 0; f < 2; f++) if (v->in.biquads[f].enable) {
|
||||
const AudrenBiquad *b = &v->in.biquads[f];
|
||||
@@ -867,6 +884,31 @@ void audio_mixer_render(AudioRenderer *r, double seconds) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rt_trace & RT_TRACE_AUDIO) {
|
||||
// Voices mixed in the last pass and not in this one, and why; then voices that read the same wave buffer memory
|
||||
// in this pass (one stream heard twice, offset by how far apart the two read).
|
||||
for (int i = 0; i < r->param.voice_count && i < 1024; i++) {
|
||||
if (!m->trace_seen[i] || m->trace_seen[i] + 1 != m->trace_pass) continue; // 0: never mixed
|
||||
const ServerVoice *v = &r->voices[i];
|
||||
rt_log("audio: voice %d stops at pass %llu: %s; %llu samples played, %u buffers consumed", i,
|
||||
(unsigned long long)m->trace_pass,
|
||||
!v->in.in_use ? "released by the game" : v->state == SV_PAUSED ? "paused"
|
||||
: v->state != SV_STARTED ? "stopped by the game" : "out of wave buffers",
|
||||
(unsigned long long)v->played, (unsigned)v->consumed);
|
||||
}
|
||||
for (int i = 0; i < r->param.voice_count && i < 1024; i++) {
|
||||
if (m->trace_seen[i] != m->trace_pass || !m->trace_buf[i]) continue;
|
||||
for (int j = i + 1; j < r->param.voice_count && j < 1024 && m->trace_shared < 400; j++)
|
||||
if (m->trace_seen[j] == m->trace_pass && m->trace_buf[j] == m->trace_buf[i] &&
|
||||
m->trace_pair[i] != ((uint64_t)j << 48 ^ m->trace_buf[i])) { // once per pair and buffer
|
||||
m->trace_pair[i] = (uint64_t)j << 48 ^ m->trace_buf[i];
|
||||
m->trace_shared++;
|
||||
rt_log("audio: voices %d and %d both play the wave buffer at %#llx in pass %llu (offsets %llu and %llu)",
|
||||
i, j, (unsigned long long)m->trace_buf[i], (unsigned long long)m->trace_pass,
|
||||
(unsigned long long)r->voices[i].offset, (unsigned long long)r->voices[j].offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* submixes: deepest first, so every mix is complete before it is folded into its destination */
|
||||
int order[256], n = 0, depth[256];
|
||||
for (int i = 1; i < mc && n < 256; i++) if (r->mixes[i].in_use) { depth[n] = mix_depth(r, i); order[n++] = i; }
|
||||
|
||||
@@ -41,7 +41,7 @@ static const char *const known[] = {
|
||||
"BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COLOR_CONTRAST", "COLOR_GAMMA",
|
||||
"COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT",
|
||||
"DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR",
|
||||
"DUMP_LOG", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"DUMP_LOG", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "DUMP_MOVIE", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FREEZE_IDLE", "FREE_CORES",
|
||||
"FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE",
|
||||
"HDR_PEAK_NITS", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD",
|
||||
|
||||
@@ -54,6 +54,7 @@ typedef struct {
|
||||
PlatMutex codec; // dav1d: the decoder thread while it decodes, Flush / Finalize
|
||||
PlatCond work; // a sample arrived, or quit
|
||||
PlatThread *thread;
|
||||
int run_index; // which movie of the run this is, counted from 1 as decoders come up (for the log)
|
||||
Dav1dContext *dav1d;
|
||||
uint8_t in_ev[0x40], out_ev[0x40]; // nn::os::SystemEventType each
|
||||
int in_bound, out_bound;
|
||||
@@ -426,6 +427,8 @@ static void ov_dtor(Cpu *c) {
|
||||
*slot = NULL;
|
||||
gfx_movie_stop();
|
||||
}
|
||||
void vk_dump_movie_frame(int k, uint64_t shown); // vk_dump.c (NX2NAVI_DUMP_MOVIE)
|
||||
static int movies_started; // decoders that came up this run (Video.run_index)
|
||||
// Result Initialize(void *memory, size_t size, MediaMimeType mime, VideoDecoderOutputFormat format, VideoCodecMode)
|
||||
static void ov_initialize(Cpu *c) {
|
||||
Video **slot = arg_p(c, 0);
|
||||
@@ -450,8 +453,9 @@ static void ov_initialize(Cpu *c) {
|
||||
if (r < 0) rt_fatal("movie: dav1d_open failed (%d)", r);
|
||||
v->thread = plat_thread_new(decoder_thread, v, "movie decoder");
|
||||
if (!v->thread) rt_fatal("movie: cannot start the decoder thread");
|
||||
rt_log("movie: video decoder up (AV1 via dav1d %s on its own thread; mime %u, output format %u, mode %u)",
|
||||
dav1d_version(), (unsigned)arg_x(c, 3), (unsigned)arg_x(c, 4), (unsigned)arg_x(c, 5));
|
||||
v->run_index = __atomic_add_fetch(&movies_started, 1, __ATOMIC_RELAXED);
|
||||
rt_log("movie: video decoder %d up (AV1 via dav1d %s on its own thread; mime %u, output format %u, mode %u)",
|
||||
v->run_index, dav1d_version(), (unsigned)arg_x(c, 3), (unsigned)arg_x(c, 4), (unsigned)arg_x(c, 5));
|
||||
ret_x(c, 0);
|
||||
}
|
||||
// Result Configure(const MediaProperty *, const void *configuration, size_t): the AV1 sequence header also comes
|
||||
@@ -629,6 +633,7 @@ static void ov_acquire(Cpu *c) {
|
||||
v->busy[f] = 1;
|
||||
v->shown += !p.eos;
|
||||
if (p.nv12 && v->shown == 1) rt_log("movie: first frame %dx%d shown", p.w, p.h);
|
||||
if (p.nv12) vk_dump_movie_frame(v->run_index, v->shown);
|
||||
if (p.nv12) { // pacing report every 600 frames (10 s): the gaps between acquisitions and their time stamps
|
||||
static uint64_t last_ns, sum_gap, max_gap, n;
|
||||
uint64_t now = plat_now_ns(), gap = last_ns ? now - last_ns : 0;
|
||||
|
||||
@@ -935,6 +935,11 @@ int plat_mem_state(uint64_t addr, uint64_t limit, uint64_t *end) {
|
||||
return v == PS_FREE ? PLAT_MEM_FREE : v == PS_RESERVED ? PLAT_MEM_RESERVED : v - PS_NONE;
|
||||
}
|
||||
|
||||
int plat_mem_census(uint64_t *priv, uint64_t *wc, uint64_t *wc_allocs) {
|
||||
*priv = *wc = *wc_allocs = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t plat_mem_written(uint64_t addr, uint64_t n, uint64_t *pages, uint64_t max, int reset) {
|
||||
if (!max || !n) return 0;
|
||||
if (ww_fd < 0) return UINT64_MAX;
|
||||
|
||||
@@ -215,6 +215,9 @@ int plat_mem_protect(uint64_t addr, uint64_t n, int prot); // committed pages on
|
||||
// The page at addr: PLAT_PROT_* when committed, else PLAT_MEM_RESERVED or PLAT_MEM_FREE (not reserved by us). *end
|
||||
// gets the end of the run of pages in the same state, at most limit.
|
||||
int plat_mem_state(uint64_t addr, uint64_t limit, uint64_t *end);
|
||||
// The process's committed private memory and the part of it mapped write-combined (Windows PAGE_WRITECOMBINE: memory
|
||||
// the GPU driver maps uncached for the CPU), with the number of allocations that part spans. 0 where unsupported.
|
||||
int plat_mem_census(uint64_t *priv, uint64_t *wc, uint64_t *wc_allocs);
|
||||
// The pages of a watched reservation written since the last reset, up to max page addresses into pages, in address
|
||||
// order; reset: those reported start over as unwritten. UINT64_MAX when writes to the range are not tracked.
|
||||
uint64_t plat_mem_written(uint64_t addr, uint64_t n, uint64_t *pages, uint64_t max, int reset);
|
||||
|
||||
@@ -684,6 +684,26 @@ int plat_mem_state(uint64_t addr, uint64_t limit, uint64_t *end) {
|
||||
return p == PAGE_READWRITE ? PLAT_PROT_RW : p == PAGE_READONLY ? PLAT_PROT_READ : PLAT_PROT_NONE;
|
||||
}
|
||||
|
||||
int plat_mem_census(uint64_t *priv, uint64_t *wc, uint64_t *wc_allocs) {
|
||||
*priv = *wc = *wc_allocs = 0;
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
uintptr_t a = 0;
|
||||
void *last = NULL;
|
||||
while (VirtualQuery((void *)a, &mbi, sizeof mbi) == sizeof mbi) {
|
||||
if (mbi.State == MEM_COMMIT && mbi.Type == MEM_PRIVATE) {
|
||||
*priv += mbi.RegionSize;
|
||||
if (mbi.Protect & PAGE_WRITECOMBINE) {
|
||||
*wc += mbi.RegionSize;
|
||||
if (mbi.AllocationBase != last) (*wc_allocs)++, last = mbi.AllocationBase;
|
||||
}
|
||||
}
|
||||
uintptr_t next = (uintptr_t)mbi.BaseAddress + mbi.RegionSize;
|
||||
if (next <= a) break;
|
||||
a = next;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Contains code Copyright (c) 2026 Peiikai (MIT; see THIRD_PARTY_NOTICES.md).
|
||||
// GetWriteWatch with the reset flag.
|
||||
uint64_t plat_mem_written(uint64_t addr, uint64_t n, uint64_t *pages, uint64_t max, int reset) {
|
||||
|
||||
@@ -462,9 +462,9 @@ static void buf_snap(VkExec *ex, int pass) {
|
||||
vk_completion_add(ex->fence, buf_done, j);
|
||||
}
|
||||
|
||||
static int active(void) {
|
||||
static int active(void) { // passes_f is NULL before a dump that opens its files when it starts (open_files)
|
||||
uint64_t f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) + 1;
|
||||
return !finished && (f == dump_frame || (log_from && f >= log_from && f < dump_frame));
|
||||
return !finished && passes_f && (f == dump_frame || (log_from && f >= log_from && f < dump_frame));
|
||||
}
|
||||
static uint64_t frame_now(void) { return __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) + 1; }
|
||||
|
||||
@@ -744,6 +744,11 @@ void vk_dump_draw(VkExec *ex, const VkPipeState *s, VkPipeline p, const VkPipeIn
|
||||
Str b = {0};
|
||||
sp(&b, "vs %016llx fs %016llx prog %llu prim %d\n", (unsigned long long)shader_hash(s->vs),
|
||||
(unsigned long long)shader_hash(s->fs), (unsigned long long)(ex->prog ? ex->prog->serial : 0), s->prim);
|
||||
// target 0's blending as NVN numbers (NVNblendFunc, NVNblendEquation), which decides whether a quad covers or mixes
|
||||
const blend_st *bl = &s->blend[0];
|
||||
sp(&b, " blend: enabled targets %#x; target 0 rgb %u*src %u*dst eq %u, alpha %u*src %u*dst eq %u; channel mask %#x\n",
|
||||
(unsigned)s->color.blend_en, (unsigned)bl->src_rgb, (unsigned)bl->dst_rgb, (unsigned)bl->eq_rgb,
|
||||
(unsigned)bl->src_a, (unsigned)bl->dst_a, (unsigned)bl->eq_a, (unsigned)s->chmask.mask);
|
||||
describe_bindings(&b, ex, info);
|
||||
ents[nents++] = (Ent){p, th, 1, b.s};
|
||||
out:
|
||||
@@ -792,9 +797,12 @@ static void pass_decide(int same_targets) {
|
||||
if (!pass_skip) copied++;
|
||||
}
|
||||
|
||||
static void open_files(void);
|
||||
|
||||
void vk_dump_pass_end(VkExec *ex) {
|
||||
plat_mutex_lock(&rec_lock);
|
||||
if (dump_after && dump_frame == UINT64_MAX && ex->depth.tex && (uint64_t)(uintptr_t)ex->depth.tex->mem == dump_after) {
|
||||
if (!passes_f) open_files(); // NX2NAVI_DUMP_WHITE and NX2NAVI_DUMP_MOVIE open them for each of their dumps
|
||||
dump_frame = frame_now(); // this pass and the rest of its frame
|
||||
rt_log("vk_dump: a pass drew into %#llx in frame %llu: it and the rest of the frame go to %s",
|
||||
(unsigned long long)dump_after, (unsigned long long)dump_frame, dir);
|
||||
@@ -943,6 +951,21 @@ static void make_dirs(char *path) { plat_file_mkdir_p(path); }
|
||||
int vk_dump_white; // vk_backend.c asks for a thumbnail of every present while it is set
|
||||
#define dump_white vk_dump_white
|
||||
|
||||
// NX2NAVI_DUMP_MOVIE=<k>:<frame>[,<frame>...] (diagnosis): the k-th movie of the run (counted from 1 as each video
|
||||
// decoder comes up, ov_movie2.c ov_initialize) asks for a dump of the next present once it has shown each listed
|
||||
// frame, so a movie's picture can be followed through the game's passes at chosen moments. Each dump has its own
|
||||
// folder, base_dir/f<present>.
|
||||
static int movie_k, movie_n, movie_done;
|
||||
static uint64_t movie_at[8];
|
||||
static int movie_req; // set by the movie's thread, taken by vk_dump_present
|
||||
|
||||
void vk_dump_movie_frame(int k, uint64_t shown) {
|
||||
if (!movie_k || k != movie_k || movie_done >= movie_n || shown != movie_at[movie_done]) return;
|
||||
movie_done++;
|
||||
__atomic_store_n(&movie_req, 1, __ATOMIC_RELEASE);
|
||||
rt_log("vk_dump: movie %d shows frame %llu: dumping the next present", k, (unsigned long long)shown);
|
||||
}
|
||||
|
||||
// passes.txt and images.txt in dir (a new folder per NX2NAVI_DUMP_WHITE attempt)
|
||||
static void open_files(void) {
|
||||
make_dirs(dir);
|
||||
@@ -961,9 +984,18 @@ void vk_dump_init(void) {
|
||||
// (a target drawn once, at an area load)
|
||||
const char *da = cfg_get("NX2NAVI_DUMP_AFTER");
|
||||
dump_after = da && *da ? strtoull(da, NULL, 0) : 0;
|
||||
const char *dm = cfg_get("NX2NAVI_DUMP_MOVIE");
|
||||
if (dm && *dm) {
|
||||
char *q;
|
||||
movie_k = (int)strtol(dm, &q, 10);
|
||||
while ((*q == ':' || *q == ',') && movie_n < 8) movie_at[movie_n++] = strtoull(q + 1, &q, 10);
|
||||
if (movie_k < 1 || !movie_n) movie_k = 0;
|
||||
}
|
||||
if (dump_white || dump_after) {
|
||||
dump_frame = UINT64_MAX;
|
||||
vk_thumbs_enable(16);
|
||||
} else if (movie_k) {
|
||||
dump_frame = UINT64_MAX;
|
||||
} else if (!e || !*e || !(dump_frame = strtoull(e, NULL, 10))) return;
|
||||
const char *lf = cfg_get("NX2NAVI_DUMP_LOG");
|
||||
if (lf && *lf) log_from = strtoull(lf, NULL, 10);
|
||||
@@ -984,7 +1016,7 @@ void vk_dump_init(void) {
|
||||
snprintf(base_dir, sizeof base_dir, "%s", d && *d ? d : "dump");
|
||||
snprintf(dir, sizeof dir, "%s", base_dir);
|
||||
char path[600];
|
||||
if (!dump_white) open_files();
|
||||
if (!dump_white && !movie_k) open_files();
|
||||
const char *bf = cfg_get("NX2NAVI_DUMP_BUF");
|
||||
if (bf && *bf) {
|
||||
char *q;
|
||||
@@ -1039,6 +1071,12 @@ void vk_dump_present(uint64_t frame) {
|
||||
white_last = 0;
|
||||
}
|
||||
if (dump_white && !white_caught && !white_last && dump_frame == UINT64_MAX) white_check(frame);
|
||||
if (movie_k && dump_frame == UINT64_MAX && __atomic_exchange_n(&movie_req, 0, __ATOMIC_ACQ_REL)) {
|
||||
snprintf(dir, sizeof dir, "%s/f%llu", base_dir, (unsigned long long)(frame + 1));
|
||||
open_files(); // before the frame is named: its passes write to them
|
||||
dump_frame = frame + 1;
|
||||
rt_log("vk_dump: frame %llu goes to %s", (unsigned long long)dump_frame, dir);
|
||||
}
|
||||
if (frame != dump_frame) return;
|
||||
plat_mutex_lock(&rec_lock);
|
||||
finished = 1;
|
||||
@@ -1053,8 +1091,8 @@ void vk_dump_present(uint64_t frame) {
|
||||
passes_f = NULL;
|
||||
rt_log("vk_dump: frame %llu: %d passes and dispatches, about %llu MB of PNGs in %s", (unsigned long long)frame, seq,
|
||||
(unsigned long long)(png_bytes >> 20), dir);
|
||||
if (dump_white) { // ready for another attempt (vk_dump_present checks this one's thumbnail 3 presents on)
|
||||
white_last = frame;
|
||||
if (dump_white || movie_k) { // ready for another dump (vk_dump_present checks a white one's thumbnail 3 presents on)
|
||||
if (dump_white) white_last = frame;
|
||||
plat_mutex_lock(&rec_lock);
|
||||
seq = copied = 0, last_targets = 0, pass_skip = NULL, png_bytes = 0;
|
||||
nluts = nluts_done = nents = ents_over = pass_draws = 0;
|
||||
|
||||
@@ -4097,11 +4097,67 @@ static int native_tensor(const VkExec *ex) {
|
||||
return on || !uses_tensor_ops(ex);
|
||||
}
|
||||
|
||||
// Everything an untranslated program binds (NX2NAVI_LOG_CS_BINDS): what a stand-in could use instead. Texture lock held.
|
||||
static void log_cs_bindings_locked(const VkExec *ex) {
|
||||
char line[1600];
|
||||
int o = 0;
|
||||
line[0] = 0;
|
||||
for (int i = 0; i < 160 && o < (int)sizeof line - 80; i++) {
|
||||
int im = i >= 128;
|
||||
uint64_t h = im ? ex->img[NVN_STAGE_CS][i - 128 < 32 ? i - 128 : 0] : ex->tex[NVN_STAGE_CS][i];
|
||||
if (im && i - 128 >= 32) break;
|
||||
view_t v; int hv = 0;
|
||||
const VkTexImage *t = h ? vk_texture_by_id_locked(NVN_HANDLE_TEX(h), &v, &hv) : NULL;
|
||||
if (t && (i == 0 || h != ex->tex[NVN_STAGE_CS][0] || im))
|
||||
o += snprintf(line + o, sizeof line - o, " %s%d=%ux%u/f%d@%#llx", im ? "img" : "tex", im ? i - 128 : i,
|
||||
t->width, t->height, t->format, (unsigned long long)t->addr);
|
||||
}
|
||||
for (int i = 0; i < 18 && o < (int)sizeof line - 60; i++)
|
||||
if (ex->ubo[NVN_STAGE_CS][i].size)
|
||||
o += snprintf(line + o, sizeof line - o, " ubo%d=%#llx+%#x", i + 3,
|
||||
(unsigned long long)ex->ubo[NVN_STAGE_CS][i].addr, (unsigned)ex->ubo[NVN_STAGE_CS][i].size);
|
||||
rt_log("vk_exec: its bindings:%s", line);
|
||||
}
|
||||
|
||||
// NX2NAVI_LOG_CS_BINDS: an untranslated program the fallback leaves alone, so its output keeps what it held (black when
|
||||
// nothing else wrote it): why, and what it binds. in_place -1: not a tensor program (its translation failed). Each
|
||||
// (program, output) once, 256 at most. Texture lock held.
|
||||
static void log_fallback_skip_locked(const VkExec *ex, const VkTexImage *out, int in_place) {
|
||||
static struct { uint64_t prog, d; } seen[256];
|
||||
static int n;
|
||||
uint64_t pr = ex->prog ? ex->prog->serial : 0, d = out ? out->addr : 0;
|
||||
for (int k = 0; k < n; k++)
|
||||
if (seen[k].prog == pr && seen[k].d == d) return;
|
||||
if (n == 256) return;
|
||||
seen[n].prog = pr, seen[n].d = d, n++;
|
||||
if (in_place < 0)
|
||||
rt_log("vk_exec: fallback leaves prog %llu alone: not translated and no tensor-core ops, so nothing stands in",
|
||||
(unsigned long long)pr);
|
||||
else if (!out)
|
||||
rt_log("vk_exec: fallback leaves prog %llu alone: it binds no single-sample 2D colour image to write",
|
||||
(unsigned long long)pr);
|
||||
else
|
||||
rt_log("vk_exec: fallback leaves prog %llu alone: %s; its output %ux%u fmt %d at %#llx", (unsigned long long)pr,
|
||||
in_place ? "it also samples its output (in place)"
|
||||
: "no RGBA8 input and no input in the output's format, no larger than the output",
|
||||
out->width, out->height, out->format, (unsigned long long)out->addr);
|
||||
log_cs_bindings_locked(ex);
|
||||
}
|
||||
|
||||
static void untranslated_dispatch_fallback(VkExec *ex) {
|
||||
static int on = -1;
|
||||
if (on < 0) on = rt_knob("CS_FALLBACK", "1");
|
||||
if (!on || !uses_tensor_ops(ex)) return;
|
||||
const VkTexImage *dst = NULL, *src = NULL;
|
||||
if (!on) return;
|
||||
if (!uses_tensor_ops(ex)) { // its translation failed, and no stand-in exists for programs without tensor ops
|
||||
if (knob_log_cs_binds()) {
|
||||
vk_texture_lock();
|
||||
log_fallback_skip_locked(ex, NULL, -1);
|
||||
vk_texture_unlock();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const VkTexImage *dst = NULL, *src = NULL, *out;
|
||||
int in_place = 0;
|
||||
vk_texture_lock();
|
||||
for (int i = 0; i < 32; i++) {
|
||||
uint64_t h = ex->img[NVN_STAGE_CS][i];
|
||||
@@ -4111,11 +4167,12 @@ static void untranslated_dispatch_fallback(VkExec *ex) {
|
||||
(!dst || (uint64_t)t->width * t->height > (uint64_t)dst->width * dst->height))
|
||||
dst = t;
|
||||
}
|
||||
out = dst;
|
||||
for (int i = 0; dst && i < 128; i++) { // an in-place pass (its output also sampled) is left alone
|
||||
uint64_t h = ex->tex[NVN_STAGE_CS][i];
|
||||
view_t v; int hv = 0;
|
||||
const VkTexImage *t = h ? vk_texture_by_id_locked(NVN_HANDLE_TEX(h), &v, &hv) : NULL;
|
||||
if (t && t->image == dst->image) { dst = NULL; break; }
|
||||
if (t && t->image == dst->image) { dst = NULL; in_place = 1; break; }
|
||||
}
|
||||
for (int i = 0; dst && i < 128; i++) {
|
||||
uint64_t h = ex->tex[NVN_STAGE_CS][i];
|
||||
@@ -4131,6 +4188,7 @@ static void untranslated_dispatch_fallback(VkExec *ex) {
|
||||
src = t;
|
||||
}
|
||||
if (dst && src) vk_texture_storage_bound_locked(dst);
|
||||
else if (knob_log_cs_binds()) log_fallback_skip_locked(ex, out, in_place);
|
||||
if (dst && src && knob_log_cs_binds()) { // each distinct (program, source, target) once, 256 at most
|
||||
static struct { uint64_t prog, s, d; } seen[256];
|
||||
static int n;
|
||||
@@ -4142,23 +4200,7 @@ static void untranslated_dispatch_fallback(VkExec *ex) {
|
||||
rt_log("vk_exec: fallback blit prog %llu: %ux%u fmt %d at %#llx -> %ux%u fmt %d at %#llx",
|
||||
(unsigned long long)(ex->prog ? ex->prog->serial : 0), src->width, src->height, src->format,
|
||||
(unsigned long long)src->addr, dst->width, dst->height, dst->format, (unsigned long long)dst->addr);
|
||||
char line[1600]; // everything the untranslated program binds: what a stand-in could use instead
|
||||
int o = 0;
|
||||
for (int i = 0; i < 160 && o < (int)sizeof line - 80; i++) {
|
||||
int im = i >= 128;
|
||||
uint64_t h = im ? ex->img[NVN_STAGE_CS][i - 128 < 32 ? i - 128 : 0] : ex->tex[NVN_STAGE_CS][i];
|
||||
if (im && i - 128 >= 32) break;
|
||||
view_t v; int hv = 0;
|
||||
const VkTexImage *t = h ? vk_texture_by_id_locked(NVN_HANDLE_TEX(h), &v, &hv) : NULL;
|
||||
if (t && (i == 0 || h != ex->tex[NVN_STAGE_CS][0] || im))
|
||||
o += snprintf(line + o, sizeof line - o, " %s%d=%ux%u/f%d@%#llx", im ? "img" : "tex", im ? i - 128 : i,
|
||||
t->width, t->height, t->format, (unsigned long long)t->addr);
|
||||
}
|
||||
for (int i = 0; i < 18 && o < (int)sizeof line - 60; i++)
|
||||
if (ex->ubo[NVN_STAGE_CS][i].size)
|
||||
o += snprintf(line + o, sizeof line - o, " ubo%d=%#llx+%#x", i + 3,
|
||||
(unsigned long long)ex->ubo[NVN_STAGE_CS][i].addr, (unsigned)ex->ubo[NVN_STAGE_CS][i].size);
|
||||
rt_log("vk_exec: its bindings:%s", line);
|
||||
log_cs_bindings_locked(ex);
|
||||
}
|
||||
}
|
||||
VkImage si = src ? src->image : VK_NULL_HANDLE, di = dst ? dst->image : VK_NULL_HANDLE;
|
||||
|
||||
@@ -2104,6 +2104,84 @@ static void mirror_log(uint64_t frame) {
|
||||
a.flush_bytes / f / M, a.flush_calls / f, a.flush_sum / f / M);
|
||||
}
|
||||
|
||||
// After vram_log: every heap's usage as the driver reports it (VK_EXT_memory_budget) beside VMA's share of it, VMA by
|
||||
// memory type, and the process's private commit with its write-combined part (host-visible memory the driver maps
|
||||
// uncached), to tell which memory a long session grows. When the write-combined total (VMA's blocks where that is not
|
||||
// known) grew by 2 GiB since the last look, VMA's detailed map goes to vma-frame<N>.json beside the log, 4 at most.
|
||||
// The process's part walks the whole address space (plat_mem_census), 100-240 ms in a long session, so it runs on a
|
||||
// thread of its own (census_main) and logs a line of its own; a look while the last walk still runs goes without it.
|
||||
typedef struct { VkCtx *c; uint64_t frame; } CensusJob;
|
||||
static volatile int32_t census_busy;
|
||||
|
||||
static void census_main(void *arg) {
|
||||
CensusJob j = *(CensusJob *)arg;
|
||||
free(arg);
|
||||
const double M = 1048576.0;
|
||||
uint64_t priv = 0, wc = 0, wcn = 0, now;
|
||||
int have = plat_mem_census(&priv, &wc, &wcn);
|
||||
if (have) {
|
||||
rt_log("mem: process frame %llu: private %.0f MiB, write-combined %.0f MiB in %llu allocations",
|
||||
(unsigned long long)j.frame, priv / M, wc / M, (unsigned long long)wcn);
|
||||
now = wc;
|
||||
} else {
|
||||
VmaBudget vb[VK_MAX_MEMORY_HEAPS];
|
||||
vmaGetHeapBudgets(j.c->vma, vb);
|
||||
now = 0;
|
||||
for (uint32_t h = 0; h < j.c->mem_props.memoryHeapCount && h < VK_MAX_MEMORY_HEAPS; h++) now += vb[h].statistics.blockBytes;
|
||||
}
|
||||
static uint64_t base;
|
||||
static int dumps = -1; // -1: no baseline yet
|
||||
if (dumps < 0) base = now, dumps = 0;
|
||||
else if (dumps < 4 && now >= base + (2ull << 30) && rt_log_path()) {
|
||||
base = now, dumps++;
|
||||
const char *lp = rt_log_path(), *sl = strrchr(lp, '/'), *bs = strrchr(lp, '\\');
|
||||
if (bs && (!sl || bs > sl)) sl = bs;
|
||||
char path[1024];
|
||||
snprintf(path, sizeof path, "%.*svma-frame%llu.json", sl ? (int)(sl - lp) + 1 : 0, lp, (unsigned long long)j.frame);
|
||||
char *json = NULL;
|
||||
vmaBuildStatsString(j.c->vma, &json, VK_TRUE);
|
||||
FILE *f = json ? fopen(path, "wb") : NULL;
|
||||
int ok = f && fputs(json, f) >= 0;
|
||||
if (f && fclose(f)) ok = 0;
|
||||
rt_log("mem: vma detailed map %s %s", ok ? "written to" : "not written:", path);
|
||||
if (json) vmaFreeStatsString(j.c->vma, json);
|
||||
}
|
||||
plat_xchg32(&census_busy, 0);
|
||||
}
|
||||
|
||||
static void heap_log(VkCtx *c, uint64_t frame, const VmaBudget *vb) {
|
||||
const double M = 1048576.0;
|
||||
VkPhysicalDeviceMemoryBudgetPropertiesEXT bp = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT};
|
||||
if (c->has_memory_budget) {
|
||||
VkPhysicalDeviceMemoryProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, .pNext = &bp};
|
||||
vkGetPhysicalDeviceMemoryProperties2(c->phys, &p2);
|
||||
}
|
||||
char line[1536];
|
||||
int o = snprintf(line, sizeof line, "mem: heaps frame %llu:", (unsigned long long)frame);
|
||||
for (uint32_t h = 0; h < c->mem_props.memoryHeapCount && h < VK_MAX_MEMORY_HEAPS && o < (int)sizeof line - 160; h++)
|
||||
o += snprintf(line + o, sizeof line - (size_t)o, " heap %u (%s) used %.0f of %.0f MiB, vma %u blocks %.0f MiB, %u allocations %.0f MiB;",
|
||||
h, c->mem_props.memoryHeaps[h].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ? "device" : "host",
|
||||
(c->has_memory_budget ? bp.heapUsage[h] : vb[h].usage) / M,
|
||||
(c->has_memory_budget ? bp.heapBudget[h] : vb[h].budget) / M, vb[h].statistics.blockCount,
|
||||
vb[h].statistics.blockBytes / M, vb[h].statistics.allocationCount, vb[h].statistics.allocationBytes / M);
|
||||
rt_log("%s", line);
|
||||
VmaTotalStatistics ts;
|
||||
vmaCalculateStatistics(c->vma, &ts);
|
||||
o = snprintf(line, sizeof line, "mem: vma by type frame %llu:", (unsigned long long)frame);
|
||||
for (uint32_t t = 0; t < c->mem_props.memoryTypeCount && t < VK_MAX_MEMORY_TYPES && o < (int)sizeof line - 120; t++) {
|
||||
const VmaDetailedStatistics *d = &ts.memoryType[t];
|
||||
if (!d->statistics.blockCount) continue;
|
||||
o += snprintf(line + o, sizeof line - (size_t)o, " type %u: %u blocks %.0f MiB, %u allocations %.0f MiB, largest %.1f MiB;", t,
|
||||
d->statistics.blockCount, d->statistics.blockBytes / M, d->statistics.allocationCount,
|
||||
d->statistics.allocationBytes / M, d->allocationSizeMax / M);
|
||||
}
|
||||
rt_log("%s", line);
|
||||
if (plat_xchg32(&census_busy, 1)) return;
|
||||
CensusJob *j = malloc(sizeof *j);
|
||||
if (j) *j = (CensusJob){c, frame};
|
||||
if (!j || !plat_thread_spawn(census_main, j, "mem census", 0)) free(j), plat_xchg32(&census_busy, 0);
|
||||
}
|
||||
|
||||
// With NX2NAVI_TRACE=perf every 600 frames: what holds device-local memory, to see what grows over a long session.
|
||||
// VMA's blocks and allocations on the device-local heaps, texture entries with their own memory, the VRAM mirrors and
|
||||
// the objects waiting for their last submission to retire.
|
||||
@@ -2126,6 +2204,7 @@ static void vram_log(uint64_t frame) {
|
||||
alloc_bytes / M, (unsigned long long)t.live, (unsigned long long)t.own_live, t.bytes_live / M,
|
||||
(unsigned long long)t.released, (unsigned long long)t.own_released, t.bytes_released / M, (long long)m_live_n,
|
||||
m_live_bytes / M, dead_pending());
|
||||
heap_log(c, frame, vb);
|
||||
}
|
||||
|
||||
// Device class: INTEGRATED -> uma; a discrete GPU with a DEVICE_LOCAL heap of 1 GiB or more beside a
|
||||
|
||||
Reference in New Issue
Block a user