Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dm/gfx/nvn/nvn_mtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -3965,7 +3965,7 @@
cpu_unc_take(t);
}
static uint64_t n[2]; if (n[unc]++ < 4) MLOG("texture written by the CPU before its first use ser=%llu %ux%ux%u format %#x%s pool flags %#x: uploaded from its storage, re-uploaded when it changes (%llu so far)",
(unsigned long long)t->serial, t->d.width, t->d.height, t->d.depth, t->d.format, unc ? " (uncompressed, in storage the GPU has not written)" : "", t->pool->flags, (unsigned long long)n[unc]);

Check failure on line 3968 in dm/gfx/nvn/nvn_mtl.m

View workflow job for this annotation

GitHub Actions / clang-tidy (ratchet)

Access to field 'flags' results in a dereference of a null pointer (loaded from field 'pool') [clang-analyzer-core.NullDereference] (10 in this file, the baseline has 9)
return 1;
}
// nvn_ft_poll (hle_nvn.c, tex_dirty_upload): the CPU wrote the pages of a registered texture after its first use. It is taken from its storage by the rule tex_cpu_content uses at first
Expand Down Expand Up @@ -7846,7 +7846,7 @@
const char *e = getenv("DM_PSO_ARCHIVE"); NSString *user = pso_user_path();
g_arch_dir = e && !strcmp(e, "off") ? nil : e && *e ? @(e) : user ? [user.stringByDeletingLastPathComponent stringByAppendingPathComponent:@"pso_archive"] : nil;
NSMutableArray<id<MTL4Archive>> *arch = [NSMutableArray array], *archp = [NSMutableArray array];
pso_bundle_open(archp); // first: it holds every pair's base
arch_open_begin(); pso_bundle_open(archp); arch_open_end(); // first: it holds every pair's base. Mapped, like the device's archives below: on an external drive Foundation would read the whole file (GBs) into memory
if (g_arch_dir) {
g_arch_q = dispatch_queue_create("dm.nvn.pso-archive", dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0));
g_arch_pending = dispatch_group_create();
Expand Down
1 change: 1 addition & 0 deletions docs/reference/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ The guest address space, heaps, pools, virtual address memory and the allocators
- **Symptom:** `footprint` shows `Malloc Large` about the size of `pso_archive/` (the log's `pipeline archive …: N files, … MB`), resident or swapped for the whole run. `MallocStackLogging=1` with `malloc_history <pid> -allBySize` gives `newArchiveWithURL` → `MTL4ArchiveImpl::loadFromURL` → `LoaderGlobalState::loadFile` → `-[NSData initWithContentsOfFile:options:maxLength:error:]` → malloc.
- **Cause:** where the file is. Metal loads each archive through `NSData` with `NSDataReadingMappedIfSafe`, and Foundation counts a file on an external APFS drive on USB (`Removable Media: Fixed`) as unsafe to map: it reads the whole file into allocated memory. On the internal disk it maps the file. `newArchiveWithURL:error:` takes only a URL.
- **Fix:** `arch_open_begin` in `nvn_mtl.m`, for every game: while the host opens its archives, it replaces that `NSData` method's implementation, and a read of a `.mtl4a` asks for `NSDataReadingMappedAlways`. It is a private method, so a system without it reads the files as before. A workaround of the framework's choice, as no public call offers one. The game already runs from that drive, so a drive pulled out ends the run either way. Mapped files are clean pages the system can drop, and they do not count in the footprint.
- **The bundled archive too:** `pso_bundle_open` (the app's `Resources/pso/<gpu>.mtl4a`) ran before that window opened, so an app on an external drive still had its whole bundled archive in memory. It opens inside the window now. Ocarina of Time, app on an external SSD, same save and scene: footprint 19.0 → 12.2 GB, `Malloc Large` 5,032 → 135 MB (one 4.8 GB `NSData`), frame rate unchanged.
- **Check:** a 133 MB archive on the external drive: footprint +129 MB without it, +2 MB with it. Ocarina of Time on its walk with a 3.5 GB archive: footprint 15.0 → 11.8 GB, peak 16.7 → 12.8 GB, `Malloc Large` 3.5 GB → 59 MB, opening 4.6 → 3.0 s. Long frames did not change.
- **Found on:** [Kirby Star Allies](../../dm/games/01007E3006DDA000/README.md): the same stage route gave a footprint of 5,109 MB with its 1.13 GB archive on the external drive and 4,013 MB on the internal disk. [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game). iOS was not measured; its files are on the internal disk.

Expand Down
Loading