From 84666523e9a278ac95ca43dbaa534e8aaaf3ebd2 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 25 Feb 2019 22:08:53 +0100 Subject: Add LUPS reporting and fix glaring oversight The GLFW window rendering loop used to dispatch the compute shaders was restricted to 60 FPS. I did not notice this because I never actually measured the computed lattice updates per seconds in addition to trying to push the GPU to its limits. Turns out the lattice sizes I commonly use can be updated 500 times per second comfortably… Now this looks more like the performance gains promised by GPU computation. --- src/main.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc index 0b4df95..eeeb130 100644 --- a/src/main.cc +++ b/src/main.cc @@ -26,7 +26,7 @@ constexpr GLuint nX = 512; constexpr GLuint nY = 128; -constexpr int lups = 100; // max lattice updates per second +constexpr double maxLUPS = 500; float getWorldHeight(int window_width, int window_height, float world_width) { return world_width / window_width * window_height; @@ -120,15 +120,11 @@ int render(bool open_boundaries) { return -1; } - auto last_frame = timer::now(); - bool update_lattice = true; bool tick = true; auto pause_key = window.getKeyWatcher(GLFW_KEY_SPACE); - GLuint iT = 0; - int prevMouseState = 0; float prevLatticeMouseX; float prevLatticeMouseY; @@ -140,6 +136,12 @@ int render(bool open_boundaries) { auto tick_buffers = { lattice_a->getBuffer(), lattice_b->getBuffer(), fluid->getBuffer() }; auto tock_buffers = { lattice_b->getBuffer(), lattice_a->getBuffer(), fluid->getBuffer() }; + GLuint iT = 0; + int statLUPS = 0; + + auto last_lattice_update = timer::now(); + auto last_lups_update = timer::now(); + window.render([&](bool window_size_changed) { if ( pause_key.wasClicked() ) { update_lattice = !update_lattice; @@ -151,7 +153,15 @@ int render(bool open_boundaries) { } if ( update_lattice ) { - if ( timer::millisecondsSince(last_frame) >= 1000/lups ) { + if ( timer::secondsSince(last_lups_update) >= 1.0 ) { + std::cout << "\rComputing about " << statLUPS << " lattice updates per second." << std::flush; + statLUPS = 0; + last_lups_update = timer::now(); + } + + if ( timer::millisecondsSince(last_lattice_update) >= 1000/maxLUPS ) { + statLUPS += 1; + if ( tick ) { interact_shader->workOn(tick_buffers); collide_shader->workOn(tick_buffers); @@ -198,7 +208,7 @@ int render(bool open_boundaries) { collide_shader->dispatch(nX, nY); } - last_frame = timer::now(); + last_lattice_update = timer::now(); } } @@ -214,6 +224,8 @@ int render(bool open_boundaries) { } }); + std::cout << std::endl; + return 0; } -- cgit v1.2.3