mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 17:59:58 -04:00
Make the mesh fallback's programs on up to four worker threads instead of one.
A place's task and mesh programs all arrive in its first frames, and each one's draws are left out until its compute pipelines are built, so with one thread the foliage of a first visit filled in one program at a time. NX2NAVI_MESH_FALLBACK_WORKERS (auto: one thread for each 4 logical processors, 1 to 4) sets how many threads make them, and the log says how long the queue took to empty the first time. Measured with the fallback forced on, no pipeline cache and new exe names (cold driver cache), the adult save's first 75 s: with 1 worker the first 5 programs were ready after 420 ms, 3,266 draws were skipped while a pipeline or program was pending, 1% low 16.1 fps and 145 frames over 50 ms; with 4 workers 256 ms, 956 draws, 55.7 fps and 35. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5036,9 +5036,10 @@ static MfbVs mfb_vs_tab[MFB_TAB];
|
||||
static struct {
|
||||
PlatMutex lock;
|
||||
PlatCond wake;
|
||||
PlatThread *th;
|
||||
int threads, busy; // workers started, workers making a program now
|
||||
MfbCs *head, *tail;
|
||||
uint64_t made, failed, pending_skips;
|
||||
uint64_t first_ms, drained; // the first program's queueing; the queue has emptied once (logged)
|
||||
} MFB = {.lock = PLAT_MUTEX_INIT};
|
||||
|
||||
static uint32_t mfb_binding_base(const GfxShader *s) { // one past the highest binding the module declares
|
||||
@@ -5090,6 +5091,16 @@ static void mfb_make(MfbCs *e) {
|
||||
__atomic_store_n(&e->state, ok ? 1 : -1, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
// The programs queued at their first draws are made by NX2NAVI_MESH_FALLBACK_WORKERS threads (auto: one for each 4
|
||||
// logical processors, 1 to 4). A place's mesh programs all arrive in its first frames and each one's draws are left
|
||||
// out until its compute pipelines are built (up to seconds each on some drivers), so with one thread the foliage of a
|
||||
// first visit filled in one program at a time. The first time the queue empties the log says how long it took.
|
||||
static int mfb_worker_count(void) {
|
||||
const char *v = cfg_value("NX2NAVI_MESH_FALLBACK_WORKERS");
|
||||
int n = strcmp(v, "auto") ? atoi(v) : (int)plat_cpu_usable() / 4;
|
||||
return n < 1 ? 1 : n > 4 ? 4 : n;
|
||||
}
|
||||
|
||||
static void mfb_worker(void *arg) {
|
||||
(void)arg;
|
||||
plat_thread_priority(PLAT_PRIO_BELOW_NORMAL); // as the pipeline workers' optimised builds: the game's threads go first
|
||||
@@ -5098,8 +5109,15 @@ static void mfb_worker(void *arg) {
|
||||
while (!MFB.head) plat_cond_wait(&MFB.wake, &MFB.lock);
|
||||
MfbCs *e = MFB.head;
|
||||
if (!(MFB.head = e->next)) MFB.tail = NULL;
|
||||
MFB.busy++;
|
||||
plat_mutex_unlock(&MFB.lock);
|
||||
mfb_make(e);
|
||||
plat_mutex_lock(&MFB.lock);
|
||||
if (!--MFB.busy && !MFB.head && !MFB.drained++)
|
||||
rt_log("vk: mesh fallback: %llu programs made (%llu refused) on %d threads, the queue empty %llu ms after the "
|
||||
"first program was queued (NX2NAVI_MESH_FALLBACK_WORKERS)", (unsigned long long)MFB.made,
|
||||
(unsigned long long)MFB.failed, MFB.threads, (unsigned long long)(plat_now_ms() - MFB.first_ms));
|
||||
plat_mutex_unlock(&MFB.lock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5132,7 +5150,15 @@ static MfbCs *mfb_cs_get(VkExec *ex, const GfxShader *ms, const GfxShader *ts) {
|
||||
return e;
|
||||
}
|
||||
plat_mutex_lock(&MFB.lock);
|
||||
if (!MFB.th) plat_cond_init(&MFB.wake), MFB.th = plat_thread_new(mfb_worker, NULL, "mesh fallback");
|
||||
if (!MFB.threads) {
|
||||
plat_cond_init(&MFB.wake);
|
||||
MFB.first_ms = plat_now_ms();
|
||||
for (int w = mfb_worker_count(); w > 0; w--) {
|
||||
PlatThread *t = plat_thread_new(mfb_worker, NULL, "mesh fallback");
|
||||
if (t) plat_thread_detach(t), MFB.threads++;
|
||||
}
|
||||
if (!MFB.threads) rt_fatal("vk: mesh fallback: cannot start a worker thread");
|
||||
}
|
||||
if (MFB.tail) MFB.tail->next = e;
|
||||
else MFB.head = e;
|
||||
MFB.tail = e;
|
||||
|
||||
Reference in New Issue
Block a user