mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 15:59:59 -04:00
Count only the making of textures against a frame's texture creation time.
The limit on what a frame's pool refreshes may spend creating textures was charged with the whole refresh, including its check of every entry the pools hold. In Kakariko that check takes 0.8 ms a submission, six submissions a frame, so most of the 6 ms was gone before a texture was made and the frame's later refreshes made none: 87 refreshes in 600 frames, with 1,090 slots left between them. The game moves about thirty textures to new storage every four or five frames there, and the ones a refresh left were on screen as their grey stand-ins for a frame; a player's recording shows three lamp posts turn grey for one frame that way. The limit now counts the time the lookups spend making entries and uploading them the first time. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -585,6 +585,7 @@ const VkTexImage *vk_texture_exact_by_id_locked(int id, view_t *view, int *has_v
|
||||
uint32_t vk_texture_slots_gen(void);
|
||||
int vk_texture_slot_count_locked(void);
|
||||
void vk_texture_create_budget_locked(int n); // slot lookups create at most n entries (mapped storage only); -1 any
|
||||
uint64_t vk_texture_pool_make_ns_take(void); // ns the pool's lookups spent making and first uploading entries since the last call
|
||||
int vk_texture_create_deferred_locked(void); // a lookup since the last call left a creation to the budget // one past the highest texture slot registered so far (or more)
|
||||
int vk_sampler_slot_count_locked(void);
|
||||
// Bindless pools (vk_exec_draw.c, "texture and sampler pools"): set 2 of every pipeline layout. Shaders that index
|
||||
|
||||
@@ -1965,7 +1965,7 @@ static struct {
|
||||
int ready, uab, sealed; // sealed: a part of the current submission already reads sets[cur]
|
||||
uint32_t kinds, gen, epoch, sgen;
|
||||
int retry; // the last sync left slots to the creation budget
|
||||
uint64_t frame, frame_ns; // the frame of the last sync, and the sync time spent in it (pool_create_ns)
|
||||
uint64_t frame, frame_ns; // the frame of the last sync, and the time its syncs spent making textures (pool_create_ns)
|
||||
uint64_t n_frame_stops, n_defer_skips; // syncs that created nothing for the frame's time, lookups they skipped
|
||||
uint64_t *tok; // per texture slot: vk_texture_slot_token it was filled under (0: stand-ins)
|
||||
VkImageView *view; // [kind * VK_POOL_TEX + id]: what the entry holds
|
||||
@@ -2198,9 +2198,16 @@ static int pool_create_budget(void) {
|
||||
// The refresh runs before every draw that binds the pools, not once per submission, so the count above held for each
|
||||
// draw: an area load made 4,925 entries (1.7 GB of uploads) in one 430 ms frame, and while slots were left over every
|
||||
// draw walked the whole table and looked each of them up again (key and hash), about 100 ms of that frame on its own.
|
||||
// Once a frame's refreshes have taken NX2NAVI_POOL_CREATE_MS (default 6; 0: no limit), its later ones create nothing,
|
||||
// and skip the slots left earlier in the frame (pool_defer) instead of looking them up again; the first refresh of
|
||||
// each frame keeps its count budget. The slots left keep their stand-in, a few frames longer in a large load.
|
||||
// Once a frame's refreshes have spent NX2NAVI_POOL_CREATE_MS (default 6; 0: no limit) making textures, its later ones
|
||||
// create nothing, and skip the slots left earlier in the frame (pool_defer) instead of looking them up again; the
|
||||
// first refresh of each frame keeps its count budget. The slots left keep their stand-in, a few frames longer in a
|
||||
// large load.
|
||||
// The time counted is what the lookups spend making entries and uploading them the first time
|
||||
// (vk_texture_pool_make_ns_take). It was the whole refresh, with its check of every entry the pools hold: in Kakariko
|
||||
// that check alone takes 0.8 ms a submission, six submissions a frame, so most of the 6 ms was gone before a texture
|
||||
// was made, and the frame's later refreshes made none. The game moves about thirty of its textures to new storage
|
||||
// every four or five frames there; the ones a refresh left were on screen as their grey stand-ins for a frame (three
|
||||
// lamp posts in one recorded frame), 87 refreshes in 600 frames with 1,090 slots left between them.
|
||||
static uint64_t pool_create_ns(void) {
|
||||
static int64_t ns = -1, load_ns;
|
||||
if (ns < 0) {
|
||||
@@ -2551,10 +2558,11 @@ static void pool_sync(VkExec *ex) {
|
||||
if (PL.sealed) return; // current when checked: a change since waits for the next sync, which takes a new set
|
||||
uint64_t t0 = kern_now_ns(), f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
|
||||
if (f != PL.frame) PL.frame = f, PL.frame_ns = 0;
|
||||
vk_texture_pool_make_ns_take(); // what other lookups left: only this sync's making counts for the frame
|
||||
pool_sync_entries(ex);
|
||||
uint64_t t1 = kern_now_ns();
|
||||
PL.sync_ns += t1 - t0;
|
||||
PL.frame_ns += t1 - t0;
|
||||
PL.frame_ns += vk_texture_pool_make_ns_take();
|
||||
if (switched) {
|
||||
vk_texture_lock();
|
||||
pool_catch_up(from, pre); // what the other sets got since; this sync's own writes went into it already
|
||||
|
||||
@@ -1521,6 +1521,7 @@ static int pool_presnap(void) {
|
||||
if (mode < 0) mode = rt_knob("POOL_PRESNAP", "1");
|
||||
return RT_KNOB_ON(mode);
|
||||
}
|
||||
static void pool_made(uint64_t t0); // below, with the pool's creation budget
|
||||
|
||||
// The submission being recorded checked the pool's entries by this list: for the idle clock it walked the pool
|
||||
// (vk_texture_new_submit).
|
||||
@@ -1556,7 +1557,9 @@ int vk_texture_pool_fresh_locked(void) {
|
||||
}
|
||||
if (e->released) continue;
|
||||
if (!e->uploaded || e->checked != submit_epoch) {
|
||||
uint64_t m0 = e->uploaded ? 0 : kern_now_ns(); // a first upload is part of making the entry
|
||||
make_fresh_snap(e);
|
||||
if (m0) pool_made(m0);
|
||||
e->checked = submit_epoch;
|
||||
n_pool_checks++;
|
||||
}
|
||||
@@ -4123,6 +4126,12 @@ static int want_take(void) {
|
||||
}
|
||||
|
||||
void vk_texture_create_budget_locked(int n) { create_budget = n, create_deferred = 0; }
|
||||
|
||||
// What the pool's lookups have spent making entries (entry_of under the budget) and uploading them the first time,
|
||||
// since the last call: the time vk_exec_draw.c pool_create_ns limits in a frame. Texture lock held where it is added.
|
||||
static uint64_t pool_make_ns;
|
||||
uint64_t vk_texture_pool_make_ns_take(void) { return __atomic_exchange_n(&pool_make_ns, 0, __ATOMIC_RELAXED); }
|
||||
static void pool_made(uint64_t t0) { __atomic_fetch_add(&pool_make_ns, kern_now_ns() - t0, __ATOMIC_RELAXED); }
|
||||
int vk_texture_create_deferred_locked(void) { int d = create_deferred; create_deferred = 0; return d; }
|
||||
|
||||
// NX2NAVI_TEX_STALE_KEPT (default 1; 0: the stand-in, as before): a finalized slot of a CPU-written texture resolves to
|
||||
@@ -4189,7 +4198,9 @@ static Tex *slot_resolve(TexSlot *s, view_t *view, int *has_view) {
|
||||
else if (!mem_readable((uint64_t)(uintptr_t)s->t.mem, s->t.L.size)) e = NULL;
|
||||
else if (!create_budget && !(s->cwant && want_take())) create_deferred = 1;
|
||||
else {
|
||||
uint64_t m0 = kern_now_ns();
|
||||
e = entry_of(&s->t);
|
||||
pool_made(m0);
|
||||
if (create_budget > 0) create_budget--;
|
||||
}
|
||||
if (e) s->cwant = 0;
|
||||
@@ -4320,7 +4331,9 @@ const VkTexImage *vk_texture_by_id_locked(int id, view_t *view, int *has_view) {
|
||||
round_checks++;
|
||||
// a released entry here is a finalized slot's own (stale_kept): the storage may be the game's to free or reuse
|
||||
if (e && !e->released && (!e->uploaded || e->checked != submit_epoch)) {
|
||||
uint64_t m0 = pool_ctx && !e->uploaded ? kern_now_ns() : 0; // the pool's lookup: as in its list check
|
||||
make_fresh_snap(e);
|
||||
if (m0) pool_made(m0);
|
||||
e->checked = submit_epoch;
|
||||
touch(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user