mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 18:09:58 -04:00
Stop flushing the shader cache files every read checks, so shader preparation translates twice as fast.
Each translation flushed its .spv and .res.json to the disk, wrote its .use mask with a flushed, written-through rename and renamed its outputs written through: about six waits for the drive per shader. An NVMe drive does about 1,100 flushed files a second, a SATA SSD or a hard drive far fewer, so the translators sat mostly idle. Every read already checks these files (spirv_complete, reflection_valid, the .use magic and size) and a torn one is translated again, so they are now written whole but not flushed (plat_file_write_cached, plat_file_replace without durable). The .in files stay flushed: they hold the guest's code and only their header and size are checked. 4,683 shaders of the install's preparation on a Ryzen 7 7700X and a Samsung 990 PRO: translation 36.4 and 37.2 s before, 18.4 and 18.9 s after; every .spv, .res.json, .use and .in file and shader-prepared.bin are the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -755,9 +755,9 @@ static void sync_dir_of(const char *path) {
|
||||
}
|
||||
}
|
||||
|
||||
int plat_file_replace(const char *from, const char *to) {
|
||||
int plat_file_replace(const char *from, const char *to, int durable) {
|
||||
if (rename(from, to)) return 0;
|
||||
sync_dir_of(to);
|
||||
if (durable) sync_dir_of(to);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -804,7 +804,8 @@ void plat_unlock_file(const char *path) {
|
||||
plat_mutex_unlock(&lock_lock);
|
||||
}
|
||||
|
||||
int plat_file_write_atomic(const char *path, const void *data, size_t n) {
|
||||
// path.<pid>.<tid>.tmp renamed over path; durable: the file and then its folder are synced to the disk.
|
||||
static int write_swap(const char *path, const void *data, size_t n, int durable) {
|
||||
// A rename replaces a read-only file here (only the folder's permission counts) but not on Windows: a file the
|
||||
// player made read-only stays as it is on both.
|
||||
if (access(path, W_OK) && errno != ENOENT) return 0;
|
||||
@@ -813,16 +814,20 @@ int plat_file_write_atomic(const char *path, const void *data, size_t n) {
|
||||
if (len < 0 || len >= (int)sizeof tmp) return 0;
|
||||
int fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if (fd < 0) return 0;
|
||||
int ok = write_all(fd, data, n) && fsync(fd) == 0;
|
||||
int ok = write_all(fd, data, n) && (!durable || fsync(fd) == 0);
|
||||
ok = close(fd) == 0 && ok;
|
||||
if (ok && !rename(tmp, path)) {
|
||||
sync_dir_of(path);
|
||||
if (durable) sync_dir_of(path);
|
||||
return 1;
|
||||
}
|
||||
unlink(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plat_file_write_atomic(const char *path, const void *data, size_t n) { return write_swap(path, data, n, 1); }
|
||||
|
||||
int plat_file_write_cached(const char *path, const void *data, size_t n) { return write_swap(path, data, n, 0); }
|
||||
|
||||
int plat_file_flush(const char *path) {
|
||||
int fd = open(path, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0) return 0;
|
||||
|
||||
Reference in New Issue
Block a user