Commit Graph
2726 Commits
Author SHA1 Message Date
Codex 4f24f73070 audio: retain fractional phase in aligned S16 conversion
Correct sub-phase rounding after bounded offline chunks without changing normal playback processing. Check the actual correction kernel against a nine-hour exact sample-clock oracle.
2026-11-16 20:01:26 +01:00
Codex 00904f5d64 audio: expose aligned cold starts for fixed-ratio S16 sinc conversion
Center offline output on source frame zero and report the input lookahead needed for tail draining. Existing processing and reset paths remain unchanged. This supplies latency handling for worker-owned fractional recording conversion.

Check impulses, independent fractional-rate tone phase, chunk invariance and tail drain at 8-192 kHz. GCC/Clang sanitizers, Windows C89 and four NDK ABI builds pass; missing and one-frame compensation mutants are rejected.
2026-11-16 20:01:26 +01:00
LibretroAdmin 5627044718 vfs: a file's volume - read-only, change-time kept, mount, drive kind
retro_vfs_file_volume_impl() tells, for an open stream, what its
volume is; retro_vfs_stat_volume_impl() the same for a path, following
links. The caller says what it wants, as each part costs a query of its
own on some platforms:

- WANT_FLAGS: mounted read-only, and whether the filesystem's kernel
  alone sets change times (so no user can forge one). One fstatfs()
  answers both on Linux (statfs's f_flags, ST_VALID since 2.6.36, with
  a statvfs fallback before that), macOS and the BSDs; statvfs()
  elsewhere on POSIX. Windows reads FILE_READ_ONLY_VOLUME through
  GetVolumeInformationByHandleW, looked up by name once, lock-free.
- WANT_MOUNT (Linux): the mount id, from statx's STATX_MNT_ID through
  syscall(), else /proc/self/fdinfo.
- WANT_KIND (Windows): the drive type of the path's drive letter -
  fixed, removable, remote or RAM.

Purely additive: nothing existing calls it. UWP answers "can't be
told"; the backend parity check agrees on all 44 symbols.
vfs_stable_test checks it against statfs/statvfs and /proc's mnt_id,
two opens of a file against each other and the path lookup, /proc as
another mount, and Windows' drive kind and flags (under wine, 64-bit,
64-bit stdio and 32-bit). The fdinfo fallback was run with statx
refused.
2026-11-16 16:01:16 +01:00
LibretroAdmin 930b13400d vfs: owner, permissions and type in a file's identity; identity by path
struct retro_vfs_file_identity now also carries the owner, group and
POSIX permission bits (where the platform has them, flagged by
RETRO_VFS_IDENTITY_HAS_OWNER) and whether it is a regular file, a
folder or something else.

retro_vfs_stat_identity_impl() gives the same identity for what a path
names, following links, without opening a stream: stat() on POSIX; on
Windows a handle opened only to query attributes, shared with everyone,
so a folder or a file another process holds open answers too. It tells
"nothing there" (1/0) apart from "can't be told" (-1), so callers can
keep a missing file distinct from one they may not look at.

Purely additive: the new fields are filled from the stat/handle query
the identity already made, so no stream gains a syscall. UWP gets a
definition that answers "can't be told"; the backend parity check
agrees on all 42 symbols. vfs_stable_test covers the fields against
stat(), folders, missing paths, links, FIFOs/devices and an
unsearchable folder (as a non-root user).
2026-11-16 15:43:57 +01:00
LibretroAdmin 40f7eed9ab vfs: a stream's size counts its positional writes
retro_vfs_file_write_at_impl() (filestream_write_at()) wrote without
touching the stream's size at all: after a positional write past the
end, or an append, retro_vfs_file_size_impl(), filestream_get_size()
and filestream_eof() still gave the size from before it. On master a
new test finds it on descriptor and stdio streams alike - grown files
reported at their old size, appends at 0, eof true in the middle of
the file.

A positional write that writes now marks the stream's size_grown, an
atomic of its own beside append_end (positional writers run on any
number of threads at once, so the hint bits that a descriptor write
marks are no place for it). It reads the mark first and sets it only
if unset, so writers on many threads don't all store to one line. The
next size query clears the mark and then asks the file, so a write
landing after the clear marks it again and none is missed: a
descriptor's size is the file's; a stdio or native Windows stream's,
which may still hold bytes of its own, the larger of the file's and
what its own writes reached. No lock, no wait.

Built where the size can be asked of the file (VFS_SIZE_LAZY, as for
the descriptor writes); where there is no positional I/O nothing
changes.

samples/file/vfs/vfs_positional_size_test: writes past the end, inside,
after a truncate, appends, and four threads writing interleaved records
at once, on descriptor and stdio streams, through the impl and through
filestream (get_size, tell, eof); it fails on master and passes now -
on Linux with and without mmap, under ASan/UBSan and ThreadSanitizer,
and as 64-bit native and C-runtime and 32-bit Windows builds under
wine - and is added to both samples workflows. vfs_size_contract_test
and the rest of the VFS suite pass as before (under wine, the same
three tests master fails there).

Cost: four threads of 64-byte positional writes on one stream, best of
five passes, four runs - 749/437/555/631 ns per write before,
623/415/672/598 ns after: within the run-to-run noise.
2026-11-16 15:06:47 +01:00
LibretroAdmin 22ba917922 libretro-common: word_wrap_offset(), with a test
menu_wrap_offset(), which finds where a byte of a string landed in its
word_wrap() or word_wrap_wideglyph() wrap, moves to stdstring.c beside
them as word_wrap_offset(), and MaterialUI and XMB call it from there.

It gave a glyph the wide-glyph wrap had put a line end before the
offset of that line end, so the input dialog's caret sat at the end
of the line above; it now gives the glyph's own.

