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

Improved performance for colored graphics #286

Merged
merged 4 commits into from Mar 12, 2016

Conversation

@bvssvni
Copy link
Member

commented Mar 9, 2016

Closes #283

bvssvni added some commits Mar 9, 2016

Reduce number of draw calls
- Added `CHUNKS` to control memory usage of buffers
- Added `Gfx2d::colored_offset`
- Added `Gfx2d::colored_draw_state`
- Remove multiple of components since `create_buffer_dynamic` uses the
size of type
- Added `GfxGraphics::flush_colored`
@bvssvni

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2016

I'm getting an OutOfBounds when setting CHUNKS = 1.

thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: OutOfBounds { target: 8208, source: 8192 }', ../src/libcore/result.rs:746
stack backtrace:
   1:        0x101d7d538 - sys::backtrace::tracing::imp::write::hdcc91e23d52f1e9feuv
   2:        0x101d7f185 - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44401
   3:        0x101d7eda8 - panicking::default_handler::h5bfcd298419b6ef54Wz
   4:        0x101d73d16 - sys_common::unwind::begin_unwind_inner::hbee05b49f1a706c20su
   5:        0x101d741ce - sys_common::unwind::begin_unwind_fmt::hac9a85f022410ea86ru
   6:        0x101d7ca57 - rust_begin_unwind
   7:        0x101da3080 - panicking::panic_fmt::h98dcb863ad76e04b7mM
   8:        0x101b390cc - result::unwrap_failed::h16207664000137731971
   9:        0x101b38f69 - result::Result<T, E>::unwrap::h6565847892804117424
  10:        0x101b42dc6 - gfx_graphics::back_end::GfxGraphics<'a, R, C>.Graphics::tri_list::_$u7b$$u7b$closure$u7d$$u7d$::closure.24117
  11:        0x101b45651 - extern $u22$rust.call$u22$$u20$fn$LP$$RF$mut$u20$for$LT$$u27$r$GT$$u20$core..ops..FnMut$LP$$RF$$u27$r$u20$$u5b$f32$u5d$$RP$$u20$$u2b$$u20$$u27$static$C$$u20$$LP$$RF$$u27$static$u20$$u5b$f32$u5d$$C$$RP$$RP$::object_shim.24241::hc1284efc972ff8b2
  12:        0x101b455fa - graphics::line::Line::draw_tri::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::closure.24210
  13:        0x101b451b2 - triangulation::stream_polygon_tri_list::h5829249386123331210
  14:        0x101b428bc - graphics::line::Line::draw_tri::_$u7b$$u7b$closure$u7d$$u7d$::closure.24115
  15:        0x101b3da97 - back_end::GfxGraphics<'a, R, C>.Graphics::tri_list::h10316126248497586634
  16:        0x101b3d7d3 - line::Line::draw_tri::h14829398184492136288
  17:        0x101b3d653 - deform::DeformGrid::draw_vertical_lines::h5891561837499658206
  18:        0x101b2ea9f - main::_$u7b$$u7b$closure$u7d$$u7d$::closure.23743
  19:        0x101b2e2f5 - back_end::Gfx2d<R>::draw::h7783497041085704393
  20:        0x101b2c579 - PistonWindow<T, W>::draw_2d::h8227702290646774362
  21:        0x101a28f79 - main::hd62f102780f00f9flaa
  22:        0x101d7e9b2 - sys_common::unwind::try::try_fn::h14955010582267137138
  23:        0x101d7c9eb - __rust_try
  24:        0x101d7e870 - rt::lang_start::hb0216a17e8d25b77aPz
  25:        0x101b72129 - main

8208/8 = 1026

8192/8 = 1024

Use `from_raw_parts` instead of `transmute`
Fixes an out of bounds bug because the slice length changes meaning
when transmuting.
@bvssvni

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2016

Found out that from_raw_parts should be used instead of transmute.

@bvssvni

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2016

@mitchmindtree Tested all_widgets example in Conrod. It is a lot faster in both release modes. I don't notice the difference. Feels a little more responsive in debug mode, though.

The deform example is noticeable better in debug mode. In release mode it even runs smoothly with a 40x40 grid, which is significantly better than the old version.

@bvssvni

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2016

(deform example, 40x40 grid, 1000 frames, benchmark mode)

Old:

real    2m17.501s
user    2m10.801s
sys 0m5.863s

real    2m18.918s
user    2m12.004s
sys 0m5.952s

New:

real    0m22.146s
user    0m17.496s
sys 0m3.819s

real    0m21.431s
user    0m16.774s
sys 0m3.846s

This is a 6.4x speedup!

bvssvni added a commit that referenced this pull request Mar 12, 2016

Merge pull request #286 from bvssvni/optimize
Improved performance for colored graphics

@bvssvni bvssvni merged commit 18f78d0 into PistonDevelopers:master Mar 12, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@bvssvni bvssvni deleted the bvssvni:optimize branch Mar 12, 2016

@bvssvni

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2016

Published as 0.23.1.

@mitchmindtree

This comment has been minimized.

Copy link
Member

commented Mar 13, 2016

@bvssvni woah great work, that's super exciting!

I'm currently finishing off some DSP work atm, but will hopefully get back to conrod in the next couple days and try out the update - can't wait!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.