VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I'm just wondering if my emulator would have a good speed boost, when I move my CPU core emulation thread (running a x86 processor) to the ME chip, but keeping all hardware emulation (video, audio, timing) on the main CPU. Since the CPU thread doesn't access any hardware directly, just RAM objects with data from emulated RAM or emulated hardware structures in RAM or emulator locks (SDL Semaphores), wouldn't it speed up the CPU thread to move it to the ME processor (and a seperate thread in Windows)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 7, by crazyc

User metadata
Rank Member
Rank
Member

Without cache coherency the clocks you'll lose flushing the cache will outweigh the gain from running on the other CPU. Consider doing something on the ME that depends on little else like audio mixing.

Reply 2 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

Can the audio mixer even run from the ME processor? It uses floating point math to apply gain etc. Will that still run on the ME processor? Also I'm using SDL to send the audio to the audio chip(either Windows or the PSP). Can I tell SDL to run the audio thread on the ME?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 4 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

What if I call the SDL audio thread routines for starting the audio thread or terminating/locking it on the ME? Some examples I found can do this using a little bit of assembly and a function pointer. So whenever my threads need to do anything related to the audio thread (start/stop/lock/unlock) just instruct the ME thread to run one of the four functions, wait for termination of the function and continue on the main CPU?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 5 of 7, by crazyc

User metadata
Rank Member
Rank
Member

There are no syscalls available on the ME. They share RAM at the same address but they don't share any MMIO so the SC kernel cannot be used on the ME. You can compile your code and it'll run properly on ME as long as it uses no PSP library calls. What you can do is start a monitor thread on the SC that waits for an ME interrupt while it does the mixing then the thread can pass the mix buffer directly to the output.

Reply 6 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++
crazyc wrote:

There are no syscalls available on the ME. They share RAM at the same address but they don't share any MMIO so the SC kernel cannot be used on the ME. You can compile your code and it'll run properly on ME as long as it uses no PSP library calls. What you can do is start a monitor thread on the SC that waits for an ME interrupt while it does the mixing then the thread can pass the mix buffer directly to the output.

What do you mean by this? What does the main CPU do? What does the ME do? Can SDL still be used to process audio in this way (with a SDL audio thread)?

Like this?

- SDL calls audio callback.
- Audio callback informs the ME that it needs audio.
- ME processed audio while main CPU audio callback delays.
- ME raises interrupt.
- Audio callback sees interrupt and continues execution (letting SDL pass the buffer to output).

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 7 of 7, by crazyc

User metadata
Rank Member
Rank
Member

That's right. You just need to make sure the input audio data (SB PCM buffers and OPL register) is flushed from the SC cache and invalidated in the ME cache before processing and flushed from the ME cache when done (since the audio is passed to the DAC via DMA you don't have to do anything with SC before starting the output). BTW, you should use sceAudioSRCOutputBlocking to output because you avoid the overhead of the PSP kernel software multichannel mixing and get hardware sample rate conversion for free.