word_wrap_offset_test wraps plain, wide-glyph and mixed text at every
width from 1 to 39, with line ends left or made NUL as the drivers
make them, and checks that every character lands on itself or on the
line end its space or newline became, in order, that the end lands
on the end, that no wrap more than doubles its text, and that the
caret before a word moved to the next line is on that line. It found
the wrong offset and the wide-glyph wrap's runaway at narrow widths.
2026-11-16 11:49:11 +01:00
LibretroAdmin 02bc19b302 vfs: a stable open that hands back the identity it vouched with
retro_vfs_file_open_stable_impl(path, id): the stable open
(RETRO_VFS_FILE_ACCESS_HINT_IMPL_STABLE) that also fills id from the
query the open already makes to vouch for the file. A caller that opens
a file and asks at once which file it is - the core signature check,
on every core load - no longer pays a second query for it:

- POSIX: the open's fstat() (regular file, size) fills the identity
  too, so open + identity is one fstat() where it was two.
- Windows: the identity's own queries (GetFileInformationByHandle and,
  where present, GetFileInformationByHandleEx) stand in for the open's
  GetFileSizeEx, one call fewer.

The identity is the file's as opened; retro_vfs_file_identity_impl()
still queries afresh for anyone asking later. NULL with id zeroed
unless the stream is a stable one: a path the VFS opens by another
scheme is closed and refused, so a caller can't get an identity
without the open's guarantees.

Purely additive. retro_vfs_file_open_impl() is now a one-line wrapper
over the same open with no identity asked for, and does exactly what it
did; the identity code moved ahead of the open so both use it. UWP
defines the call (no stable open there: NULL), and
tools/vfs_backend_parity agrees on 41 symbols.

vfs_stable_test checks the handed-back identity equals the stream's
own answer, and that a directory, a missing file or a NULL id gets
NULL and a zeroed id; it passes on Linux with and without mmap and
under ASan/UBSan, and as 64-bit and 32-bit Windows builds under wine.
The rest of the VFS suite passes as before on Linux and as a 64-bit
Windows build under wine.
2026-11-16 09:17:58 +01:00
LibretroAdmin ab3b8aca06 vfs: a stable open, a stream's identity, and mapping on demand
Three additions to the built-in implementation, for a caller that
checks what it reads (the core signature check, which has kept its own
open/read/identity/map code per platform beside the VFS). Nothing that
exists changes: no existing hint, path or call behaves differently, and
every new branch is behind the new hint or the new calls.

RETRO_VFS_FILE_ACCESS_HINT_IMPL_STABLE, in vfs_implementation.h rather
than the frontend ABI: a read-only open of a local regular file on the
descriptor path, with no stdio buffer. It fails unless the file is
regular, and its size comes from that same answer (one fstat() on
POSIX, which is the probe an open makes anyway); it never waits on a
FIFO, never takes a controlling terminal and is not inherited
(O_NONBLOCK, O_NOCTTY, O_CLOEXEC). On Windows it shares the file for
reading only (_wsopen/_sopen with _SH_DENYWR, _O_NOINHERIT,
_O_SEQUENTIAL), so nothing writes, renames or deletes it while it is
open. Any other mode or scheme drops the hint and opens as before. The
UWP backend refuses it: it can't keep those promises, and a caller must
not think it has them.

retro_vfs_file_identity_impl(): which file a descriptor-path stream is,
read from its handle - volume, file id (Windows' 128-bit id where
GetFileInformationByHandleEx has it, else the inode), size, mtime and
change time, in seconds from 1970. One fstat() on POSIX.

retro_vfs_file_map_impl(): maps a descriptor-path stream whole and
read-only when asked, for a caller that wants to look at the bytes
rather than copy them out; the stream owns the mapping and drops it at
close. Reads, seeks and the position never see it (it is kept apart
from a FREQUENT_ACCESS mapping by its own internal flag), and a second
call returns the same one. NULL where nothing maps, so the caller
reads. The header says when a mapping is safe to read: a file nothing
else can shorten, on a local fixed volume.

UWP defines both calls (no identity, no mapping), so its link still
matches the C backend; tools/vfs_backend_parity agrees on 40 symbols.

samples/file/vfs/vfs_stable_test covers all three, including a FIFO
refused without waiting, a directory refused, Windows refusing writes,
renames and deletes while the file is open and allowing them after,
the mapping leaving the read position alone, identity following the
handle across a rename over its path, and opens without the hint
unchanged. It passes on Linux with and without mmap (and under ASan and
UBSan), and as 64-bit (native and C-runtime streams) and 32-bit
Windows builds under wine; it is added to both samples workflows. The
rest of the VFS suite passes as before (vfs_seek_contract_test's 4 GiB
case fails in a 32-bit build under wine on master too).

