teakra icon indicating copy to clipboard operation
teakra copied to clipboard

Discussion: Having the Teakra user own DSP RAM instead of Teakra itself

Open wheremyfoodat opened this issue 11 months ago • 2 comments

Hi! At the moment, Teakra itself creates and owns DSP RAM, with the user being able to get a pointer to it via the interface. I'd like to inquire about your thoughts on (optionally?) allowing for the user to own DSP RAM themselves, and pass it to Teakra instead.

There's a handful of reasons why I believe this would be helpful for DSi/3DS emulators.

  • The current design does not allow for fastmem to be used with DSP RAM. Fastmem is a technique that creates a mirror of the emulated system's vaddr space inside a sectiom of the host's vaddr space. Then, an access to a guest vaddr can be performed by just accessing fastmem_base + vaddr. This significantly speeds up memory accesses, as they no longer have to go through any address decoding or pagetables, everything is handled by the host MMU.
    • In order to achieve this, we typically create a memory arena using VirtualAlloc/mmap, from which we allocate the emulated system's memory (eg FCRAM and DSP RAM on 3DS). As Teakra wants to own and manage its own memory, we can't do this, thus DSP RAM can't be used with fastmem, and needs slow memory access fallbacks instead.
  • Letting the user manage DSP RAM themselves would allow for things like using shared memory for it. This lets the emulator easily share DSP RAM between processes which opens up some nice possibilities, like hooking it up to external debugging tools.
  • Albeit a niche use case, there could be situations where one wants DSP RAM to persist even after the Teakra object is destroyed.

Thank you for your time.

wheremyfoodat avatar Dec 01 '24 09:12 wheremyfoodat

Sounds like a good idea to me! I don't see any problem with this. I haven't touched this code base for quite long, though, and I don't have much time working on it at the moment... Feel free to fork and/or send PR with the change.

wwylele avatar Dec 01 '24 17:12 wwylele

Sorry for the inactivity, been busy with other things.

@raphaelthegreat told me he already has a commit that makes this change here https://github.com/raphaelthegreat/teakra/commit/ad825418ef8b91e31bea678a9f470988bac6b568

This could be cherry-picked and merged if deemed fit.

wheremyfoodat avatar Dec 08 '24 13:12 wheremyfoodat