Copy large textures out of the game's memory on several threads at once: a level of 1 MiB or more goes to a small worker pool as bands of rows (par_jobs.c, tex_deswizzle.c tex_bl_copy_mt), and so does a large block copy for the GPU's ASTC decoder, so the upload's storage copy no longer runs on the drawing thread alone. The bytes are those of the one-thread copy; par_jobs = 0 turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 08:35:42 -05:00
parent e7c2fc6a6b
commit fadd4a6d5e
9 changed files with 347 additions and 25 deletions

14
runtime/par_jobs.h Normal file
View File

@@ -0,0 +1,14 @@
// par_jobs.c: a small pool of persistent threads for CPU work the drawing threads would otherwise do alone, such as a
// large texture's copy out of the game's memory (tex_deswizzle.c tex_bl_copy_mt). One job at a time; the caller takes
// part and returns when every piece is done.
#pragma once
#include <stddef.h>
// Runs fn(arg, i) for every i in [0, n) on the pool's threads and the caller's, in no set order, and returns once all
// have returned. A second caller while the pool runs a job, a pool that could not start, NX2NAVI_PAR_JOBS=0 or n 1 run
// every piece on the calling thread instead. fn must not call par_run itself (it would run its pieces alone).
void par_run(int n, void (*fn)(void *arg, int i), void *arg);
// The threads a job can spread over, the caller counted; 1 when the pool is off.
int par_threads(void);
// memcpy with large copies (PAR_MEMCPY_MIN and up) split over the pool.
void par_memcpy(void *dst, const void *src, size_t n);