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

Fps benchmark speed #189

Closed
Alphapage opened this issue Dec 24, 2023 · 5 comments
Closed

Fps benchmark speed #189

Alphapage opened this issue Dec 24, 2023 · 5 comments

Comments

@Alphapage
Copy link

Hello,

The readme example below runs at approximatively 120fps on my Mac M1.

Can other processor perform better or is it a softbuffer limitation ?

Thank you in advance for your help.

use std::num::NonZeroU32;
use std::rc::Rc;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;

fn main() {
    let event_loop = EventLoop::new().unwrap();
    let window = Rc::new(WindowBuilder::new().build(&event_loop).unwrap());
    let context = softbuffer::Context::new(window.clone()).unwrap();
    let mut surface = softbuffer::Surface::new(&context, window.clone()).unwrap();

    event_loop
        .run(move |event, elwt| {
            elwt.set_control_flow(ControlFlow::Poll);

            let tt = std::time::Instant::now();

            let (width, height) = {
                let size = window.inner_size();
                (size.width, size.height)
            };
            surface
                .resize(
                    NonZeroU32::new(width).unwrap(),
                    NonZeroU32::new(height).unwrap(),
                )
                .unwrap();

            let mut buffer = surface.buffer_mut().unwrap();
            for index in 0..(width * height) {
                let y = index / width;
                let x = index % width;
                let red = x % 255;
                let green = y % 255;
                let blue = (x * y) % 255;

                buffer[index as usize] = blue | (green << 8) | (red << 16);
            }

            buffer.present().unwrap();

            println!("{}", 1.0 / tt.elapsed().as_secs_f64());

            match event {
                Event::WindowEvent {
                    window_id,
                    event: WindowEvent::RedrawRequested,
                } if window_id == window.id() => {}
                Event::WindowEvent {
                    event: WindowEvent::CloseRequested,
                    window_id,
                } if window_id == window.id() => {
                    elwt.exit();
                }
                _ => {}
            }
        })
        .unwrap();
}
@notgull
Copy link
Member

notgull commented Dec 24, 2023

There was discussion of using a more efficient backend for macOS, see #83

@Alphapage
Copy link
Author

Ok, great news...
But can you tell me what is the average performance on linux or windows, a pc can reach depending the cpu ?
Is it 1000fps , 10000fps , more ???

@notgull
Copy link
Member

notgull commented Dec 24, 2023

For Linux, I've personally benchmarked it to be around 600 FPS in the worst case. Not sure about other platforms; we use less efficient strategies for those.

@ids1024
Copy link
Member

ids1024 commented Dec 24, 2023

Though if you get 600fps testing softbuffer, that will go down as soon as you have a software renderer doing non-trivial things. Which presumably would be the case for typical real uses.

Hopefully softbuffer won't be the bottleneck. But if you want the best performance you'll want OpenGL/Vulkan/Metal rather than a software renderer.

@Alphapage
Copy link
Author

Yes it goes down very quickly by doing some trivial things too :(
Thank you for your expertise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants