Brings in RetroArch's "rchd: allocate nothing per hunk once an image
is open" and "rchd: say how long lent bytes have to live". CHD reads
no longer allocate once the image is open: the staging buffer is
reused, the CD FLAC decoder is kept and rewound, and the hunk cache,
CD sector scratch and FLAC rewind point are allocated at open. A
malloc counter over every sector of CD LZMA, CD FLAC and mixed images
went from 299 allocations during reads to 0.
Bring every libretro-common file the core builds up to RetroArch
61606d92b8b026106b51f75365bea592a6fb94b9. 34 files had drifted, including rchd (now accepts
version 5 hunks up to 1 MiB, the largest chdman writes) and
chd_stream, which now reads through vfs_prefetch.
New files the synced sources need: vfs/vfs_prefetch.c and
encodings/encoding_xxh64.c (with their headers), built with HAVE_CHD.
Dropped what nothing builds or includes any more:
streams/file_stream_transforms.c and its header (the core never calls
rfopen/rfread and friends) and the libchdr headers (the core always
reads CHDs with rchd).
tools/chd/run.sh: drop memmap/memmap.c, which the repo does not carry
(the script could not build), and add the new sources plus
retro_eventcount.c that vfs_prefetch needs with threads.
Nothing in the core calls into memmap.c: file_stream maps files through
vfs_implementation, which takes mmap() from the system headers. The
synced copy carries memshm_create, which needs shm_open/shm_unlink from
librt on glibc older than 2.34, so linking it with --no-undefined fails
on the xenial build lanes.
The threaded DSP takes no mutex or condition variable. The emulation
thread publishes a monotonic tick count with a release store and wakes
the DSP thread through a retro_eventcount once per 32 ticks and at
frame end; the DSP thread runs every posted tick and writes samples
into a retro_spsc ring that upload hands to the frontend in place.
Mode switches keep samples in order, and the thread runs out every
posted tick before it exits. THREADED_DSP defines HAVE_THREADS and
builds the eventcount and SPSC sources.
libretro-common is synced with RetroArch master and holds only the
sources the core builds and the headers they and the core include;
rstrtod.c is built since file_stream needs it.
The CHD build selects rchd's zstd codec alongside DEFLATE, LZMA and
FLAC and compiles encoding_rzstd.c, so images compressed with cdzs or
zstd read like any other. rchd, chd_stream, encoding_rzstd,
encoding_deflate and compat/intrinsics.h are resynced from RetroArch.
tools/chd/run.sh compresses a synthetic two-track image with each CD
codec chdman offers and checks every sector against the CUE it came
from, raw and cooked, under ASan and UBSan.
- Refresh the vendored libretro-common tree to the pinned upstream snapshot.
- Replace CHD stream integration with VFS-backed RCHD decoding and per-track logical maps.
- Build the RCHD and RFLAC codec closure and remove obsolete libchdr and LZMA dependency trees.
- Negotiate frontend VFS v3 for file, path, and directory access with legacy fallback.
- Preserve mixed-track gaps, raw-sector offsets, and native CD-DA sample order.
It doesn't appear there are any libretro standard libraries to manage
CDROM images. While such a thing would be useful in the long run for
this change I've imported the pce fast deps used by libchdr and
libretro-common's chd_stream.