Skip to content

apu: Add new DSP56300 emulator with JIT execution engine#2801

Draft
mborgerson wants to merge 3 commits intoxemu-project:masterfrom
mborgerson:feat/faster-dsp
Draft

apu: Add new DSP56300 emulator with JIT execution engine#2801
mborgerson wants to merge 3 commits intoxemu-project:masterfrom
mborgerson:feat/faster-dsp

Conversation

@mborgerson
Copy link
Copy Markdown
Member

@mborgerson mborgerson commented Mar 20, 2026

  • Fixes a few bugs in the existing C interpreter
  • Adds a state abstraction layer to switch between engines at runtime and maintain snapshot compatibility

TODO:

  • Fix xemu test cases
  • Fix macOS Build (target arch specification)
  • Fix Windows build (Rust toolchain)
  • Add dsp56300 license details to xemu's license gen script
  • Pin version

@mborgerson mborgerson marked this pull request as draft March 20, 2026 01:45
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the DSP56300 emulation by integrating a high-performance JIT engine alongside the existing C interpreter. The core architecture has been redesigned to support seamless runtime switching between these engines, preserving VM state and snapshot compatibility. This enhancement aims to improve audio processing efficiency and accuracy, while also providing users with control over the chosen DSP execution method through new configuration options.

Highlights

  • New DSP56300 JIT Emulator: A new Just-In-Time (JIT) execution engine has been added for the DSP56300 emulator, offering potentially faster processing for audio.
  • DSP Engine Abstraction: An abstraction layer was introduced to allow dynamic switching between the existing C interpreter and the new JIT engine at runtime, ensuring snapshot compatibility across engine changes.
  • C Interpreter Bug Fixes and Refinements: Several bugs in the existing C interpreter were addressed, and its internal structure was refactored to align with the new abstraction, including changes to interrupt handling and peripheral access.
  • Improved APU Thread Utilization Metrics: The APU thread's utilization calculation was refined to more accurately measure time spent building frames, replacing the previous sleep-based metric.
  • UI Integration: New UI toggles have been added to enable or disable the DSP JIT engine and control real-time DSP processing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new DSP JIT (Just-In-Time) compilation engine for improved audio processing performance, configurable via a new use_dsp_jit option. The DSP emulation architecture has been refactored to support multiple backends (C interpreter and JIT) through a common DSPOps interface and a unified DspCoreState structure for VM state synchronization. This includes updating APU state tracking to use microseconds and a frame_work_acc_us metric, abstracting DSP cache invalidation, and integrating DSP state synchronization with VM save/load operations. Debugging macros have been removed, and the DSP DMA logic has been enhanced to include dma_read_count for more accurate DMA completion timing. The C interpreter's DSP core has been simplified by removing unused interrupt types and debug-related fields from its state, while the JIT backend provides a Rust-based implementation with memory region mapping and state synchronization logic.

@Triticum0

This comment was marked as resolved.

@Triticum0
Copy link
Copy Markdown
Collaborator

Triticum0 commented Mar 20, 2026

Once available for test
TODO:

@mborgerson mborgerson force-pushed the feat/faster-dsp branch 8 times, most recently from 161b4eb to 691b91f Compare March 20, 2026 08:26
@Triticum0
Copy link
Copy Markdown
Collaborator

Triticum0 commented Mar 20, 2026

Audio Loop that happens in Night Caster series and other games still occurs on the JIT engine

@Triticum0
Copy link
Copy Markdown
Collaborator

Midi behaviour also not improved seem less heavy that interpreter but still causes broken audio and games to lock up #579

@Triticum0
Copy link
Copy Markdown
Collaborator

From my preliminary tested performance improvements range from about 60% to 100% based on utilization metrics. and maxing utilization doesn't seem to be a concern based on my hardware. Will do some testing on low end hardware but couldn't see any regressions from what I tested. Also audio crackling seem way less to mostly fixed but only anecdotal to take with pinch of salt.

@Triticum0
Copy link
Copy Markdown
Collaborator

Triticum0 commented Mar 20, 2026

Doesn't Improve #2372 or #2600

@Triticum0
Copy link
Copy Markdown
Collaborator

Triticum0 commented Mar 20, 2026

JIT engine seem to use less GP Cycles compared to Interperter on Sega Online

JIT
GP Cycles (- 37.1%)
EP Cycles (- 46%)

Screenshot_20260320_182839

Interperter

Screenshot_20260320_182851

@Triticum0
Copy link
Copy Markdown
Collaborator

From 20+ games I tested only game which doesn't run at full speed with JIT was Sega GT Online. Also using Savestates for sega GT Online while another disk is loaded caused an assertion.
../hw/xbox/mcpx/apu/dsp/gp_ep.c:60: void scatter_gather_rw(MCPXAPUState *, hwaddr, unsigned int, uint8_t *, uint32_t, size_t, _Bool): Assertion page_entry <= max_sge' failed.
Doesn't occur if sega GT Online is mounted already.

@Triticum0
Copy link
Copy Markdown
Collaborator

Triticum0 commented Mar 20, 2026

Also had performance issues in v-rally 3. not sure what cause it high utilisation even with Jit engine after a while performance stablized but need to be look at as some reason performance dropped to single digits.

@Triticum0
Copy link
Copy Markdown
Collaborator

I recorded so gameplay comparison but not sure if I post it TLDR:

Fixes performance slowdown due to dsp.

Fixes Audio Utilization crackling

Doesn't fix cracking issues on ea games which seems to be tide to frame-rate, which based on regression issues #2790 and #2096

Other than performance improvements didn't fix any outstanding audio assertion/bug

Lastly do you recent performance regression some game weren't included do regression make comparison not useful, as well so of the performance differences might been due to recent regression.

- Fixes a few bugs in the existing C interpreter
- Adds a state abstraction layer to switch between engines at runtime
  and maintain snapshot compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants