Skip to content

Reuse a dynamic buffer for different draw calls #5

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

Closed
bvssvni opened this issue Feb 10, 2015 · 10 comments
Closed

Reuse a dynamic buffer for different draw calls #5

bvssvni opened this issue Feb 10, 2015 · 10 comments
Labels

Comments

@bvssvni
Copy link
Member

bvssvni commented Feb 10, 2015

Currently it creates a new vertex buffer at each call.

It also allocates in .collect() when converting from a flat array to the buffer.

@bvssvni bvssvni added the draft label Feb 10, 2015
@tomaka
Copy link
Contributor

tomaka commented Feb 10, 2015

For performance, it should also use a persistent buffer when available.

@bvssvni
Copy link
Member Author

bvssvni commented Feb 10, 2015

gfx_graphics uses graphics::BACK_END_MAX_VERTEX_COUNT to compute the size of the buffer upfront, which piston-graphics uses to limit the chunk size. This might be changed in the future to reduce cache misses.

@milibopp
Copy link
Contributor

Removing the allocation would require Glium's buffers to be constructed from slices, I think.

@bvssvni
Copy link
Member Author

bvssvni commented Feb 10, 2015

Is it possible to update the buffer with slices?

@tomaka
Copy link
Contributor

tomaka commented Feb 10, 2015

It's not only a problem of slice vs vec. Creating a vertex buffer is a slightly costly operation due both to the implementation of glium (the background thread thing) and to glium/glium#478. I think that calling collect() would in fact be faster than uploading using a slice, because it avoid a synchronization between the two threads.

The most optimal implementation, in my opinion, uses two persistent buffers.
When you draw something, you map and write the data in the one of the buffers, then draw with it. And every time you draw, you alternate the buffer that you use (first you use buffer A, then buffer B, then buffer A, then buffer B, etc.).

This way you use the CPU to upload the data in the video memory while the GPU is drawing simultaneously.

@tomaka
Copy link
Contributor

tomaka commented Feb 10, 2015

I can write the implementation, but we'd need something similar to gfx_graphics's G2D, ie. a struct that persists between draw calls where we can store the buffer.

But that's API-related so I think I'm going to leave this to you.

@bvssvni
Copy link
Member Author

bvssvni commented Feb 10, 2015

@tomaka Just go ahead if you know what to do. If it gets similar to gfx_graphics then that's fine.

@tomaka
Copy link
Contributor

tomaka commented Feb 10, 2015

I'll need to work on glium/glium#481 first

@tomaka
Copy link
Contributor

tomaka commented Feb 10, 2015

I'm blocked on glium/glium#482 which is blocked on rust-lang/rust#22156

@bvssvni
Copy link
Member Author

bvssvni commented May 4, 2015

It seems this is already done? Closing.

@bvssvni bvssvni closed this as completed May 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants