Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mt - Improve performance with threads and other optimizations #62

Merged
merged 39 commits into from
Nov 4, 2021

Conversation

alloncm
Copy link
Owner

@alloncm alloncm commented Nov 1, 2021

Closes #57
Closes #53
Closes #34

Since SDL is really ambiguous about rendering from another
thread the emulation is running on another thread.

Using crossbeam parker for sync between threads
(Some kind of AutoResetEvent from C#)
And using rtrb for the ring buffer queue for moving data
between the threads
chose criterion cause the regualr one is stil unstable.
test with `cargo bench`
- Use crossbeam-utils instead of the whole lib
- Cache the analog sample in the channel
instead of calculating it each time
This optimization gained a crazy performance boost!
Probably cause of the lack of division in the new solution.
I was checking optimization of replacing f32 with u16 or u32
 but it seems that f32 is the better option,
 anyway if another platform will need replacing
 (or adding a compile condition should be easier).
Add proper handling of closing the program
# Conflicts:
#	Cargo.lock
#	lib_gb/Cargo.toml
The merge broke some code in the tests
Which turn to be faster (with blocking involved.
In order to abstract the sample type primitive.
This should improve performance of
the sound terminal
# Conflicts:
#	gb/src/audio_resampler.rs
#	lib_gb/benches/my_bench.rs
#	lib_gb/src/apu/audio_device.rs
#	lib_gb/src/apu/channel.rs
#	lib_gb/src/apu/gb_apu.rs
#	lib_gb/src/apu/sound_terminal.rs
Casued by merge shit
This is important since it can cause flickering in the sound
* Inline it, for some reason it wont be inlined automaticaly
* Instead of multiplying with 1 or 0 Im anding with 0xFFFF or 0
Update thhe ppu and the apu dev status
There ware too much cloning whcih caused a BO in debug mode.
Using pointer casted to usize to communicate between threads
and a multi buffering in the ppu
(to avoid race conditions, at least I hope)
I managed to solve this issue in debug mode too!
Instead of cycling every t_cycle the apu now
cycle in m_cycle increasing its performance by almost 4!
This will hust emulation accuracy
but I think I can live with this minor hit :D
Add frame cap using SDL_Delay.

Also add the option to configure the emulation speed (both ppu and apu)
* Audio pull by deafult and under the featue flag - push-audio
* vsync is on by default and by passing `--no-vsync` it can be disabled
There are 2 flags
* sdl-resample - will compile the sdl resampler instead of my resampler
* push-audio - will push the audio to the device instead
of the device pulling it by himslef.
The apu timer test was outdated.
The apu timer counts in tcycles but increment itself each time by 4
cycles and not 1.
gb/src/audio/audio_resampler.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_audio_resampler.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Outdated Show resolved Hide resolved
gb/src/main.rs Outdated Show resolved Hide resolved
gb/Cargo.toml Outdated Show resolved Hide resolved
gb/src/audio/mod.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Show resolved Hide resolved
@alloncm alloncm marked this pull request as ready for review November 1, 2021 22:50
gb/src/audio/mod.rs Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Outdated Show resolved Hide resolved
gb/src/audio/sdl_pull_audio_device.rs Outdated Show resolved Hide resolved
gb/src/audio/audio_resampler.rs Outdated Show resolved Hide resolved
gb/src/main.rs Show resolved Hide resolved
gb/src/main.rs Outdated Show resolved Hide resolved
lib_gb/src/apu/sound_terminal.rs Show resolved Hide resolved
lib_gb/src/apu/timer.rs Show resolved Hide resolved
lib_gb/src/apu/timer.rs Show resolved Hide resolved
@alloncm alloncm changed the title Feature/mt - Improve performance with threads Feature/mt - Improve performance with threads and other optimizations Nov 4, 2021
Some renaming and other cosmetic changes like extracting to files.
Also using cfg-if for ifdef like code
Also fIxed a typo in the sdl-resample feature
According to the benchmark this has improved performance a bit :)
@alloncm alloncm merged commit 2dc558d into dev Nov 4, 2021
@alloncm alloncm deleted the feature/mt branch November 4, 2021 19:55
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.

Improve performance Sound sync Sound accuracy
1 participant