mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 20:09:57 -04:00
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:
@@ -45,7 +45,7 @@ static const char *const known[] = {
|
||||
"COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT",
|
||||
"DMABUF", "DMABUF_MB", "DRAW_CRUMBS", "GPA_LATE", "DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_KEEP", "DLAA_CUT", "DLSS_IDLE_FREE", "DLAA_EDGE_FILL", "DLAA_AT_UPSCALER", "FFX_DEBUG", "FFX_KEYS", "FSR3_SHARPEN", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TARGET_KEEP", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_PREBLOOM", "DLSS_RANGE", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR",
|
||||
"DUMP_LOG", "DUMP_RAW", "DUMP_SHADERS", "DUMP_FILE", "DS3", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "DUMP_MOVIE", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CRASH_FILTER_GUARD", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "GPU_TIMELINE",
|
||||
"FFX_PIPE_CACHE", "FLIGHT_SPIKE_MS", "STUTTER_MAP", "FLIGHT_THUMBS", "FLIGHT_EVERY", "FLIGHT_FLASH", "FLIGHT_FLASH_DIFF", "FLIGHT_FLASH_CELLS", "FLUSH_SPAN", "FLUSH_UPLOAD", "FOG_CULL", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FG_MULT", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FRAMEGEN_MULTIPLIER", "FREEZE_IDLE", "FREEZE_ASYNC", "FREEZE_BUDGET_US", "FREE_CORES",
|
||||
"FFX_PIPE_CACHE", "FLIGHT_SPIKE_MS", "STUTTER_MAP", "PAR_JOBS", "FLIGHT_THUMBS", "FLIGHT_EVERY", "FLIGHT_FLASH", "FLIGHT_FLASH_DIFF", "FLIGHT_FLASH_CELLS", "FLUSH_SPAN", "FLUSH_UPLOAD", "FOG_CULL", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FG_MULT", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FRAMEGEN_MULTIPLIER", "FREEZE_IDLE", "FREEZE_ASYNC", "FREEZE_BUDGET_US", "FREE_CORES",
|
||||
"FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPA_TWIN_MAX_KB", "MIRROR_CAPTURE_KB", "WB_SKIP_MB", "GPL", "GPL_DRAW_BUILD", "GPL_FEEDBACK", "GPL_MESH", "PIPE_AHEAD", "PIPE_FAST_WORKERS", "PIPE_FRAME_WAIT_MS", "PIPE_LINK_DRAW_MS", "PIPE_SKIP_STEADY", "DRAW_WRITERS_WAIT", "PROG_LEAD", "GPU", "GPU_INDEX", "GPU_PASSES", "GPU_NAME", "HDR",
|
||||
"HDR_GAME_NITS", "HDR_LIVE", "HEAP_LAZY", "HDR_PEAK_NITS", "HDR_UI_NITS",
|
||||
// retired: the HDR look's settings of earlier versions, now fixed (vk_hdr.c, shaders/hdr_tonemap.frag); read by
|
||||
@@ -158,7 +158,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"SPLIT_IDLE", "performance"}, {"SPLIT_IN_PASS", "performance"}, {"SPLIT_US", "performance"}, {"VK_VALIDATION", "performance"},
|
||||
{"VK_DYN_VERTEX", "performance"}, {"VK_DYN_A2C", "performance"}, {"VK_SUBGROUP_PIN", "performance"}, {"VK_RECONVERGE", "performance"},
|
||||
{"VK_NAN_PRESERVE", "performance"}, {"VK_NAN_BITS", "performance"},
|
||||
{"DRAW_CRUMBS", "diagnostics"}, {"TRACE", "diagnostics"}, {"FLIGHT", "diagnostics"}, {"PASS_CRUMBS", "diagnostics"}, {"FLIGHT_SPIKE_MS", "diagnostics"}, {"STUTTER_MAP", "diagnostics"},
|
||||
{"DRAW_CRUMBS", "diagnostics"}, {"TRACE", "diagnostics"}, {"FLIGHT", "diagnostics"}, {"PASS_CRUMBS", "diagnostics"}, {"FLIGHT_SPIKE_MS", "diagnostics"}, {"STUTTER_MAP", "diagnostics"}, {"PAR_JOBS", "performance"},
|
||||
{"FLIGHT_FLASH", "diagnostics"}, {"FLIGHT_FLASH_DIFF", "diagnostics"}, {"FLIGHT_FLASH_CELLS", "diagnostics"},
|
||||
{"WB_FENCE_LIMIT", "diagnostics"}, {"WB_MERGE", "diagnostics"}, {"WB_EXACT", "diagnostics"}, {"MEM_CENSUS", "diagnostics"}, {"WB_NO_REUP", "diagnostics"}, {"WB_PROBE", "diagnostics"}, {"WB_SPLIT", "performance"}, {"SHADOW_BULK_WRITE", "performance"}, {"WB_LAZY", "performance"}, {"HEAP_LAZY", "performance"}, {"BARRIER_GAME", "performance"}, {"MESH_AHEAD", "performance"}, {"MESH_FALLBACK", "performance"}, {"MESH_FALLBACK_MB", "performance"}, {"MESH_FALLBACK_WORKERS", "performance"}, {"WB_LAZY_TOUCH", "diagnostics"}, {"WB_LAZY_CHUNK", "performance"}, {"FLUSH_UPLOAD", "diagnostics"}, {"GPA_TWIN_MAX_KB", "diagnostics"}, {"MIRROR_CAPTURE_KB", "diagnostics"}, {"WB_SKIP_MB", "diagnostics"},
|
||||
{"WB_MERGE_MAX", "diagnostics"}, {"MV_SURVEY", "diagnostics"}, {"TEXUP_LOG_MS", "diagnostics"},
|
||||
@@ -402,6 +402,8 @@ static const CfgMeta metas[] = {
|
||||
{"TRACE", "", NULL, RESTART}, {"FLIGHT", "0", "0|1", RESTART}, {"FLIGHT_SPIKE_MS", "100", "0..60000", RESTART},
|
||||
// stutter_map.c: hitches by area and cause, and the pipelines and shaders draws met missing (0 off, 1 on)
|
||||
{"STUTTER_MAP", "0", "0|1", RESTART},
|
||||
// par_jobs.c: the worker pool that splits a large texture's copy out of the game's memory (0: the thread that makes it alone)
|
||||
{"PAR_JOBS", "1", "0|1", RESTART},
|
||||
// flight.c "The flash trigger": on or off, and flight_flash.h flash_test's two thresholds
|
||||
{"FLIGHT_FLASH", "1", "0|1", RESTART}, {"FLIGHT_FLASH_DIFF", "24", "4..255", RESTART}, {"FLIGHT_FLASH_CELLS", "3", "1..144", RESTART},
|
||||
{"WB_FENCE_LIMIT", "65536", "0..1073741824", RESTART}, {"WB_MERGE", "1", "0|1", RESTART}, {"WB_EXACT", "1", "0|1", RESTART}, {"MEM_CENSUS", "0", "0|1", RESTART}, {"WB_NO_REUP", "1", "0|1", RESTART}, {"WB_PROBE", "0", "0|1", RESTART}, {"WB_SPLIT", "1", "0|1|2|3", RESTART}, {"WB_LAZY", WB_LAZY_DEFAULT, "0|1", RESTART}, {"HEAP_LAZY", "0", "0|1", RESTART}, {"WB_LAZY_TOUCH", "0", "0..16", RESTART}, {"WB_LAZY_CHUNK", "0", "0|1", RESTART}, {"FLUSH_UPLOAD", "0", "0|1", RESTART}, {"GPA_TWIN_MAX_KB", "0", "0..1048576", RESTART},
|
||||
|
||||
117
runtime/par_jobs.c
Normal file
117
runtime/par_jobs.c
Normal file
@@ -0,0 +1,117 @@
|
||||
// A pool of persistent threads that runs one job at a time (par_jobs.h). The threads sleep on a condition variable
|
||||
// between jobs and cost nothing while the game does not use them. A job is n pieces claimed one by one from an atomic
|
||||
// counter by the caller and the workers alike, so a slow piece or a busy core evens out. One caller at a time: the
|
||||
// pool's busy lock is only tried, never waited for, so a second caller (or a piece that calls par_run) runs alone
|
||||
// rather than waiting, and no caller can wait for a pool that waits for it.
|
||||
//
|
||||
// Size: the usable hardware threads less two (the drawing thread and the game's main thread), at most PAR_MAX_THREADS
|
||||
// in all, the caller counted. NX2NAVI_PAR_JOBS=0 runs every job on its caller (cfg.c).
|
||||
#include <string.h>
|
||||
|
||||
#include "cfg.h"
|
||||
#include "host.h"
|
||||
#include "par_jobs.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
#define PAR_MAX_THREADS 8
|
||||
#define PAR_MEMCPY_MIN (1u << 20) // below this, waking the pool costs about what the copy does
|
||||
#define PAR_MEMCPY_PIECE (256u << 10)
|
||||
|
||||
static struct {
|
||||
PlatOnce once;
|
||||
PlatMutex busy; // held by the caller for its whole job
|
||||
PlatMutex lock;
|
||||
PlatCond work, done;
|
||||
int threads; // workers, the caller not counted
|
||||
int off;
|
||||
uint64_t gen; // bumped per job; a worker takes part in each job once
|
||||
int active; // workers that have not finished the current job
|
||||
void (*fn)(void *arg, int i); // the current job (written under lock before gen is bumped)
|
||||
void *arg;
|
||||
int n;
|
||||
volatile int32_t next; // the first piece not yet claimed
|
||||
} J = {PLAT_ONCE_INIT, .lock = PLAT_MUTEX_INIT, .work = PLAT_COND_INIT, .done = PLAT_COND_INIT};
|
||||
|
||||
static void claim(void) {
|
||||
for (;;) {
|
||||
int i = __atomic_fetch_add(&J.next, 1, __ATOMIC_RELAXED);
|
||||
if (i >= J.n) return;
|
||||
J.fn(J.arg, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void worker(void *arg) {
|
||||
(void)arg;
|
||||
uint64_t seen = 0;
|
||||
plat_mutex_lock(&J.lock);
|
||||
for (;;) {
|
||||
while (J.gen == seen) plat_cond_wait(&J.work, &J.lock);
|
||||
seen = J.gen;
|
||||
plat_mutex_unlock(&J.lock);
|
||||
claim();
|
||||
plat_mutex_lock(&J.lock);
|
||||
if (!--J.active) plat_cond_broadcast(&J.done);
|
||||
}
|
||||
}
|
||||
|
||||
static void pool_init(void *param) {
|
||||
(void)param;
|
||||
if (!cfg_bool("NX2NAVI_PAR_JOBS")) {
|
||||
J.off = 1;
|
||||
rt_log("par_jobs: off (NX2NAVI_PAR_JOBS=0): large texture copies run on the thread that makes them");
|
||||
return;
|
||||
}
|
||||
int cpus = (int)plat_cpu_usable() - 2;
|
||||
int n = (cpus < 1 ? 1 : cpus > PAR_MAX_THREADS ? PAR_MAX_THREADS : cpus) - 1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (!plat_thread_spawn(worker, NULL, "par jobs", 0)) break;
|
||||
J.threads++;
|
||||
}
|
||||
rt_log("par_jobs: %d workers for large texture copies (and the thread that asks)", J.threads);
|
||||
}
|
||||
|
||||
int par_threads(void) {
|
||||
plat_once(&J.once, pool_init, NULL);
|
||||
return J.off ? 1 : J.threads + 1;
|
||||
}
|
||||
|
||||
void par_run(int n, void (*fn)(void *arg, int i), void *arg) {
|
||||
if (n <= 0) return;
|
||||
if (n == 1 || par_threads() < 2 || !plat_mutex_trylock(&J.busy)) {
|
||||
for (int i = 0; i < n; i++) fn(arg, i);
|
||||
return;
|
||||
}
|
||||
plat_mutex_lock(&J.lock);
|
||||
J.fn = fn, J.arg = arg, J.n = n;
|
||||
__atomic_store_n(&J.next, 0, __ATOMIC_RELAXED);
|
||||
J.active = J.threads;
|
||||
J.gen++;
|
||||
plat_cond_broadcast(&J.work);
|
||||
plat_mutex_unlock(&J.lock);
|
||||
claim();
|
||||
plat_mutex_lock(&J.lock);
|
||||
while (J.active) plat_cond_wait(&J.done, &J.lock);
|
||||
plat_mutex_unlock(&J.lock);
|
||||
plat_mutex_unlock(&J.busy);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t n, piece;
|
||||
} Copy;
|
||||
|
||||
static void copy_piece(void *arg, int i) {
|
||||
const Copy *c = arg;
|
||||
size_t at = (size_t)i * c->piece, len = c->n - at < c->piece ? c->n - at : c->piece;
|
||||
memcpy(c->dst + at, c->src + at, len);
|
||||
}
|
||||
|
||||
void par_memcpy(void *dst, const void *src, size_t n) {
|
||||
if (n < PAR_MEMCPY_MIN || par_threads() < 2) {
|
||||
memcpy(dst, src, n);
|
||||
return;
|
||||
}
|
||||
Copy c = {dst, src, n, PAR_MEMCPY_PIECE};
|
||||
par_run((int)((n + c.piece - 1) / c.piece), copy_piece, &c);
|
||||
}
|
||||
14
runtime/par_jobs.h
Normal file
14
runtime/par_jobs.h
Normal 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);
|
||||
@@ -17,6 +17,10 @@ int nvn_deswizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const vo
|
||||
size_t dst_pitch);
|
||||
int nvn_swizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src_linear, size_t src_pitch,
|
||||
void *dst_storage);
|
||||
// nvn_deswizzle with a large level's block-linear copy split over the par_jobs pool (tex_bl_copy_mt): the same bytes.
|
||||
// For the texture upload, which runs on a drawing thread; the caller keeps the storage mapped until it returns.
|
||||
int nvn_deswizzle_mt(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src_storage, void *dst_linear,
|
||||
size_t dst_pitch);
|
||||
// One box of a level and layer, [x, x + wb) bytes by [y, y + h) block rows of slice z (3D textures), between the storage
|
||||
// and caller rows of pitch bytes, touching nothing else of the level: ReadTexels / WriteTexels of a region cost the
|
||||
// region, not the level. Same textures as nvn_deswizzle; -1 for others and for a box outside the level.
|
||||
@@ -30,6 +34,9 @@ int nvn_deswizzle_geom(const nvn_texdesc *d, unsigned level, unsigned layer, uin
|
||||
// The copy loop on its own, for callers that know the level geometry (bl points at the level's first byte).
|
||||
void tex_bl_copy(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint32_t slices,
|
||||
unsigned th, unsigned td, int to_linear);
|
||||
// tex_bl_copy with a level of 1 MiB or more split into bands of rows over the par_jobs pool; the same bytes.
|
||||
void tex_bl_copy_mt(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint32_t slices,
|
||||
unsigned th, unsigned td, int to_linear);
|
||||
|
||||
// ---- tex_astc.c ----
|
||||
// ASTC LDR 2D to RGBA8, bit-exact with astcenc's 8-bit decode. blocks: row-major 16-byte blocks covering
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// ASTC 4x4 title logo and BC4 masks decode without seams (an edge-continuity search over all 120 orders of the five
|
||||
// address bits picks it for both; OCARINA-BRINGUP.md round 18). Block and level arithmetic are unchanged.
|
||||
#include "host.h"
|
||||
#include "par_jobs.h"
|
||||
#include "tex.h"
|
||||
#include <string.h>
|
||||
|
||||
@@ -62,29 +63,71 @@ int nvn_deswizzle_geom(const nvn_texdesc *d, unsigned level, unsigned layer,
|
||||
|
||||
// nvn_bl_offset per row instead of per 16 bytes: within a row, GOB column k starts k blocks further, and the four
|
||||
// 16-byte segments of a GOB row (x % 64 = 0, 16, 32, 48) sit at 0, 32, 256 and 288 of it (Switch 2: 0, 64, 256, 320).
|
||||
void tex_bl_copy(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint32_t slices,
|
||||
unsigned th, unsigned td, int to_linear) {
|
||||
// Rows [r0, r1) of the slices one after the other (row z * rows + y): each row finds its own place in the block-linear
|
||||
// storage, so any range of rows copies on its own, and tex_bl_copy_mt hands ranges to several threads.
|
||||
static void bl_copy_rows(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint64_t r0,
|
||||
uint64_t r1, unsigned th, unsigned td, int to_linear) {
|
||||
static const uint32_t seg_x1[4] = {0, 32, 256, 288}, seg_nvn2[4] = {0, 64, 256, 320};
|
||||
const uint32_t *seg = gob_nvn2() ? seg_nvn2 : seg_x1;
|
||||
uint64_t block = 512ull << th << td;
|
||||
for (uint32_t z = 0; z < slices; z++)
|
||||
for (uint32_t y = 0; y < rows; y++) {
|
||||
uint8_t *row = lin + ((size_t)z * rows + y) * pitch, *g = bl + nvn_bl_offset(0, y, z, row_bytes, rows, th, td);
|
||||
uint32_t x = 0;
|
||||
if (to_linear)
|
||||
for (; x + 64 <= row_bytes; x += 64, g += block)
|
||||
for (int s = 0; s < 4; s++) memcpy(row + x + 16 * s, g + seg[s], 16);
|
||||
else
|
||||
for (; x + 64 <= row_bytes; x += 64, g += block)
|
||||
for (int s = 0; s < 4; s++) memcpy(g + seg[s], row + x + 16 * s, 16);
|
||||
for (int s = 0; x < row_bytes; s++, x += 16) { // a partial GOB at the row's end
|
||||
uint32_t n = row_bytes - x < 16 ? row_bytes - x : 16;
|
||||
if (to_linear) memcpy(row + x, g + seg[s], n); else memcpy(g + seg[s], row + x, n);
|
||||
}
|
||||
for (uint64_t r = r0; r < r1; r++) {
|
||||
uint32_t z = (uint32_t)(r / rows), y = (uint32_t)(r % rows);
|
||||
uint8_t *row = lin + (size_t)r * pitch, *g = bl + nvn_bl_offset(0, y, z, row_bytes, rows, th, td);
|
||||
uint32_t x = 0;
|
||||
if (to_linear)
|
||||
for (; x + 64 <= row_bytes; x += 64, g += block)
|
||||
for (int s = 0; s < 4; s++) memcpy(row + x + 16 * s, g + seg[s], 16);
|
||||
else
|
||||
for (; x + 64 <= row_bytes; x += 64, g += block)
|
||||
for (int s = 0; s < 4; s++) memcpy(g + seg[s], row + x + 16 * s, 16);
|
||||
for (int s = 0; x < row_bytes; s++, x += 16) { // a partial GOB at the row's end
|
||||
uint32_t n = row_bytes - x < 16 ? row_bytes - x : 16;
|
||||
if (to_linear) memcpy(row + x, g + seg[s], n); else memcpy(g + seg[s], row + x, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int move(const nvn_texdesc *d, unsigned level, unsigned layer, uint8_t *bl, uint8_t *lin, size_t pitch, int to_linear) {
|
||||
void tex_bl_copy(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint32_t slices,
|
||||
unsigned th, unsigned td, int to_linear) {
|
||||
bl_copy_rows(bl, lin, pitch, row_bytes, rows, 0, (uint64_t)rows * slices, th, td, to_linear);
|
||||
}
|
||||
|
||||
// tex_bl_copy over the par_jobs pool: a level of BL_MT_MIN bytes or more (smaller ones gained nothing: 0.5 MiB took
|
||||
// 0.01 ms either way, 2 MiB went 3.3 times faster, 16 MiB 2.5 times) goes as bands of rows, about BL_MT_BAND
|
||||
// bytes each, so a large texture's copy out of the game's memory (the upload's storage copy, 75% of its CPU time in an
|
||||
// area's streaming) does not run on the drawing thread alone. The bytes written are those of tex_bl_copy.
|
||||
#define BL_MT_MIN (1u << 20)
|
||||
#define BL_MT_BAND (128u << 10)
|
||||
typedef struct {
|
||||
uint8_t *bl, *lin;
|
||||
size_t pitch;
|
||||
uint32_t row_bytes, rows;
|
||||
uint64_t all, band;
|
||||
unsigned th, td;
|
||||
int to_linear;
|
||||
} BlJob;
|
||||
|
||||
static void bl_band(void *arg, int i) {
|
||||
const BlJob *j = arg;
|
||||
uint64_t r0 = (uint64_t)i * j->band, r1 = r0 + j->band < j->all ? r0 + j->band : j->all;
|
||||
bl_copy_rows(j->bl, j->lin, j->pitch, j->row_bytes, j->rows, r0, r1, j->th, j->td, j->to_linear);
|
||||
}
|
||||
|
||||
void tex_bl_copy_mt(uint8_t *bl, uint8_t *lin, size_t pitch, uint32_t row_bytes, uint32_t rows, uint32_t slices,
|
||||
unsigned th, unsigned td, int to_linear) {
|
||||
uint64_t all = (uint64_t)rows * slices, bytes = all * row_bytes;
|
||||
if (bytes < BL_MT_MIN || !row_bytes || par_threads() < 2) {
|
||||
tex_bl_copy(bl, lin, pitch, row_bytes, rows, slices, th, td, to_linear);
|
||||
return;
|
||||
}
|
||||
uint64_t band = BL_MT_BAND / row_bytes;
|
||||
if (band < 1) band = 1;
|
||||
BlJob j = {bl, lin, pitch, row_bytes, rows, all, band, th, td, to_linear};
|
||||
par_run((int)((all + band - 1) / band), bl_band, &j);
|
||||
}
|
||||
|
||||
static int move(const nvn_texdesc *d, unsigned level, unsigned layer, uint8_t *bl, uint8_t *lin, size_t pitch, int to_linear,
|
||||
int mt) {
|
||||
if (nvn_tex_is_linear(d)) {
|
||||
if (level || layer || d->samples > 1 || (d->target != 0 && d->target != 1 && d->target != 7)) return -1;
|
||||
int bw, bh, bpb = nvn_fmt_bpb(d->format, &bw, &bh);
|
||||
@@ -101,7 +144,7 @@ static int move(const nvn_texdesc *d, unsigned level, unsigned layer, uint8_t *b
|
||||
uint32_t row_bytes, rows, slices, bpb; uint64_t base; unsigned th, td;
|
||||
if (nvn_deswizzle_geom(d, level, layer, &row_bytes, &rows, &slices, &base, &th, &td, &bpb)) return -1;
|
||||
if (pitch < row_bytes) return -1;
|
||||
tex_bl_copy(bl + base, lin, pitch, row_bytes, rows, slices, th, td, to_linear);
|
||||
(mt ? tex_bl_copy_mt : tex_bl_copy)(bl + base, lin, pitch, row_bytes, rows, slices, th, td, to_linear);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -138,8 +181,11 @@ int nvn_texels_box(const nvn_texdesc *d, unsigned level, unsigned layer, uint32_
|
||||
}
|
||||
|
||||
int nvn_deswizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src, void *dst, size_t dst_pitch) {
|
||||
return move(d, level, layer, (uint8_t *)src, (uint8_t *)dst, dst_pitch, 1);
|
||||
return move(d, level, layer, (uint8_t *)src, (uint8_t *)dst, dst_pitch, 1, 0);
|
||||
}
|
||||
int nvn_deswizzle_mt(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src, void *dst, size_t dst_pitch) {
|
||||
return move(d, level, layer, (uint8_t *)src, (uint8_t *)dst, dst_pitch, 1, 1);
|
||||
}
|
||||
int nvn_swizzle(const nvn_texdesc *d, unsigned level, unsigned layer, const void *src, size_t src_pitch, void *dst) {
|
||||
return move(d, level, layer, (uint8_t *)dst, (uint8_t *)src, src_pitch, 0);
|
||||
return move(d, level, layer, (uint8_t *)dst, (uint8_t *)src, src_pitch, 0, 0);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "nvn_api.h"
|
||||
#include "nvn_hmap.h"
|
||||
#include "nvn_tex.h"
|
||||
#include "par_jobs.h"
|
||||
#include "tex.h"
|
||||
#include "vk.h"
|
||||
#include "vk_dlaa.h"
|
||||
@@ -3754,14 +3755,14 @@ static void upload(Tex *e) {
|
||||
}
|
||||
if (gdsw && !sk) {
|
||||
if (held && check) opq = astc_copy_opaque(e, stg, t->mem, size, &bc1_dec);
|
||||
else if (held) memcpy(stg, t->mem, size);
|
||||
else if (held) par_memcpy(stg, t->mem, size); // large blocks over the par_jobs pool
|
||||
else memset(stg, 0, size);
|
||||
} else if (gdsw) {
|
||||
VkDeviceSize at = 0;
|
||||
for (k = 0; k < n; k++) { // astc_bl_regions checked that each lies inside the storage
|
||||
VkDeviceSize nb = vk_astc_region_bytes(&ar[k], (uint32_t)bw, (uint32_t)bh);
|
||||
if (held && check) opq &= astc_copy_opaque(e, stg + at, t->mem + ar[k].src, nb, &bc1_dec);
|
||||
else if (held) memcpy(stg + at, t->mem + ar[k].src, nb);
|
||||
else if (held) par_memcpy(stg + at, t->mem + ar[k].src, nb);
|
||||
else memset(stg + at, 0, nb);
|
||||
ar[k].src = at, at += nb;
|
||||
}
|
||||
@@ -3776,7 +3777,7 @@ static void upload(Tex *e) {
|
||||
tmps[k - k0] = tmp;
|
||||
if (!held) {
|
||||
memset(tmp ? tmp : dst, 0, raw);
|
||||
} else if (nvn_deswizzle(d, lv + sk, ly, t->mem, tmp ? tmp : dst, rb)) {
|
||||
} else if (nvn_deswizzle_mt(d, lv + sk, ly, t->mem, tmp ? tmp : dst, rb)) { // large levels: par_jobs.c
|
||||
log_limited(&n_bad, "texture %#llx fmt %#x target %d: level %u layer %u has no CPU layout; uploaded as zeros",
|
||||
(unsigned long long)e->pub.addr, d->format, d->target, lv + sk, ly);
|
||||
memset(tmp ? tmp : dst, 0, raw);
|
||||
|
||||
Reference in New Issue
Block a user