-
Notifications
You must be signed in to change notification settings - Fork 51
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
Replace renderOneFrame for per-workspace update calls #323
Comments
Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Requires ign-rendering update to compile correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Requires ign-rendering update to compile correctly Requires ign-gazebo update to run correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
@iche033 Quick question.
I believe it should say "This shouldn't be used in applications with multiple cameras" ? Because this function should be used for apps with a single camera, or multiple consumers of a single camera images. |
Figured out a more user friendly solution to efficient loops of cameras i.e. the All Cameras should call FlushSomething() (name pending) inside The user would still have to call A value of 0 means we flush every camera (old behavior) and no need to call With these changes, a user updating like this:
should achieve optimum performance |
yes :)
sounds good! I'm assuming the idea is to keep the value at 0 as default behavior and let advanced users call |
The idea is that default is 0 yes. This value being 0 is to ease porting of existing users, where failing to call PostRenderGpuFlush results in leaks or other weird behavior (and the complexity of existing codebases is unknown but presumably large). |
UpdateWith my recent changes in my branch, Turns out this change will fix a subtle bug caused by Ogre2GpuRays; therefore this fix is no longer merely a "performance improvement" and now it is a bugfix too (only present when using ogre2):
Technically the problem is global e.g. rendering to a two regular cameras and then to all 6 faces of a Ogre2GpuRays means the particles can be in up to 8 different time-states instead of 1. |
I have a question for you @iche033 about the default value of SetNumCameraPassesPerGpuFlush I made a couple changes to the proposed ones, which is less intrusive than what was originally proposed. The current changes are like the following:
Given that we can warn the user what's wrong (i.e. they didn't update their code to call Scene::PostRender), it may be better to set a default value for SetNumCameraPassesPerGpuFlush somewhere between [1; 6] rather than defaulting to legacy value of 0 What do you think? |
The changes sound good to me. We should probably target these changes to
I am thinking of a way to ease transition for users. Instead of an assert, we could print out an error msg like you're already doing, and in addition, we either call
yeah I think that's fine. How about a default value to 1? For users wanting to use more cameras, they'll then need to change this value. We'll likely need a small tutorial teaching users how to use these APIs later Some other minor comments on APIs:
|
We can do that, but issuing some Ogre commands before PostRender (e.g. creating/destroying a light between PreRender/PostRender is a no-go*) might cause trouble, hence the message must put emphasis in the importance of doing it.
I should clarify this better in the docs: If you set a value of e.g. 6, but you have a single camera and call PostRender, this will force a flush and hence having a value of 1 or 6 won't matter as the result will be exactly the same (in every term: performance, memory consumption). A value of 6 is like an upper bound. We may queue up to 6 render passes or less; but never more. But that does not mean a value of 6 unnecessarily wastes 6x more RAM than a value of 1 if you only have one regular camera.
Got it. TL;DR changes for me to implement
|
I see, thanks for the clarification, that makes sense. |
Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Requires ign-rendering update to compile correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
OK! So I did extensive testing(*) and it looks stable and working. Which surprised me. It looks ready or almost ready to start merging. But I do have a couple of questions on the merge:
Thus probably gazebo_scene_viewer demo is the only one I should be able to get working to see if it works, and then the code should be merged to main (repos to be merged are ign-rendering, -gazebo, -sensors) (*)which of course means another user will encounter an obvious-unmissable problem the second they try it out |
|
Great! I probably will have then to merge with SetCameraPassCountPerGpuFlush = 0 as default at least until ign-gazebo and ign-sensors get updated so that these modules are PostFrame-aware |
|
Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Requires ign-rendering update to compile correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Requires ign-rendering update to compile correctly Requires ign-gazebo update to run correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
* 🎈 5.1.0 (#351) Signed-off-by: Louise Poubel <louise@openrobotics.org> * Replace renderOneFrame for per-workspace update calls Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects #323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add Scene::SetLegacyAutoGpuFlush Affects #323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add Scene::SetNumCameraPassesPerGpuFlush Renamed PostRenderGpuFlush to PostRender PostRenderGpuFlush was leaking too much internal behavior of how the engine works into the user. The new way of forcing the user to pair PreRender and PostRender calls is much easier to understand and user-friendly Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Assert when PreRender/PostRender calls are used incorrectly Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix warnings generated by gazebo in legacy mode Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add missing listener triggers Fixes GpuRays/GpuRaysTest.RaysParticles failure Particle FXs should now be working as intended Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Rename functions to be consistent w/ Ignition naming convention SetNumCameraPassesPerGpuFlush -> SetCameraPassCountPerGpuFlush GetNumCameraPassesPerGpuFlush -> GetCameraPassCountPerGpuFlush GetLegacyAutoGpuFlush -> LegacyAutoGpuFlush Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Document that SetCameraPassCountPerGpuFlush is an upper bound Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Document Camera::Update shouldn't be called if there's many cameras Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Check in Render() call that we're inside PreRender / PostRender Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix INTEGRATION_camera crash Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix EndFrame not getting called when in non-legacy mode INTEGRATION_depth_camera now succeeds Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix wrong documentation about Camera::Capture Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Update Migration notes w/ Scene::PostRender Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add missing call in doc's recomendations Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Improve documentation and make asserts more helpful Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Default cameraPassCountPerGpuFlush until all modules are merged Fix wrong documentation about currNumCameraPasses Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Remove unnecessary headers Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Style changes for consistency with the rest of the codebase Better document code in FlushGpuCommandsOnly Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Multiple fixes - Do not recommend the user to call Camera::PreRender in docs. This is done implicitly via Scene::PreRender - Rename GetCameraPassCountPerGpuFlush -> CameraPassCountPerGpuFlush - CameraPassCountPerGpuFlush was incorrectly always returning 0 - Grammar mistakes in comments Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Make cameraPassCountPerGpuFlush default to 6 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> Co-authored-by: Louise Poubel <louise@openrobotics.org>
…145) * Call Scene::PostRenderGpuFlush Requires ign-rendering update to compile correctly Requires ign-gazebo update to run correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Update to use the renamed PostRender call Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Update integration test Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Rename SetNumCameraPassesPerGpuFlush -> SetCameraPassCountPerGpuFlush Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
* Call Scene::PostRenderGpuFlush Requires ign-rendering update to compile correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Update to use the renamed PostRender call Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Avoid warnings from Legacy mode Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Default to SetNumCameraPassesPerGpuFlush = 6 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Rename SetNumCameraPassesPerGpuFlush -> SetCameraPassCountPerGpuFlush Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Style changes Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
* 🎈 5.1.0 (gazebosim#351) Signed-off-by: Louise Poubel <louise@openrobotics.org> * Replace renderOneFrame for per-workspace update calls Add Scene::PostRenderGpuFlush Breaks ABI. Needs changes to other components as well, so they call Scene::PostRenderGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add Scene::SetLegacyAutoGpuFlush Affects gazebosim#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add Scene::SetNumCameraPassesPerGpuFlush Renamed PostRenderGpuFlush to PostRender PostRenderGpuFlush was leaking too much internal behavior of how the engine works into the user. The new way of forcing the user to pair PreRender and PostRender calls is much easier to understand and user-friendly Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Assert when PreRender/PostRender calls are used incorrectly Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix warnings generated by gazebo in legacy mode Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add missing listener triggers Fixes GpuRays/GpuRaysTest.RaysParticles failure Particle FXs should now be working as intended Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Rename functions to be consistent w/ Ignition naming convention SetNumCameraPassesPerGpuFlush -> SetCameraPassCountPerGpuFlush GetNumCameraPassesPerGpuFlush -> GetCameraPassCountPerGpuFlush GetLegacyAutoGpuFlush -> LegacyAutoGpuFlush Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Document that SetCameraPassCountPerGpuFlush is an upper bound Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Document Camera::Update shouldn't be called if there's many cameras Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Check in Render() call that we're inside PreRender / PostRender Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix INTEGRATION_camera crash Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix EndFrame not getting called when in non-legacy mode INTEGRATION_depth_camera now succeeds Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Fix wrong documentation about Camera::Capture Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Update Migration notes w/ Scene::PostRender Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Add missing call in doc's recomendations Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Improve documentation and make asserts more helpful Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Default cameraPassCountPerGpuFlush until all modules are merged Fix wrong documentation about currNumCameraPasses Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Remove unnecessary headers Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Style changes for consistency with the rest of the codebase Better document code in FlushGpuCommandsOnly Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Multiple fixes - Do not recommend the user to call Camera::PreRender in docs. This is done implicitly via Scene::PreRender - Rename GetCameraPassCountPerGpuFlush -> CameraPassCountPerGpuFlush - CameraPassCountPerGpuFlush was incorrectly always returning 0 - Grammar mistakes in comments Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Make cameraPassCountPerGpuFlush default to 6 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> Co-authored-by: Louise Poubel <louise@openrobotics.org> Signed-off-by: William Lew <WilliamMilesLew@gmail.com>
* Call Scene::PostRenderGpuFlush Requires ign-rendering update to compile correctly Affects gazebosim/gz-rendering#323 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Update to use the renamed PostRender call Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Avoid warnings from Legacy mode Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Default to SetNumCameraPassesPerGpuFlush = 6 Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Rename SetNumCameraPassesPerGpuFlush -> SetCameraPassCountPerGpuFlush Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> * Style changes Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar> Signed-off-by: William Lew <WilliamMilesLew@gmail.com>
@iche033 is this fixed? |
yes we can consider this as complete. |
Current behavior
Currently Gazebo is doing, for every camera (of any type):
This is inefficient. Because:
Desired behavior
The code can be replaced with the following:
While
Ogre::SceneManager::updateSceneGraph
gets moved toScene::PreRender
and a GPU flush is moved toScene::PostRenderGpuFlush
(PostRenderGpuFlush currently doesn't exist)Exceptions
Scene::PostRenderGpuFlush
Flushes all buffered frame data and starts 'a new frame'.CPUs queue up a bunch of rendering commands and then waits for the GPU to finish up.
If we flush too often, the CPU will often have to wait for the GPU doing nothing.
If we flush too infrequently, RAM consumption will rise due to queueing up unsubmitted work.
This function should be called after updating all cameras / once per frame, but it may be called more often if you're updating too many cameras and running out of memory.
Example:
108 is way too much, causing out of memory situations;
so flushing once per probe may make better sense in this case.
Note however that Gazebo is currently flushing once per cubemap face (i.e. flushing 6x3 = 18 times). While with my proposal (once per cubemap) we would flush 3 times.
Reason
This is merely a performance improvement.
This paves the way for an additional improvement. For example currently Depth Sensors are doing the following:
This negates our optimization proposed in this ticket because PostRender will force the CPU to wait for the GPU. The render loop can be improved to the following:
This allows the CPU to do more work while the GPU is rendering the previous cameras in parallel
N is an arbitrary number, where it depends on available memory and scene type (large values of N queue up too much, low values cause too much stall).
Impact
This is an ABI and API breaking change.
Other components need to change so they also call PostRenderGpuFlush (usually looking for calls to Scene::PreRender is a good start).
e.g. ign-sensors needs to add a call to PostRenderGpuFlush
Users must call PostRenderGpuFlush at some point or else errors or out of memory conditions may occur.
Because of this, a boolean will be added for migrating users. This boolean will control whether the old behavior or the new behavior is used.
In the old behavior, Gazebo will issue one updateSceneGraph and one PostRenderGpuFlush per Camera (default) which is what Gazebo is currently doing.
In the new behavior, Gazebo assumes the user properly calls PreRender and PostRenderGpuFlush when appropriate
Samples need to be updated to reflect this change
Risks
Implementation suggestion
I'm the one implementing this feature. This ticket is for tracking progress.
Progress
Progress can be tracked at:
Blocking problems:
With cameraPassCountPerGpuFlush = 6
With cameraPassCountPerGpuFlush = 0
The text was updated successfully, but these errors were encountered: