docs(libSceAudioOut): count the blocking values passed to sceAudioOut2ContextPush #12698

Merged
xXPBSXx merged 2 commits from upstream-pr/12698 into main 2026-10-30 11:20:59 +00:00
xXPBSXx commented 2026-10-29 02:55:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-29T02:55:16Z.


What

Adds one sentence to the technical debt entry for sceAudioOut2ContextAdvance and sceAudioOut2ContextPush: in the 39 local titles that call sceAudioOut2ContextPush, its 66 direct call sites pass blocking as 0 at 19 sites and as 1 at 43 sites; at 4 sites the value is not constant (one is computed from a comparison, one is set differently on two paths that reach the call). So both values occur. Jump stubs to the function (11) are not counted.

The entry then reads (the new part is its last sentence):

  • sceAudioOut2ContextAdvance and sceAudioOut2ContextPush (libSceAudioOut) - with an SDL device, Advance snapshots each port's PCM and gain; Push consumes completed grains in order and a blocking Push waits for Advance when none is ready. Inferred from PPSA26358, which rewrites the same 512-frame, 12-channel float buffer on a producer thread and pushes on another thread. In 39 local titles, 66 direct Push calls pass blocking 0 (19), 1 (43), not constant (4). Console buffer ownership, snapshot timing and empty-queue errors are unverified. Completed grains remain queued until Push consumes them, so memory use grows with an unconsumed PCM backlog. The console backlog limit is unverified. A nonblocking Push without a completed grain throws; this is a runtime restriction, not a console measurement. Context destruction concurrent with active calls remains unsupported. Without an SDL device the existing wall-clock path remains.

Changed: docs/dev/debt/libSceAudioOut.md, one existing entry extended by one sentence. No code change.

Method: for each of the 53 local titles the import table of the title's executable was read, and the direct call instructions to the imported function were counted in that executable (static counting only, nothing run on a console); the value of the blocking argument was read from the instructions just before each call and checked by a second, independent count. Per-title results and the counting script are attached to this PR. They contain counts, addresses and classifications only, no game code. Calls through the GOT (call [rip+got]) would not be read; every registry call site of the import in these executables is a stub jmp [rip+got], so there are none.

Overlap

Three open PRs change docs/dev/debt/libSceAudioOut.md, none of them this entry: #12425 changes single lines at 36 and 135, #11762 adds three lines after line 11, and #5021 adds two lines after line 28. git merge-tree of this branch against the heads of #12425 and #11762 is clean. #5021 does not merge cleanly into main on its own either, with or without this change. Measured on the file sets of all 1393 open PRs (git diff --name-only from the merge base to each PR head, all refs fetched). Duplicates checked through the pull request API over all pull requests: no open or merged PR counts the blocking values of sceAudioOut2ContextPush.

Tested

Documentation only. tools/check_conventions.py --base upstream/main passes; based on current main 3a2b919816. Not built, not run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5061291648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12698). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-29T02:55:16Z. --- ### What Adds one sentence to the technical debt entry for `sceAudioOut2ContextAdvance` and `sceAudioOut2ContextPush`: in the 39 local titles that call `sceAudioOut2ContextPush`, its 66 direct call sites pass `blocking` as 0 at 19 sites and as 1 at 43 sites; at 4 sites the value is not constant (one is computed from a comparison, one is set differently on two paths that reach the call). So both values occur. Jump stubs to the function (11) are not counted. The entry then reads (the new part is its last sentence): > - [sceAudioOut2ContextAdvance and sceAudioOut2ContextPush](../../../core/libs/prx/libSceAudioOut/src/AudioOut2Context.cpp) (libSceAudioOut) - with an SDL device, Advance snapshots each port's PCM and gain; Push consumes completed grains in order and a blocking Push waits for Advance when none is ready. Inferred from PPSA26358, which rewrites the same 512-frame, 12-channel float buffer on a producer thread and pushes on another thread. In 39 local titles, 66 direct Push calls pass blocking 0 (19), 1 (43), not constant (4). Console buffer ownership, snapshot timing and empty-queue errors are unverified. Completed grains remain queued until Push consumes them, so memory use grows with an unconsumed PCM backlog. The console backlog limit is unverified. A nonblocking Push without a completed grain throws; this is a runtime restriction, not a console measurement. Context destruction concurrent with active calls remains unsupported. Without an SDL device the existing wall-clock path remains. Changed: `docs/dev/debt/libSceAudioOut.md`, one existing entry extended by one sentence. No code change. Method: for each of the 53 local titles the import table of the title's executable was read, and the direct `call` instructions to the imported function were counted in that executable (static counting only, nothing run on a console); the value of the `blocking` argument was read from the instructions just before each call and checked by a second, independent count. Per-title results and the counting script are attached to this PR. They contain counts, addresses and classifications only, no game code. Calls through the GOT (`call [rip+got]`) would not be read; every registry call site of the import in these executables is a stub `jmp [rip+got]`, so there are none. ### Overlap Three open PRs change `docs/dev/debt/libSceAudioOut.md`, none of them this entry: #12425 changes single lines at 36 and 135, #11762 adds three lines after line 11, and #5021 adds two lines after line 28. `git merge-tree` of this branch against the heads of #12425 and #11762 is clean. #5021 does not merge cleanly into `main` on its own either, with or without this change. Measured on the file sets of all 1393 open PRs (`git diff --name-only` from the merge base to each PR head, all refs fetched). Duplicates checked through the pull request API over all pull requests: no open or merged PR counts the `blocking` values of `sceAudioOut2ContextPush`. ### Tested Documentation only. `tools/check_conventions.py --base upstream/main` passes; based on current `main` `3a2b919816`. Not built, not run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rooklz commented 2026-10-29 04:28:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T04:28:58Z.

Review: COMMENTED


I checked the attached data and script. I ran nothing on title code: I don't have the 53 executables. I only ran the posted arg_value() on synthetic input with GNU objdump 2.42 (Ubuntu 24.04, x86_64).

What I checked (head ba998c5558, main b433c40f2f)

Check Result
git merge-tree --write-tree upstream/main clean (the entry moved to L11 on main, and the merge still applies)
check_conventions.py --base upstream/main --head passed
git diff --check clean
Per-title table recounted with a script 39 titles, 66 direct calls, 11 tail jumps, blocking 0×19 / 1×44 / computed×3, every row's site count = its "Direct calls" column. Matches the summary line and the new sentence
Sentence vs AudioOut2Context.cpp L342/L354: nonblocking Push rejects on a full queue and throws without a grain, so the 19 0 sites reach code paths the entry already describes

arg_value() on synthetic windows

I put each byte sequence right before an E8 call in a fake one-segment ELF and called the posted function unchanged. It is wrong on 16 of 31 cases, and the errors go both ways:

Sequence before call posted correct
mov esi,1; cdq / mul ecx computed 1 (only edx/eax are written)
mov esi,1; pop rsi / movsxd rsi,eax / adc esi,0 / bswap esi / rol esi,1 / popcnt esi,eax 1 not constant
mov esi,1; rep movsb / lodsb 1 not constant (implicit rsi)
mov esi,1; call f; mov rdi,rax 1 not constant (call clobbers esi)
mov sil,1 / mov si,1 1 not constant (upper bits unknown)
mov esi,1; jne +2; xor esi,esi / jmp over the xor 0 not constant (branch inside the window)
window starting in the middle of an instruction (b8 00 00 48 b8 | be 01 …) unreadable 1 (objdump desyncs. The call offset is never printed as an instruction start)

The reasons: the write list has no pop/movsxd/adc/rol/bswap/popcnt/string ops/call, mul|div|cdq counts as a write for any register, the immediate is accepted for sil/si, and the walk ignores branches. Also, nothing checks that the call offset was decoded as an instruction start.

I also compiled 13 small C functions that call push(ctx, blocking) (constants, x != 0, ternaries, a loop with i & 1, a volatile load, a call between the setup and the push, a global first argument) with gcc 13.3 at -O0/-O1/-O2/-O3/-Os. On those 87 call sites the posted script is right every time. So real compiler output rarely hits the cases above, and I don't expect the 19/44/3 split to change. Still, the 0 and 1 counts depend on this walk. A stricter version (below) is right on all 31 synthetic cases and gives the same answer on all 87 compiled sites. It changes three things: it uses an explicit "first operand is the register" test plus implicit writers, it treats a branch landing between the last write and the call as not constant, and it re-decodes from 64…48 bytes back, reporting ambiguous if those starts disagree. If you re-run it over the 66 sites, any change would show up as computed/ambiguous rows.

replacement for arg_value (same signature)
FULL = {'esi': r'(?:esi|rsi)', 'edx': r'(?:edx|rdx)'}
IMPLICIT = {'esi': ('rep', 'movs', 'lods', 'stos', 'cmps', 'scas', 'outs', 'ins'), 'edx': ('cdq', 'cqo', 'cwd', 'mul', 'div', 'idiv', 'rdtsc', 'rdtscp', 'cpuid', 'rdmsr', 'rdpmc', 'xgetbv')}
READS = ('cmp', 'test', 'push', 'bt ', 'nop')
def classify_window(txt, callpos, reg):
    r = REGS[reg]
    first = re.compile(r'\S+\s+(?:\w+ PTR )?' + r + r'\b')
    anywhere = re.compile(r'\b' + r + r'\b')
    last = None
    lastpos = -1
    targets = []
    synced = False
    for line in txt.split('\n'):
        m = re.match(r'\s+([0-9a-f]+):\s+(?:[0-9a-f]{2} )+\s*(.*)', line)
        if not m:
            continue
        pos = int(m.group(1), 16)
        ins = m.group(2).strip()
        if pos >= callpos:
            synced = pos == callpos
            break
        op = ins.split()[0] if ins else ''
        if op.startswith('j') or op.startswith('loop') or op in ('bnd', 'notrack', 'ret'):
            t = re.search(r'\b0x([0-9a-f]+)\b|^\S+\s+([0-9a-f]+)\b', ins)
            targets.append((pos, int(t.group(1) or t.group(2), 16) if t and op not in ('ret',) and 'PTR' not in ins and '[' not in ins else None, op))
            continue
        if op.startswith(READS):
            continue
        if op == 'call' or op.startswith(IMPLICIT[reg]) or (op.startswith(('xchg', 'xadd', 'cmpxchg')) and anywhere.search(ins)) or first.match(ins):
            last, lastpos = ins, pos
    if not synced:
        return None
    if last is None:
        return 'unreadable'
    for pos, target, op in targets:
        if target is not None and lastpos < target <= callpos:
            return 'computed'
    f = FULL[reg]
    if re.match(r'xor\s+' + f + r',\s*' + f + r'$', last):
        return '0'
    m = re.match(r'mov\s+' + f + r',\s*(0x[0-9a-f]+|\d+)$', last)
    if m:
        return str(int(m.group(1), 0))
    return 'computed'


def arg_value(objdump, data, segs, va, reg, tmp):
    fo = file_offset(segs, va)
    seen = set()
    for back in range(64, 47, -1):
        w0 = max(0, fo - back)
        with open(tmp, 'wb') as fh:
            fh.write(data[w0:fo + 5])
        txt = subprocess.run([objdump, '-D', '-b', 'binary', '-mi386:x86-64', '-M', 'intel', tmp],
                             capture_output=True, text=True).stdout
        v = classify_window(txt, fo - w0, reg)
        if v is not None:
            seen.add(v)
    return seen.pop() if len(seen) == 1 else 'ambiguous'

