From d68ff7243ae12f6571bade16b965e049db5103f6 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Sat, 21 Feb 2026 00:39:11 +0900 Subject: [PATCH] [XMA] Fix consume-only path write offset and drain check --- src/xenia/apu/xma_context_new.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/xenia/apu/xma_context_new.cc b/src/xenia/apu/xma_context_new.cc index 30f081b34..c1a8018d9 100644 --- a/src/xenia/apu/xma_context_new.cc +++ b/src/xenia/apu/xma_context_new.cc @@ -130,9 +130,19 @@ bool XmaContextNew::Work() { RingBuffer output_rb = PrepareOutputRingBuffer(&data); if (data.IsConsumeOnlyContext()) { + XELOGAPU("XmaContext {}: Consume-only context, draining subframes", id()); Consume(&output_rb, &data); + data.output_buffer_write_offset = + output_rb.write_offset() / kOutputBytesPerBlock; + // Clearing contexts that match TightBufferOutput heuristic can disrupt + // playback (e.g. audio noise during races in PGR4), so we only clear + // contexts with enough output buffer headroom where empty input reliably + // indicates the stream is finished (e.g. needed for dialog completion in + // Borderlands 2 startup). if (!data.HasTightOutputBuffer() && - data.output_buffer_read_offset == data.output_buffer_write_offset) { + current_frame_remaining_subframes_ == 0 && output_rb.empty()) { + XELOGAPU("XmaContext {}: Consume-only context fully drained, clearing", + id()); ClearLocked(&data); } StoreContextMerged(data, initial_data, context_ptr);