mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 13:59:56 -04:00
A render target's frame count follows its storage, not the guest's texture object, and a mesh draw no longer waits for a pipeline that is known to be compiling.
Found in the first run of the previous two commits (a first visit of Kokiri Forest from a state that had only seen Hyrule Field): - The count of frames a target was rendered in started again whenever the guest's texture object changed, and the game initializes its render target objects anew every frame at the same storage: the log showed `seen 2129/2128 in 1 frames`, so no target ever became steady and the rule did nothing. The owner of an image is now the storage address the texture cache keys it by. An image handed on to a texture elsewhere still starts at none. - A one-shot mesh draw waited its 8 ms in every frame that met the same pipeline while it compiled for 150 to 1100 ms: 17 waits, 170 ms, every draw skipped at the end, up to four in one frame. A mesh pipeline that has been building for longer than that wait is a compile, and the draws after the first do not wait for it (vk_pipeline_building_ms). - The last wait of a full-screen draw with no picture to hold was 40 ms a draw, and two such draws made 86 ms in one frame. It is 40 ms a frame now. - A one-shot vertex draw skipped at the end of its wait gets its log line however short the wait was (seven were skipped with no line, so their targets could not be named). That run against the same cell of the earlier comparison (same exe path, cache state, route and settings; one run each): the load's worst wait of the draws in one frame 99 ms against 735 ms, no mesh wait over 13 ms against 524 and 206 ms. Two long frames remain in both runs (628 and 862 ms here, 660 and 854 ms there): two compute pipelines built at their first dispatch, about 395 and 397 ms. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -714,6 +714,9 @@ VkPipeline vk_pipeline_graphics(const VkPipeState *s, const VkPipeInfo **info);
|
||||
// wait_ms > 0 waits up to that long for a pending pipeline first. Pipelines built in a run are recorded to
|
||||
// pipeline-keys.bin next to the pipeline cache and prebuilt at the next boot (NX2NAVI_PIPE_PREBUILD=0: not).
|
||||
VkPipeline vk_pipeline_graphics_async(const VkPipeState *s, const VkPipeInfo **info, int *pending, uint32_t wait_ms);
|
||||
// How long the pipeline of s has been building since a draw first missed it, in milliseconds; 0 when it is unknown,
|
||||
// usable, or no draw has missed it.
|
||||
double vk_pipeline_building_ms(const VkPipeState *s);
|
||||
// The stage libraries of a draw the replay has not reached yet, queued to the workers when no pipeline is known for its
|
||||
// state (vk_pipeline.c "stage libraries ahead of their draws"). Returns the libraries queued.
|
||||
int vk_pipeline_hint(const VkPipeState *s);
|
||||
|
||||
@@ -482,7 +482,7 @@ static void free_views(void *arg) { // completion thread, once the submission
|
||||
uint64_t vk_exec_steady_passes; // lookups a steady target alone made per-frame (vk_exec_targets_recent)
|
||||
|
||||
static TfrTarget tfr_of(const VkExecTarget *t) {
|
||||
return (TfrTarget){(uint64_t)(uintptr_t)t->image, t->level, t->base_layer, t->tex ? t->tex->serial : 0};
|
||||
return (TfrTarget){(uint64_t)(uintptr_t)t->image, t->level, t->base_layer, t->img ? t->img->addr : 0};
|
||||
}
|
||||
|
||||
static int steady_on(void) {
|
||||
@@ -522,7 +522,7 @@ void vk_exec_targets_describe(VkExec *ex, char *buf, size_t cap) {
|
||||
int w = snprintf(buf + n, cap - n, "%s%c%d fmt %d %ux%u L%u seen %llu/%llu in %u frames", n ? "; " : "",
|
||||
i < 8 ? 'c' : 'd', i < 8 ? i : 0, (int)t->format, t->width, t->height, t->base_layer,
|
||||
(unsigned long long)(e ? e->last : 0), (unsigned long long)(e ? e->prev : 0),
|
||||
e && e->serial == ft.serial ? e->n : 0);
|
||||
e && e->owner == ft.owner ? e->n : 0);
|
||||
if (w < 0) break;
|
||||
n += (size_t)w;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,10 @@ static uint32_t oneshot_wait_ms(void) {
|
||||
}
|
||||
#define ONESHOT_WAIT_MS oneshot_wait_ms()
|
||||
// A mesh pipeline has no stage libraries and so no fast link: the wait is for its whole build, a few milliseconds
|
||||
// when the pipeline cache holds it and 200 ms or more when it does not. A longer wait only finds out which.
|
||||
// when the pipeline cache holds it and 200 ms or more when it does not. A longer wait only finds out which, and one
|
||||
// that has been building for longer than this is a compile: the draws that meet it in the frames after wait for
|
||||
// nothing (oneshot_ms). Before that rule a first visit waited 8 to 13 ms for each of 17 mesh draws over nine frames,
|
||||
// up to four in one frame, and every one of them was skipped at the end.
|
||||
#define MESH_WAIT_MS 8u
|
||||
static int oneshot_budget_on(void) {
|
||||
static int on = -1;
|
||||
@@ -3370,10 +3373,12 @@ static void pool_charge(uint64_t *pool, uint64_t t0) {
|
||||
*pool = spent < *pool ? *pool - spent : 0;
|
||||
}
|
||||
|
||||
// What a one-shot draw may wait for its pipeline from pool.
|
||||
static uint32_t oneshot_ms(const uint64_t *pool, int mesh) {
|
||||
// What a one-shot draw with the state s may wait for its pipeline from pool.
|
||||
static uint32_t oneshot_ms(const uint64_t *pool, int mesh, const VkPipeState *s) {
|
||||
uint32_t ms = (uint32_t)(*pool / 1000000);
|
||||
return mesh && ms > MESH_WAIT_MS ? MESH_WAIT_MS : ms;
|
||||
if (!mesh || !ms) return ms;
|
||||
if (vk_pipeline_building_ms(s) > MESH_WAIT_MS) return 0; // a compile (MESH_WAIT_MS)
|
||||
return ms > MESH_WAIT_MS ? MESH_WAIT_MS : ms;
|
||||
}
|
||||
|
||||
// ---- wait accounting: what the replay thread spent on draws that found their pipeline or a shader missing
|
||||
@@ -3403,12 +3408,19 @@ static uint32_t link_draw_ms(void) {
|
||||
return (uint32_t)ms;
|
||||
}
|
||||
#define LINK_DRAW_MS link_draw_ms()
|
||||
// How long a full-screen draw waits on for its pipeline once the frame's wait pool is spent and the previous picture
|
||||
// cannot be held any longer (prepare_draw_ex). Every such pipeline has a fast link (vk_pipeline.c gpl_feedback), so
|
||||
// the wait is for stage libraries: a few milliseconds from the driver's cache, and in the one case a player's session
|
||||
// shows the draw had its pipeline 18 ms into this wait. It was 500 ms while a pipeline with a feedback loop waited
|
||||
// for its whole optimised build; with the pool before it, a frame now waits under 100 ms for pipelines in all.
|
||||
// How long the full-screen draws of a frame wait on for their pipelines, in all, once the frame's wait pool is spent
|
||||
// and the previous picture cannot be held any longer (prepare_draw_ex, last_wait). Every such pipeline has a fast link
|
||||
// (vk_pipeline.c gpl_feedback), so the wait is for stage libraries: a few milliseconds from the driver's cache, and
|
||||
// in the one case a player's session shows the draw had its pipeline 18 ms into this wait. It was 500 ms for each
|
||||
// draw while a pipeline with a feedback loop waited for its whole optimised build; with the pool before it, a frame
|
||||
// now waits under 100 ms for pipelines in all.
|
||||
#define FULLSCREEN_LAST_MS 40u
|
||||
static uint64_t *last_wait(void) {
|
||||
static uint64_t frame = ~0ull, left;
|
||||
uint64_t f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
|
||||
if (f != frame) frame = f, left = FULLSCREEN_LAST_MS * 1000000ull;
|
||||
return &left;
|
||||
}
|
||||
static uint64_t *link_budget(void) {
|
||||
static uint64_t frame = ~0ull, left, per_frame = ~0ull;
|
||||
if (per_frame == ~0ull) {
|
||||
@@ -3695,7 +3707,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
int fullscreen = 0; // the wait is a full-screen draw's
|
||||
if (oneshot > 0 && oneshot_budget_on()) {
|
||||
budget = frame_wait();
|
||||
wait_ms = oneshot_ms(budget, mesh);
|
||||
wait_ms = oneshot_ms(budget, mesh, &s);
|
||||
if (wait_ms) t0 = kern_now_ns();
|
||||
} else if (oneshot > 0) {
|
||||
wait_ms = ONESHOT_WAIT_MS;
|
||||
@@ -3745,7 +3757,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
if (!w0) w0 = kern_now_ns();
|
||||
if (oneshot_budget_on()) {
|
||||
uint64_t *pool = frame_wait(), b0 = kern_now_ns();
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, oneshot_ms(pool, mesh));
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, oneshot_ms(pool, mesh, &s));
|
||||
pool_charge(pool, b0);
|
||||
} else {
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, ONESHOT_WAIT_MS);
|
||||
@@ -3753,12 +3765,15 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
}
|
||||
// A full-screen draw still pending after its budget: skipped, it leaves the frame black or unlit. While the
|
||||
// previous picture can stay on screen in its place (vk_frame_hold_left) that is what happens; once that time
|
||||
// is used up the draw waits on, FULLSCREEN_LAST_MS at most, before such a frame is shown.
|
||||
if (pending && fullscreen && !vk_frame_hold_left()) {
|
||||
// is used up the draw waits on, from the FULLSCREEN_LAST_MS of its frame, before such a frame is shown.
|
||||
uint64_t *last = pending && fullscreen && !vk_frame_hold_left() ? last_wait() : NULL;
|
||||
if (last && *last >= 1000000) {
|
||||
why = "full-screen, nothing left to hold the picture";
|
||||
kind = WK_LAST;
|
||||
if (!w0) w0 = kern_now_ns();
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, FULLSCREEN_LAST_MS);
|
||||
uint64_t b0 = kern_now_ns();
|
||||
p = vk_pipeline_graphics_async(&s, &info, &pending, (uint32_t)(*last / 1000000));
|
||||
pool_charge(last, b0);
|
||||
}
|
||||
if (m0) wait_note(kind, m0, pending), draw_stats_tick();
|
||||
PM.valid = !pending && p && info;
|
||||
@@ -3766,7 +3781,8 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
}
|
||||
uint64_t waited = w0 ? kern_now_ns() - w0 : 0;
|
||||
static int wait_logs;
|
||||
if (why && waited >= 2000000 && wait_logs < 200) {
|
||||
// also a one-shot draw skipped at the end of its wait, however short: its target may not be drawn again
|
||||
if (why && (waited >= 2000000 || (pending && kind == WK_ONESHOT)) && wait_logs < 200) {
|
||||
char tg[512];
|
||||
wait_logs++;
|
||||
vk_exec_targets_describe(ex, tg, sizeof tg);
|
||||
|
||||
@@ -3819,6 +3819,18 @@ VkPipeline vk_pipeline_graphics_async(const VkPipeState *s, const VkPipeInfo **i
|
||||
return graphics(s, info, A.on, pending, wait_ms);
|
||||
}
|
||||
|
||||
double vk_pipeline_building_ms(const VkPipeState *s) {
|
||||
if (!s->vs || !P.ready) return 0;
|
||||
GKey k;
|
||||
gkey_fill(s, &k);
|
||||
uint64_t h = key_hash(&k, sizeof k);
|
||||
plat_mutex_lock(&P.lock);
|
||||
const Pipe *p = pipe_find(&k, sizeof k, h);
|
||||
double ms = p && p->building && !p->info.pipeline && p->t_miss ? (double)(plat_now_ns() - p->t_miss) / 1e6 : 0;
|
||||
plat_mutex_unlock(&P.lock);
|
||||
return ms;
|
||||
}
|
||||
|
||||
// ---- boot prewarm from the key file (comment at "pipeline keys")
|
||||
|
||||
static int id_cmp(const void *x, const void *y) { return memcmp(x, y, 32); }
|
||||
|
||||
@@ -18,12 +18,14 @@
|
||||
// frames before, so each draw with a new pipeline waited on the replay thread, and a mesh draw, whose pipeline has no
|
||||
// fast link, for its whole compile. One player's session shows it three times at area changes: frames of 954, 1015
|
||||
// and 684 ms, six mesh draws waiting 52 to 660 ms each in passes whose targets had been rendered in thousands of
|
||||
// frames. An entry therefore also counts the frames its subresource was rendered in, for as long as it is the same
|
||||
// guest texture (its initialization serial: an image taken over by another texture starts again at none). From
|
||||
// TFR_STEADY frames on the target is one the game draws again and again, and its draws are skipped while a pipeline
|
||||
// builds, as in any other frame, however long ago the last one was. A target generated once never gets there; one
|
||||
// generated again at every area load would after TFR_STEADY loads, by when its pipelines are recorded and prebuilt
|
||||
// at the start.
|
||||
// frames. An entry therefore also counts the frames its subresource was rendered in, for as long as the image is the
|
||||
// texture at the same storage (its owner, the storage GPU address the texture cache keys the image by: an image
|
||||
// handed on to a texture elsewhere starts again at none). The guest's texture object does not serve as the owner:
|
||||
// the game initializes its render target objects anew every frame at the same storage, so a count kept per object
|
||||
// never passed one. From TFR_STEADY frames on the target is one the game draws again and again, and its draws are
|
||||
// skipped while a pipeline builds, as in any other frame, however long ago the last one was. A target generated once
|
||||
// never gets there; one generated again at every area load would after TFR_STEADY loads, by when its pipelines are
|
||||
// recorded and prebuilt at the start.
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -33,9 +35,9 @@
|
||||
#define TFR_RECENT 4
|
||||
#define TFR_STEADY 8
|
||||
|
||||
// One render target of a pass: the image handle as a number, the subresource, the guest texture's serial (0 unknown).
|
||||
typedef struct { uint64_t image; uint32_t level, layer; uint64_t serial; } TfrTarget;
|
||||
typedef struct { uint64_t image; uint32_t level, layer, n; uint64_t last, prev, serial; } TargetFrames;
|
||||
// One render target of a pass: the image handle as a number, the subresource, the image's owner (0 unknown).
|
||||
typedef struct { uint64_t image; uint32_t level, layer; uint64_t owner; } TfrTarget;
|
||||
typedef struct { uint64_t image; uint32_t level, layer, n; uint64_t last, prev, owner; } TargetFrames;
|
||||
static TargetFrames tfr[TFR_SETS * TFR_WAYS];
|
||||
|
||||
// The target's entry, or with make the entry it takes (the set's oldest, an empty one first); NULL without make
|
||||
@@ -55,7 +57,7 @@ static inline TargetFrames *tfr_find(const TfrTarget *t, int make) {
|
||||
// The target is rendered in frame stamp.
|
||||
static inline void tfr_note(const TfrTarget *t, uint64_t stamp) {
|
||||
TargetFrames *e = tfr_find(t, 1);
|
||||
if (e->serial != t->serial) e->serial = t->serial, e->n = 0; // another texture has the image now: its own count
|
||||
if (e->owner != t->owner) e->owner = t->owner, e->n = 0; // another texture has the image now: its own count
|
||||
if (e->last != stamp) e->prev = e->last, e->last = stamp, e->n += e->n < UINT32_MAX;
|
||||
}
|
||||
|
||||
@@ -73,10 +75,10 @@ static inline int tfr_recent(const TfrTarget *t, uint64_t stamp) {
|
||||
// No frame before stamp rendered the target.
|
||||
static inline int tfr_first(const TfrTarget *t, uint64_t stamp) { return !tfr_before(t, stamp); }
|
||||
|
||||
// TFR_STEADY frames or more before stamp rendered the target as the texture it is now.
|
||||
// TFR_STEADY frames or more before stamp rendered the target under the owner it has now.
|
||||
static inline int tfr_steady(const TfrTarget *t, uint64_t stamp) {
|
||||
const TargetFrames *e = tfr_find(t, 0);
|
||||
return e && e->serial == t->serial && e->n - (e->last == stamp) >= TFR_STEADY;
|
||||
return e && e->owner == t->owner && e->n - (e->last == stamp) >= TFR_STEADY;
|
||||
}
|
||||
|
||||
// Whether the pass with the n_color colour targets c and the depth target d (NULL: none) is one the game renders
|
||||
|
||||
Reference in New Issue
Block a user