Two smaller points

  1. "unreadable (3)" vs the script's computed. In the script, unreadable means no write in the window, and computed means some other write. All 3 sites are computed. The comment explains why the sentence says "unreadable", but someone re-running the script will see a category the sentence doesn't use. Maybe "or a computed value (3)".
  2. Calls straight through the GOT are not counted (the same gap as in #12707). CallSiteResolver.cpp L67-104 also records a title's own call [rip+got] (FF 15) as a call site. The script treats each recorded address as a stub and only counts E8/E9 rel32 that target it, so FF 15 sites are skipped silently. The Limits bullet covers function pointers but not this case. A per-title count of callSites entries that are not PLT stubs, or one more phrase in Limits, would close it.

Docs-only change, the numbers match the attachment, and neither gap is likely to change them. This is a comment, not a change request.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692863136 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12698#pullrequestreview-5692863136). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T04:28:58Z. **Review:** COMMENTED --- I checked the attached data and script. I ran nothing on title code: I don't have the 53 executables. I only ran the posted `arg_value()` on synthetic input with GNU objdump 2.42 (Ubuntu 24.04, x86_64). ### What I checked (head `ba998c5558`, main `b433c40f2f`) | Check | Result | |---|---| | `git merge-tree --write-tree upstream/main` | clean (the entry moved to L11 on main, and the merge still applies) | | `check_conventions.py --base upstream/main --head` | passed | | `git diff --check` | clean | | Per-title table recounted with a script | 39 titles, 66 direct calls, 11 tail jumps, blocking `0`×19 / `1`×44 / `computed`×3, every row's site count = its "Direct calls" column. Matches the summary line and the new sentence | | Sentence vs `AudioOut2Context.cpp` | L342/L354: nonblocking Push rejects on a full queue and throws without a grain, so the 19 `0` sites reach code paths the entry already describes | ### `arg_value()` on synthetic windows I put each byte sequence right before an `E8` call in a fake one-segment ELF and called the posted function unchanged. It is wrong on **16 of 31** cases, and the errors go both ways: | Sequence before `call` | posted | correct | |---|---|---| | `mov esi,1; cdq` / `mul ecx` | computed | 1 (only edx/eax are written) | | `mov esi,1; pop rsi` / `movsxd rsi,eax` / `adc esi,0` / `bswap esi` / `rol esi,1` / `popcnt esi,eax` | 1 | not constant | | `mov esi,1; rep movsb` / `lodsb` | 1 | not constant (implicit rsi) | | `mov esi,1; call f; mov rdi,rax` | 1 | not constant (call clobbers esi) | | `mov sil,1` / `mov si,1` | 1 | not constant (upper bits unknown) | | `mov esi,1; jne +2; xor esi,esi` / `jmp` over the xor | 0 | not constant (branch inside the window) | | window starting in the middle of an instruction (`b8 00 00 48 b8 \| be 01 …`) | unreadable | 1 (objdump desyncs. The call offset is never printed as an instruction start) | The reasons: the `write` list has no `pop`/`movsxd`/`adc`/`rol`/`bswap`/`popcnt`/string ops/`call`, `mul|div|cdq` counts as a write for any register, the immediate is accepted for `sil`/`si`, and the walk ignores branches. Also, nothing checks that the call offset was decoded as an instruction start. I also compiled 13 small C functions that call `push(ctx, blocking)` (constants, `x != 0`, ternaries, a loop with `i & 1`, a volatile load, a call between the setup and the push, a global first argument) with gcc 13.3 at -O0/-O1/-O2/-O3/-Os. On those **87 call sites the posted script is right every time**. So real compiler output rarely hits the cases above, and I don't expect the 19/44/3 split to change. Still, the 0 and 1 counts depend on this walk. A stricter version (below) is right on all 31 synthetic cases and gives the same answer on all 87 compiled sites. It changes three things: it uses an explicit "first operand is the register" test plus implicit writers, it treats a branch landing between the last write and the call as not constant, and it re-decodes from 64…48 bytes back, reporting `ambiguous` if those starts disagree. If you re-run it over the 66 sites, any change would show up as `computed`/`ambiguous` rows. <details><summary>replacement for arg_value (same signature)</summary> ```python FULL = {'esi': r'(?:esi|rsi)', 'edx': r'(?:edx|rdx)'} IMPLICIT = {'esi': ('rep', 'movs', 'lods', 'stos', 'cmps', 'scas', 'outs', 'ins'), 'edx': ('cdq', 'cqo', 'cwd', 'mul', 'div', 'idiv', 'rdtsc', 'rdtscp', 'cpuid', 'rdmsr', 'rdpmc', 'xgetbv')} READS = ('cmp', 'test', 'push', 'bt ', 'nop') def classify_window(txt, callpos, reg): r = REGS[reg] first = re.compile(r'\S+\s+(?:\w+ PTR )?' + r + r'\b') anywhere = re.compile(r'\b' + r + r'\b') last = None lastpos = -1 targets = [] synced = False for line in txt.split('\n'): m = re.match(r'\s+([0-9a-f]+):\s+(?:[0-9a-f]{2} )+\s*(.*)', line) if not m: continue pos = int(m.group(1), 16) ins = m.group(2).strip() if pos >= callpos: synced = pos == callpos break op = ins.split()[0] if ins else '' if op.startswith('j') or op.startswith('loop') or op in ('bnd', 'notrack', 'ret'): t = re.search(r'\b0x([0-9a-f]+)\b|^\S+\s+([0-9a-f]+)\b', ins) targets.append((pos, int(t.group(1) or t.group(2), 16) if t and op not in ('ret',) and 'PTR' not in ins and '[' not in ins else None, op)) continue if op.startswith(READS): continue if op == 'call' or op.startswith(IMPLICIT[reg]) or (op.startswith(('xchg', 'xadd', 'cmpxchg')) and anywhere.search(ins)) or first.match(ins): last, lastpos = ins, pos if not synced: return None if last is None: return 'unreadable' for pos, target, op in targets: if target is not None and lastpos < target <= callpos: return 'computed' f = FULL[reg] if re.match(r'xor\s+' + f + r',\s*' + f + r'$', last): return '0' m = re.match(r'mov\s+' + f + r',\s*(0x[0-9a-f]+|\d+)$', last) if m: return str(int(m.group(1), 0)) return 'computed' def arg_value(objdump, data, segs, va, reg, tmp): fo = file_offset(segs, va) seen = set() for back in range(64, 47, -1): w0 = max(0, fo - back) with open(tmp, 'wb') as fh: fh.write(data[w0:fo + 5]) txt = subprocess.run([objdump, '-D', '-b', 'binary', '-mi386:x86-64', '-M', 'intel', tmp], capture_output=True, text=True).stdout v = classify_window(txt, fo - w0, reg) if v is not None: seen.add(v) return seen.pop() if len(seen) == 1 else 'ambiguous' ``` </details> ### Two smaller points 1. **"unreadable (3)" vs the script's `computed`.** In the script, `unreadable` means *no write in the window*, and `computed` means *some other write*. All 3 sites are `computed`. The comment explains why the sentence says "unreadable", but someone re-running the script will see a category the sentence doesn't use. Maybe "or a computed value (3)". 2. **Calls straight through the GOT are not counted** (the same gap as in #12707). `CallSiteResolver.cpp` L67-104 also records a title's own `call [rip+got]` (`FF 15`) as a call site. The script treats each recorded address as a stub and only counts `E8`/`E9 rel32` that target it, so `FF 15` sites are skipped silently. The Limits bullet covers function pointers but not this case. A per-title count of `callSites` entries that are not PLT stubs, or one more phrase in Limits, would close it. Docs-only change, the numbers match the attachment, and neither gap is likely to change them. This is a comment, not a change request. AI-assisted: yes
THEMANnt commented 2026-10-29 07:07:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-29T07:07:42Z.

Review: APPROVED


Reviewed f205990ead16296bbc0e41a928565b7d56ab0dd3 against 3a2b91981651569163768854a1fcdc7193b6667b. The direct-call census is clearly separated from the existing SDL/snapshot/queue implementation and the unverified console semantics. The linked Advance/Push implementation resolves and retains those host restrictions. No actionable finding in the documentation change.

Validation: inspected the changed wording and relevant pinned source; relative source links and git diff --check pass. Documentation-only validation: no runtime behavior changed. Author-reported title inventories, console/emulator observations and macOS/physical-GPU measurements were not independently reproduced; this review does not certify those measurements.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5694036902 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12698#pullrequestreview-5694036902). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-29T07:07:42Z. **Review:** APPROVED --- Reviewed `f205990ead16296bbc0e41a928565b7d56ab0dd3` against `3a2b91981651569163768854a1fcdc7193b6667b`. The direct-call census is clearly separated from the existing SDL/snapshot/queue implementation and the unverified console semantics. The linked Advance/Push implementation resolves and retains those host restrictions. No actionable finding in the documentation change. Validation: inspected the changed wording and relevant pinned source; relative source links and git diff --check pass. Documentation-only validation: no runtime behavior changed. Author-reported title inventories, console/emulator observations and macOS/physical-GPU measurements were not independently reproduced; this review does not certify those measurements.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12698
No description provided.