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

Expose safe interface to OpenGL timer queries #1407

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicokoch
Copy link
Collaborator

This module provides utilities to profile GPU execution times in a new module glium::timer.

This example shows how to use the new functionalities (from the docs):

// drawing a frame
use glium::timer;
let mut target = display.draw();
let handle = timer::measure(&display, || {
    target.clear_color(0.0, 0.0, 0.0, 0.0);
    target.draw(&vertex_buffer, &index_buffer, &program, &uniforms, &Default::default()).unwrap();
    target.finish().unwrap();
}).unwrap();
println!("GPU needed {:?} to draw", handle.get_measurement().interval());

I had this code lying around from ancient times and ported it to glium.
It makes use of GL_arb_timer_query

This module provides utilities to profile GPU execution times.
/// If the GPU is idle during execution, the clock keeps ticking, so it doesn't make a lot
/// of sense to use this function for CPU-heavy tasks.
pub fn measure<F, M>(facade: &F, measure: M) -> Result<AsyncTimerHandle, TimerCreationError>
where F: Facade, M: FnOnce() -> ()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not really good with the closure traits. Is FnOnce the correct choice?

@nicokoch
Copy link
Collaborator Author

I see something similar has already been implemented in draw_parameters, so maybe this won't be very useful.

How ever, in l. 114 is says FIXME: handle Timestamp separately, so maybe there's hope.

@tomaka
Copy link
Member

tomaka commented Jan 18, 2016

Isn't that what's already implemented in debug.rs? https://github.com/tomaka/glium/blob/master/src/debug.rs#L119

@nicokoch
Copy link
Collaborator Author

Oh you're right.

What do you think about the api in general?
I know other query objects are currently handled in draw parameters, but my design would allow profiling things like compute shaders (or other non-draw related GL functionality) too.

@tomaka
Copy link
Member

tomaka commented Jan 19, 2016

Your design works for timestamp queries, but not for other kind of queries because the user can only activate one query of each type simultaneously.

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.

None yet

2 participants