Record the draws rejected during preparation in a captured frame.

A draw can be left out before it opens a render pass, and the pass list of a frame capture then showed nothing of it.
passes.txt now ends with the rejected draws of the captured frame by mesh or vertex draw and reason, each with the
first program it met, and says so when there were none. A draw left out by NX2NAVI_SKIP_PROG or NX2NAVI_SKIP_SHADERS
is counted under a reason of its own. The frame to capture and its files are set together under the recorder's lock.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
DeepDaddyTTV
2026-11-10 19:36:32 -05:00
committed by chrg6
parent d577f8c325
commit 5b7703e08e
3 changed files with 55 additions and 25 deletions

View File

@@ -8,7 +8,7 @@
// ..._tm.png float formats: x/(1+x) of the same image (the plain one clamps);
// in both, a pixel with a NaN channel is magenta
// passes.txt per pass or dispatch: targets, draws, each distinct pipeline + texture set with its shaders' SPIR-V
// hashes (sh_<hash>.spv written once) and the bound textures with their samplers
// hashes (sh_<hash>.spv written once) and the bound textures with their samplers; draw preparation rejections by reason while the capture ran
// images.txt per image: channel min/max, distinct texel values over the image and over its top quarter
// Sampled 8-bit 2D textures up to TEX2D_CAP texels are copied once each as pass_<seq>_tex<id>_... at the end of the pass
// that samples them; texture lines carry the storage address, mirror state, upload count and the image's and slot's
@@ -474,6 +474,32 @@ static int active(void) { // passes_f is NULL before a dump that opens its fil
}
static uint64_t frame_now(void) { return __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) + 1; }
// A draw can be rejected before it opens a render pass. Count it against the captured frame as a whole.
static struct { uint64_t count, first_prog; } skipped[2][SK_COUNT];
void vk_dump_draw_skipped(const VkExec *ex, int mesh, int why) {
plat_mutex_lock(&rec_lock);
if (!finished && passes_f && frame_now() == dump_frame) {
if (!skipped[mesh][why].count) skipped[mesh][why].first_prog = ex->prog ? ex->prog->serial : 0;
skipped[mesh][why].count++;
}
plat_mutex_unlock(&rec_lock);
}
static void write_skipped(uint64_t frame) {
uint64_t total = 0;
for (int m = 0; m < 2; m++) for (int k = 0; k < SK_COUNT; k++) {
uint64_t n = skipped[m][k].count;
if (!n) continue;
fprintf(passes_f, " skipped %s: %llu (%s, first program %llu)\n", m ? "mesh" : "vertex",
(unsigned long long)n, vk_draw_skip_names[k], (unsigned long long)skipped[m][k].first_prog);
total += n;
}
fprintf(passes_f, "frame %llu: %llu draws rejected during draw preparation while capture was active\n",
(unsigned long long)frame, (unsigned long long)total);
memset(skipped, 0, sizeof skipped);
}
typedef struct { char *s; size_t n, cap; } Str;
__attribute__((format(printf, 2, 3))) static void sp(Str *b, const char *fmt, ...) {
@@ -1226,6 +1252,15 @@ static int thumb_white(uint64_t f) {
return bright * 100 > n * 97;
}
// Publish the selected frame and its output files together to the recording hooks.
static void open_frame(uint64_t frame) {
plat_mutex_lock(&rec_lock);
snprintf(dir, sizeof dir, "%s/f%llu", base_dir, (unsigned long long)frame);
open_files();
dump_frame = frame;
plat_mutex_unlock(&rec_lock);
}
static void white_check(uint64_t frame) {
static int run; // consecutive white thumbnails: white runs are mostly 1-2 frames, too short for a dump 4 frames on
if (frame < 1800) return;
@@ -1234,9 +1269,7 @@ static void white_check(uint64_t frame) {
run = w ? run + 1 : 0;
if (run >= 3) { // frames frame-5..frame-3 white: the run is likely still on 4 frames later
run = 0;
dump_frame = frame + 1;
snprintf(dir, sizeof dir, "%s/f%llu", base_dir, (unsigned long long)dump_frame);
open_files();
open_frame(frame + 1);
rt_log("vk_dump: frames %llu-%llu were white; frame %llu goes to %s", (unsigned long long)(frame - 5),
(unsigned long long)(frame - 3), (unsigned long long)dump_frame, dir);
}
@@ -1251,18 +1284,14 @@ void vk_dump_present(uint64_t frame) {
}
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;
open_frame(frame + 1);
rt_log("vk_dump: frame %llu goes to %s", (unsigned long long)dump_frame, dir);
}
if (key_mode && dump_frame == UINT64_MAX) { // NX2NAVI_DUMP=key: a new press of Insert names the next frame
static int held;
int now = input_dump_key();
if (now && !held) {
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;
open_frame(frame + 1);
rt_log("vk_dump: Insert: frame %llu goes to %s", (unsigned long long)dump_frame, dir);
}
held = now;
@@ -1274,14 +1303,13 @@ void vk_dump_present(uint64_t frame) {
free(txt);
file_more = n > 8 ? 7 : n > 1 ? n - 1 : 0;
plat_file_delete(dump_file);
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;
open_frame(frame + 1);
rt_log("vk_dump: %s found: frame %llu goes to %s", dump_file, (unsigned long long)dump_frame, dir);
}
if (frame != dump_frame) return;
plat_mutex_lock(&rec_lock);
finished = 1;
write_skipped(frame);
plat_mutex_unlock(&rec_lock);
vk_sync_finish(); // the frame's copies are converted and written
mq_write();
@@ -1305,9 +1333,7 @@ void vk_dump_present(uint64_t frame) {
}
if (file_more > 0) { // NX2NAVI_DUMP_FILE with a count: the next frame too
file_more--;
snprintf(dir, sizeof dir, "%s/f%llu", base_dir, (unsigned long long)(frame + 1));
open_files();
dump_frame = frame + 1;
open_frame(frame + 1);
rt_log("vk_dump: frame %llu goes to %s", (unsigned long long)dump_frame, dir);
}
}

View File

@@ -254,6 +254,10 @@ void vk_dump_init(void); // reads the environment; vk_exec_recor
void vk_dump_pass_end(VkExec *ex); // after vkCmdEndRendering
// after a draw's binds; mesh: a mesh draw (s->vs is its mesh stage, s->ts its task stage or NULL)
void vk_dump_draw(VkExec *ex, const VkPipeState *s, VkPipeline p, const VkPipeInfo *info, int mesh);
enum { SK_DISABLED, SK_SCISSOR, SK_NO_PROGRAM, SK_NO_VERTEX_STAGE, SK_SHADER_PENDING, SK_SHADER_FAILED, SK_DLAA,
SK_PIPE_PENDING, SK_PIPE_FAILED, SK_POOL_OFF, SK_PROG_FILTER, SK_SHADER_FILTER, SK_COUNT };
extern const char *const vk_draw_skip_names[SK_COUNT];
void vk_dump_draw_skipped(const VkExec *ex, int mesh, int why);
// Around a mesh draw of the dumped frame (after vk_dump_draw): a primitives-generated query, listed in mesh_prims.txt.
// begin returns the query, or -1 when none was begun; end takes that value.
int vk_dump_mesh_begin(VkExec *ex);

View File

@@ -4064,13 +4064,12 @@ static int pipe_memo_on(void) {
// the draws issued and skipped since the last line (only when something was skipped). A black screen with draws
// skipped for "shader failed" or "pipeline failed" points at the translator or the pipeline; draws issued and still
// nothing on screen point at the shaders' results (NX2NAVI_DUMP).
enum { SK_DISABLED, SK_SCISSOR, SK_NO_PROGRAM, SK_NO_VERTEX_STAGE, SK_SHADER_PENDING, SK_SHADER_FAILED, SK_DLAA,
SK_PIPE_PENDING, SK_PIPE_FAILED, SK_POOL_OFF, SK_COUNT };
static const char *const sk_names[SK_COUNT] = {
"rendering disabled (render condition)", "empty scissor", "no program bound",
const char *const vk_draw_skip_names[SK_COUNT] = {
"rendering disabled", "empty scissor", "no program bound",
"no vertex (or mesh) stage in the program", "shader still translating",
"shader failed to translate (see gfx_shader: translation failed)", "replaced by the upscaler",
"pipeline still building", "pipeline could not be created", "uses the texture pools (NX2NAVI_POOL=0)"};
"pipeline still building", "pipeline could not be created", "uses the texture pools (NX2NAVI_POOL=0)",
"excluded by NX2NAVI_SKIP_PROG", "excluded by NX2NAVI_SKIP_SHADERS"};
#define DRAW_STATS_FRAMES 600
static struct { uint64_t issued[2], skipped[2][SK_COUNT], frame; uint32_t first[2]; } DRS;
@@ -4105,7 +4104,7 @@ static void draw_stats_tick(void) {
int o = snprintf(line, sizeof line, "vk: %s draws over %llu frames: %llu issued, skipped:", m ? "mesh" : "vertex",
(unsigned long long)(f - DRS.frame), (unsigned long long)DRS.issued[m]);
for (int k = 0; k < SK_COUNT && o < (int)sizeof line - 60; k++)
if (DRS.skipped[m][k]) o += snprintf(line + o, sizeof line - o, " %s %llu;", sk_names[k], (unsigned long long)DRS.skipped[m][k]);
if (DRS.skipped[m][k]) o += snprintf(line + o, sizeof line - o, " %s %llu;", vk_draw_skip_names[k], (unsigned long long)DRS.skipped[m][k]);
rt_log("%s", line);
}
memset(&DRS, 0, sizeof DRS.issued + sizeof DRS.skipped);
@@ -4124,11 +4123,12 @@ uint32_t vk_exec_pending_draws_take(void) {
static int draw_skipped(const VkExec *ex, int mesh, int why) {
DRS.skipped[mesh][why]++;
if (vk_dump_armed) vk_dump_draw_skipped(ex, mesh, why);
if (why == SK_SHADER_PENDING || why == SK_PIPE_PENDING) pending_draws++;
if (why == SK_PIPE_PENDING) perf_count(PERF_CNT_PIPE_SKIP); // skipped draws only: a lookup that then waited is none
if (!(DRS.first[mesh] >> why & 1)) {
DRS.first[mesh] |= 1u << why;
rt_log("vk: first %s draw skipped because: %s (program %llu)", mesh ? "mesh" : "vertex", sk_names[why],
rt_log("vk: first %s draw skipped because: %s (program %llu)", mesh ? "mesh" : "vertex", vk_draw_skip_names[why],
ex->prog ? (unsigned long long)ex->prog->serial : 0ull);
}
draw_stats_tick();
@@ -4215,7 +4215,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
if (!sc.extent.width || !sc.extent.height) return draw_skipped(ex, mesh, SK_SCISSOR);
if (!ex->prog) return draw_skipped(ex, mesh, SK_NO_PROGRAM);
if (prog_lead_on()) prog_lead(ex->prog, mesh);
if (n_skip_prog && skip_prog_wanted(ex->prog->serial)) return draw_skipped(ex, mesh, SK_DISABLED); // -1 until read
if (n_skip_prog && skip_prog_wanted(ex->prog->serial)) return draw_skipped(ex, mesh, SK_PROG_FILTER); // -1 until read
int has_vs, has_fs, vs_wait = 0, fs_wait = 0, memo = mesh ? 0 : shader_memo_on();
int has_ts = 0, ts_wait = 0, vst = mesh ? NVN_STAGE_MESH : NVN_STAGE_VS;
const GfxShader *vs, *fs, *ts = NULL;
@@ -4260,7 +4260,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
return perf_count(PERF_CNT_SHADER_SKIP), draw_skipped(ex, mesh, SK_SHADER_PENDING);
}
if (!vs || (has_fs && !fs) || (has_ts && !ts)) return draw_skipped(ex, mesh, SK_SHADER_FAILED);
if (shader_skipped(vs) || shader_skipped(fs)) return draw_skipped(ex, mesh, SK_POOL_OFF); // NX2NAVI_SKIP_SHADERS
if (shader_skipped(vs) || shader_skipped(fs)) return draw_skipped(ex, mesh, SK_SHADER_FILTER);
if (vk_dlaa_skip_draw(ex, fs)) return draw_skipped(ex, mesh, SK_DLAA); // the game's FXAA off, or its scaling replaced by DLSS (vk_dlaa.c)
uint32_t fbl = feedback_prepare(ex, fs);
VkPipeState s = ex->pipe;