vfs_native_bench, master against this, three interleaved runs on
Linux: every row within run-to-run noise (open + 4 KiB read + close
2204/2207/2307 ns against 2246/2279/2190 ns; 1 MiB sequential reads
60.6/83.6/62.0 us against 63.5/62.2/59.1 us).
2026-11-16 09:04:43 +01:00
LibretroAdmin 5066d334bb libretro-common/rpng: declare rpng_alloc once
rpng.h declared rpng_alloc twice, which -Wredundant-decls warns about in
every C++ file that includes it with that warning on (parallel-ps3's).
2026-11-15 23:49:12 +01:00
LibretroAdmin 22be806976 libretro-common/crypto: add aes_ctr128_crypt
AES-CTR with the counter incremented as one 128-bit big-endian number,
SP 800-38A's standard incrementing function (OpenSSL's CRYPTO_ctr128,
mbedtls's aes_crypt_ctr). aes_ctr_crypt carries only the low 32 bits, as
GCM needs; formats whose initial counter is a random 128-bit value (the
PS3's SELF files, for the RPCS3 core) need the carry into the rest.

It runs aes_ctr_crypt's AES-NI and ARMv8 multi-block paths in runs that
stop where the low 32 bits wrap, and carries into octets 0..11 by hand,
so the fast paths are untouched.

test_crypto checks it against the SP 800-38A F.5.1 vector, then against
a block-at-a-time reference from counters about to wrap their low word,
their low 96 bits and the whole block, in one call and in pieces.
2026-11-15 11:30:42 +01:00
Codex 82423cb5eb json: avoid revalidating borrowed response fields
Add bounded navigation for immutable spans already accepted by rjson. Carry validation provenance through private achievements fields and iterators so nested objects and array entries do not repeat full syntax and Unicode validation. Raw responses and unvalidated fields retain the strict reader.

Skip populated field prefixes during selection and decode quoted strings directly through the shared string reader. Keep the buffered parser unchanged and test nested spans, malformed raw fields, duplicates and HTTP-buffer lifetimes.
2026-11-15 04:35:16 +01:00
Codex 753e517f4f rhash: use shared AES and hash primitives
Use libretro-common AES in all builds and retain the expanded key across CBC and CTR calls. Keep an AES-only build for targets without the full crypto feature. Preserve full-width CTR carry and remove the duplicate cipher implementation.

Share digest formatting and endian operations. Handle incomplete swap tails without overrunning the buffer. Validate frozen cipher vectors, unaligned primitives and disc/ZIP identification.
2026-11-15 04:27:32 +01:00
Codex 0c6182025e json: share borrowed spans with the achievements response readers
Add opt-in source spans, root-member visits and direct string decoding.
Compile the shared grammar for buffered and borrowed input so the existing
buffered token loop has no borrowed-mode checks or extra state. Span scans
validate strings and numbers without materializing their token text.

Use these helpers in bundled rcheevos, removing its duplicate recursive
parser and Unicode/string decoder. Keep response-owned strings in the
existing arena and retain API-specific field/default/error handling.
Responses now follow rjson's stricter syntax, Unicode and nesting rules.

Cover read-only input, truncations, nested counts, escapes, escaped field
names, duplicate fields and response lifetime in the existing test targets.
2026-11-15 03:39:43 +01:00
LibretroAdmin 6ba45f7acb retro_atomic: one half of the 128-bit word alone
retro_atomic_load_acquire_128_lo(p) and retro_atomic_load_acquire_128_hi(p)
read one 64-bit half of a retro_atomic_128_t with acquire ordering: the
half as it is, not paired with the other half of the same value.

They are for one field of a pair that changes together: the owner of a
lock whose word also holds its queue, a pointer whose generation is not
needed to look at it. The whole value is a compare-and-swap on every
backend but GCC and Clang on x86-64, so the cache line is written by a
load; a half is a plain aligned eight-byte load everywhere, which both
processors do in one access:

- GCC and Clang (x86-64, AArch64): __atomic_load_n with
  __ATOMIC_ACQUIRE on the volatile word;
- MSVC x86-64: a volatile load and a compiler barrier (x86-64 orders
  loads);
- MSVC ARM64: __iso_volatile_load64 and __dmb(_ARM64_BARRIER_ISH).

No cast on the GCC and Clang paths, C89 throughout.

retro_atomic_test reads each half after the single-thread operations,
and its four 128-bit readers read both halves alone beside the whole
value under the counting and swapping threads: the low half never goes
back, the high one (its complement) never forward. With the low half
reading the high word the test fails both ways. Passes on x86-64 and,
under qemu, AArch64; the MSVC paths are not compiled here.
2026-11-14 22:22:28 +01:00
LibretroAdmin a6ea5fe940 retro_atomic: a 128-bit word where the processor has one
Two 64-bit words loaded, stored, exchanged and compare-and-swapped as
one: retro_atomic_128_t, with retro_u128_t as its value, on x86-64
(CMPXCHG16B) and little-endian AArch64 (LDAXP/STLXP) with GCC, Clang
or MSVC. RETRO_ATOMIC_HAS_128 is set there and nowhere else.

For libretro cores that emulate a machine with 128-bit atomics of its
own, or keep a pointer with its generation in one word (parallel-ps3's
memory reservations and shared pointers), which until now had to bring
their own.

- retro_atomic_cas_128 takes the expected value as the other widths
  do; retro_atomic_cas_seen_128 also reports what was there on
  failure, so a retry loop does not load again. On AArch64 a mismatch
  is written back before it is reported: a pair read by LDAXP is only
  known to be whole once a store to it has succeeded.
- x86-64 with GCC or Clang loads and stores with one aligned MOVDQA,
  written in assembly so the compiler cannot split it. MSVC and
  AArch64 load by swapping the value for itself.
- The new code has no C-style cast on the GCC and Clang paths, so a
  C++ unit built with -Wold-style-cast can include it.

retro_atomic_test: the operations on one thread, then four threads
counting with compare-and-swap loops, one storing and exchanging, four
exchanging against each other and four reading a pair whose halves are
each other's complement. Run with GCC and Clang, as C89 and gnu99,
under ThreadSanitizer and AddressSanitizer, and as AArch64 under
qemu-user. A load or a store done as two 8-byte accesses and an
exchange done as a load and a store each fail it.

The MSVC path (_InterlockedCompareExchange128) is not compiled or run
here.
2026-11-14 07:28:20 +01:00
LibretroAdmin 7786f59ac4 libretro-common: retro_waitaddr, parking on words and waking by address
retro_eventcount parks on an object both sides hold. Code written
around a futex, WaitOnAddress or C++20's atomic wait parks on bare
addresses instead: a thread sleeps while the 32-bit words at up to
eight addresses still hold the values it saw, and whoever changes one
wakes it by naming that address.

retro_waitaddr_wait, retro_waitaddr_notify_one and
retro_waitaddr_notify_all do that over retro_eventcount and
retro_atomic, with no lock of their own. A waiter is a record out of a
pool that only grows, published in the bucket of each address it names;
a notifier claims the records that name its address with a
compare-and-swap on the record's state and generation and wakes them
through each record's own eventcount. notify_one wakes one thread that
was waiting when it was called.

A notify with nobody waiting in the address's bucket is one
read-modify-write: 13 ns for a store and a notify here, no syscall.

The sample covers the bound, several addresses, notify_one against
notify_all, and tokens handed to sleeping takers by notify_one alone,
where a lost wake hangs the test - which found one while this was
written (a claim that landed before the waiter had prepared its
eventcount). Run over the futex and the condition-variable backends and
under ThreadSanitizer and ASan/UBSan. Not run on Windows.
2026-11-13 06:35:52 +01:00
libretroadmin 71f2adcaeb libretro-common/xxh3: hash short known lengths in place
xxh3.h carries the 0-to-128-octet path with the default secret as
constants; under GCC and Clang, xxh3_64() with a length the compiler
knows to be at most 128 expands to it, so a call site such as a
64-octet CLUT hash compiles to the four multiplies and the avalanche,
with no call and no length tests. Every other length still calls the
function, which keeps its runtime path choice.

xxhash_test checks each such length, 0 to 128 and just past it, with
and without a seed, against the function. It no longer lists the
scalar long path on NEON builds, which have none, so it builds and
passes on AArch64; the cross-arch job now runs it under qemu-user on
AArch64 (NEON) and ARMv7 (scalar), which no other job builds.
2026-11-13 06:01:10 +01:00
LibretroAdmin 6e7ad2318b rslc: invariant on a declared variable, and a double scalar
RSLC_EXTENDED, SPIR-V only. Both are what the parallel-ps3 vertex
programs carry on a GPU whose driver is NVIDIA's and that has 64-bit
floats: every vertex program a game has was refused there, which
stopped the emulator. The core's test built its programs as a software
driver gets them and never made either.

- invariant gl_Position; (and any output or built-in named after its
  declaration) makes the variable invariant: the Invariant decoration,
  on the gl_PerVertex member for a built-in.
- double: a 64-bit scalar. It is converted to and from the other
  numbers (implicitly from int, uint and float), calculated with,
  negated and compared; abs, sign, floor, ceil, trunc, round, fract,
  sqrt, min, max, clamp and mix take it. A literal converted to double
  keeps the value it was written with (0.000001 is the double, not the
  float widened), as glslang's does. A double is never folded: no
  vectors, block members or constant expressions of it. Float64 is
  declared.

rslc_ext_test has the vertex stage's depth function word for word; it
checks the member's decoration, the 64-bit type, the conversions and
the literal's bits, and the module validates.
2026-11-13 03:56:50 +01:00
LibretroAdmin 07bea38175 rslc: the builder can ask an array's length
rslc_b_length makes what length() makes when parsed: the declared
length of a sized array, and for the unsized last member of a storage
block OpArrayLength of the block (SPIR-V only). A stage that loops to
the end of a buffer could not be built by calls without it.

rslc_ext_build_test builds a compute stage that sums a storage block's
unsized array up to its length, and gets the words the same stage
parsed from GLSL compiles to.
2026-11-13 03:21:28 +01:00
LibretroAdmin 855002e6d6 data_transfer: a window feed never reads in a gap the consumer has passed
A feed whose frontier was further behind the consumer than its margin
filled everything from the frontier to the consumer in one extend. A
consumer far into a large file - its media past a large leading
section, or a small step back there that the feed takes for a lap and
rewinds to the head - made most of the file resident: the preview of
a 7.8 GB MP4 with its media at the end committed 6 GB and was killed.
The frontier now moves up to the margin behind the consumer before the
extend, which reads only from there; the bytes it skips are behind the
consumer and outside its margin, never read.

data_transfer_window_test starts a consumer 1 MiB from the end of a
256 MiB source, moves it on and steps it back, and checks that each
feed reads and keeps resident no more than the margin and lookahead
around it; without the change the first feed reads all 256 MiB.
2026-11-13 03:12:48 +01:00
LibretroAdmin 9f3c78217f rtga: rtga_decode_rows, rows where the caller wants them
As rjpeg_decode_rows: one call writes each row, BGRA or RGBA in byte
order, into memory the caller names per row, or into rtga's own row,
which is kept for the next image. The decode loops write through the
row being filled, so rtga_process_image's surface is one more place
rows go. rtga_test checks the rows against rtga_process_image over
every type, depth and origin, raw and RLE, files cut short and both
byte orders.
2026-11-13 03:06:17 +01:00
LibretroAdmin 75869ea349 rslc: one multisampled image, as a sampler and as a storage image
RSLC_EXTENDED, SPIR-V only. What the parallel-ps3 Vulkan renderer's
multisample resolve tasks and passes use; with it rslc compiles all 79
of that renderer's fixed shaders, to modules with glslang's interface
and layouts.

- sampler2DMS, isampler2DMS, usampler2DMS: texelFetch with the sample,
  textureSize without a level. (sampler2DMSArray was there; the plain
  one was not.)
- image2DMS, iimage2DMS, uimage2DMS: imageLoad and imageStore take the
  sample, which goes out as the Sample image operand;
  StorageImageMultisample is declared.
- Image formats rg32f, rg16f, r16f, r11f_g11f_b10f, rgba16, rgb10_a2,
  rg16, r16 and rgba8_snorm. StorageImageExtendedFormats is declared
  for every format outside the base set, not only r8 and rg8.
- An image that is only written may leave its format out; the module
  declares StorageImageWriteWithoutFormat. One that is read still needs
  it.

rslc_ext_test has the resolve, the unresolve and the fragment fetches;
the modules validate.
2026-11-13 01:33:55 +01:00
LibretroAdmin d7f44c5e94 rslc: a step through a swizzle, a member's offset, the stencil reference
From the parallel-ps3 Vulkan renderer's deswizzle tasks, overlay pass
and depth-stencil resolve, which did not compile.

All builds:
- v.xy-- and ++v.zx. A step went through one pointer to its operand,
  and several components of a vector have none: the statement was
  refused ("cannot emit statement"). It is read as a value, stepped and
  written back the way an assignment to the same place is.

RSLC_EXTENDED, SPIR-V only (a printed destination refuses the stage):
- layout(offset = n) on a block's member places it there, and the
  members after it follow: a fragment stage's part of a push block that
  starts where the vertex stage's ends. The qualifier was parsed and
  dropped, so the members sat at 0.
- gl_FragStencilRefARB (GL_ARB_shader_stencil_export): the built-in,
  StencilExportEXT with its extension, and StencilRefReplacingEXT on
  the entry point, as glslang emits it.

rslc_ext_test has a stage for each. What the stepped swizzle computes
is not run by it; the module validates.
2026-11-13 01:29:13 +01:00
LibretroAdmin 6879826551 rslc: what an emulator's generated stages say, and a macro that names itself
Found compiling every shader source the parallel-ps3 Vulkan renderer's
interpreter and compute tasks make (29 stages, 639 KB of GLSL), none of
which compiled before and all of which do now, with the interface and
block layouts glslang gives them.

All builds:
- A macro's own name inside its expansion stays painted. It was left
  alone while the macro was being expanded but became a macro again
  when those tokens were scanned a second time - an argument prescanned
  and then rescanned in the body it was substituted into - so
  "#define offset params().offset" used inside another macro's argument
  expanded twice and read a member that does not exist.

RSLC_EXTENDED:
- #version 420, 430 and 440 are taken as the dialect 450 is.
- gl_WorkGroupSize: the constant the local size layout made.
- A uniform block that says std430 is laid out std430, the first block
  too (it was std140 whatever it said: a float[3] after three scalars
  went to offset 80, glslang puts it at 76).
- A uniform block's last member may be an array of unstated length
  (GL_EXT_uniform_buffer_unsized_array). SPIR-V only: the printed
  destinations refuse it.

rslc_ext_test has a stage for each, and 410 still refused.
2026-11-13 01:12:21 +01:00
libretroadmin 155c1d8f59 retro_posix_source.h: ask old glibc for BSD and SVID names too
glibc before 2.19 ignores _DEFAULT_SOURCE, and the _POSIX_C_SOURCE set
here turns off its implicit _BSD_SOURCE, so strcasecmp(), M_PI,
syscall(), MAP_ANONYMOUS and SA_ONSTACK go undeclared. webOS ships
glibc 2.12, where a core's net_http.c no longer compiled. _BSD_SOURCE
and _SVID_SOURCE are what such a glibc enables by default; newer ones
accept them silently beside _DEFAULT_SOURCE.

The webOS job compiles every file including the header with the SDK's
compiler and no feature macros of its own.
2026-11-13 00:32:01 +01:00
LibretroAdmin a26d6b552b retro_deque: push_front_growing
push_back_growing's counterpart, for a queue with no limit of its own
that takes its newest at the front (a most-recently-used list): when
the queue holds its limit it first reserves twice as much, and only
that push allocates.

The sample pushes 100 at the front of a queue made for 4: in order,
five allocations.
2026-11-13 00:00:19 +01:00
LibretroAdmin c4174413a1 vfs: stdio streams keep their position, so a write does not ask for it
A buffered write asked stdio where the stream stood, to keep its size,
on every call. The stream keeps that position itself: set by a seek
from the start, moved by a relative seek and by what each read and
write moves, and unknown after a seek from the end, a failed seek, a
read error or a short write, when the next write or tell asks stdio
once. Tell answers from it too.

vfs_write_mix_test checks the position and the size after every kind
of operation, and fails 2030 checks with reads not moving it.
2026-11-12 23:59:19 +01:00
LibretroAdmin c7a5f6edb8 vfs: Windows write streams on a handle of their own; stdio streams settle before truncate, punch and flush
On Windows NT, streams opened to write, read and write, or update are
opened on a handle of their own like read-only ones, created or opened
as the C runtime would and shared the same way. The 64 KiB buffer holds
either what was read or one run of writes not yet in the file: writes
that carry on from the run join it, anything else writes the run out in
one WriteFile at its offset, and a write as large as the buffer goes
straight to the file. Reads, truncates, holes, flushes and closes write
the run out first, and a seek from the end counts it.
VFS_WIN32_NO_NATIVE keeps the C runtime.

On a stdio stream, truncating and punching a hole first write out what
stdio holds and afterwards seek back to the stream's position, so
writes made before them are cut or zeroed with the rest and nothing
read ahead outlives them. Flushing a stream that reads as well as
writes does the same, since msvcrt's fflush drops the read-ahead
without seeking back.

vfs_write_mix_test drives writes, seeks, reads, truncates, holes,
flushes, reads at offsets and reopening in every write mode against a
copy of the file, and runs in the Linux samples job and both Windows
lanes. The VFS samples build Linux with _GNU_SOURCE as RetroArch does,
so hole punching runs there. vfs_bulk_read_test checks where a plain
write stream opens, vfs_close_test counts a native write stream's
close as the descriptor close it is, and vfs_native_bench times writes.
2026-11-12 23:37:09 +01:00
LibretroAdmin 434b5525b6 retro_deque: a queue with no limit of its own, and no old-style casts in C++
Two things for the code that moves to it from std::deque and
std::queue.

push_back_growing: where the old code relied on a queue with no limit,
a push into a queue that holds its limit first reserves twice as much.
Only that push allocates; a queue given at init the most it is expected
to hold never does. Nothing is dropped that was not dropped before.

The header's casts are C++'s when it is included from C++
(RETRO_DEQUE_CAST), so a C++ unit built with -Wold-style-cast, or with
it as an error, includes the header as it is, without turning the
warning off around each use.

The sample grows a queue from 4 to 128 in order, and counts the
allocations: five, at the doublings.
2026-11-12 22:49:05 +01:00
LibretroAdmin 6bda23daad retro_deque: a pointer type as the element
RETRO_DEQUE_DEFINE(threads, struct thread*) did not compile in C++ and
meant the wrong thing in C: the functions take "const type *value", and
with a pointer type written out that is a pointer to a pointer to const,
not a pointer to a const element.

The macro names the element's type once (name_value_t) and uses that
name, so const is the element's whatever the type is spelled as.

The sample has a queue of pointers, pushed from a pointer and from a
const pointer.
2026-11-12 22:42:47 +01:00
LibretroAdmin 8714cee2fe libretro-common: retro_deque, a double-ended queue of one type in one block
What std::deque is used for - push and pop at either end, the n-th
element, insert and erase in the middle, in order - without what it
costs. std::deque keeps its elements in blocks of a few dozen and takes
a block from the heap, or gives one back, each time its contents cross a
block's end: a queue pushed at one end and popped at the other does that
for ever, however few elements it holds. libretro-common's generic_queue
allocates a node for every push.

retro_deque is a ring in one block, a power of two long, set aside when
the queue is made for as many elements as the caller says it holds.
Pushing, popping, inserting and erasing never allocate; a push into a
queue at its limit is refused with one compare; reserve is the one call
besides init that allocates. Insert and erase move whichever side of the
place is shorter.

The functions are made for the element's type by a macro
(RETRO_DEQUE_DEFINE(name, type)), so an element is copied as what it is
and not through memcpy with a size known only at run time. C89, header
only; MSVC compiles it.

Against std::deque built with the same flags (g++ -O3), on the two uses
it replaces first, the PS3 core's event queues and its scheduler's
deadlines:

  an event sent and taken   4.2 ns   std::deque 5.7 ns, and an
                                     allocation every 16 events
  scheduler step, 4 asleep  8.4 ns   11.9 ns
                  16       14.1 ns   21.3 ns
                  64       40.0 ns   60.8 ns

  send     21 instructions, no call   41 and a call
  take     22, no call                41 and a call
  insert   92, no call               338 and 13 calls
  expire   21, no call                46 and a call

The sample runs two million pushes, pops, inserts and erases against a
model, a struct element, the limit, reserve, and a queue marched along
for a million elements in its one block; built as C89, pedantic. In the
libretro-common samples workflow; passes under ASan and UBSan.
2026-11-12 22:38:18 +01:00
LibretroAdmin fd17192acb formats: no file I/O - image_texture's path loaders go through streams/
formats/image_texture.c loaded images by path through the data_transfer
file adapter. Its four path loaders (image_texture_load, _load_ex,
_load_request, _load_request_ex) move to streams/image_texture_file.c,
declared in streams/image_texture_file.h, the same split data_transfer,
cdfs and the DVD reader got. The names and behaviour are unchanged;
callers include the new header.

formats/image_texture.c keeps the buffer decoders and makes
image_texture_load_buffer_probe public so the adapter can reach it.
image_texture_load_set stays in formats/image_texture_set.c: it does no
file I/O of its own, and gfx_surface_still tests it against a stubbed
load_request.

griffin, Makefile.common, the companion test scripts and the sample
Makefiles that build the loaders add streams/image_texture_file.c; the
overlay task sample, which stubs image loading, does not.
2026-11-12 22:27:29 +01:00
LibretroAdmin d5eedad5ff vfs: Windows reads at offsets take the synchronous handle when it is free
A call through filestream_read_at or filestream_write_at takes the
stream's synchronous second handle - Windows' cached-read fast path for
a lone caller - when no other call holds it, one CAS on a flag; a call
that finds it held takes the overlapped handle, whose calls Windows
runs side by side. A native stream's own handle serves as the
synchronous one.
2026-11-12 20:14:31 +01:00
LibretroAdmin 92e1e205ce rflac: rflac_seek_point gives the seek point's frame; FLAC seeks land
rflac_seek gives the byte a seek point is at, but not the frame it is
at, which rflac_seek_resumed needs. audio_transfer told it 0, so the
decoder took the point for the start of the stream and the remainder
was decoded on from the point as if from frame 0: a seek in a FLAC
buffer with a seek table landed as many frames past its target as the
point was from the start.

rflac_seek_point gives both (rflac_seek is it, without the frame), and
audio_transfer resumes at the point's own frame. The audio_transfer_flac
sample gains a fixture with a seek table (made with flac and metaflac;
ffmpeg writes none) and a lane of seeks between and onto its points,
forward and back, which failed before.
2026-11-12 20:06:20 +01:00
LibretroAdmin b42806c02c vfs: Windows reads and writes at offsets on an overlapped handle
The second handle filestream_read_at and filestream_write_at go through
is opened for overlapped I/O - the relative NtCreateFile without
FILE_SYNCHRONOUS_IO_*, the path reopen with FILE_FLAG_OVERLAPPED - so
Windows no longer runs its calls one at a time and threads reading at
offsets read side by side. Each call waits on an event of its own:
one of eight a stream keeps, claimed by a bit with one CAS and made at
first use, or a passing one beyond eight; a call that completes at
once never waits. Native read-only streams take this handle too
instead of sharing their own, and synchronous, one.

vfs_positional_wide_test runs the positional test from twelve threads,
past the eight events; the cross-libc Windows job runs it.
2026-11-12 20:01:26 +01:00
LibretroAdmin 9ce7ef2311 vfs: read-only Windows streams on their own handle by default
Read-only streams on Windows NT take their own handle, position and
buffer over the C runtime's FILE by default; VFS_WIN32_NO_NATIVE keeps
the C runtime. Measured with vfs_native_bench on Windows: 1-byte
sequential reads 16.0 -> 6.8 ns, 16-byte 16.6 -> 7.5 ns, 256-byte 40.0
-> 30.4 ns; 4 KiB and up, random reads, reads at offsets, threads and
small-file opens the same within run-to-run spread.

The cross-libc Windows job's second VFS pass is now the C runtime one
(make VFS_NATIVE=0); vfs_native_bench_native is the default build and
vfs_native_bench the C runtime one.
2026-11-12 19:46:42 +01:00
LibretroAdmin cf816b8940 vfs: read-only Windows streams on a handle of their own (VFS_WIN32_NATIVE, opt-in)
Built with VFS_WIN32_NATIVE, a read-only stream on Windows NT opens with
CreateFileW instead of a C runtime FILE: it keeps its own position and
a 64 KiB buffer, reads at that position with ReadFile, and serves
filestream_read_at from the same handle, with no second one. Writable,
mapped, descriptor and scheme streams, and 9x, are as before, and so is
every build without the define.

vfs_native_bench and vfs_native_bench_native time the two on the same
reads - sequential at six sizes, random by seek and by read_at, read_at
from four threads, small-file opens - for deciding the default on
Windows. The cross-libc Windows job runs the VFS stream, path, large
file, read-ahead and positional tests built with it too.
2026-11-12 19:22:20 +01:00
LibretroAdmin 68b07f6a1a formats: no file I/O - data_transfer, cdfs and the DVD file reader go through streams/
data_transfer reads only through its reader callback. The path entry
points keep their names, data_transfer_open_prefix and
data_transfer_open_window, in streams/data_transfer_file.c
(<streams/data_transfer_file.h>), which opens the file through
filestream, reads it at offsets and closes it with the transfer;
data_transfer_open_prefix_reader and data_transfer_set_release are the
core's side of that.

cdfs reads only through the stream a track holds. cdfs_open_track,
cdfs_open_data_track and cdfs_open_raw_track are in
streams/cdfs_file.c (<streams/cdfs_file.h>); the length-based sector
probe they use is cdfs_track_sector_size_from_length.

rdvd_vfs, which binds files to the DVD source, and rdvd_stream, which
drives it, are streams/rdvd_vfs.c and streams/rdvd_stream.c, their
headers under <streams/>.

cdfs_file_test covers the path openers: a cooked iso and a raw bin
sized by length, a cue sheet resolving its bin beside it, an INDEX 01
offset, the data track, refusals.
2026-11-12 19:22:20 +01:00
LibretroAdmin 4206fe8f52 streams, zip, vfs: reads at offsets through intfstream and the zip reader; Windows second handle from ntdll
intfstream_read_at reads at an offset and leaves the stream's position
where it was: files and memory streams without touching the stream, so
from several threads at once, CHD tracks by seeking there and back. The
buffered stream reads from the file and keeps its window, and its own
refills and wide reads go to the file at the offset. memstream_read_at
backs memory streams. The CUE/ISO serial detectors read their probes
this way.

The zip reader takes its end records, directory, local headers and
member chunks with one read at the offset each, where the file has
them; the reads the stream lends from stay as they are.

The Windows second handle is opened relative to the stream's own with
an empty name through ntdll's NtCreateFile on every NT. From Vista on
that is what ReOpenFile does; before it the handle is kept only when
its volume and file index match the stream's, else the path reopen
follows.

Lanes: intfstream_read_at_test (file, buffered, memory; four threads),
vfs_positional_ntverify_test (the check, on any version); archive_zip64
counts reads at offsets as reads through the stream.
2026-11-12 18:40:38 +01:00
Codex 92656bf572 net: retain independent wake references for late notifications
Duplicate both pipe ends so an asynchronous completion can outlive its canceled owner without SIGPIPE or waking a replacement job after descriptor reuse. Cover allocation, dup and descriptor setup rollback as well as owner retirement.
2026-11-12 15:33:19 +01:00
Codex 9ce6ee410f net: add a nonblocking pollable producer wake
Provide a POSIX close-on-exec wake pipe so an I/O worker can poll producer notifications together with sockets. Keep queue epochs with the caller; notifying and acknowledging never wait. Exercise real descriptor flags, saturation, combined socket readiness, EINTR and partial-startup rollback, with explicit unsupported admission on other platforms.
2026-11-12 15:13:39 +01:00
LibretroAdmin 48b9aef3f4 retro_cas_record: read, work on a copy, put it back only if it changed
retro_cas_record_read_versioned copies the record out and says which
record that was; retro_cas_record_replace puts a value in its place if
it still is that one. For a caller whose reads mostly change nothing:
such a read is two loads and a copy and writes nothing shared, where
begin and abort take a slot and give it back (two atomic writes) for
the same outcome. A caller that did change its copy puts it back with
one compare-and-swap, without doing its work a second time.

begin and commit stay for changes made in place.

retro_cas_record_test: half the twenty threads now change the record
this way, the other half in place, on the same record. With replace
made to ignore the version the total falls short by a third.
2026-11-12 09:10:44 +01:00
LibretroAdmin 8d85478046 libretro-common: retro_cas_record, a record several threads change with no lock
retro_seqlock is for one writer. This is for the case a mutex is
usually taken for: read-change-write of a small record from several
threads. Nobody writes the record in place: a change is made on a copy
in a spare slot and swapped in with one compare-and-swap; a thread
that lost the race makes its change again on the newer record. Readers
copy the record out and never wait. One of the racing threads always
gets through, so a thread that is preempted or stopped mid-change
holds nobody up.

Header only, C89, the storage the caller's (16 slots). Where there is
no lock-free compare-and-swap RETRO_CAS_RECORD_LOCK_FREE is not
defined and the caller keeps its own serialisation.

retro_cas_record_test: twenty threads (more than there are spare
slots) make 100000 changes each to one record while three threads copy
it. No change lost, each thread's count exact, no copy torn or going
back, aborts leave no trace, every spare slot given back. With the
compare-and-swap replaced by a plain store the total comes out at a
fraction. Runs in the libretro-common samples workflow; passes under
ASan and UBSan.
2026-11-12 08:39:46 +01:00
LibretroAdmin c5cd9ae6f8 vfs: the Windows positional handle only where pointer atomics exist
34fd7248 keeps the second handle Windows positional I/O reads through
in a retro_atomic_ptr_t, declared and set up wherever _WIN32 is. The
volatile atomic backend has no pointer type or operations, and
vfs_close_result_test builds vfs_implementation.c as a PS2 TU forced
onto it (-DPS2 -DRETRO_ATOMIC_FORCE_VOLATILE) with a Windows compiler,
MSYS2's in the Windows VFS samples job, MinGW's under Wine: neither
built.

vfs.h has VFS_HAVE_AT_HANDLE where _WIN32 meets a backend with pointer
atomics; the field, its initialisation and VFS_POSITIONAL_WIN32 follow
it. Without it read_at and write_at return -1 and the caller seeks and
reads as before, as on the platforms with neither pread nor ReOpenFile.
Every real Windows build has pointer atomics and is unchanged.

The MinGW builds of vfs_close_result_test, vfs_positional_test,
vfs_readahead_test and vfs_prefetch_offthread_test build without
warnings and pass under Wine - the positional test through the
Windows second handle - and the Linux VFS samples pass under ASan and
UBSan.
2026-11-12 08:31:22 +01:00
LibretroAdmin 34fd7248c0 libretro: VFS v6 - reads and writes at an offset, with no lock
read_at and write_at take the offset with the call and leave the
stream's own position alone, so any number of threads can use one
handle at once and a core no longer needs a lock of its own around
seek-then-read. write_at with RETRO_VFS_WRITE_AT_APPEND reserves its
place at the end with one atomic add, so appends from several threads
neither overlap nor tear.

pread/pwrite where the platform has them, a second handle with its
own position (ReOpenFile, OVERLAPPED) on Windows, a memcpy for a
mapped stream. -1 where there is neither (consoles, UWP, the other
schemes); the caller then does what it did before.

filestream_read_at / filestream_write_at reach it from libretro-common.

vfs_positional_test: four threads read at offsets on one handle while
a fifth reads it in sequence, for buffered, descriptor and mapped
streams, then four threads append records. With the positional read
swapped for seek-then-read it reports tens of thousands of wrong reads.
Runs in the libretro-common samples workflow; also built with MinGW
and run under wine.
2026-11-12 08:15:00 +01:00
LibretroAdmin ae907bff65 libretro: OpenGL contexts for a core's own threads
RETRO_ENVIRONMENT_GET_HW_SHARED_CONTEXT_INTERFACE (104, experimental)
gives an OpenGL or OpenGL ES hardware core contexts in its own
context's share group, for threads of its own: create and destroy on
the core's thread, make_current on the thread that uses one. A core
can then render or compile shaders off its main thread with nothing of
the window system in the core. A frontend that cannot make such
contexts answers false, and the core keeps its GL work on the thread
that calls retro_run.

RetroArch answers it with the context drivers' shared contexts, which
GLX, Wayland and X11 EGL already had for OpenXR; WGL, KMS/DRM and
Android get them here. The WGL one shares with the context current on
the calling thread (the core's), made with the window context's
attributes, and binds on the window's device context.

samples/gfx/gl_shared_context is a core whose second thread clears a
texture through such a context that retro_run then shows; the EGL
hardware core workflow runs it on GLX and EGL, threaded and not, with
a compatibility and a 3.3 core context.
2026-11-12 04:32:16 +01:00
LibretroAdmin fd7e99a94c net_http, task_http: a chunked download goes to the file where it was received
The chunked decoder slid every payload byte down over the chunk
headers before it, so the decoded body was one run for the sink: one
copy of the whole body inside the receive buffer, on top of the
receive itself.

A sink can now take the body as runs (net_http_connection_set_sink_spans).
For such a sink, a chunk of 16 KB or more stays where it was received
and is recorded as a run; shorter chunks are still slid down onto the
end of the run before them, so the runs stay few and long.  At most
16 runs are held, in the handle, so nothing is allocated mid-transfer;
with all 16 in use, further chunks are slid as before until the hand-
off.  The hand-off point is unchanged: when the free window behind
the held bytes would fall below 32 KB, and at the end of the body or
when it is cut short.

task_http's download sink takes runs and writes them with
filestream_writev: one writev() on the targets that have it, so the
chunks reach the file from where they were received.  An identity
body goes as one run, as before.  net_http_connection_set_sink and
its sinks are unchanged.
2026-11-12 03:47:46 +01:00
LibretroAdmin 2440f44bb3 libretro-common: filestream_writev, a gathered write
filestream_writev writes several pieces of memory to a stream, in
order, as filestream_write would one after another.  A stream opened
with RETRO_VFS_FILE_ACCESS_HINT_SEQUENTIAL_BULK, which writes to its
descriptor, hands them to the kernel in one writev() call on Linux,
Android, Apple and the BSDs, so pieces scattered through a buffer
reach the file without being copied together first.  Elsewhere -
Windows, the consoles, buffered streams, smb:// and nfs://, and a
core's own VFS - the pieces are written one by one.

retro_vfs_file_writev_impl backs it in both VFS backends; the UWP one
writes the pieces one by one.  struct retro_vfs_span (vfs/vfs.h) is
the piece.
2026-11-12 03:47:43 +01:00
LibretroAdmin 2cc624e8dc retro_atomic: C++ casts in the C++11 backend
The C++11 backend cast values with C casts, in its macros and its
compare-and-swap functions. A project built with
-Werror=old-style-cast, RPCS3 for one, could not include the header.
The casts are now static_cast, and the compare-and-swap functions
turn the bool into 1 or 0 with ?:.

The C++11 sample is built with -Werror=old-style-cast; on the old
header it stops with 19 errors. It also tries cas_ptr, fetch_add_64
and cas_64 now, and the stand-in old <atomic> declares the member
fetch operations the 64-bit macros use.
2026-11-11 23:42:30 +01:00
LibretroAdmin 5ab2152e6a The checks today's commits left behind: cloud sync reads, centre point picks, gapless WMA, the H.264 border
66376b18 sends cloud sync reads to disk through
task_push_http_download_file_with_headers(), which the webdav_options,
webdav_backup, webdav_reauth, s3_backup and gdrive_backup samples
include webdav.c, s3.c or google_drive.c without: none of them linked.
Each stubs it as the GET it is, recorded as their transfer stubs record
one. webdav_reauth's stale-nonce read wrote nothing to the file the
callback now opens, and read the stale copy there; it writes the body
first, as the download would.

ab6a34d3 has the point scaler take the sample nearest each output
pixel's centre, and video_frame_convert_to_bgr24()'s fused downscale
path (screenshots, translation) still started half a sample short, so
video_frame_failure_test found it apart from the scaler it checks
against. It starts from the centre too. Its 2x2 to 1x1 case now
expects the bottom right sample, the one nearest the centre.

a2cd6efc plays WMA1 and WMA2 gapless: a stream's first frame is the
encoder's priming and its second half plays on the drain.
wma_player_test's fixture is one frame, so what plays is that frame's
second half, as audio_transfer_wma_test was told in the same commit.

The H.264 encoder's border copies its first and last rows outwards,
rows that are never the same; the overlap check allows them.

The five cloud sync samples pass, video_frame_failure_test and its
translation check, pixconv_test, scaler_point_test and
image_scale_transfer_test pass, check-wma passes, and the overlap copy
check is clean.
2026-11-11 21:23:52 +01:00